-rw-r--r-- | noncore/net/mail/mainwindow.cpp | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp index d3b9c34..a0ce6c1 100644 --- a/noncore/net/mail/mainwindow.cpp +++ b/noncore/net/mail/mainwindow.cpp | |||
@@ -1,241 +1,244 @@ | |||
1 | #include <qlabel.h> | 1 | #include <qlabel.h> |
2 | #include <qvbox.h> | 2 | #include <qvbox.h> |
3 | #include <qheader.h> | 3 | #include <qheader.h> |
4 | #include <qtimer.h> | 4 | #include <qtimer.h> |
5 | #include <qlayout.h> | 5 | #include <qlayout.h> |
6 | #include <qmessagebox.h> | 6 | #include <qmessagebox.h> |
7 | #include <qtextstream.h> | 7 | #include <qtextstream.h> |
8 | 8 | ||
9 | #include <qpe/qpeapplication.h> | 9 | #include <qpe/qpeapplication.h> |
10 | #include <qpe/resource.h> | 10 | #include <qpe/resource.h> |
11 | 11 | ||
12 | #include "defines.h" | 12 | #include "defines.h" |
13 | #include "mainwindow.h" | 13 | #include "mainwindow.h" |
14 | #include "settingsdialog.h" | 14 | #include "settingsdialog.h" |
15 | #include "viewmail.h" | 15 | #include "viewmail.h" |
16 | #include "mailtypes.h" | 16 | #include "mailtypes.h" |
17 | #include "mailistviewitem.h" | 17 | #include "mailistviewitem.h" |
18 | 18 | ||
19 | 19 | ||
20 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) | 20 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) |
21 | : QMainWindow( parent, name, flags ) | 21 | : QMainWindow( parent, name, flags ) |
22 | { | 22 | { |
23 | setCaption( tr( "Mail" ) ); | 23 | setCaption( tr( "Mail" ) ); |
24 | setToolBarsMovable( false ); | 24 | setToolBarsMovable( false ); |
25 | 25 | ||
26 | toolBar = new QToolBar( this ); | 26 | toolBar = new QToolBar( this ); |
27 | menuBar = new QMenuBar( toolBar ); | 27 | menuBar = new QMenuBar( toolBar ); |
28 | mailMenu = new QPopupMenu( menuBar ); | 28 | mailMenu = new QPopupMenu( menuBar ); |
29 | menuBar->insertItem( tr( "Mail" ), mailMenu ); | 29 | menuBar->insertItem( tr( "Mail" ), mailMenu ); |
30 | settingsMenu = new QPopupMenu( menuBar ); | 30 | settingsMenu = new QPopupMenu( menuBar ); |
31 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); | 31 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); |
32 | 32 | ||
33 | addToolBar( toolBar ); | 33 | addToolBar( toolBar ); |
34 | toolBar->setHorizontalStretchable( true ); | 34 | toolBar->setHorizontalStretchable( true ); |
35 | 35 | ||
36 | QLabel *spacer = new QLabel( toolBar ); | 36 | QLabel *spacer = new QLabel( toolBar ); |
37 | spacer->setBackgroundMode( QWidget::PaletteButton ); | 37 | spacer->setBackgroundMode( QWidget::PaletteButton ); |
38 | toolBar->setStretchableWidget( spacer ); | 38 | toolBar->setStretchableWidget( spacer ); |
39 | 39 | ||
40 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, | 40 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, |
41 | 0, 0, this ); | 41 | 0, 0, this ); |
42 | composeMail->addTo( toolBar ); | 42 | composeMail->addTo( toolBar ); |
43 | composeMail->addTo( mailMenu ); | 43 | composeMail->addTo( mailMenu ); |
44 | 44 | ||
45 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, | 45 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, |
46 | 0, 0, this ); | 46 | 0, 0, this ); |
47 | sendQueued->addTo( toolBar ); | 47 | sendQueued->addTo( toolBar ); |
48 | sendQueued->addTo( mailMenu ); | 48 | sendQueued->addTo( mailMenu ); |
49 | 49 | ||
50 | /* | 50 | /* |
51 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, | 51 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, |
52 | 0, 0, this ); | 52 | 0, 0, this ); |
53 | syncFolders->addTo( toolBar ); | 53 | syncFolders->addTo( toolBar ); |
54 | syncFolders->addTo( mailMenu ); | 54 | syncFolders->addTo( mailMenu ); |
55 | */ | 55 | */ |
56 | 56 | ||
57 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, | 57 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, |
58 | 0, 0, this, 0, true ); | 58 | 0, 0, this, 0, true ); |
59 | showFolders->addTo( toolBar ); | 59 | showFolders->addTo( toolBar ); |
60 | showFolders->addTo( mailMenu ); | 60 | showFolders->addTo( mailMenu ); |
61 | showFolders->setOn( true ); | 61 | showFolders->setOn( true ); |
62 | connect(showFolders, SIGNAL( toggled( bool ) ), | 62 | connect(showFolders, SIGNAL( toggled( bool ) ), |
63 | SLOT( slotShowFolders( bool ) ) ); | 63 | SLOT( slotShowFolders( bool ) ) ); |
64 | 64 | ||
65 | /* | 65 | /* |
66 | searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, | 66 | searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, |
67 | 0, 0, this ); | 67 | 0, 0, this ); |
68 | searchMails->addTo( toolBar ); | 68 | searchMails->addTo( toolBar ); |
69 | searchMails->addTo( mailMenu ); | 69 | searchMails->addTo( mailMenu ); |
70 | */ | 70 | */ |
71 | 71 | ||
72 | deleteMails = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); | 72 | deleteMails = new QAction(tr("Delete Mail"), QIconSet(Resource::loadPixmap("mail/delete")), 0, 0, this); |
73 | deleteMails->addTo( toolBar ); | 73 | deleteMails->addTo( toolBar ); |
74 | deleteMails->addTo( mailMenu ); | 74 | deleteMails->addTo( mailMenu ); |
75 | connect( deleteMails, SIGNAL( activated() ), | 75 | connect( deleteMails, SIGNAL( activated() ), |
76 | SLOT( slotDeleteMail() ) ); | 76 | SLOT( slotDeleteMail() ) ); |
77 | 77 | ||
78 | editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, | 78 | editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, |
79 | 0, 0, this ); | 79 | 0, 0, this ); |
80 | editSettings->addTo( settingsMenu ); | 80 | editSettings->addTo( settingsMenu ); |
81 | connect( editSettings, SIGNAL( activated() ), | 81 | connect( editSettings, SIGNAL( activated() ), |
82 | SLOT( slotEditSettings() ) ); | 82 | SLOT( slotEditSettings() ) ); |
83 | 83 | ||
84 | editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, | 84 | editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, |
85 | 0, 0, this ); | 85 | 0, 0, this ); |
86 | editAccounts->addTo( settingsMenu ); | 86 | editAccounts->addTo( settingsMenu ); |
87 | 87 | ||
88 | QWidget *view = new QWidget( this ); | 88 | //setCentralWidget( view ); |
89 | setCentralWidget( view ); | 89 | |
90 | QVBox* wrapperBox = new QVBox( this ); | ||
91 | setCentralWidget( wrapperBox ); | ||
92 | |||
93 | QWidget *view = new QWidget( wrapperBox ); | ||
90 | 94 | ||
91 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); | 95 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); |
92 | 96 | ||
93 | folderView = new AccountView( view ); | 97 | folderView = new AccountView( view ); |
94 | folderView->header()->hide(); | 98 | folderView->header()->hide(); |
95 | folderView->setRootIsDecorated( true ); | 99 | folderView->setRootIsDecorated( true ); |
96 | folderView->addColumn( tr( "Mailbox" ) ); | 100 | folderView->addColumn( tr( "Mailbox" ) ); |
97 | //folderView->hide(); | ||
98 | 101 | ||
99 | layout->addWidget( folderView ); | 102 | layout->addWidget( folderView ); |
100 | 103 | ||
101 | mailView = new QListView( view ); | 104 | mailView = new QListView( view ); |
102 | mailView->addColumn( tr( "" ) ); | 105 | mailView->addColumn( tr( "" ) ); |
103 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); | 106 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); |
104 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); | 107 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); |
105 | mailView->addColumn( tr( "Size" ),QListView::Manual); | 108 | mailView->addColumn( tr( "Size" ),QListView::Manual); |
106 | mailView->addColumn( tr( "Date" )); | 109 | mailView->addColumn( tr( "Date" )); |
107 | mailView->setAllColumnsShowFocus(true); | 110 | mailView->setAllColumnsShowFocus(true); |
108 | mailView->setSorting(-1); | 111 | mailView->setSorting(-1); |
109 | 112 | ||
110 | statusWidget = new StatusWidget( view ); | 113 | statusWidget = new StatusWidget( wrapperBox ); |
114 | statusWidget->hide(); | ||
111 | 115 | ||
112 | layout->addWidget( mailView ); | 116 | layout->addWidget( mailView ); |
113 | layout->addWidget( statusWidget ); | ||
114 | layout->setStretchFactor( folderView, 1 ); | 117 | layout->setStretchFactor( folderView, 1 ); |
115 | layout->setStretchFactor( mailView, 2 ); | 118 | layout->setStretchFactor( mailView, 2 ); |
116 | 119 | ||
117 | 120 | ||
118 | slotAdjustLayout(); | 121 | slotAdjustLayout(); |
119 | 122 | ||
120 | connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this, | 123 | connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this, |
121 | SLOT( displayMail( QListViewItem * ) ) ); | 124 | SLOT( displayMail( QListViewItem * ) ) ); |
122 | 125 | ||
123 | connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); | 126 | connect(folderView, SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); |
124 | 127 | ||
125 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); | 128 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); |
126 | 129 | ||
127 | } | 130 | } |
128 | 131 | ||
129 | 132 | ||
130 | void MainWindow::slotAdjustLayout() { | 133 | void MainWindow::slotAdjustLayout() { |
131 | 134 | ||
132 | QWidget *d = QApplication::desktop(); | 135 | QWidget *d = QApplication::desktop(); |
133 | 136 | ||
134 | if ( d->width() < d->height() ) { | 137 | if ( d->width() < d->height() ) { |
135 | layout->setDirection( QBoxLayout::TopToBottom ); | 138 | layout->setDirection( QBoxLayout::TopToBottom ); |
136 | } else { | 139 | } else { |
137 | layout->setDirection( QBoxLayout::LeftToRight ); | 140 | layout->setDirection( QBoxLayout::LeftToRight ); |
138 | } | 141 | } |
139 | delete d; | 142 | delete d; |
140 | } | 143 | } |
141 | 144 | ||
142 | void MainWindow::slotAdjustColumns() | 145 | void MainWindow::slotAdjustColumns() |
143 | { | 146 | { |
144 | bool hidden = folderView->isHidden(); | 147 | bool hidden = folderView->isHidden(); |
145 | if ( hidden ) folderView->show(); | 148 | if ( hidden ) folderView->show(); |
146 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); | 149 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); |
147 | if ( hidden ) folderView->hide(); | 150 | if ( hidden ) folderView->hide(); |
148 | 151 | ||
149 | mailView->setColumnWidth( 0, 10 ); | 152 | mailView->setColumnWidth( 0, 10 ); |
150 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); | 153 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); |
151 | mailView->setColumnWidth( 2, 80 ); | 154 | mailView->setColumnWidth( 2, 80 ); |
152 | mailView->setColumnWidth( 3, 50 ); | 155 | mailView->setColumnWidth( 3, 50 ); |
153 | mailView->setColumnWidth( 4, 50 ); | 156 | mailView->setColumnWidth( 4, 50 ); |
154 | } | 157 | } |
155 | 158 | ||
156 | void MainWindow::slotEditSettings() { | 159 | void MainWindow::slotEditSettings() { |
157 | SettingsDialog settingsDialog( this, 0, true ); | 160 | SettingsDialog settingsDialog( this, 0, true ); |
158 | settingsDialog.showMaximized(); | 161 | settingsDialog.showMaximized(); |
159 | settingsDialog.exec(); | 162 | settingsDialog.exec(); |
160 | } | 163 | } |
161 | 164 | ||
162 | void MainWindow::slotShowFolders( bool show ) | 165 | void MainWindow::slotShowFolders( bool show ) |
163 | { | 166 | { |
164 | qDebug( "Show Folders" ); | 167 | qDebug( "Show Folders" ); |
165 | if ( show && folderView->isHidden() ) { | 168 | if ( show && folderView->isHidden() ) { |
166 | qDebug( "-> showing" ); | 169 | qDebug( "-> showing" ); |
167 | folderView->show(); | 170 | folderView->show(); |
168 | } else if ( !show && !folderView->isHidden() ) { | 171 | } else if ( !show && !folderView->isHidden() ) { |
169 | qDebug( "-> hiding" ); | 172 | qDebug( "-> hiding" ); |
170 | folderView->hide(); | 173 | folderView->hide(); |
171 | } | 174 | } |
172 | } | 175 | } |
173 | 176 | ||
174 | void MainWindow::refreshMailView(QList<RecMail>*list) | 177 | void MainWindow::refreshMailView(QList<RecMail>*list) |
175 | { | 178 | { |
176 | MailListViewItem*item = 0; | 179 | MailListViewItem*item = 0; |
177 | mailView->clear(); | 180 | mailView->clear(); |
178 | for (unsigned int i = 0; i < list->count();++i) { | 181 | for (unsigned int i = 0; i < list->count();++i) { |
179 | item = new MailListViewItem(mailView,item); | 182 | item = new MailListViewItem(mailView,item); |
180 | item->storeData(*(list->at(i))); | 183 | item->storeData(*(list->at(i))); |
181 | item->showEntry(); | 184 | item->showEntry(); |
182 | } | 185 | } |
183 | } | 186 | } |
184 | void MainWindow::displayMail(QListViewItem*item) | 187 | void MainWindow::displayMail(QListViewItem*item) |
185 | { | 188 | { |
186 | 189 | ||
187 | if (!item) return; | 190 | if (!item) return; |
188 | RecMail mail = ((MailListViewItem*)item)->data(); | 191 | RecMail mail = ((MailListViewItem*)item)->data(); |
189 | RecBody body = folderView->fetchBody(mail); | 192 | RecBody body = folderView->fetchBody(mail); |
190 | 193 | ||
191 | ViewMail readMail( this ); | 194 | ViewMail readMail( this ); |
192 | readMail.setBody( body ); | 195 | readMail.setBody( body ); |
193 | readMail.setMail( mail ); | 196 | readMail.setMail( mail ); |
194 | readMail.showMaximized(); | 197 | readMail.showMaximized(); |
195 | readMail.exec(); | 198 | readMail.exec(); |
196 | 199 | ||
197 | if ( readMail.deleted ) { | 200 | if ( readMail.deleted ) { |
198 | folderView->refreshCurrent(); | 201 | folderView->refreshCurrent(); |
199 | } else { | 202 | } else { |
200 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") ); | 203 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "") ); |
201 | } | 204 | } |
202 | } | 205 | } |
203 | 206 | ||
204 | void MainWindow::slotDeleteMail() | 207 | void MainWindow::slotDeleteMail() |
205 | { | 208 | { |
206 | if (!mailView->currentItem()) return; | 209 | if (!mailView->currentItem()) return; |
207 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); | 210 | RecMail mail = ((MailListViewItem*)mailView->currentItem() )->data(); |
208 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { | 211 | if ( QMessageBox::warning(this, tr("Delete Mail"), QString( tr("<p>Do you really want to delete this mail? <br><br>" ) + mail.getFrom() + " - " + mail.getSubject() ) , QMessageBox::Yes, QMessageBox::No ) == QMessageBox::Yes ) { |
209 | mail.Wrapper()->deleteMail( mail ); | 212 | mail.Wrapper()->deleteMail( mail ); |
210 | folderView->refreshCurrent(); | 213 | folderView->refreshCurrent(); |
211 | } | 214 | } |
212 | } | 215 | } |
213 | 216 | ||
214 | 217 | ||
215 | 218 | ||
216 | MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) | 219 | MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) |
217 | :QListViewItem(parent,item),mail_data() | 220 | :QListViewItem(parent,item),mail_data() |
218 | { | 221 | { |
219 | } | 222 | } |
220 | 223 | ||
221 | void MailListViewItem::showEntry() | 224 | void MailListViewItem::showEntry() |
222 | { | 225 | { |
223 | if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) { | 226 | if ( mail_data.getFlags().testBit( FLAG_ANSWERED ) == true) { |
224 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") ); | 227 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgreplied") ); |
225 | } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { | 228 | } else if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { |
226 | /* I think it looks nicer if there are not such a log of icons but only on mails | 229 | /* I think it looks nicer if there are not such a log of icons but only on mails |
227 | replied or new - Alwin*/ | 230 | replied or new - Alwin*/ |
228 | //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") ); | 231 | //setPixmap( 0, Resource::loadPixmap( "mail/kmmsgunseen") ); |
229 | } else { | 232 | } else { |
230 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") ); | 233 | setPixmap( 0, Resource::loadPixmap( "mail/kmmsgnew") ); |
231 | } | 234 | } |
232 | double s = mail_data.Msgsize(); | 235 | double s = mail_data.Msgsize(); |
233 | int w; | 236 | int w; |
234 | w=0; | 237 | w=0; |
235 | 238 | ||
236 | while (s>1024) { | 239 | while (s>1024) { |
237 | s/=1024; | 240 | s/=1024; |
238 | ++w; | 241 | ++w; |
239 | if (w>=2) break; | 242 | if (w>=2) break; |
240 | } | 243 | } |
241 | 244 | ||