Wt examples  4.10.4
Classes | Public Member Functions | Private Member Functions | Private Attributes | List of all members
AttachmentEdit Class Reference

An edit field for an email attachment. More...

#include <AttachmentEdit.h>

Inheritance diagram for AttachmentEdit:
[legend]

Classes

class  UploadInfo
 

Public Member Functions

 AttachmentEdit (Composer *composer)
 Creates an attachment edit field. More...
 
bool uploadNow ()
 Updates the file now. More...
 
bool uploadFailed () const
 Returns whether the upload failed. More...
 
std::vector< Attachmentattachments ()
 Returns the attachment. More...
 
SignaluploadDone ()
 Signal emitted when new attachment(s) have been uploaded (or failed to upload. More...
 
- Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget ()
 
 ~WContainerWidget ()
 
void setLayout (std::unique_ptr< WLayout > layout)
 
Layout * setLayout (std::unique_ptr< Layout > layout)
 
WLayoutlayout () const
 
virtual void addWidget (std::unique_ptr< WWidget > widget)
 
Widget * addWidget (std::unique_ptr< Widget > widget)
 
Widget * addNew (Args &&...args)
 
virtual void insertBefore (std::unique_ptr< WWidget > widget, WWidget *before)
 
Widget * insertBefore (std::unique_ptr< Widget > widget, WWidget *before)
 
virtual void insertWidget (int index, std::unique_ptr< WWidget > widget)
 
Widget * insertWidget (int index, std::unique_ptr< Widget > widget)
 
Widget * insertNew (int index, Args &&...args)
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget) override
 
virtual void clear ()
 
virtual int indexOf (WWidget *widget) const
 
virtual WWidgetwidget (int index) const
 
virtual int count () const
 
void setContentAlignment (WFlags< AlignmentFlag > contentAlignment)
 
void setPadding (const WLength &padding, WFlags< Side > sides=AllSides)
 
WLength padding (Side side) const
 
WFlags< AlignmentFlagcontentAlignment () const
 
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Orientation::Horizontal|Orientation::Vertical))
 
void setList (bool list, bool ordered=false)
 
bool isList () const
 
bool isUnorderedList () const
 
bool isOrderedList () const
 
EventSignal< WScrollEvent > & scrolled ()
 
int scrollTop () const
 
int scrollLeft () const
 
virtual std::unique_ptr< WWidgetremoveWidget (WWidget *widget)
 
std::unique_ptr< Widget > removeWidget (Widget *widget)
 
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget ()
 
EventSignal< WKeyEvent > & keyWentDown ()
 
EventSignal< WKeyEvent > & keyPressed ()
 
EventSignal< WKeyEvent > & keyWentUp ()
 
EventSignalenterPressed ()
 
EventSignalescapePressed ()
 
EventSignal< WMouseEvent > & clicked ()
 
EventSignal< WMouseEvent > & doubleClicked ()
 
EventSignal< WMouseEvent > & mouseWentDown ()
 
EventSignal< WMouseEvent > & mouseWentUp ()
 
EventSignal< WMouseEvent > & mouseWentOut ()
 
EventSignal< WMouseEvent > & mouseWentOver ()
 
EventSignal< WMouseEvent > & mouseMoved ()
 
EventSignal< WMouseEvent > & mouseDragged ()
 
EventSignal< WMouseEvent > & mouseWheel ()
 
EventSignal< WTouchEvent > & touchStarted ()
 
EventSignal< WTouchEvent > & touchEnded ()
 
EventSignal< WTouchEvent > & touchMoved ()
 
EventSignal< WGestureEvent > & gestureStarted ()
 
EventSignal< WGestureEvent > & gestureChanged ()
 
EventSignal< WGestureEvent > & gestureEnded ()
 
void setDraggable (const std::string &mimeType, WWidget *dragWidget=nullptr, bool isDragWidgetOnly=false, WObject *sourceWidget=nullptr)
 
