| 1 | // -*- c-basic-offset: 2 -*- |
|---|
| 2 | /* |
|---|
| 3 | * This file is part of Licq, an instant messaging client for UNIX. |
|---|
| 4 | * Copyright (C) 2007 Licq developers |
|---|
| 5 | * |
|---|
| 6 | * Licq is free software; you can redistribute it and/or modify |
|---|
| 7 | * it under the terms of the GNU General Public License as published by |
|---|
| 8 | * the Free Software Foundation; either version 2 of the License, or |
|---|
| 9 | * (at your option) any later version. |
|---|
| 10 | * |
|---|
| 11 | * Licq is distributed in the hope that it will be useful, |
|---|
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 14 | * GNU General Public License for more details. |
|---|
| 15 | * |
|---|
| 16 | * You should have received a copy of the GNU General Public License |
|---|
| 17 | * along with Licq; if not, write to the Free Software |
|---|
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
|---|
| 19 | */ |
|---|
| 20 | |
|---|
| 21 | #include "settingsdlg.h" |
|---|
| 22 | |
|---|
| 23 | #include "config.h" |
|---|
| 24 | |
|---|
| 25 | #include <QDialogButtonBox> |
|---|
| 26 | #include <QPushButton> |
|---|
| 27 | #include <QVBoxLayout> |
|---|
| 28 | |
|---|
| 29 | #include "core/licqgui.h" |
|---|
| 30 | #include "core/mainwin.h" |
|---|
| 31 | |
|---|
| 32 | #include "helpers/support.h" |
|---|
| 33 | |
|---|
| 34 | #include "widgets/treepager.h" |
|---|
| 35 | |
|---|
| 36 | #include "chat.h" |
|---|
| 37 | #include "contactlist.h" |
|---|
| 38 | #include "events.h" |
|---|
| 39 | #include "general.h" |
|---|
| 40 | #include "network.h" |
|---|
| 41 | #include "status.h" |
|---|
| 42 | |
|---|
| 43 | using namespace LicqQtGui; |
|---|
| 44 | /* TRANSLATOR LicqQtGui::SettingsDlg */ |
|---|
| 45 | |
|---|
| 46 | SettingsDlg* SettingsDlg::myInstance = NULL; |
|---|
| 47 | |
|---|
| 48 | void SettingsDlg::show(SettingsPage page) |
|---|
| 49 | { |
|---|
| 50 | if (myInstance == NULL) |
|---|
| 51 | myInstance = new SettingsDlg(gMainWindow); |
|---|
| 52 | |
|---|
| 53 | myInstance->showPage(page); |
|---|
| 54 | myInstance->raise(); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | SettingsDlg::SettingsDlg(QWidget* parent) |
|---|
| 58 | : QDialog(parent, Qt::WindowTitleHint | Qt::WindowSystemMenuHint) |
|---|
| 59 | { |
|---|
| 60 | Support::setWidgetProps(this, "SettingsDialog"); |
|---|
| 61 | setWindowTitle(tr("Licq Settings")); |
|---|
| 62 | setAttribute(Qt::WA_DeleteOnClose, true); |
|---|
| 63 | |
|---|
| 64 | QVBoxLayout* top_lay = new QVBoxLayout(this); |
|---|
| 65 | |
|---|
| 66 | myPager = new TreePager(this); |
|---|
| 67 | top_lay->addWidget(myPager); |
|---|
| 68 | |
|---|
| 69 | QDialogButtonBox* buttons = new QDialogButtonBox( |
|---|
| 70 | QDialogButtonBox::Ok | |
|---|
| 71 | QDialogButtonBox::Cancel | |
|---|
| 72 | QDialogButtonBox::Apply); |
|---|
| 73 | |
|---|
| 74 | connect(buttons, SIGNAL(accepted()), SLOT(ok())); |
|---|
| 75 | connect(buttons, SIGNAL(rejected()), SLOT(close())); |
|---|
| 76 | connect(buttons->button(QDialogButtonBox::Apply), |
|---|
| 77 | SIGNAL(clicked()), SLOT(apply())); |
|---|
| 78 | |
|---|
| 79 | top_lay->addWidget(buttons); |
|---|
| 80 | |
|---|
| 81 | myContactListSettings = new Settings::ContactList(this); |
|---|
| 82 | myGeneralSettings = new Settings::General(this); |
|---|
| 83 | myChatSettings = new Settings::Chat(this); |
|---|
| 84 | myEventsSettings = new Settings::Events(this); |
|---|
| 85 | myNetworkSettings = new Settings::Network(this); |
|---|
| 86 | myStatusSettings = new Settings::Status(this); |
|---|
| 87 | |
|---|
| 88 | QDialog::show(); |
|---|
| 89 | } |
|---|
| 90 | |
|---|
| 91 | SettingsDlg::~SettingsDlg() |
|---|
| 92 | { |
|---|
| 93 | myInstance = NULL; |
|---|
| 94 | } |
|---|
| 95 | |
|---|
| 96 | void SettingsDlg::addPage(SettingsPage page, QWidget* widget, QString title, SettingsPage parent) |
|---|
| 97 | { |
|---|
| 98 | myPages.insert(page, widget); |
|---|
| 99 | myPager->addPage(widget, title, (parent == UnknownPage ? NULL : myPages.value(parent))); |
|---|
| 100 | } |
|---|
| 101 | |
|---|
| 102 | void SettingsDlg::showPage(SettingsPage page) |
|---|
| 103 | { |
|---|
| 104 | if (myPages.contains(page)) |
|---|
| 105 | myPager->showPage(myPages.value(page)); |
|---|
| 106 | } |
|---|
| 107 | |
|---|
| 108 | void SettingsDlg::ok() |
|---|
| 109 | { |
|---|
| 110 | apply(); |
|---|
| 111 | LicqGui::instance()->saveConfig(); |
|---|
| 112 | close(); |
|---|
| 113 | } |
|---|
| 114 | |
|---|
| 115 | void SettingsDlg::apply() |
|---|
| 116 | { |
|---|
| 117 | myGeneralSettings->apply(); |
|---|
| 118 | myContactListSettings->apply(); |
|---|
| 119 | myChatSettings->apply(); |
|---|
| 120 | myEventsSettings->apply(); |
|---|
| 121 | myNetworkSettings->apply(); |
|---|
| 122 | myStatusSettings->apply(); |
|---|
| 123 | } |
|---|