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