1 /**
2  * \file kid3qtapplication.cpp
3  * QApplication subclass with adapted session management.
4  *
5  * \b Project: Kid3
6  * \author Urs Fleisch
7  * \date 5 Aug 2014
8  *
9  * Copyright (C) 2014-2018  Urs Fleisch
10  *
11  * This file is part of Kid3.
12  *
13  * Kid3 is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 2 of the License, or
16  * (at your option) any later version.
17  *
18  * Kid3 is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
25  */
26 
27 #include "kid3qtapplication.h"
28 #include <typeinfo>
29 #include <QStringList>
30 #ifdef Q_OS_MAC
31 #include <QFileOpenEvent>
32 #endif
33 
34 /**
35  * Constructor.
36  * @param argc number of arguments (including command)
37  * @param argv arguments
38  */
Kid3QtApplication(int & argc,char ** argv)39 Kid3QtApplication::Kid3QtApplication(int& argc, char** argv)
40   : QApplication(argc, argv)
41 {
42 }
43 
44 /**
45  * Called when session manager wants application to commit all its data.
46  *
47  * This method is reimplemented to avoid closing all top level widgets and
48  * make restoring with the KDE window manager working.
49  *
50  * @param manager session manager
51  */
commitData(QSessionManager & manager)52 void Kid3QtApplication::commitData(QSessionManager& manager)
53 {
54   emit commitDataRequest(manager);
55 }
56 
57 /**
58  * Send event to receiver.
59  * @param receiver receiver
60  * @param event event
61  * @return return value from receiver's event handler.
62  */
notify(QObject * receiver,QEvent * event)63 bool Kid3QtApplication::notify(QObject* receiver, QEvent* event)
64 {
65   try {
66     return QApplication::notify(receiver, event);
67   } catch (std::exception& ex) {
68     qWarning("Exception %s (%s) was caught", typeid(ex).name(), ex.what());
69   }
70   return false;
71 }
72 
73 /**
74  * Handle file open events on Mac OS X.
75  * @param e event
76  * @return true if event handled.
77  */
event(QEvent * e)78 bool Kid3QtApplication::event(QEvent* e)
79 {
80 #ifdef Q_OS_MAC
81   if (e->type() == QEvent::FileOpen) {
82     emit openFileRequested({static_cast<QFileOpenEvent*>(e)->file()});
83     return true;
84   }
85 #endif
86   return QApplication::event(e);
87 }
88