11 #include <boost/lexical_cast.hpp> 16 #include <Wt/WApplication> 17 #include <Wt/WCheckBox> 18 #include <Wt/WCssDecorationStyle> 19 #include <Wt/WFileResource> 20 #include <Wt/WFileUpload> 21 #include <Wt/WProgressBar> 30 WContainerWidget *parent)
31 : WContainerWidget(parent),
37 keep_ =
new WCheckBox(
this);
43 std::streamsize fsize = 0;
45 std::ifstream theFile(
info_.spoolFileName().c_str());
46 theFile.seekg(0, std::ios_base::end);
47 fsize = theFile.tellg();
52 size = boost::lexical_cast<std::wstring>(fsize) + L
" bytes";
54 size = boost::lexical_cast<std::wstring>((int)(fsize / 1024))
57 std::wstring fn =
static_cast<std::wstring
> 58 (escapeText(WString::fromUTF8(
info_.clientFileName())));
61 =
new WAnchor(
"", fn + L
" (<i>" + WString::fromUTF8(
info_.contentType())
62 + L
"</i>) " + size,
this);
64 WFileResource *res =
new WFileResource(
info_.contentType(),
65 info_.spoolFileName(),
67 res->suggestFileName(
info_.clientFileName());
72 : WContainerWidget(parent),
80 upload_ =
new WFileUpload(
this);
87 WProgressBar *progress =
new WProgressBar();
88 progress->setFormat(WString::Empty);
89 progress->setVerticalAlignment(AlignMiddle);
90 upload_->setProgressBar(progress);
96 upload_->decorationStyle().font().setSize(WFont::Smaller);
97 upload_->setVerticalAlignment(AlignMiddle);
99 remove_->
item()->clicked().connect(
this, &WWidget::hide);
103 error_ =
new WText(
"",
this);
104 error_->setStyleClass(
"error");
105 error_->setMargin(WLength(5), Left);
147 std::vector<Http::UploadedFile> files =
upload_->uploadedFiles();
149 if (!files.empty()) {
160 for (
unsigned i = 0; i < files.size(); ++i)
163 error_->setText(tr(
"msg.file-empty"));
180 error_->setText(tr(
"msg.file-too-large")
182 .arg(WApplication::instance()->maximumRequestSize() / 1024));
193 std::vector<Attachment> result;
195 for (
unsigned i = 0; i <
uploadInfo_.size(); ++i) {
200 (WString::fromUTF8(f.clientFileName()),
201 WString::fromUTF8(f.contentType()),
void uploaded()
Slot triggered when the WFileUpload completed an upload.
Signal< void > uploadDone_
WInteractWidget * item()
Returns the clickable part.
AttachmentEdit(Composer *composer, WContainerWidget *parent=0)
Creates an attachment edit field.
WAnchor * downloadLink_
Anchor referencing the file.
An E-mail composer widget.
Option * remove_
The option to cancel the file upload.
WCheckBox * keep_
The check box to keep or discard the uploaded file.
std::vector< Attachment > attachments()
Returns the attachment.
void removeAttachment(AttachmentEdit *attachment)
Remove the given attachment edit.
WFileUpload * upload_
The WFileUpload control.
void remove()
Slot triggered when the users wishes to remove this attachment edit.
UploadInfo(const Http::UploadedFile &f, WContainerWidget *parent=0)
bool uploadNow()
Updates the file now.
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.
bool uploadFailed_
The state of the last upload process.
std::vector< UploadInfo * > uploadInfo_