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 : ConfigPage(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->btnLanServersColor->setColorHtml(gConfig.doomseeker.lanServersColor);
75  d->cbMarkServersWithBuddies->setChecked(gConfig.doomseeker.bMarkServersWithBuddies);
76 
77  // Make sure that the tray is available. If it's not, disable tray icon
78  // completely and make sure no change can be done to the configuration in
79  // this manner.
80  if (!QSystemTrayIcon::isSystemTrayAvailable())
81  {
82  gConfig.doomseeker.bUseTrayIcon = false;
83  gConfig.doomseeker.bCloseToTrayIcon = false;
84  d->gboUseTrayIcon->setEnabled(false);
85  }
86 
87  d->gboUseTrayIcon->setChecked(gConfig.doomseeker.bUseTrayIcon);
88 
89  d->cbCloseToTrayIcon->setChecked(gConfig.doomseeker.bCloseToTrayIcon);
90 
91  d->cbColorizeConsole->setChecked(gConfig.doomseeker.bColorizeServerConsole);
92  d->cbDrawGridInServerTable->setChecked(gConfig.doomseeker.bDrawGridInServerTable);
93 
94  d->cbHidePasswords->setChecked(gConfig.doomseeker.bHidePasswords);
95 
96  d->cbLookupHosts->setChecked(gConfig.doomseeker.bLookupHosts);
97 
98  // This is not really an appearance option, but it does change how the list
99  // appears and thus utilized the fact that the appearance options cause the
100  // list to refresh. It also doesn't fit into any of the other existing
101  // categories at this time.
102  d->cbBotsNotPlayers->setChecked(gConfig.doomseeker.bBotsAreNotPlayers);
103 
104  // Set language.
105  int idxLanguage = d->cboLanguage->findData(gConfig.doomseeker.localization);
106  if (idxLanguage >= 0)
107  {
108  d->cboLanguage->setCurrentIndex(idxLanguage);
109  }
110  else
111  {
112  // Display that there is something wrong.
113  QString name = gConfig.doomseeker.localization;
114  const QPixmap& icon = IP2C::instance()->flagUnknown;
115  QString str = tr("Unknown language definition \"%1\"").arg(name);
116  d->cboLanguage->addItem(icon, str, name);
117  d->cboLanguage->setCurrentIndex(d->cboLanguage->count() - 1);
118  }
119 }
120 
122 {
123  gConfig.doomseeker.slotStyle = d->slotStyle->currentIndex();
124  gConfig.doomseeker.bMarkServersWithBuddies = d->cbMarkServersWithBuddies->isChecked();
125  gConfig.doomseeker.buddyServersColor = d->btnBuddyServersColor->colorHtml();
126  gConfig.doomseeker.customServersColor = d->btnCustomServersColor->colorHtml();
127  gConfig.doomseeker.lanServersColor = d->btnLanServersColor->colorHtml();
128  gConfig.doomseeker.bUseTrayIcon = d->gboUseTrayIcon->isChecked();
129  gConfig.doomseeker.bCloseToTrayIcon = d->cbCloseToTrayIcon->isChecked();
130  gConfig.doomseeker.bColorizeServerConsole = d->cbColorizeConsole->isChecked();
131  gConfig.doomseeker.bDrawGridInServerTable = d->cbDrawGridInServerTable->isChecked();
132  gConfig.doomseeker.bBotsAreNotPlayers = d->cbBotsNotPlayers->isChecked();
133  gConfig.doomseeker.bHidePasswords = d->cbHidePasswords->isChecked();
134  gConfig.doomseeker.bLookupHosts = d->cbLookupHosts->isChecked();
135  QString localization = d->cboLanguage->itemData(d->cboLanguage->currentIndex()).toString();
136  if (localization != gConfig.doomseeker.localization)
137  {
138  // Translation may be strenuous so do it only if the selected
139  // value actually changed.
140  gConfig.doomseeker.localization = localization;
141  gLog << tr("Loading translation \"%1\"").arg(localization);
142  Localization::loadTranslation(localization);
143  }
144 
145  emit appearanceChanged();
146 }
void readSettings()
Reimplement this to read settings from config into widgets.
QString localeName
Compliant with language_country standard. See QLocale::name()
void appearanceChanged()
Emit to tell Doomseeker to redraw certain widgets.
QString niceName
Name that will be displayed to user.
void saveSettings()
Reimplement this to write settings to config from widgets.
QIcon icon() const
Reimplement this to return a displayable icon for the ConfigPage.
Definition: cfgappearance.h:39
QString countryCodeName
The same as code used for country flags in IP2C.
QString name() const
Reimplement this to return a list-displayable name for this ConfigPage.
Definition: cfgappearance.h:40
Base class for configuration pages.
Definition: configpage.h:43