An edit field for an email attachment. More...
#include <AttachmentEdit.h>
Inherits Wt::WContainerWidget.
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.
AttachmentEdit::~AttachmentEdit | ( | ) |
Definition at line 88 of file AttachmentEdit.C.
00089 { 00090 // delete the local attachment file copy, if it was not taken from us. 00091 if (!taken_) 00092 unlink(spoolFileName_.c_str()); 00093 }
Attachment AttachmentEdit::attachment | ( | ) |
Return the attachment.
Definition at line 184 of file AttachmentEdit.C.
00185 { 00186 taken_ = true; 00187 return Attachment(fileName_, contentDescription_, spoolFileName_); 00188 }
void AttachmentEdit::fileTooLarge | ( | int | size | ) | [private, slot] |
Slot triggered when the WFileUpload received an oversized file.
Definition at line 168 of file AttachmentEdit.C.
00169 { 00170 error_->setText(tr("msg.file-too-large")); 00171 uploadFailed_ = true; 00172 00173 /* 00174 * Signal to the Composer that a new asyncrhonous file upload was processed. 00175 */ 00176 uploadDone_.emit(); 00177 }
bool AttachmentEdit::include | ( | ) | const |
Return whether this attachment must be included in the message.
Definition at line 179 of file AttachmentEdit.C.
00180 { 00181 return keep_->isChecked(); 00182 }
void AttachmentEdit::remove | ( | ) | [private, slot] |
Slot triggered when the users wishes to remove this attachment edit.
Definition at line 163 of file AttachmentEdit.C.
00164 { 00165 composer_->removeAttachment(this); 00166 }
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.
00068 { return uploadDone_; }
void AttachmentEdit::uploaded | ( | ) | [private, slot] |
Slot triggered when the WFileUpload completed an upload.
Definition at line 111 of file AttachmentEdit.C.
00112 { 00113 if (!upload_->emptyFileName()) { 00114 fileName_ = upload_->clientFileName(); 00115 spoolFileName_ = upload_->spoolFileName(); 00116 upload_->stealSpooledFile(); 00117 contentDescription_ = upload_->contentDescription(); 00118 00119 /* 00120 * Delete this widgets since we have a succesfull upload. 00121 */ 00122 delete upload_; 00123 upload_ = 0; 00124 delete remove_; 00125 remove_ = 0; 00126 00127 error_->setText(""); 00128 00129 /* 00130 * Include the file ? 00131 */ 00132 keep_->show(); 00133 keep_->setChecked(); 00134 00135 /* 00136 * Give information on the file uploaded. 00137 */ 00138 struct stat buf; 00139 stat(spoolFileName_.c_str(), &buf); 00140 std::wstring size; 00141 if (buf.st_size < 1024) 00142 size = boost::lexical_cast<std::wstring>(buf.st_size) + L" bytes"; 00143 else 00144 size = boost::lexical_cast<std::wstring>((int)(buf.st_size / 1024)) 00145 + L"kb"; 00146 00147 uploaded_->setText(static_cast<std::wstring>(escapeText(fileName_)) 00148 + L" (<i>" + contentDescription_ + L"</i>) " + size); 00149 uploaded_->show(); 00150 00151 uploadFailed_ = false; 00152 } else { 00153 error_->setText(tr("msg.file-empty")); 00154 uploadFailed_ = true; 00155 } 00156 00157 /* 00158 * Signal to the Composer that a new asyncrhonous file upload was processed. 00159 */ 00160 uploadDone_.emit(); 00161 }
bool AttachmentEdit::uploadFailed | ( | ) | const [inline] |
Return whether the upload failed.
Definition at line 55 of file AttachmentEdit.h.
00055 { 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.
00096 { 00097 /* 00098 * See if this attachment still needs to be uploaded, 00099 * and return if a new asynchronous upload is started. 00100 */ 00101 if (upload_) { 00102 if (upload_->canUpload()) { 00103 upload_->upload(); 00104 return true; 00105 } else 00106 return false; 00107 } else 00108 return false; 00109 }
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.