Wt examples
3.2.3
|
An E-mail composer widget. More...
#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 |
An E-mail composer widget.
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.
: WCompositeWidget(parent), saving_(false), sending_(false) { setImplementation(layout_ = new WContainerWidget()); createUi(); }
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.
{ if (saving_) { --attachmentsPending_; std::cerr << "Attachments still: " << attachmentsPending_ << std::endl; if (attachmentsPending_ == 0) saved(); } }
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.
{ std::vector<Attachment> attachments; for (unsigned i = 0; i < attachments_.size() - 1; ++i) { std::vector<Attachment> toadd = attachments_[i]->attachments(); attachments.insert(attachments.end(), toadd.begin(), toadd.end()); } return attachments; }
void Composer::attachMore | ( | ) | [private] |
Add an attachment edit.
Definition at line 249 of file Composer.C.
{ /* * Create and append the next AttachmentEdit, that will be hidden. */ AttachmentEdit *edit = new AttachmentEdit(this); edits_->elementAt(5, 1)->insertBefore(edit, attachOtherFile_); attachments_.push_back(edit); attachments_.back()->hide(); // Connect the attachOtherFile_ option to show this attachment. attachOtherFile_->item()->clicked() .connect(attachments_.back(), &WWidget::show); }
std::vector< Contact > Composer::bcc | ( | ) | const |
std::vector< Contact > Composer::cc | ( | ) | const |
void Composer::createUi | ( | ) | [private] |
Definition at line 93 of file Composer.C.
{ setStyleClass("darker"); // horizontal layout container, used for top and bottom buttons. WContainerWidget *horiz; /* * Top buttons */ horiz = new WContainerWidget(layout_); horiz->setPadding(5); topSendButton_ = new WPushButton(tr("msg.send"), horiz); topSendButton_->setStyleClass("default"); // default action topSaveNowButton_ = new WPushButton(tr("msg.savenow"), horiz); topDiscardButton_ = new WPushButton(tr("msg.discard"), horiz); // Text widget which shows status messages, next to the top buttons. statusMsg_ = new WText(horiz); statusMsg_->setMargin(15, Left); /* * To, Cc, Bcc, Subject, Attachments * * They are organized in a two-column table: left column for * labels, and right column for the edit. */ edits_ = new WTable(layout_); edits_->setStyleClass("lighter"); edits_->resize(WLength(100, WLength::Percentage), WLength::Auto); edits_->elementAt(0, 0)->resize(WLength(1, WLength::Percentage), WLength::Auto); /* * To, Cc, Bcc */ toEdit_ = new AddresseeEdit(tr("msg.to"), edits_->elementAt(0, 1), edits_->elementAt(0, 0)); // add some space above To: edits_->elementAt(0, 1)->setMargin(5, Top); ccEdit_ = new AddresseeEdit(tr("msg.cc"), edits_->elementAt(1, 1), edits_->elementAt(1, 0)); bccEdit_ = new AddresseeEdit(tr("msg.bcc"), edits_->elementAt(2, 1), edits_->elementAt(2, 0)); ccEdit_->hide(); bccEdit_->hide(); /* * Addressbook suggestions popup */ contactSuggestions_ = new ContactSuggestions(layout_); contactSuggestions_->forEdit(toEdit_); contactSuggestions_->forEdit(ccEdit_); contactSuggestions_->forEdit(bccEdit_); /* * We use an OptionList widget to show the expand options for * ccEdit_ and bccEdit_ nicely next to each other, separated * by pipe characters. */ options_ = new OptionList(edits_->elementAt(3, 1)); options_->add(addcc_ = new Option(tr("msg.addcc"))); options_->add(addbcc_ = new Option(tr("msg.addbcc"))); /* * Subject */ new Label(tr("msg.subject"), edits_->elementAt(4, 0)); subject_ = new WLineEdit(edits_->elementAt(4, 1)); subject_->resize(WLength(99, WLength::Percentage), WLength::Auto); /* * Attachments */ new WImage("icons/paperclip.png", edits_->elementAt(5, 0)); edits_->elementAt(5, 0)->setContentAlignment(AlignRight | AlignTop); edits_->elementAt(5, 0)->setPadding(3); // Attachment edits: we always have the next attachmentedit ready // but hidden. This improves the response time, since the show() // and hide() slots are stateless. attachments_.push_back(new AttachmentEdit(this, edits_->elementAt(5, 1))); attachments_.back()->hide(); /* * Two options for attaching files. The first does not say 'another'. */ attachFile_ = new Option(tr("msg.attachfile"), edits_->elementAt(5, 1)); attachOtherFile_ = new Option(tr("msg.attachanother"), edits_->elementAt(5, 1)); attachOtherFile_->hide(); /* * Message */ message_ = new WTextArea(layout_); message_->setColumns(80); message_->setRows(10); // should be 20, but let's keep it smaller message_->setMargin(10); /* * Bottom buttons */ horiz = new WContainerWidget(layout_); horiz->setPadding(5); botSendButton_ = new WPushButton(tr("msg.send"), horiz); botSendButton_->setStyleClass("default"); botSaveNowButton_ = new WPushButton(tr("msg.savenow"), horiz); botDiscardButton_ = new WPushButton(tr("msg.discard"), horiz); /* * Button events. */ topSendButton_->clicked().connect(this, &Composer::sendIt); botSendButton_->clicked().connect(this, &Composer::sendIt); topSaveNowButton_->clicked().connect(this, &Composer::saveNow); botSaveNowButton_->clicked().connect(this, &Composer::saveNow); topDiscardButton_->clicked().connect(this, &Composer::discardIt); botDiscardButton_->clicked().connect(this, &Composer::discardIt); /* * Option events to show the cc or Bcc edit. * * Clicking on the option should both show the corresponding edit, and * hide the option itself. */ addcc_->item()->clicked().connect(ccEdit_, &WWidget::show); addcc_->item()->clicked().connect(addcc_, &WWidget::hide); addcc_->item()->clicked().connect(options_, &OptionList::update); addcc_->item()->clicked().connect(ccEdit_, &WFormWidget::setFocus); addbcc_->item()->clicked().connect(bccEdit_, &WWidget::show); addbcc_->item()->clicked().connect(addbcc_, &WWidget::hide); addbcc_->item()->clicked().connect(options_, &OptionList::update); addbcc_->item()->clicked().connect(bccEdit_, &WFormWidget::setFocus); /* * Option event to attach the first attachment. * * We show the first attachment, and call attachMore() to prepare the * next attachment edit that will be hidden. * * In addition, we need to show the 'attach More' option, and hide the * 'attach' option. */ attachFile_->item()->clicked().connect(attachments_.back(), &WWidget::show); attachFile_->item()->clicked().connect(attachOtherFile_, &WWidget::show); attachFile_->item()->clicked().connect(attachFile_, &WWidget::hide); attachFile_->item()->clicked().connect(this, &Composer::attachMore); attachOtherFile_->item()->clicked().connect(this, &Composer::attachMore); }
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.
const WString & Composer::message | ( | ) | const |
void Composer::removeAttachment | ( | AttachmentEdit * | attachment | ) | [private] |
Remove the given attachment edit.
Definition at line 264 of file Composer.C.
{ /* * Remove the given attachment from the attachments list. */ std::vector<AttachmentEdit *>::iterator i = std::find(attachments_.begin(), attachments_.end(), attachment); if (i != attachments_.end()) { attachments_.erase(i); delete attachment; if (attachments_.size() == 1) { /* * This was the last visible attachment, thus, we should switch * the option control again. */ attachOtherFile_->hide(); attachFile_->show(); attachFile_->item()->clicked() .connect(attachments_.back(), &WWidget::show); } } }
void Composer::saved | ( | ) | [private] |
All attachments have been processed, determine the result of saving the message.
Definition at line 348 of file Composer.C.
{ /* * All attachments have been processed. */ bool attachmentsFailed = false; for (unsigned i = 0; i < attachments_.size() - 1; ++i) if (attachments_[i]->uploadFailed()) { attachmentsFailed = true; break; } if (attachmentsFailed) { setStatus(tr("msg.attachment.failed"), "error"); } else { #ifndef WIN32 time_t t = time(0); struct tm td; gmtime_r(&t, &td); char buffer[100]; strftime(buffer, 100, "%H:%M", &td); #else char buffer[] = "server"; // Should fix this; for now just make sense #endif setStatus(tr("msg.ok"), "status"); statusMsg_->setText(std::string("Draft saved at ") + buffer); if (sending_) { send.emit(); return; } } saving_ = false; sending_ = false; }
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.
{ if (!saving_) { saving_ = true; /* * Check if any attachments still need to be uploaded. * This may be the case when fileupload change events could not * be caught (for example in Konqueror). */ attachmentsPending_ = 0; for (unsigned i = 0; i < attachments_.size() - 1; ++i) { if (attachments_[i]->uploadNow()) { ++attachmentsPending_; // this will trigger attachmentDone() when done, see // the AttachmentEdit constructor. } } std::cerr << "Attachments pending: " << attachmentsPending_ << std::endl; if (attachmentsPending_) setStatus(tr("msg.uploading"), "status"); else saved(); } }
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.
void Composer::setAddressBook | ( | const std::vector< Contact > & | addressBook | ) |
Set the address book, for autocomplete suggestions.
Definition at line 65 of file Composer.C.
{ contactSuggestions_->setAddressBook(contacts); }
void Composer::setMessage | ( | const WString & | message | ) |
Set the status, and apply the given style.
Definition at line 342 of file Composer.C.
{ statusMsg_->setText(text); statusMsg_->setStyleClass(style); }
void Composer::setSubject | ( | const WString & | subject | ) |
void Composer::setTo | ( | const std::vector< Contact > & | to | ) |
const WString & Composer::subject | ( | ) | const |
std::vector< Contact > Composer::to | ( | ) | const |
friend class AttachmentEdit [friend] |
Definition at line 194 of file Composer.h.
Option* Composer::addbcc_ [private] |
Option for editing Bcc:
Definition at line 127 of file Composer.h.
Option* Composer::addcc_ [private] |
Option for editing Cc:
Definition at line 125 of file Composer.h.
Option* Composer::attachFile_ [private] |
Option for attaching a file.
Definition at line 129 of file Composer.h.
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.
int Composer::attachmentsPending_ [private] |
number of attachments waiting to be uploaded during saving
Definition at line 143 of file Composer.h.
Option* Composer::attachOtherFile_ [private] |
Option for attaching another file.
Definition at line 131 of file Composer.h.
AddresseeEdit* Composer::bccEdit_ [private] |
Bcc: Addressees edit.
Definition at line 113 of file Composer.h.
WPushButton * Composer::botDiscardButton_ [private] |
Definition at line 103 of file Composer.h.
WPushButton * Composer::botSaveNowButton_ [private] |
Definition at line 103 of file Composer.h.
WPushButton* Composer::botSendButton_ [private] |
Definition at line 103 of file Composer.h.
AddresseeEdit* Composer::ccEdit_ [private] |
Cc: Addressees edit.
Definition at line 111 of file Composer.h.
ContactSuggestions* Composer::contactSuggestions_ [private] |
The suggestions popup for the addressee edits.
Definition at line 116 of file Composer.h.
Wt::Signal<void> Composer::discard |
The message must be discarded.
Definition at line 97 of file Composer.h.
WTable* Composer::edits_ [private] |
Definition at line 106 of file Composer.h.
WContainerWidget* Composer::layout_ [private] |
Definition at line 100 of file Composer.h.
WTextArea* Composer::message_ [private] |
WTextArea for the main message.
Definition at line 137 of file Composer.h.
OptionList* Composer::options_ [private] |
OptionsList for editing Cc or Bcc.
Definition at line 122 of file Composer.h.
bool Composer::saving_ [private] |
state when waiting asyncrhonously for attachments to be uploaded
Definition at line 140 of file Composer.h.
Wt::Signal<void> Composer::send |
The message is ready to be sent...
Definition at line 93 of file Composer.h.
bool Composer::sending_ [private] |
Definition at line 140 of file Composer.h.
WText* Composer::statusMsg_ [private] |
Definition at line 104 of file Composer.h.
WLineEdit* Composer::subject_ [private] |
The subject line edit.
Definition at line 119 of file Composer.h.
AddresseeEdit* Composer::toEdit_ [private] |
To: Addressees edit.
Definition at line 109 of file Composer.h.
WPushButton * Composer::topDiscardButton_ [private] |
Definition at line 102 of file Composer.h.
WPushButton * Composer::topSaveNowButton_ [private] |
Definition at line 102 of file Composer.h.
WPushButton* Composer::topSendButton_ [private] |
Definition at line 102 of file Composer.h.