Merge pull request #1357

e1359ac refactor platform dependant code
400c385 add minimal cmdline parser
ffeecb6 move monero stuff after app constructor + cmdline parser
1b07cda move screen defs earlier in main function & fix width and height
74233bf force -platform xcb on linux
59a4afe consistency in if/else statements and MACROS
pull/2/head
luigi1111 6 years ago
commit 9f0d771f40
No known key found for this signature in database
GPG Key ID: F4ACA0183641E010

@ -65,6 +65,11 @@
#include "QrCodeScanner.h"
#endif
bool isIOS = false;
bool isAndroid = false;
bool isWindows = false;
bool isDesktop = false;
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
{
// Send all message types to logger
@ -73,32 +78,70 @@ void messageHandler(QtMsgType type, const QMessageLogContext &context, const QSt
int main(int argc, char *argv[])
{
Monero::Utils::onStartup();
// platform dependant settings
#if !defined(Q_OS_ANDROID) && !defined(Q_OS_IOS)
bool isDesktop = true;
#elif defined(Q_OS_ANDROID)
bool isAndroid = true;
#elif defined(Q_OS_IOS)
bool isIOS = true;
#endif
#ifdef Q_OS_WIN
bool isWindows = true;
#endif
// disable "QApplication: invalid style override passed" warning
if (isDesktop) putenv((char*)"QT_STYLE_OVERRIDE=fusion");
#ifdef Q_OS_LINUX
// force platform xcb
if (isDesktop) putenv((char*)"QT_QPA_PLATFORM=xcb");
#endif
// // Enable high DPI scaling on windows & linux
//#if !defined(Q_OS_ANDROID) && QT_VERSION >= 0x050600
// QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
// qDebug() << "High DPI auto scaling - enabled";
//#endif
// Log settings
Monero::Wallet::init(argv[0], "monero-wallet-gui");
// qInstallMessageHandler(messageHandler);
MainApp app(argc, argv);
qDebug() << "app startd";
app.setApplicationName("monero-gui");
app.setOrganizationDomain("getmonero.org");
app.setOrganizationName("monero-project");
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
app.setWindowIcon(QIcon(":/images/appicon.ico"));
#endif
#if defined(Q_OS_LINUX)
if (isDesktop) app.setWindowIcon(QIcon(":/images/appicon.ico"));
#endif
filter *eventFilter = new filter;
app.installEventFilter(eventFilter);
QCommandLineParser parser;
parser.addHelpOption();
parser.process(app);
Monero::Utils::onStartup();
// Log settings
Monero::Wallet::init(argv[0], "monero-wallet-gui");
// qInstallMessageHandler(messageHandler);
qDebug() << "app startd";
// screen settings
// Mobile is designed on 128dpi
qreal ref_dpi = 128;
QRect geo = QApplication::desktop()->availableGeometry();
QRect rect = QGuiApplication::primaryScreen()->geometry();
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
qreal physicalDpi = QGuiApplication::primaryScreen()->physicalDotsPerInch();
qreal calculated_ratio = physicalDpi/ref_dpi;
qWarning().nospace() << "Qt:" << QT_VERSION_STR << " | screen: " << rect.width()
<< "x" << rect.height() << " - dpi: " << dpi << " - ratio:"
<< calculated_ratio;
// registering types for QML
qmlRegisterType<clipboardAdapter>("moneroComponents.Clipboard", 1, 0, "Clipboard");
@ -169,7 +212,6 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance());
engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());
const QStringList arguments = QCoreApplication::arguments();
engine.rootContext()->setContextProperty("mainApp", &app);
@ -177,6 +219,7 @@ int main(int argc, char *argv[])
// Exclude daemon manager from IOS
#ifndef Q_OS_IOS
const QStringList arguments = QCoreApplication::arguments();
DaemonManager * daemonManager = DaemonManager::instance(&arguments);
engine.rootContext()->setContextProperty("daemonManager", daemonManager);
#endif
@ -186,41 +229,16 @@ int main(int argc, char *argv[])
// to save the wallet file (.keys, .bin), they have to be user-accessible for
// backups - I reckon we save that in My Documents\Monero Accounts\ on
// Windows, ~/Monero Accounts/ on nix / osx
bool isWindows = false;
bool isIOS = false;
bool isMac = false;
bool isAndroid = false;
#ifdef Q_OS_WIN
isWindows = true;
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
#elif defined(Q_OS_IOS)
isIOS = true;
#if defined(Q_OS_WIN) || defined(Q_OS_IOS)
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
#elif defined(Q_OS_UNIX)
#else
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
#endif
#ifdef Q_OS_MAC
isMac = true;
#endif
#ifdef Q_OS_ANDROID
isAndroid = true;
#endif
engine.rootContext()->setContextProperty("isWindows", isWindows);
engine.rootContext()->setContextProperty("isIOS", isIOS);
engine.rootContext()->setContextProperty("isAndroid", isAndroid);
// screen settings
// Mobile is designed on 128dpi
qreal ref_dpi = 128;
QRect geo = QApplication::desktop()->availableGeometry();
QRect rect = QGuiApplication::primaryScreen()->geometry();
qreal height = qMax(rect.width(), rect.height());
qreal width = qMin(rect.width(), rect.height());
qreal dpi = QGuiApplication::primaryScreen()->logicalDotsPerInch();
qreal physicalDpi = QGuiApplication::primaryScreen()->physicalDotsPerInch();
qreal calculated_ratio = physicalDpi/ref_dpi;
engine.rootContext()->setContextProperty("screenWidth", geo.width());
engine.rootContext()->setContextProperty("screenHeight", geo.height());
#ifdef Q_OS_ANDROID
@ -229,11 +247,9 @@ int main(int argc, char *argv[])
engine.rootContext()->setContextProperty("scaleRatio", 1);
#endif
qWarning().nospace() << "Qt:" << QT_VERSION_STR << " | screen: " << width
<< "x" << height << " - dpi: " << dpi << " - ratio:"
<< calculated_ratio;
if (!moneroAccountsRootDir.empty()) {
if (!moneroAccountsRootDir.empty())
{
QString moneroAccountsDir = moneroAccountsRootDir.at(0) + "/Monero/wallets";
engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsDir);
}
@ -241,12 +257,10 @@ int main(int argc, char *argv[])
// Get default account name
QString accountName = qgetenv("USER"); // mac/linux
if (accountName.isEmpty()){
if (accountName.isEmpty())
accountName = qgetenv("USERNAME"); // Windows
}
if (accountName.isEmpty()) {
if (accountName.isEmpty())
accountName = "My monero Account";
}
engine.rootContext()->setContextProperty("defaultAccountName", accountName);
engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath());
@ -273,14 +287,15 @@ int main(int argc, char *argv[])
#ifdef WITH_SCANNER
QObject *qmlCamera = rootObject->findChild<QObject*>("qrCameraQML");
if( qmlCamera ){
if (qmlCamera)
{
qDebug() << "QrCodeScanner : object found";
QCamera *camera_ = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
QObject *qmlFinder = rootObject->findChild<QObject*>("QrFinder");
qobject_cast<QrCodeScanner*>(qmlFinder)->setSource(camera_);
} else {
qDebug() << "QrCodeScanner : something went wrong !";
}
else
qDebug() << "QrCodeScanner : something went wrong !";
#endif
QObject::connect(eventFilter, SIGNAL(sequencePressed(QVariant,QVariant)), rootObject, SLOT(sequencePressed(QVariant,QVariant)));