Wt examples  3.2.1
Public Member Functions | Public Attributes | Private Member Functions | Private Attributes | Friends | List of all members
Composer Class Reference

An E-mail composer widget. More...

#include <Composer.h>

Inheritance diagram for Composer:
Inheritance graph
[legend]

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< Contactto () const
 Get the To: contacts.
std::vector< Contactcc () const
 Get the Cc: contacts.
std::vector< Contactbcc () const
 Get the Bc: contacts.
const WStringsubject () const
 Get the subject.
std::vector< Attachmentattachments () const
 Get the list of attachments.
const WStringmessage () const
 Get the message.
- Public Member Functions inherited from Wt::WCompositeWidget
 WCompositeWidget (WContainerWidget *parent=0)
 WCompositeWidget (WWidget *implementation, WContainerWidget *parent)
virtual const std::string id () const
virtual void setPositionScheme (PositionScheme scheme)
virtual PositionScheme positionScheme () const
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
virtual WLength offset (Side s) const
virtual void resize (const WLength &width, const WLength &height)
virtual WLength width () const
virtual WLength height () const
virtual void setMinimumSize (const WLength &width, const WLength &height)
virtual WLength minimumWidth () const
virtual WLength minimumHeight () const
virtual void setMaximumSize (const WLength &width, const WLength &height)
virtual WLength maximumWidth () const
virtual WLength maximumHeight () const
virtual void setLineHeight (const WLength &height)
virtual WLength lineHeight () const
virtual void setFloatSide (Side s)
virtual Side floatSide () const
virtual void setClearSides (WFlags< Side > sides)
virtual WFlags< SideclearSides () const
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
virtual WLength margin (Side side) const
virtual void setHiddenKeepsGeometry (bool enabled)
virtual bool hiddenKeepsGeometry () const
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
virtual bool isHidden () const
virtual bool isVisible () const
virtual void setDisabled (bool disabled)
virtual bool isDisabled () const
virtual bool isEnabled () const
virtual void setPopup (bool popup)
virtual bool isPopup () const
virtual void setInline (bool isInline)
virtual bool isInline () const
virtual void setDecorationStyle (const WCssDecorationStyle &style)
virtual WCssDecorationStyledecorationStyle ()
virtual void setStyleClass (const WString &styleClass)
virtual WString styleClass () const
virtual void addStyleClass (const WString &styleClass, bool force=false)
virtual void removeStyleClass (const WString &styleClass, bool force=false)
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength::Auto)
virtual AlignmentFlag verticalAlignment () const
virtual WLength verticalAlignmentLength () const
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
virtual WString toolTip () const
virtual void refresh ()
virtual void setAttributeValue (const std::string &name, const WString &value)
virtual WString attributeValue (const std::string &name) const
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
virtual std::string javaScriptMember (const std::string &name) const
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
virtual void load ()
virtual bool loaded () const
virtual void setTabIndex (int index)
virtual int tabIndex () const
virtual void setId (const std::string &id)
virtual WWidgetfind (const std::string &name)
virtual void setSelectable (bool selectable)
virtual void doJavaScript (const std::string &js)
virtual void propagateSetEnabled (bool enabled)
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
WWidgetparent () const
void setWidth (const WLength &width)
void setHeight (const WLength &height)
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
std::string jsRef () const
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
virtual void stopAcceptDrops (const std::string &mimeType)
virtual void htmlText (std::ostream &out)
bool isRendered () const
void hide ()
void animateHide (const WAnimation &animation)
void show ()
void animateShow (const WAnimation &animation)
void enable ()
void disable ()
bool layoutSizeAware () const
- Public Member Functions inherited from Wt::WObject
 WObject (WObject *parent=0)
virtual ~WObject ()
void setObjectName (const std::string &name)
virtual std::string objectName () const
void resetLearnedSlots ()
void resetLearnedSlot (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)())
WStatelessSlot * implementStateless (void(T::*method)(), void(T::*undoMethod)())
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
void addChild (WObject *child)
virtual void removeChild (WObject *child)
const std::vector< WObject * > & children () const

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

WContainerWidgetlayout_
WPushButtontopSendButton_
WPushButtontopSaveNowButton_
WPushButtontopDiscardButton_
WPushButtonbotSendButton_
WPushButtonbotSaveNowButton_
WPushButtonbotDiscardButton_
WTextstatusMsg_
WTableedits_
AddresseeEdittoEdit_
 To: Addressees edit.
AddresseeEditccEdit_
 Cc: Addressees edit.
AddresseeEditbccEdit_
 Bcc: Addressees edit.
ContactSuggestionscontactSuggestions_
 The suggestions popup for the addressee edits.
WLineEditsubject_
 The subject line edit.
OptionListoptions_
 OptionsList for editing Cc or Bcc.
Optionaddcc_
 Option for editing Cc:
