Diffstat (limited to 'noncore/net/mail/accountview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/accountview.cpp | 818 |
1 files changed, 5 insertions, 813 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 3048e49..d9792d4 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp | |||
@@ -1,565 +1,12 @@ | |||
1 | #include "accountview.h" | 1 | #include "accountview.h" |
2 | #include <libmailwrapper/mailtypes.h> | 2 | #include "accountitem.h" |
3 | #include <libmailwrapper/abstractmail.h> | ||
4 | #include "defines.h" | ||
5 | #include "newmaildir.h" | ||
6 | #include "selectstore.h" | 3 | #include "selectstore.h" |
7 | #include <qmessagebox.h> | 4 | #include <qmessagebox.h> |
8 | #include <qpopupmenu.h> | 5 | #include <qpopupmenu.h> |
6 | #include <libmailwrapper/settings.h> | ||
7 | #include <libmailwrapper/mailwrapper.h> | ||
8 | #include <libmailwrapper/mailtypes.h> | ||
9 | #include <libmailwrapper/abstractmail.h> | ||
9 | 10 | ||
10 | #define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} | ||
11 | /** | ||
12 | * POP3 Account stuff | ||
13 | */ | ||
14 | POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) | ||
15 | : AccountViewItem( parent ) | ||
16 | { | ||
17 | account = a; | ||
18 | wrapper = AbstractMail::getWrapper( account ); | ||
19 | SETPIX(PIXMAP_POP3FOLDER); | ||
20 | #if 0 | ||
21 | if (!account->getOffline()) { | ||
22 | setPixmap( 0, ); | ||
23 | } else { | ||
24 | setPixmap( 0, PIXMAP_OFFLINE ); | ||
25 | } | ||
26 | #endif | ||
27 | setText( 0, account->getAccountName() ); | ||
28 | setOpen( true ); | ||
29 | } | ||
30 | |||
31 | POP3viewItem::~POP3viewItem() | ||
32 | { | ||
33 | delete wrapper; | ||
34 | } | ||
35 | |||
36 | AbstractMail *POP3viewItem::getWrapper() | ||
37 | { | ||
38 | return wrapper; | ||
39 | } | ||
40 | |||
41 | void POP3viewItem::refresh( QList<RecMail> & ) | ||
42 | { | ||
43 | refresh(); | ||
44 | } | ||
45 | |||
46 | void POP3viewItem::refresh() | ||
47 | { | ||
48 | if (account->getOffline()) return; | ||
49 | QList<Folder> *folders = wrapper->listFolders(); | ||
50 | QListViewItem *child = firstChild(); | ||
51 | while ( child ) { | ||
52 | QListViewItem *tmp = child; | ||
53 | child = child->nextSibling(); | ||
54 | delete tmp; | ||
55 | } | ||
56 | Folder *it; | ||
57 | QListViewItem*item = 0; | ||
58 | for ( it = folders->first(); it; it = folders->next() ) { | ||
59 | item = new POP3folderItem( it, this , item ); | ||
60 | item->setSelectable(it->may_select()); | ||
61 | } | ||
62 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
63 | folders->setAutoDelete(false); | ||
64 | delete folders; | ||
65 | } | ||
66 | |||
67 | RecBody POP3viewItem::fetchBody( const RecMail &mail ) | ||
68 | { | ||
69 | qDebug( "POP3 fetchBody" ); | ||
70 | return wrapper->fetchBody( mail ); | ||
71 | } | ||
72 | |||
73 | QPopupMenu * POP3viewItem::getContextMenu() | ||
74 | { | ||
75 | QPopupMenu *m = new QPopupMenu(0); | ||
76 | if (m) { | ||
77 | if (!account->getOffline()) { | ||
78 | m->insertItem(QObject::tr("Disconnect",contextName),0); | ||
79 | m->insertItem(QObject::tr("Set offline",contextName),1); | ||
80 | } else { | ||
81 | m->insertItem(QObject::tr("Set online",contextName),1); | ||
82 | } | ||
83 | } | ||
84 | return m; | ||
85 | } | ||
86 | |||
87 | void POP3viewItem::disconnect() | ||
88 | { | ||
89 | QListViewItem *child = firstChild(); | ||
90 | while ( child ) { | ||
91 | QListViewItem *tmp = child; | ||
92 | child = child->nextSibling(); | ||
93 | delete tmp; | ||
94 | } | ||
95 | wrapper->logout(); | ||
96 | } | ||
97 | |||
98 | void POP3viewItem::setOnOffline() | ||
99 | { | ||
100 | if (!account->getOffline()) { | ||
101 | disconnect(); | ||
102 | } | ||
103 | account->setOffline(!account->getOffline()); | ||
104 | account->save(); | ||
105 | SETPIX(PIXMAP_POP3FOLDER); | ||
106 | refresh(); | ||
107 | } | ||
108 | |||
109 | void POP3viewItem::contextMenuSelected(int which) | ||
110 | { | ||
111 | switch (which) { | ||
112 | case 0: | ||
113 | disconnect(); | ||
114 | break; | ||
115 | case 1: | ||
116 | setOnOffline(); | ||
117 | break; | ||
118 | } | ||
119 | } | ||
120 | |||
121 | POP3folderItem::~POP3folderItem() | ||
122 | { | ||
123 | delete folder; | ||
124 | } | ||
125 | |||
126 | POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) | ||
127 | : AccountViewItem( parent,after ) | ||
128 | { | ||
129 | folder = folderInit; | ||
130 | pop3 = parent; | ||
131 | if (folder->getDisplayName().lower()!="inbox") { | ||
132 | setPixmap( 0, PIXMAP_POP3FOLDER ); | ||
133 | } else { | ||
134 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
135 | } | ||
136 | setText( 0, folder->getDisplayName() ); | ||
137 | } | ||
138 | |||
139 | void POP3folderItem::refresh(QList<RecMail>&target) | ||
140 | { | ||
141 | if (folder->may_select()) | ||
142 | pop3->getWrapper()->listMessages( folder->getName(),target ); | ||
143 | } | ||
144 | |||
145 | RecBody POP3folderItem::fetchBody(const RecMail&aMail) | ||
146 | { | ||
147 | return pop3->getWrapper()->fetchBody(aMail); | ||
148 | } | ||
149 | |||
150 | QPopupMenu * POP3folderItem::getContextMenu() | ||
151 | { | ||
152 | QPopupMenu *m = new QPopupMenu(0); | ||
153 | if (m) { | ||
154 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | ||
155 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | ||
156 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | ||
157 | } | ||
158 | return m; | ||
159 | } | ||
160 | |||
161 | void POP3folderItem::downloadMails() | ||
162 | { | ||
163 | AccountView*bl = pop3->accountView(); | ||
164 | if (!bl) return; | ||
165 | bl->downloadMails(folder,pop3->getWrapper()); | ||
166 | } | ||
167 | |||
168 | void POP3folderItem::contextMenuSelected(int which) | ||
169 | { | ||
170 | AccountView * view = (AccountView*)listView(); | ||
171 | switch (which) { | ||
172 | case 0: | ||
173 | /* must be 'cause pop3 lists are cached */ | ||
174 | pop3->getWrapper()->logout(); | ||
175 | view->refreshCurrent(); | ||
176 | break; | ||
177 | case 1: | ||
178 | deleteAllMail(pop3->getWrapper(),folder); | ||
179 | break; | ||
180 | case 2: | ||
181 | downloadMails(); | ||
182 | break; | ||
183 | default: | ||
184 | break; | ||
185 | } | ||
186 | } | ||
187 | |||
188 | /** | ||
189 | * IMAP Account stuff | ||
190 | */ | ||
191 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) | ||
192 | : AccountViewItem( parent ) | ||
193 | { | ||
194 | account = a; | ||
195 | wrapper = AbstractMail::getWrapper( account ); | ||
196 | SETPIX(PIXMAP_IMAPFOLDER); | ||
197 | setText( 0, account->getAccountName() ); | ||
198 | setOpen( true ); | ||
199 | } | ||
200 | |||
201 | IMAPviewItem::~IMAPviewItem() | ||
202 | { | ||
203 | delete wrapper; | ||
204 | } | ||
205 | |||
206 | AbstractMail *IMAPviewItem::getWrapper() | ||
207 | { | ||
208 | return wrapper; | ||
209 | } | ||
210 | |||
211 | IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start) | ||
212 | { | ||
213 | IMAPfolderItem*pitem,*sitem; | ||
214 | if (!start) pitem = (IMAPfolderItem*)firstChild(); | ||
215 | else pitem = (IMAPfolderItem*)start->firstChild(); | ||
216 | while (pitem) { | ||
217 | if (pitem->matchName(path)) { | ||
218 | break; | ||
219 | } | ||
220 | if (pitem->childCount()>0) { | ||
221 | sitem = findSubItem(path,pitem); | ||
222 | if (sitem) { | ||
223 | pitem = sitem; | ||
224 | break; | ||
225 | } | ||
226 | } | ||
227 | pitem=(IMAPfolderItem*)pitem->nextSibling(); | ||
228 | } | ||
229 | return pitem; | ||
230 | } | ||
231 | |||
232 | void IMAPviewItem::refresh(QList<RecMail>&) | ||
233 | { | ||
234 | refreshFolders(false); | ||
235 | } | ||
236 | |||
237 | void IMAPviewItem::removeChilds() | ||
238 | { | ||
239 | QListViewItem *child = firstChild(); | ||
240 | while ( child ) { | ||
241 | QListViewItem *tmp = child; | ||
242 | child = child->nextSibling(); | ||
243 | delete tmp; | ||
244 | } | ||
245 | } | ||
246 | |||
247 | const QStringList&IMAPviewItem::subFolders() | ||
248 | { | ||
249 | return currentFolders; | ||
250 | } | ||
251 | |||
252 | void IMAPviewItem::refreshFolders(bool force) | ||
253 | { | ||
254 | if (childCount()>0 && force==false) return; | ||
255 | if (account->getOffline()) return; | ||
256 | |||
257 | removeChilds(); | ||
258 | currentFolders.clear(); | ||
259 | QList<Folder> *folders = wrapper->listFolders(); | ||
260 | |||
261 | Folder *it; | ||
262 | QListViewItem*item = 0; | ||
263 | QListViewItem*titem = 0; | ||
264 | QString fname,del,search; | ||
265 | int pos; | ||
266 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
267 | folders->setAutoDelete(false); | ||
268 | |||
269 | for ( it = folders->first(); it; it = folders->next() ) { | ||
270 | if (it->getDisplayName().lower()=="inbox") { | ||
271 | item = new IMAPfolderItem( it, this , item ); | ||
272 | folders->remove(it); | ||
273 | qDebug("inbox found"); | ||
274 | break; | ||
275 | } | ||
276 | } | ||
277 | for ( it = folders->first(); it; it = folders->next() ) { | ||
278 | fname = it->getDisplayName(); | ||
279 | currentFolders.append(it->getName()); | ||
280 | pos = fname.findRev(it->Separator()); | ||
281 | if (pos != -1) { | ||
282 | fname = fname.left(pos); | ||
283 | } | ||
284 | IMAPfolderItem*pitem = findSubItem(fname); | ||
285 | if (pitem) { | ||
286 | titem = item; | ||
287 | item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); | ||
288 | /* setup the short name */ | ||
289 | item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); | ||
290 | item = titem; | ||
291 | } else { | ||
292 | item = new IMAPfolderItem( it, this , item ); | ||
293 | } | ||
294 | } | ||
295 | delete folders; | ||
296 | } | ||
297 | |||
298 | QPopupMenu * IMAPviewItem::getContextMenu() | ||
299 | { | ||
300 | QPopupMenu *m = new QPopupMenu(0); | ||
301 | if (m) { | ||
302 | if (!account->getOffline()) { | ||
303 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | ||
304 | m->insertItem(QObject::tr("Create new folder",contextName),1); | ||
305 | m->insertSeparator(); | ||
306 | m->insertItem(QObject::tr("Disconnect",contextName),2); | ||
307 | m->insertItem(QObject::tr("Set offline",contextName),3); | ||
308 | } else { | ||
309 | m->insertItem(QObject::tr("Set online",contextName),3); | ||
310 | } | ||
311 | } | ||
312 | return m; | ||
313 | } | ||
314 | |||
315 | void IMAPviewItem::createNewFolder() | ||
316 | { | ||
317 | Newmdirdlg ndirdlg; | ||
318 | ndirdlg.showMaximized(); | ||
319 | if (ndirdlg.exec()) { | ||
320 | QString ndir = ndirdlg.Newdir(); | ||
321 | bool makesubs = ndirdlg.subpossible(); | ||
322 | QString delemiter = "/"; | ||
323 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); | ||
324 | if (item) { | ||
325 | delemiter = item->Delemiter(); | ||
326 | } | ||
327 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { | ||
328 | refreshFolders(true); | ||
329 | } | ||
330 | } | ||
331 | } | ||
332 | |||
333 | void IMAPviewItem::contextMenuSelected(int id) | ||
334 | { | ||
335 | qDebug("Id selected: %i",id); | ||
336 | switch (id) { | ||
337 | case 0: | ||
338 | refreshFolders(true); | ||
339 | break; | ||
340 | case 1: | ||
341 | createNewFolder(); | ||
342 | break; | ||
343 | case 2: | ||
344 | removeChilds(); | ||
345 | wrapper->logout(); | ||
346 | break; | ||
347 | case 3: | ||
348 | if (account->getOffline()==false) { | ||
349 | removeChilds(); | ||
350 | wrapper->logout(); | ||
351 | } | ||
352 | account->setOffline(!account->getOffline()); | ||
353 | account->save(); | ||
354 | SETPIX(PIXMAP_IMAPFOLDER); | ||
355 | refreshFolders(false); | ||
356 | break; | ||
357 | default: | ||
358 | break; | ||
359 | } | ||
360 | } | ||
361 | |||
362 | RecBody IMAPviewItem::fetchBody(const RecMail&) | ||
363 | { | ||
364 | return RecBody(); | ||
365 | } | ||
366 | |||
367 | bool IMAPviewItem::offline() | ||
368 | { | ||
369 | return account->getOffline(); | ||
370 | } | ||
371 | |||
372 | IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) | ||
373 | : AccountViewItem( parent , after ) | ||
374 | { | ||
375 | folder = folderInit; | ||
376 | imap = parent; | ||
377 | if (folder->getDisplayName().lower()!="inbox") { | ||
378 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | ||
379 | } else { | ||
380 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
381 | } | ||
382 | setText( 0, folder->getDisplayName() ); | ||
383 | } | ||
384 | |||
385 | IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) | ||
386 | : AccountViewItem( parent,after ) | ||
387 | { | ||
388 | folder = folderInit; | ||
389 | imap = master; | ||
390 | if (folder->getDisplayName().lower()!="inbox") { | ||
391 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | ||
392 | } else { | ||
393 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
394 | } | ||
395 | setText( 0, folder->getDisplayName() ); | ||
396 | } | ||
397 | |||
398 | IMAPfolderItem::~IMAPfolderItem() | ||
399 | { | ||
400 | delete folder; | ||
401 | } | ||
402 | |||
403 | const QString& IMAPfolderItem::Delemiter()const | ||
404 | { | ||
405 | return folder->Separator(); | ||
406 | } | ||
407 | |||
408 | bool IMAPfolderItem::matchName(const QString&name)const | ||
409 | { | ||
410 | return folder->getDisplayName()==name; | ||
411 | } | ||
412 | |||
413 | void IMAPfolderItem::refresh(QList<RecMail>&target) | ||
414 | { | ||
415 | if (folder->may_select()) { | ||
416 | imap->getWrapper()->listMessages( folder->getName(),target ); | ||
417 | } else { | ||
418 | target.clear(); | ||
419 | } | ||
420 | } | ||
421 | |||
422 | RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) | ||
423 | { | ||
424 | return imap->getWrapper()->fetchBody(aMail); | ||
425 | } | ||
426 | |||
427 | QPopupMenu * IMAPfolderItem::getContextMenu() | ||
428 | { | ||
429 | QPopupMenu *m = new QPopupMenu(0); | ||
430 | if (m) { | ||
431 | if (folder->may_select()) { | ||
432 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | ||
433 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); | ||
434 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | ||
435 | } | ||
436 | if (folder->no_inferior()==false) { | ||
437 | m->insertItem(QObject::tr("Create new subfolder",contextName),2); | ||
438 | } | ||
439 | if (folder->getDisplayName().lower()!="inbox") { | ||
440 | m->insertItem(QObject::tr("Delete folder",contextName),3); | ||
441 | } | ||
442 | } | ||
443 | return m; | ||
444 | } | ||
445 | |||
446 | void IMAPfolderItem::createNewFolder() | ||
447 | { | ||
448 | Newmdirdlg ndirdlg; | ||
449 | ndirdlg.showMaximized(); | ||
450 | if (ndirdlg.exec()) { | ||
451 | QString ndir = ndirdlg.Newdir(); | ||
452 | bool makesubs = ndirdlg.subpossible(); | ||
453 | QString delemiter = Delemiter(); | ||
454 | if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { | ||
455 | imap->refreshFolders(true); | ||
456 | } | ||
457 | } | ||
458 | } | ||
459 | |||
460 | void IMAPfolderItem::deleteFolder() | ||
461 | { | ||
462 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | ||
463 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | ||
464 | QObject::tr("Yes",contextName), | ||
465 | QObject::tr("No",contextName),QString::null,1,1); | ||
466 | qDebug("Auswahl: %i",yesno); | ||
467 | if (yesno == 0) { | ||
468 | if (imap->getWrapper()->deleteMbox(folder)) { | ||
469 | QListView*v=listView(); | ||
470 | IMAPviewItem * box = imap; | ||
471 | /* be carefull - after that this object is destroyd so don't use | ||
472 | * any member of it after that call!!*/ | ||
473 | imap->refreshFolders(true); | ||
474 | if (v) { | ||
475 | v->setSelected(box,true); | ||
476 | } | ||
477 | } | ||
478 | } | ||
479 | } | ||
480 | |||
481 | void IMAPfolderItem::downloadMails() | ||
482 | { | ||
483 | AccountView*bl = imap->accountView(); | ||
484 | if (!bl) return; | ||
485 | bl->downloadMails(folder,imap->getWrapper()); | ||
486 | } | ||
487 | |||
488 | void IMAPfolderItem::contextMenuSelected(int id) | ||
489 | { | ||
490 | qDebug("Selected id: %i",id); | ||
491 | AccountView * view = (AccountView*)listView(); | ||
492 | switch(id) { | ||
493 | case 0: | ||
494 | view->refreshCurrent(); | ||
495 | break; | ||
496 | case 1: | ||
497 | deleteAllMail(imap->getWrapper(),folder); | ||
498 | break; | ||
499 | case 2: | ||
500 | createNewFolder(); | ||
501 | break; | ||
502 | case 3: | ||
503 | deleteFolder(); | ||
504 | break; | ||
505 | case 4: | ||
506 | downloadMails(); | ||
507 | break; | ||
508 | default: | ||
509 | break; | ||
510 | } | ||
511 | } | ||
512 | |||
513 | /** | ||
514 | * Generic stuff | ||
515 | */ | ||
516 | |||
517 | const QString AccountViewItem::contextName="AccountViewItem"; | ||
518 | |||
519 | AccountViewItem::AccountViewItem( AccountView *parent ) | ||
520 | : QListViewItem( parent ) | ||
521 | { | ||
522 | m_Backlink = parent; | ||
523 | } | ||
524 | |||
525 | AccountViewItem::AccountViewItem( QListViewItem *parent) | ||
526 | : QListViewItem( parent) | ||
527 | { | ||
528 | m_Backlink = 0; | ||
529 | } | ||
530 | |||
531 | AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) | ||
532 | :QListViewItem( parent,after ) | ||
533 | { | ||
534 | m_Backlink = 0; | ||
535 | } | ||
536 | |||
537 | AccountViewItem::~AccountViewItem() | ||
538 | { | ||
539 | } | ||
540 | |||
541 | AccountView*AccountViewItem::accountView() | ||
542 | { | ||
543 | return m_Backlink; | ||
544 | } | ||
545 | |||
546 | void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder) | ||
547 | { | ||
548 | if (!wrapper) return; | ||
549 | QString fname=""; | ||
550 | if (folder) fname = folder->getDisplayName(); | ||
551 | int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), | ||
552 | QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). | ||
553 | arg(fname), | ||
554 | QObject::tr("Yes",contextName), | ||
555 | QObject::tr("No",contextName),QString::null,1,1); | ||
556 | qDebug("Auswahl: %i",yesno); | ||
557 | if (yesno == 0) { | ||
558 | if (wrapper->deleteAllMail(folder)) { | ||
559 | AccountView * view = (AccountView*)listView(); | ||
560 | if (view) view->refreshCurrent(); | ||
561 | } | ||
562 | } | ||
563 | } | ||
564 | 11 | ||
565 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | 12 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) |
@@ -570,5 +17,4 @@ AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | |||
570 | connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, | 17 | connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, |
571 | SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); | 18 | SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); |
572 | |||
573 | setSorting(0); | 19 | setSorting(0); |
574 | } | 20 | } |
@@ -702,256 +148,2 @@ void AccountView::downloadMails(Folder*fromFolder,AbstractMail*fromWrapper) | |||
702 | refreshCurrent(); | 148 | refreshCurrent(); |
703 | } | 149 | } |
704 | |||
705 | /** | ||
706 | * MH Account stuff | ||
707 | */ | ||
708 | /* MH is a little bit different - the top folder can contains messages other than in IMAP and | ||
709 | POP3 and MBOX */ | ||
710 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) | ||
711 | : AccountViewItem( parent ) | ||
712 | { | ||
713 | m_Path = aPath; | ||
714 | /* be carefull - the space within settext is wanted - thats why the string twice */ | ||
715 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); | ||
716 | setPixmap( 0, PIXMAP_LOCALFOLDER ); | ||
717 | setText( 0, " Local Folders" ); | ||
718 | setOpen( true ); | ||
719 | folder = 0; | ||
720 | } | ||
721 | |||
722 | MHviewItem::~MHviewItem() | ||
723 | { | ||
724 | delete wrapper; | ||
725 | if (folder) delete folder; | ||
726 | } | ||
727 | |||
728 | AbstractMail *MHviewItem::getWrapper() | ||
729 | { | ||
730 | return wrapper; | ||
731 | } | ||
732 | |||
733 | void MHviewItem::refresh( QList<RecMail> & target) | ||
734 | { | ||
735 | refresh(false); | ||
736 | getWrapper()->listMessages( "",target ); | ||
737 | } | ||
738 | |||
739 | void MHviewItem::removeChilds() | ||
740 | { | ||
741 | QListViewItem *child = firstChild(); | ||
742 | while ( child ) { | ||
743 | QListViewItem *tmp = child; | ||
744 | child = child->nextSibling(); | ||
745 | delete tmp; | ||
746 | } | ||
747 | } | ||
748 | |||
749 | void MHviewItem::refresh(bool force) | ||
750 | { | ||
751 | if (childCount()>0 && force==false) return; | ||
752 | removeChilds(); | ||
753 | QList<Folder> *folders = wrapper->listFolders(); | ||
754 | Folder *it; | ||
755 | MHfolderItem*item = 0; | ||
756 | MHfolderItem*pmaster = 0; | ||
757 | QString fname = ""; | ||
758 | for ( it = folders->first(); it; it = folders->next() ) { | ||
759 | fname = it->getDisplayName(); | ||
760 | /* this folder itself */ | ||
761 | if (fname=="/") { | ||
762 | folder = it; | ||
763 | continue; | ||
764 | } | ||
765 | if (pmaster) { | ||
766 | item = new MHfolderItem( it, pmaster, item, this ); | ||
767 | } else { | ||
768 | item = new MHfolderItem( it, this , item ); | ||
769 | } | ||
770 | item->setSelectable(it->may_select()); | ||
771 | } | ||
772 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
773 | folders->setAutoDelete(false); | ||
774 | delete folders; | ||
775 | } | ||
776 | |||
777 | RecBody MHviewItem::fetchBody( const RecMail &mail ) | ||
778 | { | ||
779 | qDebug( "MH fetchBody" ); | ||
780 | return wrapper->fetchBody( mail ); | ||
781 | } | ||
782 | |||
783 | QPopupMenu * MHviewItem::getContextMenu() | ||
784 | { | ||
785 | QPopupMenu *m = new QPopupMenu(0); | ||
786 | if (m) { | ||
787 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | ||
788 | m->insertItem(QObject::tr("Create new folder",contextName),1); | ||
789 | m->insertItem(QObject::tr("Delete all mails",contextName),2); | ||
790 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); | ||
791 | } | ||
792 | return m; | ||
793 | } | ||
794 | |||
795 | void MHviewItem::createFolder() | ||
796 | { | ||
797 | Newmdirdlg ndirdlg(0,0,true); | ||
798 | ndirdlg.showMaximized(); | ||
799 | if (ndirdlg.exec()) { | ||
800 | QString ndir = ndirdlg.Newdir(); | ||
801 | if (wrapper->createMbox(ndir)) { | ||
802 | refresh(true); | ||
803 | } | ||
804 | } | ||
805 | } | ||
806 | |||
807 | void MHviewItem::downloadMails() | ||
808 | { | ||
809 | AccountView*bl = accountView(); | ||
810 | if (!bl) return; | ||
811 | bl->downloadMails(folder,getWrapper()); | ||
812 | } | ||
813 | |||
814 | QStringList MHviewItem::subFolders() | ||
815 | { | ||
816 | QStringList result; | ||
817 | QListViewItem *child = firstChild(); | ||
818 | result.append("/"); | ||
819 | while ( child ) { | ||
820 | MHfolderItem *tmp = (MHfolderItem*)child; | ||
821 | child = child->nextSibling(); | ||
822 | result.append(tmp->getFolder()->getDisplayName()); | ||
823 | } | ||
824 | qDebug("Size of result: %i",result.count()); | ||
825 | return result; | ||
826 | } | ||
827 | |||
828 | void MHviewItem::contextMenuSelected(int which) | ||
829 | { | ||
830 | switch (which) { | ||
831 | case 0: | ||
832 | refresh(true); | ||
833 | break; | ||
834 | case 1: | ||
835 | createFolder(); | ||
836 | break; | ||
837 | case 2: | ||
838 | deleteAllMail(getWrapper(),folder); | ||
839 | break; | ||
840 | case 3: | ||
841 | downloadMails(); | ||
842 | break; | ||
843 | default: | ||
844 | break; | ||
845 | } | ||
846 | } | ||
847 | |||
848 | MHfolderItem::~MHfolderItem() | ||
849 | { | ||
850 | delete folder; | ||
851 | } | ||
852 | |||
853 | MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after ) | ||
854 | : AccountViewItem( parent,after ) | ||
855 | { | ||
856 | folder = folderInit; | ||
857 | mbox = parent; | ||
858 | initName(); | ||
859 | } | ||
860 | |||
861 | MHfolderItem::MHfolderItem( Folder *folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) | ||
862 | : AccountViewItem( parent,after ) | ||
863 | { | ||
864 | folder = folderInit; | ||
865 | mbox = master; | ||
866 | initName(); | ||
867 | } | ||
868 | |||
869 | void MHfolderItem::initName() | ||
870 | { | ||
871 | QString bName = folder->getDisplayName(); | ||
872 | if (bName.startsWith("/")&&bName.length()>1) { | ||
873 | bName.replace(0,1,""); | ||
874 | } | ||
875 | if (bName.lower() == "outgoing") { | ||
876 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); | ||
877 | } else if (bName.lower() == "inbox") { | ||
878 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
879 | } else { | ||
880 | setPixmap( 0, PIXMAP_MBOXFOLDER ); | ||
881 | } | ||
882 | setText( 0, bName ); | ||
883 | } | ||
884 | |||
885 | Folder*MHfolderItem::getFolder() | ||
886 | { | ||
887 | return folder; | ||
888 | } | ||
889 | |||
890 | void MHfolderItem::refresh(QList<RecMail>&target) | ||
891 | { | ||
892 | if (folder->may_select()) | ||
893 | mbox->getWrapper()->listMessages( folder->getName(),target ); | ||
894 | } | ||
895 | |||
896 | RecBody MHfolderItem::fetchBody(const RecMail&aMail) | ||
897 | { | ||
898 | return mbox->getWrapper()->fetchBody(aMail); | ||
899 | } | ||
900 | |||
901 | void MHfolderItem::deleteFolder() | ||
902 | { | ||
903 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | ||
904 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | ||
905 | QObject::tr("Yes",contextName), | ||
906 | QObject::tr("No",contextName),QString::null,1,1); | ||
907 | qDebug("Auswahl: %i",yesno); | ||
908 | if (yesno == 0) { | ||
909 | if (mbox->getWrapper()->deleteMbox(folder)) { | ||
910 | QListView*v=listView(); | ||
911 | MHviewItem * box = mbox; | ||
912 | /* be carefull - after that this object is destroyd so don't use | ||
913 | * any member of it after that call!!*/ | ||
914 | mbox->refresh(true); | ||
915 | if (v) { | ||
916 | v->setSelected(box,true); | ||
917 | } | ||
918 | } | ||
919 | } | ||
920 | } | ||
921 | |||
922 | QPopupMenu * MHfolderItem::getContextMenu() | ||
923 | { | ||
924 | QPopupMenu *m = new QPopupMenu(0); | ||
925 | if (m) { | ||
926 | m->insertItem(QObject::tr("Delete all mails",contextName),0); | ||
927 | m->insertItem(QObject::tr("Delete folder",contextName),1); | ||
928 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | ||
929 | m->insertItem(QObject::tr("Create new folder",contextName),3); | ||
930 | } | ||
931 | return m; | ||
932 | } | ||
933 | |||
934 | void MHfolderItem::downloadMails() | ||
935 | { | ||
936 | AccountView*bl = mbox->accountView(); | ||
937 | if (!bl) return; | ||
938 | bl->downloadMails(folder,mbox->getWrapper()); | ||
939 | } | ||
940 | |||
941 | void MHfolderItem::contextMenuSelected(int which) | ||
942 | { | ||
943 | switch(which) { | ||
944 | case 0: | ||
945 | deleteAllMail(mbox->getWrapper(),folder); | ||
946 | break; | ||
947 | case 1: | ||
948 | deleteFolder(); | ||
949 | break; | ||
950 | case 2: | ||
951 | downloadMails(); | ||
952 | break; | ||
953 | default: | ||
954 | break; | ||
955 | } | ||
956 | } | ||
957 | |||