Wt examples  3.3.8
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:
Inheritance graph
[legend]

Classes

class  UploadInfo
 

Public Member Functions

 AttachmentEdit (Composer *composer, WContainerWidget *parent=0)
 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...
 
Signal< void > & uploadDone ()
 Signal emitted when new attachment(s) have been uploaded (or failed to upload. More...
 
- Public Member Functions inherited from Wt::WContainerWidget
 WContainerWidget (WContainerWidget *parent=0)
 
 ~WContainerWidget ()
 
void setLayout (WLayout *layout)
 
void setLayout (WLayout *layout, WFlags< AlignmentFlag > alignment)
 
WLayoutlayout ()
 
virtual void addWidget (WWidget *widget)
 
virtual void insertBefore (WWidget *widget, WWidget *before)
 
virtual void insertWidget (int index, WWidget *widget)
 
virtual void removeWidget (WWidget *widget)
 
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=All)
 
WLength padding (Side side) const
 
WFlags< AlignmentFlagcontentAlignment () const
 
void setOverflow (Overflow overflow, WFlags< Orientation > orientation=(Horizontal|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
 
- Public Member Functions inherited from Wt::WInteractWidget
 WInteractWidget (WContainerWidget *parent=0)
 
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=0, bool isDragWidgetOnly=false, WObject *sourceWidget=0)
 
void unsetDraggable ()
 
void setMouseOverDelay (int delay)
 
int mouseOverDelay () const
 
virtual void setPopup (bool popup)
 
virtual void load ()
 
virtual bool isEnabled () const
 
- Public Member Functions inherited from Wt::WWebWidget
 WWebWidget (WContainerWidget *parent=0)
 
virtual void setPositionScheme (PositionScheme scheme)
 
virtual PositionScheme positionScheme () const
 
virtual void setOffsets (const WLength &offset, WFlags< Side > sides=All)
 
virtual WLength offset (Side s) const
 
virtual void resize (const WLength &width, const WLength &height)
 
virtual WLength width () const
 
virtual WLength height () const
 
virtual void setMinimumSize (const WLength &width, const WLength &height)
 
virtual WLength minimumWidth () const
 
virtual WLength minimumHeight () const
 
virtual void setMaximumSize (const WLength &width, const WLength &height)
 
virtual WLength maximumWidth () const
 
virtual WLength maximumHeight () const
 
virtual void setLineHeight (const WLength &height)
 
virtual WLength lineHeight () const
 
virtual void setFloatSide (Side s)
 
virtual Side floatSide () const
 
virtual void setClearSides (WFlags< Side > sides)
 
virtual WFlags< SideclearSides () const
 
virtual void setMargin (const WLength &margin, WFlags< Side > sides=All)
 
virtual WLength margin (Side side) const
 
virtual void setHiddenKeepsGeometry (bool enabled)
 
virtual bool hiddenKeepsGeometry () const
 
virtual void setHidden (bool hidden, const WAnimation &animation=WAnimation())
 
virtual bool isHidden () const
 
virtual bool isVisible () const
 
virtual void setDisabled (bool disabled)
 
virtual bool isDisabled () const
 
virtual bool isPopup () const
 
virtual void setInline (bool isInline)
 
virtual bool isInline () const
 
virtual void setDecorationStyle (const WCssDecorationStyle &style)
 
virtual WCssDecorationStyledecorationStyle ()
 
virtual void setStyleClass (const WString &styleClass)
 
virtual WString styleClass () const
 
virtual void addStyleClass (const WString &styleClass, bool force=false)
 
virtual void removeStyleClass (const WString &styleClass, bool force=false)
 
virtual bool hasStyleClass (const WString &styleClass) const
 
virtual void setVerticalAlignment (AlignmentFlag alignment, const WLength &length=WLength())
 
virtual AlignmentFlag verticalAlignment () const
 
virtual WLength verticalAlignmentLength () const
 
virtual void setToolTip (const WString &text, TextFormat textFormat=PlainText)
 
virtual void setDeferredToolTip (bool enable, TextFormat textFormat=PlainText)
 
virtual WString toolTip () const
 
virtual void refresh ()
 
virtual void setAttributeValue (const std::string &name, const WString &value)
 
virtual WString attributeValue (const std::string &name) const
 
virtual void setJavaScriptMember (const std::string &name, const std::string &value)
 
virtual std::string javaScriptMember (const std::string &name) const
 
virtual void callJavaScriptMember (const std::string &name, const std::string &args)
 
virtual bool loaded () const
 
virtual void setId (const std::string &id)
 
virtual WWidgetfind (const std::string &name)
 
virtual WWidgetfindById (const std::string &id)
 
virtual void setSelectable (bool selectable)
 
virtual void doJavaScript (const std::string &javascript)
 
virtual const std::string id () const
 
void setLoadLaterWhenInvisible (bool)
 
std::string htmlTagName () const
 
void setHtmlTagName (const std::string &tag)
 
const std::vector< WWidget * > & children () const
 
SignalchildrenChanged ()
 
virtual void setCanReceiveFocus (bool enabled)
 
virtual bool canReceiveFocus () const
 
virtual bool setFirstFocus ()
 
virtual void setFocus (bool focus)
 
virtual bool hasFocus () const
 
virtual void setTabIndex (int index)
 
virtual int tabIndex () const
 
EventSignalblurred ()
 
EventSignalfocussed ()
 
virtual bool scrollVisibilityEnabled () const WT_CXX11ONLY(finaloverride)
 
virtual void setScrollVisibilityEnabled (bool enabled) WT_CXX11ONLY(finaloverride)
 
virtual int scrollVisibilityMargin () const WT_CXX11ONLY(finaloverride)
 
virtual void setScrollVisibilityMargin (int margin) WT_CXX11ONLY(finaloverride)
 
virtual Signal< bool > & scrollVisibilityChanged () WT_CXX11ONLY(finaloverride)
 
virtual bool isScrollVisible () const WT_CXX11ONLY(finaloverride)
 
virtual void setThemeStyleEnabled (bool enabled)
 
virtual bool isThemeStyleEnabled () const
 
- Public Member Functions inherited from Wt::WWidget
virtual ~WWidget ()
 
WWidgetparent () const
 
virtual void removeChild (WObject *child)
 
void setWidth (const WLength &width)
 
void setHeight (const WLength &height)
 
virtual void positionAt (const WWidget *widget, 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 setObjectName (const std::string &name)
 
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
 WObject (WObject *parent=0)
 
virtual ~WObject ()
 
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)
 
void addChild (WObject *child)
 
const std::vector< WObject * > & children () const
 
WObjectparent () const
 

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< void > 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::WContainerWidget
enum  Overflow
 
- Public Types inherited from Wt::WObject
typedef void(WObject::* Method) ()
 
- Static Public Member Functions inherited from Wt::WWebWidget
static WString escapeText (const WString &text, bool newlinesToo=false)
 
static std::string & escapeText (std::string &text, bool newlinestoo=false)
 
static bool removeScript (WString &text)
 
static std::string jsStringLiteral (const std::string &v, char delimiter= '\'')
 
- Static Public Member Functions inherited from Wt::WWidget
static WString tr (const char *key)
 
- Public Attributes inherited from Wt::WContainerWidget
 OverflowVisible
 
 OverflowAuto
 
 OverflowHidden
 
 OverflowScroll
 
- Protected Member Functions inherited from Wt::WInteractWidget
virtual void propagateSetEnabled (bool enabled)
 
- Protected Member Functions inherited from Wt::WWebWidget
virtual void enableAjax ()
 
virtual WStatelessSlot * getStateless (Method method)
 
virtual void render (WFlags< RenderFlag > flags)
 
- Protected Member Functions inherited from Wt::WWidget
void setLayoutSizeAware (bool sizeAware)
 
virtual void layoutSizeChanged (int width, int height)
 
 WWidget (WContainerWidget *parent=0)
 
virtual void dropEvent (WDropEvent dropEvent)
 
virtual int boxPadding (Orientation orientation) const
 
virtual int boxBorder (Orientation orientation) const
 
void scheduleRender (WFlags< RepaintFlag > flags=0)
 
- Static Protected Member Functions inherited from Wt::WObject
static WObjectsender ()
 

Detailed Description

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.

Constructor & Destructor Documentation

AttachmentEdit::AttachmentEdit ( Composer composer,
WContainerWidget parent = 0 
)

Creates an attachment edit field.

Definition at line 71 of file AttachmentEdit.C.

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

Member Function Documentation

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

Returns the attachment.

Definition at line 191 of file AttachmentEdit.C.

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

Slot triggered when the WFileUpload received an oversized file.

Definition at line 178 of file AttachmentEdit.C.

179 {
180  error_->setText(tr("msg.file-too-large")
181  .arg(size / 1024)
182  .arg(WApplication::instance()->maximumRequestSize() / 1024));
183  uploadFailed_ = true;
184 
185  /*
186  * Signal to the Composer that a new asyncrhonous file upload was processed.
187  */
188  uploadDone_.emit();
189 }
void emit(A1 a1=NoClass::none, A2 a2=NoClass::none, A3 a3=NoClass::none, A4 a4=NoClass::none, A5 a5=NoClass::none, A6 a6=NoClass::none) const
Signal< void > uploadDone_
static WString tr(const char *key)
bool setText(const WString &text)
WText * error_
The text box to display an error (empty or too big file)
bool uploadFailed_
The state of the last upload process.
void AttachmentEdit::remove ( )
private

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

Definition at line 173 of file AttachmentEdit.C.

174 {
176 }
void removeAttachment(AttachmentEdit *attachment)
Remove the given attachment edit.
Definition: Composer.C:264
Composer * composer_
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.

63 { return uploadDone_; }
Signal< void > uploadDone_
void AttachmentEdit::uploaded ( )
private

Slot triggered when the WFileUpload completed an upload.

Definition at line 145 of file AttachmentEdit.C.

146 {
147  std::vector<Http::UploadedFile> files = upload_->uploadedFiles();
148 
149  if (!files.empty()) {
150  /*
151  * Delete this widgets since we have a succesfull upload.
152  */
153  delete upload_;
154  upload_ = 0;
155  delete remove_;
156  remove_ = 0;
157  delete error_;
158  error_ = 0;
159 
160  for (unsigned i = 0; i < files.size(); ++i)
161  uploadInfo_.push_back(new UploadInfo(files[i], this));
162  } else {
163  error_->setText(tr("msg.file-empty"));
164  uploadFailed_ = true;
165  }
166 
167  /*
168  * Signal to the Composer that a new asynchronous file upload was processed.
169  */
170  uploadDone_.emit();
171 }
void emit(A1 a1=NoClass::none, A2 a2=NoClass::none, A3 a3=NoClass::none, A4 a4=NoClass::none, A5 a5=NoClass::none, A6 a6=NoClass::none) const
Signal< void > uploadDone_
static WString tr(const char *key)
Option * remove_
The option to cancel the file upload.
bool setText(const WString &text)
WFileUpload * upload_
The WFileUpload control.
const std::vector< Http::UploadedFile > & uploadedFiles() const
WText * error_
The text box to display an error (empty or too big file)
bool uploadFailed_
The state of the last upload process.
std::vector< UploadInfo * > uploadInfo_
bool AttachmentEdit::uploadFailed ( ) const
inline

Returns whether the upload failed.

Definition at line 54 of file AttachmentEdit.h.

54 { return uploadFailed_; }
bool uploadFailed_
The state of the last upload process.
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.

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

Member Data Documentation

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.


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

Generated on Mon Sep 4 2017 for the C++ Web Toolkit (Wt) by doxygen 1.8.11