00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "filterlogviewmovedmodel.h"
00019
00020 FilterLogViewMovedModel::FilterLogViewMovedModel( QObject* parent, FilterLog* log ): QAbstractItemModel( parent )
00021 {
00022 this->log = log;
00023
00024
00025 lastSortOrder = Qt::AscendingOrder;
00026 lastSortColumn = 0;
00027
00028
00029 list.append( log->getMovedMails() );
00030
00031 }
00032
00033 QVariant FilterLogViewMovedModel::data( const QModelIndex& index, int role ) const
00034 {
00035
00036 if( !index.isValid() ) return QVariant();
00037
00038 if( index.row() > rowCount() || index.column() > NUMBER_VIEWMOVED_COLUMNS - 1 ) return QVariant();
00039
00040 if( index.row() > list.size() - 1 ) return QVariant();
00041
00042
00043 FilterLogEntry entry = list.at( index.row() );
00044
00045 switch( role ) {
00046
00047 case( Qt::DisplayRole ) : {
00048
00049 switch( index.column() ) {
00050
00051 case 0 : return QVariant( entry.getDate().toString( KDateTime::LocalDate) ); break;
00052 case 1 : return QVariant( entry.getSender() ); break;
00053 case 2 : return QVariant( entry.getAccount() ); break;
00054 case 3 : return QVariant( entry.getMailbox() ); break;
00055 case 4 : return QVariant( entry.getSubject() ); break;
00056 default : return QVariant(); break;
00057 }
00058 }
00059
00060 default : return QVariant();
00061
00062 }
00063
00064
00065 }
00066
00067 int FilterLogViewMovedModel::columnCount(const QModelIndex& ) const
00068 {
00069 return NUMBER_VIEWMOVED_COLUMNS;
00070 }
00071
00072 int FilterLogViewMovedModel::rowCount( const QModelIndex& parent ) const
00073 {
00074
00075 if( parent.isValid() ) return 0;
00076
00077 return list.size();
00078
00079 }
00080
00081 QModelIndex FilterLogViewMovedModel::parent( const QModelIndex& ) const
00082 {
00083 return QModelIndex();
00084 }
00085
00086 QModelIndex FilterLogViewMovedModel::index(int row, int column, const QModelIndex& parent) const
00087 {
00088
00089
00090 if( parent.isValid() ) return QModelIndex();
00091
00092 return createIndex( row, column );
00093
00094 }
00095
00096 QVariant FilterLogViewMovedModel::headerData(int section, Qt::Orientation orientation, int role) const
00097 {
00098
00099 if( role != Qt::DisplayRole || orientation != Qt::Horizontal )
00100 return QVariant();
00101
00102 switch( section )
00103 {
00104 case 0 : return QVariant( i18nc( "@title:column send date", "Date" ) ); break;
00105 case 1 : return QVariant( i18nc( "@title:column sender of the mail", "Sender" ) ); break;
00106 case 2 : return QVariant( i18nc( "@title:column account name", "Account" ) ); break;
00107 case 3 : return QVariant( i18nc( "@title:column name of the mailbox where the mail was written", "Moved To" ) ); break;
00108 case 4 : return QVariant( i18nc( "@title:column mail subject", "Subject" ) ); break;
00109 default : return QVariant();
00110 }
00111 }
00112
00113 void FilterLogViewMovedModel::sort(int column, Qt::SortOrder order)
00114 {
00115
00116
00117 lastSortOrder = order;
00118 lastSortColumn = column;
00119
00120 if( list.isEmpty() ) return;
00121
00122
00123 LogViewSort prop;
00124 switch( column ) {
00125
00126 case 0 : prop = LogViewSortDate; break;
00127 case 1 : prop = LogViewSortFrom; break;
00128 case 2 : prop = LogViewSortAccount; break;
00129 case 3 : prop = LogViewSortSubject; break;
00130 default : prop = LogViewSortDate; break;
00131 }
00132
00133
00134 QList<FilterLogEntry> sortedList;
00135
00136 QListIterator<FilterLogEntry> itUnsort( list );
00137 while( itUnsort.hasNext() ) {
00138
00139
00140 FilterLogEntry entryUnsorted = itUnsort.next();
00141
00142
00143 if( sortedList.size() == 0 ) {
00144
00145 sortedList.append( entryUnsorted );
00146
00147 } else {
00148
00149 int sizeSortedList = sortedList.size();
00150 int indexSort = 0;
00151 bool placed = false;
00152 while( indexSort < sizeSortedList && !placed ) {
00153
00154
00155 FilterLogEntry entrySorted = sortedList.at( indexSort );
00156
00157
00158
00159 if( order == Qt::AscendingOrder ) {
00160
00161 if( entryUnsorted.compare( entrySorted, prop ) <= 0 ) {
00162
00163 sortedList.insert( indexSort, entryUnsorted );
00164 placed = true;
00165 }
00166
00167 } else {
00168
00169 if( entryUnsorted.compare( entrySorted, prop ) > 0 ) {
00170
00171 sortedList.insert( indexSort, entryUnsorted );
00172 placed = true;
00173 }
00174 }
00175
00176 indexSort++;
00177 }
00178
00179
00180 if( !placed )
00181 sortedList.append( entryUnsorted );
00182 }
00183 }
00184
00185
00186 list.clear();
00187 list.append( sortedList );
00188
00189 reset();
00190 }
00191
00192 void FilterLogViewMovedModel::sort()
00193 {
00194 sort( lastSortColumn, lastSortOrder );
00195 }
00196
00197 void FilterLogViewMovedModel::refresh()
00198 {
00199 list.clear();
00200 list.append( log->getMovedMails() );
00201 sort();
00202 reset();
00203 }
00204
00205 void FilterLogViewMovedModel::saveSetup()
00206 {
00207 KConfigGroup* conf = new KConfigGroup( KGlobal::config(), CONFIG_GROUP_VIEW );
00208
00209 conf->writeEntry( CONFIG_ENTRY_SORT_COLUMN_LOGVIEW_MOVED, lastSortColumn );
00210
00211 if( lastSortOrder == Qt::AscendingOrder ) {
00212
00213 conf->writeEntry( CONFIG_ENTRY_SORT_ORDER_LOGVIEW_MOVED, CONFIG_VALUE_SORT_ORDER_ASCENDING );
00214
00215 } else {
00216
00217 conf->writeEntry( CONFIG_ENTRY_SORT_ORDER_LOGVIEW_MOVED, CONFIG_VALUE_SORT_ORDER_DESCENDING );
00218 }
00219
00220 conf->sync();
00221
00222
00223 }
00224