kmpopfiltercnfrmdlg.cpp
00001 /*************************************************************************** 00002 kmpopheadersdlg.cpp 00003 ------------------- 00004 begin : Mon Oct 22 2001 00005 copyright : (C) 2001 by Heiko Hund 00006 Thorsten Zachmann 00007 email : heiko@ist.eigentlich.net 00008 T.Zachmann@zagge.de 00009 ***************************************************************************/ 00010 00011 #include <config.h> 00012 #include "kmpopfiltercnfrmdlg.h" 00013 #include "kmheaders.h" 00014 00015 #include <tqlayout.h> 00016 #include <tqlabel.h> 00017 #include <tqheader.h> 00018 #include <tqcheckbox.h> 00019 #include <tqvgroupbox.h> 00020 #include <tqtimer.h> 00021 00022 #include <tdelocale.h> 00023 #include <tdeio/global.h> 00024 00025 #include <assert.h> 00026 00029 KMPopHeadersView::KMPopHeadersView(TQWidget *aParent, KMPopFilterCnfrmDlg *aDialog) 00030 : TDEListView(aParent) 00031 { 00032 mDialog=aDialog; 00033 int mDownIndex=addColumn(TQIconSet(TQPixmap(mDown)), TQString(), 24); 00034 assert( mDownIndex == Down ); //This code relies on the fact that radiobuttons are the first three columns for easier Column-Action mapping 00035 //it does not necessarily be true - you could redefine mapToColumn and mapToAction to eg. shift those numbers by 1 00036 addColumn(TQIconSet(TQPixmap(mLater)), TQString(), 24); 00037 addColumn(TQIconSet(TQPixmap(mDel)), TQString(), 24); 00038 00039 /*int subjCol =*/ addColumn(i18n("Subject"), 180); 00040 /*int sendCol =*/ addColumn(i18n("Sender"), 150); 00041 /*int recvCol =*/ addColumn(i18n("Receiver"), 150); 00042 int dateCol = addColumn(i18n("Date"), 120); 00043 int sizeCol = addColumn(i18n("Size"), 80); 00044 00045 setAllColumnsShowFocus(true); 00046 00047 setColumnAlignment(Down, TQt::AlignHCenter); 00048 setColumnAlignment(Later, TQt::AlignHCenter); 00049 setColumnAlignment(Delete, TQt::AlignHCenter); 00050 setColumnAlignment(sizeCol, TQt::AlignRight); 00051 00052 setSorting(dateCol, false); 00053 setShowSortIndicator(true); 00054 header()->setResizeEnabled(false, Down); 00055 header()->setResizeEnabled(false, Later); 00056 header()->setResizeEnabled(false, Delete); 00057 header()->setClickEnabled(false, Down); 00058 header()->setClickEnabled(false, Later); 00059 header()->setClickEnabled(false, Delete); 00060 00061 //we rely on fixed column order, so we forbid this 00062 header()->setMovingEnabled(false); 00063 00064 connect(this, TQT_SIGNAL(pressed(TQListViewItem*, const TQPoint&, int)), 00065 TQT_SLOT(slotPressed(TQListViewItem*, const TQPoint&, int))); 00066 } 00067 00068 KMPopHeadersView::~KMPopHeadersView() 00069 { 00070 } 00071 00072 //Handle keystrokes - Left and Right key select previous/next action correspondingly 00073 void KMPopHeadersView::keyPressEvent( TQKeyEvent *e ) 00074 { 00075 if (e->key() == Key_Left) { 00076 KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>( selectedItem() ); 00077 if (item&&mDialog) { 00078 if (item->action()) { //here we rely on the fact that the leftmost action is equal to 0! 00079 item->setAction((KMPopFilterAction)((int)item->action()-1)); 00080 mDialog->setAction( selectedItem(), item->action()); 00081 } 00082 } 00083 } else if (e->key() == Key_Right) { 00084 KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>( selectedItem() ); 00085 if (item&&mDialog) { 00086 if (item->action()<NoAction-1) { //here we rely on the fact that right most action is one less than NoAction! 00087 item->setAction((KMPopFilterAction)((int)item->action()+1)); 00088 mDialog->setAction( selectedItem(), item->action()); 00089 } 00090 } 00091 } else { 00092 TQListView::keyPressEvent( e ); 00093 } 00094 } 00095 00096 void KMPopHeadersView::slotPressed(TQListViewItem* aItem, const TQPoint&, int aColumn) { 00097 if ( !( aItem && aColumn>=0 && aColumn<NoAction ) ) return; 00098 KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>(aItem); 00099 assert( item ); 00100 item->setAction(mapToAction(aColumn)); 00101 } 00102 00103 const char *KMPopHeadersView::mUnchecked[26] = { 00104 "19 16 9 1", 00105 " c None", 00106 "# c #000000", 00107 ". c #ffffff", 00108 "a c #4a4c4a", 00109 "b c #524c52", 00110 "c c #efefef", 00111 "e c #fff2ff", 00112 "f c #f6f2f6", 00113 "g c #fff6ff", 00114 " ", 00115 " ", 00116 " aaaa ", 00117 " ba####aa ", 00118 " a##....aac ", 00119 " a#......ec ", 00120 " a#........fc ", 00121 " a#........gc ", 00122 " a#........fc ", 00123 " b#........gc ", 00124 " a#......gc ", 00125 " age....gec ", 00126 " ccfgfgcc ", 00127 " cccc ", 00128 " ", 00129 " ",}; 00130 00131 const char *KMPopHeadersView::mChecked[26] = { 00132 "19 16 9 1", 00133 " c None", 00134 "# c #000000", 00135 ". c #ffffff", 00136 "a c #4a4c4a", 00137 "b c #524c52", 00138 "c c #efefef", 00139 "e c #fff2ff", 00140 "f c #f6f2f6", 00141 "g c #fff6ff", 00142 " ", 00143 " ", 00144 " aaaa ", 00145 " ba####aa ", 00146 " a##....aac ", 00147 " a#......ec ", 00148 " a#...##...fc ", 00149 " a#..####..gc ", 00150 " a#..####..fc ", 00151 " b#...##...gc ", 00152 " a#......gc ", 00153 " age....gec ", 00154 " ccfgfgcc ", 00155 " cccc ", 00156 " ", 00157 " ",}; 00158 00159 const char *KMPopHeadersView::mLater[25] = { 00160 "16 16 8 1", 00161 ". c None", 00162 "g c #303030", 00163 "c c #585858", 00164 "f c #a0a0a0", 00165 "b c #c0c000", 00166 "e c #dcdcdc", 00167 "a c #ffff00", 00168 "d c #ffffff", 00169 "................", 00170 "...........eaa..", 00171 "..........eaaa..", 00172 ".........ebaab..", 00173 ".........eaaa...", 00174 "........eaaab...", 00175 "........eaaa....", 00176 ".......eaaab....", 00177 "eaae..ebaccccc..", 00178 "eaaae.eaacdedc..", 00179 "ebaaabaaabcdc...", 00180 ".ebaaaaaa.fgf...", 00181 "..ebaaaa..cec...", 00182 "...ebaab.cdedc..", 00183 "........eccccc..", 00184 "................"}; 00185 00186 const char *KMPopHeadersView::mDown[20] = { 00187 "16 16 3 1", 00188 ". c None", 00189 "a c #008000", 00190 "b c #00c000", 00191 "................", 00192 "............aa..", 00193 "...........aaa..", 00194 "..........baab..", 00195 "..........aaa...", 00196 ".........baab...", 00197 ".........aaa....", 00198 "........aaab....", 00199 ".aa....baaa.....", 00200 ".aaa...aaa......", 00201 ".baaabaaab......", 00202 "..baaaaaa.......", 00203 "...baaaa........", 00204 "....baab........", 00205 "................", 00206 "................"}; 00207 00208 const char *KMPopHeadersView::mDel[19] = { 00209 "16 16 2 1", 00210 ". c None", 00211 "# c #c00000", 00212 "................", 00213 "................", 00214 "..##.......##...", 00215 "..###.....###...", 00216 "...###...###....", 00217 "....###.###.....", 00218 ".....#####......", 00219 "......###.......", 00220 ".....#####......", 00221 "....###.###.....", 00222 "...###...###....", 00223 "..###.....###...", 00224 "..##.......##...", 00225 "................", 00226 "................", 00227 "................"}; 00228 00229 00235 KMPopHeadersViewItem::KMPopHeadersViewItem(KMPopHeadersView *aParent, KMPopFilterAction aAction) 00236 : TDEListViewItem(aParent) 00237 { 00238 mParent = aParent; 00239 mAction = NoAction; 00240 00241 setPixmap(mParent->mapToColumn(Delete), TQPixmap(KMPopHeadersView::mUnchecked)); 00242 setPixmap(mParent->mapToColumn(Down), TQPixmap(KMPopHeadersView::mUnchecked)); 00243 setPixmap(mParent->mapToColumn(Later), TQPixmap(KMPopHeadersView::mUnchecked)); 00244 00245 setAction( aAction ); 00246 } 00247 00248 KMPopHeadersViewItem::~KMPopHeadersViewItem() 00249 { 00250 } 00251 00252 void KMPopHeadersViewItem::setAction(KMPopFilterAction aAction) 00253 { 00254 if(aAction != NoAction && aAction!=mAction) 00255 { 00256 if ( mAction!=NoAction ) setPixmap(mParent->mapToColumn(mAction), TQPixmap(KMPopHeadersView::mUnchecked)); 00257 setPixmap(mParent->mapToColumn(aAction), TQPixmap(KMPopHeadersView::mChecked)); 00258 mAction=aAction; 00259 } 00260 } 00261 00262 void KMPopHeadersViewItem::paintFocus(TQPainter *, const TQColorGroup &, const TQRect &) 00263 { 00264 } 00265 00266 TQString KMPopHeadersViewItem::key(int col, bool) const 00267 { 00268 if (col == 3) return KMMsgBase::skipKeyword(text(col).lower()); 00269 if (col == 6) return text(8); 00270 if (col == 7) 00271 return text(col).rightJustify( 10, '0', false); 00272 return text(col); 00273 } 00274 00280 KMPopFilterCnfrmDlg::KMPopFilterCnfrmDlg(TQPtrList<KMPopHeaders> *aHeaders, const TQString &aAccount, bool aShowLaterMsgs, TQWidget *aParent, const char *aName) 00281 : KDialogBase(aParent, aName, true, i18n("POP Filter"), Ok | Help, Ok, false) 00282 { 00283 unsigned int rulesetCount = 0; 00284 //mHeaders = aHeaders; 00285 mShowLaterMsgs = aShowLaterMsgs; 00286 mLowerBoxVisible = false; 00287 00288 TQWidget *w = new TQWidget(this); 00289 setMainWidget(w); 00290 00291 TQVBoxLayout *vbl = new TQVBoxLayout(w, 0, spacingHint()); 00292 00293 TQLabel *l = new TQLabel(i18n("Messages to filter found on POP Account: <b>%1</b><p>" 00294 "The messages shown exceed the maximum size limit you defined for this account.<br>You can select " 00295 "what you want to do with them by checking the appropriate button.").arg(aAccount), w); 00296 vbl->addWidget(l); 00297 00298 TQVGroupBox *upperBox = new TQVGroupBox(i18n("Messages Exceeding Size"), w); 00299 upperBox->hide(); 00300 KMPopHeadersView *lv = new KMPopHeadersView(upperBox, this); 00301 vbl->addWidget(upperBox); 00302 00303 TQVGroupBox *lowerBox = new TQVGroupBox(i18n("Ruleset Filtered Messages: none"), w); 00304 TQString checkBoxText((aShowLaterMsgs)? 00305 i18n("Show messages matched by a ruleset and tagged 'Download' or 'Delete'"): 00306 i18n("Show messages matched by a filter ruleset")); 00307 TQCheckBox* cb = new TQCheckBox(checkBoxText, lowerBox); 00308 cb->setEnabled(false); 00309 mFilteredHeaders = new KMPopHeadersView(lowerBox, this); 00310 mFilteredHeaders->hide(); 00311 vbl->addWidget(lowerBox); 00312 00313 mFilteredHeaders->header()->setResizeEnabled(false, 8); 00314 mFilteredHeaders->setColumnWidth(8, 0); 00315 00316 // fill the listviews with data from the headers 00317 KMPopHeaders *headers; 00318 for(headers = aHeaders->first(); headers; headers = aHeaders->next()) 00319 { 00320 KMPopHeadersViewItem *lvi = 0; 00321 00322 if(headers->ruleMatched()) 00323 { 00324 if(aShowLaterMsgs && headers->action() == Later) 00325 { 00326 // insert messages tagged 'later' only 00327 lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action()); 00328 mFilteredHeaders->show(); 00329 mLowerBoxVisible = true; 00330 } 00331 else if(aShowLaterMsgs) 00332 { 00333 // enable checkbox to show 'delete' and 'download' msgs 00334 // but don't insert them into the listview yet 00335 mDDLList.append(headers); 00336 cb->setEnabled(true); 00337 } 00338 else if(!aShowLaterMsgs) 00339 { 00340 // insert all messaged tagged by a ruleset, enable 00341 // the checkbox, but don't show the listview yet 00342 lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action()); 00343 cb->setEnabled(true); 00344 } 00345 rulesetCount++; 00346 } 00347 else 00348 { 00349 // insert all messages not tagged by a ruleset 00350 // into the upper listview 00351 lvi = new KMPopHeadersViewItem(lv, headers->action()); 00352 upperBox->show(); 00353 } 00354 00355 if(lvi) 00356 { 00357 mItemMap[lvi] = headers; 00358 setupLVI(lvi,headers->header()); 00359 } 00360 } 00361 00362 if(rulesetCount) 00363 lowerBox->setTitle(i18n("Ruleset Filtered Messages: %1").arg(rulesetCount)); 00364 00365 // connect signals and slots 00366 connect(lv, TQT_SIGNAL(pressed(TQListViewItem*, const TQPoint&, int)), 00367 this, TQT_SLOT(slotPressed(TQListViewItem*, const TQPoint&, int))); 00368 connect(mFilteredHeaders, TQT_SIGNAL(pressed(TQListViewItem*, const TQPoint&, int)), 00369 this, TQT_SLOT(slotPressed(TQListViewItem*, const TQPoint&, int))); 00370 connect(cb, TQT_SIGNAL(toggled(bool)), 00371 this, TQT_SLOT(slotToggled(bool))); 00372 00373 adjustSize(); 00374 TQTimer::singleShot(0, this, TQT_SLOT(slotUpdateMinimumSize())); 00375 } 00376 00377 KMPopFilterCnfrmDlg::~KMPopFilterCnfrmDlg() 00378 { 00379 } 00380 00381 void KMPopFilterCnfrmDlg::setupLVI(KMPopHeadersViewItem *lvi, KMMessage *msg) 00382 { 00383 // set the subject 00384 TQString tmp = msg->subject(); 00385 if(tmp.isEmpty()) 00386 tmp = i18n("no subject"); 00387 lvi->setText(3, tmp); 00388 00389 // set the sender 00390 tmp = msg->fromStrip(); 00391 if(tmp.isEmpty()) 00392 tmp = i18n("unknown"); 00393 lvi->setText(4, tmp); 00394 00395 // set the receiver 00396 tmp = msg->toStrip(); 00397 if(tmp.isEmpty()) 00398 tmp = i18n("unknown"); 00399 lvi->setText(5, tmp); 00400 00401 // set the date 00402 lvi->setText(6, KMime::DateFormatter::formatDate( KMime::DateFormatter::Fancy, msg->date() ) ); 00403 // set the size 00404 lvi->setText(7, TDEIO::convertSize(msg->msgLength())); 00405 // Date for sorting 00406 lvi->setText(8, msg->dateIsoStr()); 00407 } 00408 00409 void KMPopFilterCnfrmDlg::setAction(TQListViewItem *aItem, KMPopFilterAction aAction) 00410 { 00411 mItemMap[aItem]->setAction(aAction); 00412 } 00419 void KMPopFilterCnfrmDlg::slotPressed(TQListViewItem *aItem, const TQPoint &, int aColumn) 00420 { 00421 if ( aColumn>=0 && aColumn<NoAction ) setAction(aItem,KMPopHeadersView::mapToAction(aColumn)); 00422 } 00423 00424 void KMPopFilterCnfrmDlg::slotToggled(bool aOn) 00425 { 00426 if(aOn) 00427 { 00428 if(mShowLaterMsgs) 00429 { 00430 // show download and delete msgs in the list view too 00431 for(KMPopHeaders* headers = mDDLList.first(); headers; headers = mDDLList.next()) 00432 { 00433 KMPopHeadersViewItem *lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action()); 00434 mItemMap[lvi] = headers; 00435 mDelList.append(lvi); 00436 setupLVI(lvi,headers->header()); 00437 } 00438 } 00439 00440 if(!mLowerBoxVisible) 00441 { 00442 mFilteredHeaders->show(); 00443 } 00444 } 00445 else 00446 { 00447 if(mShowLaterMsgs) 00448 { 00449 // delete download and delete msgs from the lower listview 00450 for(KMPopHeadersViewItem* item = mDelList.first(); item; item = mDelList.next()) 00451 { 00452 mFilteredHeaders->takeItem(item); 00453 } 00454 mDelList.clear(); 00455 } 00456 00457 if(!mLowerBoxVisible) 00458 { 00459 mFilteredHeaders->hide(); 00460 } 00461 } 00462 TQTimer::singleShot(0, this, TQT_SLOT(slotUpdateMinimumSize())); 00463 } 00464 00465 void KMPopFilterCnfrmDlg::slotUpdateMinimumSize() 00466 { 00467 mainWidget()->setMinimumSize(mainWidget()->sizeHint()); 00468 } 00469 00470 #include "kmpopfiltercnfrmdlg.moc"