Diffstat (limited to 'noncore/net/mail/composemail.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/net/mail/composemail.cpp | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/noncore/net/mail/composemail.cpp b/noncore/net/mail/composemail.cpp new file mode 100644 index 0000000..a17ccb3 --- a/dev/null +++ b/noncore/net/mail/composemail.cpp | |||
@@ -0,0 +1,180 @@ | |||
1 | #include <qt.h> | ||
2 | #include <qcombobox.h> | ||
3 | #include <qmessagebox.h> | ||
4 | #include <qlistview.h> | ||
5 | #include <qtabwidget.h> | ||
6 | #include <qmultilineedit.h> | ||
7 | #include <qregexp.h> | ||
8 | |||
9 | #include <opie/ofiledialog.h> | ||
10 | #include <qpe/resource.h> | ||
11 | |||
12 | #include "composemail.h" | ||
13 | #include "mailwrapper.h" | ||
14 | |||
15 | ComposeMail::ComposeMail( Settings *s, QWidget *parent, const char *name, bool modal, WFlags flags ) | ||
16 | : ComposeMailUI( parent, name, modal, flags ) | ||
17 | { | ||
18 | settings = s; | ||
19 | |||
20 | attList->addColumn( tr( "Name" ) ); | ||
21 | attList->addColumn( tr( "Size" ) ); | ||
22 | |||
23 | QList<Account> accounts = settings->getAccounts(); | ||
24 | Account *it; | ||
25 | for ( it = accounts.first(); it; it = accounts.next() ) { | ||
26 | if ( it->getType().compare( "SMTP" ) == 0 ) { | ||
27 | SMTPaccount *smtp = static_cast<SMTPaccount *>(it); | ||
28 | fromBox->insertItem( smtp->getMail() ); | ||
29 | smtpAccounts.append( smtp ); | ||
30 | } | ||
31 | } | ||
32 | |||
33 | if ( smtpAccounts.count() > 0 ) { | ||
34 | fillValues( fromBox->currentItem() ); | ||
35 | } else { | ||
36 | QMessageBox::information( this, tr( "Problem" ), | ||
37 | tr( "<p>Please create an SMTP account first.</p>" ), | ||
38 | tr( "Ok" ) ); | ||
39 | } | ||
40 | |||
41 | connect( fromBox, SIGNAL( activated( int ) ), SLOT( fillValues( int ) ) ); | ||
42 | connect( toButton, SIGNAL( clicked() ), SLOT( pickAddressTo() ) ); | ||
43 | connect( ccButton, SIGNAL( clicked() ), SLOT( pickAddressCC() ) ); | ||
44 | connect( bccButton, SIGNAL( clicked() ), SLOT( pickAddressBCC() ) ); | ||
45 | connect( replyButton, SIGNAL( clicked() ), SLOT( pickAddressReply() ) ); | ||
46 | connect( addButton, SIGNAL( clicked() ), SLOT( addAttachment() ) ); | ||
47 | connect( deleteButton, SIGNAL( clicked() ), SLOT( removeAttachment() ) ); | ||
48 | } | ||
49 | |||
50 | void ComposeMail::pickAddress( QLineEdit *line ) | ||
51 | { | ||
52 | QString names = AddressPicker::getNames(); | ||
53 | if ( line->text().isEmpty() ) { | ||
54 | line->setText( names ); | ||
55 | } else if ( !names.isEmpty() ) { | ||
56 | line->setText( line->text() + ", " + names ); | ||
57 | } | ||
58 | } | ||
59 | |||
60 | void ComposeMail::pickAddressTo() | ||
61 | { | ||
62 | pickAddress( toLine ); | ||
63 | } | ||
64 | |||
65 | void ComposeMail::pickAddressCC() | ||
66 | { | ||
67 | pickAddress( ccLine ); | ||
68 | } | ||
69 | |||
70 | void ComposeMail::pickAddressBCC() | ||
71 | { | ||
72 | pickAddress( bccLine ); | ||
73 | } | ||
74 | |||
75 | void ComposeMail::pickAddressReply() | ||
76 | { | ||
77 | pickAddress( replyLine ); | ||
78 | } | ||
79 | |||
80 | void ComposeMail::fillValues( int current ) | ||
81 | { | ||
82 | SMTPaccount *smtp = smtpAccounts.at( current ); | ||
83 | |||
84 | ccLine->clear(); | ||
85 | if ( smtp->getUseCC() ) { | ||
86 | ccLine->setText( smtp->getCC() ); | ||
87 | } | ||
88 | bccLine->clear(); | ||
89 | if ( smtp->getUseBCC() ) { | ||
90 | bccLine->setText( smtp->getBCC() ); | ||
91 | } | ||
92 | replyLine->clear(); | ||
93 | if ( smtp->getUseReply() ) { | ||
94 | replyLine->setText( smtp->getReply() ); | ||
95 | } | ||
96 | |||
97 | sigMultiLine->setText( smtp->getSignature() ); | ||
98 | } | ||
99 | |||
100 | void ComposeMail::slotAdjustColumns() | ||
101 | { | ||
102 | int currPage = tabWidget->currentPageIndex(); | ||
103 | |||
104 | tabWidget->showPage( attachTab ); | ||
105 | attList->setColumnWidth( 0, attList->visibleWidth() - 80 ); | ||
106 | attList->setColumnWidth( 1, 80 ); | ||
107 | |||
108 | tabWidget->setCurrentPage( currPage ); | ||
109 | } | ||
110 | |||
111 | void ComposeMail::addAttachment() | ||
112 | { | ||
113 | DocLnk lnk = OFileDialog::getOpenFileName( 1, "/" ); | ||
114 | if ( !lnk.name().isEmpty() ) { | ||
115 | Attachment *att = new Attachment( lnk ); | ||
116 | (void) new AttachViewItem( attList, att ); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | void ComposeMail::removeAttachment() | ||
121 | { | ||
122 | if ( !attList->currentItem() ) { | ||
123 | QMessageBox::information( this, tr( "Error" ), | ||
124 | tr( "<p>Please select a File.</p>" ), | ||
125 | tr( "Ok" ) ); | ||
126 | } else { | ||
127 | attList->takeItem( attList->currentItem() ); | ||
128 | } | ||
129 | } | ||
130 | |||
131 | void ComposeMail::accept() | ||
132 | { | ||
133 | qDebug( "Sending Mail with " + | ||
134 | smtpAccounts.at( fromBox->currentItem() )->getAccountName() ); | ||
135 | Mail *mail = new Mail(); | ||
136 | SMTPaccount *smtp = smtpAccounts.at( fromBox->currentItem() ); | ||
137 | mail->setMail( smtp->getMail() ); | ||
138 | mail->setName( smtp->getName() ); | ||
139 | |||
140 | if ( !toLine->text().isEmpty() ) { | ||
141 | mail->setTo( toLine->text() ); | ||
142 | } else { | ||
143 | qDebug( "No Reciever spezified -> returning" ); | ||
144 | return; | ||
145 | } | ||
146 | |||
147 | mail->setCC( ccLine->text() ); | ||
148 | mail->setBCC( bccLine->text() ); | ||
149 | mail->setReply( replyLine->text() ); | ||
150 | mail->setSubject( subjectLine->text() ); | ||
151 | QString txt = message->text(); | ||
152 | if ( !sigMultiLine->text().isEmpty() ) { | ||
153 | txt.append( "\n--\n" ); | ||
154 | txt.append( sigMultiLine->text() ); | ||
155 | } | ||
156 | mail->setMessage( txt ); | ||
157 | AttachViewItem *it = (AttachViewItem *) attList->firstChild(); | ||
158 | while ( it != NULL ) { | ||
159 | mail->addAttachment( it->getAttachment() ); | ||
160 | it = (AttachViewItem *) it->itemBelow(); | ||
161 | } | ||
162 | |||
163 | MailWrapper wrapper( settings ); | ||
164 | wrapper.sendMail( *mail ); | ||
165 | |||
166 | QDialog::accept(); | ||
167 | } | ||
168 | |||
169 | AttachViewItem::AttachViewItem( QListView *parent, Attachment *att ) | ||
170 | : QListViewItem( parent ) | ||
171 | { | ||
172 | attachment = att; | ||
173 | qDebug( att->getMimeType() ); | ||
174 | setPixmap( 0, attachment->getDocLnk().pixmap().isNull() ? | ||
175 | Resource::loadPixmap( "UnknownDocument-14" ) : | ||
176 | attachment->getDocLnk().pixmap() ); | ||
177 | setText( 0, att->getName().isEmpty() ? att->getFileName() : att->getName() ); | ||
178 | setText( 1, QString::number( att->getSize() ) ); | ||
179 | } | ||
180 | |||