summaryrefslogtreecommitdiff
path: root/controller.cxx
blob: e70a66da9c68ee460880a4dbc6a2725a152eadb7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <QtQml>
#include <qicclient/admin.hxx>
#include "controller.hxx"

extern "C" {
	void sign_up(char const*, char const*);
	struct icclient_catalog* catalog_data(char const*);
}

Controller::Controller(QObject* parent) :
	QObject{parent},
	catalog{nullptr}
{
#ifdef __ANDROID__
	QString cert{CA_BUNDLE};
	QString path{QDir{QStandardPaths::writableLocation(QStandardPaths::AppDataLocation)}.absolutePath()
		% cert.remove(0, cert.lastIndexOf("/"))};
	QFile{"assets:" % cert}.copy(path);
#endif
	interchange = new Client{SAMPLEURL, IMAGE_DIR
#ifdef __ANDROID__
		, path.toLatin1().constData()
#endif
	};
	auto engine = static_cast<QQmlApplicationEngine*>(parent);
	engine->load(QUrl{QStringLiteral("qrc:/main.qml")});
	auto window = engine->rootObjects()[0];
	window->setProperty("imageDir", SAMPLEURL"/images/");
	connect(window, SIGNAL(signUp(QString)), this, SIGNAL(signUp(QString)));
	connect(this, &Controller::signUp, [/*this,*/
#ifdef __ANDROID__
			path
#endif
			](QString const& brand) {
			sign_up(brand.toLatin1().constData(),
#ifdef __ANDROID__
					path.toLatin1().constData()
#else
					nullptr
#endif
			       );
//			interchange->catalog(brand);
	});
	connect(interchange, &Client::gotCatalog, [this,engine,window](QString const& response) {
		catalog = new Catalog{catalog_data(response.toLatin1().constData())};
		engine->rootContext()->setContextProperty("catalog", catalog);
		QMetaObject::invokeMethod(window, "pushCatalog");
	});
}

Controller::~Controller()
{
	if (catalog) delete catalog;
	delete interchange;
}