Project

General

Profile

Bug #2187 ยป TriggerWFileUploadBug.cpp

Georg Baumann, 09/06/2013 11:05 AM

 
#include <Wt/WApplication>
#include <Wt/WEnvironment>
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WPushButton>
#include <Wt/WText>
#include <Wt/WFileUpload>
#include <Wt/WMessageBox>

using namespace Wt;
using namespace std;

////////////////////////////////////////////////////////////////////
class TriggerWFileUploadBugWidget: public Wt::WContainerWidget {
public:
TriggerWFileUploadBugWidget(Wt::WContainerWidget *parent = 0);

virtual ~TriggerWFileUploadBugWidget() {
}

private:
Wt::WFileUpload *firstfileUpload;

WPushButton *loadButton;

void doUpload();
void fileUploaded();
void fileMuchTooLarge(::int64_t size);
};


TriggerWFileUploadBugWidget::TriggerWFileUploadBugWidget(WContainerWidget *parent)
:
WContainerWidget(parent)
{
this->addWidget(new WText("First: "));
firstfileUpload = new Wt::WFileUpload(this);
firstfileUpload->setFileTextSize(40);

firstfileUpload->uploaded().connect(this, &TriggerWFileUploadBugWidget::fileUploaded);
firstfileUpload->fileTooLarge().connect(this, &TriggerWFileUploadBugWidget::fileMuchTooLarge);

this->addWidget(new WBreak());
loadButton = new WPushButton("Load", this);

loadButton->clicked().connect(this, &TriggerWFileUploadBugWidget::doUpload);
}

////////////////////////////////////////////////////////////////
void TriggerWFileUploadBugWidget::doUpload() {
firstfileUpload->upload();

cerr << "Started upload" << endl;
loadButton->disable();
}

void TriggerWFileUploadBugWidget::fileUploaded() {
string firstfileClient=firstfileUpload->clientFileName().narrow();
cerr << "Entered allFilesUploaded" << endl;

WMessageBox::show("File successfully uploaded","Got file: " + firstfileClient,Ok);
}

void TriggerWFileUploadBugWidget::fileMuchTooLarge(::int64_t size) {

// NEVER CALLED !!!

WMessageBox::show("Error","File too large",Ok);
}

WApplication *createApplication(const WEnvironment& env) {
Wt::WApplication *app = new Wt::WApplication(env);
app->setTitle("WFileUpload bug");

new TriggerWFileUploadBugWidget(app->root());

return app;
}

int main(int argc, char **argv)
{
return WRun(argc, argv, &createApplication);
}

    (1-1/1)