summaryrefslogtreecommitdiff
path: root/noncore/unsupported/mailit/emaillistitem.cpp
Unidiff
Diffstat (limited to 'noncore/unsupported/mailit/emaillistitem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/unsupported/mailit/emaillistitem.cpp73
1 files changed, 66 insertions, 7 deletions
diff --git a/noncore/unsupported/mailit/emaillistitem.cpp b/noncore/unsupported/mailit/emaillistitem.cpp
index fc9f766..a25f93a 100644
--- a/noncore/unsupported/mailit/emaillistitem.cpp
+++ b/noncore/unsupported/mailit/emaillistitem.cpp
@@ -16,44 +16,45 @@
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#include <qstring.h> 20#include <qstring.h>
21#include <qpe/resource.h> 21#include <qpe/resource.h>
22#include "emaillistitem.h" 22#include "emaillistitem.h"
23 23
24EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox) 24EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox)
25 : QListViewItem(parent) 25 : QListViewItem(parent)
26{ 26{
27 QString temp; 27 QString temp;
28 28
29 mail = mailIn; 29 mail = mailIn;
30 30
31 if (inbox) { 31 if (inbox) {
32 setText(0, mail.from); 32 setText(0, mail.from);
33 } else { 33 } else {
34 QStringList::Iterator it = mail.recipients.begin(); 34 QStringList::Iterator it = mail.recipients.begin();
35 temp = *it; 35 temp = *it;
36 if (mail.recipients.count() > 1) 36 if (mail.recipients.count() > 1)
37 temp += "..."; 37 temp += "...";
38 setText(0, temp); 38 setText(0, temp);
39 } 39 }
40 setText(1, mail.subject); 40 setText(1, mail.subject);
41 setText(2,mail.date); 41 // setText(2,mail.date);
42 42 setText(2,dateFromULCString(mail.date));
43
43 if (mailIn.files.count()>0) 44 if (mailIn.files.count()>0)
44 { 45 {
45 setPixmap(0, Resource::loadPixmap("mailit/attach")); 46 setPixmap(0, Resource::loadPixmap("mailit/attach"));
46 } 47 }
47 48
48 selected = FALSE; 49 selected = FALSE;
49} 50}
50 51
51Email* EmailListItem::getMail() 52Email* EmailListItem::getMail()
52{ 53{
53 return &mail; 54 return &mail;
54} 55}
55 56
56void EmailListItem::setMail(Email newMail) 57void EmailListItem::setMail(Email newMail)
57{ 58{
58 mail = newMail; 59 mail = newMail;
59 repaint(); 60 repaint();
@@ -73,27 +74,85 @@ bool EmailListItem::isItemSelected()
73 74
74void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg, 75void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg,
75 int column, int width, int alignment ) 76 int column, int width, int alignment )
76{ 77{
77 78
78 QColorGroup _cg( cg ); 79 QColorGroup _cg( cg );
79 QColor c = _cg.text(); 80 QColor c = _cg.text();
80 81
81 if ( (! mail.read) && (mail.received) ) 82 if ( (! mail.read) && (mail.received) )
82 _cg.setColor( QColorGroup::Text, Qt::blue); 83 _cg.setColor( QColorGroup::Text, Qt::blue);
83 if (!mail.downloaded) 84 if (!mail.downloaded)
84 _cg.setColor( QColorGroup::Text, Qt::red); 85 _cg.setColor( QColorGroup::Text, Qt::red);
85 86
86/* if (selected) { 87/* if (selected) {
87 _cg.setColor(QColorGroup::Base, Qt::blue); 88 _cg.setColor(QColorGroup::Base, Qt::blue);
88 _cg.setColor(QColorGroup::Text, Qt::yellow); 89 _cg.setColor(QColorGroup::Text, Qt::yellow);
89 if (isSelected()) { 90 if (isSelected()) {
90 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow); 91 _cg.setColor(QColorGroup::HighlightedText, Qt::yellow);
91 } else { 92 } else {
92 _cg.setColor(QColorGroup::Highlight, Qt::blue); 93 _cg.setColor(QColorGroup::Highlight, Qt::blue);
93 } 94 }
94 } 95 }
95*/ 96*/
96 QListViewItem::paintCell( p, _cg, column, width, alignment ); 97 QListViewItem::paintCell( p, _cg, column, width, alignment );
97 98
98 _cg.setColor( QColorGroup::Text, c ); 99 _cg.setColor( QColorGroup::Text, c );
99} 100}
101
102/*
103 * Converts an E-Mail date (ULC) RFC 2822 conform to a QDateTime.
104 * Returning a QString with formatting of "YYYY-MM-DD HH:MM:SS"
105 * (zodiac: This method was tested with more than 300 inbox mails,
106 * it didn't slow down the loading of mail-it.)
107 */
108QString EmailListItem::dateFromULCString( QString ulcDate )
109{
110 QString sTemp, sTime;
111 int iPos, iDay, iMon=1, iYear;
112
113 iPos=ulcDate.find(',');
114 if (iPos) { // it has a day-of-week
115 ulcDate=ulcDate.remove(0,++iPos); //.stripWhiteSpace();
116 }
117
118 QStringList dateEntries = QStringList::split(" ",ulcDate,FALSE);
119 QStringList::Iterator iter = dateEntries.begin();
120
121 // Get day as DD
122 iDay = (*iter++).toInt();
123
124 // Get month as string Mmm
125 sTemp = (*iter++);
126 if (sTemp =="Jan") {iMon=1;} else
127 if (sTemp =="Feb") {iMon=2;} else
128 if (sTemp =="Mar") {iMon=3;} else
129 if (sTemp =="Apr") {iMon=4;} else
130 if (sTemp =="May") {iMon=5;} else
131 if (sTemp =="Jun") {iMon=6;} else
132 if (sTemp =="Jul") {iMon=7;} else
133 if (sTemp =="Aug") {iMon=8;} else
134 if (sTemp =="Sep") {iMon=9;} else
135 if (sTemp =="Oct") {iMon=10;} else
136 if (sTemp =="Nov") {iMon=11;} else
137 if (sTemp =="Dec") {iMon=12;}
138
139 // Get year as YYYY or YY
140 iYear = (*iter++).toInt();
141
142 QDate date = QDate(iYear, iMon, iDay);
143
144 // Convert timestring into a QTime
145 QStringList timeEntries = QStringList::split(":",(*iter++),FALSE);
146 QStringList::Iterator iterTime = timeEntries.begin();
147 iYear=(*iterTime++).toInt(); // var reuse.. *cough*
148 iMon=(*iterTime++).toInt();
149 iDay=(*iterTime++).toInt();
150 QTime time = QTime(iYear,iMon,iDay);
151
152 return QString::number(date.year())+"-"
153 +QString::number(date.month()).rightJustify(2,'0')+"-"
154 +QString::number(date.day()).rightJustify(2,'0')+" "
155 +time.toString();
156}
157
158