#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 Member Functions | |
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. |
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.
00027 : WContainerWidget(parent), 00028 composer_(composer), 00029 uploadDone_(this), 00030 uploadFailed_(false), 00031 taken_(false) 00032 { 00033 /* 00034 * The file upload itself. 00035 */ 00036 upload_ = new WFileUpload(this); 00037 upload_->setFileTextSize(40); 00038 00039 /* 00040 * The 'remove' option. 00041 */ 00042 remove_ = new Option(tr("msg.remove"), this); 00043 upload_->decorationStyle().font().setSize(WFont::Smaller); 00044 remove_->setMargin(5, Left); 00045 remove_->item()->clicked().connect(SLOT(this, WWidget::hide)); 00046 remove_->item()->clicked().connect(SLOT(this, AttachmentEdit::remove)); 00047 00048 /* 00049 * Fields that will display the feedback. 00050 */ 00051 00052 // The check box to include or exclude the attachment. 00053 keep_ = new WCheckBox(this); 00054 keep_->hide(); 00055 00056 // The uploaded file information. 00057 uploaded_ = new WText("", this); 00058 uploaded_->setStyleClass("option"); 00059 uploaded_->hide(); 00060 00061 // The error message. 00062 error_ = new WText("", this); 00063 error_->setStyleClass("error"); 00064 error_->setMargin(WLength(5), Left); 00065 00066 /* 00067 * React to events. 00068 */ 00069 00070 // Try to catch the fileupload change signal to trigger an upload. 00071 // We could do like google and at a delay with a WTimer as well... 00072 upload_->changed().connect(SLOT(upload_, WFileUpload::upload)); 00073 00074 // React to a succesfull upload. 00075 upload_->uploaded().connect(SLOT(this, AttachmentEdit::uploaded)); 00076 00077 // React to a fileupload problem. 00078 upload_->fileTooLarge().connect(SLOT(this, AttachmentEdit::fileTooLarge)); 00079 00080 /* 00081 * Connect the uploadDone signal to the Composer's attachmentDone, 00082 * so that the Composer can keep track of attachment upload progress, 00083 * if it wishes. 00084 */ 00085 uploadDone_.connect(SLOT(composer, Composer::attachmentDone)); 00086 }
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 }
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 }
bool AttachmentEdit::uploadFailed | ( | ) | const [inline] |
Return whether the upload failed.
Definition at line 55 of file AttachmentEdit.h.
00055 { return uploadFailed_; }
bool AttachmentEdit::include | ( | ) | const |
Return whether this attachment must be included in the message.
Definition at line 179 of file AttachmentEdit.C.
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 }
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 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 }
void AttachmentEdit::fileTooLarge | ( | int | size | ) | [private] |
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 }
void AttachmentEdit::remove | ( | ) | [private] |
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 }
Composer* AttachmentEdit::composer_ [private] |
Definition at line 71 of file AttachmentEdit.h.
Signal<void> AttachmentEdit::uploadDone_ [private] |
Definition at line 73 of file AttachmentEdit.h.
WFileUpload* AttachmentEdit::upload_ [private] |
WText* AttachmentEdit::uploaded_ [private] |
WCheckBox* AttachmentEdit::keep_ [private] |
Option* AttachmentEdit::remove_ [private] |
WText* AttachmentEdit::error_ [private] |
The text box to display an error (empty or too big file).
Definition at line 88 of file AttachmentEdit.h.
bool AttachmentEdit::uploadFailed_ [private] |
std::wstring AttachmentEdit::fileName_ [private] |
std::string AttachmentEdit::spoolFileName_ [private] |
std::wstring AttachmentEdit::contentDescription_ [private] |
The content description that was sent along with the file.
Definition at line 100 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.