00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "filterlogentry.h"
00019
00020 FilterLogEntry::FilterLogEntry()
00021 {
00022
00023 sentDateTime.setDate( QDate( 2007, 11, 7 ) );
00024 sentDateTime.setTime( QTime( 19, 05 ) );
00025 act = FActNone;
00026 }
00027
00028 FilterLogEntry::FilterLogEntry( FilterAction_Type action, const KDateTime& dateTime, const QString& sender, const QString& account, const QString& subject, const QString& mailbox)
00029 : act( action ), sentDateTime( dateTime ), sender( sender ), account( account ), subject( subject ), mailbox( mailbox )
00030 {
00031 }
00032
00033 FilterLogEntry::~FilterLogEntry()
00034 {
00035 }
00036
00037 void FilterLogEntry::print()
00038 {
00039 QString strAction;
00040 switch( act )
00041 {
00042 case FActPass : strAction = "Passed"; break;
00043 case FActDelete : strAction = "Deleted"; break;
00044 case FActMark : strAction = "Marked"; break;
00045 case FActSpamcheck : strAction = "forwarded to check for spam"; break;
00046 case FActMove : strAction = QString( "moved to %1" ).arg( mailbox); break;
00047 case FActNone : strAction = "no Action (THIS IS AN ERROR!)"; break;
00048 default : strAction = "ERROR! UNKNOWN ACTION"; break;
00049 }
00050
00051 kdDebug() << sentDateTime.toString( KDateTime::LocalDate ) << ";" << account << ";" << sender << ";" << subject << ";" << strAction << endl;
00052 }
00053
00054 FilterLogEntry::FilterLogEntry(const FilterLogEntry & ent)
00055 {
00056 this->sentDateTime = ent.sentDateTime;
00057 this->account = ent.account;
00058 this->sender = ent.sender;
00059 this->subject = ent.subject;
00060 this->act = ent.act;
00061 this->mailbox = ent.mailbox;
00062 }
00063
00064 FilterLogEntry& FilterLogEntry::operator=( const FilterLogEntry & ent )
00065 {
00066 if( this == &ent ) return *this;
00067
00068 this->sentDateTime = ent.sentDateTime;
00069 this->account = ent.account;
00070 this->sender = ent.sender;
00071 this->subject = ent.subject;
00072 this->mailbox = ent.mailbox;
00073 this->act = ent.act;
00074
00075 return *this;
00076 }
00077
00078 bool FilterLogEntry::isOlder( uint days )
00079 {
00080 return sentDateTime.date().addDays( days ) < QDate::currentDate();
00081 }
00082
00083 bool FilterLogEntry::operator== ( const FilterLogEntry& ent ) const
00084 {
00085 return sentDateTime == ent.sentDateTime;
00086 }
00087
00088 bool FilterLogEntry::operator!=( const FilterLogEntry& ent ) const
00089 {
00090 return sentDateTime != ent.sentDateTime;
00091 }
00092
00093 bool FilterLogEntry::operator>( const FilterLogEntry& ent ) const
00094 {
00095 return sentDateTime > ent.sentDateTime;
00096 }
00097
00098 bool FilterLogEntry::operator>=( const FilterLogEntry& ent ) const
00099 {
00100 return sentDateTime >= ent.sentDateTime;
00101 }
00102
00103 bool FilterLogEntry::operator<( const FilterLogEntry& ent ) const
00104 {
00105 return sentDateTime < ent.sentDateTime;
00106 }
00107
00108 bool FilterLogEntry::operator<=( const FilterLogEntry & ent ) const
00109 {
00110 return sentDateTime <= ent.sentDateTime;
00111 }
00112
00113 void FilterLogEntry::save( QDomDocument& doc, QDomElement& parent )
00114 {
00115
00116 QDomElement elem = doc.createElement( LOG_ENTRY_ELEMENT );
00117 elem.setAttribute( LOG_ENTRY_ATTRIBUTE_DATETIME, sentDateTime.toString( KDateTime::ISODate ) );
00118 elem.setAttribute( LOG_ENTRY_ATTRIBUTE_SENDER, sender );
00119 elem.setAttribute( LOG_ENTRY_ATTRIBUTE_ACCOUNT, account );
00120 elem.setAttribute( LOG_ENTRY_ATTRIBUTE_SUBJECT, subject );
00121
00122
00123 parent.appendChild( elem );
00124 }
00125
00126 KDateTime FilterLogEntry::getDate( ) const
00127 {
00128 return sentDateTime;
00129 }
00130
00131 QString FilterLogEntry::getSender( ) const
00132 {
00133 return sender;
00134 }
00135
00136 QString FilterLogEntry::getAccount( ) const
00137 {
00138 return account;
00139 }
00140
00141 QString FilterLogEntry::getSubject( ) const
00142 {
00143 return subject;
00144 }
00145
00146 QString FilterLogEntry::getMailbox( ) const
00147 {
00148 return mailbox;
00149 }
00150
00151 int FilterLogEntry::compare( const FilterLogEntry& other, LogViewSort property ) const
00152 {
00153 switch( property ) {
00154
00155 case( LogViewSortDate ) : {
00156
00157 if( getDate() == other.getDate() ) return 0;
00158 else if( getDate() > other.getDate() ) return 1;
00159 else return -1;
00160
00161 }
00162
00163 case( LogViewSortFrom ) : {
00164
00165 return QString::localeAwareCompare( getSender(), other.getSender() );
00166 }
00167
00168 case( LogViewSortAccount ) : {
00169
00170 return QString::localeAwareCompare( getAccount(), other.getAccount() );
00171 }
00172
00173 case( LogViewSortSubject ) : {
00174
00175 return QString::localeAwareCompare( getSubject(), other.getSubject() );
00176 }
00177
00178 case( LogViewSortMailbox ) : {
00179
00180 return QString::localeAwareCompare( getMailbox(), other.getMailbox() );
00181 }
00182
00183 default : {
00184
00185 if( getDate() == other.getDate() ) return 0;
00186 else if( getDate() > other.getDate() ) return 1;
00187 else return -1;
00188
00189 }
00190
00191 }
00192 }