Optionaddbcc_
 Option for editing Bcc:
OptionattachFile_
 Option for attaching a file.
OptionattachOtherFile_
 Option for attaching another file.
std::vector< AttachmentEdit * > attachments_
 Array which holds all the attachments, including one extra invisible one.
WTextAreamessage_
 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

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method )()
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
- Protected Member Functions inherited from Wt::WCompositeWidget
virtual void enableAjax ()
void setImplementation (WWidget *widget)
WWidgetimplementation ()
virtual int boxPadding (Orientation orientation) const
virtual int boxBorder (Orientation orientation) const
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()

Detailed Description

An E-mail composer widget.

This widget is part of the Wt composer example.

Definition at line 40 of file Composer.h.

Constructor & Destructor Documentation

Composer::Composer ( WContainerWidget parent = 0)

Construct a new Composer.

Definition at line 25 of file Composer.C.

Member Function Documentation

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_) {
std::cerr << "Attachments still: " << attachmentsPending_ << std::endl;
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);
attachments_.push_back(edit);
attachments_.back()->hide();
// Connect the attachOtherFile_ option to show this attachment.
.connect(attachments_.back(), &WWidget::show);
}
std::vector< Contact > Composer::bcc ( ) const

Get the Bc: contacts.

Definition at line 60 of file Composer.C.

{
return bccEdit_->addressees();
}
std::vector< Contact > Composer::cc ( ) const

Get the Cc: contacts.

Definition at line 55 of file Composer.C.

{
return ccEdit_->addressees();
}
void Composer::createUi ( )
private

Definition at line 93 of file Composer.C.

{
setStyleClass("darker");
// horizontal layout container, used for top and bottom buttons.
/*
* 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_->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));
bccEdit_->hide();
/*
* Addressbook suggestions popup
*/
/*
* We use an OptionList widget to show the expand options for
* ccEdit_ and bccEdit_ nicely next to each other, separated
* by pipe characters.
*/
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_->resize(WLength(99, WLength::Percentage), WLength::Auto);
/*
* Attachments
*/
new WImage("icons/paperclip.png", edits_->elementAt(5, 0));
edits_->elementAt(5, 0)->setContentAlignment(AlignRight | AlignTop);
// 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_->setRows(10); // should be 20, but let's keep it smaller
/*
* Bottom buttons
*/
horiz = new WContainerWidget(layout_);
horiz->setPadding(5);
botSendButton_ = new WPushButton(tr("msg.send"), horiz);
botSaveNowButton_ = new WPushButton(tr("msg.savenow"), horiz);
botDiscardButton_ = new WPushButton(tr("msg.discard"), horiz);
/*
* Button events.
*/
/*
* 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(ccEdit_, &WFormWidget::setFocus);
addbcc_->item()->clicked().connect(bccEdit_, &WWidget::show);
addbcc_->item()->clicked().connect(addbcc_, &WWidget::hide);
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(attachOtherFile_, &WWidget::show);
attachFile_->item()->clicked().connect(attachFile_, &WWidget::hide);
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

Get the message.

Definition at line 88 of file Composer.C.

{
return message_->text();
}
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.
*/
.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_) {
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).
*/
for (unsigned i = 0; i < attachments_.size() - 1; ++i) {
if (attachments_[i]->uploadNow()) {
// this will trigger attachmentDone() when done, see
// the AttachmentEdit constructor.
}
}
std::cerr << "Attachments pending: " << attachmentsPending_ << std::endl;
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.

{
if (!sending_) {
sending_ = true;
/*
* First save -- this will check for the sending_ state
* signal if successfull.
*/
}
}
void Composer::setAddressBook ( const std::vector< Contact > &  addressBook)

Set the address book, for autocomplete suggestions.

Definition at line 65 of file Composer.C.

void Composer::setMessage ( const WString message)

Set the message.

Definition at line 45 of file Composer.C.

{
message_->setText(message);
}
void Composer::setStatus ( const WString text,
const WString style 
)
private

Set the status, and apply the given style.

Definition at line 342 of file Composer.C.

void Composer::setSubject ( const WString subject)

Set subject.

Definition at line 40 of file Composer.C.

{
subject_->setText(subject);
}
void Composer::setTo ( const std::vector< Contact > &  to)

Set message To: contacts.

Definition at line 35 of file Composer.C.

const WString & Composer::subject ( ) const

Get the subject.

Definition at line 70 of file Composer.C.

{
return subject_->text();
}
std::vector< Contact > Composer::to ( ) const

Get the To: contacts.

Definition at line 50 of file Composer.C.

{
return toEdit_->addressees();
}

Friends And Related Function Documentation

friend class AttachmentEdit
friend

Definition at line 194 of file Composer.h.

Member Data Documentation

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.


The documentation for this class was generated from the following files:

Generated on Wed Oct 22 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2