00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <config.h>
00012 #include "kmpopfiltercnfrmdlg.h"
00013 #include "kmheaders.h"
00014
00015 #include <qlayout.h>
00016 #include <qlabel.h>
00017 #include <qheader.h>
00018 #include <qcheckbox.h>
00019 #include <qvgroupbox.h>
00020 #include <qtimer.h>
00021
00022 #include <klocale.h>
00023 #include <kio/global.h>
00024
00025 #include <assert.h>
00026
00029 KMPopHeadersView::KMPopHeadersView(QWidget *aParent, KMPopFilterCnfrmDlg *aDialog)
00030 : KListView(aParent)
00031 {
00032 mDialog=aDialog;
00033 int mDownIndex=addColumn(QIconSet(QPixmap(mDown)), QString::null, 24);
00034 assert( mDownIndex == Down );
00035
00036 addColumn(QIconSet(QPixmap(mLater)), QString::null, 24);
00037 addColumn(QIconSet(QPixmap(mDel)), QString::null, 24);
00038
00039 addColumn(i18n("Subject"), 180);
00040 addColumn(i18n("Sender"), 150);
00041 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, Qt::AlignHCenter);
00048 setColumnAlignment(Later, Qt::AlignHCenter);
00049 setColumnAlignment(Delete, Qt::AlignHCenter);
00050 setColumnAlignment(sizeCol, Qt::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
00062 header()->setMovingEnabled(false);
00063
00064 connect(this, SIGNAL(pressed(QListViewItem*, const QPoint&, int)),
00065 SLOT(slotPressed(QListViewItem*, const QPoint&, int)));
00066 }
00067
00068 KMPopHeadersView::~KMPopHeadersView()
00069 {
00070 }
00071
00072
00073 void KMPopHeadersView::keyPressEvent( QKeyEvent *e )
00074 {
00075 if (e->key() == Key_Left) {
00076 KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>( selectedItem() );
00077 if (item&&mDialog) {
00078 if (item->action()) {
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) {
00087 item->setAction((KMPopFilterAction)((int)item->action()+1));
00088 mDialog->setAction( selectedItem(), item->action());
00089 }
00090 }
00091 } else {
00092 QListView::keyPressEvent( e );
00093 }
00094 }
00095
00096 void KMPopHeadersView::slotPressed(QListViewItem* aItem, const QPoint&, 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 : KListViewItem(aParent)
00237 {
00238 mParent = aParent;
00239 mAction = NoAction;
00240
00241 setPixmap(mParent->mapToColumn(Delete), QPixmap(KMPopHeadersView::mUnchecked));
00242 setPixmap(mParent->mapToColumn(Down), QPixmap(KMPopHeadersView::mUnchecked));
00243 setPixmap(mParent->mapToColumn(Later), QPixmap(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), QPixmap(KMPopHeadersView::mUnchecked));
00257 setPixmap(mParent->mapToColumn(aAction), QPixmap(KMPopHeadersView::mChecked));
00258 mAction=aAction;
00259 }
00260 }
00261
00262 void KMPopHeadersViewItem::paintFocus(QPainter *, const QColorGroup &, const QRect &)
00263 {
00264 }
00265
00266 QString 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(QPtrList<KMPopHeaders> *aHeaders, const QString &aAccount, bool aShowLaterMsgs, QWidget *aParent, const char *aName)
00281 : KDialogBase(aParent, aName, true, i18n("POP Filter"), Ok | Help, Ok, false)
00282 {
00283 unsigned int rulesetCount = 0;
00284
00285 mShowLaterMsgs = aShowLaterMsgs;
00286 mLowerBoxVisible = false;
00287
00288 QWidget *w = new QWidget(this);
00289 setMainWidget(w);
00290
00291 QVBoxLayout *vbl = new QVBoxLayout(w, 0, spacingHint());
00292
00293 QLabel *l = new QLabel(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 QVGroupBox *upperBox = new QVGroupBox(i18n("Messages Exceeding Size"), w);
00299 upperBox->hide();
00300 KMPopHeadersView *lv = new KMPopHeadersView(upperBox, this);
00301 vbl->addWidget(upperBox);
00302
00303 QVGroupBox *lowerBox = new QVGroupBox(i18n("Ruleset Filtered Messages: none"), w);
00304 QString 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 QCheckBox* cb = new QCheckBox(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
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
00327 lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
00328 mFilteredHeaders->show();
00329 mLowerBoxVisible = true;
00330 }
00331 else if(aShowLaterMsgs)
00332 {
00333
00334
00335 mDDLList.append(headers);
00336 cb->setEnabled(true);
00337 }
00338 else if(!aShowLaterMsgs)
00339 {
00340
00341
00342 lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
00343 cb->setEnabled(true);
00344 }
00345 rulesetCount++;
00346 }
00347 else
00348 {
00349
00350
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
00366 connect(lv, SIGNAL(pressed(QListViewItem*, const QPoint&, int)),
00367 this, SLOT(slotPressed(QListViewItem*, const QPoint&, int)));
00368 connect(mFilteredHeaders, SIGNAL(pressed(QListViewItem*, const QPoint&, int)),
00369 this, SLOT(slotPressed(QListViewItem*, const QPoint&, int)));
00370 connect(cb, SIGNAL(toggled(bool)),
00371 this, SLOT(slotToggled(bool)));
00372
00373 adjustSize();
00374 QTimer::singleShot(0, this, SLOT(slotUpdateMinimumSize()));
00375 }
00376
00377 KMPopFilterCnfrmDlg::~KMPopFilterCnfrmDlg()
00378 {
00379 }
00380
00381 void KMPopFilterCnfrmDlg::setupLVI(KMPopHeadersViewItem *lvi, KMMessage *msg)
00382 {
00383
00384 QString tmp = msg->subject();
00385 if(tmp.isEmpty())
00386 tmp = i18n("no subject");
00387 lvi->setText(3, tmp);
00388
00389
00390 tmp = msg->fromStrip();
00391 if(tmp.isEmpty())
00392 tmp = i18n("unknown");
00393 lvi->setText(4, tmp);
00394
00395
00396 tmp = msg->toStrip();
00397 if(tmp.isEmpty())
00398 tmp = i18n("unknown");
00399 lvi->setText(5, tmp);
00400
00401
00402 lvi->setText(6, KMime::DateFormatter::formatDate( KMime::DateFormatter::Fancy, msg->date() ) );
00403
00404 lvi->setText(7, KIO::convertSize(msg->msgLength()));
00405
00406 lvi->setText(8, msg->dateIsoStr());
00407 }
00408
00409 void KMPopFilterCnfrmDlg::setAction(QListViewItem *aItem, KMPopFilterAction aAction)
00410 {
00411 mItemMap[aItem]->setAction(aAction);
00412 }
00419 void KMPopFilterCnfrmDlg::slotPressed(QListViewItem *aItem, const QPoint &, 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
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
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 QTimer::singleShot(0, this, SLOT(slotUpdateMinimumSize()));
00463 }
00464
00465 void KMPopFilterCnfrmDlg::slotUpdateMinimumSize()
00466 {
00467 mainWidget()->setMinimumSize(mainWidget()->sizeHint());
00468 }
00469
00470 #include "kmpopfiltercnfrmdlg.moc"