Diffstat (limited to 'noncore/net/mail/viewmail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/viewmail.cpp | 56 |
1 files changed, 53 insertions, 3 deletions
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,33 +1,36 @@ | |||
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; |
@@ -43,25 +46,25 @@ 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) { |
@@ -89,24 +92,66 @@ for (unsigned int i = 0; i < body.Parts().count();++i) { | |||
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(); |
@@ -114,24 +159,26 @@ setText(); | |||
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 | } |
@@ -163,35 +210,38 @@ void ViewMail::setText() | |||
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 | ||