cfgappearance.cpp
1 //------------------------------------------------------------------------------
2 // cfgappearance.cpp
3 //------------------------------------------------------------------------------
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 // 02110-1301, USA.
19 //
20 //------------------------------------------------------------------------------
21 // Copyright (C) 2009 "Zalewa" <zalewapl@gmail.com>
22 //------------------------------------------------------------------------------
23 #include "cfgappearance.h"
24 #include "ui_cfgappearance.h"
25 
26 #include "configuration/doomseekerconfig.h"
27 #include <QColorDialog>
28 #include <QSystemTrayIcon>
29 #include "ip2c/ip2c.h"
30 #include "localization.h"
31 #include "log.h"
32 #include "main.h"
33 
34 DClass<CFGAppearance> : public Ui::CFGAppearance
35 {
36 };
37 
38 DPointered(CFGAppearance)
39 
40 CFGAppearance::CFGAppearance(QWidget *parent)
41 : ConfigurationBaseBox(parent)
42 {
43  d->setupUi(this);
44 }
45 
46 CFGAppearance::~CFGAppearance()
47 {
48 }
49 
50 void CFGAppearance::initLanguagesList()
51 {
52  const QList<LocalizationInfo>& localizations = Main::localizations;
53  foreach (const LocalizationInfo& obj, localizations)
54  {
55  const QString& flagName = obj.countryCodeName;
56  const QString& translationName = obj.localeName;
57  const QString& displayName = obj.niceName;
58 
59  QPixmap flag = IP2C::instance()->flag(flagName);
60  d->cboLanguage->addItem(flag, displayName, translationName);
61  }
62 }
63 
65 {
66  if (d->cboLanguage->count() == 0)
67  {
68  initLanguagesList();
69  }
70  d->slotStyle->setCurrentIndex(gConfig.doomseeker.slotStyle);
71 
72  d->btnCustomServersColor->setColorHtml(gConfig.doomseeker.customServersColor);
73  d->btnBuddyServersColor->setColorHtml(gConfig.doomseeker.buddyServersColor);
74  d->cbMarkServersWithBuddies->setChecked(gConfig.doomseeker.bMarkServersWithBuddies);
75 
76  // Make sure that the tray is available. If it's not, disable tray icon
77  // completely and make sure no change can be done to the configuration in
78  // this manner.
79  if (!QSystemTrayIcon::isSystemTrayAvailable())
80  {
81  gConfig.doomseeker.bUseTrayIcon = false;
82  gConfig.doomseeker.bCloseToTrayIcon = false;
83  d->gboUseTrayIcon->setEnabled(false);
84  }
85 
86  d->gboUseTrayIcon->setChecked(gConfig.doomseeker.bUseTrayIcon);
87 
88  d->cbCloseToTrayIcon->setChecked(gConfig.doomseeker.bCloseToTrayIcon);
89 
90  d->cbColorizeConsole->setChecked(gConfig.doomseeker.bColorizeServerConsole);
91  d->cbDrawGridInServerTable->setChecked(gConfig.doomseeker.bDrawGridInServerTable);
92 
93  d->cbHidePasswords->setChecked(gConfig.doomseeker.bHidePasswords);
94 
95  d->cbLookupHosts->setChecked(gConfig.doomseeker.bLookupHosts);
96 
97  // This is not really an appearance option, but it does change how the list
98  // appears and thus utilized the fact that the appearance options cause the
99  // list to refresh. It also doesn't fit into any of the other existing
100  // categories at this time.
101  d->cbBotsNotPlayers->setChecked(gConfig.doomseeker.bBotsAreNotPlayers);
102 
103  // Set language.
104  int idxLanguage = d->cboLanguage->findData(gConfig.doomseeker.localization);
105  if (idxLanguage >= 0)
106  {
107  d->cboLanguage->setCurrentIndex(idxLanguage);
108  }
109  else
110  {
111  // Display that there is something wrong.
112  QString name = gConfig.doomseeker.localization;
113  const QPixmap& icon = IP2C::instance()->flagUnknown;
114  QString str = tr("Unknown language definition \"%1\"").arg(name);
115  d->cboLanguage->addItem(icon, str, name);
116  d->cboLanguage->setCurrentIndex(d->cboLanguage->count() - 1);
117  }
118 }
119 
121 {
122  gConfig.doomseeker.slotStyle = d->slotStyle->currentIndex();
123  gConfig.doomseeker.bMarkServersWithBuddies = d->cbMarkServersWithBuddies->isChecked();
124  gConfig.doomseeker.buddyServersColor = d->btnBuddyServersColor->colorHtml();
125  gConfig.doomseeker.customServersColor = d->btnCustomServersColor->colorHtml();
126  gConfig.doomseeker.bUseTrayIcon = d->gboUseTrayIcon->isChecked();
127  gConfig.doomseeker.bCloseToTrayIcon = d->cbCloseToTrayIcon->isChecked();
128  gConfig.doomseeker.bColorizeServerConsole = d->cbColorizeConsole->isChecked();
129  gConfig.doomseeker.bDrawGridInServerTable = d->cbDrawGridInServerTable->isChecked();
130  gConfig.doomseeker.bBotsAreNotPlayers = d->cbBotsNotPlayers->isChecked();
131  gConfig.doomseeker.bHidePasswords = d->cbHidePasswords->isChecked();
132  gConfig.doomseeker.bLookupHosts = d->cbLookupHosts->isChecked();
133  QString localization = d->cboLanguage->itemData(d->cboLanguage->currentIndex()).toString();
134  if (localization != gConfig.doomseeker.localization)
135  {
136  // Translation may be strenuous so do it only if the selected
137  // value actually changed.
138  gConfig.doomseeker.localization = localization;
139  gLog << tr("Loading translation \"%1\"").arg(localization);
140  Localization::loadTranslation(localization);
141  }
142 
143  emit appearanceChanged();
144 }
void readSettings()
Reimplement this to read settings from config into widgets.
QString localeName
Compliant with language_country standard. See QLocale::name()
QString niceName
Name that will be displayed to user.
void saveSettings()
Reimplement this to write settings to config from widgets.
void appearanceChanged()
Emit to tell Doomseeker to redraw certain widgets.
QIcon icon() const
Reimplement this to return a displayable icon for the ConfigurationBaseBox.
Definition: cfgappearance.h:39
QString countryCodeName
The same as code used for country flags in IP2C.
Base class for configuration pages.
QString name() const
Reimplement this to return a list-displayable name for this ConfigurationBaseBox. ...
Definition: cfgappearance.h:40