Skip to content

Commit 34ed9ef

Browse files
committed
Several changes:
- added WFileDropWidget with example - avoid XSS when using WString::tr with user-supplied arg - WDropEvent: mouseEvent() and touchEvent() return pointers and make defensive copy, breaks backwards compatibility - WObject should not be copy assignable - Fixing compiler warnings - Fixes to touch selection behaviour in WTableView and WTreeView (issue #4656) - Fixed PayPal regression caused by HTTP client only using TLSv1, not later versions - Use $.event.fix on events triggered. This fixes click events and mousedown events on WTableViews when more recent versions of jQuery are used. - Fixed regression with touch for WCartesianChart since touchEvents were implemented - Workaround in JSON tests for boost versions before 1.47 - Only sync back WJavaScriptExposableObjects if they've been changed (fixes issue #5414) - Fix issue #5404: stuck WPopupMenu button - Added option for specifying crosshair color, resolves issue #5180 - fix WTreeView error while handling row removals: error in WTreeView::widgetForIndex() - Added Combined session tracking mode - Removed redirectToSession() - Added missing include that made MinGW build fail
1 parent b1b79ec commit 34ed9ef

Some content is hidden

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

80 files changed

+1813
-747
lines changed

examples/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ SUBDIRS(
221221
dragdrop
222222
feature
223223
filetreetable
224+
filedrop
224225
form
225226
gitmodel
226227
hangman

examples/filedrop/CMakeLists.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#
2+
# The ADD_EXAMPLE macro (defined in examples/CMakeLists.txt) ensures that
3+
# the example is correctly built for the requested connector. It is equivalent
4+
# to the following two lines:
5+
# ADD_EXECUTABLE(hello.wt hello.C)
6+
# TARGET_LINK_LIBRARIES(hello.wt ${EXAMPLES_CONNECTOR})
7+
# except when the ISAPI (for Microsoft IIS) connector is used, where it will
8+
# build a DLL with the proper symbols exported.
9+
#
10+
WT_ADD_EXAMPLE(filedrop.wt filedrop.C FileDropApplication.C)
11+
12+
#
13+
# If you have Wt installed somehwere, you should use the
14+
# installed Wt header files for your own Wt projects.
15+
# e.g. INCLUDE_DIRECTORIES(/usr/local/include)
16+
# instead of the following:
17+
#
18+
INCLUDE_DIRECTORIES(${WT_SOURCE_DIR}/src)
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/*
2+
* Copyright (C) 2016 Emweb bvba, Herent, Belgium.
3+
*
4+
* See the LICENSE file for terms of use.
5+
*/
6+
7+
#include "FileDropApplication.h"
8+
9+
#include <Wt/WContainerWidget>
10+
#include <Wt/WText>
11+
#include <Wt/WFileDropWidget>
12+
#include <Wt/WFileUpload>
13+
14+
#include <iostream>
15+
#include <fstream>
16+
17+
using namespace Wt;
18+
19+
static const std::string UPLOAD_FOLDER = "./uploaded/";
20+
21+
FileDropApplication::FileDropApplication(const WEnvironment& env)
22+
: WApplication(env)
23+
{
24+
setTitle("File Drop Example");
25+
26+
new WText("<h1>Try dropping a file in the widget below</h1>", root());
27+
28+
drop_ = new WFileDropWidget();
29+
root()->addWidget(drop_);
30+
31+
connectFileUpload();
32+
33+
log_ = new WText(root());
34+
}
35+
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);
42+
}
43+
44+
void FileDropApplication::saveFile()
45+
{
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;
57+
}
58+
59+
dest << src.rdbuf();
60+
61+
// Add a little block to the container-widget
62+
WContainerWidget *block = new WContainerWidget(drop_);
63+
block->setWidth(20);
64+
block->setHeight(20);
65+
block->setMargin(10);
66+
block->decorationStyle().setBackgroundColor(WColor("black"));
67+
}
68+
69+
70+
log_->setText("Thanks for the file(s)");
71+
72+
drop_->resetUpload();
73+
connectFileUpload();
74+
}
75+
76+
void FileDropApplication::fileTooBig()
77+
{
78+
log_->setText("The file is too big ...");
79+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// This may look like C code, but it's really -*- C++ -*-
2+
/*
3+
* Copyright (C) 2016 Emweb bvba, Herent, Belgium.
4+
*
5+
* See the LICENSE file for terms of use.
6+
*/
7+
8+
#ifndef FILEDROPAPPLICATION_H_
9+
#define FILEDROPAPPLICATION_H_
10+
11+
#include <Wt/WApplication>
12+
13+
using namespace Wt;
14+
15+
namespace Wt {
16+
class WFileDropWidget;
17+
}
18+
19+
class FileDropApplication : public WApplication
20+
{
21+
public:
22+
FileDropApplication(const WEnvironment& env);
23+
24+
private:
25+
WText *log_;
26+
WFileDropWidget *drop_;
27+
28+
void saveFile();
29+
void fileTooBig();
30+
void connectFileUpload();
31+
};
32+
33+
34+
#endif

examples/filedrop/filedrop.C

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
/*
2+
* Copyright (C) 2016 Emweb bvba, Herent, Belgium.
3+
*
4+
* See the LICENSE file for terms of use.
5+
*/
6+
#include "FileDropApplication.h"
7+
8+
using namespace Wt;
9+
10+
WApplication *createApplication(const WEnvironment& env)
11+
{
12+
return new FileDropApplication(env);
13+
}
14+
15+
int main(int argc, char **argv)
16+
{
17+
return WRun(argc, argv, &createApplication);
18+
}
19+

examples/filedrop/uploaded/README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
==== README file mainly to commit empty folder to git
2+
This folder contains all files uploaded through the filedrop widget

0 commit comments

Comments
 (0)