author | harlekin <harlekin> | 2003-12-13 13:45:40 (UTC) |
---|---|---|
committer | harlekin <harlekin> | 2003-12-13 13:45:40 (UTC) |
commit | e1dc235a829398482dddc66b931d6eec840382ec (patch) (unidiff) | |
tree | b4a93390a382eb9ce2f9c9a3703e4f03c3e475e0 | |
parent | 865b023c57f657c8eff26baa670fc76bbcd548e4 (diff) | |
download | opie-e1dc235a829398482dddc66b931d6eec840382ec.zip opie-e1dc235a829398482dddc66b931d6eec840382ec.tar.gz opie-e1dc235a829398482dddc66b931d6eec840382ec.tar.bz2 |
beginning of attachment handling ( user side )
-rw-r--r-- | noncore/net/mail/mainwindow.cpp | 6 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 56 | ||||
-rw-r--r-- | noncore/net/mail/viewmail.h | 2 |
3 files changed, 59 insertions, 5 deletions
diff --git a/noncore/net/mail/mainwindow.cpp b/noncore/net/mail/mainwindow.cpp index f0a915d..560715c 100644 --- a/noncore/net/mail/mainwindow.cpp +++ b/noncore/net/mail/mainwindow.cpp | |||
@@ -1,193 +1,195 @@ | |||
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 | 6 | ||
7 | #include <qpe/qpeapplication.h> | 7 | #include <qpe/qpeapplication.h> |
8 | #include <qpe/resource.h> | 8 | #include <qpe/resource.h> |
9 | 9 | ||
10 | #include "defines.h" | 10 | #include "defines.h" |
11 | #include "mainwindow.h" | 11 | #include "mainwindow.h" |
12 | #include "viewmail.h" | 12 | #include "viewmail.h" |
13 | #include "mailtypes.h" | 13 | #include "mailtypes.h" |
14 | #include "mailistviewitem.h" | 14 | #include "mailistviewitem.h" |
15 | 15 | ||
16 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) | 16 | MainWindow::MainWindow( QWidget *parent, const char *name, WFlags flags ) |
17 | : QMainWindow( parent, name, flags ) | 17 | : QMainWindow( parent, name, flags ) |
18 | { | 18 | { |
19 | setCaption( tr( "Mail" ) ); | 19 | setCaption( tr( "Mail" ) ); |
20 | setToolBarsMovable( false ); | 20 | setToolBarsMovable( false ); |
21 | 21 | ||
22 | toolBar = new QToolBar( this ); | 22 | toolBar = new QToolBar( this ); |
23 | menuBar = new QMenuBar( toolBar ); | 23 | menuBar = new QMenuBar( toolBar ); |
24 | mailMenu = new QPopupMenu( menuBar ); | 24 | mailMenu = new QPopupMenu( menuBar ); |
25 | menuBar->insertItem( tr( "Mail" ), mailMenu ); | 25 | menuBar->insertItem( tr( "Mail" ), mailMenu ); |
26 | settingsMenu = new QPopupMenu( menuBar ); | 26 | settingsMenu = new QPopupMenu( menuBar ); |
27 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); | 27 | menuBar->insertItem( tr( "Settings" ), settingsMenu ); |
28 | 28 | ||
29 | addToolBar( toolBar ); | 29 | addToolBar( toolBar ); |
30 | toolBar->setHorizontalStretchable( true ); | 30 | toolBar->setHorizontalStretchable( true ); |
31 | 31 | ||
32 | QLabel *spacer = new QLabel( toolBar ); | 32 | QLabel *spacer = new QLabel( toolBar ); |
33 | spacer->setBackgroundMode( QWidget::PaletteButton ); | 33 | spacer->setBackgroundMode( QWidget::PaletteButton ); |
34 | toolBar->setStretchableWidget( spacer ); | 34 | toolBar->setStretchableWidget( spacer ); |
35 | 35 | ||
36 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, | 36 | composeMail = new QAction( tr( "Compose new mail" ), ICON_COMPOSEMAIL, |
37 | 0, 0, this ); | 37 | 0, 0, this ); |
38 | composeMail->addTo( toolBar ); | 38 | composeMail->addTo( toolBar ); |
39 | composeMail->addTo( mailMenu ); | 39 | composeMail->addTo( mailMenu ); |
40 | 40 | ||
41 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, | 41 | sendQueued = new QAction( tr( "Send queued mails" ), ICON_SENDQUEUED, |
42 | 0, 0, this ); | 42 | 0, 0, this ); |
43 | sendQueued->addTo( toolBar ); | 43 | sendQueued->addTo( toolBar ); |
44 | sendQueued->addTo( mailMenu ); | 44 | sendQueued->addTo( mailMenu ); |
45 | 45 | ||
46 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, | 46 | syncFolders = new QAction( tr( "Sync mailfolders" ), ICON_SYNC, |
47 | 0, 0, this ); | 47 | 0, 0, this ); |
48 | syncFolders->addTo( toolBar ); | 48 | syncFolders->addTo( toolBar ); |
49 | syncFolders->addTo( mailMenu ); | 49 | syncFolders->addTo( mailMenu ); |
50 | 50 | ||
51 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, | 51 | showFolders = new QAction( tr( "Show/Hide folders" ), ICON_SHOWFOLDERS, |
52 | 0, 0, this, 0, true ); | 52 | 0, 0, this, 0, true ); |
53 | showFolders->addTo( toolBar ); | 53 | showFolders->addTo( toolBar ); |
54 | showFolders->addTo( mailMenu ); | 54 | showFolders->addTo( mailMenu ); |
55 | connect(showFolders, SIGNAL( toggled( bool ) ), | 55 | connect(showFolders, SIGNAL( toggled( bool ) ), |
56 | SLOT( slotShowFolders( bool ) ) ); | 56 | SLOT( slotShowFolders( bool ) ) ); |
57 | 57 | ||
58 | searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, | 58 | searchMails = new QAction( tr( "Search mails" ), ICON_SEARCHMAILS, |
59 | 0, 0, this ); | 59 | 0, 0, this ); |
60 | searchMails->addTo( toolBar ); | 60 | searchMails->addTo( toolBar ); |
61 | searchMails->addTo( mailMenu ); | 61 | searchMails->addTo( mailMenu ); |
62 | 62 | ||
63 | 63 | ||
64 | editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, | 64 | editSettings = new QAction( tr( "Edit settings" ), ICON_EDITSETTINGS, |
65 | 0, 0, this ); | 65 | 0, 0, this ); |
66 | editSettings->addTo( settingsMenu ); | 66 | editSettings->addTo( settingsMenu ); |
67 | 67 | ||
68 | editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, | 68 | editAccounts = new QAction( tr( "Configure accounts" ), ICON_EDITACCOUNTS, |
69 | 0, 0, this ); | 69 | 0, 0, this ); |
70 | editAccounts->addTo( settingsMenu ); | 70 | editAccounts->addTo( settingsMenu ); |
71 | 71 | ||
72 | QWidget *view = new QWidget( this ); | 72 | QWidget *view = new QWidget( this ); |
73 | setCentralWidget( view ); | 73 | setCentralWidget( view ); |
74 | 74 | ||
75 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); | 75 | layout = new QBoxLayout ( view, QBoxLayout::LeftToRight ); |
76 | 76 | ||
77 | folderView = new AccountView( view ); | 77 | folderView = new AccountView( view ); |
78 | folderView->header()->hide(); | 78 | folderView->header()->hide(); |
79 | folderView->addColumn( tr( "Mailbox" ) ); | 79 | folderView->addColumn( tr( "Mailbox" ) ); |
80 | folderView->hide(); | 80 | folderView->hide(); |
81 | 81 | ||
82 | layout->addWidget( folderView ); | 82 | layout->addWidget( folderView ); |
83 | 83 | ||
84 | mailView = new QListView( view ); | 84 | mailView = new QListView( view ); |
85 | mailView->addColumn( tr( "Status" ) ); | 85 | mailView->addColumn( tr( "Status" ) ); |
86 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); | 86 | mailView->addColumn( tr( "Subject" ),QListView::Manual ); |
87 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); | 87 | mailView->addColumn( tr( "Sender" ),QListView::Manual ); |
88 | mailView->addColumn( tr( "Date" )); | 88 | mailView->addColumn( tr( "Date" )); |
89 | mailView->setAllColumnsShowFocus(true); | 89 | mailView->setAllColumnsShowFocus(true); |
90 | mailView->setSorting(-1); | 90 | mailView->setSorting(-1); |
91 | 91 | ||
92 | layout->addWidget( mailView ); | 92 | layout->addWidget( mailView ); |
93 | layout->setStretchFactor( folderView, 1 ); | 93 | layout->setStretchFactor( folderView, 1 ); |
94 | layout->setStretchFactor( mailView, 2 ); | 94 | layout->setStretchFactor( mailView, 2 ); |
95 | 95 | ||
96 | slotAdjustLayout(); | 96 | slotAdjustLayout(); |
97 | 97 | ||
98 | connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this, | 98 | connect( mailView, SIGNAL( clicked( QListViewItem * ) ),this, |
99 | SLOT( displayMail( QListViewItem * ) ) ); | 99 | SLOT( displayMail( QListViewItem * ) ) ); |
100 | 100 | ||
101 | connect(folderView,SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); | 101 | connect(folderView,SIGNAL(refreshMailview(QList<RecMail>*)),this,SLOT(refreshMailView(QList<RecMail>*))); |
102 | 102 | ||
103 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); | 103 | QTimer::singleShot( 1000, this, SLOT( slotAdjustColumns() ) ); |
104 | } | 104 | } |
105 | 105 | ||
106 | 106 | ||
107 | void MainWindow::slotAdjustLayout() { | 107 | void MainWindow::slotAdjustLayout() { |
108 | 108 | ||
109 | QWidget *d = QApplication::desktop(); | 109 | QWidget *d = QApplication::desktop(); |
110 | 110 | ||
111 | if ( d->width() < d->height() ) { | 111 | if ( d->width() < d->height() ) { |
112 | layout->setDirection( QBoxLayout::TopToBottom ); | 112 | layout->setDirection( QBoxLayout::TopToBottom ); |
113 | } else { | 113 | } else { |
114 | layout->setDirection( QBoxLayout::LeftToRight ); | 114 | layout->setDirection( QBoxLayout::LeftToRight ); |
115 | } | 115 | } |
116 | delete d; | 116 | delete d; |
117 | } | 117 | } |
118 | 118 | ||
119 | void MainWindow::slotAdjustColumns() | 119 | void MainWindow::slotAdjustColumns() |
120 | { | 120 | { |
121 | bool hidden = folderView->isHidden(); | 121 | bool hidden = folderView->isHidden(); |
122 | if ( hidden ) folderView->show(); | 122 | if ( hidden ) folderView->show(); |
123 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); | 123 | folderView->setColumnWidth( 0, folderView->visibleWidth() ); |
124 | if ( hidden ) folderView->hide(); | 124 | if ( hidden ) folderView->hide(); |
125 | 125 | ||
126 | mailView->setColumnWidth( 0, 10 ); | 126 | mailView->setColumnWidth( 0, 10 ); |
127 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); | 127 | mailView->setColumnWidth( 1, mailView->visibleWidth() - 130 ); |
128 | mailView->setColumnWidth( 2, 80 ); | 128 | mailView->setColumnWidth( 2, 80 ); |
129 | mailView->setColumnWidth( 3, 50 ); | 129 | mailView->setColumnWidth( 3, 50 ); |
130 | } | 130 | } |
131 | 131 | ||
132 | void MainWindow::slotShowFolders( bool show ) | 132 | void MainWindow::slotShowFolders( bool show ) |
133 | { | 133 | { |
134 | qDebug( "Show Folders" ); | 134 | qDebug( "Show Folders" ); |
135 | if ( show && folderView->isHidden() ) { | 135 | if ( show && folderView->isHidden() ) { |
136 | qDebug( "-> showing" ); | 136 | qDebug( "-> showing" ); |
137 | folderView->show(); | 137 | folderView->show(); |
138 | } else if ( !show && !folderView->isHidden() ) { | 138 | } else if ( !show && !folderView->isHidden() ) { |
139 | qDebug( "-> hiding" ); | 139 | qDebug( "-> hiding" ); |
140 | folderView->hide(); | 140 | folderView->hide(); |
141 | } | 141 | } |
142 | } | 142 | } |
143 | 143 | ||
144 | void MainWindow::refreshMailView(QList<RecMail>*list) | 144 | void MainWindow::refreshMailView(QList<RecMail>*list) |
145 | { | 145 | { |
146 | MailListViewItem*item = 0; | 146 | MailListViewItem*item = 0; |
147 | mailView->clear(); | 147 | mailView->clear(); |
148 | for (unsigned int i = 0; i < list->count();++i) { | 148 | for (unsigned int i = 0; i < list->count();++i) { |
149 | item = new MailListViewItem(mailView,item); | 149 | item = new MailListViewItem(mailView,item); |
150 | item->storeData(*(list->at(i))); | 150 | item->storeData(*(list->at(i))); |
151 | item->showEntry(); | 151 | item->showEntry(); |
152 | } | 152 | } |
153 | } | 153 | } |
154 | void MainWindow::displayMail(QListViewItem*item) | 154 | void MainWindow::displayMail(QListViewItem*item) |
155 | { | 155 | { |
156 | if (!item) return; | 156 | if (!item) return; |
157 | RecMail mail = ((MailListViewItem*)item)->data(); | 157 | RecMail mail = ((MailListViewItem*)item)->data(); |
158 | RecBody body = folderView->fetchBody(mail); | 158 | RecBody body = folderView->fetchBody(mail); |
159 | 159 | ||
160 | ViewMail readMail( this ); | 160 | ViewMail readMail( this ); |
161 | readMail.setBody( body ); | 161 | readMail.setBody( body ); |
162 | readMail.setMail( mail ); | 162 | readMail.setMail( mail ); |
163 | readMail.showMaximized(); | 163 | readMail.showMaximized(); |
164 | readMail.exec(); | 164 | readMail.exec(); |
165 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgunseen") ); | 165 | ( (MailListViewItem*)item )->setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgunseen") ); |
166 | } | 166 | } |
167 | 167 | ||
168 | MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * after ) | 168 | MailListViewItem::MailListViewItem(QListView * parent, MailListViewItem * item ) |
169 | :QListViewItem(parent,after),mail_data() | 169 | :QListViewItem(parent,item),mail_data() |
170 | { | 170 | { |
171 | } | 171 | } |
172 | 172 | ||
173 | void MailListViewItem::showEntry() | 173 | void MailListViewItem::showEntry() |
174 | { | 174 | { |
175 | if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { | 175 | if ( mail_data.getFlags().testBit( FLAG_SEEN ) == true ) { |
176 | setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgunseen") ); | 176 | setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgunseen") ); |
177 | } else { | 177 | } else { |
178 | setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgnew") ); | 178 | setPixmap( 0, Resource::loadPixmap( "opiemail/kmmsgnew") ); |
179 | } | 179 | } |
180 | setText(1,mail_data.getSubject()); | 180 | setText(1,mail_data.getSubject()); |
181 | setText(2,mail_data.getFrom()); | 181 | setText(2,mail_data.getFrom()); |
182 | setText(3,mail_data.getDate()); | 182 | setText(3,mail_data.getDate()); |
183 | } | 183 | } |
184 | 184 | ||
185 | void MailListViewItem::storeData(const RecMail&data) | 185 | void MailListViewItem::storeData(const RecMail&data) |
186 | { | 186 | { |
187 | mail_data = data; | 187 | mail_data = data; |
188 | } | 188 | } |
189 | 189 | ||
190 | const RecMail& MailListViewItem::data()const | 190 | const RecMail& MailListViewItem::data()const |
191 | { | 191 | { |
192 | return mail_data; | 192 | return mail_data; |
193 | } | 193 | } |
194 | |||
195 | |||
diff --git a/noncore/net/mail/viewmail.cpp b/noncore/net/mail/viewmail.cpp index 39c9820..c24d5d3 100644 --- a/noncore/net/mail/viewmail.cpp +++ b/noncore/net/mail/viewmail.cpp | |||
@@ -1,264 +1,314 @@ | |||
1 | #include <qtextbrowser.h> | 1 | #include <qtextbrowser.h> |
2 | #include <qmessagebox.h> | 2 | #include <qmessagebox.h> |
3 | #include <qtextstream.h> | 3 | #include <qtextstream.h> |
4 | #include <qaction.h> | 4 | #include <qaction.h> |
5 | #include <qpopupmenu.h> | ||
5 | #include <qapplication.h> | 6 | #include <qapplication.h> |
6 | 7 | ||
8 | #include <opie/ofiledialog.h> | ||
9 | |||
7 | #include "settings.h" | 10 | #include "settings.h" |
8 | #include "composemail.h" | 11 | #include "composemail.h" |
9 | #include "viewmail.h" | 12 | #include "viewmail.h" |
10 | 13 | ||
11 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) | 14 | AttachItem::AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num) |
12 | : QListViewItem(parent,after),_partNum(num) | 15 | : QListViewItem(parent,after),_partNum(num) |
13 | { | 16 | { |
14 | setText(0, mime); | 17 | setText(0, mime); |
15 | setText(1, file); | 18 | setText(1, file); |
16 | setText(2, desc); | 19 | setText(2, desc); |
17 | } | 20 | } |
18 | 21 | ||
19 | |||
20 | void ViewMail::setBody( RecBody body ) { | 22 | void ViewMail::setBody( RecBody body ) { |
21 | 23 | ||
24 | m_body = body; | ||
22 | m_mail[2] = body.Bodytext(); | 25 | m_mail[2] = body.Bodytext(); |
23 | attachbutton->setEnabled(body.Parts().count()>0); | 26 | attachbutton->setEnabled(body.Parts().count()>0); |
24 | attachments->setEnabled(body.Parts().count()>0); | 27 | attachments->setEnabled(body.Parts().count()>0); |
25 | if (body.Parts().count()==0) { | 28 | if (body.Parts().count()==0) { |
26 | return; | 29 | return; |
27 | } | 30 | } |
28 | AttachItem * curItem=0; | 31 | AttachItem * curItem=0; |
29 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); | 32 | QString type=body.Description().Type()+"/"+body.Description().Subtype(); |
30 | QString desc; | 33 | QString desc; |
31 | double s = body.Description().Size(); | 34 | double s = body.Description().Size(); |
32 | int w; | 35 | int w; |
33 | w=0; | 36 | w=0; |
34 | 37 | ||
35 | while (s>1024) { | 38 | while (s>1024) { |
36 | s/=1024; | 39 | s/=1024; |
37 | ++w; | 40 | ++w; |
38 | if (w>=2) break; | 41 | if (w>=2) break; |
39 | } | 42 | } |
40 | 43 | ||
41 | QString q=""; | 44 | QString q=""; |
42 | switch(w) { | 45 | switch(w) { |
43 | case 1: | 46 | case 1: |
44 | q="k"; | 47 | q="k"; |
45 | break; | 48 | break; |
46 | case 2: | 49 | case 2: |
47 | q="M"; | 50 | q="M"; |
48 | break; | 51 | break; |
49 | default: | 52 | default: |
50 | break; | 53 | break; |
51 | } | 54 | } |
52 | 55 | ||
53 | { | 56 | { |
54 | /* I did not found a method to make a CONTENT reset on a QTextStream | 57 | /* I did not found a method to make a CONTENT reset on a QTextStream |
55 | so I use this construct that the stream will re-constructed in each | 58 | so I use this construct that the stream will re-constructed in each |
56 | loop. To let it work, the textstream is packed into a own area of | 59 | loop. To let it work, the textstream is packed into a own area of |
57 | code is it will be destructed after finishing its small job. | 60 | code is it will be destructed after finishing its small job. |
58 | */ | 61 | */ |
59 | QTextOStream o(&desc); | 62 | QTextOStream o(&desc); |
60 | if (w>0) o.precision(2); else o.precision(0); | 63 | if (w>0) o.precision(2); else o.precision(0); |
61 | o.setf(QTextStream::fixed); | 64 | o.setf(QTextStream::fixed); |
62 | o << s << " " << q << "Byte"; | 65 | o << s << " " << q << "Byte"; |
63 | } | 66 | } |
64 | 67 | ||
65 | curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); | 68 | curItem=new AttachItem(attachments,curItem,type,"Mailbody",desc,-1); |
66 | QString filename = ""; | 69 | QString filename = ""; |
67 | for (unsigned int i = 0; i < body.Parts().count();++i) { | 70 | for (unsigned int i = 0; i < body.Parts().count();++i) { |
68 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); | 71 | type = body.Parts()[i].Type()+"/"+body.Parts()[i].Subtype(); |
69 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); | 72 | part_plist_t::ConstIterator it = body.Parts()[i].Parameters().begin(); |
70 | for (;it!=body.Parts()[i].Parameters().end();++it) { | 73 | for (;it!=body.Parts()[i].Parameters().end();++it) { |
71 | if (it.key().lower()=="name") { | 74 | if (it.key().lower()=="name") { |
72 | filename=it.data(); | 75 | filename=it.data(); |
73 | } | 76 | } |
74 | } | 77 | } |
75 | s = body.Parts()[i].Size(); | 78 | s = body.Parts()[i].Size(); |
76 | w = 0; | 79 | w = 0; |
77 | while (s>1024) { | 80 | while (s>1024) { |
78 | s/=1024; | 81 | s/=1024; |
79 | ++w; | 82 | ++w; |
80 | if (w>=2) break; | 83 | if (w>=2) break; |
81 | } | 84 | } |
82 | switch(w) { | 85 | switch(w) { |
83 | case 1: | 86 | case 1: |
84 | q="k"; | 87 | q="k"; |
85 | break; | 88 | break; |
86 | case 2: | 89 | case 2: |
87 | q="M"; | 90 | q="M"; |
88 | break; | 91 | break; |
89 | default: | 92 | default: |
90 | q=""; | 93 | q=""; |
91 | break; | 94 | break; |
92 | } | 95 | } |
93 | QTextOStream o(&desc); | 96 | QTextOStream o(&desc); |
94 | if (w>0) o.precision(2); else o.precision(0); | 97 | if (w>0) o.precision(2); else o.precision(0); |
95 | o.setf(QTextStream::fixed); | 98 | o.setf(QTextStream::fixed); |
96 | o << s << " " << q << "Byte"; | 99 | o << s << " " << q << "Byte"; |
97 | curItem=new AttachItem(attachments,curItem,type,filename,desc,i); | 100 | curItem=new AttachItem(attachments,curItem,type,filename,desc,i); |
98 | } | 101 | } |
99 | } | 102 | } |
100 | 103 | ||
104 | void ViewMail::slotItemClicked( QListViewItem * item , const QPoint & point, int c ) { | ||
105 | if (!item ) | ||
106 | return; | ||
107 | |||
108 | QPopupMenu *menu = new QPopupMenu(); | ||
109 | int ret=0; | ||
110 | |||
111 | if ( item->text( 0 ).left( 4 ) == "text" ) { | ||
112 | menu->insertItem( tr( "Show Text" ), 1 ); | ||
113 | } | ||
114 | menu->insertItem( tr( "Save Attachemt" ), 0 ); | ||
115 | menu->insertSeparator(1); | ||
116 | |||
117 | ret = menu->exec( point, 0 ); | ||
118 | |||
119 | switch(ret) { | ||
120 | case 0: | ||
121 | { MimeTypes types; | ||
122 | types.insert( "all", "*" ); | ||
123 | QString str = OFileDialog::getSaveFileName( 1, | ||
124 | "/", item->text( 1 ) , types, 0 ); | ||
125 | |||
126 | if( !str.isEmpty() ) { | ||
127 | qDebug( " first we will need a MIME wrapper" ); | ||
128 | } | ||
129 | } | ||
130 | break ; | ||
131 | |||
132 | case 1: | ||
133 | |||
134 | qDebug( QString( "Test selected" ).arg( ( ( AttachItem* )item )->Partnumber() ) ); | ||
135 | if ( ( ( AttachItem* )item )->Partnumber() == -1 ) { | ||
136 | setText(); | ||
137 | } else { | ||
138 | browser->setText( ( m_body.Parts()[( ( AttachItem* )item )->Partnumber() ] ).Identifier() ); | ||
139 | } | ||
140 | break; | ||
141 | } | ||
142 | delete menu; | ||
143 | } | ||
144 | |||
145 | |||
101 | void ViewMail::setMail( RecMail mail ) { | 146 | void ViewMail::setMail( RecMail mail ) { |
102 | 147 | ||
103 | m_mail[0] = mail.getFrom(); | 148 | m_mail[0] = mail.getFrom(); |
104 | m_mail[1] = mail.getSubject(); | 149 | m_mail[1] = mail.getSubject(); |
105 | m_mail[3] = mail.getDate(); | 150 | m_mail[3] = mail.getDate(); |
106 | m_mail[4] = mail.Msgid(); | 151 | m_mail[4] = mail.Msgid(); |
107 | 152 | ||
108 | m_mail2[0] = mail.To(); | 153 | m_mail2[0] = mail.To(); |
109 | m_mail2[1] = mail.CC(); | 154 | m_mail2[1] = mail.CC(); |
110 | m_mail2[2] = mail.Bcc(); | 155 | m_mail2[2] = mail.Bcc(); |
111 | 156 | ||
112 | setText(); | 157 | setText(); |
113 | } | 158 | } |
114 | 159 | ||
115 | 160 | ||
116 | 161 | ||
117 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) | 162 | ViewMail::ViewMail( QWidget *parent, const char *name, WFlags fl) |
118 | : ViewMailBase(parent, name, fl), _inLoop(false) | 163 | : ViewMailBase(parent, name, fl), _inLoop(false) |
119 | { | 164 | { |
120 | m_gotBody = false; | 165 | m_gotBody = false; |
121 | 166 | ||
122 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); | 167 | connect(reply, SIGNAL(activated()), SLOT(slotReply())); |
123 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); | 168 | connect(forward, SIGNAL(activated()), SLOT(slotForward())); |
124 | 169 | ||
125 | attachments->setEnabled(m_gotBody); | 170 | attachments->setEnabled(m_gotBody); |
171 | connect( attachments, SIGNAL( clicked ( QListViewItem *, const QPoint & , int ) ), SLOT( slotItemClicked( QListViewItem *, const QPoint & , int ) ) ); | ||
172 | |||
126 | } | 173 | } |
127 | 174 | ||
128 | void ViewMail::setText() | 175 | void ViewMail::setText() |
129 | { | 176 | { |
130 | 177 | ||
131 | QString toString; | 178 | QString toString; |
132 | QString ccString; | 179 | QString ccString; |
133 | QString bccString; | 180 | QString bccString; |
134 | 181 | ||
135 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { | 182 | for ( QStringList::Iterator it = ( m_mail2[0] ).begin(); it != ( m_mail2[0] ).end(); ++it ) { |
136 | toString += (*it); | 183 | toString += (*it); |
137 | } | 184 | } |
138 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { | 185 | for ( QStringList::Iterator it = ( m_mail2[1] ).begin(); it != ( m_mail2[1] ).end(); ++it ) { |
139 | ccString += (*it); | 186 | ccString += (*it); |
140 | } | 187 | } |
141 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { | 188 | for ( QStringList::Iterator it = ( m_mail2[2] ).begin(); it != ( m_mail2[2] ).end(); ++it ) { |
142 | bccString += (*it); | 189 | bccString += (*it); |
143 | } | 190 | } |
144 | 191 | ||
145 | setCaption( caption().arg( m_mail[0] ) ); | 192 | setCaption( caption().arg( m_mail[0] ) ); |
146 | 193 | ||
147 | m_mailHtml = "<html><body>" | 194 | m_mailHtml = "<html><body>" |
148 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" | 195 | "<table width=\"100%\" border=\"0\"><tr bgcolor=\"#FFDD76\"><td>" |
149 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" | 196 | "<div align=left><b>" + deHtml( m_mail[1] ) + "</b></div>" |
150 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" | 197 | "</td></tr><tr bgcolor=\"#EEEEE6\"><td>" |
151 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" | 198 | "<b>" + tr( "From" ) + ": </b><font color=#6C86C0>" + deHtml( m_mail[0] ) + "</font><br>" |
152 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + | 199 | "<b>" + tr( "To" ) + ": </b><font color=#6C86C0>" + deHtml( toString ) + "</font><br><b>" + |
153 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" | 200 | tr( "Cc" ) + ": </b>" + deHtml( ccString ) + "<br>" |
154 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + | 201 | "<b>" + tr( "Date" ) + ": </b> " + m_mail[3] + |
155 | "</td></tr></table><font face=fixed>"; | 202 | "</td></tr></table><font face=fixed>"; |
156 | 203 | ||
157 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); | 204 | browser->setText( QString( m_mailHtml) + deHtml( m_mail[2] ) + "</font></html>" ); |
158 | // remove later in favor of a real handling | 205 | // remove later in favor of a real handling |
159 | m_gotBody = true; | 206 | m_gotBody = true; |
160 | } | 207 | } |
161 | 208 | ||
162 | 209 | ||
163 | ViewMail::~ViewMail() | 210 | ViewMail::~ViewMail() |
164 | { | 211 | { |
165 | hide(); | 212 | hide(); |
166 | } | 213 | } |
167 | 214 | ||
168 | void ViewMail::hide() | 215 | void ViewMail::hide() |
169 | { | 216 | { |
170 | QWidget::hide(); | 217 | QWidget::hide(); |
171 | 218 | ||
172 | if (_inLoop) { | 219 | if (_inLoop) { |
173 | _inLoop = false; | 220 | _inLoop = false; |
174 | qApp->exit_loop(); | 221 | qApp->exit_loop(); |
175 | } | 222 | |
223 | } | ||
224 | |||
176 | } | 225 | } |
177 | 226 | ||
178 | void ViewMail::exec() | 227 | void ViewMail::exec() |
179 | { | 228 | { |
180 | show(); | 229 | show(); |
181 | 230 | ||
182 | if (!_inLoop) { | 231 | if (!_inLoop) { |
183 | _inLoop = true; | 232 | _inLoop = true; |
184 | qApp->enter_loop(); | 233 | qApp->enter_loop(); |
185 | } | 234 | } |
235 | |||
186 | } | 236 | } |
187 | 237 | ||
188 | QString ViewMail::deHtml(const QString &string) | 238 | QString ViewMail::deHtml(const QString &string) |
189 | { | 239 | { |
190 | QString string_ = string; | 240 | QString string_ = string; |
191 | string_.replace(QRegExp("&"), "&"); | 241 | string_.replace(QRegExp("&"), "&"); |
192 | string_.replace(QRegExp("<"), "<"); | 242 | string_.replace(QRegExp("<"), "<"); |
193 | string_.replace(QRegExp(">"), ">"); | 243 | string_.replace(QRegExp(">"), ">"); |
194 | string_.replace(QRegExp("\\n"), "<br>"); | 244 | string_.replace(QRegExp("\\n"), "<br>"); |
195 | return string_; | 245 | return string_; |
196 | } | 246 | } |
197 | 247 | ||
198 | void ViewMail::slotReply() | 248 | void ViewMail::slotReply() |
199 | { | 249 | { |
200 | if (!m_gotBody) { | 250 | if (!m_gotBody) { |
201 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); | 251 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot reply yet."), tr("Ok")); |
202 | return; | 252 | return; |
203 | } | 253 | } |
204 | 254 | ||
205 | QString rtext; | 255 | QString rtext; |
206 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose | 256 | rtext += QString("* %1 wrote on %2:\n") // no i18n on purpose |
207 | .arg( m_mail[1] ) | 257 | .arg( m_mail[1] ) |
208 | .arg( m_mail[3] ); | 258 | .arg( m_mail[3] ); |
209 | 259 | ||
210 | QString text = m_mail[2]; | 260 | QString text = m_mail[2]; |
211 | QStringList lines = QStringList::split(QRegExp("\\n"), text); | 261 | QStringList lines = QStringList::split(QRegExp("\\n"), text); |
212 | QStringList::Iterator it; | 262 | QStringList::Iterator it; |
213 | for (it = lines.begin(); it != lines.end(); it++) { | 263 | for (it = lines.begin(); it != lines.end(); it++) { |
214 | rtext += "> " + *it + "\n"; | 264 | rtext += "> " + *it + "\n"; |
215 | } | 265 | } |
216 | rtext += "\n"; | 266 | rtext += "\n"; |
217 | 267 | ||
218 | QString prefix; | 268 | QString prefix; |
219 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; | 269 | if ( m_mail[1].find(QRegExp("^Re: *$")) != -1) prefix = ""; |
220 | else prefix = "Re: "; // no i18n on purpose | 270 | else prefix = "Re: "; // no i18n on purpose |
221 | 271 | ||
222 | Settings *settings = new Settings(); | 272 | Settings *settings = new Settings(); |
223 | ComposeMail composer( settings ,this, 0, true); | 273 | ComposeMail composer( settings ,this, 0, true); |
224 | composer.setTo( m_mail[0] ); | 274 | composer.setTo( m_mail[0] ); |
225 | composer.setSubject( "Re: " + m_mail[1] ); | 275 | composer.setSubject( "Re: " + m_mail[1] ); |
226 | composer.setMessage( rtext ); | 276 | composer.setMessage( rtext ); |
227 | composer.showMaximized(); | 277 | composer.showMaximized(); |
228 | composer.exec(); | 278 | composer.exec(); |
229 | 279 | ||
230 | } | 280 | } |
231 | 281 | ||
232 | void ViewMail::slotForward() | 282 | void ViewMail::slotForward() |
233 | { | 283 | { |
234 | if (!m_gotBody) { | 284 | if (!m_gotBody) { |
235 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); | 285 | QMessageBox::information(this, tr("Error"), tr("<p>The mail body is not yet downloaded, so you cannot forward yet."), tr("Ok")); |
236 | return; | 286 | return; |
237 | } | 287 | } |
238 | 288 | ||
239 | QString ftext; | 289 | QString ftext; |
240 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") | 290 | ftext += QString("\n----- Forwarded message from %1 -----\n\n") |
241 | .arg( m_mail[0] ); | 291 | .arg( m_mail[0] ); |
242 | if (!m_mail[3].isNull()) | 292 | if (!m_mail[3].isNull()) |
243 | ftext += QString("Date: %1\n") | 293 | ftext += QString("Date: %1\n") |
244 | .arg( m_mail[3] ); | 294 | .arg( m_mail[3] ); |
245 | if (!m_mail[0].isNull()) | 295 | if (!m_mail[0].isNull()) |
246 | ftext += QString("From: %1\n") | 296 | ftext += QString("From: %1\n") |
247 | .arg( m_mail[0] ); | 297 | .arg( m_mail[0] ); |
248 | if (!m_mail[1].isNull()) | 298 | if (!m_mail[1].isNull()) |
249 | ftext += QString("Subject: %1\n") | 299 | ftext += QString("Subject: %1\n") |
250 | .arg( m_mail[1] ); | 300 | .arg( m_mail[1] ); |
251 | 301 | ||
252 | ftext += QString("\n%1\n") | 302 | ftext += QString("\n%1\n") |
253 | .arg( m_mail[2]); | 303 | .arg( m_mail[2]); |
254 | 304 | ||
255 | ftext += QString("----- End forwarded message -----\n"); | 305 | ftext += QString("----- End forwarded message -----\n"); |
256 | 306 | ||
257 | Settings *settings = new Settings(); | 307 | Settings *settings = new Settings(); |
258 | ComposeMail composer( settings ,this, 0, true); | 308 | ComposeMail composer( settings ,this, 0, true); |
259 | composer.setSubject( "Fwd: " + m_mail[1] ); | 309 | composer.setSubject( "Fwd: " + m_mail[1] ); |
260 | composer.setMessage( ftext ); | 310 | composer.setMessage( ftext ); |
261 | composer.showMaximized(); | 311 | composer.showMaximized(); |
262 | composer.exec(); | 312 | composer.exec(); |
263 | } | 313 | } |
264 | 314 | ||
diff --git a/noncore/net/mail/viewmail.h b/noncore/net/mail/viewmail.h index b497434..0e85839 100644 --- a/noncore/net/mail/viewmail.h +++ b/noncore/net/mail/viewmail.h | |||
@@ -1,54 +1,56 @@ | |||
1 | #ifndef VIEWMAIL_H | 1 | #ifndef VIEWMAIL_H |
2 | #define VIEWMAIL_H | 2 | #define VIEWMAIL_H |
3 | 3 | ||
4 | #include <qlistview.h> | 4 | #include <qlistview.h> |
5 | #include <qmap.h> | 5 | #include <qmap.h> |
6 | #include <qstringlist.h> | 6 | #include <qstringlist.h> |
7 | 7 | ||
8 | #include "viewmailbase.h" | 8 | #include "viewmailbase.h" |
9 | #include "mailtypes.h" | 9 | #include "mailtypes.h" |
10 | 10 | ||
11 | class AttachItem : public QListViewItem | 11 | class AttachItem : public QListViewItem |
12 | { | 12 | { |
13 | public: | 13 | public: |
14 | AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num); | 14 | AttachItem(QListView * parent,QListViewItem *after, const QString&mime,const QString&file,const QString&desc,int num); |
15 | int Partnumber() { return _partNum; } | 15 | int Partnumber() { return _partNum; } |
16 | 16 | ||
17 | private: | 17 | private: |
18 | int _partNum; | 18 | int _partNum; |
19 | }; | 19 | }; |
20 | 20 | ||
21 | class ViewMail : public ViewMailBase | 21 | class ViewMail : public ViewMailBase |
22 | { | 22 | { |
23 | Q_OBJECT | 23 | Q_OBJECT |
24 | 24 | ||
25 | public: | 25 | public: |
26 | ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal); | 26 | ViewMail( QWidget *parent = 0, const char *name = 0, WFlags fl = Qt::WType_Modal); |
27 | ~ViewMail(); | 27 | ~ViewMail(); |
28 | 28 | ||
29 | void hide(); | 29 | void hide(); |
30 | void exec(); | 30 | void exec(); |
31 | void setMail( RecMail mail ); | 31 | void setMail( RecMail mail ); |
32 | void setBody( RecBody body ); | 32 | void setBody( RecBody body ); |
33 | 33 | ||
34 | protected: | 34 | protected: |
35 | QString deHtml(const QString &string); | 35 | QString deHtml(const QString &string); |
36 | 36 | ||
37 | protected slots: | 37 | protected slots: |
38 | void slotReply(); | 38 | void slotReply(); |
39 | void slotForward(); | 39 | void slotForward(); |
40 | void setText(); | 40 | void setText(); |
41 | void slotItemClicked( QListViewItem * item , const QPoint & point, int c ); | ||
41 | 42 | ||
42 | private: | 43 | private: |
43 | bool _inLoop; | 44 | bool _inLoop; |
44 | QString m_mailHtml; | 45 | QString m_mailHtml; |
45 | bool m_gotBody; | 46 | bool m_gotBody; |
47 | RecBody m_body; | ||
46 | 48 | ||
47 | // 0 from 1 subject 2 bodytext 3 date | 49 | // 0 from 1 subject 2 bodytext 3 date |
48 | QMap <int,QString> m_mail; | 50 | QMap <int,QString> m_mail; |
49 | // 0 to 1 cc 2 bcc | 51 | // 0 to 1 cc 2 bcc |
50 | QMap <int,QStringList> m_mail2; | 52 | QMap <int,QStringList> m_mail2; |
51 | 53 | ||
52 | }; | 54 | }; |
53 | 55 | ||
54 | #endif | 56 | #endif |