-rw-r--r-- | kmicromail/composemail.cpp | 99 |
1 files changed, 88 insertions, 11 deletions
diff --git a/kmicromail/composemail.cpp b/kmicromail/composemail.cpp index 654cfc0..5f446fa 100644 --- a/kmicromail/composemail.cpp +++ b/kmicromail/composemail.cpp | |||
@@ -26,23 +26,35 @@ | |||
26 | #include <qlabel.h> | 26 | #include <qlabel.h> |
27 | #include <qtabwidget.h> | 27 | #include <qtabwidget.h> |
28 | #include <qlistview.h> | 28 | #include <qlistview.h> |
29 | #include <kabc/addresseedialog.h> | 29 | #include <kabc/addresseedialog.h> |
30 | #include <kabc/stdaddressbook.h> | 30 | #include <kabc/stdaddressbook.h> |
31 | #include <kabc/addressee.h> | 31 | #include <kabc/addressee.h> |
32 | 32 | #ifdef DESKTOP_VERSION | |
33 | #include <kabc/addresseedialog.h> | ||
34 | #else //DESKTOP_VERSION | ||
35 | #include <libkdepim/externalapphandler.h> | ||
36 | #endif //DESKTOP_VERSION | ||
33 | 37 | ||
34 | 38 | ||
35 | //using namespace Opie::Core; | 39 | //using namespace Opie::Core; |
36 | //using namespace Opie::Ui; | 40 | //using namespace Opie::Ui; |
37 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 41 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
38 | : ComposeMailUI( parent, name, modal, flags ) | 42 | : ComposeMailUI( parent, name, modal, flags ) |
39 | { | 43 | { |
40 | 44 | ||
45 | mPickLineEdit = 0; | ||
46 | 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&))); | ||
41 | settings = s; | 48 | settings = s; |
42 | m_replyid = ""; | 49 | m_replyid = ""; |
50 | KConfig config( locateLocal("config", "kabcrc") ); | ||
51 | config.setGroup( "General" ); | ||
52 | QString whoami_uid = config.readEntry( "WhoAmI" ); | ||
53 | bool res = ExternalAppHandler::instance()->requestDetailsFromKAPI("", "sendbacklist", whoami_uid); | ||
54 | #ifdef DESKTOP_VERSION | ||
43 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); | 55 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); |
44 | QStringList mails = con.emails(); | 56 | QStringList mails = con.emails(); |
45 | QString defmail = con.preferredEmail(); | 57 | QString defmail = con.preferredEmail(); |
46 | if ( mails.count() == 0) | 58 | if ( mails.count() == 0) |
47 | QMessageBox::information( 0, tr( "Hint" ), | 59 | QMessageBox::information( 0, tr( "Hint" ), |
48 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), | 60 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), |
@@ -54,12 +66,13 @@ ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool m | |||
54 | for (;sit!=mails.end();++sit) { | 66 | for (;sit!=mails.end();++sit) { |
55 | if ( (*sit)==defmail) | 67 | if ( (*sit)==defmail) |
56 | continue; | 68 | continue; |
57 | fromBox->insertItem((*sit)); | 69 | fromBox->insertItem((*sit)); |
58 | } | 70 | } |
59 | senderNameEdit->setText(con.formattedName()); | 71 | senderNameEdit->setText(con.formattedName()); |
72 | #endif | ||
60 | Config cfg( "mail" ); | 73 | Config cfg( "mail" ); |
61 | cfg.setGroup( "Compose" ); | 74 | cfg.setGroup( "Compose" ); |
62 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 75 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
63 | 76 | ||
64 | attList->addColumn( tr( "Name" ) ); | 77 | attList->addColumn( tr( "Name" ) ); |
65 | attList->addColumn( tr( "Size" ) ); | 78 | attList->addColumn( tr( "Size" ) ); |
@@ -88,15 +101,18 @@ ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool m | |||
88 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 101 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
89 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 102 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
90 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 103 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
91 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 104 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
92 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); | 105 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); |
93 | mMail = 0; | 106 | mMail = 0; |
94 | warnAttach = true; | 107 | warnAttach = true; |
95 | 108 | ||
96 | } | 109 | } |
110 | |||
111 | |||
112 | |||
97 | void ComposeMail::saveAsDraft() | 113 | void ComposeMail::saveAsDraft() |
98 | { | 114 | { |
99 | 115 | ||
100 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); | 116 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); |
101 | mail->setMail(fromBox->currentText()); | 117 | mail->setMail(fromBox->currentText()); |
102 | mail->setTo( toLine->text() ); | 118 | mail->setTo( toLine->text() ); |
@@ -137,35 +153,92 @@ void ComposeMail::clearStatus() | |||
137 | } | 153 | } |
138 | void ComposeMail::setStatus( QString status ) | 154 | void ComposeMail::setStatus( QString status ) |
139 | { | 155 | { |
140 | topLevelWidget()->setCaption( status ); | 156 | topLevelWidget()->setCaption( status ); |
141 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; | 157 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; |
142 | } | 158 | } |
143 | void ComposeMail::pickAddress( QLineEdit *line ) | 159 | void ComposeMail::pickAddress( ) |
144 | { | 160 | { |
161 | |||
162 | QLineEdit *line = mPickLineEdit; | ||
163 | if ( line == 0 ) | ||
164 | return; | ||
165 | #ifdef DESKTOP_VERSION | ||
145 | //qDebug(" ComposeMail::pickAddress "); | 166 | //qDebug(" ComposeMail::pickAddress "); |
146 | QString names ;//= AddressPicker::getNames(); | 167 | QString names ;//= AddressPicker::getNames(); |
147 | 168 | ||
148 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 169 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
149 | uint i=0; | 170 | uint i=0; |
150 | for (i=0; i < list.count(); i++) { | 171 | for (i=0; i < list.count(); i++) { |
151 | if ( !list[i].preferredEmail().isEmpty()) { | 172 | if ( !list[i].preferredEmail().isEmpty()) { |
152 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; | 173 | if ( ! names.isEmpty() ) |
153 | if ( i < list.count() -1 ) | ||
154 | names+= ","; | 174 | names+= ","; |
175 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; | ||
176 | |||
155 | } | 177 | } |
156 | } | 178 | } |
157 | 179 | ||
158 | 180 | ||
159 | if ( line->text().isEmpty() ) { | 181 | if ( line->text().isEmpty() ) { |
160 | line->setText( names ); | 182 | line->setText( names ); |
161 | } else if ( !names.isEmpty() ) { | 183 | } else if ( !names.isEmpty() ) { |
162 | line->setText( line->text() + ", " + names ); | 184 | line->setText( line->text() + ", " + names ); |
163 | } | 185 | } |
186 | #else | ||
187 | bool res = ExternalAppHandler::instance()->requestNameEmailUidListFromKAPI("QPE/Application/ompi", this->name() /* name is here the unique uid*/); | ||
188 | // the result should now arrive through method insertAttendees | ||
189 | #endif | ||
190 | } | ||
191 | //the map includes name/email pairs, that comes from Ka/Pi | ||
192 | void ComposeMail::insertAttendees(const QString& uid,const QStringList& nameList,const QStringList& emailList,const QStringList& uidList) | ||
193 | { | ||
194 | qDebug("ComposeMail::insertAttendees "); | ||
195 | raise(); | ||
196 | |||
197 | if ( mPickLineEdit == 0 ) { //whoami received | ||
198 | |||
199 | QString defmail = uidList[0]; | ||
200 | if ( emailList.count() == 0 ) | ||
201 | QMessageBox::information( 0, tr( "Hint" ), | ||
202 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), | ||
203 | tr( "Ok" ) ); | ||
204 | if (defmail.length()!=0) { | ||
205 | fromBox->insertItem(defmail); | ||
206 | } | ||
207 | QStringList::ConstIterator sit = emailList.begin(); | ||
208 | int pref = 0; | ||
209 | for (;sit!=emailList.end();++sit) { | ||
210 | if ( (*sit)==defmail) | ||
211 | continue; | ||
212 | fromBox->insertItem((*sit)); | ||
213 | } | ||
214 | senderNameEdit->setText(nameList[0]); | ||
215 | return; | ||
216 | } | ||
217 | QString names ; | ||
218 | QLineEdit *line = mPickLineEdit; | ||
219 | if (uid == this->name()) | ||
220 | { | ||
221 | for ( int i = 0; i < nameList.count(); i++) | ||
222 | { | ||
223 | QString _name = nameList[i]; | ||
224 | QString _email = emailList[i]; | ||
225 | QString _uid = uidList[i]; | ||
226 | if ( ! _email.isEmpty() ) { | ||
227 | if ( ! names.isEmpty() ) | ||
228 | names+= ","; | ||
229 | names+= "\""+_name +"\"<" +_email +">"; | ||
230 | } | ||
231 | } | ||
232 | } | ||
233 | if ( line->text().isEmpty() ) { | ||
234 | line->setText( names ); | ||
235 | } else if ( !names.isEmpty() ) { | ||
236 | line->setText( line->text() + ", " + names ); | ||
237 | } | ||
164 | } | 238 | } |
165 | |||
166 | 239 | ||
167 | void ComposeMail::setTo( const QString & to ) | 240 | void ComposeMail::setTo( const QString & to ) |
168 | { | 241 | { |
169 | toLine->setText( to ); | 242 | toLine->setText( to ); |
170 | } | 243 | } |
171 | 244 | ||
@@ -184,28 +257,32 @@ void ComposeMail::setMessage( const QString & text ) | |||
184 | message->setText( text ); | 257 | message->setText( text ); |
185 | } | 258 | } |
186 | 259 | ||
187 | 260 | ||
188 | void ComposeMail::pickAddressTo() | 261 | void ComposeMail::pickAddressTo() |
189 | { | 262 | { |
190 | pickAddress( toLine ); | 263 | mPickLineEdit = toLine; |
264 | pickAddress( ); | ||
191 | } | 265 | } |
192 | 266 | ||
193 | void ComposeMail::pickAddressCC() | 267 | void ComposeMail::pickAddressCC() |
194 | { | 268 | { |
195 | pickAddress( ccLine ); | 269 | mPickLineEdit = ccLine; |
270 | pickAddress( ); | ||
196 | } | 271 | } |
197 | 272 | ||
198 | void ComposeMail::pickAddressBCC() | 273 | void ComposeMail::pickAddressBCC() |
199 | { | 274 | { |
200 | pickAddress( bccLine ); | 275 | mPickLineEdit = bccLine; |
276 | pickAddress( ); | ||
201 | } | 277 | } |
202 | 278 | ||
203 | void ComposeMail::pickAddressReply() | 279 | void ComposeMail::pickAddressReply() |
204 | { | 280 | { |
205 | pickAddress( replyLine ); | 281 | mPickLineEdit = replyLine; |
282 | pickAddress( ); | ||
206 | } | 283 | } |
207 | 284 | ||
208 | void ComposeMail::fillValues( int ) | 285 | void ComposeMail::fillValues( int ) |
209 | { | 286 | { |
210 | #if 0 | 287 | #if 0 |
211 | SMTPaccount *smtp = smtpAccounts.at( current ); | 288 | SMTPaccount *smtp = smtpAccounts.at( current ); |