14 #include <Wt/WAnchor.h> 15 #include <Wt/WApplication.h> 16 #include <Wt/WCheckBox.h> 17 #include <Wt/WCssDecorationStyle.h> 18 #include <Wt/WFileResource.h> 20 #include <Wt/WFileUpload.h> 21 #include <Wt/WProgressBar.h> 36 keep_ = this->addWidget(cpp14::make_unique<WCheckBox>());
42 std::streamsize fsize = 0;
44 std::ifstream theFile(
info_.spoolFileName().c_str());
45 theFile.seekg(0, std::ios_base::end);
46 fsize = theFile.tellg();
51 size = WString(std::to_string(fsize)) + U
" bytes";
53 size = WString(std::to_string((
int)(fsize / 1024)))
56 std::u32string fn = static_cast<std::u32string>
57 (escapeText(WString(
info_.clientFileName())));
60 = this->addWidget(cpp14::make_unique<WAnchor>(
"", fn + U
" (<i>" + WString(
info_.contentType())
63 auto res = std::make_shared<WFileResource>(
info_.contentType(),
info_.spoolFileName());
64 res->suggestFileName(
info_.clientFileName());
77 upload_ = this->addWidget(cpp14::make_unique<WFileUpload>());
84 std::unique_ptr<WProgressBar> progress = cpp14::make_unique<WProgressBar>();
85 progress->setFormat(WString::Empty);
86 progress->setVerticalAlignment(AlignmentFlag::Middle);
87 upload_->setProgressBar(std::move(progress));
92 remove_ = this->addWidget(cpp14::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);
100 error_ = this->addWidget(cpp14::make_unique<WText>(
""));
101 error_->setStyleClass(
"error");
102 error_->setMargin(WLength(5), Side::Left);
144 std::vector<Http::UploadedFile> files =
upload_->uploadedFiles();
146 if (!files.empty()) {
153 this->removeWidget(
error_);
156 for (
unsigned i = 0; i < files.size(); ++i) {
157 UploadInfo *info = this->addWidget(cpp14::make_unique<UploadInfo>(files[i]));
161 error_->setText(tr(
"msg.file-empty"));
178 error_->setText(tr(
"msg.file-too-large")
180 .arg(WApplication::instance()->maximumRequestSize() / 1024));
191 std::vector<Attachment> result;
193 for (
unsigned i = 0; i <
uploadInfo_.size(); ++i) {
198 (WString(f.clientFileName()),
199 WString(f.contentType()),
void uploaded()
Slot triggered when the WFileUpload completed an upload.
WInteractWidget * item()
Returns the clickable part.
UploadInfo(const Http::UploadedFile &f)
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.
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)
AttachmentEdit(Composer *composer)
Creates an attachment edit field.
void attachmentDone()
Slotcalled when an attachment has been uploaded.
bool uploadFailed_
The state of the last upload process.
std::vector< UploadInfo * > uploadInfo_