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