author | alwin <alwin> | 2004-01-10 03:22:16 (UTC) |
---|---|---|
committer | alwin <alwin> | 2004-01-10 03:22:16 (UTC) |
commit | abf23602a446e30ec18d16d3495da5747a96072b (patch) (unidiff) | |
tree | 80dd4d6089c3d7c5f45a8f0a4e6c2b53cfca2e9b /noncore/net/mail/accountitem.cpp | |
parent | 6248e82bf1b077c54e3e2b85801a99fa0f86434d (diff) | |
download | opie-abf23602a446e30ec18d16d3495da5747a96072b.zip opie-abf23602a446e30ec18d16d3495da5747a96072b.tar.gz opie-abf23602a446e30ec18d16d3495da5747a96072b.tar.bz2 |
mh box fully functional
splitted the stuff of accountview list into seperate files so the other
parts care about changes inside accountitems
Diffstat (limited to 'noncore/net/mail/accountitem.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/accountitem.cpp | 842 |
1 files changed, 842 insertions, 0 deletions
diff --git a/noncore/net/mail/accountitem.cpp b/noncore/net/mail/accountitem.cpp new file mode 100644 index 0000000..2d3cd4b --- a/dev/null +++ b/noncore/net/mail/accountitem.cpp | |||
@@ -0,0 +1,842 @@ | |||
1 | #include "accountitem.h" | ||
2 | #include "accountview.h" | ||
3 | #include <qpopupmenu.h> | ||
4 | #include <qmessagebox.h> | ||
5 | #include "selectstore.h" | ||
6 | #include "newmaildir.h" | ||
7 | #include <libmailwrapper/mailtypes.h> | ||
8 | #include <libmailwrapper/abstractmail.h> | ||
9 | #include <libmailwrapper/mailwrapper.h> | ||
10 | #include "defines.h" | ||
11 | |||
12 | #define SETPIX(x) if (!account->getOffline()) {setPixmap( 0,x);} else {setPixmap( 0, PIXMAP_OFFLINE );} | ||
13 | /** | ||
14 | * POP3 Account stuff | ||
15 | */ | ||
16 | POP3viewItem::POP3viewItem( POP3account *a, AccountView *parent ) | ||
17 | : AccountViewItem( parent ) | ||
18 | { | ||
19 | account = a; | ||
20 | wrapper = AbstractMail::getWrapper( account ); | ||
21 | SETPIX(PIXMAP_POP3FOLDER); | ||
22 | #if 0 | ||
23 | if (!account->getOffline()) { | ||
24 | setPixmap( 0, ); | ||
25 | } else { | ||
26 | setPixmap( 0, PIXMAP_OFFLINE ); | ||
27 | } | ||
28 | #endif | ||
29 | setText( 0, account->getAccountName() ); | ||
30 | setOpen( true ); | ||
31 | } | ||
32 | |||
33 | POP3viewItem::~POP3viewItem() | ||
34 | { | ||
35 | delete wrapper; | ||
36 | } | ||
37 | |||
38 | AbstractMail *POP3viewItem::getWrapper() | ||
39 | { | ||
40 | return wrapper; | ||
41 | } | ||
42 | |||
43 | void POP3viewItem::refresh( QList<RecMail> & ) | ||
44 | { | ||
45 | refresh(); | ||
46 | } | ||
47 | |||
48 | void POP3viewItem::refresh() | ||
49 | { | ||
50 | if (account->getOffline()) return; | ||
51 | QList<Folder> *folders = wrapper->listFolders(); | ||
52 | QListViewItem *child = firstChild(); | ||
53 | while ( child ) { | ||
54 | QListViewItem *tmp = child; | ||
55 | child = child->nextSibling(); | ||
56 | delete tmp; | ||
57 | } | ||
58 | Folder *it; | ||
59 | QListViewItem*item = 0; | ||
60 | for ( it = folders->first(); it; it = folders->next() ) { | ||
61 | item = new POP3folderItem( it, this , item ); | ||
62 | item->setSelectable(it->may_select()); | ||
63 | } | ||
64 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
65 | folders->setAutoDelete(false); | ||
66 | delete folders; | ||
67 | } | ||
68 | |||
69 | RecBody POP3viewItem::fetchBody( const RecMail &mail ) | ||
70 | { | ||
71 | qDebug( "POP3 fetchBody" ); | ||
72 | return wrapper->fetchBody( mail ); | ||
73 | } | ||
74 | |||
75 | QPopupMenu * POP3viewItem::getContextMenu() | ||
76 | { | ||
77 | QPopupMenu *m = new QPopupMenu(0); | ||
78 | if (m) { | ||
79 | if (!account->getOffline()) { | ||
80 | m->insertItem(QObject::tr("Disconnect",contextName),0); | ||
81 | m->insertItem(QObject::tr("Set offline",contextName),1); | ||
82 | } else { | ||
83 | m->insertItem(QObject::tr("Set online",contextName),1); | ||
84 | } | ||
85 | } | ||
86 | return m; | ||
87 | } | ||
88 | |||
89 | void POP3viewItem::disconnect() | ||
90 | { | ||
91 | QListViewItem *child = firstChild(); | ||
92 | while ( child ) { | ||
93 | QListViewItem *tmp = child; | ||
94 | child = child->nextSibling(); | ||
95 | delete tmp; | ||
96 | } | ||
97 | wrapper->logout(); | ||
98 | } | ||
99 | |||
100 | void POP3viewItem::setOnOffline() | ||
101 | { | ||
102 | if (!account->getOffline()) { | ||
103 | disconnect(); | ||
104 | } | ||
105 | account->setOffline(!account->getOffline()); | ||
106 | account->save(); | ||
107 | SETPIX(PIXMAP_POP3FOLDER); | ||
108 | refresh(); | ||
109 | } | ||
110 | |||
111 | void POP3viewItem::contextMenuSelected(int which) | ||
112 | { | ||
113 | switch (which) { | ||
114 | case 0: | ||
115 | disconnect(); | ||
116 | break; | ||
117 | case 1: | ||
118 | setOnOffline(); | ||
119 | break; | ||
120 | } | ||
121 | } | ||
122 | |||
123 | POP3folderItem::~POP3folderItem() | ||
124 | { | ||
125 | } | ||
126 | |||
127 | POP3folderItem::POP3folderItem( Folder *folderInit, POP3viewItem *parent , QListViewItem*after ) | ||
128 | : AccountViewItem( parent,after ) | ||
129 | { | ||
130 | folder = folderInit; | ||
131 | pop3 = parent; | ||
132 | if (folder->getDisplayName().lower()!="inbox") { | ||
133 | setPixmap( 0, PIXMAP_POP3FOLDER ); | ||
134 | } else { | ||
135 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
136 | } | ||
137 | setText( 0, folder->getDisplayName() ); | ||
138 | } | ||
139 | |||
140 | void POP3folderItem::refresh(QList<RecMail>&target) | ||
141 | { | ||
142 | if (folder->may_select()) | ||
143 | pop3->getWrapper()->listMessages( folder->getName(),target ); | ||
144 | } | ||
145 | |||
146 | RecBody POP3folderItem::fetchBody(const RecMail&aMail) | ||
147 | { | ||
148 | return pop3->getWrapper()->fetchBody(aMail); | ||
149 | } | ||
150 | |||
151 | QPopupMenu * POP3folderItem::getContextMenu() | ||
152 | { | ||
153 | QPopupMenu *m = new QPopupMenu(0); | ||
154 | if (m) { | ||
155 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | ||
156 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | ||
157 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | ||
158 | } | ||
159 | return m; | ||
160 | } | ||
161 | |||
162 | void POP3folderItem::downloadMails() | ||
163 | { | ||
164 | AccountView*bl = pop3->accountView(); | ||
165 | if (!bl) return; | ||
166 | bl->downloadMails(folder,pop3->getWrapper()); | ||
167 | } | ||
168 | |||
169 | void POP3folderItem::contextMenuSelected(int which) | ||
170 | { | ||
171 | AccountView * view = (AccountView*)listView(); | ||
172 | switch (which) { | ||
173 | case 0: | ||
174 | /* must be 'cause pop3 lists are cached */ | ||
175 | pop3->getWrapper()->logout(); | ||
176 | view->refreshCurrent(); | ||
177 | break; | ||
178 | case 1: | ||
179 | deleteAllMail(pop3->getWrapper(),folder); | ||
180 | break; | ||
181 | case 2: | ||
182 | downloadMails(); | ||
183 | break; | ||
184 | default: | ||
185 | break; | ||
186 | } | ||
187 | } | ||
188 | |||
189 | /** | ||
190 | * IMAP Account stuff | ||
191 | */ | ||
192 | IMAPviewItem::IMAPviewItem( IMAPaccount *a, AccountView *parent ) | ||
193 | : AccountViewItem( parent ) | ||
194 | { | ||
195 | account = a; | ||
196 | wrapper = AbstractMail::getWrapper( account ); | ||
197 | SETPIX(PIXMAP_IMAPFOLDER); | ||
198 | setText( 0, account->getAccountName() ); | ||
199 | setOpen( true ); | ||
200 | } | ||
201 | |||
202 | IMAPviewItem::~IMAPviewItem() | ||
203 | { | ||
204 | delete wrapper; | ||
205 | } | ||
206 | |||
207 | AbstractMail *IMAPviewItem::getWrapper() | ||
208 | { | ||
209 | return wrapper; | ||
210 | } | ||
211 | |||
212 | void IMAPviewItem::refresh(QList<RecMail>&) | ||
213 | { | ||
214 | refreshFolders(false); | ||
215 | } | ||
216 | |||
217 | const QStringList&IMAPviewItem::subFolders() | ||
218 | { | ||
219 | return currentFolders; | ||
220 | } | ||
221 | |||
222 | void IMAPviewItem::refreshFolders(bool force) | ||
223 | { | ||
224 | if (childCount()>0 && force==false) return; | ||
225 | if (account->getOffline()) return; | ||
226 | |||
227 | removeChilds(); | ||
228 | currentFolders.clear(); | ||
229 | QList<Folder> *folders = wrapper->listFolders(); | ||
230 | |||
231 | Folder *it; | ||
232 | QListViewItem*item = 0; | ||
233 | QListViewItem*titem = 0; | ||
234 | QString fname,del,search; | ||
235 | int pos; | ||
236 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
237 | folders->setAutoDelete(false); | ||
238 | |||
239 | for ( it = folders->first(); it; it = folders->next() ) { | ||
240 | if (it->getDisplayName().lower()=="inbox") { | ||
241 | item = new IMAPfolderItem( it, this , item ); | ||
242 | folders->remove(it); | ||
243 | qDebug("inbox found"); | ||
244 | break; | ||
245 | } | ||
246 | } | ||
247 | for ( it = folders->first(); it; it = folders->next() ) { | ||
248 | fname = it->getDisplayName(); | ||
249 | currentFolders.append(it->getName()); | ||
250 | pos = fname.findRev(it->Separator()); | ||
251 | if (pos != -1) { | ||
252 | fname = fname.left(pos); | ||
253 | } | ||
254 | IMAPfolderItem*pitem = (IMAPfolderItem*)findSubItem(fname); | ||
255 | if (pitem) { | ||
256 | titem = item; | ||
257 | item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); | ||
258 | /* setup the short name */ | ||
259 | item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); | ||
260 | item = titem; | ||
261 | } else { | ||
262 | item = new IMAPfolderItem( it, this , item ); | ||
263 | } | ||
264 | } | ||
265 | delete folders; | ||
266 | } | ||
267 | |||
268 | QPopupMenu * IMAPviewItem::getContextMenu() | ||
269 | { | ||
270 | QPopupMenu *m = new QPopupMenu(0); | ||
271 | if (m) { | ||
272 | if (!account->getOffline()) { | ||
273 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | ||
274 | m->insertItem(QObject::tr("Create new folder",contextName),1); | ||
275 | m->insertSeparator(); | ||
276 | m->insertItem(QObject::tr("Disconnect",contextName),2); | ||
277 | m->insertItem(QObject::tr("Set offline",contextName),3); | ||
278 | } else { | ||
279 | m->insertItem(QObject::tr("Set online",contextName),3); | ||
280 | } | ||
281 | } | ||
282 | return m; | ||
283 | } | ||
284 | |||
285 | void IMAPviewItem::createNewFolder() | ||
286 | { | ||
287 | Newmdirdlg ndirdlg; | ||
288 | ndirdlg.showMaximized(); | ||
289 | if (ndirdlg.exec()) { | ||
290 | QString ndir = ndirdlg.Newdir(); | ||
291 | bool makesubs = ndirdlg.subpossible(); | ||
292 | QString delemiter = "/"; | ||
293 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); | ||
294 | if (item) { | ||
295 | delemiter = item->Delemiter(); | ||
296 | } | ||
297 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { | ||
298 | refreshFolders(true); | ||
299 | } | ||
300 | } | ||
301 | } | ||
302 | |||
303 | void IMAPviewItem::contextMenuSelected(int id) | ||
304 | { | ||
305 | qDebug("Id selected: %i",id); | ||
306 | switch (id) { | ||
307 | case 0: | ||
308 | refreshFolders(true); | ||
309 | break; | ||
310 | case 1: | ||
311 | createNewFolder(); | ||
312 | break; | ||
313 | case 2: | ||
314 | removeChilds(); | ||
315 | wrapper->logout(); | ||
316 | break; | ||
317 | case 3: | ||
318 | if (account->getOffline()==false) { | ||
319 | removeChilds(); | ||
320 | wrapper->logout(); | ||
321 | } | ||
322 | account->setOffline(!account->getOffline()); | ||
323 | account->save(); | ||
324 | SETPIX(PIXMAP_IMAPFOLDER); | ||
325 | refreshFolders(false); | ||
326 | break; | ||
327 | default: | ||
328 | break; | ||
329 | } | ||
330 | } | ||
331 | |||
332 | RecBody IMAPviewItem::fetchBody(const RecMail&) | ||
333 | { | ||
334 | return RecBody(); | ||
335 | } | ||
336 | |||
337 | bool IMAPviewItem::offline() | ||
338 | { | ||
339 | return account->getOffline(); | ||
340 | } | ||
341 | |||
342 | IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPviewItem *parent , QListViewItem*after ) | ||
343 | : AccountViewItem( parent , after ) | ||
344 | { | ||
345 | folder = folderInit; | ||
346 | imap = parent; | ||
347 | if (folder->getDisplayName().lower()!="inbox") { | ||
348 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | ||
349 | } else { | ||
350 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
351 | } | ||
352 | setText( 0, folder->getDisplayName() ); | ||
353 | } | ||
354 | |||
355 | IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QListViewItem*after, IMAPviewItem *master ) | ||
356 | : AccountViewItem( parent,after ) | ||
357 | { | ||
358 | folder = folderInit; | ||
359 | imap = master; | ||
360 | if (folder->getDisplayName().lower()!="inbox") { | ||
361 | setPixmap( 0, PIXMAP_IMAPFOLDER ); | ||
362 | } else { | ||
363 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
364 | } | ||
365 | setText( 0, folder->getDisplayName() ); | ||
366 | } | ||
367 | |||
368 | IMAPfolderItem::~IMAPfolderItem() | ||
369 | { | ||
370 | } | ||
371 | |||
372 | const QString& IMAPfolderItem::Delemiter()const | ||
373 | { | ||
374 | return folder->Separator(); | ||
375 | } | ||
376 | |||
377 | void IMAPfolderItem::refresh(QList<RecMail>&target) | ||
378 | { | ||
379 | if (folder->may_select()) { | ||
380 | imap->getWrapper()->listMessages( folder->getName(),target ); | ||
381 | } else { | ||
382 | target.clear(); | ||
383 | } | ||
384 | } | ||
385 | |||
386 | RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) | ||
387 | { | ||
388 | return imap->getWrapper()->fetchBody(aMail); | ||
389 | } | ||
390 | |||
391 | QPopupMenu * IMAPfolderItem::getContextMenu() | ||
392 | { | ||
393 | QPopupMenu *m = new QPopupMenu(0); | ||
394 | if (m) { | ||
395 | if (folder->may_select()) { | ||
396 | m->insertItem(QObject::tr("Refresh header list",contextName),0); | ||
397 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),4); | ||
398 | m->insertItem(QObject::tr("Delete all mails",contextName),1); | ||
399 | } | ||
400 | if (folder->no_inferior()==false) { | ||
401 | m->insertItem(QObject::tr("Create new subfolder",contextName),2); | ||
402 | } | ||
403 | if (folder->getDisplayName().lower()!="inbox") { | ||
404 | m->insertItem(QObject::tr("Delete folder",contextName),3); | ||
405 | } | ||
406 | } | ||
407 | return m; | ||
408 | } | ||
409 | |||
410 | void IMAPfolderItem::createNewFolder() | ||
411 | { | ||
412 | Newmdirdlg ndirdlg; | ||
413 | ndirdlg.showMaximized(); | ||
414 | if (ndirdlg.exec()) { | ||
415 | QString ndir = ndirdlg.Newdir(); | ||
416 | bool makesubs = ndirdlg.subpossible(); | ||
417 | QString delemiter = Delemiter(); | ||
418 | if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { | ||
419 | imap->refreshFolders(true); | ||
420 | } | ||
421 | } | ||
422 | } | ||
423 | |||
424 | void IMAPfolderItem::deleteFolder() | ||
425 | { | ||
426 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | ||
427 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | ||
428 | QObject::tr("Yes",contextName), | ||
429 | QObject::tr("No",contextName),QString::null,1,1); | ||
430 | qDebug("Auswahl: %i",yesno); | ||
431 | if (yesno == 0) { | ||
432 | if (imap->getWrapper()->deleteMbox(folder)) { | ||
433 | QListView*v=listView(); | ||
434 | IMAPviewItem * box = imap; | ||
435 | /* be carefull - after that this object is destroyd so don't use | ||
436 | * any member of it after that call!!*/ | ||
437 | imap->refreshFolders(true); | ||
438 | if (v) { | ||
439 | v->setSelected(box,true); | ||
440 | } | ||
441 | } | ||
442 | } | ||
443 | } | ||
444 | |||
445 | void IMAPfolderItem::downloadMails() | ||
446 | { | ||
447 | AccountView*bl = imap->accountView(); | ||
448 | if (!bl) return; | ||
449 | bl->downloadMails(folder,imap->getWrapper()); | ||
450 | } | ||
451 | |||
452 | void IMAPfolderItem::contextMenuSelected(int id) | ||
453 | { | ||
454 | qDebug("Selected id: %i",id); | ||
455 | AccountView * view = (AccountView*)listView(); | ||
456 | switch(id) { | ||
457 | case 0: | ||
458 | view->refreshCurrent(); | ||
459 | break; | ||
460 | case 1: | ||
461 | deleteAllMail(imap->getWrapper(),folder); | ||
462 | break; | ||
463 | case 2: | ||
464 | createNewFolder(); | ||
465 | break; | ||
466 | case 3: | ||
467 | deleteFolder(); | ||
468 | break; | ||
469 | case 4: | ||
470 | downloadMails(); | ||
471 | break; | ||
472 | default: | ||
473 | break; | ||
474 | } | ||
475 | } | ||
476 | |||
477 | /** | ||
478 | * MH Account stuff | ||
479 | */ | ||
480 | /* MH is a little bit different - the top folder can contains messages other than in IMAP and | ||
481 | POP3 and MBOX */ | ||
482 | MHviewItem::MHviewItem( const QString&aPath, AccountView *parent ) | ||
483 | : AccountViewItem( parent ) | ||
484 | { | ||
485 | m_Path = aPath; | ||
486 | /* be carefull - the space within settext is wanted - thats why the string twice */ | ||
487 | wrapper = AbstractMail::getWrapper( m_Path,"Local Folders"); | ||
488 | setPixmap( 0, PIXMAP_LOCALFOLDER ); | ||
489 | setText( 0, " Local Folders" ); | ||
490 | setOpen( true ); | ||
491 | folder = 0; | ||
492 | } | ||
493 | |||
494 | MHviewItem::~MHviewItem() | ||
495 | { | ||
496 | delete wrapper; | ||
497 | } | ||
498 | |||
499 | AbstractMail *MHviewItem::getWrapper() | ||
500 | { | ||
501 | return wrapper; | ||
502 | } | ||
503 | |||
504 | void MHviewItem::refresh( QList<RecMail> & target) | ||
505 | { | ||
506 | refresh(false); | ||
507 | getWrapper()->listMessages( "",target ); | ||
508 | } | ||
509 | |||
510 | void MHviewItem::refresh(bool force) | ||
511 | { | ||
512 | if (childCount()>0 && force==false) return; | ||
513 | removeChilds(); | ||
514 | currentFolders.clear(); | ||
515 | QList<Folder> *folders = wrapper->listFolders(); | ||
516 | Folder *it; | ||
517 | MHfolderItem*item = 0; | ||
518 | MHfolderItem*pmaster = 0; | ||
519 | QString fname = ""; | ||
520 | int pos; | ||
521 | for ( it = folders->first(); it; it = folders->next() ) { | ||
522 | fname = it->getDisplayName(); | ||
523 | /* this folder itself */ | ||
524 | if (fname=="/") { | ||
525 | currentFolders.append(fname); | ||
526 | folder = it; | ||
527 | continue; | ||
528 | } | ||
529 | currentFolders.append(fname); | ||
530 | pos = fname.findRev("/"); | ||
531 | if (pos > 0) { | ||
532 | fname = fname.left(pos); | ||
533 | pmaster = (MHfolderItem*)findSubItem(fname); | ||
534 | } else { | ||
535 | pmaster = 0; | ||
536 | } | ||
537 | if (pmaster) { | ||
538 | item = new MHfolderItem( it, pmaster, item, this ); | ||
539 | } else { | ||
540 | item = new MHfolderItem( it, this , item ); | ||
541 | } | ||
542 | item->setSelectable(it->may_select()); | ||
543 | } | ||
544 | // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | ||
545 | folders->setAutoDelete(false); | ||
546 | delete folders; | ||
547 | } | ||
548 | |||
549 | RecBody MHviewItem::fetchBody( const RecMail &mail ) | ||
550 | { | ||
551 | qDebug( "MH fetchBody" ); | ||
552 | return wrapper->fetchBody( mail ); | ||
553 | } | ||
554 | |||
555 | QPopupMenu * MHviewItem::getContextMenu() | ||
556 | { | ||
557 | QPopupMenu *m = new QPopupMenu(0); | ||
558 | if (m) { | ||
559 | m->insertItem(QObject::tr("Refresh folder list",contextName),0); | ||
560 | m->insertItem(QObject::tr("Create new folder",contextName),1); | ||
561 | m->insertItem(QObject::tr("Delete all mails",contextName),2); | ||
562 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),3); | ||
563 | } | ||
564 | return m; | ||
565 | } | ||
566 | |||
567 | void MHviewItem::createFolder() | ||
568 | { | ||
569 | Newmdirdlg ndirdlg(0,0,true); | ||
570 | ndirdlg.showMaximized(); | ||
571 | if (ndirdlg.exec()) { | ||
572 | QString ndir = ndirdlg.Newdir(); | ||
573 | if (wrapper->createMbox(ndir)) { | ||
574 | refresh(true); | ||
575 | } | ||
576 | } | ||
577 | } | ||
578 | |||
579 | void MHviewItem::downloadMails() | ||
580 | { | ||
581 | AccountView*bl = accountView(); | ||
582 | if (!bl) return; | ||
583 | bl->downloadMails(folder,getWrapper()); | ||
584 | } | ||
585 | |||
586 | QStringList MHviewItem::subFolders() | ||
587 | { | ||
588 | return currentFolders; | ||
589 | } | ||
590 | |||
591 | void MHviewItem::contextMenuSelected(int which) | ||
592 | { | ||
593 | switch (which) { | ||
594 | case 0: | ||
595 | refresh(true); | ||
596 | break; | ||
597 | case 1: | ||
598 | createFolder(); | ||
599 | break; | ||
600 | case 2: | ||
601 | deleteAllMail(getWrapper(),folder); | ||
602 | break; | ||
603 | case 3: | ||
604 | downloadMails(); | ||
605 | break; | ||
606 | default: | ||
607 | break; | ||
608 | } | ||
609 | } | ||
610 | |||
611 | MHfolderItem::~MHfolderItem() | ||
612 | { | ||
613 | } | ||
614 | |||
615 | MHfolderItem::MHfolderItem( Folder *folderInit, MHviewItem *parent , QListViewItem*after ) | ||
616 | : AccountViewItem( parent,after ) | ||
617 | { | ||
618 | folder = folderInit; | ||
619 | mbox = parent; | ||
620 | initName(); | ||
621 | } | ||
622 | |||
623 | MHfolderItem::MHfolderItem( Folder *folderInit, MHfolderItem *parent, QListViewItem*after, MHviewItem*master) | ||
624 | : AccountViewItem( parent,after ) | ||
625 | { | ||
626 | folder = folderInit; | ||
627 | mbox = master; | ||
628 | initName(); | ||
629 | } | ||
630 | |||
631 | void MHfolderItem::initName() | ||
632 | { | ||
633 | QString bName = folder->getDisplayName(); | ||
634 | if (bName.startsWith("/")&&bName.length()>1) { | ||
635 | bName.replace(0,1,""); | ||
636 | } | ||
637 | int pos = bName.findRev("/"); | ||
638 | if (pos > 0) { | ||
639 | bName.replace(0,pos+1,""); | ||
640 | } | ||
641 | if (bName.lower() == "outgoing") { | ||
642 | setPixmap( 0, PIXMAP_OUTBOXFOLDER ); | ||
643 | } else if (bName.lower() == "inbox") { | ||
644 | setPixmap( 0, PIXMAP_INBOXFOLDER); | ||
645 | } else { | ||
646 | setPixmap( 0, PIXMAP_MBOXFOLDER ); | ||
647 | } | ||
648 | setText( 0, bName ); | ||
649 | } | ||
650 | |||
651 | Folder*MHfolderItem::getFolder() | ||
652 | { | ||
653 | return folder; | ||
654 | } | ||
655 | |||
656 | void MHfolderItem::refresh(QList<RecMail>&target) | ||
657 | { | ||
658 | if (folder->may_select()) | ||
659 | mbox->getWrapper()->listMessages( folder->getName(),target ); | ||
660 | } | ||
661 | |||
662 | RecBody MHfolderItem::fetchBody(const RecMail&aMail) | ||
663 | { | ||
664 | return mbox->getWrapper()->fetchBody(aMail); | ||
665 | } | ||
666 | |||
667 | void MHfolderItem::deleteFolder() | ||
668 | { | ||
669 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder",contextName), | ||
670 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>",contextName).arg(folder->getDisplayName()), | ||
671 | QObject::tr("Yes",contextName), | ||
672 | QObject::tr("No",contextName),QString::null,1,1); | ||
673 | qDebug("Auswahl: %i",yesno); | ||
674 | if (yesno == 0) { | ||
675 | if (mbox->getWrapper()->deleteMbox(folder)) { | ||
676 | QListView*v=listView(); | ||
677 | MHviewItem * box = mbox; | ||
678 | /* be carefull - after that this object is destroyd so don't use | ||
679 | * any member of it after that call!!*/ | ||
680 | mbox->refresh(true); | ||
681 | if (v) { | ||
682 | v->setSelected(box,true); | ||
683 | } | ||
684 | } | ||
685 | } | ||
686 | } | ||
687 | |||
688 | QPopupMenu * MHfolderItem::getContextMenu() | ||
689 | { | ||
690 | QPopupMenu *m = new QPopupMenu(0); | ||
691 | if (m) { | ||
692 | m->insertItem(QObject::tr("Move/Copie all mails",contextName),2); | ||
693 | m->insertItem(QObject::tr("Delete all mails",contextName),0); | ||
694 | m->insertItem(QObject::tr("Create new subfolder",contextName),3); | ||
695 | m->insertItem(QObject::tr("Delete folder",contextName),1); | ||
696 | } | ||
697 | return m; | ||
698 | } | ||
699 | |||
700 | void MHfolderItem::downloadMails() | ||
701 | { | ||
702 | AccountView*bl = mbox->accountView(); | ||
703 | if (!bl) return; | ||
704 | bl->downloadMails(folder,mbox->getWrapper()); | ||
705 | } | ||
706 | |||
707 | void MHfolderItem::createFolder() | ||
708 | { | ||
709 | Newmdirdlg ndirdlg(0,0,true); | ||
710 | ndirdlg.showMaximized(); | ||
711 | if (ndirdlg.exec()) { | ||
712 | QString ndir = ndirdlg.Newdir(); | ||
713 | if (mbox->getWrapper()->createMbox(ndir,folder)) { | ||
714 | QListView*v=listView(); | ||
715 | MHviewItem * box = mbox; | ||
716 | /* be carefull - after that this object is destroyd so don't use | ||
717 | * any member of it after that call!!*/ | ||
718 | mbox->refresh(true); | ||
719 | if (v) { | ||
720 | v->setSelected(box,true); | ||
721 | } | ||
722 | } | ||
723 | } | ||
724 | } | ||
725 | |||
726 | void MHfolderItem::contextMenuSelected(int which) | ||
727 | { | ||
728 | switch(which) { | ||
729 | case 0: | ||
730 | deleteAllMail(mbox->getWrapper(),folder); | ||
731 | break; | ||
732 | case 1: | ||
733 | deleteFolder(); | ||
734 | break; | ||
735 | case 2: | ||
736 | downloadMails(); | ||
737 | break; | ||
738 | case 3: | ||
739 | createFolder(); | ||
740 | break; | ||
741 | default: | ||
742 | break; | ||
743 | } | ||
744 | } | ||
745 | |||
746 | /** | ||
747 | * Generic stuff | ||
748 | */ | ||
749 | |||
750 | const QString AccountViewItem::contextName="AccountViewItem"; | ||
751 | |||
752 | AccountViewItem::AccountViewItem( AccountView *parent ) | ||
753 | : QListViewItem( parent ) | ||
754 | { | ||
755 | init(); | ||
756 | m_Backlink = parent; | ||
757 | } | ||
758 | |||
759 | AccountViewItem::AccountViewItem( QListViewItem *parent) | ||
760 | : QListViewItem( parent) | ||
761 | { | ||
762 | init(); | ||
763 | } | ||
764 | |||
765 | AccountViewItem::AccountViewItem( QListViewItem *parent , QListViewItem*after ) | ||
766 | :QListViewItem( parent,after ) | ||
767 | { | ||
768 | init(); | ||
769 | } | ||
770 | |||
771 | void AccountViewItem::init() | ||
772 | { | ||
773 | m_Backlink = 0; | ||
774 | folder = 0; | ||
775 | } | ||
776 | |||
777 | AccountViewItem::~AccountViewItem() | ||
778 | { | ||
779 | if (folder) delete folder; | ||
780 | } | ||
781 | |||
782 | AccountView*AccountViewItem::accountView() | ||
783 | { | ||
784 | return m_Backlink; | ||
785 | } | ||
786 | |||
787 | void AccountViewItem::deleteAllMail(AbstractMail*wrapper,Folder*folder) | ||
788 | { | ||
789 | if (!wrapper) return; | ||
790 | QString fname=""; | ||
791 | if (folder) fname = folder->getDisplayName(); | ||
792 | int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails",contextName), | ||
793 | QObject::tr("<center>Realy delete all mails in box <br>%1</center>",contextName). | ||
794 | arg(fname), | ||
795 | QObject::tr("Yes",contextName), | ||
796 | QObject::tr("No",contextName),QString::null,1,1); | ||
797 | qDebug("Auswahl: %i",yesno); | ||
798 | if (yesno == 0) { | ||
799 | if (wrapper->deleteAllMail(folder)) { | ||
800 | AccountView * view = (AccountView*)listView(); | ||
801 | if (view) view->refreshCurrent(); | ||
802 | } | ||
803 | } | ||
804 | } | ||
805 | |||
806 | void AccountViewItem::removeChilds() | ||
807 | { | ||
808 | QListViewItem *child = firstChild(); | ||
809 | while ( child ) { | ||
810 | QListViewItem *tmp = child; | ||
811 | child = child->nextSibling(); | ||
812 | delete tmp; | ||
813 | } | ||
814 | } | ||
815 | |||
816 | bool AccountViewItem::matchName(const QString&name)const | ||
817 | { | ||
818 | if (!folder) return false; | ||
819 | return folder->getDisplayName()==name; | ||
820 | } | ||
821 | |||
822 | |||
823 | AccountViewItem*AccountViewItem::findSubItem(const QString&path,AccountViewItem*start) | ||
824 | { | ||
825 | AccountViewItem*pitem,*sitem; | ||
826 | if (!start) pitem = (AccountViewItem*)firstChild(); | ||
827 | else pitem = (AccountViewItem*)start->firstChild(); | ||
828 | while (pitem) { | ||
829 | if (pitem->matchName(path)) { | ||
830 | break; | ||
831 | } | ||
832 | if (pitem->childCount()>0) { | ||
833 | sitem = findSubItem(path,pitem); | ||
834 | if (sitem) { | ||
835 | pitem = sitem; | ||
836 | break; | ||
837 | } | ||
838 | } | ||
839 | pitem=(AccountViewItem*)pitem->nextSibling(); | ||
840 | } | ||
841 | return pitem; | ||
842 | } | ||