2
* Copyright (C) 2015 Canonical, Ltd.
4
* This program is free software; you can redistribute it and/or modify
5
* it under the terms of the GNU General Public License as published by
6
* the Free Software Foundation; version 3.
8
* This program is distributed in the hope that it will be useful,
9
* but WITHOUT ANY WARRANTY; without even the implied warranty of
10
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
* GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18
#include <QGuiApplication>
21
#include <QQmlContext>
24
QVariantMap parseAccountArg(QStringList args)
26
//syncmonitor:///authenticate?id=%1&service=%2
27
Q_FOREACH(const QString &arg, args) {
28
if (arg.startsWith("syncmonitor:///")) {
29
QUrl url = QUrl::fromPercentEncoding(arg.toUtf8());
30
QString methodName = url.path().right(url.path().length() -1);
31
if (methodName != "authenticate") {
35
//convert items to map
37
QList<QPair<QString, QString> > queryItemsPair = query.queryItems();
38
QMap<QString, QString> queryItems;
39
for(int i=0; i < queryItemsPair.count(); i++) {
40
QPair<QString, QString> item = queryItemsPair[i];
41
queryItems.insert(item.first, item.second);
44
if (queryItems.contains("id") && queryItems.contains("service")) {
46
info.insert("accountId", queryItems.value("id"));
47
info.insert("serviceName", queryItems.value("service"));
57
int main(int argc, char **argv)
59
QCoreApplication::setOrganizationName("Canonical");
60
QCoreApplication::setOrganizationDomain("canonical.com");
61
QCoreApplication::setApplicationName("Sync Monitor Helper");
63
QGuiApplication *app = new QGuiApplication(argc, argv);
64
QVariantMap accountInfo = parseAccountArg(app->arguments());
65
if (accountInfo.isEmpty()) {
66
qWarning() << "Usage: sync-monitor-helper syncmonitor:///authenticate?id=<accountId>&service=<serviceName";
71
QQuickView *view = new QQuickView;
72
app->connect(view->engine(), SIGNAL(quit()), SLOT(quit()));
74
view->setResizeMode(QQuickView::SizeRootObjectToView);
75
view->setTitle("Sync Monitor");
76
view->rootContext()->setContextProperty("ONLINE_ACCOUNT", accountInfo);
77
view->setSource(QUrl("qrc:/main.qml"));
79
qDebug() << accountInfo;
80
view->showMaximized();