An edit field for an email attachment. More...
#include <AttachmentEdit.h>
Public Member Functions | |
AttachmentEdit (Composer *composer, WContainerWidget *parent=0) | |
Create an attachment edit field. | |
~AttachmentEdit () | |
bool | uploadNow () |
Update the file now. | |
bool | uploadFailed () const |
Return whether the upload failed. | |
bool | include () const |
Return whether this attachment must be included in the message. | |
Attachment | attachment () |
Return the attachment. | |
Signal< void > & | uploadDone () |
Signal emitted when a new attachment has been uploaded (or failed to upload. | |
Private Slots | |
void | uploaded () |
Slot triggered when the WFileUpload completed an upload. | |
void | fileTooLarge (int size) |
Slot triggered when the WFileUpload received an oversized file. | |
void | remove () |
Slot triggered when the users wishes to remove this attachment edit. | |
Private Attributes | |
Composer * | composer_ |
Signal< void > | uploadDone_ |
WFileUpload * | upload_ |
The WFileUpload control. | |
WText * | uploaded_ |
The text describing the uploaded file. | |
WCheckBox * | keep_ |
The check box to keep or discard the uploaded file. | |
Option * | remove_ |
The option to remove the file. | |
WText * | error_ |
The text box to display an error (empty or too big file) | |
bool | uploadFailed_ |
The state of the last upload process. | |
std::wstring | fileName_ |
The filename of the uploaded file. | |
std::string | spoolFileName_ |
The filename of the local spool file. | |
std::wstring | contentDescription_ |
The content description that was sent along with the file. | |
bool | taken_ |
Whether the spool file is "taken" and is no longer managed by the edit. |
An edit field for an email attachment.
This widget managements one attachment edit: it shows a file upload control, handles the upload, and gives feed-back on the file uploaded.
This widget is part of the Wt composer example.
Definition at line 37 of file AttachmentEdit.h.
AttachmentEdit::AttachmentEdit | ( | Composer * | composer, |
WContainerWidget * | parent = 0 |
||
) |
Create an attachment edit field.
Definition at line 26 of file AttachmentEdit.C.
: WContainerWidget(parent), composer_(composer), uploadDone_(this), uploadFailed_(false), taken_(false) { /* * The file upload itself. */ upload_ = new WFileUpload(this); upload_->setFileTextSize(40); /* * The 'remove' option. */ remove_ = new Option(tr("msg.remove"), this); upload_->decorationStyle().font().setSize(WFont::Smaller); remove_->setMargin(5, Left); remove_->item()->clicked().connect(SLOT(this, WWidget::hide)); remove_->item()->clicked().connect(SLOT(this, AttachmentEdit::remove)); /* * Fields that will display the feedback. */ // The check box to include or exclude the attachment. keep_ = new WCheckBox(this); keep_->hide(); // The uploaded file information. uploaded_ = new WText("", this); uploaded_->setStyleClass("option"); uploaded_->hide(); // The error message. error_ = new WText("", this); error_->setStyleClass("error"); error_->setMargin(WLength(5), Left); /* * React to events. */ // Try to catch the fileupload change signal to trigger an upload. // We could do like google and at a delay with a WTimer as well... upload_->changed().connect(SLOT(upload_, WFileUpload::upload)); // React to a succesfull upload. upload_->uploaded().connect(SLOT(this, AttachmentEdit::uploaded)); // React to a fileupload problem. upload_->fileTooLarge().connect(SLOT(this, AttachmentEdit::fileTooLarge)); /* * Connect the uploadDone signal to the Composer's attachmentDone, * so that the Composer can keep track of attachment upload progress, * if it wishes. */ uploadDone_.connect(SLOT(composer, Composer::attachmentDone)); }
AttachmentEdit::~AttachmentEdit | ( | ) |
Definition at line 88 of file AttachmentEdit.C.
{ // delete the local attachment file copy, if it was not taken from us. if (!taken_) unlink(spoolFileName_.c_str()); }
Attachment AttachmentEdit::attachment | ( | ) |
Return the attachment.
Definition at line 184 of file AttachmentEdit.C.
{ taken_ = true; return Attachment(fileName_, contentDescription_, spoolFileName_); }
void AttachmentEdit::fileTooLarge | ( | int | size ) | [private, slot] |
Slot triggered when the WFileUpload received an oversized file.
Definition at line 168 of file AttachmentEdit.C.
{ error_->setText(tr("msg.file-too-large")); uploadFailed_ = true; /* * Signal to the Composer that a new asyncrhonous file upload was processed. */ uploadDone_.emit(); }
bool AttachmentEdit::include | ( | ) | const |
Return whether this attachment must be included in the message.
Definition at line 179 of file AttachmentEdit.C.
void AttachmentEdit::remove | ( | ) | [private, slot] |
Slot triggered when the users wishes to remove this attachment edit.
Definition at line 163 of file AttachmentEdit.C.
{ composer_->removeAttachment(this); }
Signal<void>& AttachmentEdit::uploadDone | ( | ) | [inline] |
Signal emitted when a new attachment has been uploaded (or failed to upload.
Definition at line 68 of file AttachmentEdit.h.
{ return uploadDone_; }
void AttachmentEdit::uploaded | ( | ) | [private, slot] |
Slot triggered when the WFileUpload completed an upload.
Definition at line 111 of file AttachmentEdit.C.
{ if (!upload_->emptyFileName()) { fileName_ = upload_->clientFileName(); spoolFileName_ = upload_->spoolFileName(); upload_->stealSpooledFile(); contentDescription_ = upload_->contentDescription(); /* * Delete this widgets since we have a succesfull upload. */ delete upload_; upload_ = 0; delete remove_; remove_ = 0; error_->setText(""); /* * Include the file ? */ keep_->show(); keep_->setChecked(); /* * Give information on the file uploaded. */ struct stat buf; stat(spoolFileName_.c_str(), &buf); std::wstring size; if (buf.st_size < 1024) size = boost::lexical_cast<std::wstring>(buf.st_size) + L" bytes"; else size = boost::lexical_cast<std::wstring>((int)(buf.st_size / 1024)) + L"kb"; uploaded_->setText(static_cast<std::wstring>(escapeText(fileName_)) + L" (<i>" + contentDescription_ + L"</i>) " + size); uploaded_->show(); uploadFailed_ = false; } else { error_->setText(tr("msg.file-empty")); uploadFailed_ = true; } /* * Signal to the Composer that a new asyncrhonous file upload was processed. */ uploadDone_.emit(); }
bool AttachmentEdit::uploadFailed | ( | ) | const [inline] |
Return whether the upload failed.
Definition at line 55 of file AttachmentEdit.h.
{ return uploadFailed_; }
bool AttachmentEdit::uploadNow | ( | ) |
Update the file now.
Returns whether a new file will be uploaded. If so, the uploadDone signal will be signalled when the file is uploaded (or failed to upload).
Definition at line 95 of file AttachmentEdit.C.
Composer* AttachmentEdit::composer_ [private] |
Definition at line 71 of file AttachmentEdit.h.
std::wstring AttachmentEdit::contentDescription_ [private] |
The content description that was sent along with the file.
Definition at line 100 of file AttachmentEdit.h.
WText* AttachmentEdit::error_ [private] |
The text box to display an error (empty or too big file)
Definition at line 88 of file AttachmentEdit.h.
std::wstring AttachmentEdit::fileName_ [private] |
The filename of the uploaded file.
Definition at line 94 of file AttachmentEdit.h.
WCheckBox* AttachmentEdit::keep_ [private] |
The check box to keep or discard the uploaded file.
Definition at line 82 of file AttachmentEdit.h.
Option* AttachmentEdit::remove_ [private] |
The option to remove the file.
Definition at line 85 of file AttachmentEdit.h.
std::string AttachmentEdit::spoolFileName_ [private] |
The filename of the local spool file.
Definition at line 97 of file AttachmentEdit.h.
bool AttachmentEdit::taken_ [private] |
Whether the spool file is "taken" and is no longer managed by the edit.
Definition at line 103 of file AttachmentEdit.h.
WFileUpload* AttachmentEdit::upload_ [private] |
The WFileUpload control.
Definition at line 76 of file AttachmentEdit.h.
Signal<void> AttachmentEdit::uploadDone_ [private] |
Definition at line 73 of file AttachmentEdit.h.
WText* AttachmentEdit::uploaded_ [private] |
The text describing the uploaded file.
Definition at line 79 of file AttachmentEdit.h.
bool AttachmentEdit::uploadFailed_ [private] |
The state of the last upload process.
Definition at line 91 of file AttachmentEdit.h.