| 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 "general.h" |
|---|
| 22 | |
|---|
| 23 | #include "config.h" |
|---|
| 24 | |
|---|
| 25 | #include <QCheckBox> |
|---|
| 26 | #include <QComboBox> |
|---|
| 27 | #include <QDir> |
|---|
| 28 | #include <QGridLayout> |
|---|
| 29 | #include <QGroupBox> |
|---|
| 30 | #include <QLabel> |
|---|
| 31 | #include <QRadioButton> |
|---|
| 32 | #include <QVBoxLayout> |
|---|
| 33 | |
|---|
| 34 | #include <licq_constants.h> |
|---|
| 35 | |
|---|
| 36 | #include "config/general.h" |
|---|
| 37 | #include "core/gui-defines.h" |
|---|
| 38 | #include "widgets/fontedit.h" |
|---|
| 39 | |
|---|
| 40 | #include "settingsdlg.h" |
|---|
| 41 | |
|---|
| 42 | using namespace LicqQtGui; |
|---|
| 43 | /* TRANSLATOR LicqQtGui::Settings::General */ |
|---|
| 44 | |
|---|
| 45 | Settings::General::General(SettingsDlg* parent) |
|---|
| 46 | : QObject(parent) |
|---|
| 47 | { |
|---|
| 48 | parent->addPage(SettingsDlg::DockingPage, createPageDocking(parent), |
|---|
| 49 | tr("Docking"), SettingsDlg::ContactListPage); |
|---|
| 50 | parent->addPage(SettingsDlg::FontsPage, createPageFonts(parent), |
|---|
| 51 | tr("Fonts"), SettingsDlg::ContactListPage); |
|---|
| 52 | |
|---|
| 53 | load(); |
|---|
| 54 | } |
|---|
| 55 | |
|---|
| 56 | QWidget* Settings::General::createPageDocking(QWidget* parent) |
|---|
| 57 | { |
|---|
| 58 | QWidget* w = new QWidget(parent); |
|---|
| 59 | QVBoxLayout* myPageDockingLayout = new QVBoxLayout(w); |
|---|
| 60 | myPageDockingLayout->setContentsMargins(0, 0, 0, 0); |
|---|
| 61 | |
|---|
| 62 | myDockingBox = new QGroupBox(tr("Docking")); |
|---|
| 63 | myDockingLayout = new QGridLayout(myDockingBox); |
|---|
| 64 | |
|---|
| 65 | myUseDockCheck = new QCheckBox(tr("Use dock icon"), myDockingBox); |
|---|
| 66 | myUseDockCheck->setToolTip(tr("Controls whether or not the dockable icon should be displayed.")); |
|---|
| 67 | myDockingLayout->addWidget(myUseDockCheck, 0, 0); |
|---|
| 68 | |
|---|
| 69 | myHiddenCheck = new QCheckBox(tr("Start hidden")); |
|---|
| 70 | myHiddenCheck->setToolTip(tr("Start main window hidden. Only the dock icon will be visible.")); |
|---|
| 71 | myDockingLayout->addWidget(myHiddenCheck, 0, 1); |
|---|
| 72 | |
|---|
| 73 | myDockDefaultRadio = new QRadioButton(tr("Default icon")); |
|---|
| 74 | myDockingLayout->addWidget(myDockDefaultRadio, 1, 0); |
|---|
| 75 | |
|---|
| 76 | myDockFortyEightCheck = new QCheckBox(tr("64 x 48 dock icon")); |
|---|
| 77 | myDockFortyEightCheck->setToolTip(tr("Selects between the standard 64x64 icon used in the WindowMaker/Afterstep wharf\n" |
|---|
| 78 | "and a shorter 64x48 icon for use in the Gnome/KDE panel.")); |
|---|
| 79 | myDockingLayout->addWidget(myDockFortyEightCheck, 1, 1); |
|---|
| 80 | |
|---|
| 81 | myDockThemedRadio = new QRadioButton(tr("Themed icon")); |
|---|
| 82 | myDockingLayout->addWidget(myDockThemedRadio, 2, 0); |
|---|
| 83 | |
|---|
| 84 | myDockTrayRadio = new QRadioButton(tr("Tray icon")); |
|---|
| 85 | myDockTrayRadio->setToolTip(tr("Uses the freedesktop.org standard to dock a small icon into the system tray.\n" |
|---|
| 86 | "Works with many different window managers.")); |
|---|
| 87 | myDockingLayout->addWidget(myDockTrayRadio, 3, 0); |
|---|
| 88 | |
|---|
| 89 | myDockTrayBlinkCheck = new QCheckBox(tr("Blink on events")); |
|---|
| 90 | myDockTrayBlinkCheck->setToolTip(tr("Make tray icon blink on unread incoming events.")); |
|---|
| 91 | myDockingLayout->addWidget(myDockTrayBlinkCheck, 3, 1); |
|---|
| 92 | |
|---|
| 93 | // TODO: Move this to Event pages when we get different kinds of popup |
|---|
| 94 | myTrayMsgOnlineNotify = new QCheckBox(tr("Show popup for Online notify")); |
|---|
| 95 | myTrayMsgOnlineNotify->setToolTip(tr("Show balloon popup message when contacts marked for online notify comes online.")); |
|---|
| 96 | myDockingLayout->addWidget(myTrayMsgOnlineNotify, 4, 1); |
|---|
| 97 | |
|---|
| 98 | myDockThemeCombo = new QComboBox(); |
|---|
| 99 | // Set the currently available themes |
|---|
| 100 | QString szDockThemesDir = QString::fromLocal8Bit(SHARE_DIR) + QTGUI_DIR + DOCK_DIR; |
|---|
| 101 | QDir d(szDockThemesDir); |
|---|
| 102 | d.setFilter(QDir::Dirs | QDir::NoDotAndDotDot); |
|---|
| 103 | myDockThemeCombo->addItems(d.entryList()); |
|---|
| 104 | connect(myDockDefaultRadio, SIGNAL(toggled(bool)), myDockFortyEightCheck, SLOT(setEnabled(bool))); |
|---|
| 105 | connect(myDockThemedRadio, SIGNAL(toggled(bool)), myDockThemeCombo, SLOT(setEnabled(bool))); |
|---|
| 106 | connect(myDockTrayRadio, SIGNAL(toggled(bool)), myDockTrayBlinkCheck, SLOT(setEnabled(bool))); |
|---|
| 107 | connect(myDockTrayRadio, SIGNAL(toggled(bool)), myTrayMsgOnlineNotify, SLOT(setEnabled(bool))); |
|---|
| 108 | connect(myUseDockCheck, SIGNAL(toggled(bool)), SLOT(useDockToggled(bool))); |
|---|
| 109 | myDockingLayout->addWidget(myDockThemeCombo, 2, 1); |
|---|
| 110 | |
|---|
| 111 | |
|---|
| 112 | myPageDockingLayout->addWidget(myDockingBox); |
|---|
| 113 | myPageDockingLayout->addStretch(1); |
|---|
| 114 | |
|---|
| 115 | return w; |
|---|
| 116 | } |
|---|
| 117 | |
|---|
| 118 | QWidget* Settings::General::createPageFonts(QWidget* parent) |
|---|
| 119 | { |
|---|
| 120 | QWidget* w = new QWidget(parent); |
|---|
| 121 | myPageFontsLayout = new QVBoxLayout(w); |
|---|
| 122 | myPageFontsLayout->setContentsMargins(0, 0, 0, 0); |
|---|
| 123 | |
|---|
| 124 | myFontBox = new QGroupBox(tr("Fonts")); |
|---|
| 125 | myFontLayout = new QGridLayout(myFontBox); |
|---|
| 126 | |
|---|
| 127 | // Standard font |
|---|
| 128 | myFontLabel = new QLabel(tr("General:")); |
|---|
| 129 | myFontLabel->setToolTip(tr("Used for normal text.")); |
|---|
| 130 | myFontLayout->addWidget(myFontLabel, 0, 0); |
|---|
| 131 | myNormalFontEdit = new FontEdit(); |
|---|
| 132 | myNormalFontEdit->setToolTip(myFontLabel->toolTip()); |
|---|
| 133 | myFontLabel->setBuddy(myNormalFontEdit); |
|---|
| 134 | myFontLayout->addWidget(myNormalFontEdit, 0, 1); |
|---|
| 135 | connect(myNormalFontEdit, SIGNAL(fontSelected(const QFont&)), SLOT(normalFontChanged(const QFont&))); |
|---|
| 136 | |
|---|
| 137 | // Edit font |
|---|
| 138 | myEditFontLabel = new QLabel(tr("Editing:")); |
|---|
| 139 | myEditFontLabel->setToolTip(tr("Used in message editor etc.")); |
|---|
| 140 | myFontLayout->addWidget(myEditFontLabel, 1, 0); |
|---|
| 141 | myEditFontEdit = new FontEdit(); |
|---|
| 142 | myEditFontEdit->setToolTip(myEditFontLabel->toolTip()); |
|---|
| 143 | myEditFontLabel->setBuddy(myEditFontEdit); |
|---|
| 144 | myFontLayout->addWidget(myEditFontEdit, 1, 1); |
|---|
| 145 | |
|---|
| 146 | // History font |
|---|
| 147 | myHistoryFontLabel = new QLabel(tr("History:")); |
|---|
| 148 | myHistoryFontLabel->setToolTip(tr("Used in message history.")); |
|---|
| 149 | myFontLayout->addWidget(myHistoryFontLabel, 2, 0); |
|---|
| 150 | myHistoryFontEdit = new FontEdit(); |
|---|
| 151 | myHistoryFontEdit->setToolTip(myHistoryFontLabel->toolTip()); |
|---|
| 152 | myHistoryFontLabel->setBuddy(myHistoryFontEdit); |
|---|
| 153 | myFontLayout->addWidget(myHistoryFontEdit, 2, 1); |
|---|
| 154 | |
|---|
| 155 | // Fixed font |
|---|
| 156 | myFixedFontLabel = new QLabel(tr("Fixed:")); |
|---|
| 157 | myFixedFontLabel->setToolTip(tr("Used in file editor and network log.")); |
|---|
| 158 | myFontLayout->addWidget(myFixedFontLabel, 3, 0); |
|---|
| 159 | myFixedFontEdit = new FontEdit(); |
|---|
| 160 | myFixedFontEdit->setToolTip(myFixedFontLabel->toolTip()); |
|---|
| 161 | myFixedFontLabel->setBuddy(myFixedFontEdit); |
|---|
| 162 | myFontLayout->addWidget(myFixedFontEdit, 3, 1); |
|---|
| 163 | |
|---|
| 164 | myPageFontsLayout->addWidget(myFontBox); |
|---|
| 165 | myPageFontsLayout->addStretch(1); |
|---|
| 166 | |
|---|
| 167 | return w; |
|---|
| 168 | } |
|---|
| 169 | |
|---|
| 170 | void Settings::General::useDockToggled(bool useDock) |
|---|
| 171 | { |
|---|
| 172 | if (!useDock) |
|---|
| 173 | { |
|---|
| 174 | #ifndef USE_KDE |
|---|
| 175 | myDockThemeCombo->setEnabled(false); |
|---|
| 176 | myDockDefaultRadio->setEnabled(false); |
|---|
| 177 | myDockThemedRadio->setEnabled(false); |
|---|
| 178 | myDockTrayRadio->setEnabled(false); |
|---|
| 179 | myDockFortyEightCheck->setEnabled(false); |
|---|
| 180 | myDockTrayBlinkCheck->setEnabled(false); |
|---|
| 181 | myTrayMsgOnlineNotify->setEnabled(false); |
|---|
| 182 | #endif |
|---|
| 183 | myHiddenCheck->setEnabled(false); |
|---|
| 184 | myHiddenCheck->setChecked(false); |
|---|
| 185 | return; |
|---|
| 186 | } |
|---|
| 187 | else |
|---|
| 188 | { |
|---|
| 189 | myHiddenCheck->setEnabled(true); |
|---|
| 190 | } |
|---|
| 191 | |
|---|
| 192 | // Turned on |
|---|
| 193 | #ifndef USE_KDE |
|---|
| 194 | myDockDefaultRadio->setEnabled(true); |
|---|
| 195 | myDockThemedRadio->setEnabled(true); |
|---|
| 196 | myDockTrayRadio->setEnabled(true); |
|---|
| 197 | if (myDockDefaultRadio->isChecked()) |
|---|
| 198 | { |
|---|
| 199 | myDockFortyEightCheck->setEnabled(true); |
|---|
| 200 | myDockThemeCombo->setEnabled(false); |
|---|
| 201 | myDockTrayBlinkCheck->setEnabled(false); |
|---|
| 202 | myTrayMsgOnlineNotify->setEnabled(false); |
|---|
| 203 | } |
|---|
| 204 | else if (myDockThemedRadio->isChecked()) |
|---|
| 205 | { |
|---|
| 206 | myDockFortyEightCheck->setEnabled(false); |
|---|
| 207 | myDockThemeCombo->setEnabled(true); |
|---|
| 208 | myDockTrayBlinkCheck->setEnabled(false); |
|---|
| 209 | myTrayMsgOnlineNotify->setEnabled(false); |
|---|
| 210 | } |
|---|
| 211 | else if (myDockTrayRadio->isChecked()) |
|---|
| 212 | { |
|---|
| 213 | myDockFortyEightCheck->setEnabled(false); |
|---|
| 214 | myDockThemeCombo->setEnabled(false); |
|---|
| 215 | myDockTrayBlinkCheck->setEnabled(true); |
|---|
| 216 | myTrayMsgOnlineNotify->setEnabled(true); |
|---|
| 217 | } |
|---|
| 218 | else |
|---|
| 219 | myDockDefaultRadio->setChecked(true); |
|---|
| 220 | #endif |
|---|
| 221 | } |
|---|
| 222 | |
|---|
| 223 | void Settings::General::normalFontChanged(const QFont& font) |
|---|
| 224 | { |
|---|
| 225 | myEditFontEdit->setFont(font); |
|---|
| 226 | myHistoryFontEdit->setFont(font); |
|---|
| 227 | } |
|---|
| 228 | |
|---|
| 229 | void Settings::General::load() |
|---|
| 230 | { |
|---|
| 231 | Config::General* generalConfig = Config::General::instance(); |
|---|
| 232 | |
|---|
| 233 | myHiddenCheck->setChecked(generalConfig->mainwinStartHidden()); |
|---|
| 234 | myUseDockCheck->setChecked(generalConfig->dockMode() != Config::General::DockNone); |
|---|
| 235 | #ifndef USE_KDE |
|---|
| 236 | myDockDefaultRadio->setChecked(generalConfig->dockMode() == Config::General::DockDefault); |
|---|
| 237 | myDockFortyEightCheck->setChecked(generalConfig->defaultIconFortyEight()); |
|---|
| 238 | myDockThemedRadio->setChecked(generalConfig->dockMode() == Config::General::DockThemed); |
|---|
| 239 | for (unsigned short i = 0; i < myDockThemeCombo->count(); ++i) |
|---|
| 240 | { |
|---|
| 241 | if (myDockThemeCombo->itemText(i) == generalConfig->themedIconTheme()) |
|---|
| 242 | { |
|---|
| 243 | myDockThemeCombo->setCurrentIndex(i); |
|---|
| 244 | break; |
|---|
| 245 | } |
|---|
| 246 | } |
|---|
| 247 | #endif |
|---|
| 248 | myDockTrayRadio->setChecked(generalConfig->dockMode() == Config::General::DockTray); |
|---|
| 249 | myDockTrayBlinkCheck->setChecked(generalConfig->trayBlink()); |
|---|
| 250 | myTrayMsgOnlineNotify->setChecked(generalConfig->trayMsgOnlineNotify()); |
|---|
| 251 | useDockToggled(myUseDockCheck->isChecked()); |
|---|
| 252 | |
|---|
| 253 | myNormalFontEdit->setFont(QFont(generalConfig->normalFont())); |
|---|
| 254 | myEditFontEdit->setFont(QFont(generalConfig->editFont())); |
|---|
| 255 | myHistoryFontEdit->setFont(QFont(generalConfig->historyFont())); |
|---|
| 256 | myFixedFontEdit->setFont(QFont(generalConfig->fixedFont())); |
|---|
| 257 | } |
|---|
| 258 | |
|---|
| 259 | void Settings::General::apply() |
|---|
| 260 | { |
|---|
| 261 | Config::General* generalConfig = Config::General::instance(); |
|---|
| 262 | generalConfig->blockUpdates(true); |
|---|
| 263 | |
|---|
| 264 | generalConfig->setMainwinStartHidden(myHiddenCheck->isChecked()); |
|---|
| 265 | Config::General::DockMode newDockMode = Config::General::DockNone; |
|---|
| 266 | if (myUseDockCheck->isChecked()) |
|---|
| 267 | { |
|---|
| 268 | #ifdef USE_KDE |
|---|
| 269 | newDockMode = Config::General::DockTray; |
|---|
| 270 | #else |
|---|
| 271 | if (myDockDefaultRadio->isChecked()) |
|---|
| 272 | newDockMode = Config::General::DockDefault; |
|---|
| 273 | else if (myDockThemedRadio->isChecked()) |
|---|
| 274 | newDockMode = Config::General::DockThemed; |
|---|
| 275 | else if (myDockTrayRadio->isChecked()) |
|---|
| 276 | newDockMode = Config::General::DockTray; |
|---|
| 277 | #endif |
|---|
| 278 | } |
|---|
| 279 | generalConfig->setDockMode(newDockMode); |
|---|
| 280 | #ifndef USE_KDE |
|---|
| 281 | generalConfig->setDefaultIconFortyEight(myDockFortyEightCheck->isChecked()); |
|---|
| 282 | generalConfig->setThemedIconTheme(myDockThemeCombo->currentText()); |
|---|
| 283 | #endif |
|---|
| 284 | generalConfig->setTrayBlink(myDockTrayBlinkCheck->isChecked()); |
|---|
| 285 | generalConfig->setTrayMsgOnlineNotify(myTrayMsgOnlineNotify->isChecked()); |
|---|
| 286 | |
|---|
| 287 | if (myNormalFontEdit->font() == Config::General::instance()->defaultFont()) |
|---|
| 288 | generalConfig->setNormalFont(QString::null); |
|---|
| 289 | else |
|---|
| 290 | generalConfig->setNormalFont(myNormalFontEdit->font().toString()); |
|---|
| 291 | |
|---|
| 292 | if (myEditFontEdit->font() == Config::General::instance()->defaultFont()) |
|---|
| 293 | generalConfig->setEditFont(QString::null); |
|---|
| 294 | else |
|---|
| 295 | generalConfig->setEditFont(myEditFontEdit->font().toString()); |
|---|
| 296 | |
|---|
| 297 | if (myHistoryFontEdit->font() == Config::General::instance()->defaultFont()) |
|---|
| 298 | generalConfig->setHistoryFont(QString::null); |
|---|
| 299 | else |
|---|
| 300 | generalConfig->setHistoryFont(myHistoryFontEdit->font().toString()); |
|---|
| 301 | |
|---|
| 302 | if (myFixedFontEdit->font() == Config::General::instance()->defaultFixedFont()) |
|---|
| 303 | generalConfig->setFixedFont(QString::null); |
|---|
| 304 | else |
|---|
| 305 | generalConfig->setFixedFont(myFixedFontEdit->font().toString()); |
|---|
| 306 | |
|---|
| 307 | generalConfig->blockUpdates(false); |
|---|
| 308 | } |
|---|