2016-08-22 21:19:33 -04:00
|
|
|
/*
|
|
|
|
* RetroShare Android QML App
|
2017-03-17 12:22:58 -04:00
|
|
|
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org>
|
2016-08-22 21:19:33 -04:00
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Affero General Public License as
|
|
|
|
* published by the Free Software Foundation, either version 3 of the
|
|
|
|
* License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Affero General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Affero General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
#include <QtGlobal>
|
2016-08-22 21:19:33 -04:00
|
|
|
#include <QGuiApplication>
|
|
|
|
#include <QQmlApplicationEngine>
|
2016-09-04 09:01:44 -04:00
|
|
|
#include <QQmlContext>
|
|
|
|
#include <QQmlComponent>
|
2016-08-22 21:19:33 -04:00
|
|
|
#include <QDebug>
|
2017-04-18 17:14:44 -04:00
|
|
|
#include <QDir>
|
2017-04-19 17:46:30 -04:00
|
|
|
#include <QThread>
|
|
|
|
#include <QVariant>
|
2016-08-22 21:19:33 -04:00
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
#ifdef Q_OS_ANDROID
|
|
|
|
# include <QtAndroid>
|
|
|
|
# include <QtAndroidExtras/QAndroidJniObject>
|
|
|
|
# include <atomic>
|
2017-07-04 10:27:12 -04:00
|
|
|
# include "androidplatforminteracions.h"
|
|
|
|
#else
|
|
|
|
# include "defaultplatforminteracions.h"
|
2017-04-14 20:17:27 -04:00
|
|
|
#endif // Q_OS_ANDROID
|
|
|
|
|
2017-07-04 10:27:12 -04:00
|
|
|
|
2016-09-04 09:01:44 -04:00
|
|
|
#include "libresapilocalclient.h"
|
2017-04-14 20:17:27 -04:00
|
|
|
#include "rsqmlappengine.h"
|
2017-07-10 13:50:11 -04:00
|
|
|
#include "androidimagepicker.h"
|
2017-07-04 10:27:12 -04:00
|
|
|
#include "platforminteracions.h"
|
2016-08-22 21:19:33 -04:00
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2016-12-08 09:56:23 -05:00
|
|
|
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
|
|
|
QGuiApplication app(argc, argv);
|
2016-08-22 21:19:33 -04:00
|
|
|
|
2017-03-17 12:22:58 -04:00
|
|
|
/** When possible it is better to use +rsApi+ object directly instead of
|
|
|
|
* multiple instances of +LibresapiLocalClient+ in Qml */
|
2016-09-15 07:07:13 -04:00
|
|
|
qmlRegisterType<LibresapiLocalClient>(
|
|
|
|
"org.retroshare.qml_components.LibresapiLocalClient", 1, 0,
|
|
|
|
"LibresapiLocalClient");
|
2016-08-22 21:19:33 -04:00
|
|
|
|
2017-07-10 13:50:11 -04:00
|
|
|
|
2017-04-18 17:14:44 -04:00
|
|
|
QString sockPath = QDir::homePath() + "/.retroshare";
|
2016-12-08 09:56:23 -05:00
|
|
|
sockPath.append("/libresapi.sock");
|
|
|
|
|
|
|
|
LibresapiLocalClient rsApi;
|
|
|
|
rsApi.openConnection(sockPath);
|
2016-08-22 21:19:33 -04:00
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
RsQmlAppEngine engine(true);
|
|
|
|
QQmlContext& rootContext = *engine.rootContext();
|
|
|
|
|
2017-07-10 13:50:11 -04:00
|
|
|
qmlRegisterType<AndroidImagePicker>(
|
|
|
|
"org.retroshare.qml_components.AndroidImagePicker", 1, 0,
|
|
|
|
"AndroidImagePicker");
|
|
|
|
|
|
|
|
AndroidImagePicker androidImagePicker;
|
|
|
|
engine.rootContext()->setContextProperty("androidImagePicker",
|
|
|
|
&androidImagePicker);
|
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
QStringList mainArgs = app.arguments();
|
|
|
|
|
|
|
|
#ifdef Q_OS_ANDROID
|
2017-04-19 17:46:30 -04:00
|
|
|
rootContext.setContextProperty("Q_OS_ANDROID", QVariant(true));
|
2017-04-14 20:17:27 -04:00
|
|
|
|
2017-07-04 10:27:12 -04:00
|
|
|
AndroidPlatformInteracions platformGW(&app);
|
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
/* Add Activity Intent data to args, because onNewIntent is called only if
|
|
|
|
* the Intet was triggered when the Activity was already created, so only in
|
|
|
|
* case onCreate is not called.
|
|
|
|
* The solution exposed in http://stackoverflow.com/a/36942185 is not
|
|
|
|
* adaptable to our case, because when onCreate is called the RsQmlAppEngine
|
|
|
|
* is not ready yet.
|
|
|
|
*/
|
|
|
|
uint waitCount = 0;
|
|
|
|
std::atomic<bool> waitIntent(true);
|
|
|
|
QString uriStr;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
QtAndroid::runOnAndroidThread(
|
|
|
|
[&waitIntent, &uriStr]()
|
|
|
|
{
|
|
|
|
QAndroidJniObject activity = QtAndroid::androidActivity();
|
|
|
|
if(!activity.isValid())
|
|
|
|
{
|
|
|
|
qDebug() << "QtAndroid::runOnAndroidThread(...)"
|
|
|
|
<< "activity not ready yet";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAndroidJniObject intent = activity.callObjectMethod(
|
|
|
|
"getIntent", "()Landroid/content/Intent;");
|
|
|
|
if(!intent.isValid())
|
|
|
|
{
|
|
|
|
qDebug() << "QtAndroid::runOnAndroidThread(...)"
|
|
|
|
<< "intent not ready yet";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
QAndroidJniObject intentData = intent.callObjectMethod(
|
|
|
|
"getDataString", "()Ljava/lang/String;");
|
|
|
|
if(intentData.isValid()) uriStr = intentData.toString();
|
|
|
|
|
|
|
|
waitIntent = false;
|
|
|
|
});
|
|
|
|
|
|
|
|
if(waitIntent)
|
|
|
|
{
|
|
|
|
qWarning() << "uriStr not ready yet after waiting"
|
|
|
|
<< waitCount << "times";
|
|
|
|
app.processEvents();
|
|
|
|
++waitCount;
|
2017-04-19 17:46:30 -04:00
|
|
|
QThread::msleep(10);
|
2017-04-14 20:17:27 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
while (waitIntent);
|
|
|
|
|
|
|
|
qDebug() << "Got uriStr:" << uriStr;
|
|
|
|
|
|
|
|
if(!uriStr.isEmpty()) mainArgs.append(uriStr);
|
|
|
|
#else
|
2017-07-04 10:27:12 -04:00
|
|
|
DefaultPlatformInteracions platformGW(&app);
|
2017-04-19 17:46:30 -04:00
|
|
|
rootContext.setContextProperty("Q_OS_ANDROID", QVariant(false));
|
2017-04-14 20:17:27 -04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
rootContext.setContextProperty("mainArgs", mainArgs);
|
2017-07-04 10:27:12 -04:00
|
|
|
rootContext.setContextProperty("platformGW", &platformGW);
|
2017-04-11 07:11:57 -04:00
|
|
|
|
2017-04-03 15:07:33 -04:00
|
|
|
#ifdef QT_DEBUG
|
2017-04-19 17:46:30 -04:00
|
|
|
rootContext.setContextProperty("QT_DEBUG", QVariant(true));
|
2017-04-20 15:39:59 -04:00
|
|
|
rsApi.setDebug(false);
|
2017-04-03 15:07:33 -04:00
|
|
|
#else
|
2017-04-19 17:46:30 -04:00
|
|
|
rootContext.setContextProperty("QT_DEBUG", QVariant(false));
|
2017-04-03 15:07:33 -04:00
|
|
|
#endif // QT_DEBUG
|
|
|
|
|
2017-04-14 20:17:27 -04:00
|
|
|
rootContext.setContextProperty("apiSocketPath", sockPath);
|
|
|
|
rootContext.setContextProperty("rsApi", &rsApi);
|
|
|
|
engine.load(QUrl(QLatin1String("qrc:/main-app.qml")));
|
2016-08-22 21:19:33 -04:00
|
|
|
|
2016-12-08 09:56:23 -05:00
|
|
|
return app.exec();
|
2016-08-22 21:19:33 -04:00
|
|
|
}
|