Skip to content

Commit bac28e1

Browse files
committed
Several changes:
- Changes to WFileDropWidget - Fix issue #5378 - Fix issue #5331: allow WTimer to be a child of WApplication - Fix issue #5459 - Fix issue #5458 - Fix issue #5352 - Fix issue #5261 - Applied patch of bug 5391 to fix WTextEdit (TinyMCE 4) in layout gets excessive height under certain conditions - GraphicsMagick: properly deallocate ExceptionInfo - Fix for issue #5382, "confirm email first" dialog is not displayed anymore when user has a verified email address" - MetaDbo destructor shouldn't throw - Fixed missing round_js_str in some places - Fix non-threaded version of Wt with boost 1.61 - Fixed heap buffer overflow in Wt::narrow() - Issue #5428: Added headers() function for http connections to retrieve all headers - WDropEvent: mouseEvent() and touchEvent() return pointers (breaks backwards compatibility) - WObject should not be copy assignable - Feature #4656: fixes for multi item selection
1 parent 9c73276 commit bac28e1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+2254
-1228
lines changed

doc/main

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,9 +568,13 @@ appRoot=C:\Program Files\MyApplications\AppRoot
568568
<dt><strong>tracking</strong></dt>
569569

570570
<dd>How session tracking is implemented: automatically (using
571-
cookies when available, otherwise using URL rewriting) or
571+
cookies when available, otherwise using URL rewriting),
572572
strictly using URL rewriting (which allows multiple concurrent
573-
sessions from one user). </dd>
573+
sessions from one user), or a combined tracking strategy that uses
574+
URL rewriting in combination with a shared cookie between
575+
sessions in the same browser for extra session hijacking protection.
576+
The combined strategy does not fall back to only URL rewriting when
577+
cookies are not available: it will simply refuse access.</dd>
574578

575579
<dt><strong>reload-is-new-session</strong></dt>
576580

examples/filedrop/FileDropApplication.C

Lines changed: 94 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -7,73 +7,130 @@
77
#include "FileDropApplication.h"
88

99
#include <Wt/WContainerWidget>
10+
#include <Wt/WPushButton>
1011
#include <Wt/WText>
1112
#include <Wt/WFileDropWidget>
12-
#include <Wt/WFileUpload>
13+
#include "Wt/Utils"
1314

1415
#include <iostream>
1516
#include <fstream>
1617

1718
using namespace Wt;
1819

1920
static const std::string UPLOAD_FOLDER = "./uploaded/";
21+
static const int MAX_FILES = 36;
22+
2023

2124
FileDropApplication::FileDropApplication(const WEnvironment& env)
22-
: WApplication(env)
25+
: WApplication(env),
26+
nbUploads_(0)
2327
{
2428
setTitle("File Drop Example");
29+
useStyleSheet("style.css");
2530

2631
new WText("<h1>Try dropping a file in the widget below</h1>", root());
27-
28-
drop_ = new WFileDropWidget();
29-
root()->addWidget(drop_);
3032

31-
connectFileUpload();
33+
drop_ = new WFileDropWidget(root());
34+
35+
drop_->drop().connect(this, &FileDropApplication::handleDrop);
36+
drop_->newUpload().connect(this,&FileDropApplication::updateProgressListener);
37+
drop_->uploaded().connect(this, &FileDropApplication::saveFile);
38+
drop_->uploadFailed().connect(this, &FileDropApplication::failed);
39+
drop_->tooLarge().connect(this, &FileDropApplication::tooLarge);
3240

3341
log_ = new WText(root());
34-
}
42+
log_->setInline(false);
43+
log_->setTextFormat(XHTMLText);
3544

36-
void FileDropApplication::connectFileUpload()
37-
{
38-
drop_->fileUpload()->setMultiple(true);
39-
drop_->fileUpload()->uploaded().connect(this, &FileDropApplication::saveFile);
40-
drop_->fileUpload()->fileTooLarge().connect(this,
41-
&FileDropApplication::fileTooBig);
45+
WPushButton *abort = new WPushButton("Abort current upload", root());
46+
abort->clicked().connect(this, &FileDropApplication::cancelUpload);
4247
}
4348

