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

0001 /***************************************************************************
0002  *   Copyright (C) 2009-2018 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 "MainUi.h"
0022 
0023 #include <QLayout>
0024 #include <QLoggingCategory>
0025 
0026 #include <KConfig>
0027 #include <KConfigGroup>
0028 #include <QIcon>
0029 #include <QDialog>
0030 #include <KLocalizedString>
0031 
0032 #include "ApperKCM.h"
0033 
0034 Q_DECLARE_LOGGING_CATEGORY(APPER)
0035 
0036 MainUi::MainUi(QWidget *parent) :
0037     QMainWindow(parent),
0038     m_apperModule(nullptr)
0039 {
0040     setWindowIcon(QIcon::fromTheme(QLatin1String("system-software-install")));
0041     setWindowTitle(i18n("Apper"));
0042 
0043     KConfig config(QLatin1String("apper"));
0044     KConfigGroup configGroup(&config, "MainUi");
0045     restoreGeometry(configGroup.readEntry("geometry", QByteArray()));
0046     restoreState(configGroup.readEntry("state", QByteArray()));
0047 
0048     m_apperModule = new ApperKCM(this);
0049     setCentralWidget(m_apperModule);
0050     connect(m_apperModule, &ApperKCM::caption, this, &MainUi::setWindowTitle);
0051 }
0052 
0053 MainUi::~MainUi()
0054 {
0055 }
0056 
0057 void MainUi::showAll()
0058 {
0059     if (m_apperModule) {
0060         m_apperModule->setProperty("page", QLatin1String("home"));
0061     }
0062 }
0063 
0064 void MainUi::showUpdates()
0065 {
0066     if (m_apperModule) {
0067         m_apperModule->setProperty("page", QLatin1String("updates"));
0068     }
0069 }
0070 
0071 void MainUi::showSettings()
0072 {
0073     if (m_apperModule) {
0074         m_apperModule->setProperty("page", QLatin1String("settings"));
0075     }
0076 }
0077 
0078 void MainUi::closeEvent(QCloseEvent *event)
0079 {
0080     KConfig config(QLatin1String("apper"));
0081     KConfigGroup configGroup(&config, "MainUi");
0082     configGroup.writeEntry("geometry", saveGeometry());
0083     configGroup.writeEntry("state", saveState());
0084     QMainWindow::closeEvent(event);
0085 
0086     emit finished();
0087 }
0088 
0089 #include "moc_MainUi.cpp"