| Wt examples
    3.3.0
    | 
An edit field for an email attachment. More...
#include <AttachmentEdit.h>

| Classes | |
| class | UploadInfo | 
| Public Member Functions | |
| AttachmentEdit (Composer *composer, WContainerWidget *parent=0) | |
| Creates an attachment edit field. | |
| bool | uploadNow () | 
| Updates the file now. | |
| bool | uploadFailed () const | 
| Returns whether the upload failed. | |
| std::vector< Attachment > | attachments () | 
| Returns the attachment. | |
| Signal< void > & | uploadDone () | 
| Signal emitted when new attachment(s) have been uploaded (or failed to upload. | |
| Private Member Functions | |
| void | uploaded () | 
| Slot triggered when the WFileUpload completed an upload. | |
| void | fileTooLarge (::int64_t 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. | |
| std::vector< UploadInfo * > | uploadInfo_ | 
| WText * | error_ | 
| The text box to display an error (empty or too big file) | |
| Option * | remove_ | 
| The option to cancel the file upload. | |
| bool | uploadFailed_ | 
| The state of the last upload process. | |
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 | ||
| ) | 
Creates an attachment edit field.
Definition at line 71 of file AttachmentEdit.C.
: WContainerWidget(parent), composer_(composer), uploadDone_(this), uploadFailed_(false) { /* * The file upload itself. */ upload_ = new WFileUpload(this); upload_->setMultiple(true); upload_->setFileTextSize(40); /* * A progress bar */ WProgressBar *progress = new WProgressBar(); progress->setFormat(WString::Empty); progress->setVerticalAlignment(AlignMiddle); upload_->setProgressBar(progress); /* * The 'remove' option. */ remove_ = new Option(tr("msg.remove"), this); upload_->decorationStyle().font().setSize(WFont::Smaller); upload_->setVerticalAlignment(AlignMiddle); remove_->setMargin(5, Left); remove_->item()->clicked().connect(this, &WWidget::hide); remove_->item()->clicked().connect(this, &AttachmentEdit::remove); // 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(upload_, &WFileUpload::upload); // React to a succesfull upload. upload_->uploaded().connect(this, &AttachmentEdit::uploaded); // React to a fileupload problem. upload_->fileTooLarge().connect(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(composer, &Composer::attachmentDone); }
| std::vector< Attachment > AttachmentEdit::attachments | ( | ) | 
Returns the attachment.
Definition at line 191 of file AttachmentEdit.C.
{
  std::vector<Attachment> result;
  for (unsigned i = 0; i < uploadInfo_.size(); ++i) {
    if (uploadInfo_[i]->keep_->isChecked()) {
      Http::UploadedFile& f = uploadInfo_[i]->info_;
      f.stealSpoolFile();
      result.push_back(Attachment
                       (WString::fromUTF8(f.clientFileName()),
                        WString::fromUTF8(f.contentType()),
                        f.spoolFileName()));
    }
  }
  return result;
}
| void AttachmentEdit::fileTooLarge | ( | ::int64_t | size | ) |  [private] | 
Slot triggered when the WFileUpload received an oversized file.
Definition at line 178 of file AttachmentEdit.C.
{
  error_->setText(tr("msg.file-too-large")
                  .arg(size / 1024)
                  .arg(WApplication::instance()->maximumRequestSize() / 1024));
  uploadFailed_ = true;
  /*
   * Signal to the Composer that a new asyncrhonous file upload was processed.
   */
  uploadDone_.emit();
}
| void AttachmentEdit::remove | ( | ) |  [private] | 
Slot triggered when the users wishes to remove this attachment edit.
Definition at line 173 of file AttachmentEdit.C.
{
  composer_->removeAttachment(this);
}
| Signal<void>& AttachmentEdit::uploadDone | ( | ) |  [inline] | 
Signal emitted when new attachment(s) have been uploaded (or failed to upload.
Definition at line 63 of file AttachmentEdit.h.
{ return uploadDone_; }
| void AttachmentEdit::uploaded | ( | ) |  [private] | 
Slot triggered when the WFileUpload completed an upload.
Definition at line 145 of file AttachmentEdit.C.
{
  std::vector<Http::UploadedFile> files = upload_->uploadedFiles();
  if (!files.empty()) {
    /*
     * Delete this widgets since we have a succesfull upload.
     */
    delete upload_;
    upload_ = 0;
    delete remove_;
    remove_ = 0;
    delete error_;
    error_ = 0;
    for (unsigned i = 0; i < files.size(); ++i)
      uploadInfo_.push_back(new UploadInfo(files[i], this));
  } else {
    error_->setText(tr("msg.file-empty"));
    uploadFailed_ = true;
  }
  /*
   * Signal to the Composer that a new asynchronous file upload was processed.
   */
  uploadDone_.emit();
}
| bool AttachmentEdit::uploadFailed | ( | ) | const  [inline] | 
Returns whether the upload failed.
Definition at line 54 of file AttachmentEdit.h.
{ return uploadFailed_; }
| bool AttachmentEdit::uploadNow | ( | ) | 
Updates 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 129 of file AttachmentEdit.C.
| Composer* AttachmentEdit::composer_  [private] | 
Definition at line 66 of file AttachmentEdit.h.
| WText* AttachmentEdit::error_  [private] | 
The text box to display an error (empty or too big file)
Definition at line 90 of file AttachmentEdit.h.
| Option* AttachmentEdit::remove_  [private] | 
The option to cancel the file upload.
Definition at line 93 of file AttachmentEdit.h.
| WFileUpload* AttachmentEdit::upload_  [private] | 
The WFileUpload control.
Definition at line 71 of file AttachmentEdit.h.
| Signal<void> AttachmentEdit::uploadDone_  [private] | 
Definition at line 68 of file AttachmentEdit.h.
| bool AttachmentEdit::uploadFailed_  [private] | 
The state of the last upload process.
Definition at line 96 of file AttachmentEdit.h.
| std::vector<UploadInfo *> AttachmentEdit::uploadInfo_  [private] | 
Definition at line 87 of file AttachmentEdit.h.
 1.7.5.1
 1.7.5.1