Diffstat (limited to 'noncore/net/mail/accountview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/accountview.cpp | 179 |
1 files changed, 172 insertions, 7 deletions
diff --git a/noncore/net/mail/accountview.cpp b/noncore/net/mail/accountview.cpp index 59e8bc0..8aac14b 100644 --- a/noncore/net/mail/accountview.cpp +++ b/noncore/net/mail/accountview.cpp | |||
@@ -3,9 +3,11 @@ | |||
3 | #include "mailtypes.h" | 3 | #include "mailtypes.h" |
4 | #include "defines.h" | 4 | #include "defines.h" |
5 | #include "newmaildir.h" | ||
6 | #include <qmessagebox.h> | ||
7 | #include <qpopupmenu.h> | ||
5 | 8 | ||
6 | /** | 9 | /** |
7 | * POP3 Account stuff | 10 | * POP3 Account stuff |
8 | */ | 11 | */ |
9 | |||
10 | POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) | 12 | POP3viewItem::POP3viewItem( POP3account *a, QListView *parent ) |
11 | : AccountViewItem( parent ) | 13 | : AccountViewItem( parent ) |
@@ -129,5 +131,10 @@ IMAPfolderItem*IMAPviewItem::findSubItem(const QString&path,IMAPfolderItem*start | |||
129 | void IMAPviewItem::refresh(QList<RecMail>&) | 131 | void IMAPviewItem::refresh(QList<RecMail>&) |
130 | { | 132 | { |
131 | if (childCount()>0) return; | 133 | refreshFolders(false); |
134 | } | ||
135 | |||
136 | void IMAPviewItem::refreshFolders(bool force) | ||
137 | { | ||
138 | if (childCount()>0 && force==false) return; | ||
132 | QList<Folder> *folders = wrapper->listFolders(); | 139 | QList<Folder> *folders = wrapper->listFolders(); |
133 | 140 | ||
@@ -165,5 +172,4 @@ void IMAPviewItem::refresh(QList<RecMail>&) | |||
165 | titem = item; | 172 | titem = item; |
166 | item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); | 173 | item = new IMAPfolderItem(it,pitem,pitem->firstChild(),this); |
167 | item->setSelectable(it->may_select()); | ||
168 | /* setup the short name */ | 174 | /* setup the short name */ |
169 | item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); | 175 | item->setText(0,it->getDisplayName().right(it->getDisplayName().length()-pos-1)); |
@@ -171,5 +177,4 @@ void IMAPviewItem::refresh(QList<RecMail>&) | |||
171 | } else { | 177 | } else { |
172 | item = new IMAPfolderItem( it, this , item ); | 178 | item = new IMAPfolderItem( it, this , item ); |
173 | item->setSelectable(it->may_select()); | ||
174 | } | 179 | } |
175 | } | 180 | } |
@@ -177,4 +182,49 @@ void IMAPviewItem::refresh(QList<RecMail>&) | |||
177 | } | 182 | } |
178 | 183 | ||
184 | QPopupMenu * IMAPviewItem::getContextMenu() | ||
185 | { | ||
186 | QPopupMenu *m = new QPopupMenu(0); | ||
187 | if (m) { | ||
188 | m->insertItem(QObject::tr("Refresh folder list","IMAPviewItem"),0); | ||
189 | m->insertItem(QObject::tr("Create new folder","IMAPviewItem"),1); | ||
190 | m->insertSeparator(); | ||
191 | m->insertItem(QObject::tr("Disconnect","IMAPviewItem"),2); | ||
192 | } | ||
193 | return m; | ||
194 | } | ||
195 | |||
196 | void IMAPviewItem::createNewFolder() | ||
197 | { | ||
198 | Newmdirdlg ndirdlg; | ||
199 | ndirdlg.showMaximized(); | ||
200 | if (ndirdlg.exec()) { | ||
201 | QString ndir = ndirdlg.Newdir(); | ||
202 | bool makesubs = ndirdlg.subpossible(); | ||
203 | QString delemiter = "/"; | ||
204 | IMAPfolderItem*item = (IMAPfolderItem*)firstChild(); | ||
205 | if (item) { | ||
206 | delemiter = item->Delemiter(); | ||
207 | } | ||
208 | if (wrapper->createMbox(ndir,0,delemiter,makesubs)) { | ||
209 | refreshFolders(true); | ||
210 | } | ||
211 | } | ||
212 | } | ||
213 | |||
214 | void IMAPviewItem::contextMenuSelected(int id) | ||
215 | { | ||
216 | qDebug("Id selected: %i",id); | ||
217 | switch (id) { | ||
218 | case 0: | ||
219 | refreshFolders(true); | ||
220 | break; | ||
221 | case 1: | ||
222 | createNewFolder(); | ||
223 | break; | ||
224 | default: | ||
225 | break; | ||
226 | } | ||
227 | } | ||
228 | |||
179 | RecBody IMAPviewItem::fetchBody(const RecMail&) | 229 | RecBody IMAPviewItem::fetchBody(const RecMail&) |
180 | { | 230 | { |
@@ -213,4 +263,9 @@ IMAPfolderItem::IMAPfolderItem( Folder *folderInit, IMAPfolderItem *parent , QLi | |||
213 | } | 263 | } |
214 | 264 | ||
265 | const QString& IMAPfolderItem::Delemiter()const | ||
266 | { | ||
267 | return folder->Separator(); | ||
268 | } | ||
269 | |||
215 | bool IMAPfolderItem::matchName(const QString&name)const | 270 | bool IMAPfolderItem::matchName(const QString&name)const |
216 | { | 271 | { |
@@ -220,6 +275,9 @@ bool IMAPfolderItem::matchName(const QString&name)const | |||
220 | void IMAPfolderItem::refresh(QList<RecMail>&target) | 275 | void IMAPfolderItem::refresh(QList<RecMail>&target) |
221 | { | 276 | { |
222 | if (folder->may_select()) | 277 | if (folder->may_select()) { |
223 | imap->getWrapper()->listMessages( folder->getName(),target ); | 278 | imap->getWrapper()->listMessages( folder->getName(),target ); |
279 | } else { | ||
280 | target.clear(); | ||
281 | } | ||
224 | } | 282 | } |
225 | 283 | ||
@@ -229,4 +287,88 @@ RecBody IMAPfolderItem::fetchBody(const RecMail&aMail) | |||
229 | } | 287 | } |
230 | 288 | ||
289 | QPopupMenu * IMAPfolderItem::getContextMenu() | ||
290 | { | ||
291 | QPopupMenu *m = new QPopupMenu(0); | ||
292 | if (m) { | ||
293 | if (folder->may_select()) { | ||
294 | m->insertItem(QObject::tr("Refresh header list","IMAPfolderItem"),0); | ||
295 | m->insertItem(QObject::tr("Delete all mails","IMAPfolderItem"),1); | ||
296 | } | ||
297 | if (folder->no_inferior()==false) { | ||
298 | m->insertItem(QObject::tr("Create new subfolder","IMAPfolderItem"),2); | ||
299 | } | ||
300 | if (folder->getDisplayName().lower()!="inbox") { | ||
301 | m->insertItem(QObject::tr("Delete folder","IMAPfolderItem"),3); | ||
302 | } | ||
303 | } | ||
304 | return m; | ||
305 | } | ||
306 | |||
307 | void IMAPfolderItem::deleteAllMails() | ||
308 | { | ||
309 | int yesno = QMessageBox::warning(0,QObject::tr("Delete all mails","IMAPfolderItem"), | ||
310 | QObject::tr("<center>Realy delete all mails in box <br>%1</center>","IMAPfolderItem").arg(folder->getDisplayName()), | ||
311 | QObject::tr("Yes","IMAPfolderItem"), | ||
312 | QObject::tr("No","IMAPfolderItem"),QString::null,1,1); | ||
313 | qDebug("Auswahl: %i",yesno); | ||
314 | if (yesno == 0) { | ||
315 | if (imap->getWrapper()->deleteAllMail(folder)) { | ||
316 | AccountView * view = (AccountView*)listView(); | ||
317 | if (view) view->refreshCurrent(); | ||
318 | } | ||
319 | } | ||
320 | } | ||
321 | |||
322 | void IMAPfolderItem::createNewFolder() | ||
323 | { | ||
324 | Newmdirdlg ndirdlg; | ||
325 | ndirdlg.showMaximized(); | ||
326 | if (ndirdlg.exec()) { | ||
327 | QString ndir = ndirdlg.Newdir(); | ||
328 | bool makesubs = ndirdlg.subpossible(); | ||
329 | QString delemiter = Delemiter(); | ||
330 | if (imap->wrapper->createMbox(ndir,folder,delemiter,makesubs)) { | ||
331 | imap->refreshFolders(true); | ||
332 | } | ||
333 | } | ||
334 | } | ||
335 | |||
336 | void IMAPfolderItem::deleteFolder() | ||
337 | { | ||
338 | int yesno = QMessageBox::warning(0,QObject::tr("Delete folder","IMAPfolderItem"), | ||
339 | QObject::tr("<center>Realy delete folder <br><b>%1</b><br>and all if it content?</center>","IMAPfolderItem").arg(folder->getDisplayName()), | ||
340 | QObject::tr("Yes","IMAPfolderItem"), | ||
341 | QObject::tr("No","IMAPfolderItem"),QString::null,1,1); | ||
342 | qDebug("Auswahl: %i",yesno); | ||
343 | if (yesno == 0) { | ||
344 | if (imap->getWrapper()->deleteMbox(folder)) { | ||
345 | /* be carefull - after that this object is destroyd so don't call | ||
346 | * any member of it after that call!!*/ | ||
347 | imap->refreshFolders(true); | ||
348 | } | ||
349 | } | ||
350 | } | ||
351 | |||
352 | void IMAPfolderItem::contextMenuSelected(int id) | ||
353 | { | ||
354 | qDebug("Selected id: %i",id); | ||
355 | AccountView * view = (AccountView*)listView(); | ||
356 | switch(id) { | ||
357 | case 0: | ||
358 | view->refreshCurrent(); | ||
359 | break; | ||
360 | case 1: | ||
361 | deleteAllMails(); | ||
362 | break; | ||
363 | case 2: | ||
364 | createNewFolder(); | ||
365 | break; | ||
366 | case 3: | ||
367 | deleteFolder(); | ||
368 | break; | ||
369 | default: | ||
370 | break; | ||
371 | } | ||
372 | } | ||
231 | 373 | ||
232 | /** | 374 | /** |
@@ -238,8 +380,31 @@ AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) | |||
238 | { | 380 | { |
239 | connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), | 381 | connect( this, SIGNAL( selectionChanged( QListViewItem * ) ), |
240 | SLOT( refresh( QListViewItem * ) ) ); | 382 | SLOT( refresh( QListViewItem * ) ) ); |
383 | connect( this, SIGNAL( mouseButtonPressed(int, QListViewItem *,const QPoint&,int ) ),this, | ||
384 | SLOT( slotHold( int, QListViewItem *,const QPoint&,int ) ) ); | ||
385 | |||
241 | setSorting(0); | 386 | setSorting(0); |
242 | } | 387 | } |
243 | 388 | ||
389 | void AccountView::slotContextMenu(int id) | ||
390 | { | ||
391 | AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); | ||
392 | if (!view) return; | ||
393 | view->contextMenuSelected(id); | ||
394 | } | ||
395 | |||
396 | void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) | ||
397 | { | ||
398 | if (button==1) {return;} | ||
399 | if (!item) return; | ||
400 | AccountViewItem *view = static_cast<AccountViewItem *>(item); | ||
401 | QPopupMenu*m = view->getContextMenu(); | ||
402 | if (!m) return; | ||
403 | connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); | ||
404 | m->setFocus(); | ||
405 | m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); | ||
406 | delete m; | ||
407 | } | ||
408 | |||
244 | void AccountView::populate( QList<Account> list ) | 409 | void AccountView::populate( QList<Account> list ) |
245 | { | 410 | { |
@@ -278,4 +443,5 @@ void AccountView::refresh(QListViewItem *item) { | |||
278 | void AccountView::refreshCurrent() | 443 | void AccountView::refreshCurrent() |
279 | { | 444 | { |
445 | m_currentItem = currentItem(); | ||
280 | if ( !m_currentItem ) return; | 446 | if ( !m_currentItem ) return; |
281 | QList<RecMail> headerlist; | 447 | QList<RecMail> headerlist; |
@@ -379,3 +545,2 @@ RecBody MBOXfolderItem::fetchBody(const RecMail&aMail) | |||
379 | return mbox->getWrapper()->fetchBody(aMail); | 545 | return mbox->getWrapper()->fetchBody(aMail); |
380 | } | 546 | } |
381 | |||