summaryrefslogtreecommitdiffabout
path: root/kmicromail/accountview.cpp
Unidiff
Diffstat (limited to 'kmicromail/accountview.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--kmicromail/accountview.cpp30
1 files changed, 16 insertions, 14 deletions
diff --git a/kmicromail/accountview.cpp b/kmicromail/accountview.cpp
index d1d4f7e..eea1f65 100644
--- a/kmicromail/accountview.cpp
+++ b/kmicromail/accountview.cpp
@@ -1,263 +1,265 @@
1 1
2#include "accountview.h" 2#include "accountview.h"
3#include "accountitem.h" 3#include "accountitem.h"
4#include "selectstore.h" 4#include "selectstore.h"
5 5
6#include <libmailwrapper/settings.h> 6#include <libmailwrapper/settings.h>
7#include <libmailwrapper/mailwrapper.h> 7#include <libmailwrapper/mailwrapper.h>
8#include <libmailwrapper/mailtypes.h> 8#include <libmailwrapper/mailtypes.h>
9#include <libmailwrapper/abstractmail.h> 9#include <libmailwrapper/abstractmail.h>
10 10
11/* OPIE */ 11/* OPIE */
12#include <qpe/qpeapplication.h> 12#include <qpe/qpeapplication.h>
13 13
14/* QT */ 14/* QT */
15#include <qmessagebox.h> 15#include <qmessagebox.h>
16#include <qpopupmenu.h> 16#include <q3popupmenu.h>
17#include <qcheckbox.h> 17#include <qcheckbox.h>
18#include <qtimer.h> 18#include <qtimer.h>
19#include <qspinbox.h> 19#include <qspinbox.h>
20//Added by qt3to4:
21#include <Q3ValueList>
20#include <klocale.h> 22#include <klocale.h>
21#include <kmessagebox.h> 23#include <kmessagebox.h>
22 24
23using namespace Opie::Core; 25using namespace Opie::Core;
24AccountView::AccountView( QWidget *parent, const char *name, WFlags flags ) 26AccountView::AccountView( QWidget *parent, const char *name, Qt::WFlags flags )
25 : QListView( parent, name, flags ) 27 : Q3ListView( parent, name, flags )
26{ 28{
27 //connect( this, SIGNAL( selectionChanged(QListViewItem*) ), 29 //connect( this, SIGNAL( selectionChanged(QListViewItem*) ),
28 // SLOT( refresh(QListViewItem*) ) ); 30 // SLOT( refresh(QListViewItem*) ) );
29 connect( this, SIGNAL( clicked(QListViewItem*) ), 31 connect( this, SIGNAL( clicked(Q3ListViewItem*) ),
30 SLOT( refresh(QListViewItem*) ) ); 32 SLOT( refresh(Q3ListViewItem*) ) );
31 connect( this, SIGNAL( returnPressed(QListViewItem*) ), 33 connect( this, SIGNAL( returnPressed(Q3ListViewItem*) ),
32 SLOT( refresh(QListViewItem*) ) ); 34 SLOT( refresh(Q3ListViewItem*) ) );
33 connect( this, SIGNAL( mouseButtonPressed(int,QListViewItem*,const QPoint&,int) ),this, 35 connect( this, SIGNAL( mouseButtonPressed(int,Q3ListViewItem*,const QPoint&,int) ),this,
34 SLOT( slotHold(int,QListViewItem*,const QPoint&,int) ) ); 36 SLOT( slotHold(int,Q3ListViewItem*,const QPoint&,int) ) );
35 setSorting(0); 37 setSorting(0);
36} 38}
37 39
38AccountView::~AccountView() 40AccountView::~AccountView()
39{ 41{
40 imapAccounts.clear(); 42 imapAccounts.clear();
41 mhAccounts.clear(); 43 mhAccounts.clear();
42} 44}
43 45
44void AccountView::slotContextMenu(int id) 46void AccountView::slotContextMenu(int id)
45{ 47{
46 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 48 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
47 if (!view) return; 49 if (!view) return;
48 view->contextMenuSelected(id); 50 view->contextMenuSelected(id);
49} 51}
50 52
51void AccountView::slotHold(int button, QListViewItem * item,const QPoint&,int) 53void AccountView::slotHold(int button, Q3ListViewItem * item,const QPoint&,int)
52{ 54{
53 if (button==1) {return;} 55 if (button==1) {return;}
54 if (!item) return; 56 if (!item) return;
55 AccountViewItem *view = static_cast<AccountViewItem *>(item); 57 AccountViewItem *view = static_cast<AccountViewItem *>(item);
56 QPopupMenu*m = view->getContextMenu(); 58 Q3PopupMenu*m = view->getContextMenu();
57 if (!m) return; 59 if (!m) return;
58 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int))); 60 connect(m,SIGNAL(activated(int)),this,SLOT(slotContextMenu(int)));
59 m->setFocus(); 61 m->setFocus();
60 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) ); 62 m->exec( QPoint( QCursor::pos().x(), QCursor::pos().y()) );
61 delete m; 63 delete m;
62} 64}
63 65
64void AccountView::populate( QList<Account> list ) 66void AccountView::populate( QList<Account> list )
65{ 67{
66 clear(); 68 clear();
67 69
68 imapAccounts.clear(); 70 imapAccounts.clear();
69 mhAccounts.clear(); 71 mhAccounts.clear();
70 72
71 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this)); 73 mhAccounts.append(new MHviewItem(AbstractMail::defaultLocalfolder(),this));
72 74
73 Account *it; 75 Account *it;
74 for ( it = list.first(); it; it = list.next() ) 76 for ( it = list.first(); it; it = list.next() )
75 { 77 {
76 if ( it->getType() == MAILLIB::A_IMAP ) 78 if ( it->getType() == MAILLIB::A_IMAP )
77 { 79 {
78 IMAPaccount *imap = static_cast<IMAPaccount *>(it); 80 IMAPaccount *imap = static_cast<IMAPaccount *>(it);
79 imapAccounts.append(new IMAPviewItem( imap, this )); 81 imapAccounts.append(new IMAPviewItem( imap, this ));
80 } 82 }
81 else if ( it->getType() == MAILLIB::A_POP3 ) 83 else if ( it->getType() == MAILLIB::A_POP3 )
82 { 84 {
83 POP3account *pop3 = static_cast<POP3account *>(it); 85 POP3account *pop3 = static_cast<POP3account *>(it);
84 /* must not be hold 'cause it isn't required */ 86 /* must not be hold 'cause it isn't required */
85 (void) new POP3viewItem( pop3, this ); 87 (void) new POP3viewItem( pop3, this );
86 } 88 }
87 else if ( it->getType() == MAILLIB::A_NNTP ) 89 else if ( it->getType() == MAILLIB::A_NNTP )
88 { 90 {
89 NNTPaccount *nntp = static_cast<NNTPaccount *>(it); 91 NNTPaccount *nntp = static_cast<NNTPaccount *>(it);
90 /* must not be hold 'cause it isn't required */ 92 /* must not be hold 'cause it isn't required */
91 (void) new NNTPviewItem( nntp, this ); 93 (void) new NNTPviewItem( nntp, this );
92 } 94 }
93 } 95 }
94} 96}
95 97
96void AccountView::refresh(QListViewItem *item) 98void AccountView::refresh(Q3ListViewItem *item)
97{ 99{
98 if ( item ) 100 if ( item )
99 { 101 {
100 bool ask = true; 102 bool ask = true;
101 //qDebug("text -%s- ",item->text( 0 ).latin1() ); 103 //qDebug("text -%s- ",item->text( 0 ).latin1() );
102 if ( item->text( 0 ) == i18n (" Local Mailfolders") ) 104 if ( item->text( 0 ) == i18n (" Local Mailfolders") )
103 ask = false; 105 ask = false;
104 else { 106 else {
105 if ( item->parent() ) 107 if ( item->parent() )
106 if ( item->parent()->text( 0 ) == i18n (" Local Mailfolders") ) 108 if ( item->parent()->text( 0 ) == i18n (" Local Mailfolders") )
107 ask = false; 109 ask = false;
108 } 110 }
109 if ( ask ) { 111 if ( ask ) {
110 int result = KMessageBox::warningContinueCancel(this, 112 int result = KMessageBox::warningContinueCancel(this,
111 i18n("Refresh\n%1\n?").arg( item->text(0) ), 113 i18n("Refresh\n%1\n?").arg( item->text(0) ),
112 i18n("Refresh"),i18n("Refresh"),i18n("Cancel"), 114 i18n("Refresh"),i18n("Refresh"),i18n("Cancel"),
113 true); 115 true);
114 if (result != KMessageBox::Continue) return; 116 if (result != KMessageBox::Continue) return;
115 } 117 }
116 m_currentItem = item; 118 m_currentItem = item;
117 topLevelWidget()->setCaption( i18n ( "Refreshing %1 ... please wait" ). arg ( m_currentItem->text( 0 ) ) ) ; 119 topLevelWidget()->setCaption( i18n ( "Refreshing %1 ... please wait" ). arg ( m_currentItem->text( 0 ) ) ) ;
118 QTimer::singleShot( 500, this, SLOT ( refreshCurrentSelected() ) ); 120 QTimer::singleShot( 500, this, SLOT ( refreshCurrentSelected() ) );
119 121
120 } 122 }
121} 123}
122void AccountView::refreshOutgoing() 124void AccountView::refreshOutgoing()
123{ 125{
124 m_currentItem = currentItem(); 126 m_currentItem = currentItem();
125 if ( !m_currentItem ) return; 127 if ( !m_currentItem ) return;
126 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 128 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
127 if ( !view->getFolder() ) 129 if ( !view->getFolder() )
128 return; 130 return;
129 QString bName = view->getFolder()->getDisplayName(); 131 QString bName = view->getFolder()->getDisplayName();
130 if (bName.startsWith("/")&&bName.length()>1) 132 if (bName.startsWith("/")&&bName.length()>1)
131 { 133 {
132 bName.replace(0,1,""); 134 bName.replace(0,1,"");
133 } 135 }
134 int pos = bName.findRev("/"); 136 int pos = bName.findRev("/");
135 if (pos > 0) 137 if (pos > 0)
136 { 138 {
137 bName.replace(0,pos+1,""); 139 bName.replace(0,pos+1,"");
138 } 140 }
139 //qDebug("name *%s* ",bName.lower().latin1() ); 141 //qDebug("name *%s* ",bName.lower().latin1() );
140 if ( bName.lower() == "outgoing" || bName.lower() == "sent" || bName.lower() == "sendfailed" ) { 142 if ( bName.lower() == "outgoing" || bName.lower() == "sent" || bName.lower() == "sendfailed" ) {
141 refreshCurrent(); 143 refreshCurrent();
142 // qDebug("refresh "); 144 // qDebug("refresh ");
143 } 145 }
144} 146}
145void AccountView::refreshCurrentSelected() 147void AccountView::refreshCurrentSelected()
146{ 148{
147 if ( !m_currentItem ) return; 149 if ( !m_currentItem ) return;
148 QValueList<RecMailP> headerlist; 150 Q3ValueList<RecMailP> headerlist;
149 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem); 151 AccountViewItem *view = static_cast<AccountViewItem *>(m_currentItem);
150 view->refresh(headerlist); 152 view->refresh(headerlist);
151 emit refreshMailview(headerlist); 153 emit refreshMailview(headerlist);
152 topLevelWidget()->setCaption( i18n ( "KOpieMail/Pi" ) ) ; 154 topLevelWidget()->setCaption( i18n ( "KOpieMail/Pi" ) ) ;
153} 155}
154 156
155void AccountView::refreshCurrent() 157void AccountView::refreshCurrent()
156{ 158{
157 m_currentItem = currentItem(); 159 m_currentItem = currentItem();
158 if ( !m_currentItem ) return; 160 if ( !m_currentItem ) return;
159 topLevelWidget()->setCaption( i18n ( "Refreshing %1 ... please wait" ). arg ( m_currentItem->text( 0 ) ) ) ; 161 topLevelWidget()->setCaption( i18n ( "Refreshing %1 ... please wait" ). arg ( m_currentItem->text( 0 ) ) ) ;
160 QTimer::singleShot( 500, this, SLOT ( refreshCurrentSelected() ) ); 162 QTimer::singleShot( 500, this, SLOT ( refreshCurrentSelected() ) );
161} 163}
162 164
163void AccountView::refreshAll() 165void AccountView::refreshAll()
164{ 166{
165} 167}
166 168
167RecBodyP AccountView::fetchBody(const RecMailP&aMail) 169RecBodyP AccountView::fetchBody(const RecMailP&aMail)
168{ 170{
169 QListViewItem*item = selectedItem (); 171 Q3ListViewItem*item = selectedItem ();
170 if (!item) return new RecBody(); 172 if (!item) return new RecBody();
171 AccountViewItem *view = static_cast<AccountViewItem *>(item); 173 AccountViewItem *view = static_cast<AccountViewItem *>(item);
172 return view->fetchBody(aMail); 174 return view->fetchBody(aMail);
173} 175}
174 176
175void AccountView::setupFolderselect(Selectstore*sels) 177void AccountView::setupFolderselect(Selectstore*sels)
176{ 178{
177 179
178#ifndef DESKTOP_VERSION 180#ifndef DESKTOP_VERSION
179 sels->showMaximized(); 181 sels->showMaximized();
180#else 182#else
181 sels->show(); 183 sels->show();
182#endif 184#endif
183 QStringList sFolders; 185 QStringList sFolders;
184 unsigned int i = 0; 186 unsigned int i = 0;
185 for (i=0; i < mhAccounts.count();++i) 187 for (i=0; i < mhAccounts.count();++i)
186 { 188 {
187 mhAccounts[i]->refresh(false); 189 mhAccounts[i]->refresh(false);
188 sFolders = mhAccounts[i]->subFolders(); 190 sFolders = mhAccounts[i]->subFolders();
189 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders); 191 sels->addAccounts(mhAccounts[i]->getWrapper(),sFolders);
190 } 192 }
191 for (i=0; i < imapAccounts.count();++i) 193 for (i=0; i < imapAccounts.count();++i)
192 { 194 {
193 if (imapAccounts[i]->offline()) 195 if (imapAccounts[i]->offline())
194 continue; 196 continue;
195 imapAccounts[i]->refreshFolders(false); 197 imapAccounts[i]->refreshFolders(false);
196 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders()); 198 sels->addAccounts(imapAccounts[i]->getWrapper(),imapAccounts[i]->subFolders());
197 } 199 }
198} 200}
199void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper) 201void AccountView::downloadMailsInbox(const FolderP&fromFolder,AbstractMail*fromWrapper)
200{ 202{
201#if 0 203#if 0
202 AbstractMail*targetMail = 0; 204 AbstractMail*targetMail = 0;
203 QString targetFolder = ""; 205 QString targetFolder = "";
204 Selectstore sels; 206 Selectstore sels;
205 setupFolderselect(&sels); 207 setupFolderselect(&sels);
206 if (!sels.exec()) return; 208 if (!sels.exec()) return;
207 targetMail = sels.currentMail(); 209 targetMail = sels.currentMail();
208 targetFolder = sels.currentFolder(); 210 targetFolder = sels.currentFolder();
209 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 211 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
210 targetFolder.isEmpty()) 212 targetFolder.isEmpty())
211 { 213 {
212 return; 214 return;
213 } 215 }
214 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 216 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
215 { 217 {
216 QMessageBox::critical(0,i18n("Error creating new Folder"), 218 QMessageBox::critical(0,i18n("Error creating new Folder"),
217 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 219 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
218 return; 220 return;
219 } 221 }
220 int maxsize = 0; 222 int maxsize = 0;
221 if ( sels.useSize->isChecked()) 223 if ( sels.useSize->isChecked())
222 maxsize = sels.sizeSpinBox->value(); 224 maxsize = sels.sizeSpinBox->value();
223 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); 225 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize);
224#endif 226#endif
225 fromWrapper->downloadNewMails( fromFolder, mhAccounts[0]->getWrapper()); 227 fromWrapper->downloadNewMails( fromFolder, mhAccounts[0]->getWrapper());
226 refreshCurrent(); 228 refreshCurrent();
227 229
228} 230}
229 231
230void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper) 232void AccountView::downloadMails(const FolderP&fromFolder,AbstractMail*fromWrapper)
231{ 233{
232 AbstractMail*targetMail = 0; 234 AbstractMail*targetMail = 0;
233 QString targetFolder = ""; 235 QString targetFolder = "";
234 Selectstore sels; 236 Selectstore sels;
235 setupFolderselect(&sels); 237 setupFolderselect(&sels);
236 if (!sels.exec()) return; 238 if (!sels.exec()) return;
237 targetMail = sels.currentMail(); 239 targetMail = sels.currentMail();
238 targetFolder = sels.currentFolder(); 240 targetFolder = sels.currentFolder();
239 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) || 241 if ( (fromWrapper==targetMail && fromFolder->getName()==targetFolder) ||
240 targetFolder.isEmpty()) 242 targetFolder.isEmpty())
241 { 243 {
242 return; 244 return;
243 } 245 }
244 if (sels.newFolder() && !targetMail->createMbox(targetFolder)) 246 if (sels.newFolder() && !targetMail->createMbox(targetFolder))
245 { 247 {
246 QMessageBox::critical(0,i18n("Error creating new Folder"), 248 QMessageBox::critical(0,i18n("Error creating new Folder"),
247 i18n("<center>Error while creating<br>new folder - breaking.</center>")); 249 i18n("<center>Error while creating<br>new folder - breaking.</center>"));
248 return; 250 return;
249 } 251 }
250 int maxsize = 0; 252 int maxsize = 0;
251 if ( sels.useSize->isChecked()) 253 if ( sels.useSize->isChecked())
252 maxsize = sels.sizeSpinBox->value(); 254 maxsize = sels.sizeSpinBox->value();
253 255
254 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize); 256 fromWrapper->mvcpAllMails(fromFolder,targetFolder,targetMail,sels.moveMails(), maxsize);
255 refreshCurrent(); 257 refreshCurrent();
256} 258}
257 259
258bool AccountView::currentisDraft() 260bool AccountView::currentisDraft()
259{ 261{
260 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem()); 262 AccountViewItem *view = static_cast<AccountViewItem *>(currentItem());
261 if (!view) return false; 263 if (!view) return false;
262 return view->isDraftfolder(); 264 return view->isDraftfolder();
263} 265}