-rw-r--r-- | kmicromail/composemail.cpp | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/kmicromail/composemail.cpp b/kmicromail/composemail.cpp index 9b799b3..e6f7daa 100644 --- a/kmicromail/composemail.cpp +++ b/kmicromail/composemail.cpp | |||
@@ -1,246 +1,264 @@ | |||
1 | // CHANGED 2004-08-06 Lutz Rogowski | 1 | // CHANGED 2004-08-06 Lutz Rogowski |
2 | 2 | ||
3 | #include "composemail.h" | 3 | #include "composemail.h" |
4 | 4 | ||
5 | #include <libmailwrapper/smtpwrapper.h> | 5 | #include <libmailwrapper/smtpwrapper.h> |
6 | #include <libmailwrapper/storemail.h> | 6 | #include <libmailwrapper/storemail.h> |
7 | #include <libmailwrapper/abstractmail.h> | 7 | #include <libmailwrapper/abstractmail.h> |
8 | #include <libmailwrapper/mailtypes.h> | 8 | #include <libmailwrapper/mailtypes.h> |
9 | 9 | ||
10 | /* OPIE */ | 10 | /* OPIE */ |
11 | //#include <opie2/ofiledialog.h> | 11 | //#include <opie2/ofiledialog.h> |
12 | //#include <opie2/odebug.h> | 12 | //#include <opie2/odebug.h> |
13 | #include <kfiledialog.h> | 13 | #include <kfiledialog.h> |
14 | //#include <qpe/resource.h> | 14 | //#include <qpe/resource.h> |
15 | #include <qpe/config.h> | ||
16 | #include <qpe/global.h> | 15 | #include <qpe/global.h> |
17 | //#include <qpe/contact.h> | 16 | //#include <qpe/contact.h> |
18 | 17 | ||
19 | 18 | ||
20 | #include <qcombobox.h> | 19 | #include <qcombobox.h> |
21 | #include <qcheckbox.h> | 20 | #include <qcheckbox.h> |
22 | #include <qtimer.h> | 21 | #include <qtimer.h> |
23 | #include <qmessagebox.h> | 22 | #include <qmessagebox.h> |
24 | #include <qpushbutton.h> | 23 | #include <qpushbutton.h> |
25 | #include <qmultilineedit.h> | 24 | #include <qmultilineedit.h> |
26 | #include <qlabel.h> | 25 | #include <qlabel.h> |
27 | #include <qtabwidget.h> | 26 | #include <qtabwidget.h> |
28 | #include <qlistview.h> | 27 | #include <qlistview.h> |
29 | #include <kabc/addresseedialog.h> | 28 | #include <kabc/addresseedialog.h> |
30 | #include <kabc/stdaddressbook.h> | 29 | #include <kabc/stdaddressbook.h> |
31 | #include <kabc/addressee.h> | 30 | #include <kabc/addressee.h> |
32 | #ifdef DESKTOP_VERSION | 31 | #ifdef DESKTOP_VERSION |
33 | #include <kabc/addresseedialog.h> | 32 | #include <kabc/addresseedialog.h> |
34 | #else //DESKTOP_VERSION | 33 | #else //DESKTOP_VERSION |
35 | #include <libkdepim/externalapphandler.h> | 34 | #include <libkdepim/externalapphandler.h> |
36 | #endif //DESKTOP_VERSION | 35 | #endif //DESKTOP_VERSION |
37 | 36 | ||
37 | #include "koprefs.h" | ||
38 | 38 | ||
39 | //using namespace Opie::Core; | 39 | //using namespace Opie::Core; |
40 | //using namespace Opie::Ui; | 40 | //using namespace Opie::Ui; |
41 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal ) | 41 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal ) |
42 | : ComposeMailUI( parent, name, modal ) | 42 | : ComposeMailUI( parent, name, modal ) |
43 | { | 43 | { |
44 | |||
45 | mPickLineEdit = 0; | 44 | mPickLineEdit = 0; |
46 | connect(ExternalAppHandler::instance(), SIGNAL(receivedNameEmailUidListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&)), | 45 | connect(ExternalAppHandler::instance(), SIGNAL(receivedNameEmailUidListEvent(const QString&, const QStringList&, const QStringList&, const QStringList&)), |
47 | this, SLOT(insertAttendees(const QString&, const QStringList&, const QStringList&, const QStringList&))); | 46 | this, SLOT(insertAttendees(const QString&, const QStringList&, const QStringList&, const QStringList&))); |
48 | settings = s; | 47 | settings = s; |
49 | m_replyid = ""; | 48 | m_replyid = ""; |
49 | if ( KOPrefs::instance()->mUseKapi) { | ||
50 | KConfig config( locateLocal("config", "kabcrc") ); | 50 | KConfig config( locateLocal("config", "kabcrc") ); |
51 | config.setGroup( "General" ); | 51 | config.setGroup( "General" ); |
52 | QString whoami_uid = config.readEntry( "WhoAmI" ); | 52 | QString whoami_uid = config.readEntry( "WhoAmI" ); |
53 | 53 | ||
54 | if ( whoami_uid.isEmpty() ) { | 54 | if ( whoami_uid.isEmpty() ) { |
55 | QMessageBox::information( 0, tr( "Hint" ), | 55 | QMessageBox::information( 0, tr( "Hint" ), |
56 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), | 56 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), |
57 | tr( "Ok" ) ); | 57 | tr( "Ok" ) ); |
58 | 58 | ||
59 | |||
60 | fillSettings(); | ||
59 | } else | 61 | } else |
60 | ExternalAppHandler::instance()->requestDetailsFromKAPI("", "sendbacklist", whoami_uid); | 62 | ExternalAppHandler::instance()->requestDetailsFromKAPI("", "sendbacklist", whoami_uid); |
61 | 63 | ||
62 | 64 | ||
63 | #ifdef DESKTOP_VERSION | 65 | #ifdef DESKTOP_VERSION |
64 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); | 66 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); |
65 | QStringList mails = con.emails(); | 67 | QStringList mails = con.emails(); |
66 | QString defmail = con.preferredEmail(); | 68 | QString defmail = con.preferredEmail(); |
67 | if ( mails.count() == 0) | 69 | if ( mails.count() == 0) |
68 | QMessageBox::information( 0, tr( "Hint" ), | 70 | QMessageBox::information( 0, tr( "Hint" ), |
69 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), | 71 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), |
70 | tr( "Ok" ) ); | 72 | tr( "Ok" ) ); |
71 | if (defmail.length()!=0) { | 73 | if (defmail.length()!=0) { |
72 | fromBox->insertItem(defmail); | 74 | fromBox->insertItem(defmail); |
73 | } | 75 | } |
74 | QStringList::ConstIterator sit = mails.begin(); | 76 | QStringList::ConstIterator sit = mails.begin(); |
75 | for (;sit!=mails.end();++sit) { | 77 | for (;sit!=mails.end();++sit) { |
76 | if ( (*sit)==defmail) | 78 | if ( (*sit)==defmail) |
77 | continue; | 79 | continue; |
78 | fromBox->insertItem((*sit)); | 80 | fromBox->insertItem((*sit)); |
79 | } | 81 | } |
80 | senderNameEdit->setText(con.formattedName()); | 82 | senderNameEdit->setText(con.formattedName()); |
81 | #endif | 83 | #endif |
82 | Config cfg( "mail" ); | 84 | |
83 | cfg.setGroup( "Compose" ); | 85 | } else { |
84 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 86 | fillSettings(); |
87 | } | ||
88 | checkBoxLater->setChecked( KOPrefs::instance()->mSendLater ); | ||
85 | 89 | ||
86 | attList->addColumn( tr( "Name" ) ); | 90 | attList->addColumn( tr( "Name" ) ); |
87 | attList->addColumn( tr( "Size" ) ); | 91 | attList->addColumn( tr( "Size" ) ); |
88 | QList<Account> accounts = settings->getAccounts(); | 92 | QList<Account> accounts = settings->getAccounts(); |
89 | 93 | ||
94 | if ( QApplication::desktop()->width() < 320 ) | ||
95 | smtpAccountBox->setMaximumWidth( 80 ); | ||
90 | Account *it; | 96 | Account *it; |
91 | for ( it = accounts.first(); it; it = accounts.next() ) { | 97 | for ( it = accounts.first(); it; it = accounts.next() ) { |
92 | if ( it->getType()==MAILLIB::A_SMTP ) { | 98 | if ( it->getType()==MAILLIB::A_SMTP ) { |
93 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 99 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
94 | smtpAccountBox->insertItem( smtp->getAccountName() ); | 100 | smtpAccountBox->insertItem( smtp->getAccountName() ); |
95 | smtpAccounts.append( smtp ); | 101 | smtpAccounts.append( smtp ); |
96 | } | 102 | } |
97 | } | 103 | } |
98 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 104 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
99 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 105 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
100 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 106 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
101 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 107 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
102 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 108 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
103 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 109 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
104 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); | 110 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); |
105 | mMail = 0; | 111 | mMail = 0; |
106 | warnAttach = true; | 112 | warnAttach = true; |
107 | if ( smtpAccounts.count() > 0 ) { | 113 | if ( smtpAccounts.count() > 0 ) { |
108 | fillValues( smtpAccountBox->currentItem() ); | 114 | fillValues( smtpAccountBox->currentItem() ); |
109 | } else { | 115 | } else { |
110 | QMessageBox::information( 0, tr( "Problem" ), | 116 | QMessageBox::information( 0, tr( "Problem" ), |
111 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail.\n" ), | 117 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail.\n" ), |
112 | tr( "Ok" ) ); | 118 | tr( "Ok" ) ); |
113 | return; | 119 | return; |
114 | } | 120 | } |
115 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); | 121 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); |
116 | 122 | message->setFont ( KOPrefs::instance()->mComposeFont ); | |
117 | } | 123 | } |
118 | 124 | ||
125 | void ComposeMail::fillSettings() | ||
126 | { | ||
127 | if ( QApplication::desktop()->width() < 320 ) | ||
128 | fromBox->setMaximumWidth( 100 ); | ||
129 | QStringList mailList = QStringList::split(";",KOPrefs::instance()->mEmail); | ||
130 | QStringList::ConstIterator sit = mailList.begin(); | ||
131 | int pref = 0; | ||
132 | for (;sit!=mailList.end();++sit) { | ||
133 | fromBox->insertItem((*sit)); | ||
134 | } | ||
135 | senderNameEdit->setText(KOPrefs::instance()->mName); | ||
136 | } | ||
119 | 137 | ||
120 | 138 | ||
121 | void ComposeMail::saveAsDraft() | 139 | void ComposeMail::saveAsDraft() |
122 | { | 140 | { |
123 | 141 | ||
124 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); | 142 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); |
125 | mail->setMail(fromBox->currentText()); | 143 | mail->setMail(fromBox->currentText()); |
126 | mail->setTo( toLine->text() ); | 144 | mail->setTo( toLine->text() ); |
127 | mail->setName(senderNameEdit->text()); | 145 | mail->setName(senderNameEdit->text()); |
128 | mail->setCC( ccLine->text() ); | 146 | mail->setCC( ccLine->text() ); |
129 | mail->setBCC( bccLine->text() ); | 147 | mail->setBCC( bccLine->text() ); |
130 | mail->setReply( replyLine->text() ); | 148 | mail->setReply( replyLine->text() ); |
131 | mail->setSubject( subjectLine->text() ); | 149 | mail->setSubject( subjectLine->text() ); |
132 | if (!m_replyid.isEmpty()) { | 150 | if (!m_replyid.isEmpty()) { |
133 | QStringList ids; | 151 | QStringList ids; |
134 | ids.append(m_replyid); | 152 | ids.append(m_replyid); |
135 | mail->setInreply(ids); | 153 | mail->setInreply(ids); |
136 | } | 154 | } |
137 | QString txt = message->text(); | 155 | QString txt = message->text(); |
138 | if ( !sigMultiLine->text().isEmpty() ) { | 156 | if ( !sigMultiLine->text().isEmpty() ) { |
139 | txt.append( "\n--\n" ); | 157 | txt.append( "\n--\n" ); |
140 | txt.append( sigMultiLine->text() ); | 158 | txt.append( sigMultiLine->text() ); |
141 | } | 159 | } |
142 | mail->setMessage( txt ); | 160 | mail->setMessage( txt ); |
143 | 161 | ||
144 | /* only use the default drafts folder name! */ | 162 | /* only use the default drafts folder name! */ |
145 | Storemail wrapper(AbstractMail::draftFolder()); | 163 | Storemail wrapper(AbstractMail::draftFolder()); |
146 | wrapper.storeMail(mail); | 164 | wrapper.storeMail(mail); |
147 | 165 | ||
148 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 166 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
149 | /* attachments we will ignore! */ | 167 | /* attachments we will ignore! */ |
150 | if ( it != 0 ) { | 168 | if ( it != 0 ) { |
151 | if ( warnAttach ) | 169 | if ( warnAttach ) |
152 | QMessageBox::warning(0,tr("Store message"), | 170 | QMessageBox::warning(0,tr("Store message"), |
153 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); | 171 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); |
154 | warnAttach = false; | 172 | warnAttach = false; |
155 | } | 173 | } |
156 | setStatus( tr("Mail saved as draft!") ); | 174 | setStatus( tr("Mail saved as draft!") ); |
157 | } | 175 | } |
158 | void ComposeMail::clearStatus() | 176 | void ComposeMail::clearStatus() |
159 | { | 177 | { |
160 | topLevelWidget()->setCaption( tr("Compose mail") ); | 178 | topLevelWidget()->setCaption( tr("Compose mail") ); |
161 | } | 179 | } |
162 | void ComposeMail::setStatus( QString status ) | 180 | void ComposeMail::setStatus( QString status ) |
163 | { | 181 | { |
164 | topLevelWidget()->setCaption( status ); | 182 | topLevelWidget()->setCaption( status ); |
165 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; | 183 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; |
166 | } | 184 | } |
167 | void ComposeMail::pickAddress( ) | 185 | void ComposeMail::pickAddress( ) |
168 | { | 186 | { |
169 | 187 | ||
170 | QLineEdit *line = mPickLineEdit; | 188 | QLineEdit *line = mPickLineEdit; |
171 | if ( line == 0 ) | 189 | if ( line == 0 ) |
172 | return; | 190 | return; |
173 | #ifdef DESKTOP_VERSION | 191 | #ifdef DESKTOP_VERSION |
174 | //qDebug(" ComposeMail::pickAddress "); | 192 | //qDebug(" ComposeMail::pickAddress "); |
175 | QString names ;//= AddressPicker::getNames(); | 193 | QString names ;//= AddressPicker::getNames(); |
176 | 194 | ||
177 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 195 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
178 | uint i=0; | 196 | uint i=0; |
179 | for (i=0; i < list.count(); i++) { | 197 | for (i=0; i < list.count(); i++) { |
180 | if ( !list[i].preferredEmail().isEmpty()) { | 198 | if ( !list[i].preferredEmail().isEmpty()) { |
181 | if ( ! names.isEmpty() ) | 199 | if ( ! names.isEmpty() ) |
182 | names+= ","; | 200 | names+= ","; |
183 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; | 201 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; |
184 | 202 | ||
185 | } | 203 | } |
186 | } | 204 | } |
187 | 205 | ||
188 | 206 | ||
189 | if ( line->text().isEmpty() ) { | 207 | if ( line->text().isEmpty() ) { |
190 | line->setText( names ); | 208 | line->setText( names ); |
191 | } else if ( !names.isEmpty() ) { | 209 | } else if ( !names.isEmpty() ) { |
192 | line->setText( line->text() + ", " + names ); | 210 | line->setText( line->text() + ", " + names ); |
193 | } | 211 | } |
194 | #else | 212 | #else |
195 | bool res = ExternalAppHandler::instance()->requestNameEmailUidListFromKAPI("QPE/Application/ompi", this->name() /* name is here the unique uid*/); | 213 | bool res = ExternalAppHandler::instance()->requestNameEmailUidListFromKAPI("QPE/Application/ompi", this->name() /* name is here the unique uid*/); |
196 | // the result should now arrive through method insertAttendees | 214 | // the result should now arrive through method insertAttendees |
197 | #endif | 215 | #endif |
198 | } | 216 | } |
199 | //the map includes name/email pairs, that comes from Ka/Pi | 217 | //the map includes name/email pairs, that comes from Ka/Pi |
200 | void ComposeMail::insertAttendees(const QString& uid,const QStringList& nameList,const QStringList& emailList,const QStringList& uidList) | 218 | void ComposeMail::insertAttendees(const QString& uid,const QStringList& nameList,const QStringList& emailList,const QStringList& uidList) |
201 | { | 219 | { |
202 | //qDebug("ComposeMail::insertAttendees "); | 220 | //qDebug("ComposeMail::insertAttendees "); |
203 | raise(); | 221 | raise(); |
204 | 222 | ||
205 | if ( mPickLineEdit == 0 ) { //whoami received | 223 | if ( mPickLineEdit == 0 ) { //whoami received |
206 | QString defmail = uidList[0]; | 224 | QString defmail = uidList[0]; |
207 | if ( emailList.count() == 0 ) | 225 | if ( emailList.count() == 0 ) |
208 | QMessageBox::information( 0, tr( "Hint" ), | 226 | QMessageBox::information( 0, tr( "Hint" ), |
209 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), | 227 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), |
210 | tr( "Ok" ) ); | 228 | tr( "Ok" ) ); |
211 | if (defmail.length()!=0) { | 229 | if (defmail.length()!=0) { |
212 | fromBox->insertItem(defmail); | 230 | fromBox->insertItem(defmail); |
213 | } | 231 | } |
214 | QStringList::ConstIterator sit = emailList.begin(); | 232 | QStringList::ConstIterator sit = emailList.begin(); |
215 | int pref = 0; | 233 | int pref = 0; |
216 | for (;sit!=emailList.end();++sit) { | 234 | for (;sit!=emailList.end();++sit) { |
217 | if ( (*sit)==defmail) | 235 | if ( (*sit)==defmail) |
218 | continue; | 236 | continue; |
219 | fromBox->insertItem((*sit)); | 237 | fromBox->insertItem((*sit)); |
220 | } | 238 | } |
221 | senderNameEdit->setText(nameList[0]); | 239 | senderNameEdit->setText(nameList[0]); |
222 | return; | 240 | return; |
223 | } | 241 | } |
224 | QString names ; | 242 | QString names ; |
225 | QLineEdit *line = mPickLineEdit; | 243 | QLineEdit *line = mPickLineEdit; |
226 | if (uid == this->name()) | 244 | if (uid == this->name()) |
227 | { | 245 | { |
228 | for ( int i = 0; i < nameList.count(); i++) | 246 | for ( int i = 0; i < nameList.count(); i++) |
229 | { | 247 | { |
230 | QString _name = nameList[i]; | 248 | QString _name = nameList[i]; |
231 | QString _email = emailList[i]; | 249 | QString _email = emailList[i]; |
232 | QString _uid = uidList[i]; | 250 | QString _uid = uidList[i]; |
233 | if ( ! _email.isEmpty() ) { | 251 | if ( ! _email.isEmpty() ) { |
234 | if ( ! names.isEmpty() ) | 252 | if ( ! names.isEmpty() ) |
235 | names+= ","; | 253 | names+= ","; |
236 | names+= "\""+_name +"\"<" +_email +">"; | 254 | names+= "\""+_name +"\"<" +_email +">"; |
237 | } | 255 | } |
238 | } | 256 | } |
239 | } | 257 | } |
240 | if ( line->text().isEmpty() ) { | 258 | if ( line->text().isEmpty() ) { |
241 | line->setText( names ); | 259 | line->setText( names ); |
242 | } else if ( !names.isEmpty() ) { | 260 | } else if ( !names.isEmpty() ) { |
243 | line->setText( line->text() + ", " + names ); | 261 | line->setText( line->text() + ", " + names ); |
244 | } | 262 | } |
245 | } | 263 | } |
246 | 264 | ||