void unsetDraggable ()
 
void setMouseOverDelay (int delay)
 
int mouseOverDelay () const
 
virtual void setPopup (bool popup) override
 
virtual void load () override
 
virtual bool isEnabled () const override
 
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget ()
 
virtual std::vector< WWidget * > children () const override
 
SignalchildrenChanged ()
 
virtual void setPositionScheme (PositionScheme scheme) override
 
virtual PositionScheme positionScheme () const override
 
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=AllSides) override
 
virtual WLength offset (Side s) const override
 
virtual void resize (const WLength &width, const WLength &height) override
 
virtual WLength width () const override
 
virtual WLength height () const override
 
virtual void setMinimumSize (const WLength &width, const WLength &height) override
 
virtual WLength minimumWidth () const override
 
virtual WLength minimumHeight () const override
 
virtual void setMaximumSize (const WLength &width, const WLength &height) override
 
virtual WLength maximumWidth () const override
 
virtual WLength maximumHeight () const override
 
virtual void setLineHeight (const WLength &height) override
 
virtual WLength lineHeight () const override
 
virtual void setFloatSide (Side s) override
 
virtual Side floatSide () const override
 
virtual void setClearSides (WFlags< Side > sides) override
 
virtual WFlags< SideclearSides () const override
 
virtual void setMargin (const WLength &margin, WFlags< Side > sides=AllSides) override
 
virtual WLength margin (Side side) const override
 
virtual void setHiddenKeepsGeometry (bool enabled) override
 
virtual bool hiddenKeepsGeometry () const override
 
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation()) override
 
virtual bool isHidden () const override
 
virtual bool isVisible () const override
 
virtual void setDisabled (bool disabled) override
 
virtual bool isDisabled () const override
 
virtual bool isPopup () const override
 
virtual void setInline (bool isInline) override
 
virtual bool isInline () const override
 
virtual void setDecorationStyle (const WCssDecorationStyle &style) override
 
virtual WCssDecorationStyledecorationStyle () override
 
virtual void setStyleClass (const WString &styleClass) override
 
virtual WString styleClass () const override
 
virtual void addStyleClass (const WString &styleClass, bool force=false) override
 
virtual void removeStyleClass (const WString &styleClass, bool force=false) override
 
virtual bool hasStyleClass (const WString &styleClass) const override
 
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength()) override
 
virtual AlignmentFlag verticalAlignment () const override
 
virtual WLength verticalAlignmentLength () const override
 
virtual void setToolTip (const WString &text, TextFormat textFormat=TextFormat::Plain) override
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=TextFormat::Plain) override
 
virtual WString toolTip () const override
 
virtual void refresh () override
 
virtual void setAttributeValue (const std::string &name, const WString &value) override
 
virtual WString attributeValue (const std::string &name) const override
 
virtual void setJavaScriptMember (const std::string &name, const std::string &value) override
 
virtual std::string javaScriptMember (const std::string &name) const override
 
virtual void callJavaScriptMember (const std::string &name, const std::string &args) override
 
virtual bool loaded () const override
 
virtual void setId (const std::string &id) override
 
virtual WWidgetfind (const std::string &name) override
 
virtual WWidgetfindById (const std::string &id) override
 
virtual void setSelectable (bool selectable) override
 
virtual void doJavaScript (const std::string &javascript) override
 
virtual const std::string id () const override
 
void setLoadLaterWhenInvisible (bool)
 
std::string htmlTagName () const
 
void setHtmlTagName (const std::string &tag)
 
virtual void setCanReceiveFocus (bool enabled) override
 
virtual bool canReceiveFocus () const override
 
virtual bool setFirstFocus () override
 
virtual void setFocus (bool focus) override
 
virtual bool hasFocus () const override
 
virtual void setTabIndex (int index) override
 
virtual int tabIndex () const override
 
EventSignalblurred ()
 
