File indexing completed on 2024-12-22 05:17:15

0001 /*
0002  * This file is part of the KDE wacomtablet project. For copyright
0003  * information and license terms see the AUTHORS and COPYING files
0004  * in the top-level directory of this distribution.
0005  *
0006  * This program is free software; you can redistribute it and/or
0007  * modify it under the terms of the GNU General Public License as
0008  * published by the Free Software Foundation; either version 2 of
0009  * the License, or (at your option) any later version.
0010  *
0011  * This program is distributed in the hope that it will be useful,
0012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0014  * GNU General Public License for more details.
0015  *
0016  * You should have received a copy of the GNU General Public License
0017  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0018  */
0019 
0020 #include "mainconfig.h"
0021 
0022 #include <KConfigGroup>
0023 #include <KSharedConfig>
0024 
0025 using namespace Wacom;
0026 
0027 namespace Wacom
0028 {
0029 class MainConfigPrivate
0030 {
0031 public:
0032     KSharedConfig::Ptr config;
0033     KConfigGroup general;
0034 }; // CLASS
0035 } // NAMESPACE
0036 
0037 MainConfig::MainConfig()
0038     : d_ptr(new MainConfigPrivate)
0039 {
0040     open(QLatin1String("wacomtablet-kderc"));
0041 }
0042 
0043 MainConfig::MainConfig(const QString &fileName)
0044     : d_ptr(new MainConfigPrivate)
0045 {
0046     open(fileName);
0047 }
0048 
0049 MainConfig::~MainConfig()
0050 {
0051     Q_D(MainConfig);
0052     if (d->config) {
0053         d->config->sync();
0054     }
0055 
0056     delete this->d_ptr;
0057 }
0058 
0059 void MainConfig::open(const QString &fileName)
0060 {
0061     Q_D(MainConfig);
0062     d->config = KSharedConfig::openConfig(fileName);
0063     d->general = KConfigGroup(d->config, QStringLiteral("LastProfile"));
0064 }
0065 
0066 QString MainConfig::getLastProfile(const QString &deviceName)
0067 {
0068     Q_D(MainConfig);
0069     QString profile;
0070 
0071     if (d->config) {
0072         d->config->reparseConfiguration();
0073         profile = d->general.readEntry(deviceName);
0074     }
0075 
0076     return profile;
0077 }
0078 
0079 void MainConfig::setLastProfile(const QString &deviceName, const QString &profile)
0080 {
0081     Q_D(MainConfig);
0082     if (d->config) {
0083         d->config->reparseConfiguration();
0084         d->general.writeEntry(deviceName, profile);
0085         d->general.sync();
0086     }
0087 }