The window needs a display, which kept the package manager out of a script and off a headless machine. The command line runs the same operations through AppCore, before any widget exists, so providers, the pacman lock, the journal and the history behave exactly as in the window. Refs #22.
101 lines
3.8 KiB
C++
101 lines
3.8 KiB
C++
#include <QApplication>
|
|
#include <QCoreApplication>
|
|
#include <QLoggingCategory>
|
|
#include <QStringList>
|
|
#include <QTimer>
|
|
|
|
#include "app-settings.h"
|
|
#include "cli-application.h"
|
|
#include "cli-command.h"
|
|
#include "language-manager.h"
|
|
#include "log-manager.h"
|
|
#include "main-window.h"
|
|
#include "update-manager.h"
|
|
|
|
namespace {
|
|
|
|
// The arguments as the command-line grammar wants them: program name excluded.
|
|
QStringList commandLineArguments(int argc, char* argv[]) {
|
|
QStringList arguments;
|
|
if (argc > 1) arguments.reserve(argc - 1);
|
|
for (int i = 1; i < argc; ++i) {
|
|
arguments << QString::fromLocal8Bit(argv[i]);
|
|
}
|
|
return arguments;
|
|
}
|
|
|
|
} // namespace
|
|
|
|
int main(int argc, char* argv[]) {
|
|
const QStringList arguments = commandLineArguments(argc, argv);
|
|
|
|
// The command line is decided before any widget exists: `pacmanager install
|
|
// vlc` has to work on a machine with no display, so it runs on a
|
|
// QCoreApplication and never builds the window.
|
|
if (cli::isCliInvocation(arguments)) {
|
|
QCoreApplication app(argc, argv);
|
|
app.setApplicationName("PacManager");
|
|
app.setApplicationVersion(UpdateManager::currentVersion());
|
|
app.setOrganizationName("Freebuff");
|
|
|
|
LogManager::installQtMessageHandler();
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("app"),
|
|
QCoreApplication::translate("main", "session démarrée (v%1)")
|
|
.arg(UpdateManager::currentVersion()));
|
|
|
|
const int code = cli::run(arguments);
|
|
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("app"),
|
|
QCoreApplication::translate("main", "session terminée (code %1)").arg(code));
|
|
return code;
|
|
}
|
|
|
|
QApplication app(argc, argv);
|
|
app.setApplicationName("PacManager");
|
|
app.setApplicationVersion(UpdateManager::currentVersion());
|
|
app.setOrganizationName("Freebuff");
|
|
// Before any widget exists: the palette is what the platform draws the
|
|
// parts the stylesheet cannot reach, such as the margin around a menu.
|
|
app.setPalette(MainWindow::appPalette());
|
|
|
|
// Every log category the app uses is enabled (qCDebug included) and funnelled
|
|
// into the journal, so the Logs screen shows the same detail as a debug run
|
|
// without the user having to set QT_LOGGING_RULES.
|
|
QLoggingCategory::setFilterRules(QStringLiteral("pacmgr.*=true"));
|
|
// The chosen catalogue goes in before anything is built, widget or journal
|
|
// line: the whole session, interface included, is then in one language
|
|
// rather than starting in French and switching halfway.
|
|
LanguageManager::apply(AppSettings::instance().language());
|
|
|
|
// The journal opens where the user asked it to, not where the previous
|
|
// release wrote it: AppSettings is read before the first line is written.
|
|
LogManager::installQtMessageHandler();
|
|
LogManager::instance().logEvent(
|
|
QStringLiteral("app"),
|
|
QCoreApplication::translate("main", "session démarrée (v%1)")
|
|
.arg(UpdateManager::currentVersion()));
|
|
|
|
MainWindow window;
|
|
window.setWindowTitle(QCoreApplication::translate("main", "PacManager - Gestionnaire de Paquets"));
|
|
window.resize(1200, 760);
|
|
window.setMinimumSize(960, 600);
|
|
window.show();
|
|
|
|
// Files the desktop handed over ("Ouvrir avec PacManager", the desktop
|
|
// entry declares %U): installed once the event loop runs, so the window is
|
|
// visible and any dialog has a parent.
|
|
if (!arguments.isEmpty()) {
|
|
QTimer::singleShot(0, &window, [&window, arguments] {
|
|
window.installLocalFiles(arguments);
|
|
});
|
|
}
|
|
|
|
const int code = app.exec();
|
|
|
|
LogManager::instance().logEvent(QStringLiteral("app"),
|
|
QCoreApplication::translate("main", "session terminée (code %1)").arg(code));
|
|
return code;
|
|
}
|