EventSignalfocussed ()
 
virtual bool scrollVisibilityEnabled () const final override
 
virtual void setScrollVisibilityEnabled (bool enabled) final override
 
virtual int scrollVisibilityMargin () const final override
 
virtual void setScrollVisibilityMargin (int margin) final override
 
virtual Signal< bool > & scrollVisibilityChanged () final override
 
virtual bool isScrollVisible () const final override
 
virtual void setThemeStyleEnabled (bool enabled) final override
 
virtual bool isThemeStyleEnabled () const final override
 
virtual void setObjectName (const std::string &name) override
 
void setFocus ()
 
virtual void setFocus (bool focus)=0
 
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 
WWidgetparent () const
 
std::unique_ptr< Widget > removeWidget (Widget *widget)
 
std::unique_ptr< WWidgetremoveFromParent ()
 
void setWidth (const WLength &width)
 
void setHeight (const WLength &height)
 
virtual void positionAt (const WWidget *widget, Orientation orientation=Orientation::Vertical)
 
virtual void toggleStyleClass (const WString &styleClass, bool add, bool force=false)
 
std::string jsRef () const
 
void setFocus ()
 
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
void addChild (std::unique_ptr< WObject > child)
 
Child * addChild (std::unique_ptr< Child > child)
 
std::unique_ptr< WObjectremoveChild (WObject *child)
 
std::unique_ptr< Child > removeChild (Child *child)
 
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)())
 
void isNotStateless ()
 
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
 
- Public Member Functions inherited from Wt::Core::observable
 observable () noexcept
 
virtual ~observable ()
 
auto bindSafe (void(C::*method)(Args...)) noexcept
 
auto bindSafe (void(C::*method)(Args...) const) const noexcept
 
auto bindSafe (const Function &function) noexcept
 

Private Member Functions

void uploaded ()
 Slot triggered when the WFileUpload completed an upload. More...
 
void fileTooLarge (::int64_t size)
 Slot triggered when the WFileUpload received an oversized file. More...
 
void remove ()
 Slot triggered when the users wishes to remove this attachment edit. More...
 

Private Attributes

Composercomposer_
 
Signal uploadDone_
 
WFileUploadupload_
 The WFileUpload control. More...
 
std::vector< UploadInfo * > uploadInfo_
 
WTexterror_
 The text box to display an error (empty or too big file) More...
 
Optionremove_
 The option to cancel the file upload. More...
 
bool uploadFailed_
 The state of the last upload process. More...
 

Additional Inherited Members

- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWebWidget
static std::string jsStringLiteral (const std::string &v, char delimiter='\'')
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled) override
 
- Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax () override
 
virtual WStatelessSlot * getStateless (Method method) override
 
virtual void render (WFlags< RenderFlag > flags) override
 
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 
virtual void layoutSizeChanged (int width, int height)
 
 WWidget ()
 
virtual void dropEvent (WDropEvent dropEvent)
 
virtual int boxPadding (Orientation orientation) const
 
virtual int boxBorder (Orientation orientation) const
 
void scheduleRender (WFlags< RepaintFlag > flags=None)
 

Detailed Description

An edit field for an email attachment.

This widget manages 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.

Constructor & Destructor Documentation

◆ AttachmentEdit()

AttachmentEdit::AttachmentEdit ( Composer composer)

Creates an attachment edit field.

Definition at line 68 of file AttachmentEdit.C.

