mirror of
https://invent.kde.org/marcoa/a-la-karte.git
synced 2026-02-09 21:13:08 +00:00
Fix desktop import paths and add CLI import mode
This commit is contained in:
parent
245944fca9
commit
5f0978dd0e
2 changed files with 51 additions and 3 deletions
|
|
@ -40,7 +40,13 @@ QStringList DesktopImporter::getDesktopFilePaths() const
|
|||
// Add common system locations
|
||||
appDirs << QStringLiteral("/usr/share/applications");
|
||||
appDirs << QStringLiteral("/usr/local/share/applications");
|
||||
appDirs << expandPath(QStringLiteral("~/.local/share/applications"));
|
||||
|
||||
const QString xdgDataHome = qEnvironmentVariable("XDG_DATA_HOME");
|
||||
if (!xdgDataHome.isEmpty()) {
|
||||
appDirs << QDir(xdgDataHome).absoluteFilePath(QStringLiteral("applications"));
|
||||
} else {
|
||||
appDirs << expandPath(QStringLiteral("~/.local/share/applications"));
|
||||
}
|
||||
|
||||
// Flatpak export directories
|
||||
appDirs << expandPath(QStringLiteral("~/.local/share/flatpak/exports/share/applications"));
|
||||
|
|
|
|||
46
src/main.cpp
46
src/main.cpp
|
|
@ -8,6 +8,8 @@
|
|||
#include <QQmlApplicationEngine>
|
||||
#include <QQmlContext>
|
||||
#include <QQuickStyle>
|
||||
#include <QTextStream>
|
||||
#include <QTimer>
|
||||
|
||||
#include <KAboutData>
|
||||
#include <KCrash>
|
||||
|
|
@ -16,6 +18,7 @@
|
|||
#include <KLocalizedString>
|
||||
|
||||
#include "alakarte-version.h"
|
||||
#include "app.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
|
|
@ -47,15 +50,54 @@ int main(int argc, char *argv[])
|
|||
|
||||
QCommandLineParser parser;
|
||||
aboutData.setupCommandLine(&parser);
|
||||
|
||||
QCommandLineOption importAllAndExitOption(QStringLiteral("import-all-and-exit"), i18n("Import all enabled sources and exit"));
|
||||
QCommandLineOption importDesktopAndExitOption(QStringLiteral("import-desktop-and-exit"), i18n("Import desktop entries and exit"));
|
||||
QCommandLineOption startupAndExitOption(QStringLiteral("startup-and-exit"), i18n("Start without UI and exit after startup auto-import (if enabled)"));
|
||||
parser.addOption(importAllAndExitOption);
|
||||
parser.addOption(importDesktopAndExitOption);
|
||||
parser.addOption(startupAndExitOption);
|
||||
|
||||
parser.process(app);
|
||||
aboutData.processCommandLine(&parser);
|
||||
|
||||
KDBusService service(KDBusService::Unique);
|
||||
|
||||
if (qEnvironmentVariableIsEmpty("QT_QUICK_CONTROLS_STYLE")) {
|
||||
QQuickStyle::setStyle(QStringLiteral("org.kde.desktop"));
|
||||
}
|
||||
|
||||
if (parser.isSet(importAllAndExitOption) || parser.isSet(importDesktopAndExitOption) || parser.isSet(startupAndExitOption)) {
|
||||
App *alakarteApp = App::instance();
|
||||
|
||||
QObject::connect(alakarteApp, &App::importCompleted, &app, [&app](int count) {
|
||||
QTextStream(stdout) << count << Qt::endl;
|
||||
app.exit(0);
|
||||
});
|
||||
QObject::connect(alakarteApp, &App::importError, &app, [&app](const QString &error) {
|
||||
QTextStream(stderr) << error << Qt::endl;
|
||||
app.exit(1);
|
||||
});
|
||||
|
||||
if (parser.isSet(importAllAndExitOption)) {
|
||||
alakarteApp->importAllGames();
|
||||
} else if (parser.isSet(importDesktopAndExitOption)) {
|
||||
alakarteApp->importFromDesktop();
|
||||
} else {
|
||||
if (!alakarteApp->config() || !alakarteApp->config()->autoImportOnStartup()) {
|
||||
QTextStream(stdout) << 0 << Qt::endl;
|
||||
return 0;
|
||||
}
|
||||
|
||||
QTimer::singleShot(60000, &app, [&app]() {
|
||||
QTextStream(stderr) << QStringLiteral("Timed out waiting for auto-import") << Qt::endl;
|
||||
app.exit(2);
|
||||
});
|
||||
}
|
||||
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
KDBusService service(KDBusService::Unique);
|
||||
|
||||
QQmlApplicationEngine engine;
|
||||
|
||||
engine.rootContext()->setContextObject(new KLocalizedContext(&engine));
|
||||
|
|
|
|||
Loading…
Reference in a new issue