Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

emaillistitem.cpp

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2001 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qt Palmtop Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 #include <qstring.h>
00021 #include <qpe/resource.h>
00022 #include "emaillistitem.h"
00023 
00024 EmailListItem::EmailListItem(QListView *parent, Email mailIn, bool inbox)
00025     : QListViewItem(parent)
00026 {
00027   QString temp;
00028 
00029   mail = mailIn;
00030 
00031   if (inbox) {
00032     setText(0, mail.from);
00033   } else {
00034     QStringList::Iterator it = mail.recipients.begin();
00035     temp = *it;
00036     if (mail.recipients.count() > 1)
00037       temp += "...";
00038     setText(0, temp);
00039   }
00040   setText(1, mail.subject);
00041   // setText(2,mail.date);
00042   setText(2,dateFromULCString(mail.date));
00043 
00044   if (mailIn.files.count()>0)
00045   {
00046     setPixmap(0, Resource::loadPixmap("mailit/attach"));
00047   }
00048 
00049   selected = FALSE;
00050 }
00051 
00052 Email* EmailListItem::getMail()
00053 {
00054   return &mail;
00055 }
00056 
00057 void EmailListItem::setMail(Email newMail)
00058 {
00059   mail = newMail;
00060   repaint();
00061 }
00062 
00063 void EmailListItem::setItemSelected(bool enable)
00064 {
00065   selected = enable;
00066   setSelected(enable);
00067   repaint();
00068 }
00069 
00070 bool EmailListItem::isItemSelected()
00071 {
00072   return selected;
00073 }
00074 
00075 void EmailListItem::paintCell( QPainter *p, const QColorGroup &cg,
00076         int column, int width, int alignment )
00077 {
00078 
00079   QColorGroup _cg( cg );
00080   QColor c = _cg.text();
00081 
00082   if ( (! mail.read) && (mail.received) )
00083     _cg.setColor( QColorGroup::Text, Qt::blue);
00084   if (!mail.downloaded)
00085     _cg.setColor( QColorGroup::Text, Qt::red);
00086 
00087 /*  if (selected) {
00088     _cg.setColor(QColorGroup::Base, Qt::blue);
00089     _cg.setColor(QColorGroup::Text, Qt::yellow);
00090     if (isSelected()) {
00091       _cg.setColor(QColorGroup::HighlightedText, Qt::yellow);
00092     } else {
00093       _cg.setColor(QColorGroup::Highlight, Qt::blue);
00094     }
00095   }
00096 */
00097     QListViewItem::paintCell( p, _cg, column, width, alignment );
00098 
00099     _cg.setColor( QColorGroup::Text, c );
00100 }
00101 
00102 /*
00103  * Converts an E-Mail date (ULC) RFC 2822 conform to a QDateTime.
00104  * Returning a QString with formatting of "YYYY-MM-DD HH:MM:SS"
00105  * (zodiac: This method was tested with more than 300 inbox mails,
00106  * it didn't slow down the loading of mail-it.)
00107  */
00108 QString EmailListItem::dateFromULCString( QString ulcDate )
00109 {
00110         QString sTemp, sTime;
00111         int iPos, iDay, iMon=1, iYear;
00112 
00113         iPos=ulcDate.find(',');
00114         if (iPos) { // it has a day-of-week
00115                 ulcDate=ulcDate.remove(0,++iPos); //.stripWhiteSpace();
00116         }
00117 
00118         QStringList dateEntries = QStringList::split(" ",ulcDate,FALSE);
00119         QStringList::Iterator iter = dateEntries.begin();
00120 
00121         // Get day as DD
00122         iDay = (*iter++).toInt();
00123 
00124         // Get month as string Mmm
00125         sTemp = (*iter++);
00126         if (sTemp =="Jan") {iMon=1;} else
00127         if (sTemp =="Feb") {iMon=2;} else
00128         if (sTemp =="Mar") {iMon=3;} else
00129         if (sTemp =="Apr") {iMon=4;} else
00130         if (sTemp =="May") {iMon=5;} else
00131         if (sTemp =="Jun") {iMon=6;} else
00132         if (sTemp =="Jul") {iMon=7;} else
00133         if (sTemp =="Aug") {iMon=8;} else
00134         if (sTemp =="Sep") {iMon=9;} else
00135         if (sTemp =="Oct") {iMon=10;} else
00136         if (sTemp =="Nov") {iMon=11;} else
00137         if (sTemp =="Dec") {iMon=12;}
00138 
00139         // Get year as YYYY or YY
00140         iYear = (*iter++).toInt();
00141 
00142         QDate date = QDate(iYear, iMon, iDay);
00143 
00144         // Convert timestring into a QTime
00145         QStringList timeEntries = QStringList::split(":",(*iter++),FALSE);
00146         QStringList::Iterator iterTime = timeEntries.begin();
00147         iYear=(*iterTime++).toInt(); // var reuse.. *cough*
00148         iMon=(*iterTime++).toInt();
00149         iDay=(*iterTime++).toInt();
00150         QTime time = QTime(iYear,iMon,iDay);
00151 
00152         return QString::number(date.year())+"-"
00153                 +QString::number(date.month()).rightJustify(2,'0')+"-"
00154                 +QString::number(date.day()).rightJustify(2,'0')+" "
00155                 +time.toString();
00156 }
00157 
00158 

Generated on Sat Nov 5 16:18:09 2005 for OPIE by  doxygen 1.4.2