69  : WContainerWidget(),
70  composer_(composer),
71  uploadDone_(),
72  uploadFailed_(false)
73 {
74  /*
75  * The file upload itself.
76  */
77  upload_ = this->addWidget(std::make_unique<WFileUpload>());
78  upload_->setMultiple(true);
80 
81  /*
82  * A progress bar
83  */
84  std::unique_ptr<WProgressBar> progress = std::make_unique<WProgressBar>();
85  progress->setFormat(WString::Empty);
86  progress->setVerticalAlignment(AlignmentFlag::Middle);
87  upload_->setProgressBar(std::move(progress));
88 
89  /*
90  * The 'remove' option.
91  */
92  remove_ = this->addWidget(std::make_unique<Option>(tr("msg.remove")));
93  upload_->decorationStyle().font().setSize(FontSize::Smaller);
94  upload_->setVerticalAlignment(AlignmentFlag::Middle);
95  remove_->setMargin(5, Side::Left);
96  remove_->item()->clicked().connect(this, &WWidget::hide);
98 
99  // The error message.
100  error_ = this->addWidget(std::make_unique<WText>(""));
101  error_->setStyleClass("error");
102  error_->setMargin(WLength(5), Side::Left);
103 
104  /*
105  * React to events.
106  */
107 
108  // Try to catch the fileupload change signal to trigger an upload.
109  // We could do like google and at a delay with a WTimer as well...
110  upload_->changed().connect(upload_, &WFileUpload::upload);
111 
112  // React to a succesfull upload.
114 
115  // React to a fileupload problem.
117 
118  /*
119  * Connect the uploadDone signal to the Composer's attachmentDone,
120  * so that the Composer can keep track of attachment upload progress,
121  * if it wishes.
122  */
124 }
void remove()
Slot triggered when the users wishes to remove this attachment edit.
WText * error_
The text box to display an error (empty or too big file)
Composer * composer_
Option * remove_
The option to cancel the file upload.
bool uploadFailed_
The state of the last upload process.
void uploaded()
Slot triggered when the WFileUpload completed an upload.
WFileUpload * upload_
The WFileUpload control.
void fileTooLarge(::int64_t size)
Slot triggered when the WFileUpload received an oversized file.
void attachmentDone()
Slotcalled when an attachment has been uploaded.
Definition: Composer.C:338
WInteractWidget * item()
Returns the clickable part.
Definition: Option.h:44
Wt::Signals::connection connect(F function)
Wt::Signals::connection connect(F function)
virtual Wt::Signals::connection connect(WObject *target, WObject::Method method) override
virtual void addWidget(std::unique_ptr< WWidget > widget)
void setMultiple(bool multiple)
EventSignal & changed()
void setProgressBar(WProgressBar *progressBar)
JSignal< ::int64_t > & fileTooLarge()
EventSignal & uploaded()
void setFileTextSize(int chars)
void setSize(FontSize size)
EventSignal< WMouseEvent > & clicked()
virtual void setMargin(const WLength &margin, WFlags< Side > sides=AllSides) override
virtual void setVerticalAlignment(AlignmentFlag alignment, const WLength &length=WLength()) override
virtual void setStyleClass(const WString &styleClass) override
virtual WCssDecorationStyle & decorationStyle() override
static WString tr(const char *key)

Member Function Documentation

◆ attachments()

std::vector< Attachment > AttachmentEdit::attachments ( )

Returns the attachment.

Definition at line 189 of file AttachmentEdit.C.

190 {
191  std::vector<Attachment> result;
192 
193  for (unsigned i = 0; i < uploadInfo_.size(); ++i) {
194  if (uploadInfo_[i]->keep_->isChecked()) {
195  Http::UploadedFile& f = uploadInfo_[i]->info_;
196  f.stealSpoolFile();
197  result.push_back(Attachment
198  (WString(f.clientFileName()),
199  WString(f.contentType()),
200  f.spoolFileName()));
201  }
202  }
203 
204  return result;
205 }
std::vector< UploadInfo * > uploadInfo_
An email attachment.
Definition: Attachment.h:20
const std::string & spoolFileName() const
const std::string & clientFileName() const
void stealSpoolFile() const
const std::string & contentType() const

◆ fileTooLarge()

void AttachmentEdit::fileTooLarge ( ::int64_t  size)
private

Slot triggered when the WFileUpload received an oversized file.

