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>
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
>
63 auto res = std::make_shared<WFileResource>(
info_.contentType(),
info_.spoolFileName());
64 res->suggestFileName(
info_.clientFileName());
84 std::unique_ptr<WProgressBar> progress = std::make_unique<WProgressBar>();
86 progress->setVerticalAlignment(AlignmentFlag::Middle);
87 upload_->setProgressBar(std::move(progress));
93 upload_->decorationStyle().font().setSize(FontSize::Smaller);
94 upload_->setVerticalAlignment(AlignmentFlag::Middle);
95 remove_->setMargin(5, Side::Left);
101 error_->setStyleClass(
"error");
144 std::vector<Http::UploadedFile> files =
upload_->uploadedFiles();
146 if (!files.empty()) {
156 for (
unsigned i = 0; i < files.size(); ++i) {
161 error_->setText(
tr(
"msg.file-empty"));
178 error_->setText(
tr(
"msg.file-too-large")
191 std::vector<Attachment> result;
193 for (
unsigned i = 0; i <
uploadInfo_.size(); ++i) {
WCheckBox * keep_
The check box to keep or discard the uploaded file.
WAnchor * downloadLink_
Anchor referencing the file.
UploadInfo(const Http::UploadedFile &f)
bool uploadNow()
Updates the file now.
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).
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.
std::vector< Attachment > attachments()
Returns the attachment.
WFileUpload * upload_
The WFileUpload control.
std::vector< UploadInfo * > uploadInfo_
AttachmentEdit(Composer *composer)
Creates an attachment edit field.
void fileTooLarge(::int64_t size)
Slot triggered when the WFileUpload received an oversized file.
An E-mail composer widget.
void attachmentDone()
Slotcalled when an attachment has been uploaded.
const std::string & spoolFileName() const
const std::string & clientFileName() const
void stealSpoolFile() const
const std::string & contentType() const
static WApplication * instance()
static const WString Empty