mirror of
https://github.com/monero-project/monero-gui.git
synced 2024-11-17 08:17:59 +00:00
Merge pull request #1357
e1359ac
refactor platform dependant code400c385
add minimal cmdline parserffeecb6
move monero stuff after app constructor + cmdline parser1b07cda
move screen defs earlier in main function & fix width and height74233bf
force -platform xcb on linux59a4afe
consistency in if/else statements and MACROS
This commit is contained in:
commit
9f0d771f40
1 changed files with 64 additions and 49 deletions
113
main.cpp
113
main.cpp
|
@ -65,6 +65,11 @@
|
||||||
#include "QrCodeScanner.h"
|
#include "QrCodeScanner.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool isIOS = false;
|
||||||
|
bool isAndroid = false;
|
||||||
|
bool isWindows = false;
|
||||||
|
bool isDesktop = false;
|
||||||
|
|
||||||
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
void messageHandler(QtMsgType type, const QMessageLogContext &context, const QString &msg)
|
||||||
{
|
{
|
||||||
// Send all message types to logger
|
// 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[])
|
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
|
// // Enable high DPI scaling on windows & linux
|
||||||
//#if !defined(Q_OS_ANDROID) && QT_VERSION >= 0x050600
|
//#if !defined(Q_OS_ANDROID) && QT_VERSION >= 0x050600
|
||||||
// QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
// QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||||
// qDebug() << "High DPI auto scaling - enabled";
|
// qDebug() << "High DPI auto scaling - enabled";
|
||||||
//#endif
|
//#endif
|
||||||
|
|
||||||
// Log settings
|
|
||||||
Monero::Wallet::init(argv[0], "monero-wallet-gui");
|
|
||||||
// qInstallMessageHandler(messageHandler);
|
|
||||||
|
|
||||||
MainApp app(argc, argv);
|
MainApp app(argc, argv);
|
||||||
|
|
||||||
qDebug() << "app startd";
|
|
||||||
|
|
||||||
app.setApplicationName("monero-gui");
|
app.setApplicationName("monero-gui");
|
||||||
app.setOrganizationDomain("getmonero.org");
|
app.setOrganizationDomain("getmonero.org");
|
||||||
app.setOrganizationName("monero-project");
|
app.setOrganizationName("monero-project");
|
||||||
|
|
||||||
#if defined(Q_OS_LINUX) && !defined(Q_OS_ANDROID)
|
#if defined(Q_OS_LINUX)
|
||||||
app.setWindowIcon(QIcon(":/images/appicon.ico"));
|
if (isDesktop) app.setWindowIcon(QIcon(":/images/appicon.ico"));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
filter *eventFilter = new filter;
|
filter *eventFilter = new filter;
|
||||||
app.installEventFilter(eventFilter);
|
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
|
// registering types for QML
|
||||||
qmlRegisterType<clipboardAdapter>("moneroComponents.Clipboard", 1, 0, "Clipboard");
|
qmlRegisterType<clipboardAdapter>("moneroComponents.Clipboard", 1, 0, "Clipboard");
|
||||||
|
|
||||||
|
@ -169,7 +212,6 @@ int main(int argc, char *argv[])
|
||||||
engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance());
|
engine.rootContext()->setContextProperty("translationManager", TranslationManager::instance());
|
||||||
|
|
||||||
engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());
|
engine.addImageProvider(QLatin1String("qrcode"), new QRCodeImageProvider());
|
||||||
const QStringList arguments = QCoreApplication::arguments();
|
|
||||||
|
|
||||||
engine.rootContext()->setContextProperty("mainApp", &app);
|
engine.rootContext()->setContextProperty("mainApp", &app);
|
||||||
|
|
||||||
|
@ -177,6 +219,7 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// Exclude daemon manager from IOS
|
// Exclude daemon manager from IOS
|
||||||
#ifndef Q_OS_IOS
|
#ifndef Q_OS_IOS
|
||||||
|
const QStringList arguments = QCoreApplication::arguments();
|
||||||
DaemonManager * daemonManager = DaemonManager::instance(&arguments);
|
DaemonManager * daemonManager = DaemonManager::instance(&arguments);
|
||||||
engine.rootContext()->setContextProperty("daemonManager", daemonManager);
|
engine.rootContext()->setContextProperty("daemonManager", daemonManager);
|
||||||
#endif
|
#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
|
// 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
|
// backups - I reckon we save that in My Documents\Monero Accounts\ on
|
||||||
// Windows, ~/Monero Accounts/ on nix / osx
|
// Windows, ~/Monero Accounts/ on nix / osx
|
||||||
bool isWindows = false;
|
#if defined(Q_OS_WIN) || defined(Q_OS_IOS)
|
||||||
bool isIOS = false;
|
|
||||||
bool isMac = false;
|
|
||||||
bool isAndroid = false;
|
|
||||||
#ifdef Q_OS_WIN
|
|
||||||
isWindows = true;
|
|
||||||
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
||||||
#elif defined(Q_OS_IOS)
|
#else
|
||||||
isIOS = true;
|
|
||||||
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::DocumentsLocation);
|
|
||||||
#elif defined(Q_OS_UNIX)
|
|
||||||
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
QStringList moneroAccountsRootDir = QStandardPaths::standardLocations(QStandardPaths::HomeLocation);
|
||||||
#endif
|
#endif
|
||||||
#ifdef Q_OS_MAC
|
|
||||||
isMac = true;
|
|
||||||
#endif
|
|
||||||
#ifdef Q_OS_ANDROID
|
|
||||||
isAndroid = true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
engine.rootContext()->setContextProperty("isWindows", isWindows);
|
engine.rootContext()->setContextProperty("isWindows", isWindows);
|
||||||
engine.rootContext()->setContextProperty("isIOS", isIOS);
|
engine.rootContext()->setContextProperty("isIOS", isIOS);
|
||||||
engine.rootContext()->setContextProperty("isAndroid", isAndroid);
|
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("screenWidth", geo.width());
|
||||||
engine.rootContext()->setContextProperty("screenHeight", geo.height());
|
engine.rootContext()->setContextProperty("screenHeight", geo.height());
|
||||||
#ifdef Q_OS_ANDROID
|
#ifdef Q_OS_ANDROID
|
||||||
|
@ -229,11 +247,9 @@ int main(int argc, char *argv[])
|
||||||
engine.rootContext()->setContextProperty("scaleRatio", 1);
|
engine.rootContext()->setContextProperty("scaleRatio", 1);
|
||||||
#endif
|
#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";
|
QString moneroAccountsDir = moneroAccountsRootDir.at(0) + "/Monero/wallets";
|
||||||
engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsDir);
|
engine.rootContext()->setContextProperty("moneroAccountsDir", moneroAccountsDir);
|
||||||
}
|
}
|
||||||
|
@ -241,12 +257,10 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
// Get default account name
|
// Get default account name
|
||||||
QString accountName = qgetenv("USER"); // mac/linux
|
QString accountName = qgetenv("USER"); // mac/linux
|
||||||
if (accountName.isEmpty()){
|
if (accountName.isEmpty())
|
||||||
accountName = qgetenv("USERNAME"); // Windows
|
accountName = qgetenv("USERNAME"); // Windows
|
||||||
}
|
if (accountName.isEmpty())
|
||||||
if (accountName.isEmpty()) {
|
|
||||||
accountName = "My monero Account";
|
accountName = "My monero Account";
|
||||||
}
|
|
||||||
|
|
||||||
engine.rootContext()->setContextProperty("defaultAccountName", accountName);
|
engine.rootContext()->setContextProperty("defaultAccountName", accountName);
|
||||||
engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath());
|
engine.rootContext()->setContextProperty("applicationDirectory", QApplication::applicationDirPath());
|
||||||
|
@ -273,14 +287,15 @@ int main(int argc, char *argv[])
|
||||||
|
|
||||||
#ifdef WITH_SCANNER
|
#ifdef WITH_SCANNER
|
||||||
QObject *qmlCamera = rootObject->findChild<QObject*>("qrCameraQML");
|
QObject *qmlCamera = rootObject->findChild<QObject*>("qrCameraQML");
|
||||||
if( qmlCamera ){
|
if (qmlCamera)
|
||||||
|
{
|
||||||
qDebug() << "QrCodeScanner : object found";
|
qDebug() << "QrCodeScanner : object found";
|
||||||
QCamera *camera_ = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
|
QCamera *camera_ = qvariant_cast<QCamera*>(qmlCamera->property("mediaObject"));
|
||||||
QObject *qmlFinder = rootObject->findChild<QObject*>("QrFinder");
|
QObject *qmlFinder = rootObject->findChild<QObject*>("QrFinder");
|
||||||
qobject_cast<QrCodeScanner*>(qmlFinder)->setSource(camera_);
|
qobject_cast<QrCodeScanner*>(qmlFinder)->setSource(camera_);
|
||||||
} else {
|
|
||||||
qDebug() << "QrCodeScanner : something went wrong !";
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
qDebug() << "QrCodeScanner : something went wrong !";
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
QObject::connect(eventFilter, SIGNAL(sequencePressed(QVariant,QVariant)), rootObject, SLOT(sequencePressed(QVariant,QVariant)));
|
QObject::connect(eventFilter, SIGNAL(sequencePressed(QVariant,QVariant)), rootObject, SLOT(sequencePressed(QVariant,QVariant)));
|
||||||
|
|
Loading…
Reference in a new issue