44-
void FileDropApplication::saveFile()
49+
void FileDropApplication::handleDrop(std::vector<WFileDropWidget::File *> files)
4550
{
46-
std::vector<Http::UploadedFile> files = drop_->fileUpload()->uploadedFiles();
47-
for (int i =0; i < files.size(); i++) {
48-
std::string spool = files[i].spoolFileName();
49-
50-
std::ifstream src(spool.c_str(), std::ios::binary);
51-
std::ofstream dest((UPLOAD_FOLDER + files[i].clientFileName()).c_str(),
52-
std::ios::binary);
53-
if (dest.fail()) {
54-
std::cerr << "**** ERROR: The output file could not be opened"
55-
<< std::endl;
56-
break;
51+
for (unsigned i=0; i < files.size(); i++) {
52+
if (nbUploads_ >= MAX_FILES) {
53+
drop_->cancelUpload(files[i]);
54+
continue;
5755
}
58-
59-
dest << src.rdbuf();
6056

61-
// Add a little block to the container-widget
6257
WContainerWidget *block = new WContainerWidget(drop_);
63-
block->setWidth(20);
64-
block->setHeight(20);
65-
block->setMargin(10);
66-
block->decorationStyle().setBackgroundColor(WColor("black"));
58+
block->setToolTip(files[i]->clientFileName() + " [" + files[i]->mimeType()
59+
+ "]");
60+
block->addStyleClass("upload-block");
61+
62+
icons_[files[i]] = block;
63+
nbUploads_++;
64+
}
65+
66+
if (nbUploads_ >= MAX_FILES) {
67+
log_->setText("That's enough ...");
68+
drop_->setAcceptDrops(false);
6769
}
70+
}
71+
72+
void FileDropApplication::cancelUpload()
73+
{
74+
if (drop_->uploads().size() == drop_->currentIndex())
75+
return;
76+
77+
WFileDropWidget::File *currentFile = drop_->uploads()[drop_->currentIndex()];
78+
drop_->cancelUpload(currentFile);
79+
icons_[currentFile]->addStyleClass("cancelled");
80+
}
81+
82+
void FileDropApplication::tooLarge(WFileDropWidget::File *file)
83+
{
84+
icons_[file]->addStyleClass("invalid");
85+
86+
log_->setText("File too large: " + file->clientFileName());
87+
}
6888

89+
void FileDropApplication::failed(WFileDropWidget::File *file)
90+
{
91+
icons_[file]->addStyleClass("invalid");
6992

70-
log_->setText("Thanks for the file(s)");
93+
log_->setText("Upload failed: " + file->clientFileName());
94+
}
95+
96+
void FileDropApplication::saveFile(WFileDropWidget::File *file)
97+
{
98+
// std::string spool = file->uploadedFile().spoolFileName();
99+
// std::ifstream src(spool.c_str(), std::ios::binary);
100+
101+
// std::ofstream dest((UPLOAD_FOLDER + file->clientFileName()).c_str(),
102+
// std::ios::binary);
103+
// if (dest.fail()) {
104+
// std::cerr << "**** ERROR: The output file could not be opened"
105+
// << std::endl;
106+
// return;;
107+
// }
71108

72-
drop_->resetUpload();
73-
connectFileUpload();
109+
// dest << src.rdbuf();
110+
111+
if (icons_.find(file) != icons_.end()) {
112+
icons_[file]->addStyleClass("ready");
113+
drop_->remove(file);
114+
}
115+
}
116+
117+
void FileDropApplication::updateProgressListener()
118+
{
119+
// if there is a next file listen for progress
120+
if (drop_->currentIndex() < drop_->uploads().size()) {
121+
WFileDropWidget::File *file = drop_->uploads()[drop_->currentIndex()];
122+
file->dataReceived().connect(this, &FileDropApplication::showProgress);
123+
std::string fileName = Utils::htmlEncode(file->clientFileName());
124+
log_->setText("uploading file &quot;" + fileName + "&quot;");
125+
}
74126
}
75127

76-
void FileDropApplication::fileTooBig()
128+
void FileDropApplication::showProgress(::uint64_t current, ::uint64_t total)
77129
{
78-
log_->setText("The file is too big ...");
130+
WFileDropWidget::File *file = drop_->uploads()[drop_->currentIndex()];
131+
std::string c = boost::lexical_cast<std::string>(current/1024);
132+
std::string t = boost::lexical_cast<std::string>(total/1024);
133+
std::string fileName = Utils::htmlEncode(file->clientFileName());
134+
log_->setText("uploading file <i>&quot;" + fileName + "&quot;</i>"
135+
+ " (" + c + "kB" + " out of " + t + "kB)");
79136
}

examples/filedrop/FileDropApplication.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#define FILEDROPAPPLICATION_H_
1010

1111
#include <Wt/WApplication>
12+
#include <Wt/WFileDropWidget>
1213

1314
using namespace Wt;
14-
1515
namespace Wt {
16-
class WFileDropWidget;
16+
class WContainerWidget;
1717
}
1818

1919
class FileDropApplication : public WApplication
@@ -24,10 +24,18 @@ class FileDropApplication : public WApplication
2424
private:
2525
WText *log_;
2626
WFileDropWidget *drop_;
27-
28-
void saveFile();
29-
void fileTooBig();
30-
void connectFileUpload();
27+
int nbUploads_;
28+
29+
std::map<WFileDropWidget::File*, Wt::WContainerWidget*> icons_;
30+
31+
void handleDrop(std::vector<WFileDropWidget::File *> files);
32+
void tooLarge(WFileDropWidget::File *file);
33+
void failed(WFileDropWidget::File *file);
34+
void saveFile(WFileDropWidget::File *file);
35+
void cancelUpload();
36+
void updateProgressListener();
37+
38+
void showProgress(::uint64_t current, ::uint64_t total);
3139
};
3240

3341

examples/filedrop/style.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
2+
.upload-block {
3+
width: 10px;
4+
height: 10px;
5+
margin: 10px;
6+
border: 1px solid black;
7+
display: inline-block;
8+
}
9+
10+
.upload-block.cancelled {
11+
background-color: grey;
12+
}
13+
14+
.upload-block.ready {
15+
background-color: green;
16+
}
17+
18+
.upload-block.invalid {
19+
background-color: red;
20+
}

examples/widgetgallery/FormWidgets.C

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,11 +236,13 @@ Wt::WWidget *FormWidgets::progressBar()
236236

237237

238238
#include "examples/FileUpload.cpp"
239+
#include "examples/FileDrop.cpp"
239240

240241
Wt::WWidget *FormWidgets::fileUpload()
241242
{
242243
Wt::WTemplate *result = new TopicTemplate("forms-fileUpload");
243244
result->bindWidget("FileUpload", FileUpload());
245+
result->bindWidget("FileDrop", FileDrop());
244246

245247
return result;
246248
}

0 commit comments

Comments
 (0)