|
9 | 9 | #include <QApplication>
|
10 | 10 | #include <QFontDatabase>
|
11 | 11 |
|
| 12 | +void parseCommands(QApplication &app, QCommandLineParser &parser) |
| 13 | +{ |
| 14 | + parser.setApplicationDescription("Notes is a simple note-taking application."); |
| 15 | + parser.addHelpOption(); |
| 16 | + parser.addVersionOption(); |
| 17 | + parser.addOption(QCommandLineOption("count", "Count the number of notes")); |
| 18 | + parser.addOption(QCommandLineOption("trash-count", "Count the number of notes in the trash")); |
| 19 | + parser.addOption(QCommandLineOption("list-notes", "List all notes")); |
| 20 | + parser.process(app); |
| 21 | + |
| 22 | + if (parser.isSet("version")) { |
| 23 | + qDebug() << "Notes version: " << APP_VERSION; |
| 24 | + exit(EXIT_SUCCESS); |
| 25 | + } |
| 26 | + if (parser.isSet("count")) { |
| 27 | + throw std::runtime_error("Not implemented yet"); |
| 28 | + } |
| 29 | + if (parser.isSet("trash-count")) { |
| 30 | + throw std::runtime_error("Not implemented yet"); |
| 31 | + } |
| 32 | + if (parser.isSet("list-notes")) { |
| 33 | + throw std::runtime_error("Not implemented yet"); |
| 34 | + } |
| 35 | +} |
| 36 | + |
12 | 37 | int main(int argc, char *argv[])
|
13 | 38 | {
|
14 | 39 | QApplication app(argc, argv);
|
15 | 40 | // Set application information
|
16 |
| - app.setApplicationName("Notes"); |
17 |
| - app.setApplicationVersion(APP_VERSION); |
| 41 | + QApplication::setApplicationName("Notes"); |
| 42 | + QApplication::setApplicationVersion(APP_VERSION); |
18 | 43 |
|
19 | 44 | #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
|
20 |
| - app.setDesktopFileName(APP_ID); |
| 45 | + QApplication::setDesktopFileName(APP_ID); |
21 | 46 | #endif
|
22 | 47 |
|
| 48 | + // Parse command line arguments |
| 49 | + QCommandLineParser parser; |
| 50 | + parseCommands(app, parser); |
| 51 | + |
23 | 52 | if (QFontDatabase::addApplicationFont(":/fonts/fontawesome/fa-solid-900.ttf") < 0)
|
24 | 53 | qWarning() << "FontAwesome Solid cannot be loaded !";
|
25 | 54 |
|
@@ -100,5 +129,5 @@ int main(int argc, char *argv[])
|
100 | 129 | QObject::connect(&instance, &SingleInstance::newInstance, &w,
|
101 | 130 | [&]() { (&w)->setMainWindowVisibility(true); });
|
102 | 131 |
|
103 |
| - return app.exec(); |
| 132 | + return QApplication::exec(); |
104 | 133 | }
|
0 commit comments