Thank you this examples, and the new WStreamResource class. However,
something is missing for me. I have attached a test source. Wim, please
correct it, because in this code handleRequest method has never been
reached...

Thanks
Gabor

> The documentation of WResource explains it with an example. Another
> example: the source code of WStreamResource.C (or WFileResource in
> older Wt).
> 
> Wim.
> 
> ------------------------------------------------------------------------------
> Simplify data backup and recovery for your virtual environment with vRanger. 
> Installation's a snap, and flexible recovery options mean your data is safe,
> secure and there when you need it. Data protection magic?
> Nope - It's vRanger. Get your free trial download today. 
> http://p.sf.net/sfu/quest-sfdev2dev
> _______________________________________________
> witty-interest mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/witty-interest

#include <fstream>
#include <stdio.h>
#include <Wt/WContainerWidget>
#include <Wt/WApplication>
#include <Wt/WText>
#include <Wt/WPushButton>
#include <Wt/WStreamResource>

using namespace Wt;
using namespace std;

class MyStreamResource : public Wt::WStreamResource {
	public:
		MyStreamResource(const std::string& fileName, Wt::WObject *parent = 0)
			: Wt::WStreamResource(parent),
			fileName_(fileName) {
				suggestFileName("data.txt");
		}

		~MyStreamResource() {
			beingDeleted();
		}

		void handleRequest(const Wt::Http::Request& request,
                     Wt::Http::Response& response) {
			std::ifstream r(fileName_.c_str(), std::ios::in | std::ios::binary);
			handleRequestPiecewise(request, response, r);
		}

	private:
		std::string fileName_;
};

class MyTest : public Wt::WContainerWidget {
	public:
		MyTest( WContainerWidget *parent = 0 ) : WContainerWidget(parent) {
			
		}

	void save() {
		MyStreamResource *res = new MyStreamResource("/tmp/test.txt");
		res->setChanged();
	}
};

class MyApplication : public WApplication {
	public:

		MyApplication(const WEnvironment& environment) : WApplication(environment) {
			WText *t = new WText("Push button to download data: ");
			WPushButton *b = new WPushButton("Download");
			MyTest *s = new MyTest();
			b->clicked().connect( s, &MyTest::save );
			root()->addWidget(t);
			root()->addWidget(b);
		}
};

WApplication *createApplication(const WEnvironment& env) {
	
	WApplication *app = new MyApplication(env);

	return app;
}

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

------------------------------------------------------------------------------
Simplify data backup and recovery for your virtual environment with vRanger. 
Installation's a snap, and flexible recovery options mean your data is safe,
secure and there when you need it. Data protection magic?
Nope - It's vRanger. Get your free trial download today. 
http://p.sf.net/sfu/quest-sfdev2dev
_______________________________________________
witty-interest mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/witty-interest

Reply via email to