File indexing completed on 2024-05-12 04:55:02

0001 /**
0002  * \file kid3qtapplication.cpp
0003  * QApplication subclass with adapted session management.
0004  *
0005  * \b Project: Kid3
0006  * \author Urs Fleisch
0007  * \date 5 Aug 2014
0008  *
0009  * Copyright (C) 2014-2018  Urs Fleisch
0010  *
0011  * This file is part of Kid3.
0012  *
0013  * Kid3 is free software; you can redistribute it and/or modify
0014  * it under the terms of the GNU General Public License as published by
0015  * the Free Software Foundation; either version 2 of the License, or
0016  * (at your option) any later version.
0017  *
0018  * Kid3 is distributed in the hope that it will be useful,
0019  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0020  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0021  * GNU General Public License for more details.
0022  *
0023  * You should have received a copy of the GNU General Public License
0024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0025  */
0026 
0027 #include "kid3qtapplication.h"
0028 #include <typeinfo>
0029 #include <QStringList>
0030 #ifdef Q_OS_MAC
0031 #include <QFileOpenEvent>
0032 #endif
0033 
0034 /**
0035  * Constructor.
0036  * @param argc number of arguments (including command)
0037  * @param argv arguments
0038  */
0039 Kid3QtApplication::Kid3QtApplication(int& argc, char** argv)
0040   : QApplication(argc, argv)
0041 {
0042 }
0043 
0044 /**
0045  * Called when session manager wants application to commit all its data.
0046  *
0047  * This method is reimplemented to avoid closing all top level widgets and
0048  * make restoring with the KDE window manager working.
0049  *
0050  * @param manager session manager
0051  */
0052 void Kid3QtApplication::commitData(QSessionManager& manager)
0053 {
0054   emit commitDataRequest(manager);
0055 }
0056 
0057 /**
0058  * Send event to receiver.
0059  * @param receiver receiver
0060  * @param event event
0061  * @return return value from receiver's event handler.
0062  */
0063 bool Kid3QtApplication::notify(QObject* receiver, QEvent* event)
0064 {
0065   try {
0066     return QApplication::notify(receiver, event);
0067   } catch (std::exception& ex) {
0068     qWarning("Exception %s (%s) was caught", typeid(ex).name(), ex.what());
0069   }
0070   return false;
0071 }
0072 
0073 /**
0074  * Handle file open events on Mac OS X.
0075  * @param e event
0076  * @return true if event handled.
0077  */
0078 bool Kid3QtApplication::event(QEvent* e)
0079 {
0080 #ifdef Q_OS_MAC
0081   if (e->type() == QEvent::FileOpen) {
0082     emit openFileRequested({static_cast<QFileOpenEvent*>(e)->file()});
0083     return true;
0084   }
0085 #endif
0086   return QApplication::event(e);
0087 }