Definition at line 176 of file AttachmentEdit.C.

177 {
178  error_->setText(tr("msg.file-too-large")
179  .arg(size / 1024)
180  .arg(WApplication::instance()->maximumRequestSize() / 1024));
181  uploadFailed_ = true;
182 
183  /*
184  * Signal to the Composer that a new asyncrhonous file upload was processed.
185  */
186  uploadDone_.emit();
187 }
void emit(A... args) const
bool setText(const WString &text)

◆ remove()

void AttachmentEdit::remove ( )
private

Slot triggered when the users wishes to remove this attachment edit.

Definition at line 171 of file AttachmentEdit.C.

172 {
174 }
void removeAttachment(AttachmentEdit *attachment)
Remove the given attachment edit.
Definition: Composer.C:271

◆ uploadDone()

Signal& AttachmentEdit::uploadDone ( )
inline

Signal emitted when new attachment(s) have been uploaded (or failed to upload.

Definition at line 63 of file AttachmentEdit.h.

63 { return uploadDone_; }

◆ uploaded()

void AttachmentEdit::uploaded ( )
private

Slot triggered when the WFileUpload completed an upload.

Definition at line 142 of file AttachmentEdit.C.

143 {
144  std::vector<Http::UploadedFile> files = upload_->uploadedFiles();
145 
146  if (!files.empty()) {
147  /*
148  * Delete this widgets since we have a succesfull upload.
149  */
150  upload_ = 0;
151  this->removeWidget(remove_);
152  remove_ = 0;
153  this->removeWidget(error_);
154  error_ = 0;
155 
156  for (unsigned i = 0; i < files.size(); ++i) {
157  UploadInfo *info = this->addWidget(std::make_unique<UploadInfo>(files[i]));
158  uploadInfo_.push_back(info);
159  }
160  } else {
161  error_->setText(tr("msg.file-empty"));
162  uploadFailed_ = true;
163  }
164 
165  /*
166  * Signal to the Composer that a new asynchronous file upload was processed.
167  */
168  uploadDone_.emit();
169 }
virtual std::unique_ptr< WWidget > removeWidget(WWidget *widget) override
const std::vector< Http::UploadedFile > & uploadedFiles() const

◆ uploadFailed()

bool AttachmentEdit::uploadFailed ( ) const
inline

Returns whether the upload failed.

Definition at line 54 of file AttachmentEdit.h.

54 { return uploadFailed_; }

◆ uploadNow()

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 126 of file AttachmentEdit.C.

127 {
128  /*
129  * See if this attachment still needs to be uploaded,
130  * and return if a new asynchronous upload is started.
131  */
132  if (upload_) {
133  if (upload_->canUpload()) {
134  upload_->upload();
135  return true;
136  } else
137  return false;
138  } else
139  return false;
140 }
bool canUpload() const

Member Data Documentation

◆ composer_

Composer* AttachmentEdit::composer_
private

Definition at line 66 of file AttachmentEdit.h.

◆ error_

WText* AttachmentEdit::error_
private

The text box to display an error (empty or too big file)

Definition at line 90 of file AttachmentEdit.h.

◆ remove_

Option* AttachmentEdit::remove_
private

The option to cancel the file upload.

Definition at line 93 of file AttachmentEdit.h.

◆ upload_

WFileUpload* AttachmentEdit::upload_
private

The WFileUpload control.

Definition at line 71 of file AttachmentEdit.h.

◆ uploadDone_

Signal AttachmentEdit::uploadDone_
private

Definition at line 68 of file AttachmentEdit.h.

◆ uploadFailed_

bool AttachmentEdit::uploadFailed_
private

The state of the last upload process.

Definition at line 96 of file AttachmentEdit.h.

◆ uploadInfo_

std::vector<UploadInfo *> AttachmentEdit::uploadInfo_
private

Definition at line 87 of file AttachmentEdit.h.


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