-rw-r--r-- | kmicromail/composemail.cpp | 1 |
1 files changed, 1 insertions, 0 deletions
diff --git a/kmicromail/composemail.cpp b/kmicromail/composemail.cpp index 9060364..654cfc0 100644 --- a/kmicromail/composemail.cpp +++ b/kmicromail/composemail.cpp | |||
@@ -1,192 +1,193 @@ | |||
1 | // CHANGED 2004-08-06 Lutz Rogowski | ||
1 | 2 | ||
2 | #include "composemail.h" | 3 | #include "composemail.h" |
3 | 4 | ||
4 | #include <libmailwrapper/smtpwrapper.h> | 5 | #include <libmailwrapper/smtpwrapper.h> |
5 | #include <libmailwrapper/storemail.h> | 6 | #include <libmailwrapper/storemail.h> |
6 | #include <libmailwrapper/abstractmail.h> | 7 | #include <libmailwrapper/abstractmail.h> |
7 | #include <libmailwrapper/mailtypes.h> | 8 | #include <libmailwrapper/mailtypes.h> |
8 | 9 | ||
9 | /* OPIE */ | 10 | /* OPIE */ |
10 | //#include <opie2/ofiledialog.h> | 11 | //#include <opie2/ofiledialog.h> |
11 | //#include <opie2/odebug.h> | 12 | //#include <opie2/odebug.h> |
12 | #include <kfiledialog.h> | 13 | #include <kfiledialog.h> |
13 | //#include <qpe/resource.h> | 14 | //#include <qpe/resource.h> |
14 | #include <qpe/config.h> | 15 | #include <qpe/config.h> |
15 | #include <qpe/global.h> | 16 | #include <qpe/global.h> |
16 | //#include <qpe/contact.h> | 17 | //#include <qpe/contact.h> |
17 | 18 | ||
18 | 19 | ||
19 | #include <qcombobox.h> | 20 | #include <qcombobox.h> |
20 | #include <qcheckbox.h> | 21 | #include <qcheckbox.h> |
21 | #include <qtimer.h> | 22 | #include <qtimer.h> |
22 | #include <qmessagebox.h> | 23 | #include <qmessagebox.h> |
23 | #include <qpushbutton.h> | 24 | #include <qpushbutton.h> |
24 | #include <qmultilineedit.h> | 25 | #include <qmultilineedit.h> |
25 | #include <qlabel.h> | 26 | #include <qlabel.h> |
26 | #include <qtabwidget.h> | 27 | #include <qtabwidget.h> |
27 | #include <qlistview.h> | 28 | #include <qlistview.h> |
28 | #include <kabc/addresseedialog.h> | 29 | #include <kabc/addresseedialog.h> |
29 | #include <kabc/stdaddressbook.h> | 30 | #include <kabc/stdaddressbook.h> |
30 | #include <kabc/addressee.h> | 31 | #include <kabc/addressee.h> |
31 | 32 | ||
32 | 33 | ||
33 | 34 | ||
34 | //using namespace Opie::Core; | 35 | //using namespace Opie::Core; |
35 | //using namespace Opie::Ui; | 36 | //using namespace Opie::Ui; |
36 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | 37 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) |
37 | : ComposeMailUI( parent, name, modal, flags ) | 38 | : ComposeMailUI( parent, name, modal, flags ) |
38 | { | 39 | { |
39 | 40 | ||
40 | settings = s; | 41 | settings = s; |
41 | m_replyid = ""; | 42 | m_replyid = ""; |
42 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); | 43 | KABC::Addressee con = KABC::StdAddressBook::self()->whoAmI( ); |
43 | QStringList mails = con.emails(); | 44 | QStringList mails = con.emails(); |
44 | QString defmail = con.preferredEmail(); | 45 | QString defmail = con.preferredEmail(); |
45 | if ( mails.count() == 0) | 46 | if ( mails.count() == 0) |
46 | QMessageBox::information( 0, tr( "Hint" ), | 47 | QMessageBox::information( 0, tr( "Hint" ), |
47 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), | 48 | tr( "Please apply\n\"Set Who Am I\"\nin KA/Pi to get the from\nfield automatically filled out!\n" ), |
48 | tr( "Ok" ) ); | 49 | tr( "Ok" ) ); |
49 | if (defmail.length()!=0) { | 50 | if (defmail.length()!=0) { |
50 | fromBox->insertItem(defmail); | 51 | fromBox->insertItem(defmail); |
51 | } | 52 | } |
52 | QStringList::ConstIterator sit = mails.begin(); | 53 | QStringList::ConstIterator sit = mails.begin(); |
53 | for (;sit!=mails.end();++sit) { | 54 | for (;sit!=mails.end();++sit) { |
54 | if ( (*sit)==defmail) | 55 | if ( (*sit)==defmail) |
55 | continue; | 56 | continue; |
56 | fromBox->insertItem((*sit)); | 57 | fromBox->insertItem((*sit)); |
57 | } | 58 | } |
58 | senderNameEdit->setText(con.formattedName()); | 59 | senderNameEdit->setText(con.formattedName()); |
59 | Config cfg( "mail" ); | 60 | Config cfg( "mail" ); |
60 | cfg.setGroup( "Compose" ); | 61 | cfg.setGroup( "Compose" ); |
61 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); | 62 | checkBoxLater->setChecked( cfg.readBoolEntry( "sendLater", false ) ); |
62 | 63 | ||
63 | attList->addColumn( tr( "Name" ) ); | 64 | attList->addColumn( tr( "Name" ) ); |
64 | attList->addColumn( tr( "Size" ) ); | 65 | attList->addColumn( tr( "Size" ) ); |
65 | 66 | ||
66 | QList<Account> accounts = settings->getAccounts(); | 67 | QList<Account> accounts = settings->getAccounts(); |
67 | 68 | ||
68 | Account *it; | 69 | Account *it; |
69 | for ( it = accounts.first(); it; it = accounts.next() ) { | 70 | for ( it = accounts.first(); it; it = accounts.next() ) { |
70 | if ( it->getType()==MAILLIB::A_SMTP ) { | 71 | if ( it->getType()==MAILLIB::A_SMTP ) { |
71 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | 72 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); |
72 | smtpAccountBox->insertItem( smtp->getAccountName() ); | 73 | smtpAccountBox->insertItem( smtp->getAccountName() ); |
73 | smtpAccounts.append( smtp ); | 74 | smtpAccounts.append( smtp ); |
74 | } | 75 | } |
75 | } | 76 | } |
76 | if ( smtpAccounts.count() > 0 ) { | 77 | if ( smtpAccounts.count() > 0 ) { |
77 | fillValues( smtpAccountBox->currentItem() ); | 78 | fillValues( smtpAccountBox->currentItem() ); |
78 | } else { | 79 | } else { |
79 | QMessageBox::information( 0, tr( "Problem" ), | 80 | QMessageBox::information( 0, tr( "Problem" ), |
80 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail.\n" ), | 81 | tr( "Please create an SMTP account first.\nThe SMTP is needed for sending mail.\n" ), |
81 | tr( "Ok" ) ); | 82 | tr( "Ok" ) ); |
82 | return; | 83 | return; |
83 | } | 84 | } |
84 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); | 85 | connect( smtpAccountBox, SIGNAL( activated(int) ), SLOT( fillValues(int) ) ); |
85 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | 86 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); |
86 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | 87 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); |
87 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | 88 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); |
88 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | 89 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); |
89 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | 90 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); |
90 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | 91 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); |
91 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); | 92 | connect( SaveButton, SIGNAL( clicked() ), SLOT( saveAsDraft()) ); |
92 | mMail = 0; | 93 | mMail = 0; |
93 | warnAttach = true; | 94 | warnAttach = true; |
94 | 95 | ||
95 | } | 96 | } |
96 | void ComposeMail::saveAsDraft() | 97 | void ComposeMail::saveAsDraft() |
97 | { | 98 | { |
98 | 99 | ||
99 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); | 100 | Opie::Core::OSmartPointer<Mail> mail= new Mail(); |
100 | mail->setMail(fromBox->currentText()); | 101 | mail->setMail(fromBox->currentText()); |
101 | mail->setTo( toLine->text() ); | 102 | mail->setTo( toLine->text() ); |
102 | mail->setName(senderNameEdit->text()); | 103 | mail->setName(senderNameEdit->text()); |
103 | mail->setCC( ccLine->text() ); | 104 | mail->setCC( ccLine->text() ); |
104 | mail->setBCC( bccLine->text() ); | 105 | mail->setBCC( bccLine->text() ); |
105 | mail->setReply( replyLine->text() ); | 106 | mail->setReply( replyLine->text() ); |
106 | mail->setSubject( subjectLine->text() ); | 107 | mail->setSubject( subjectLine->text() ); |
107 | if (!m_replyid.isEmpty()) { | 108 | if (!m_replyid.isEmpty()) { |
108 | QStringList ids; | 109 | QStringList ids; |
109 | ids.append(m_replyid); | 110 | ids.append(m_replyid); |
110 | mail->setInreply(ids); | 111 | mail->setInreply(ids); |
111 | } | 112 | } |
112 | QString txt = message->text(); | 113 | QString txt = message->text(); |
113 | if ( !sigMultiLine->text().isEmpty() ) { | 114 | if ( !sigMultiLine->text().isEmpty() ) { |
114 | txt.append( "\n--\n" ); | 115 | txt.append( "\n--\n" ); |
115 | txt.append( sigMultiLine->text() ); | 116 | txt.append( sigMultiLine->text() ); |
116 | } | 117 | } |
117 | mail->setMessage( txt ); | 118 | mail->setMessage( txt ); |
118 | 119 | ||
119 | /* only use the default drafts folder name! */ | 120 | /* only use the default drafts folder name! */ |
120 | Storemail wrapper(AbstractMail::draftFolder()); | 121 | Storemail wrapper(AbstractMail::draftFolder()); |
121 | wrapper.storeMail(mail); | 122 | wrapper.storeMail(mail); |
122 | 123 | ||
123 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | 124 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); |
124 | /* attachments we will ignore! */ | 125 | /* attachments we will ignore! */ |
125 | if ( it != 0 ) { | 126 | if ( it != 0 ) { |
126 | if ( warnAttach ) | 127 | if ( warnAttach ) |
127 | QMessageBox::warning(0,tr("Store message"), | 128 | QMessageBox::warning(0,tr("Store message"), |
128 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); | 129 | tr("<center>Attachments will not be stored in \"Draft\" folder</center>")); |
129 | warnAttach = false; | 130 | warnAttach = false; |
130 | } | 131 | } |
131 | setStatus( tr("Mail saved as draft!") ); | 132 | setStatus( tr("Mail saved as draft!") ); |
132 | } | 133 | } |
133 | void ComposeMail::clearStatus() | 134 | void ComposeMail::clearStatus() |
134 | { | 135 | { |
135 | topLevelWidget()->setCaption( tr("Compose mail") ); | 136 | topLevelWidget()->setCaption( tr("Compose mail") ); |
136 | } | 137 | } |
137 | void ComposeMail::setStatus( QString status ) | 138 | void ComposeMail::setStatus( QString status ) |
138 | { | 139 | { |
139 | topLevelWidget()->setCaption( status ); | 140 | topLevelWidget()->setCaption( status ); |
140 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; | 141 | QTimer::singleShot ( 10000, this, SLOT( clearStatus() ) ) ; |
141 | } | 142 | } |
142 | void ComposeMail::pickAddress( QLineEdit *line ) | 143 | void ComposeMail::pickAddress( QLineEdit *line ) |
143 | { | 144 | { |
144 | //qDebug(" ComposeMail::pickAddress "); | 145 | //qDebug(" ComposeMail::pickAddress "); |
145 | QString names ;//= AddressPicker::getNames(); | 146 | QString names ;//= AddressPicker::getNames(); |
146 | 147 | ||
147 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); | 148 | KABC::Addressee::List list = KABC::AddresseeDialog::getAddressees(this); |
148 | uint i=0; | 149 | uint i=0; |
149 | for (i=0; i < list.count(); i++) { | 150 | for (i=0; i < list.count(); i++) { |
150 | if ( !list[i].preferredEmail().isEmpty()) { | 151 | if ( !list[i].preferredEmail().isEmpty()) { |
151 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; | 152 | names+= "\""+list[i].realName() +"\"<" +list[i].preferredEmail() +">"; |
152 | if ( i < list.count() -1 ) | 153 | if ( i < list.count() -1 ) |
153 | names+= ","; | 154 | names+= ","; |
154 | } | 155 | } |
155 | } | 156 | } |
156 | 157 | ||
157 | 158 | ||
158 | if ( line->text().isEmpty() ) { | 159 | if ( line->text().isEmpty() ) { |
159 | line->setText( names ); | 160 | line->setText( names ); |
160 | } else if ( !names.isEmpty() ) { | 161 | } else if ( !names.isEmpty() ) { |
161 | line->setText( line->text() + ", " + names ); | 162 | line->setText( line->text() + ", " + names ); |
162 | } | 163 | } |
163 | } | 164 | } |
164 | 165 | ||
165 | 166 | ||
166 | void ComposeMail::setTo( const QString & to ) | 167 | void ComposeMail::setTo( const QString & to ) |
167 | { | 168 | { |
168 | toLine->setText( to ); | 169 | toLine->setText( to ); |
169 | } | 170 | } |
170 | 171 | ||
171 | void ComposeMail::setSubject( const QString & subject ) | 172 | void ComposeMail::setSubject( const QString & subject ) |
172 | { | 173 | { |
173 | subjectLine->setText( subject ); | 174 | subjectLine->setText( subject ); |
174 | } | 175 | } |
175 | 176 | ||
176 | void ComposeMail::setInReplyTo( const QString & messageId ) | 177 | void ComposeMail::setInReplyTo( const QString & messageId ) |
177 | { | 178 | { |
178 | m_replyid = messageId; | 179 | m_replyid = messageId; |
179 | } | 180 | } |
180 | 181 | ||
181 | void ComposeMail::setMessage( const QString & text ) | 182 | void ComposeMail::setMessage( const QString & text ) |
182 | { | 183 | { |
183 | message->setText( text ); | 184 | message->setText( text ); |
184 | } | 185 | } |
185 | 186 | ||
186 | 187 | ||
187 | void ComposeMail::pickAddressTo() | 188 | void ComposeMail::pickAddressTo() |
188 | { | 189 | { |
189 | pickAddress( toLine ); | 190 | pickAddress( toLine ); |
190 | } | 191 | } |
191 | 192 | ||
192 | void ComposeMail::pickAddressCC() | 193 | void ComposeMail::pickAddressCC() |