-rw-r--r-- | kmicromail/accountview.cpp | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/kmicromail/accountview.cpp b/kmicromail/accountview.cpp new file mode 100644 index 0000000..0893733 --- a/dev/null +++ b/kmicromail/accountview.cpp | |||
@@ -0,0 +1,170 @@ | |||
1 | |||
2 | #include "accountview.h" | ||
3 | #include "accountitem.h" | ||
4 | #include "selectstore.h" | ||
5 | |||
6 | #include <libmailwrapper/settings.h> | ||
7 | #include <libmailwrapper/mailwrapper.h> | ||
8 | #include <libmailwrapper/mailtypes.h> | ||
9 | #include <libmailwrapper/abstractmail.h> | ||
10 | |||
11 | /* OPIE */ | ||
12 | #include <qpe/qpeapplication.h> | ||
13 | |||
14 | /* QT */ | ||
15 | #include <qmessagebox.h> | ||
16 | #include <qpopupmenu.h> | ||
17 | |||
18 | using namespace Opie::Core; | ||
19 | AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | ||
20 | : QListView( parent, name, flags ) | ||
21 | { | ||
22 | connect( this, SIGNAL( selectionChanged(QListViewItem*) ), | ||
23 | SLOT( refresh(QListViewItem*) ) ); | ||
24 | connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, | ||
25 | SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); | ||
26 | setSorting(0); | ||
27 | } | ||
28 | |||
29 | AccountView::~AccountView() | ||
30 | { | ||
31 | imapAccounts.clear(); | ||
32 | mhAccounts.clear(); | ||
33 | } | ||
34 | |||
35 | void AccountView::slotContextMenu(int id) | ||
36 | { | ||
37 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); | ||
38 | if (!view) return; | ||
39 | view->contextMenuSelected(id); | ||
40 | } | ||
41 | |||
42 | void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) | ||
43 | { | ||
44 | if (button==1) {return;} | ||
45 | if (!item) return; | ||
46 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | ||
47 | QPopupMenu*m = view->getContextMenu(); | ||
48 | if (!m) return; | ||
49 | connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); | ||
50 | m->setFocus(); | ||
51 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | ||
52 | delete m; | ||
53 | } | ||
54 | |||
55 | void AccountView::populate( QList<Account> list ) | ||
56 | { | ||
57 | clear(); | ||
58 | |||
59 | imapAccounts.clear(); | ||
60 | mhAccounts.clear(); | ||
61 | |||
62 | mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); | ||
63 | |||
64 | Account *it; | ||
65 | for ( it = list.first(); it; it = list.next() ) | ||
66 | { | ||
67 | if ( it->getType() == MAILLIB::A_IMAP ) | ||
68 | { | ||
69 | IMAPaccount *imap = static_cast<IMAPaccount *>(it); | ||
70 | imapAccounts.append(new IMAPviewItem( imap, this )); | ||
71 | } | ||
72 | else if ( it->getType() == MAILLIB::A_POP3 ) | ||
73 | { | ||
74 | POP3account *pop3 = static_cast<POP3account *>(it); | ||
75 | /* must not be hold 'cause it isn't required */ | ||
76 | (void) new POP3viewItem( pop3, this ); | ||
77 | } | ||
78 | else if ( it->getType() == MAILLIB::A_NNTP ) | ||
79 | { | ||
80 | NNTPaccount *nntp = static_cast<NNTPaccount *>(it); | ||
81 | /* must not be hold 'cause it isn't required */ | ||
82 | (void) new NNTPviewItem( nntp, this ); | ||
83 | } | ||
84 | } | ||
85 | } | ||
86 | |||
87 | void AccountView::refresh(QListViewItem *item) | ||
88 | { | ||
89 | if ( item ) | ||
90 | { | ||
91 | m_currentItem = item; | ||
92 | QValueList<RecMailP> headerlist; | ||
93 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | ||
94 | view->refresh(headerlist); | ||
95 | emit refreshMailview(headerlist); | ||
96 | } | ||
97 | } | ||
98 | |||
99 | void AccountView::refreshCurrent() | ||
100 | { | ||
101 | m_currentItem = currentItem(); | ||
102 | if ( !m_currentItem ) return; | ||
103 | QValueList<RecMailP> headerlist; | ||
104 | AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); | ||
105 | view->refresh(headerlist); | ||
106 | emit refreshMailview(headerlist); | ||
107 | } | ||
108 | |||
109 | void AccountView::refreshAll() | ||
110 | { | ||
111 | } | ||
112 | |||
113 | RecBodyP AccountView::fetchBody(const RecMailP&aMail) | ||
114 | { | ||
115 | QListViewItem*item = selectedItem (); | ||
116 | if (!item) return new RecBody(); | ||
117 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | ||
118 | return view->fetchBody(aMail); | ||
119 | } | ||
120 | |||
121 | void AccountView::setupFolderselect(Selectstore*sels) | ||
122 | { | ||
123 | sels->showMaximized(); | ||
124 | QStringList sFolders; | ||
125 | unsigned int i = 0; | ||
126 | for (i=0; i < mhAccounts.count();++i) | ||
127 | { | ||
128 | mhAccounts[i]->refresh(false); | ||
129 | sFolders = mhAccounts[i]->subFolders(); | ||
130 | sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); | ||
131 | } | ||
132 | for (i=0; i < imapAccounts.count();++i) | ||
133 | { | ||
134 | if (imapAccounts[i]->offline()) | ||
135 | continue; | ||
136 | imapAccounts[i]->refreshFolders(false); | ||
137 | sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); | ||
138 | } | ||
139 | } | ||
140 | |||
141 | void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) | ||
142 | { | ||
143 | AbstractMail*targetMail = 0; | ||
144 | QString targetFolder = ""; | ||
145 | Selectstore sels; | ||
146 | setupFolderselect(&sels); | ||
147 | if (!sels.exec()) return; | ||
148 | targetMail = sels.currentMail(); | ||
149 | targetFolder = sels.currentFolder(); | ||
150 | if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || | ||
151 | targetFolder.isEmpty()) | ||
152 | { | ||
153 | return; | ||
154 | } | ||
155 | if (sels.newFolder() && !targetMail->createMbox(targetFolder)) | ||
156 | { | ||
157 | QMessageBox::critical(0,tr("Error creating new Folder"), | ||
158 | tr("<center>Error while creating<br>new folder - breaking.</center>")); | ||
159 | return; | ||
160 | } | ||
161 | fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails()); | ||
162 | refreshCurrent(); | ||
163 | } | ||
164 | |||
165 | bool AccountView::currentisDraft() | ||
166 | { | ||
167 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); | ||
168 | if (!view) return false; | ||
169 | return view->isDraftfolder(); | ||
170 | } | ||