2 // 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)
4 #include "bbwtFileUploader.h"
5 #include "bbwtPackage.h"
6 //#include <Wt/WFileUpload>
10 class FileUploaderWidget : public Wt::WContainerWidget
13 FileUploaderWidget(FileUploader* box,
14 Wt::WContainerWidget *parent,
19 ~FileUploaderWidget();
29 Wt::WPushButton *mwtPushButton;
30 Wt::WFileUpload *upload;
36 FileUploaderWidget::FileUploaderWidget(FileUploader* box,
37 Wt::WContainerWidget *parent,
43 Wt::WContainerWidget(parent),
51 Wt::WContainerWidget* w = this;
52 Wt::WVBoxLayout *vLay = new Wt::WVBoxLayout();
53 Wt::WVBoxLayout *vLay1 = new Wt::WVBoxLayout();
54 Wt::WHBoxLayout *hLay1 = new Wt::WHBoxLayout();
55 Wt::WContainerWidget* aux1 = new Wt::WContainerWidget();
56 Wt::WHBoxLayout *hLay2 = new Wt::WHBoxLayout();
57 Wt::WContainerWidget* aux2 = new Wt::WContainerWidget();
58 Wt::WContainerWidget* aux3 = new Wt::WContainerWidget();
59 upload = new Wt::WFileUpload(0);
60 upload->setFileTextSize(40);
62 Wt::WPushButton *uploadButton = new Wt::WPushButton("Upload", 0);
63 // Upload when the button is clicked.
64 uploadButton->clicked().connect(upload, &Wt::WFileUpload::upload);
65 //uploadButton->clicked().connect(uploadButton, &Wt::WPushButton::disable);
66 // Upload automatically when the user entered a file.
67 //upload->changed().connect(upload, &Wt::WFileUpload::upload);
68 //upload->changed().connect(uploadButton, &Wt::WPushButton::disable);
69 // React to a succesfull upload.
70 upload->uploaded().connect(this, &FileUploaderWidget::fileUploaded);
71 // React to a fileupload problem.
72 //upload->fileTooLarge().connect(this, &FileUploaderWidget::fileTooLarge);
74 vLay->addWidget(new Wt::WText("Upload your file"));
75 hLay1->addWidget(upload,1);
76 hLay1->addWidget(uploadButton,1);
77 aux1->setLayout(hLay1);
79 hLay2->addWidget(new Wt::WText("File Name"),1);
83 name = new Wt::WLineEdit();
84 name->setText(bbtk::std2wt(mName));
85 name->setReadOnly(!nameIn);
87 hLay2->addWidget(name,1);
89 aux2->setLayout(hLay2);
92 vLay1->addWidget(aux1,1);
93 vLay1->addWidget(aux2,1);
95 aux3->setLayout(vLay1);
96 vLay->addWidget(aux3);
99 w->setMaximumSize(350,150);
105 FileUploaderWidget::~FileUploaderWidget()
110 void FileUploaderWidget::fileUploaded()
112 std::cout<<"FILEUPLOAD----UPLOADING-----"<<std::endl;
113 std::string mFilename = upload->spoolFileName();
114 std::vector<Wt::Http::UploadedFile> mFileContents = upload->uploadedFiles();
115 upload->stealSpooledFile();
116 std::string mContents;
117 mContents=mFileContents.data()->spoolFileName();
118 std::ifstream src(mContents.c_str(), std::ios::binary);
120 if(bbtk::wt2std(name->text()) == "")
122 ppa=mPath + bbtk::wt2std(upload->clientFileName());
126 ppa = mPath + bbtk::wt2std(name->text());
129 std::ofstream dst(ppa.c_str(), std::ios::binary);
131 std::cout<<"FILEUPLOAD---------"<<ppa<<std::endl;
132 mBox->updatePath(ppa);
134 /* void fileTooLarge()
136 std::cout<<"ERROR ---- bbwtFileUploader : File size too large"<<std::endl;
139 BBTK_ADD_BLACK_BOX_TO_PACKAGE(wt,FileUploader)
140 BBTK_BLACK_BOX_IMPLEMENTATION(FileUploader,bbtk::WtBlackBox);
142 // 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)
144 void FileUploader::Process()
148 if (bbGetInputTitle()!="")
150 msg = bbGetInputTitle()+": " + bbGetInputIn();
154 msg = bbGetInputIn();
156 ((wxStaticText*)bbGetOutputWidget())->SetLabel( bbtk::std2wx( msg ) );
161 void FileUploader::updatePath(std::string sPath)
163 std::cout<<"DEBUG : ----- FileUpliader.cxx "<<std::endl<<"\t\t Nuevo Path : "<<sPath<<std::endl;
164 bbSetOutputOutPath(sPath);
167 // 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)
169 void FileUploader::CreateWidget(Wt::WContainerWidget* parent)
172 FileUploaderWidget *w = new FileUploaderWidget( this,
174 bbtk::std2wt(bbGetInputTitle()),
176 bbGetInputNameFile(),
180 bbSetOutputWidget(w);
184 // 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)
186 void FileUploader::bbUserSetDefaultValues()
189 //bbSetInputPath("");
190 //Testing by Johann Felipe Gonzalez Avila, Delete this line and replace it with the path of resources given in the bbtkWtBlackBox.cxx file in the inicialization of the app CreateWindow.
191 bbSetInputPath("/home/gonzalez/Documents/pruebaResources/");
192 bbSetInputInName(true);
193 bbSetInputNameFile("");
194 bbSetOutputOutPath("");
198 // 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)
200 void FileUploader::bbUserInitializeProcessing()
205 // 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)
207 void FileUploader::bbUserFinalizeProcessing()