Use unique name for main

Qt Creator get confused if files with same name are present in the same
  project and when clickng on debug info open the same file, renaming
  main to avoid this
This commit is contained in:
Gioacchino Mazzurco 2017-04-17 00:13:21 +02:00
parent 987b5a1cdc
commit a1311c16c8
3 changed files with 1 additions and 1 deletions

View file

@ -1,131 +0,0 @@
/*
* RetroShare Android QML App
* Copyright (C) 2016-2017 Gioacchino Mazzurco <gio@eigenlab.org>
*
* 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/>.
*/
#include <QtGlobal>
#include <QGuiApplication>
#include <QQmlApplicationEngine>
#include <QQmlContext>
#include <QQmlComponent>
#include <QDebug>
#ifdef Q_OS_ANDROID
# include <QtAndroid>
# include <QtAndroidExtras/QAndroidJniObject>
# include <atomic>
#endif // Q_OS_ANDROID
#include "libresapilocalclient.h"
#include "retroshare/rsinit.h"
#include "rsqmlappengine.h"
int main(int argc, char *argv[])
{
QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
QGuiApplication app(argc, argv);
/** When possible it is better to use +rsApi+ object directly instead of
* multiple instances of +LibresapiLocalClient+ in Qml */
qmlRegisterType<LibresapiLocalClient>(
"org.retroshare.qml_components.LibresapiLocalClient", 1, 0,
"LibresapiLocalClient");
QString sockPath = QString::fromStdString(RsAccounts::ConfigDirectory());
sockPath.append("/libresapi.sock");
LibresapiLocalClient rsApi;
rsApi.openConnection(sockPath);
RsQmlAppEngine engine(true);
QQmlContext& rootContext = *engine.rootContext();
QStringList mainArgs = app.arguments();
#ifdef Q_OS_ANDROID
rootContext.setContextProperty("Q_OS_ANDROID", true);
/* 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;
usleep(10000);
}
}
while (waitIntent);
qDebug() << "Got uriStr:" << uriStr;
if(!uriStr.isEmpty()) mainArgs.append(uriStr);
#else
rootContext.setContextProperty("Q_OS_ANDROID", false);
#endif
rootContext.setContextProperty("mainArgs", mainArgs);
#ifdef QT_DEBUG
rootContext.setContextProperty("QT_DEBUG", true);
#else
rootContext.setContextProperty("QT_DEBUG", false);
#endif // QT_DEBUG
rootContext.setContextProperty("apiSocketPath", sockPath);
rootContext.setContextProperty("rsApi", &rsApi);
engine.load(QUrl(QLatin1String("qrc:/main-app.qml")));
return app.exec();
}