Changeset View
Standalone View
app/main.cpp
Show All 25 Lines | |||||
26 | #include "mainwindow.h" | 26 | #include "mainwindow.h" | ||
27 | #include "batchextract.h" | 27 | #include "batchextract.h" | ||
28 | #include "addtoarchive.h" | 28 | #include "addtoarchive.h" | ||
29 | 29 | | |||
30 | #include <QApplication> | 30 | #include <QApplication> | ||
31 | #include <QCommandLineParser> | 31 | #include <QCommandLineParser> | ||
32 | #include <QByteArray> | 32 | #include <QByteArray> | ||
33 | #include <QFileInfo> | 33 | #include <QFileInfo> | ||
34 | #ifdef Q_OS_MACOS | ||||
35 | #include <QFileOpenEvent> | ||||
36 | #endif | ||||
34 | 37 | | |||
35 | #include <KAboutData> | 38 | #include <KAboutData> | ||
36 | #include <KCrash> | 39 | #include <KCrash> | ||
37 | #include <KDBusService> | 40 | #include <KDBusService> | ||
38 | #include <Kdelibs4ConfigMigrator> | 41 | #include <Kdelibs4ConfigMigrator> | ||
39 | #include <KLocalizedString> | 42 | #include <KLocalizedString> | ||
40 | 43 | | |||
41 | using Kerfuffle::AddToArchive; | 44 | using Kerfuffle::AddToArchive; | ||
42 | 45 | | |||
46 | class OpenFileEventHandler : public QObject | ||||
47 | { | ||||
48 | Q_OBJECT | ||||
49 | public: | ||||
50 | OpenFileEventHandler(QApplication *parent, MainWindow *w) | ||||
51 | : QObject(parent) | ||||
52 | , m_window(w) | ||||
53 | { | ||||
54 | #ifdef Q_OS_MACOS | ||||
55 | parent->installEventFilter(this); | ||||
56 | #endif | ||||
57 | } | ||||
58 | | ||||
59 | bool eventFilter(QObject *obj, QEvent *event) override | ||||
60 | { | ||||
61 | #ifdef Q_OS_MACOS | ||||
62 | if (event->type() == QEvent::FileOpen) { | ||||
63 | QFileOpenEvent *openEvent = static_cast<QFileOpenEvent*>(event); | ||||
64 | qCDebug(ARK) << "File open event:" << openEvent->url() << "for window" << m_window; | ||||
65 | m_window->openUrl(openEvent->url()); | ||||
66 | return true; | ||||
67 | } | ||||
68 | #endif | ||||
69 | return QObject::eventFilter(obj, event); | ||||
70 | } | ||||
71 | private: | ||||
72 | MainWindow *m_window; | ||||
73 | }; | ||||
74 | | ||||
43 | int main(int argc, char **argv) | 75 | int main(int argc, char **argv) | ||
44 | { | 76 | { | ||
45 | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); // Required for the webengine part. | 77 | QCoreApplication::setAttribute(Qt::AA_ShareOpenGLContexts); // Required for the webengine part. | ||
46 | QApplication application(argc, argv); | 78 | QApplication application(argc, argv); | ||
47 | 79 | | |||
48 | /** | 80 | /** | ||
49 | * enable high dpi support | 81 | * enable high dpi support | ||
50 | */ | 82 | */ | ||
▲ Show 20 Lines • Show All 71 Lines • ▼ Show 20 Line(s) | 153 | aboutData.addCredit(i18n("Liam Smit"), | |||
122 | i18n("Ideas, help with the icons"), | 154 | i18n("Ideas, help with the icons"), | ||
123 | QStringLiteral("smitty@absamail.co.za")); | 155 | QStringLiteral("smitty@absamail.co.za")); | ||
124 | aboutData.addCredit(i18n("Andrew Smith"), | 156 | aboutData.addCredit(i18n("Andrew Smith"), | ||
125 | i18n("bkisofs code"), | 157 | i18n("bkisofs code"), | ||
126 | QString(), | 158 | QString(), | ||
127 | QStringLiteral("http://littlesvr.ca/misc/contactandrew.php")); | 159 | QStringLiteral("http://littlesvr.ca/misc/contactandrew.php")); | ||
128 | 160 | | |||
129 | KAboutData::setApplicationData(aboutData); | 161 | KAboutData::setApplicationData(aboutData); | ||
130 | application.setWindowIcon(QIcon::fromTheme(QStringLiteral("ark"))); | 162 | application.setWindowIcon(QIcon::fromTheme(QStringLiteral("ark"), application.windowIcon())); | ||
rjvbb: Specify the current application icon as the fallback for the lookup from theme. It will be… | |||||
131 | 163 | | |||
132 | QCommandLineParser parser; | 164 | QCommandLineParser parser; | ||
133 | parser.addHelpOption(); | 165 | parser.addHelpOption(); | ||
134 | parser.addVersionOption(); | 166 | parser.addVersionOption(); | ||
135 | 167 | | |||
136 | // Url to open. | 168 | // Url to open. | ||
137 | parser.addPositionalArgument(QStringLiteral("[urls]"), i18n("URLs to open.")); | 169 | parser.addPositionalArgument(QStringLiteral("[urls]"), i18n("URLs to open.")); | ||
138 | 170 | | |||
▲ Show 20 Lines • Show All 149 Lines • ▼ Show 20 Line(s) | 312 | } else { | |||
288 | if (!urls.isEmpty()) { | 320 | if (!urls.isEmpty()) { | ||
289 | qCDebug(ARK) << "Trying to open" << QUrl::fromUserInput(urls.at(0), QString(), QUrl::AssumeLocalFile); | 321 | qCDebug(ARK) << "Trying to open" << QUrl::fromUserInput(urls.at(0), QString(), QUrl::AssumeLocalFile); | ||
290 | 322 | | |||
291 | if (parser.isSet(QStringLiteral("dialog"))) { | 323 | if (parser.isSet(QStringLiteral("dialog"))) { | ||
292 | window->setShowExtractDialog(true); | 324 | window->setShowExtractDialog(true); | ||
293 | } | 325 | } | ||
294 | window->openUrl(QUrl::fromUserInput(urls.at(0), QString(), QUrl::AssumeLocalFile)); | 326 | window->openUrl(QUrl::fromUserInput(urls.at(0), QString(), QUrl::AssumeLocalFile)); | ||
295 | } | 327 | } | ||
328 | #ifdef Q_OS_MACOS | ||||
329 | volatile const OpenFileEventHandler *openFileEventHandler = new OpenFileEventHandler(&application, window); | ||||
330 | Q_UNUSED(openFileEventHandler); | ||||
While volatile? Also, couldn't we just use: new OpenFileEventHandler(&application, window); this way we don't need Q_UNUSED, no? elvisangelaccio: While `volatile`? Also, couldn't we just use:
```
new OpenFileEventHandler(&application… | |||||
One last thing and then it's good to go: unset this flag in the MainWindow constructor, since main.cpp is already quite crowded. elvisangelaccio: One last thing and then it's good to go: unset this flag in the MainWindow constructor, since… | |||||
331 | // we don't provide a fullscreen mode | ||||
elvisangelaccio: Please replace "we" with "MacOS" | |||||
332 | window->setWindowFlags(window->windowFlags() & ~Qt::WindowFullscreenButtonHint); | ||||
This removes the fullscreen button in the window titlebar. It is a bit cumbersome to exit the resulting fullscreen mode when there is no menu action of keyboard shortcut to accomplish this - which I think must be because there is little need for such a mode in an application like Ark. (Especially not knowing that the native Mac fullscreen mode can black out all other monitors on a multi-head setup.) The WindowFullscreenButtonHint flag is Mac-specific as far as I know and thus doesn't require an #ifdef. The QOpenFileEvent handler stuff doesn't need it either. rjvbb: This removes the fullscreen button in the window titlebar. It is a bit cumbersome to exit the… | |||||
elvisangelaccio: That's the only thing that really needs an ifdef, right? | |||||
333 | #endif | ||||
296 | window->show(); | 334 | window->show(); | ||
297 | } | 335 | } | ||
298 | } | 336 | } | ||
299 | 337 | | |||
300 | qCDebug(ARK) << "Entering application loop"; | 338 | qCDebug(ARK) << "Entering application loop"; | ||
301 | return application.exec(); | 339 | return application.exec(); | ||
302 | } | 340 | } | ||
341 | | ||||
342 | #ifdef Q_OS_MACOS | ||||
343 | #include "main.moc" | ||||
344 | #endif |
Specify the current application icon as the fallback for the lookup from theme. It will be empty like the default fallback when there is no embedded app icon and so doesn't change anything. Same thing on platforms where there is an embedded icon but no support for icon themes.