File indexing completed on 2023-11-26 04:55:47

0001 /*
0002 * Copyright (C) 2011 Daniele E. Domenichelli <daniele.domenichelli@gmail.com>
0003 *
0004 * This library is free software; you can redistribute it and/or
0005 * modify it under the terms of the GNU Lesser General Public
0006 * License as published by the Free Software Foundation; either
0007 * version 2.1 of the License, or (at your option) any later version.
0008 *
0009 * This library is distributed in the hope that it will be useful,
0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of
0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0012 * Lesser General Public License for more details.
0013 *
0014 * You should have received a copy of the GNU Lesser General Public
0015 * License along with this library; if not, write to the Free Software
0016 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
0017 */
0018 
0019 #ifndef TELEPATHY_HANDLER_APPLICATION_H
0020 #define TELEPATHY_HANDLER_APPLICATION_H
0021 
0022 #include <QApplication>
0023 
0024 #include <KTp/ktpcommoninternals_export.h>
0025 
0026 namespace KTp
0027 {
0028 
0029 /**
0030  * \brief A KApplication that exits the application when there are no running jobs
0031  *
0032  * Morover it does automatically another few things required by every handler:
0033  * - It automatically register Telepathy-Qt Types
0034  * - setQuitOnLastWindowClosed(false)
0035  * - Adds the --persist option to inhibit automatic exit.
0036  * - Adds the --debug option to enable telepathy-qt4 debug
0037  * - Enables telepathy-qt4 warnings
0038  * - Use Tp-Qt4 callback for redirecting debug output into KDebug
0039  * - Sets the KDE_FULL_SESSION environment variable to workaround dbus activation issues.
0040  */
0041 class KTPCOMMONINTERNALS_EXPORT TelepathyHandlerApplication : public QApplication
0042 {
0043     Q_OBJECT
0044 
0045 public:
0046     /**
0047      * \p initialTimeout Initial timeout time (in msec) after which application exits if no jobs are received.
0048      * \p timeout Timeout time (in msec) after which application exits after the last job is finished.
0049      */
0050     explicit TelepathyHandlerApplication(int &argc, char *argv[],
0051                                          int initialTimeout = 15000,
0052                                          int timeout = 2000);
0053 
0054     ~TelepathyHandlerApplication() override;
0055 
0056     static int newJob();
0057     static void jobFinished();
0058 
0059 private:
0060     class Private;
0061     Private * const d;
0062 
0063     Q_PRIVATE_SLOT(d, void _k_onInitialTimeout())
0064     Q_PRIVATE_SLOT(d, void _k_onTimeout())
0065 };
0066 
0067 } // namespace KTp
0068 
0069 #endif // TELEPATHY_HANDLER_APPLICATION_H