File indexing completed on 2022-09-27 16:24:39

0001 /***************************************************************************
0002  *   Copyright (C) 2008-2011 by Daniel Nicoletti                           *
0003  *   dantti12@gmail.com                                                    *
0004  *                                                                         *
0005  *   This program is free software; you can redistribute it and/or modify  *
0006  *   it under the terms of the GNU General Public License as published by  *
0007  *   the Free Software Foundation; either version 2 of the License, or     *
0008  *   (at your option) any later version.                                   *
0009  *                                                                         *
0010  *   This program is distributed in the hope that it will be useful,       *
0011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
0012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
0013  *   GNU General Public License for more details.                          *
0014  *                                                                         *
0015  *   You should have received a copy of the GNU General Public License     *
0016  *   along with this program; see the file COPYING. If not, write to       *
0017  *   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,  *
0018  *   Boston, MA 02110-1301, USA.                                           *
0019  ***************************************************************************/
0020 
0021 #include "PkSession.h"
0022 
0023 #include "PkInterface.h"
0024 
0025 #include <QApplication>
0026 
0027 #include <KLocalizedString>
0028 
0029 #include <QLoggingCategory>
0030 
0031 #include <Daemon>
0032 
0033 #define MINUTE 60000
0034 
0035 Q_DECLARE_LOGGING_CATEGORY(APPER_SESSION)
0036 
0037 using namespace PackageKit;
0038 
0039 PkSession::PkSession(QObject* parent) : QObject(parent)
0040   , m_pkInterface(new PkInterface(this))
0041 {
0042     connect(m_pkInterface, &PkInterface::close, this, &PkSession::prepareToClose);
0043 
0044     Daemon::global()->setHints(QLatin1String("locale=") + QLocale::system().name() + QLatin1String(".UTF-8"));
0045 
0046     // this enables not quitting when closing a transaction ui
0047     qApp->setQuitOnLastWindowClosed(false);
0048 
0049     // create the close timer and connect it's signal
0050     m_closeT = new QTimer(this);
0051     connect(m_closeT, &QTimer::timeout, this, &PkSession::close);
0052 
0053     prepareToClose();
0054 }
0055 
0056 void PkSession::prepareToClose()
0057 {
0058     if (isRunning()) {
0059         qCDebug(APPER_SESSION) << "Stopping Timer";
0060         m_closeT->stop();
0061     } else {
0062         qCDebug(APPER_SESSION) << "Starting Timer: " << MINUTE;
0063         m_closeT->start(MINUTE);
0064     }
0065 }
0066 
0067 bool PkSession::isRunning()
0068 {
0069     if (m_pkInterface && m_pkInterface->isRunning()) {
0070         qCDebug(APPER_SESSION) << m_pkInterface;
0071         return true;
0072     }
0073 
0074     return false;
0075 }
0076 
0077 void PkSession::close()
0078 {
0079     // This will run when the timer times out, we will check
0080     // again just to be sure.
0081     if (!isRunning()) {
0082         qCDebug(APPER_SESSION) << "Closed by Timer";
0083         qApp->quit();
0084     }
0085 }
0086 
0087 int PkSession::newInstance()
0088 {
0089     return 0;
0090 }
0091 
0092 PkSession::~PkSession()
0093 {
0094 }
0095 
0096 #include "moc_PkSession.cpp"