Improve startup code for WIP Qt Quick GUI
This commit is contained in:
parent
b356851617
commit
65c8797079
12
main.cpp
12
main.cpp
|
@ -43,6 +43,7 @@ int main(int argc, char *argv[])
|
|||
// Qt configuration arguments
|
||||
QT_CONFIG_ARGUMENTS qtConfigArgs;
|
||||
qtConfigArgs.qtWidgetsGuiArg().addSubArgument(&fileArg);
|
||||
qtConfigArgs.qtQuickGuiArg().addSubArgument(&fileArg);
|
||||
// cli argument
|
||||
Argument cliArg("interactive-cli", 'i', "starts the interactive command line interface");
|
||||
cliArg.setDenotesOperation(true);
|
||||
|
@ -60,17 +61,14 @@ int main(int argc, char *argv[])
|
|||
if (cliArg.isPresent()) {
|
||||
Cli::InteractiveCli cli;
|
||||
if (fileArg.isPresent()) {
|
||||
cli.run(fileArg.values().front());
|
||||
cli.run(fileArg.firstValue());
|
||||
} else {
|
||||
cli.run();
|
||||
}
|
||||
} else if (qtConfigArgs.areQtGuiArgsPresent()) {
|
||||
// run Qt gui if no arguments, --qt-gui or --qt-quick-gui specified, a file might be specified
|
||||
#if defined(PASSWORD_MANAGER_GUI_QTWIDGETS) || defined(PASSWORD_MANAGER_GUI_QTQUICK)
|
||||
QString file;
|
||||
if (fileArg.isPresent()) {
|
||||
file = QString::fromLocal8Bit(fileArg.values().front());
|
||||
}
|
||||
const auto file(fileArg.isPresent() ? QString::fromLocal8Bit(fileArg.firstValue()) : QString());
|
||||
#endif
|
||||
if (qtConfigArgs.qtWidgetsGuiArg().isPresent()) {
|
||||
#ifdef PASSWORD_MANAGER_GUI_QTWIDGETS
|
||||
|
@ -81,14 +79,14 @@ int main(int argc, char *argv[])
|
|||
#endif
|
||||
} else if (qtConfigArgs.qtQuickGuiArg().isPresent()) {
|
||||
#ifdef PASSWORD_MANAGER_GUI_QTQUICK
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs, file);
|
||||
#else
|
||||
CMD_UTILS_START_CONSOLE;
|
||||
cerr << "The application has not been built with Qt quick support." << endl;
|
||||
#endif
|
||||
} else {
|
||||
#if defined(PASSWORD_MANAGER_GUI_QTQUICK)
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs);
|
||||
res = QtGui::runQuickGui(argc, argv, qtConfigArgs, file);
|
||||
#elif defined(PASSWORD_MANAGER_GUI_QTWIDGETS)
|
||||
res = QtGui::runWidgetsGui(argc, argv, qtConfigArgs, file);
|
||||
#else
|
||||
|
|
|
@ -32,25 +32,46 @@ static QObject *applicationInfo(QQmlEngine *engine, QJSEngine *scriptEngine)
|
|||
return new ApplicationInfo();
|
||||
}
|
||||
|
||||
int runQuickGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs)
|
||||
int runQuickGui(int argc, char *argv[], const QtConfigArguments &qtConfigArgs, const QString &file)
|
||||
{
|
||||
// init application
|
||||
#ifdef __ANDROID__
|
||||
qputenv("QT_QUICK_CONTROLS_STYLE", "material");
|
||||
#endif
|
||||
SET_QT_APPLICATION_INFO;
|
||||
QGuiApplication::setAttribute(Qt::AA_EnableHighDpiScaling);
|
||||
#if defined(GUI_QTWIDGETS)
|
||||
QApplication a(argc, argv);
|
||||
#else
|
||||
QGuiApplication a(argc, argv);
|
||||
#endif
|
||||
|
||||
// apply settings specified via command line args
|
||||
qtConfigArgs.applySettings();
|
||||
LOAD_QT_TRANSLATIONS;
|
||||
|
||||
// load translations and enforce UTF-8 locale
|
||||
QTextCodec::setCodecForLocale(QTextCodec::codecForName("UTF-8"));
|
||||
// init quick GUI
|
||||
LOAD_QT_TRANSLATIONS;
|
||||
|
||||
// determine user paths
|
||||
const QVariantMap userPaths{
|
||||
{ QStringLiteral("desktop"), QStandardPaths::writableLocation(QStandardPaths::DesktopLocation) },
|
||||
{ QStringLiteral("documents"), QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation) },
|
||||
{ QStringLiteral("music"), QStandardPaths::writableLocation(QStandardPaths::MusicLocation) },
|
||||
{ QStringLiteral("movies"), QStandardPaths::writableLocation(QStandardPaths::MoviesLocation) },
|
||||
{ QStringLiteral("pictures"), QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) },
|
||||
{ QStringLiteral("home"), QStandardPaths::writableLocation(QStandardPaths::HomeLocation) },
|
||||
};
|
||||
|
||||
// init Quick GUI
|
||||
qmlRegisterSingletonType<QtGui::ApplicationInfo>("martchus.passwordmanager", 2, 0, "ApplicationInfo", applicationInfo);
|
||||
qmlRegisterType<QtGui::EntryFilterModel>("martchus.passwordmanager", 2, 0, "EntryFilterModel");
|
||||
qmlRegisterType<QtGui::EntryModel>("martchus.passwordmanager", 2, 0, "EntryModel");
|
||||
qmlRegisterType<QtGui::FieldModel>("martchus.passwordmanager", 2, 0, "FieldModel");
|
||||
QQmlApplicationEngine engine(QUrl("qrc:/qml/main.qml"));
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("userPaths"), userPaths);
|
||||
engine.rootContext()->setContextProperty(QStringLiteral("file"), file);
|
||||
|
||||
// start event loop
|
||||
int res = a.exec();
|
||||
return res;
|
||||
|
|
|
@ -11,7 +11,7 @@ class QtConfigArguments;
|
|||
|
||||
namespace QtGui {
|
||||
|
||||
int runQuickGui(int argc, char *argv[], const ApplicationUtilities::QtConfigArguments &qtConfigArgs);
|
||||
int runQuickGui(int argc, char *argv[], const ApplicationUtilities::QtConfigArguments &qtConfigArgs, const QString &file);
|
||||
}
|
||||
|
||||
#endif // QT_QUICK_GUI_INITIATE_H
|
||||
|
|
Loading…
Reference in New Issue