Wt examples  3.2.1
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.
bool uploadNow ()
 Updates the file now.
bool uploadFailed () const
 Returns whether the upload failed.
std::vector< Attachmentattachments ()
 Returns the attachment.
Signal< void > & uploadDone ()
 Signal emitted when new attachment(s) have been uploaded (or failed to upload.
- 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 ()
 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)
virtual void load ()
virtual bool isEnabled () const
 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 void setPopup (bool popup)
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 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 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 setTabIndex (int index)
virtual int tabIndex () const
virtual void setId (const std::string &id)
virtual WWidgetfind (const std::string &name)
virtual void setSelectable (bool selectable)
virtual void doJavaScript (const std::string &javascript)
virtual const std::string id () const
void setLoadLaterWhenInvisible (bool)
const std::vector< WWidget * > & children () const
SignalchildrenChanged ()
bool isRendered () const
virtual ~WWidget ()
WWidgetparent () const
void setWidth (const WLength &width)
void setHeight (const WLength &height)
virtual void positionAt (const WWidget *widget, Orientation orientation=Vertical)
std::string jsRef () const
virtual void acceptDrops (const std::string &mimeType, const WString &hoverStyleClass=WString())
virtual void stopAcceptDrops (const std::string &mimeType)
virtual void htmlText (std::ostream &out)
void hide ()
void animateHide (const WAnimation &animation)
void show ()
void animateShow (const WAnimation &animation)
void enable ()
void disable ()
bool layoutSizeAware () const
 WObject (WObject *parent=0)
virtual ~WObject ()
void setObjectName (const std::string &name)
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)())
WStatelessSlot * implementJavaScript (void(T::*method)(), const std::string &jsCode)
void addChild (WObject *child)

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

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

Additional Inherited Members

- Public Types inherited from Wt::WContainerWidget
enum  Overflow
- Static Public Member Functions inherited from Wt::WContainerWidget
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= '\'')
- Public Attributes inherited from Wt::WContainerWidget
 OverflowVisible
 OverflowAuto
 OverflowHidden
 OverflowScroll
- Protected Member Functions inherited from Wt::WContainerWidget
virtual void propagateSetEnabled (bool enabled)
- Static Protected Member Functions inherited from Wt::WContainerWidget
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.

: WContainerWidget(parent),
composer_(composer),
uploadDone_(this),
{
/*
* The file upload itself.
*/
upload_ = new WFileUpload(this);
/*
* 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);
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.
// React to a fileupload problem.
/*
* Connect the uploadDone signal to the Composer's attachmentDone,
* so that the Composer can keep track of attachment upload progress,
* if it wishes.
*/
}

Member Function Documentation

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()) {
result.push_back(Attachment
(WString::fromUTF8(f.clientFileName()),
WString::fromUTF8(f.contentType()),
}
}
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.
*/
}
void AttachmentEdit::remove ( )
private

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

Definition at line 173 of file AttachmentEdit.C.

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.
*/
}
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.

{
/*
* See if this attachment still needs to be uploaded,
* and return if a new asynchronous upload is started.
*/
if (upload_) {
if (upload_->canUpload()) {
return true;
} else
return false;
} else
return false;
}

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 Sat Oct 18 2014 for the C++ Web Toolkit (Wt) by doxygen 1.8.1.2