summaryrefslogtreecommitdiffabout
path: root/kmicromail/accountitem.cpp
authorzautrix <zautrix>2004-07-03 16:33:12 (UTC)
committer zautrix <zautrix>2004-07-03 16:33:12 (UTC)
commite3b89230f065c48c84b48c88edb6eb088374c487 (patch) (unidiff)
tree162ea2ef909a6f82ccfcedf45d80d6c821174912 /kmicromail/accountitem.cpp
parent2dd6ac0b2d24c91d35ce674a6c26351352df2b15 (diff)
downloadkdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.zip
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.gz
kdepimpi-e3b89230f065c48c84b48c88edb6eb088374c487.tar.bz2
Initial revision
Diffstat (limited to 'kmicromail/accountitem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/accountitem.cpp1140
1 files changed, 1140 insertions, 0 deletions
diff --git a/kmicromail/accountitem.cpp b/kmicromail/accountitem.cpp
new file mode 100644
index 0000000..d0321ef
--- a/dev/null
+++ b/kmicromail/accountitem.cpp
@@ -0,0 +1,1140 @@
1
2#include "accountitem.h"
3#include "accountview.h"
4#include "newmaildir.h"
5#include "nntpgroupsdlg.h"
6#include "defines.h"
7
8#include <libmailwrapper/mailtypes.h>
9#include <libmailwrapper/abstractmail.h>
10#include <libmailwrapper/mailwrapper.h>
11/* OPIE */
12//#include <qpe/qpeapplication.h>
13
14/* QT */
15#include <qpopupmenu.h>
16#include <qmessagebox.h>
17#include <kiconloader.h>
18
19using namespace Opie::Core;
20#define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );}
21/**
22 * POP3 Account stuff
23 */
24POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent )
25 : AccountViewItem( parent )
26{
27 account = a;
28 wrapper = AbstractMail::getWrapper( account );
29 SETPIX(PIXMAP_POP3FOLDER);
30#if 0
31 if (!account->getOffline())
32 {
33 setPixmap( 0, );
34 }
35 else
36 {
37 setPixmap( 0, PIXMAP_OFFLINE );
38 }
39#endif
40 setText( 0, account->getAccountName() );
41 setOpen( true );
42}
43
44POP3viewItem::~POP3viewItem()
45{
46 delete wrapper;
47}
48
49AbstractMail *POP3viewItem::getWrapper()
50{
51 return wrapper;
52}
53
54void POP3viewItem::refresh(QValueList<Opie::Core::OSmartPointer<RecMail> > & )
55{
56 refresh();
57}
58
59void POP3viewItem::refresh()
60{
61 if (account->getOffline()) return;
62 QValueList<FolderP> *folders = wrapper->listFolders();
63 QListViewItem *child = firstChild();
64 while ( child )
65 {
66 QListViewItem *tmp = child;
67 child = child->nextSibling();
68 delete tmp;
69 }
70 QValueList<FolderP>::ConstIterator it;
71 QListViewItem*item = 0;
72 for ( it = folders->begin(); it!=folders->end(); ++it)
73 {
74 item = new POP3folderItem( (*it), this , item );
75 item->setSelectable( (*it)->may_select());
76 }
77 delete folders;
78}
79
80RECBODYP POP3viewItem::fetchBody( const RecMailP &mail )
81{
82
83 return wrapper->fetchBody( mail );
84}
85
86QPopupMenu * POP3viewItem::getContextMenu()
87{
88 QPopupMenu *m = new QPopupMenu(0);
89 if (m)
90 {
91 if (!account->getOffline())
92 {
93 m->insertItem(QObject::tr("Disconnect",contextName),0);
94 m->insertItem(QObject::tr("Set offline",contextName),1);
95 }
96 else
97 {
98 m->insertItem(QObject::tr("Set online",contextName),1);
99 }
100 }
101 return m;
102}
103
104void POP3viewItem::disconnect()
105{
106 QListViewItem *child = firstChild();
107 while ( child )
108 {
109 QListViewItem *tmp = child;
110 child = child->nextSibling();
111 delete tmp;
112 }
113 wrapper->logout();
114}
115
116void POP3viewItem::setOnOffline()
117{
118 if (!account->getOffline())
119 {
120 disconnect();
121 }
122 account->setOffline(!account->getOffline());
123 account->save();
124 SETPIX(PIXMAP_POP3FOLDER);
125 refresh();
126}
127
128void POP3viewItem::contextMenuSelected(int which)
129{
130 switch (which)
131 {
132 case 0:
133 disconnect();
134 break;
135 case 1:
136 setOnOffline();
137 break;
138 }
139}
140
141POP3folderItem::~POP3folderItem()
142{}
143
144POP3folderItem::POP3folderItem( const FolderP&folderInit, POP3viewItem *parent , QListViewItem*after )
145 : AccountViewItem(folderInit,parent,after )
146{
147 pop3 = parent;
148 if (folder->getDisplayName().lower()!="inbox")
149 {
150 setPixmap( 0, PIXMAP_POP3FOLDER );
151 }
152 else
153 {
154 setPixmap( 0, PIXMAP_INBOXFOLDER);
155 }
156 setText( 0, folder->getDisplayName() );
157}
158
159void POP3folderItem::refresh(QValueList<RecMailP>&target)
160{
161 if (folder->may_select())
162 pop3->getWrapper()->listMessages( folder->getName(),target );
163}
164
165RECBODYP POP3folderItem::fetchBody(const RecMailP&aMail)
166{
167 return pop3->getWrapper()->fetchBody(aMail);
168}
169
170QPopupMenu * POP3folderItem::getContextMenu()
171{
172 QPopupMenu *m = new QPopupMenu(0);
173 if (m)
174 {
175 m->insertItem(QObject::tr("Refresh header list",contextName),0);
176 m->insertItem(QObject::tr("Delete all mails",contextName),1);
177 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
178 }
179 return m;
180}
181
182void POP3folderItem::downloadMails()
183{
184 AccountView*bl = pop3->accountView();
185 if (!bl) return;
186 bl->downloadMails(folder,pop3->getWrapper());
187}
188
189void POP3folderItem::contextMenuSelected(int which)
190{
191 AccountView * view = (AccountView*)listView();
192 switch (which)
193 {
194 case 0:
195 /* must be 'cause pop3 lists are cached */
196 pop3->getWrapper()->logout();
197 view->refreshCurrent();
198 break;
199 case 1:
200 deleteAllMail(pop3->getWrapper(),folder);
201 break;
202 case 2:
203 downloadMails();
204 break;
205 default:
206 break;
207 }
208}
209
210/**
211 * NNTP Account stuff
212 */
213NNTPviewItem::NNTPviewItem( NNTPaccount *a, AccountView *parent )
214 : AccountViewItem( parent )
215{
216 account = a;
217 wrapper = AbstractMail::getWrapper( account );
218 //FIXME
219 SETPIX(PIXMAP_POP3FOLDER);
220#if 0
221 if (!account->getOffline())
222 {
223 setPixmap( 0, );
224 }
225 else
226 {
227 setPixmap( 0, PIXMAP_OFFLINE );
228 }
229#endif
230 setText( 0, account->getAccountName() );
231 setOpen( true );
232}
233
234NNTPviewItem::~NNTPviewItem()
235{
236 delete wrapper;
237}
238
239AbstractMail *NNTPviewItem::getWrapper()
240{
241 return wrapper;
242}
243
244void NNTPviewItem::refresh( QValueList<RecMailP> & )
245{
246 refresh();
247}
248
249void NNTPviewItem::refresh()
250{
251 if (account->getOffline()) return;
252 QValueList<FolderP> *folders = wrapper->listFolders();
253
254 QListViewItem *child = firstChild();
255 while ( child )
256 {
257 QListViewItem *tmp = child;
258 child = child->nextSibling();
259 delete tmp;
260 }
261 QValueList<FolderP>::ConstIterator it;
262 QListViewItem*item = 0;
263 for ( it = folders->begin(); it!=folders->end(); ++it)
264 {
265 item = new NNTPfolderItem( (*it), this , item );
266 item->setSelectable( (*it)->may_select());
267 }
268 delete folders;
269}
270
271RECBODYP NNTPviewItem::fetchBody( const RecMailP &mail )
272{
273
274 return wrapper->fetchBody( mail );
275}
276
277QPopupMenu * NNTPviewItem::getContextMenu()
278{
279 QPopupMenu *m = new QPopupMenu(0);
280 if (m)
281 {
282 if (!account->getOffline())
283 {
284 m->insertItem(QObject::tr("Disconnect",contextName),0);
285 m->insertItem(QObject::tr("Set offline",contextName),1);
286 m->insertItem(QObject::tr("(Un-)Subscribe groups",contextName),2);
287 }
288 else
289 {
290 m->insertItem(QObject::tr("Set online",contextName),1);
291 }
292 }
293 return m;
294}
295
296void NNTPviewItem::subscribeGroups()
297{
298 NNTPGroupsDlg dlg(account);
299 dlg.showMaximized();
300 if ( dlg.exec()== QDialog::Accepted ){
301 refresh();
302 }
303}
304
305void NNTPviewItem::disconnect()
306{
307 QListViewItem *child = firstChild();
308 while ( child )
309 {
310 QListViewItem *tmp = child;
311 child = child->nextSibling();
312 delete tmp;
313 }
314 wrapper->logout();
315}
316
317void NNTPviewItem::setOnOffline()
318{
319 if (!account->getOffline())
320 {
321 disconnect();
322 }
323 account->setOffline(!account->getOffline());
324 account->save();
325 //FIXME
326 SETPIX(PIXMAP_POP3FOLDER);
327 refresh();
328}
329
330void NNTPviewItem::contextMenuSelected(int which)
331{
332 switch (which)
333 {
334 case 0:
335 disconnect();
336 break;
337 case 1:
338 setOnOffline();
339 break;
340 case 2:
341 subscribeGroups();
342 break;
343 }
344}
345
346NNTPfolderItem::~NNTPfolderItem()
347{}
348
349NNTPfolderItem::NNTPfolderItem( const FolderP &folderInit, NNTPviewItem *parent , QListViewItem*after )
350 : AccountViewItem( folderInit, parent,after )
351{
352 nntp = parent;
353 if (folder->getDisplayName().lower()!="inbox")
354 {
355 setPixmap( 0, PIXMAP_POP3FOLDER );
356 }
357 else
358 {
359 setPixmap( 0, PIXMAP_INBOXFOLDER);
360 }
361 setText( 0, folder->getDisplayName() );
362}
363
364void NNTPfolderItem::refresh(QValueList<RecMailP>&target)
365{
366 if (folder->may_select())
367 nntp->getWrapper()->listMessages( folder->getName(),target );
368}
369
370RECBODYP NNTPfolderItem::fetchBody(const RecMailP&aMail)
371{
372 return nntp->getWrapper()->fetchBody(aMail);
373}
374
375QPopupMenu * NNTPfolderItem::getContextMenu()
376{
377 QPopupMenu *m = new QPopupMenu(0);
378 if (m)
379 {
380 m->insertItem(QObject::tr("Refresh header list",contextName),0);
381 m->insertItem(QObject::tr("Copy all postings",contextName),1);
382 }
383 return m;
384}
385
386void NNTPfolderItem::downloadMails()
387{
388 AccountView*bl = nntp->accountView();
389 if (!bl) return;
390 bl->downloadMails(folder,nntp->getWrapper());
391}
392
393void NNTPfolderItem::contextMenuSelected(int which)
394{
395 AccountView * view = (AccountView*)listView();
396 switch (which)
397 {
398 case 0:
399 /* must be 'cause pop3 lists are cached */
400 nntp->getWrapper()->logout();
401 view->refreshCurrent();
402 break;
403 case 1:
404 downloadMails();
405 break;
406 default:
407 break;
408 }
409}
410
411/**
412 * IMAP Account stuff
413 */
414IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent )
415 : AccountViewItem( parent )
416{
417 account = a;
418 wrapper = AbstractMail::getWrapper( account );
419 SETPIX(PIXMAP_IMAPFOLDER);
420 setText( 0, account->getAccountName() );
421 setOpen( true );
422}
423
424IMAPviewItem::~IMAPviewItem()
425{
426 delete wrapper;
427}
428
429AbstractMail *IMAPviewItem::getWrapper()
430{
431 return wrapper;
432}
433
434void IMAPviewItem::refresh(QValueList<RecMailP>&)
435{
436 refreshFolders(false);
437}
438
439const QStringList&IMAPviewItem::subFolders()
440{
441 return currentFolders;
442}
443
444void IMAPviewItem::refreshFolders(bool force)
445{
446 if (childCount()>0 && force==false) return;
447 if (account->getOffline()) return;
448
449 removeChilds();
450 currentFolders.clear();
451 QValueList<FolderP> * folders = wrapper->listFolders();
452
453 QValueList<FolderP>::Iterator it;
454 QListViewItem*item = 0;
455 QListViewItem*titem = 0;
456 QString fname,del,search;
457 int pos;
458
459 for ( it = folders->begin(); it!=folders->end(); ++it)
460 {
461 if ((*it)->getDisplayName().lower()=="inbox")
462 {
463 item = new IMAPfolderItem( (*it), this , item );
464 folders->remove(it);
465 break;
466 }
467 }
468 for ( it = folders->begin(); it!=folders->end(); ++it)
469 {
470 fname = (*it)->getDisplayName();
471 currentFolders.append((*it)->getName());
472 pos = fname.findRev((*it)->Separator());
473 if (pos != -1)
474 {
475 fname = fname.left(pos);
476 }
477 IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname);
478 if (pitem)
479 {
480 titem = item;
481 item = new IMAPfolderItem( (*it),pitem,pitem->firstChild(),this);
482 /* setup the short name */
483 item->setText(0,(*it)->getDisplayName().right((*it)->getDisplayName().length()-pos-1));
484 item = titem;
485 }
486 else
487 {
488 item = new IMAPfolderItem( (*it), this , item );
489 }
490 }
491 delete folders;
492}
493
494QPopupMenu * IMAPviewItem::getContextMenu()
495{
496 QPopupMenu *m = new QPopupMenu(0);
497 if (m)
498 {
499 if (!account->getOffline())
500 {
501 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
502 m->insertItem(QObject::tr("Create new folder",contextName),1);
503 m->insertSeparator();
504 m->insertItem(QObject::tr("Disconnect",contextName),2);
505 m->insertItem(QObject::tr("Set offline",contextName),3);
506 }
507 else
508 {
509 m->insertItem(QObject::tr("Set online",contextName),3);
510 }
511 }
512 return m;
513}
514
515void IMAPviewItem::createNewFolder()
516{
517 Newmdirdlg ndirdlg;
518
519 ndirdlg.showMaximized();
520 if ( ndirdlg.exec() )
521 {
522 QString ndir = ndirdlg.Newdir();
523 bool makesubs = ndirdlg.subpossible();
524 QString delemiter = "/";
525 IMAPfolderItem*item = (IMAPfolderItem*)firstChild();
526 if (item)
527 {
528 delemiter = item->Delemiter();
529 }
530 if (wrapper->createMbox(ndir,0,delemiter,makesubs))
531 {
532 refreshFolders(true);
533 }
534 }
535}
536
537void IMAPviewItem::contextMenuSelected(int id)
538{
539
540 switch (id)
541 {
542 case 0:
543 refreshFolders(true);
544 break;
545 case 1:
546 createNewFolder();
547 break;
548 case 2:
549 removeChilds();
550 wrapper->logout();
551 break;
552 case 3:
553 if (account->getOffline()==false)
554 {
555 removeChilds();
556 wrapper->logout();
557 }
558 account->setOffline(!account->getOffline());
559 account->save();
560 SETPIX(PIXMAP_IMAPFOLDER);
561 refreshFolders(false);
562 break;
563 default:
564 break;
565 }
566}
567
568RECBODYP IMAPviewItem::fetchBody(const RecMailP&)
569{
570 return new RecBody();
571}
572
573bool IMAPviewItem::offline()
574{
575 return account->getOffline();
576}
577
578IMAPfolderItem::IMAPfolderItem( const FolderP& folderInit, IMAPviewItem *parent , QListViewItem*after )
579 : AccountViewItem( folderInit, parent , after )
580{
581 imap = parent;
582 if (folder->getDisplayName().lower()!="inbox")
583 {
584 setPixmap( 0, PIXMAP_IMAPFOLDER );
585 }
586 else
587 {
588 setPixmap( 0, PIXMAP_INBOXFOLDER);
589 }
590 setText( 0, folder->getDisplayName() );
591}
592
593IMAPfolderItem::IMAPfolderItem(const FolderP &folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master )
594 : AccountViewItem(folderInit, parent,after )
595{
596 imap = master;
597 if (folder->getDisplayName().lower()!="inbox")
598 {
599 setPixmap( 0, PIXMAP_IMAPFOLDER );
600 }
601 else
602 {
603 setPixmap( 0, PIXMAP_INBOXFOLDER);
604 }
605 setText( 0, folder->getDisplayName() );
606}
607
608IMAPfolderItem::~IMAPfolderItem()
609{}
610
611const QString& IMAPfolderItem::Delemiter()const
612{
613 return folder->Separator();
614}
615
616void IMAPfolderItem::refresh(QValueList<RecMailP>&target)
617{
618 if (folder->may_select())
619 {
620 imap->getWrapper()->listMessages( folder->getName(),target );
621 }
622 else
623 {
624 target.clear();
625 }
626}
627
628RECBODYP IMAPfolderItem::fetchBody(const RecMailP&aMail)
629{
630 return imap->getWrapper()->fetchBody(aMail);
631}
632
633QPopupMenu * IMAPfolderItem::getContextMenu()
634{
635 QPopupMenu *m = new QPopupMenu(0);
636 if (m)
637 {
638 if (folder->may_select())
639 {
640 m->insertItem(QObject::tr("Refresh header list",contextName),0);
641 m->insertItem(QObject::tr("Move/Copie all mails",contextName),4);
642 m->insertItem(QObject::tr("Delete all mails",contextName),1);
643 }
644 if (folder->no_inferior()==false)
645 {
646 m->insertItem(QObject::tr("Create new subfolder",contextName),2);
647 }
648 if (folder->getDisplayName().lower()!="inbox")
649 {
650 m->insertItem(QObject::tr("Delete folder",contextName),3);
651 }
652 }
653 return m;
654}
655
656void IMAPfolderItem::createNewFolder()
657{
658 Newmdirdlg ndirdlg;
659 ndirdlg.showMaximized();
660 if ( ndirdlg.exec() )
661 {
662 QString ndir = ndirdlg.Newdir();
663 bool makesubs = ndirdlg.subpossible();
664 QString delemiter = Delemiter();
665 if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs))
666 {
667 imap->refreshFolders(true);
668 }
669 }
670}
671
672void IMAPfolderItem::deleteFolder()
673{
674 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
675 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
676 QObject::tr("Yes",contextName),
677 QObject::tr("No",contextName),QString::null,1,1);
678
679 if (yesno == 0)
680 {
681 if (imap->getWrapper()->deleteMbox(folder))
682 {
683 QListView*v=listView();
684 IMAPviewItem * box = imap;
685 /* be carefull - after that this object is destroyd so don't use
686 * any member of it after that call!!*/
687 imap->refreshFolders(true);
688 if (v)
689 {
690 v->setSelected(box,true);
691 }
692 }
693 }
694}
695
696void IMAPfolderItem::downloadMails()
697{
698 AccountView*bl = imap->accountView();
699 if (!bl) return;
700 bl->downloadMails(folder,imap->getWrapper());
701}
702
703void IMAPfolderItem::contextMenuSelected(int id)
704{
705
706 AccountView * view = (AccountView*)listView();
707 switch(id)
708 {
709 case 0:
710 view->refreshCurrent();
711 break;
712 case 1:
713 deleteAllMail(imap->getWrapper(),folder);
714 break;
715 case 2:
716 createNewFolder();
717 break;
718 case 3:
719 deleteFolder();
720 break;
721 case 4:
722 downloadMails();
723 break;
724 default:
725 break;
726 }
727}
728
729/**
730 * MH Account stuff
731 */
732/* MH is a little bit different - the top folder can contains messages other than in IMAP and
733 POP3 and MBOX */
734MHviewItem::MHviewItem( const QString&aPath, AccountView *parent )
735 : AccountViewItem( parent )
736{
737 m_Path = aPath;
738 /* be carefull - the space within settext is wanted - thats why the string twice */
739 wrapper = AbstractMail::getWrapper( m_Path,"Local Folders");
740 setPixmap( 0, PIXMAP_LOCALFOLDER );
741 setText( 0, " Local Folders" );
742 setOpen( true );
743 folder = 0;
744}
745
746MHviewItem::~MHviewItem()
747{
748 delete wrapper;
749}
750
751AbstractMail *MHviewItem::getWrapper()
752{
753 return wrapper;
754}
755
756void MHviewItem::refresh( QValueList<RecMailP> & target)
757{
758 refresh(false);
759 getWrapper()->listMessages( "",target );
760}
761
762void MHviewItem::refresh(bool force)
763{
764 if (childCount()>0 && force==false) return;
765 removeChilds();
766 currentFolders.clear();
767 QValueList<FolderP> *folders = wrapper->listFolders();
768 QValueList<FolderP>::ConstIterator it;
769 MHfolderItem*item = 0;
770 MHfolderItem*pmaster = 0;
771 QString fname = "";
772 int pos;
773 for ( it = folders->begin(); it!=folders->end(); ++it)
774 {
775 fname = (*it)->getDisplayName();
776 /* this folder itself */
777 if (fname=="/")
778 {
779 currentFolders.append(fname);
780 folder = (*it);
781 continue;
782 }
783 currentFolders.append(fname);
784 pos = fname.findRev("/");
785 if (pos > 0)
786 {
787 fname = fname.left(pos);
788 pmaster = (MHfolderItem*)findSubItem(fname);
789 }
790 else
791 {
792 pmaster = 0;
793 }
794 if (pmaster)
795 {
796 item = new MHfolderItem( (*it), pmaster, item, this );
797 }
798 else
799 {
800 item = new MHfolderItem( (*it), this , item );
801 }
802 item->setSelectable((*it)->may_select());
803 }
804 delete folders;
805}
806
807RECBODYP MHviewItem::fetchBody( const RecMailP &mail )
808{
809
810 return wrapper->fetchBody( mail );
811}
812
813QPopupMenu * MHviewItem::getContextMenu()
814{
815 QPopupMenu *m = new QPopupMenu(0);
816 if (m)
817 {
818 m->insertItem(QObject::tr("Refresh folder list",contextName),0);
819 m->insertItem(QObject::tr("Create new folder",contextName),1);
820 m->insertItem(QObject::tr("Delete all mails",contextName),2);
821 m->insertItem(QObject::tr("Move/Copie all mails",contextName),3);
822 }
823 return m;
824}
825
826void MHviewItem::createFolder()
827{
828 Newmdirdlg ndirdlg(0,0,true);
829 ndirdlg.showMaximized();
830 if ( ndirdlg.exec() )
831 {
832 QString ndir = ndirdlg.Newdir();
833 if (wrapper->createMbox(ndir))
834 {
835 refresh(true);
836 }
837 }
838}
839
840void MHviewItem::downloadMails()
841{
842 AccountView*bl = accountView();
843 if (!bl) return;
844 bl->downloadMails(folder,getWrapper());
845}
846
847QStringList MHviewItem::subFolders()
848{
849 return currentFolders;
850}
851
852void MHviewItem::contextMenuSelected(int which)
853{
854 switch (which)
855 {
856 case 0:
857 refresh(true);
858 break;
859 case 1:
860 createFolder();
861 break;
862 case 2:
863 deleteAllMail(getWrapper(),folder);
864 break;
865 case 3:
866 downloadMails();
867 break;
868 default:
869 break;
870 }
871}
872
873MHfolderItem::~MHfolderItem()
874{}
875
876MHfolderItem::MHfolderItem( const FolderP &folderInit, MHviewItem *parent , QListViewItem*after )
877 : AccountViewItem(folderInit, parent,after )
878{
879 mbox = parent;
880 initName();
881}
882
883MHfolderItem::MHfolderItem(const FolderP& folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master)
884 : AccountViewItem(folderInit, parent,after )
885{
886 folder = folderInit;
887 mbox = master;
888 initName();
889}
890
891void MHfolderItem::initName()
892{
893 QString bName = folder->getDisplayName();
894 if (bName.startsWith("/")&&bName.length()>1)
895 {
896 bName.replace(0,1,"");
897 }
898 int pos = bName.findRev("/");
899 if (pos > 0)
900 {
901 bName.replace(0,pos+1,"");
902 }
903 if (bName.lower() == "outgoing")
904 {
905 setPixmap( 0, PIXMAP_OUTBOXFOLDER );
906 }
907 else if (bName.lower() == "inbox")
908 {
909 setPixmap( 0, PIXMAP_INBOXFOLDER);
910 } else if (bName.lower() == "drafts") {
911 setPixmap(0, SmallIcon ("edit"));
912 } else {
913 setPixmap( 0, PIXMAP_MBOXFOLDER );
914 }
915 setText( 0, bName );
916}
917
918const FolderP&MHfolderItem::getFolder()const
919{
920 return folder;
921}
922
923void MHfolderItem::refresh(QValueList<RecMailP>&target)
924{
925 if (folder->may_select())
926 mbox->getWrapper()->listMessages( folder->getName(),target );
927}
928
929RECBODYP MHfolderItem::fetchBody(const RecMailP&aMail)
930{
931 return mbox->getWrapper()->fetchBody(aMail);
932}
933
934void MHfolderItem::deleteFolder()
935{
936 int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName),
937 QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()),
938 QObject::tr("Yes",contextName),
939 QObject::tr("No",contextName),QString::null,1,1);
940
941 if (yesno == 0)
942 {
943 if (mbox->getWrapper()->deleteMbox(folder))
944 {
945 QListView*v=listView();
946 MHviewItem * box = mbox;
947 /* be carefull - after that this object is destroyd so don't use
948 * any member of it after that call!!*/
949 mbox->refresh(true);
950 if (v)
951 {
952 v->setSelected(box,true);
953 }
954 }
955 }
956}
957
958QPopupMenu * MHfolderItem::getContextMenu()
959{
960 QPopupMenu *m = new QPopupMenu(0);
961 if (m)
962 {
963 m->insertItem(QObject::tr("Move/Copie all mails",contextName),2);
964 m->insertItem(QObject::tr("Delete all mails",contextName),0);
965 m->insertItem(QObject::tr("Create new subfolder",contextName),3);
966 m->insertItem(QObject::tr("Delete folder",contextName),1);
967 }
968 return m;
969}
970
971void MHfolderItem::downloadMails()
972{
973 AccountView*bl = mbox->accountView();
974 if (!bl) return;
975 bl->downloadMails(folder,mbox->getWrapper());
976}
977
978void MHfolderItem::createFolder()
979{
980 Newmdirdlg ndirdlg(0,0,true);
981 ndirdlg.showMaximized();
982 if (ndirdlg.exec() )
983 {
984 QString ndir = ndirdlg.Newdir();
985 if (mbox->getWrapper()->createMbox(ndir,folder))
986 {
987 QListView*v=listView();
988 MHviewItem * box = mbox;
989 /* be carefull - after that this object is destroyd so don't use
990 * any member of it after that call!!*/
991 mbox->refresh(true);
992 if (v)
993 {
994 v->setSelected(box,true);
995 }
996 }
997 }
998}
999
1000void MHfolderItem::contextMenuSelected(int which)
1001{
1002 switch(which)
1003 {
1004 case 0:
1005 deleteAllMail(mbox->getWrapper(),folder);
1006 break;
1007 case 1:
1008 deleteFolder();
1009 break;
1010 case 2:
1011 downloadMails();
1012 break;
1013 case 3:
1014 createFolder();
1015 break;
1016 default:
1017 break;
1018 }
1019}
1020
1021bool MHfolderItem::isDraftfolder()
1022{
1023 if (folder && folder->getName()==AbstractMail::defaultLocalfolder()+"/"+AbstractMail::draftFolder()) return true;
1024 return false;
1025}
1026
1027/**
1028 * Generic stuff
1029 */
1030
1031const QString AccountViewItem::contextName="AccountViewItem";
1032
1033AccountViewItem::AccountViewItem( AccountView *parent )
1034 : QListViewItem( parent )
1035{
1036 init();
1037 m_Backlink = parent;
1038}
1039
1040AccountViewItem::AccountViewItem( QListViewItem *parent)
1041 : QListViewItem( parent),folder(0)
1042{
1043 init();
1044}
1045
1046AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after )
1047 :QListViewItem( parent,after ),folder(0)
1048{
1049 init();
1050}
1051
1052AccountViewItem::AccountViewItem( const Opie::Core::OSmartPointer<Folder>&folderInit,QListViewItem *parent , QListViewItem*after )
1053 :QListViewItem( parent,after ),folder(folderInit)
1054{
1055 init();
1056}
1057
1058void AccountViewItem::init()
1059{
1060 m_Backlink = 0;
1061}
1062
1063AccountViewItem::~AccountViewItem()
1064{
1065 folder = 0;
1066}
1067
1068AccountView*AccountViewItem::accountView()
1069{
1070 return m_Backlink;
1071}
1072
1073void AccountViewItem::deleteAllMail(AbstractMail*wrapper,const FolderP&folder)
1074{
1075 if (!wrapper) return;
1076 QString fname="";
1077 if (folder) fname = folder->getDisplayName();
1078 int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName),
1079 QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName).
1080 arg(fname),
1081 QObject::tr("Yes",contextName),
1082 QObject::tr("No",contextName),QString::null,1,1);
1083
1084 if (yesno == 0)
1085 {
1086 if (wrapper->deleteAllMail(folder))
1087 {
1088 AccountView * view = (AccountView*)listView();
1089 if (view) view->refreshCurrent();
1090 }
1091 }
1092}
1093
1094void AccountViewItem::removeChilds()
1095{
1096 QListViewItem *child = firstChild();
1097 while ( child )
1098 {
1099 QListViewItem *tmp = child;
1100 child = child->nextSibling();
1101 delete tmp;
1102 }
1103}
1104
1105bool AccountViewItem::matchName(const QString&name)const
1106{
1107 if (!folder) return false;
1108 return folder->getDisplayName()==name;
1109}
1110
1111
1112AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start)
1113{
1114 AccountViewItem*pitem,*sitem;
1115 if (!start) pitem = (AccountViewItem*)firstChild();
1116 else pitem = (AccountViewItem*)start->firstChild();
1117 while (pitem)
1118 {
1119 if (pitem->matchName(path))
1120 {
1121 break;
1122 }
1123 if (pitem->childCount()>0)
1124 {
1125 sitem = findSubItem(path,pitem);
1126 if (sitem)
1127 {
1128 pitem = sitem;
1129 break;
1130 }
1131 }
1132 pitem=(AccountViewItem*)pitem->nextSibling();
1133 }
1134 return pitem;
1135}
1136
1137bool AccountViewItem::isDraftfolder()
1138{
1139 return false;
1140}