X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=wt%2Fbbtk_wt_PKG%2Fsrc%2FbbwtFileUploader.cxx;fp=wt%2Fbbtk_wt_PKG%2Fsrc%2FbbwtFileUploader.cxx;h=96847c4e1c778b30e4ad9a2b24dc52a590d5e582;hb=aec464d8738507b9d26fc6915c7c063cab636dde;hp=0000000000000000000000000000000000000000;hpb=26116b2d4181a4ed3fffa07fbb75ef527d32d740;p=creaWT.git diff --git a/wt/bbtk_wt_PKG/src/bbwtFileUploader.cxx b/wt/bbtk_wt_PKG/src/bbwtFileUploader.cxx new file mode 100644 index 0000000..96847c4 --- /dev/null +++ b/wt/bbtk_wt_PKG/src/bbwtFileUploader.cxx @@ -0,0 +1,214 @@ +//===== +// Before editing this file, make sure it's a file of your own (i.e.: it wasn't generated from xml description; if so : your modifications will be lost) +//===== +#include "bbwtFileUploader.h" +#include "bbwtPackage.h" +//#include +namespace bbwt +{ + + class FileUploaderWidget : public Wt::WContainerWidget + { + public: + FileUploaderWidget(FileUploader* box, + Wt::WContainerWidget *parent, + Wt::WString label, + std::string pPath, + std::string fileName, + bool pNameIn); + ~FileUploaderWidget(); + void fileUploaded(); + void fileTooLarge(); + void mUpload(); + + + private: + FileUploader* mBox; + std::string mPath; + std::string mName; + Wt::WPushButton *mwtPushButton; + Wt::WFileUpload *upload; + bool nameIn; + Wt::WLineEdit *name; + + }; + + FileUploaderWidget::FileUploaderWidget(FileUploader* box, + Wt::WContainerWidget *parent, + Wt::WString label, + std::string pPath, + std::string fileName, + bool pNameIn) + : + Wt::WContainerWidget(parent), + mBox(box), + mPath(pPath), + mName(fileName), + nameIn(pNameIn) + { + + + Wt::WContainerWidget* w = this; + Wt::WVBoxLayout *vLay = new Wt::WVBoxLayout(); + Wt::WVBoxLayout *vLay1 = new Wt::WVBoxLayout(); + Wt::WHBoxLayout *hLay1 = new Wt::WHBoxLayout(); + Wt::WContainerWidget* aux1 = new Wt::WContainerWidget(); + Wt::WHBoxLayout *hLay2 = new Wt::WHBoxLayout(); + Wt::WContainerWidget* aux2 = new Wt::WContainerWidget(); + Wt::WContainerWidget* aux3 = new Wt::WContainerWidget(); + upload = new Wt::WFileUpload(0); + upload->setFileTextSize(40); + // Provide a button + Wt::WPushButton *uploadButton = new Wt::WPushButton("Upload", 0); + // Upload when the button is clicked. + uploadButton->clicked().connect(upload, &Wt::WFileUpload::upload); + //uploadButton->clicked().connect(uploadButton, &Wt::WPushButton::disable); + // Upload automatically when the user entered a file. + //upload->changed().connect(upload, &Wt::WFileUpload::upload); + //upload->changed().connect(uploadButton, &Wt::WPushButton::disable); + // React to a succesfull upload. + upload->uploaded().connect(this, &FileUploaderWidget::fileUploaded); + // React to a fileupload problem. + //upload->fileTooLarge().connect(this, &FileUploaderWidget::fileTooLarge); + + vLay->addWidget(new Wt::WText("Upload your file")); + hLay1->addWidget(upload,1); + hLay1->addWidget(uploadButton,1); + aux1->setLayout(hLay1); + + hLay2->addWidget(new Wt::WText("File Name"),1); + + + + name = new Wt::WLineEdit(); + name->setText(bbtk::std2wt(mName)); + name->setReadOnly(!nameIn); + + hLay2->addWidget(name,1); + + aux2->setLayout(hLay2); + + + vLay1->addWidget(aux1,1); + vLay1->addWidget(aux2,1); + + aux3->setLayout(vLay1); + vLay->addWidget(aux3); + + + w->setMaximumSize(350,150); + w->setLayout(vLay); + + + } + + FileUploaderWidget::~FileUploaderWidget() + { + + } + + void FileUploaderWidget::fileUploaded() + { + std::cout<<"FILEUPLOAD----UPLOADING-----"<spoolFileName(); + std::vector mFileContents = upload->uploadedFiles(); + upload->stealSpooledFile(); + std::string mContents; + mContents=mFileContents.data()->spoolFileName(); + std::ifstream src(mContents.c_str(), std::ios::binary); + std::string ppa; + if(bbtk::wt2std(name->text()) == "") + { + ppa=mPath + bbtk::wt2std(upload->clientFileName()); + } + else + { + ppa = mPath + bbtk::wt2std(name->text()); + + } + std::ofstream dst(ppa.c_str(), std::ios::binary); + dst << src.rdbuf(); + std::cout<<"FILEUPLOAD---------"<updatePath(ppa); + } + /* void fileTooLarge() + { + std::cout<<"ERROR ---- bbwtFileUploader : File size too large"<SetLabel( bbtk::std2wx( msg ) ); + */ +} +//===== + +void FileUploader::updatePath(std::string sPath) +{ + std::cout<<"DEBUG : ----- FileUpliader.cxx "<