File indexing completed on 2024-04-28 04:44:18
0001 /* 0002 SnoreNotify is a Notification Framework based on Qt 0003 Copyright (C) 2015 Hannah von Reth <vonreth@kde.org> 0004 0005 SnoreNotify is free software: you can redistribute it and/or modify 0006 it under the terms of the GNU Lesser General Public License as published by 0007 the Free Software Foundation, either version 3 of the License, or 0008 (at your option) any later version. 0009 0010 SnoreNotify 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 Lesser General Public License for more details. 0014 0015 You should have received a copy of the GNU Lesser General Public License 0016 along with SnoreNotify. If not, see <http://www.gnu.org/licenses/>. 0017 */ 0018 #include "settingswindow.h" 0019 #include "ui_settingswindow.h" 0020 #include "settingsutils.h" 0021 0022 #include "snore.h" 0023 #include "snore_p.h" 0024 #include "settingsdialog.h" 0025 #include "utils.h" 0026 0027 #include <QApplication> 0028 #include <QDialogButtonBox> 0029 #include <QAbstractButton> 0030 0031 #include <iostream> 0032 0033 using namespace Snore; 0034 0035 SettingsWindow::SettingsWindow(const QString &appName, QWidget *parent) : 0036 QMainWindow(parent), 0037 ui(new Ui::SettingsWindow) 0038 { 0039 ui->setupUi(this); 0040 ui->widget->show(); 0041 0042 if (appName == QLatin1String("global")) { 0043 QStringList list = SettingsUtils::knownApps(); 0044 list.removeAll(qApp->applicationName()); 0045 ui->comboBox->addItems(list); 0046 } else { 0047 if (!SettingsUtils::knownApps().contains(appName)) { 0048 std::wcerr << "Error: " << appName.toUtf8().constData() << " is not known to Snorenotify" << std::endl; 0049 exit(1); 0050 } 0051 ui->comboBox->deleteLater(); 0052 ui->label->deleteLater(); 0053 SnoreCorePrivate::instance()->setLocalSttingsPrefix(appName); 0054 setWindowTitle(tr("%1 Settings").arg(appName)); 0055 ui->widget->initTabs(); 0056 ui->widget->setVisible(true); 0057 } 0058 } 0059 0060 SettingsWindow::~SettingsWindow() 0061 { 0062 delete ui; 0063 } 0064 0065 void SettingsWindow::on_comboBox_currentIndexChanged(const QString &arg1) 0066 { 0067 SnoreCorePrivate::instance()->setLocalSttingsPrefix(arg1); 0068 ui->widget->initTabs(); 0069 ui->widget->setVisible(true); 0070 } 0071 0072 void SettingsWindow::on_buttonBox_clicked(QAbstractButton *button) 0073 { 0074 switch (ui->buttonBox->buttonRole(button)) { 0075 case QDialogButtonBox::AcceptRole: 0076 ui->widget->accept(); 0077 qApp->processEvents(); 0078 qApp->quit(); 0079 break; 0080 case QDialogButtonBox::ApplyRole: 0081 ui->widget->accept(); 0082 break; 0083 case QDialogButtonBox::ResetRole: 0084 ui->widget->reset(); 0085 break; 0086 case QDialogButtonBox::RejectRole: 0087 qApp->quit(); 0088 break; 0089 default: 0090 qCWarning(SNORE) << "unhandled role" << button->text() << ui->buttonBox->buttonRole(button); 0091 } 0092 }