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