diff --git a/sources/main.cpp b/sources/main.cpp index bf8363857..62e007abc 100644 --- a/sources/main.cpp +++ b/sources/main.cpp @@ -18,32 +18,7 @@ #include "qetapp.h" #include "singleapplication.h" #include "qet.h" -#include - -class MacOSXOpenEvent : public QObject -{ - Q_OBJECT - - public: - MacOSXOpenEvent(QObject *parent = nullptr) : - QObject(parent) - {} - - ~MacOSXOpenEvent(){} - - bool eventFilter(QObject *obj, QEvent *event) - { - if (event->type() == QEvent::FileOpen) - { - SingleApplication *app = dynamic_cast(obj); - QFileOpenEvent *open_event = static_cast(event); - QString message = "launched-with-args: " + open_event->file(); - app->sendMessage(message.toUtf8()); - return true; - } - return false; - } -}; +#include "macosxopenevent.h" /** * @brief main @@ -71,7 +46,7 @@ int main(int argc, char **argv) //Handle the opening of QET when user double click on a .qet .elmt .tbt file //or drop these same files to the QET icon of the dock MacOSXOpenEvent open_event; - app.installEventFilter(open_event); + app.installEventFilter(&open_event); #endif if (app.isSecondary()) diff --git a/sources/utils/macosxopenevent.cpp b/sources/utils/macosxopenevent.cpp new file mode 100644 index 000000000..757a7be52 --- /dev/null +++ b/sources/utils/macosxopenevent.cpp @@ -0,0 +1,37 @@ +/* + Copyright 2006-2019 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#include "macosxopenevent.h" +#include "singleapplication.h" +#include + +MacOSXOpenEvent::MacOSXOpenEvent(QObject *parent) : + QObject(parent) +{} + +bool MacOSXOpenEvent::eventFilter(QObject *watched, QEvent *event) +{ + if (event->type() == QEvent::FileOpen) + { + SingleApplication *app = dynamic_cast(watched); + QFileOpenEvent *open_event = static_cast(event); + QString message = "launched-with-args: " + open_event->file(); + app->sendMessage(message.toUtf8()); + return true; + } + return false; +} diff --git a/sources/utils/macosxopenevent.h b/sources/utils/macosxopenevent.h new file mode 100644 index 000000000..353fedb05 --- /dev/null +++ b/sources/utils/macosxopenevent.h @@ -0,0 +1,31 @@ +/* + Copyright 2006-2019 The QElectroTech Team + This file is part of QElectroTech. + + QElectroTech is free software: you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation, either version 2 of the License, or + (at your option) any later version. + + QElectroTech is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with QElectroTech. If not, see . +*/ +#ifndef MACOSXOPENEVENT_H +#define MACOSXOPENEVENT_H + +#include + +class MacOSXOpenEvent : public QObject +{ + Q_OBJECT + public: + explicit MacOSXOpenEvent(QObject *parent = nullptr); + bool eventFilter(QObject *watched, QEvent *event) override; +}; + +#endif // MACOSXOPENEVENT_H