#include <Composer.h>
Public Member Functions | |
Composer (WContainerWidget *parent=0) | |
Construct a new Composer. | |
void | setTo (const std::vector< Contact > &to) |
Set message To: contacts. | |
void | setSubject (const WString &subject) |
Set subject. | |
void | setMessage (const WString &message) |
Set the message. | |
void | setAddressBook (const std::vector< Contact > &addressBook) |
Set the address book, for autocomplete suggestions. | |
std::vector< Contact > | to () const |
Get the To: contacts. | |
std::vector< Contact > | cc () const |
Get the Cc: contacts. | |
std::vector< Contact > | bcc () const |
Get the Bc: contacts. | |
const WString & | subject () const |
Get the subject. | |
std::vector< Attachment > | attachments () const |
Get the list of attachments. | |
const WString & | message () const |
Get the message. | |
Public Attributes | |
Wt::Signal< void > | send |
The message is ready to be sent... | |
Wt::Signal< void > | discard |
The message must be discarded. | |
Private Member Functions | |
void | attachMore () |
Add an attachment edit. | |
void | removeAttachment (AttachmentEdit *attachment) |
Remove the given attachment edit. | |
void | sendIt () |
Slot attached to the Send button. | |
void | saveNow () |
Slot attached to the Save now button. | |
void | discardIt () |
Slot attached to the Discard button. | |
void | attachmentDone () |
Slotcalled when an attachment has been uploaded. | |
void | createUi () |
void | saved () |
All attachments have been processed, determine the result of saving the message. | |
void | setStatus (const WString &text, const WString &style) |
Set the status, and apply the given style. | |
Private Attributes | |
WContainerWidget * | layout_ |
WPushButton * | topSendButton_ |
WPushButton * | topSaveNowButton_ |
WPushButton * | topDiscardButton_ |
WPushButton * | botSendButton_ |
WPushButton * | botSaveNowButton_ |
WPushButton * | botDiscardButton_ |
WText * | statusMsg_ |
WTable * | edits_ |
AddresseeEdit * | toEdit_ |
To: Addressees edit. | |
AddresseeEdit * | ccEdit_ |
Cc: Addressees edit. | |
AddresseeEdit * | bccEdit_ |
Bcc: Addressees edit. | |
ContactSuggestions * | contactSuggestions_ |
The suggestions popup for the addressee edits. | |
WLineEdit * | subject_ |
The subject line edit. | |
OptionList * | options_ |
OptionsList for editing Cc or Bcc. | |
Option * | addcc_ |
Option for editing Cc:. | |
Option * | addbcc_ |
Option for editing Bcc:. | |
Option * | attachFile_ |
Option for attaching a file. | |
Option * | attachOtherFile_ |
Option for attaching another file. | |
std::vector< AttachmentEdit * > | attachments_ |
Array which holds all the attachments, including one extra invisible one. | |
WTextArea * | message_ |
WTextArea for the main message. | |
bool | saving_ |
state when waiting asyncrhonously for attachments to be uploaded | |
bool | sending_ |
int | attachmentsPending_ |
number of attachments waiting to be uploaded during saving | |
Friends | |
class | AttachmentEdit |
This widget is part of the Wt composer example.
Definition at line 40 of file Composer.h.
Composer::Composer | ( | WContainerWidget * | parent = 0 |
) |
Construct a new Composer.
Definition at line 25 of file Composer.C.
00026 : WCompositeWidget(parent), 00027 saving_(false), 00028 sending_(false) 00029 { 00030 setImplementation(layout_ = new WContainerWidget()); 00031 00032 createUi(); 00033 }
void Composer::setTo | ( | const std::vector< Contact > & | to | ) |
Set message To: contacts.
Definition at line 35 of file Composer.C.
00036 { 00037 toEdit_->setAddressees(to); 00038 }
void Composer::setSubject | ( | const WString & | subject | ) |
void Composer::setMessage | ( | const WString & | message | ) |
void Composer::setAddressBook | ( | const std::vector< Contact > & | addressBook | ) |
Set the address book, for autocomplete suggestions.
Definition at line 65 of file Composer.C.
00066 { 00067 contactSuggestions_->setAddressBook(contacts); 00068 }
std::vector< Contact > Composer::to | ( | ) | const |
Get the To: contacts.
Definition at line 50 of file Composer.C.
00051 { 00052 return toEdit_->addressees(); 00053 }
std::vector< Contact > Composer::cc | ( | ) | const |
Get the Cc: contacts.
Definition at line 55 of file Composer.C.
00056 { 00057 return ccEdit_->addressees(); 00058 }
std::vector< Contact > Composer::bcc | ( | ) | const |
Get the Bc: contacts.
Definition at line 60 of file Composer.C.
00061 { 00062 return bccEdit_->addressees(); 00063 }
const WString & Composer::subject | ( | ) | const |
std::vector< Attachment > Composer::attachments | ( | ) | const |
Get the list of attachments.
The ownership of the attachment spool files is transferred to the caller as well, be sure to delete them !
Definition at line 75 of file Composer.C.
00076 { 00077 std::vector<Attachment> attachments; 00078 00079 for (unsigned i = 0; i < attachments_.size() - 1; ++i) { 00080 if (attachments_[i]->include()) 00081 attachments.push_back(attachments_[i]->attachment()); 00082 } 00083 00084 return attachments; 00085 }
const WString & Composer::message | ( | ) | const |
void Composer::attachMore | ( | ) | [private] |
Add an attachment edit.
Definition at line 249 of file Composer.C.
00250 { 00251 /* 00252 * Create and append the next AttachmentEdit, that will be hidden. 00253 */ 00254 AttachmentEdit *edit = new AttachmentEdit(this); 00255 edits_->elementAt(5, 1)->insertBefore(edit, attachOtherFile_); 00256 attachments_.push_back(edit); 00257 attachments_.back()->hide(); 00258 00259 // Connect the attachOtherFile_ option to show this attachment. 00260 attachOtherFile_->item()->clicked().connect(SLOT(attachments_.back(), 00261 WWidget::show)); 00262 }
void Composer::removeAttachment | ( | AttachmentEdit * | attachment | ) | [private] |
Remove the given attachment edit.
Definition at line 264 of file Composer.C.
00265 { 00266 /* 00267 * Remove the given attachment from the attachments list. 00268 */ 00269 std::vector<AttachmentEdit *>::iterator i 00270 = std::find(attachments_.begin(), attachments_.end(), attachment); 00271 00272 if (i != attachments_.end()) { 00273 attachments_.erase(i); 00274 delete attachment; 00275 00276 if (attachments_.size() == 1) { 00277 /* 00278 * This was the last visible attachment, thus, we should switch 00279 * the option control again. 00280 */ 00281 attachOtherFile_->hide(); 00282 attachFile_->show(); 00283 attachFile_->item()->clicked().connect(SLOT(attachments_.back(), 00284 WWidget::show)); 00285 } 00286 } 00287 }
void Composer::sendIt | ( | ) | [private] |
Slot attached to the Send button.
Tries to save the mail message, and if succesfull, sends it.
Definition at line 289 of file Composer.C.
00290 { 00291 if (!sending_) { 00292 sending_ = true; 00293 00294 /* 00295 * First save -- this will check for the sending_ state 00296 * signal if successfull. 00297 */ 00298 saveNow(); 00299 } 00300 }
void Composer::saveNow | ( | ) | [private] |
Slot attached to the Save now button.
Tries to save the mail message, and gives feedback on failure and on success.
Definition at line 302 of file Composer.C.
00303 { 00304 if (!saving_) { 00305 saving_ = true; 00306 00307 /* 00308 * Check if any attachments still need to be uploaded. 00309 * This may be the case when fileupload change events could not 00310 * be caught (for example in Konqueror). 00311 */ 00312 attachmentsPending_ = 0; 00313 00314 for (unsigned i = 0; i < attachments_.size() - 1; ++i) { 00315 if (attachments_[i]->uploadNow()) { 00316 ++attachmentsPending_; 00317 00318 // this will trigger attachmentDone() when done, see 00319 // the AttachmentEdit constructor. 00320 } 00321 } 00322 00323 std::cerr << "Attachments pending: " << attachmentsPending_ << std::endl; 00324 if (attachmentsPending_) 00325 setStatus(tr("msg.uploading"), "status"); 00326 else 00327 saved(); 00328 } 00329 }
void Composer::discardIt | ( | ) | [private] |
Slot attached to the Discard button.
Discards the current message: emits the discard event.
Definition at line 386 of file Composer.C.
void Composer::attachmentDone | ( | ) | [private] |
Slotcalled when an attachment has been uploaded.
This used during while saving the email and waiting for remaining attachments to be uploaded. It is connected to the AttachmentEdit control signals that are emitted when an attachment has been processed.
Definition at line 331 of file Composer.C.
00332 { 00333 if (saving_) { 00334 --attachmentsPending_; 00335 std::cerr << "Attachments still: " << attachmentsPending_ << std::endl; 00336 00337 if (attachmentsPending_ == 0) 00338 saved(); 00339 } 00340 }
void Composer::createUi | ( | ) | [private] |
Definition at line 92 of file Composer.C.
00093 { 00094 setStyleClass("darker"); 00095 00096 // horizontal layout container, used for top and bottom buttons. 00097 WContainerWidget *horiz; 00098 00099 /* 00100 * Top buttons 00101 */ 00102 horiz = new WContainerWidget(layout_); 00103 horiz->setPadding(5); 00104 topSendButton_ = new WPushButton(tr("msg.send"), horiz); 00105 topSendButton_->setStyleClass("default"); // default action 00106 topSaveNowButton_ = new WPushButton(tr("msg.savenow"), horiz); 00107 topDiscardButton_ = new WPushButton(tr("msg.discard"), horiz); 00108 00109 // Text widget which shows status messages, next to the top buttons. 00110 statusMsg_ = new WText(horiz); 00111 statusMsg_->setMargin(15, Left); 00112 00113 /* 00114 * To, Cc, Bcc, Subject, Attachments 00115 * 00116 * They are organized in a two-column table: left column for 00117 * labels, and right column for the edit. 00118 */ 00119 edits_ = new WTable(layout_); 00120 edits_->setStyleClass("lighter"); 00121 edits_->resize(WLength(100, WLength::Percentage), WLength::Auto); 00122 edits_->elementAt(0, 0)->resize(WLength(1, WLength::Percentage), 00123 WLength::Auto); 00124 00125 /* 00126 * To, Cc, Bcc 00127 */ 00128 toEdit_ = new AddresseeEdit(tr("msg.to"), edits_->elementAt(0, 1), 00129 edits_->elementAt(0, 0)); 00130 // add some space above To: 00131 edits_->elementAt(0, 1)->setMargin(5, Top); 00132 ccEdit_ = new AddresseeEdit(tr("msg.cc"), edits_->elementAt(1, 1), 00133 edits_->elementAt(1, 0)); 00134 bccEdit_ = new AddresseeEdit(tr("msg.bcc"), edits_->elementAt(2, 1), 00135 edits_->elementAt(2, 0)); 00136 00137 ccEdit_->hide(); 00138 bccEdit_->hide(); 00139 00140 /* 00141 * Addressbook suggestions popup 00142 */ 00143 contactSuggestions_ = new ContactSuggestions(layout_); 00144 00145 contactSuggestions_->forEdit(toEdit_); 00146 contactSuggestions_->forEdit(ccEdit_); 00147 contactSuggestions_->forEdit(bccEdit_); 00148 00149 /* 00150 * We use an OptionList widget to show the expand options for 00151 * ccEdit_ and bccEdit_ nicely next to each other, separated 00152 * by pipe characters. 00153 */ 00154 options_ = new OptionList(edits_->elementAt(3, 1)); 00155 00156 options_->add(addcc_ = new Option(tr("msg.addcc"))); 00157 options_->add(addbcc_ = new Option(tr("msg.addbcc"))); 00158 00159 /* 00160 * Subject 00161 */ 00162 new Label(tr("msg.subject"), edits_->elementAt(4, 0)); 00163 subject_ = new WLineEdit(edits_->elementAt(4, 1)); 00164 subject_->resize(WLength(99, WLength::Percentage), WLength::Auto); 00165 00166 /* 00167 * Attachments 00168 */ 00169 new WImage("icons/paperclip.png", edits_->elementAt(5, 0)); 00170 edits_->elementAt(5, 0)->setContentAlignment(AlignRight | AlignTop); 00171 00172 00173 // Attachment edits: we always have the next attachmentedit ready 00174 // but hidden. This improves the response time, since the show() 00175 // and hide() slots are stateless. 00176 attachments_.push_back(new AttachmentEdit(this, edits_->elementAt(5, 1))); 00177 attachments_.back()->hide(); 00178 00179 /* 00180 * Two options for attaching files. The first does not say 'another'. 00181 */ 00182 attachFile_ = new Option(tr("msg.attachfile"), 00183 edits_->elementAt(5, 1)); 00184 attachOtherFile_ = new Option(tr("msg.attachanother"), 00185 edits_->elementAt(5, 1)); 00186 attachOtherFile_->hide(); 00187 00188 /* 00189 * Message 00190 */ 00191 message_ = new WTextArea(layout_); 00192 message_->setColumns(80); 00193 message_->setRows(10); // should be 20, but let's keep it smaller 00194 message_->setMargin(10); 00195 00196 /* 00197 * Bottom buttons 00198 */ 00199 horiz = new WContainerWidget(layout_); 00200 horiz->setPadding(5); 00201 botSendButton_ = new WPushButton(tr("msg.send"), horiz); 00202 botSendButton_->setStyleClass("default"); 00203 botSaveNowButton_ = new WPushButton(tr("msg.savenow"), horiz); 00204 botDiscardButton_ = new WPushButton(tr("msg.discard"), horiz); 00205 00206 /* 00207 * Button events. 00208 */ 00209 topSendButton_->clicked().connect(SLOT(this, Composer::sendIt)); 00210 botSendButton_->clicked().connect(SLOT(this, Composer::sendIt)); 00211 topSaveNowButton_->clicked().connect(SLOT(this, Composer::saveNow)); 00212 botSaveNowButton_->clicked().connect(SLOT(this, Composer::saveNow)); 00213 topDiscardButton_->clicked().connect(SLOT(this, Composer::discardIt)); 00214 botDiscardButton_->clicked().connect(SLOT(this, Composer::discardIt)); 00215 00216 /* 00217 * Option events to show the cc or Bcc edit. 00218 * 00219 * Clicking on the option should both show the corresponding edit, and 00220 * hide the option itself. 00221 */ 00222 addcc_->item()->clicked().connect(SLOT(ccEdit_, WWidget::show)); 00223 addcc_->item()->clicked().connect(SLOT(addcc_, WWidget::hide)); 00224 addcc_->item()->clicked().connect(SLOT(options_, OptionList::update)); 00225 addcc_->item()->clicked().connect(SLOT(ccEdit_, WFormWidget::setFocus)); 00226 00227 addbcc_->item()->clicked().connect(SLOT(bccEdit_, WWidget::show)); 00228 addbcc_->item()->clicked().connect(SLOT(addbcc_, WWidget::hide)); 00229 addbcc_->item()->clicked().connect(SLOT(options_, OptionList::update)); 00230 addbcc_->item()->clicked().connect(SLOT(bccEdit_, WFormWidget::setFocus)); 00231 00232 /* 00233 * Option event to attach the first attachment. 00234 * 00235 * We show the first attachment, and call attachMore() to prepare the 00236 * next attachment edit that will be hidden. 00237 * 00238 * In addition, we need to show the 'attach More' option, and hide the 00239 * 'attach' option. 00240 */ 00241 attachFile_->item()->clicked().connect(SLOT(attachments_.back(), 00242 WWidget::show)); 00243 attachFile_->item()->clicked().connect(SLOT(attachOtherFile_, WWidget::show)); 00244 attachFile_->item()->clicked().connect(SLOT(attachFile_, WWidget::hide)); 00245 attachFile_->item()->clicked().connect(SLOT(this, Composer::attachMore)); 00246 attachOtherFile_->item()->clicked().connect(SLOT(this, Composer::attachMore)); 00247 }
void Composer::saved | ( | ) | [private] |
All attachments have been processed, determine the result of saving the message.
Definition at line 348 of file Composer.C.
00349 { 00350 /* 00351 * All attachments have been processed. 00352 */ 00353 00354 bool attachmentsFailed = false; 00355 for (unsigned i = 0; i < attachments_.size() - 1; ++i) 00356 if (attachments_[i]->uploadFailed()) { 00357 attachmentsFailed = true; 00358 break; 00359 } 00360 00361 if (attachmentsFailed) { 00362 setStatus(tr("msg.attachment.failed"), "error"); 00363 } else { 00364 #ifndef WIN32 00365 time_t t = time(0); 00366 struct tm td; 00367 gmtime_r(&t, &td); 00368 char buffer[100]; 00369 strftime(buffer, 100, "%H:%M", &td); 00370 #else 00371 char buffer[] = "server"; // Should fix this; for now just make sense 00372 #endif 00373 setStatus(tr("msg.ok"), "status"); 00374 statusMsg_->setText(std::string("Draft saved at ") + buffer); 00375 00376 if (sending_) { 00377 send.emit(); 00378 return; 00379 } 00380 } 00381 00382 saving_ = false; 00383 sending_ = false; 00384 }
Set the status, and apply the given style.
Definition at line 342 of file Composer.C.
00343 { 00344 statusMsg_->setText(text); 00345 statusMsg_->setStyleClass(style); 00346 }
friend class AttachmentEdit [friend] |
Definition at line 194 of file Composer.h.
Wt::Signal<void> Composer::send |
Wt::Signal<void> Composer::discard |
WContainerWidget* Composer::layout_ [private] |
Definition at line 100 of file Composer.h.
WPushButton* Composer::topSendButton_ [private] |
Definition at line 102 of file Composer.h.
WPushButton * Composer::topSaveNowButton_ [private] |
Definition at line 102 of file Composer.h.
WPushButton * Composer::topDiscardButton_ [private] |
Definition at line 102 of file Composer.h.
WPushButton* Composer::botSendButton_ [private] |
Definition at line 103 of file Composer.h.
WPushButton * Composer::botSaveNowButton_ [private] |
Definition at line 103 of file Composer.h.
WPushButton * Composer::botDiscardButton_ [private] |
Definition at line 103 of file Composer.h.
WText* Composer::statusMsg_ [private] |
Definition at line 104 of file Composer.h.
WTable* Composer::edits_ [private] |
Definition at line 106 of file Composer.h.
AddresseeEdit* Composer::toEdit_ [private] |
AddresseeEdit* Composer::ccEdit_ [private] |
AddresseeEdit* Composer::bccEdit_ [private] |
ContactSuggestions* Composer::contactSuggestions_ [private] |
WLineEdit* Composer::subject_ [private] |
OptionList* Composer::options_ [private] |
Option* Composer::addcc_ [private] |
Option* Composer::addbcc_ [private] |
Option* Composer::attachFile_ [private] |
Option* Composer::attachOtherFile_ [private] |
std::vector<AttachmentEdit *> Composer::attachments_ [private] |
Array which holds all the attachments, including one extra invisible one.
Definition at line 134 of file Composer.h.
WTextArea* Composer::message_ [private] |
bool Composer::saving_ [private] |
state when waiting asyncrhonously for attachments to be uploaded
Definition at line 140 of file Composer.h.
bool Composer::sending_ [private] |
Definition at line 140 of file Composer.h.
int Composer::attachmentsPending_ [private] |
number of attachments waiting to be uploaded during saving
Definition at line 143 of file Composer.h.