kmail

kmpopfiltercnfrmdlg.cpp
1 /***************************************************************************
2  kmpopheadersdlg.cpp
3  -------------------
4  begin : Mon Oct 22 2001
5  copyright : (C) 2001 by Heiko Hund
6  Thorsten Zachmann
7  email : heiko@ist.eigentlich.net
8  T.Zachmann@zagge.de
9  ***************************************************************************/
10 
11 #include <config.h>
12 #include "kmpopfiltercnfrmdlg.h"
13 #include "kmheaders.h"
14 
15 #include <tqlayout.h>
16 #include <tqlabel.h>
17 #include <tqheader.h>
18 #include <tqcheckbox.h>
19 #include <tqvgroupbox.h>
20 #include <tqtimer.h>
21 
22 #include <tdelocale.h>
23 #include <tdeio/global.h>
24 
25 #include <assert.h>
26 
29 KMPopHeadersView::KMPopHeadersView(TQWidget *aParent, KMPopFilterCnfrmDlg *aDialog)
30  : TDEListView(aParent)
31 {
32  mDialog=aDialog;
33  int mDownIndex=addColumn(TQIconSet(TQPixmap(mDown)), TQString(), 24);
34  assert( mDownIndex == Down ); //This code relies on the fact that radiobuttons are the first three columns for easier Column-Action mapping
35  //it does not necessarily be true - you could redefine mapToColumn and mapToAction to eg. shift those numbers by 1
36  addColumn(TQIconSet(TQPixmap(mLater)), TQString(), 24);
37  addColumn(TQIconSet(TQPixmap(mDel)), TQString(), 24);
38 
39  /*int subjCol =*/ addColumn(i18n("Subject"), 180);
40  /*int sendCol =*/ addColumn(i18n("Sender"), 150);
41  /*int recvCol =*/ addColumn(i18n("Receiver"), 150);
42  int dateCol = addColumn(i18n("Date"), 120);
43  int sizeCol = addColumn(i18n("Size"), 80);
44 
45  setAllColumnsShowFocus(true);
46 
47  setColumnAlignment(Down, TQt::AlignHCenter);
48  setColumnAlignment(Later, TQt::AlignHCenter);
49  setColumnAlignment(Delete, TQt::AlignHCenter);
50  setColumnAlignment(sizeCol, TQt::AlignRight);
51 
52  setSorting(dateCol, false);
53  setShowSortIndicator(true);
54  header()->setResizeEnabled(false, Down);
55  header()->setResizeEnabled(false, Later);
56  header()->setResizeEnabled(false, Delete);
57  header()->setClickEnabled(false, Down);
58  header()->setClickEnabled(false, Later);
59  header()->setClickEnabled(false, Delete);
60 
61  //we rely on fixed column order, so we forbid this
62  header()->setMovingEnabled(false);
63 
64  connect(this, TQ_SIGNAL(pressed(TQListViewItem*, const TQPoint&, int)),
65  TQ_SLOT(slotPressed(TQListViewItem*, const TQPoint&, int)));
66 }
67 
68 KMPopHeadersView::~KMPopHeadersView()
69 {
70 }
71 
72 //Handle keystrokes - Left and Right key select previous/next action correspondingly
73 void KMPopHeadersView::keyPressEvent( TQKeyEvent *e )
74 {
75  if (e->key() == Key_Left) {
76  KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>( selectedItem() );
77  if (item&&mDialog) {
78  if (item->action()) { //here we rely on the fact that the leftmost action is equal to 0!
79  item->setAction((KMPopFilterAction)((int)item->action()-1));
80  mDialog->setAction( selectedItem(), item->action());
81  }
82  }
83  } else if (e->key() == Key_Right) {
84  KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>( selectedItem() );
85  if (item&&mDialog) {
86  if (item->action()<NoAction-1) { //here we rely on the fact that right most action is one less than NoAction!
87  item->setAction((KMPopFilterAction)((int)item->action()+1));
88  mDialog->setAction( selectedItem(), item->action());
89  }
90  }
91  } else {
92  TQListView::keyPressEvent( e );
93  }
94 }
95 
96 void KMPopHeadersView::slotPressed(TQListViewItem* aItem, const TQPoint&, int aColumn) {
97  if ( !( aItem && aColumn>=0 && aColumn<NoAction ) ) return;
98  KMPopHeadersViewItem *item = dynamic_cast<KMPopHeadersViewItem*>(aItem);
99  assert( item );
100  item->setAction(mapToAction(aColumn));
101 }
102 
103 const char *KMPopHeadersView::mUnchecked[26] = {
104 "19 16 9 1",
105 " c None",
106 "# c #000000",
107 ". c #ffffff",
108 "a c #4a4c4a",
109 "b c #524c52",
110 "c c #efefef",
111 "e c #fff2ff",
112 "f c #f6f2f6",
113 "g c #fff6ff",
114 " ",
115 " ",
116 " aaaa ",
117 " ba####aa ",
118 " a##....aac ",
119 " a#......ec ",
120 " a#........fc ",
121 " a#........gc ",
122 " a#........fc ",
123 " b#........gc ",
124 " a#......gc ",
125 " age....gec ",
126 " ccfgfgcc ",
127 " cccc ",
128 " ",
129 " ",};
130 
131 const char *KMPopHeadersView::mChecked[26] = {
132 "19 16 9 1",
133 " c None",
134 "# c #000000",
135 ". c #ffffff",
136 "a c #4a4c4a",
137 "b c #524c52",
138 "c c #efefef",
139 "e c #fff2ff",
140 "f c #f6f2f6",
141 "g c #fff6ff",
142 " ",
143 " ",
144 " aaaa ",
145 " ba####aa ",
146 " a##....aac ",
147 " a#......ec ",
148 " a#...##...fc ",
149 " a#..####..gc ",
150 " a#..####..fc ",
151 " b#...##...gc ",
152 " a#......gc ",
153 " age....gec ",
154 " ccfgfgcc ",
155 " cccc ",
156 " ",
157 " ",};
158 
159 const char *KMPopHeadersView::mLater[25] = {
160 "16 16 8 1",
161 ". c None",
162 "g c #303030",
163 "c c #585858",
164 "f c #a0a0a0",
165 "b c #c0c000",
166 "e c #dcdcdc",
167 "a c #ffff00",
168 "d c #ffffff",
169 "................",
170 "...........eaa..",
171 "..........eaaa..",
172 ".........ebaab..",
173 ".........eaaa...",
174 "........eaaab...",
175 "........eaaa....",
176 ".......eaaab....",
177 "eaae..ebaccccc..",
178 "eaaae.eaacdedc..",
179 "ebaaabaaabcdc...",
180 ".ebaaaaaa.fgf...",
181 "..ebaaaa..cec...",
182 "...ebaab.cdedc..",
183 "........eccccc..",
184 "................"};
185 
186 const char *KMPopHeadersView::mDown[20] = {
187 "16 16 3 1",
188 ". c None",
189 "a c #008000",
190 "b c #00c000",
191 "................",
192 "............aa..",
193 "...........aaa..",
194 "..........baab..",
195 "..........aaa...",
196 ".........baab...",
197 ".........aaa....",
198 "........aaab....",
199 ".aa....baaa.....",
200 ".aaa...aaa......",
201 ".baaabaaab......",
202 "..baaaaaa.......",
203 "...baaaa........",
204 "....baab........",
205 "................",
206 "................"};
207 
208 const char *KMPopHeadersView::mDel[19] = {
209 "16 16 2 1",
210 ". c None",
211 "# c #c00000",
212 "................",
213 "................",
214 "..##.......##...",
215 "..###.....###...",
216 "...###...###....",
217 "....###.###.....",
218 ".....#####......",
219 "......###.......",
220 ".....#####......",
221 "....###.###.....",
222 "...###...###....",
223 "..###.....###...",
224 "..##.......##...",
225 "................",
226 "................",
227 "................"};
228 
229 
235 KMPopHeadersViewItem::KMPopHeadersViewItem(KMPopHeadersView *aParent, KMPopFilterAction aAction)
236  : TDEListViewItem(aParent)
237 {
238  mParent = aParent;
239  mAction = NoAction;
240 
241  setPixmap(mParent->mapToColumn(Delete), TQPixmap(KMPopHeadersView::mUnchecked));
242  setPixmap(mParent->mapToColumn(Down), TQPixmap(KMPopHeadersView::mUnchecked));
243  setPixmap(mParent->mapToColumn(Later), TQPixmap(KMPopHeadersView::mUnchecked));
244 
245  setAction( aAction );
246 }
247 
248 KMPopHeadersViewItem::~KMPopHeadersViewItem()
249 {
250 }
251 
252 void KMPopHeadersViewItem::setAction(KMPopFilterAction aAction)
253 {
254  if(aAction != NoAction && aAction!=mAction)
255  {
256  if ( mAction!=NoAction ) setPixmap(mParent->mapToColumn(mAction), TQPixmap(KMPopHeadersView::mUnchecked));
257  setPixmap(mParent->mapToColumn(aAction), TQPixmap(KMPopHeadersView::mChecked));
258  mAction=aAction;
259  }
260 }
261 
262 void KMPopHeadersViewItem::paintFocus(TQPainter *, const TQColorGroup &, const TQRect &)
263 {
264 }
265 
266 TQString KMPopHeadersViewItem::key(int col, bool) const
267 {
268  if (col == 3) return KMMsgBase::skipKeyword(text(col).lower());
269  if (col == 6) return text(8);
270  if (col == 7)
271  return text(col).rightJustify( 10, '0', false);
272  return text(col);
273 }
274 
280 KMPopFilterCnfrmDlg::KMPopFilterCnfrmDlg(TQPtrList<KMPopHeaders> *aHeaders, const TQString &aAccount, bool aShowLaterMsgs, TQWidget *aParent, const char *aName)
281  : KDialogBase(aParent, aName, true, i18n("POP Filter"), Ok | Help, Ok, false)
282 {
283  unsigned int rulesetCount = 0;
284  //mHeaders = aHeaders;
285  mShowLaterMsgs = aShowLaterMsgs;
286  mLowerBoxVisible = false;
287 
288  TQWidget *w = new TQWidget(this);
289  setMainWidget(w);
290 
291  TQVBoxLayout *vbl = new TQVBoxLayout(w, 0, spacingHint());
292 
293  TQLabel *l = new TQLabel(i18n("Messages to filter found on POP Account: <b>%1</b><p>"
294  "The messages shown exceed the maximum size limit you defined for this account.<br>You can select "
295  "what you want to do with them by checking the appropriate button.").arg(aAccount), w);
296  vbl->addWidget(l);
297 
298  TQVGroupBox *upperBox = new TQVGroupBox(i18n("Messages Exceeding Size"), w);
299  upperBox->hide();
300  KMPopHeadersView *lv = new KMPopHeadersView(upperBox, this);
301  vbl->addWidget(upperBox);
302 
303  TQVGroupBox *lowerBox = new TQVGroupBox(i18n("Ruleset Filtered Messages: none"), w);
304  TQString checkBoxText((aShowLaterMsgs)?
305  i18n("Show messages matched by a ruleset and tagged 'Download' or 'Delete'"):
306  i18n("Show messages matched by a filter ruleset"));
307  TQCheckBox* cb = new TQCheckBox(checkBoxText, lowerBox);
308  cb->setEnabled(false);
309  mFilteredHeaders = new KMPopHeadersView(lowerBox, this);
310  mFilteredHeaders->hide();
311  vbl->addWidget(lowerBox);
312 
313  mFilteredHeaders->header()->setResizeEnabled(false, 8);
314  mFilteredHeaders->setColumnWidth(8, 0);
315 
316  // fill the listviews with data from the headers
317  KMPopHeaders *headers;
318  for(headers = aHeaders->first(); headers; headers = aHeaders->next())
319  {
320  KMPopHeadersViewItem *lvi = 0;
321 
322  if(headers->ruleMatched())
323  {
324  if(aShowLaterMsgs && headers->action() == Later)
325  {
326  // insert messages tagged 'later' only
327  lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
328  mFilteredHeaders->show();
329  mLowerBoxVisible = true;
330  }
331  else if(aShowLaterMsgs)
332  {
333  // enable checkbox to show 'delete' and 'download' msgs
334  // but don't insert them into the listview yet
335  mDDLList.append(headers);
336  cb->setEnabled(true);
337  }
338  else if(!aShowLaterMsgs)
339  {
340  // insert all messaged tagged by a ruleset, enable
341  // the checkbox, but don't show the listview yet
342  lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
343  cb->setEnabled(true);
344  }
345  rulesetCount++;
346  }
347  else
348  {
349  // insert all messages not tagged by a ruleset
350  // into the upper listview
351  lvi = new KMPopHeadersViewItem(lv, headers->action());
352  upperBox->show();
353  }
354 
355  if(lvi)
356  {
357  mItemMap[lvi] = headers;
358  setupLVI(lvi,headers->header());
359  }
360  }
361 
362  if(rulesetCount)
363  lowerBox->setTitle(i18n("Ruleset Filtered Messages: %1").arg(rulesetCount));
364 
365  // connect signals and slots
366  connect(lv, TQ_SIGNAL(pressed(TQListViewItem*, const TQPoint&, int)),
367  this, TQ_SLOT(slotPressed(TQListViewItem*, const TQPoint&, int)));
368  connect(mFilteredHeaders, TQ_SIGNAL(pressed(TQListViewItem*, const TQPoint&, int)),
369  this, TQ_SLOT(slotPressed(TQListViewItem*, const TQPoint&, int)));
370  connect(cb, TQ_SIGNAL(toggled(bool)),
371  this, TQ_SLOT(slotToggled(bool)));
372 
373  adjustSize();
374  TQTimer::singleShot(0, this, TQ_SLOT(slotUpdateMinimumSize()));
375 }
376 
377 KMPopFilterCnfrmDlg::~KMPopFilterCnfrmDlg()
378 {
379 }
380 
381 void KMPopFilterCnfrmDlg::setupLVI(KMPopHeadersViewItem *lvi, KMMessage *msg)
382 {
383  // set the subject
384  TQString tmp = msg->subject();
385  if(tmp.isEmpty())
386  tmp = i18n("no subject");
387  lvi->setText(3, tmp);
388 
389  // set the sender
390  tmp = msg->fromStrip();
391  if(tmp.isEmpty())
392  tmp = i18n("unknown");
393  lvi->setText(4, tmp);
394 
395  // set the receiver
396  tmp = msg->toStrip();
397  if(tmp.isEmpty())
398  tmp = i18n("unknown");
399  lvi->setText(5, tmp);
400 
401  // set the date
402  lvi->setText(6, KMime::DateFormatter::formatDate( KMime::DateFormatter::Fancy, msg->date() ) );
403  // set the size
404  lvi->setText(7, TDEIO::convertSize(msg->msgLength()));
405  // Date for sorting
406  lvi->setText(8, msg->dateIsoStr());
407 }
408 
409 void KMPopFilterCnfrmDlg::setAction(TQListViewItem *aItem, KMPopFilterAction aAction)
410 {
411  mItemMap[aItem]->setAction(aAction);
412 }
419 void KMPopFilterCnfrmDlg::slotPressed(TQListViewItem *aItem, const TQPoint &, int aColumn)
420 {
421  if ( aColumn>=0 && aColumn<NoAction ) setAction(aItem,KMPopHeadersView::mapToAction(aColumn));
422 }
423 
424 void KMPopFilterCnfrmDlg::slotToggled(bool aOn)
425 {
426  if(aOn)
427  {
428  if(mShowLaterMsgs)
429  {
430  // show download and delete msgs in the list view too
431  for(KMPopHeaders* headers = mDDLList.first(); headers; headers = mDDLList.next())
432  {
433  KMPopHeadersViewItem *lvi = new KMPopHeadersViewItem(mFilteredHeaders, headers->action());
434  mItemMap[lvi] = headers;
435  mDelList.append(lvi);
436  setupLVI(lvi,headers->header());
437  }
438  }
439 
440  if(!mLowerBoxVisible)
441  {
442  mFilteredHeaders->show();
443  }
444  }
445  else
446  {
447  if(mShowLaterMsgs)
448  {
449  // delete download and delete msgs from the lower listview
450  for(KMPopHeadersViewItem* item = mDelList.first(); item; item = mDelList.next())
451  {
452  mFilteredHeaders->takeItem(item);
453  }
454  mDelList.clear();
455  }
456 
457  if(!mLowerBoxVisible)
458  {
459  mFilteredHeaders->hide();
460  }
461  }
462  TQTimer::singleShot(0, this, TQ_SLOT(slotUpdateMinimumSize()));
463 }
464 
465 void KMPopFilterCnfrmDlg::slotUpdateMinimumSize()
466 {
467  mainWidget()->setMinimumSize(mainWidget()->sizeHint());
468 }
469 
470 #include "kmpopfiltercnfrmdlg.moc"
This is a Mime Message.
Definition: kmmessage.h:68
TQString subject() const
Get or set the 'Subject' header field.
Definition: kmmessage.cpp:2049
size_t msgLength() const
Unlike the above function this works also, if the message is not in a folder.
Definition: kmmessage.h:817
KMPopHeadersView(TQWidget *aParent=0, KMPopFilterCnfrmDlg *aDialog=0)
view
@ Ok
The user rights/ACL have been fetched from the server sucessfully.
Definition: acljobs.h:66