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
int dateCol = addColumn(i18n(
"Date"), 120);
00042
int sizeCol = addColumn(i18n(
"Size"), 80);
00043
00044 setAllColumnsShowFocus(
true);
00045
00046 setColumnAlignment(Down, Qt::AlignHCenter);
00047 setColumnAlignment(Later, Qt::AlignHCenter);
00048 setColumnAlignment(Delete, Qt::AlignHCenter);
00049 setColumnAlignment(sizeCol, Qt::AlignRight);
00050
00051 setSorting(dateCol,
false);
00052 setShowSortIndicator(
true);
00053 header()->setResizeEnabled(
false, Down);
00054 header()->setResizeEnabled(
false, Later);
00055 header()->setResizeEnabled(
false, Delete);
00056 header()->setClickEnabled(
false, Down);
00057 header()->setClickEnabled(
false, Later);
00058 header()->setClickEnabled(
false, Delete);
00059
00060
00061 header()->setMovingEnabled(
false);
00062
00063 connect(
this, SIGNAL(pressed(QListViewItem*,
const QPoint&,
int)),
00064 SLOT(slotPressed(QListViewItem*,
const QPoint&,
int)));
00065 }
00066
00067 KMPopHeadersView::~KMPopHeadersView()
00068 {
00069 }
00070
00071
00072
void KMPopHeadersView::keyPressEvent( QKeyEvent *e )
00073 {
00074
if (e->key() == Key_Left) {
00075 KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>( selectedItem() );
00076
if (item&&mDialog) {
00077
if (item->action()) {
00078 item->setAction((KMPopFilterAction)((
int)item->action()-1));
00079 mDialog->setAction( selectedItem(), item->action());
00080 }
00081 }
00082 }
else if (e->key() == Key_Right) {
00083 KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>( selectedItem() );
00084
if (item&&mDialog) {
00085
if (item->action()<NoAction-1) {
00086 item->setAction((KMPopFilterAction)((
int)item->action()+1));
00087 mDialog->setAction( selectedItem(), item->action());
00088 }
00089 }
00090 }
else {
00091 QListView::keyPressEvent( e );
00092 }
00093 }
00094
00095
void KMPopHeadersView::slotPressed(QListViewItem* aItem,
const QPoint&,
int aColumn) {
00096
if ( !( aItem && aColumn>=0 && aColumn<NoAction ) )
return;
00097 KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>(aItem);
00098 assert( item );
00099 item->setAction(mapToAction(aColumn));
00100 }
00101
00102
const char *KMPopHeadersView::mUnchecked[26] = {
00103
"19 16 9 1",
00104
" c None",
00105
"# c #000000",
00106
". c #ffffff",
00107
"a c #4a4c4a",
00108
"b c #524c52",
00109
"c c #efefef",
00110
"e c #fff2ff",
00111
"f c #f6f2f6",
00112
"g c #fff6ff",
00113
" ",
00114
" ",
00115
" aaaa ",
00116
" ba####aa ",
00117
" a##....aac ",
00118
" a#......ec ",
00119
" a#........fc ",
00120
" a#........gc ",
00121
" a#........fc ",
00122
" b#........gc ",
00123
" a#......gc ",
00124
" age....gec ",
00125
" ccfgfgcc ",
00126
" cccc ",
00127
" ",
00128
" ",};
00129
00130
const char *KMPopHeadersView::mChecked[26] = {
00131
"19 16 9 1",
00132
" c None",
00133
"# c #000000",
00134
". c #ffffff",
00135
"a c #4a4c4a",
00136
"b c #524c52",
00137
"c c #efefef",
00138
"e c #fff2ff",
00139
"f c #f6f2f6",
00140
"g c #fff6ff",
00141
" ",
00142
" ",
00143
" aaaa ",
00144
" ba####aa ",
00145
" a##....aac ",
00146
" a#......ec ",
00147
" a#...##...fc ",
00148
" a#..####..gc ",
00149
" a#..####..fc ",
00150
" b#...##...gc ",
00151
" a#......gc ",
00152
" age....gec ",
00153
" ccfgfgcc ",
00154
" cccc ",
00155
" ",
00156
" ",};
00157
00158
const char *KMPopHeadersView::mLater[25] = {
00159
"16 16 8 1",
00160
". c None",
00161
"g c #303030",
00162
"c c #585858",
00163
"f c #a0a0a0",
00164
"b c #c0c000",
00165
"e c #dcdcdc",
00166
"a c #ffff00",
00167
"d c #ffffff",
00168
"................",
00169
"...........eaa..",
00170
"..........eaaa..",
00171
".........ebaab..",
00172
".........eaaa...",
00173
"........eaaab...",
00174
"........eaaa....",
00175
".......eaaab....",
00176
"eaae..ebaccccc..",
00177
"eaaae.eaacdedc..",
00178
"ebaaabaaabcdc...",
00179
".ebaaaaaa.fgf...",
00180
"..ebaaaa..cec...",
00181
"...ebaab.cdedc..",
00182
"........eccccc..",
00183
"................"};
00184
00185
const char *KMPopHeadersView::mDown[20] = {
00186
"16 16 3 1",
00187
". c None",
00188
"a c #008000",
00189
"b c #00c000",
00190
"................",
00191
"............aa..",
00192
"...........aaa..",
00193
"..........baab..",
00194
"..........aaa...",
00195
".........baab...",
00196
".........aaa....",
00197
"........aaab....",
00198
".aa....baaa.....",
00199
".aaa...aaa......",
00200
".baaabaaab......",
00201
"..baaaaaa.......",
00202
"...baaaa........",
00203
"....baab........",
00204
"................",
00205
"................"};
00206
00207
const char *KMPopHeadersView::mDel[19] = {
00208
"16 16 2 1",
00209
". c None",
00210
"# c #c00000",
00211
"................",
00212
"................",
00213
"..##.......##...",
00214
"..###.....###...",
00215
"...###...###....",
00216
"....###.###.....",
00217
".....#####......",
00218
"......###.......",
00219
".....#####......",
00220
"....###.###.....",
00221
"...###...###....",
00222
"..###.....###...",
00223
"..##.......##...",
00224
"................",
00225
"................",
00226
"................"};
00227
00228
00234 KMPopHeadersViewItem::KMPopHeadersViewItem(
KMPopHeadersView *aParent, KMPopFilterAction aAction)
00235 : KListViewItem(aParent)
00236 {
00237 mParent = aParent;
00238 mAction = NoAction;
00239
00240 setPixmap(mParent->mapToColumn(Delete), QPixmap(KMPopHeadersView::mUnchecked));
00241 setPixmap(mParent->mapToColumn(Down), QPixmap(KMPopHeadersView::mUnchecked));
00242 setPixmap(mParent->mapToColumn(Later), QPixmap(KMPopHeadersView::mUnchecked));
00243
00244 setAction( aAction );
00245 }
00246
00247 KMPopHeadersViewItem::~KMPopHeadersViewItem()
00248 {
00249 }
00250
00251
void KMPopHeadersViewItem::setAction(KMPopFilterAction aAction)
00252 {
00253
if(aAction != NoAction && aAction!=mAction)
00254 {
00255
if ( mAction!=NoAction ) setPixmap(mParent->mapToColumn(mAction), QPixmap(KMPopHeadersView::mUnchecked));
00256 setPixmap(mParent->mapToColumn(aAction), QPixmap(KMPopHeadersView::mChecked));
00257 mAction=aAction;
00258 }
00259 }
00260
00261
void KMPopHeadersViewItem::paintFocus(QPainter *,
const QColorGroup &,
const QRect &)
00262 {
00263 }
00264
00265 QString KMPopHeadersViewItem::key(
int col,
bool)
const
00266
{
00267
if (col == 3)
return KMMsgBase::skipKeyword(text(col).lower());
00268
if (col == 5)
return text(7);
00269
if (col == 6)
00270 {
00271 QString st = text(col);
00272
while (st.length() < 10) st =
"0" + st;
00273
return st;
00274 }
00275
return text(col);
00276 }
00277
00283 KMPopFilterCnfrmDlg::KMPopFilterCnfrmDlg(QPtrList<KMPopHeaders> *aHeaders,
const QString &aAccount,
bool aShowLaterMsgs, QWidget *aParent,
const char *aName)
00284 : KDialogBase(aParent, aName, TRUE, i18n("KMail POP Filter"), Ok | Help, Ok, FALSE)
00285 {
00286
unsigned int rulesetCount = 0;
00287
00288 mShowLaterMsgs = aShowLaterMsgs;
00289 mLowerBoxVisible =
false;
00290
00291 QWidget *w =
new QWidget(
this);
00292 setMainWidget(w);
00293
00294 QVBoxLayout *vbl =
new QVBoxLayout(w, 0, spacingHint());
00295
00296 QLabel *l =
new QLabel(i18n(
"Messages to filter found on POP Account: <b>%1</b><p>"
00297
"The messages shown exceed the maximum size limit you defined for this account.<br>You can select "
00298
"what you want to do with them by checking the appropriate button.").arg(aAccount), w);
00299 vbl->addWidget(l);
00300
00301 QVGroupBox *upperBox =
new QVGroupBox(i18n(
"Messages Exceeding Size"), w);
00302 upperBox->hide();
00303
KMPopHeadersView *lv =
new KMPopHeadersView(upperBox,
this);
00304 vbl->addWidget(upperBox);
00305
00306 QVGroupBox *lowerBox =
new QVGroupBox(i18n(
"Ruleset Filtered Messages: none"), w);
00307 QString checkBoxText((aShowLaterMsgs)?
00308 i18n(
"Show messages matched by a ruleset and tagged 'Download' or 'Delete'"):
00309 i18n(
"Show messages matched by a filter ruleset"));
00310 QCheckBox* cb =
new QCheckBox(checkBoxText, lowerBox);
00311 cb->setEnabled(
false);
00312 mFilteredHeaders =
new KMPopHeadersView(lowerBox,
this);
00313 mFilteredHeaders->hide();
00314 vbl->addWidget(lowerBox);
00315
00316 mFilteredHeaders->header()->setResizeEnabled(
false, 7);
00317 mFilteredHeaders->setColumnWidth(7, 0);
00318
00319
00320 KMPopHeaders *headers;
00321
for(headers = aHeaders->first(); headers; headers = aHeaders->next())
00322 {
00323 KMPopHeadersViewItem *lvi = 0;
00324
00325
if(headers->ruleMatched())
00326 {
00327
if(aShowLaterMsgs && headers->action() == Later)
00328 {
00329
00330 lvi =
new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
00331 mFilteredHeaders->show();
00332 mLowerBoxVisible =
true;
00333 }
00334
else if(aShowLaterMsgs)
00335 {
00336
00337
00338 mDDLList.append(headers);
00339 cb->setEnabled(
true);
00340 }
00341
else if(!aShowLaterMsgs)
00342 {
00343
00344
00345 lvi =
new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
00346 cb->setEnabled(
true);
00347 }
00348 rulesetCount++;
00349 }
00350
else
00351 {
00352
00353
00354 lvi =
new KMPopHeadersViewItem(lv, headers->action());
00355 upperBox->show();
00356 }
00357
00358
if(lvi)
00359 {
00360 mItemMap[lvi] = headers;
00361 setupLVI(lvi,headers->header());
00362 }
00363 }
00364
00365
if(rulesetCount)
00366 lowerBox->setTitle(i18n(
"Ruleset Filtered Messages: %1").arg(rulesetCount));
00367
00368
00369 connect(lv, SIGNAL(pressed(QListViewItem*,
const QPoint&,
int)),
00370
this, SLOT(slotPressed(QListViewItem*,
const QPoint&,
int)));
00371 connect(mFilteredHeaders, SIGNAL(pressed(QListViewItem*,
const QPoint&,
int)),
00372
this, SLOT(slotPressed(QListViewItem*,
const QPoint&,
int)));
00373 connect(cb, SIGNAL(toggled(
bool)),
00374
this, SLOT(slotToggled(
bool)));
00375
00376 adjustSize();
00377 QTimer::singleShot(0,
this, SLOT(slotUpdateMinimumSize()));
00378 }
00379
00380 KMPopFilterCnfrmDlg::~KMPopFilterCnfrmDlg()
00381 {
00382 }
00383
00384
void KMPopFilterCnfrmDlg::setupLVI(KMPopHeadersViewItem *lvi, KMMessage *msg)
00385 {
00386
00387 QString tmp = msg->subject();
00388
if(tmp.isEmpty())
00389 tmp = i18n(
"no subject");
00390 lvi->setText(3, tmp);
00391
00392 tmp = msg->fromStrip();
00393
if(tmp.isEmpty())
00394 tmp = i18n(
"unknown");
00395 lvi->setText(4, msg->fromStrip());
00396
00397 lvi->setText(5, KMime::DateFormatter::formatDate( KMime::DateFormatter::Fancy, msg->date() ) );
00398
00399 lvi->setText(6, KIO::convertSize(msg->msgLength()));
00400
00401 lvi->setText(7, msg->dateIsoStr());
00402 }
00403
00404
void KMPopFilterCnfrmDlg::setAction(QListViewItem *aItem, KMPopFilterAction aAction)
00405 {
00406 mItemMap[aItem]->setAction(aAction);
00407 }
00414
void KMPopFilterCnfrmDlg::slotPressed(QListViewItem *aItem,
const QPoint &,
int aColumn)
00415 {
00416
if ( aColumn>=0 && aColumn<NoAction ) setAction(aItem,KMPopHeadersView::mapToAction(aColumn));
00417 }
00418
00419
void KMPopFilterCnfrmDlg::slotToggled(
bool aOn)
00420 {
00421
if(aOn)
00422 {
00423
if(mShowLaterMsgs)
00424 {
00425
00426
for(KMPopHeaders* headers = mDDLList.first(); headers; headers = mDDLList.next())
00427 {
00428 KMPopHeadersViewItem *lvi =
new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
00429 mItemMap[lvi] = headers;
00430 mDelList.append(lvi);
00431 setupLVI(lvi,headers->header());
00432 }
00433 }
00434
00435
if(!mLowerBoxVisible)
00436 {
00437 mFilteredHeaders->show();
00438 }
00439 }
00440
else
00441 {
00442
if(mShowLaterMsgs)
00443 {
00444
00445
for(KMPopHeadersViewItem* item = mDelList.first(); item; item = mDelList.next())
00446 {
00447 mFilteredHeaders->takeItem(item);
00448 }
00449 mDelList.clear();
00450 }
00451
00452
if(!mLowerBoxVisible)
00453 {
00454 mFilteredHeaders->hide();
00455 }
00456 }
00457 QTimer::singleShot(0,
this, SLOT(slotUpdateMinimumSize()));
00458 }
00459
00460
void KMPopFilterCnfrmDlg::slotUpdateMinimumSize()
00461 {
00462 mainWidget()->setMinimumSize(mainWidget()->sizeHint());
00463 }
00464
00465
#include "kmpopfiltercnfrmdlg.moc"