1 /***************************************************************************
2 *                                                                         *
3 *   This program is free software; you can redistribute it and/or modify  *
4 *   it under the terms of the GNU General Public License as published by  *
5 *   the Free Software Foundation; either version 3 of the License, or     *
6 *   (at your option) any later version.                                   *
7 *                                                                         *
8 ***************************************************************************/
9 
10 #include "SettingsGUI.h"
11 #include "WulforSettings.h"
12 #include "WulforUtil.h"
13 #include "MainWindow.h"
14 #include "Notification.h"
15 #include "EmoticonFactory.h"
16 #include "CustomFontModel.h"
17 
18 #include <QListWidgetItem>
19 #include <QPixmap>
20 #include <QColor>
21 #include <QColorDialog>
22 #include <QStyleFactory>
23 #include <QFontDialog>
24 #include <QFileDialog>
25 #include <QDir>
26 #include <QFile>
27 #include <QSystemTrayIcon>
28 #include <QHeaderView>
29 #include <QMap>
30 
31 #ifndef CLIENT_ICONS_DIR
32 #define CLIENT_ICONS_DIR ""
33 #endif
34 
SettingsGUI(QWidget * parent)35 SettingsGUI::SettingsGUI(QWidget *parent) :
36     QWidget(parent),
37     custom_style(false)
38 {
39     setupUi(this);
40 
41     init();
42 }
43 
~SettingsGUI()44 SettingsGUI::~SettingsGUI(){
45 
46 }
47 
init()48 void SettingsGUI::init(){
49     {//Basic tab
50         WulforUtil *WU = WulforUtil::getInstance();
51         QStringList styles = QStyleFactory::keys();
52 
53         comboBox_THEMES->addItem(tr("Default (need to restart)"));
54 
55         for (const QString &s : styles)
56             comboBox_THEMES->addItem(s);
57 
58         comboBox_THEMES->setCurrentIndex(styles.indexOf(WSGET(WS_APP_THEME)) >= 0? (styles.indexOf(WSGET(WS_APP_THEME))+1) : 0);
59 
60 
61         if (WSGET(WS_APP_FONT).isEmpty()){
62             lineEdit_APPFONT->setText(qApp->font().toString());
63             WSSET(WS_APP_FONT, qApp->font().toString());
64         }
65         else
66             lineEdit_APPFONT->setText(WSGET(WS_APP_FONT));
67 
68         int i = 0;
69         int k = -1;
70 #if !defined(Q_WS_WIN)
71         QDir translationsDir(CLIENT_TRANSLATIONS_DIR);
72 #else
73         QDir translationsDir(qApp->applicationDirPath()+QDir::separator()+CLIENT_TRANSLATIONS_DIR);
74 #endif
75         QMap<QString, QString> langNames;
76         langNames["en.qm"]       = tr("English");
77         langNames["ru.qm"]       = tr("Russian");
78         langNames["be.qm"]       = tr("Belarusian");
79         langNames["hu.qm"]       = tr("Hungarian");
80         langNames["fr.qm"]       = tr("French");
81         langNames["pl.qm"]       = tr("Polish");
82         langNames["pt_BR.qm"]    = tr("Portuguese (Brazil)");
83         langNames["sr.qm"]       = tr("Serbian (Cyrillic)");
84         langNames["sr@latin.qm"] = tr("Serbian (Latin)");
85         langNames["uk.qm"]       = tr("Ukrainian");
86         langNames["es.qm"]       = tr("Spanish");
87 		langNames["eu.qm"]       = tr("Basque");
88         langNames["bg.qm"]       = tr("Bulgarian");
89         langNames["sk.qm"]       = tr("Slovak");
90         langNames["cs.qm"]       = tr("Czech");
91         langNames["de.qm"]       = tr("German");
92         langNames["el.qm"]       = tr("Greek");
93         langNames["it.qm"]       = tr("Italian");
94         langNames["vi.qm"]       = tr("Vietnamese");
95         langNames["zh_CN.qm"]    = tr("Chinese (China)");
96         langNames["sv_SE.qm"]    = tr("Swedish (Sweden)");
97 
98         QString full_path;
99         QString lang;
100 
101         for (const auto &f : translationsDir.entryList(QDir::Files | QDir::NoSymLinks)){
102             full_path = QDir::toNativeSeparators( translationsDir.filePath(f) );
103             lang = langNames[f];
104 
105             if (!lang.isEmpty()){
106                 comboBox_LANGS->addItem(lang, full_path);
107 
108                 if (WSGET(WS_TRANSLATION_FILE).endsWith(f))
109                     k = i;
110 
111                 i++;
112             }
113         }
114         comboBox_LANGS->setCurrentIndex(k);
115 
116 #if !defined(Q_WS_WIN)
117         QString users = CLIENT_ICONS_DIR "/user/";
118 #else
119         QString users = qApp->applicationDirPath()+QDir::separator()+CLIENT_ICONS_DIR "/user/";
120 #endif
121         i = 0;
122         k = -1;
123         for (const QString &f : QDir(users).entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot)){
124             if (!f.isEmpty()){
125                 comboBox_USERS->addItem(f);
126 
127                 if (f == WSGET(WS_APP_USERTHEME))
128                     k = i;
129 
130                 i++;
131             }
132         }
133         comboBox_USERS->setCurrentIndex(k);
134 
135 #if !defined(Q_WS_WIN)
136         QString icons = CLIENT_ICONS_DIR "/appl/";
137 #else
138         QString icons = qApp->applicationDirPath()+QDir::separator()+CLIENT_ICONS_DIR "/appl/";
139 #endif
140         i = 0;
141         k = -1;
142         for (const QString &f : QDir(icons).entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot)){
143             if (!f.isEmpty()){
144                 comboBox_ICONS->addItem(f);
145 
146                 if (f == WSGET(WS_APP_ICONTHEME))
147                     k = i;
148 
149                 i++;
150             }
151         }
152         comboBox_ICONS->setCurrentIndex(k);
153 
154 #if !defined(Q_WS_WIN)
155         QString emot = CLIENT_DATA_DIR "/emoticons/";
156 #else
157         QString emot = qApp->applicationDirPath()+QDir::separator()+CLIENT_DATA_DIR "/emoticons/";
158 #endif
159         comboBox_EMOT->setCurrentIndex(0);
160         i = 0;
161         for (const QString &f : QDir(emot).entryList(QDir::Dirs | QDir::NoSymLinks | QDir::NoDotAndDotDot)){
162             if (!f.isEmpty()){
163                 comboBox_EMOT->addItem(f);
164 
165                 if (f == WSGET(WS_APP_EMOTICON_THEME))
166                     comboBox_EMOT->setCurrentIndex(i);
167 
168                 i++;
169             }
170         }
171 
172         lineEdit_LANGFILE->setText(WSGET(WS_TRANSLATION_FILE));
173 
174         toolButton_LANGBROWSE->setIcon(WU->getPixmap(WulforUtil::eiFOLDER_BLUE));
175 
176         if (WBGET(WB_MAINWINDOW_REMEMBER))
177             radioButton_REMEMBER->setChecked(true);
178         else if (WBGET(WB_MAINWINDOW_HIDE))
179             radioButton_HIDE->setChecked(true);
180         else
181             radioButton_SHOW->setChecked(true);
182 
183         groupBox_TRAY->setChecked(WBGET(WB_TRAY_ENABLED));
184         groupBox_TRAY->setEnabled(QSystemTrayIcon::isSystemTrayAvailable());
185 
186         if (WBGET(WB_MAINWINDOW_USE_SIDEBAR))
187             comboBox_TABBAR->setCurrentIndex(2);
188         else if (WBGET(WB_MAINWINDOW_USE_M_TABBAR))
189             comboBox_TABBAR->setCurrentIndex(1);
190         else
191             comboBox_TABBAR->setCurrentIndex(0);
192 
193 #if defined(Q_WS_X11)
194         checkBox_ICONTHEME->setChecked(WBGET("app/use-icon-theme", false));
195 #endif
196         checkBox_HIDE_ICONS_IN_MENU->setChecked(WBGET("mainwindow/dont-show-icons-in-menus", false));
197 
198         // Hide options which do not work in Mac OS X, MS Windows or Haiku:
199 #if defined (Q_WS_WIN) || defined (__HAIKU__)
200         checkBox_ICONTHEME->hide();
201 #elif defined(Q_WS_MAC)
202         checkBox_ICONTHEME->hide();
203         groupBox_TRAY->hide();
204 #endif
205     }
206     {//Chat tab
207         checkBox_CHATJOINS->setChecked(WBGET(WB_CHAT_SHOW_JOINS));
208         checkBox_JOINSFAV->setChecked(WBGET(WB_CHAT_SHOW_JOINS_FAV));
209         checkBox_CHATHIDDEN->setChecked(WBGET(WB_SHOW_HIDDEN_USERS));
210         checkBox_IGNOREPMHUB->setChecked(BOOLSETTING(IGNORE_HUB_PMS));
211         checkBox_IGNOREPMBOT->setChecked(BOOLSETTING(IGNORE_BOT_PMS));
212         checkBox_REDIRECTPMBOT->setChecked(WBGET(WB_CHAT_REDIRECT_BOT_PMS));
213         checkBox_REDIRECT_UNREAD->setChecked(WBGET("hubframe/redirect-pm-to-main-chat", false));
214         checkBox_KEEPFOCUS->setChecked(WBGET(WB_CHAT_KEEPFOCUS));
215         checkBox_UNREADEN_DRAW_LINE->setChecked(WBGET("hubframe/unreaden-draw-line", true));
216         checkBox_USE_CTRL_ENTER->setChecked(WBGET(WB_USE_CTRL_ENTER));
217         checkBox_ROTATING->setChecked(WBGET(WB_CHAT_ROTATING_MSGS));
218         checkBox_EMOT->setChecked(WBGET(WB_APP_ENABLE_EMOTICON));
219         checkBox_EMOTFORCE->setChecked(WBGET(WB_APP_FORCE_EMOTICONS));
220         checkBox_SMILEPANEL->setChecked(WBGET(WB_CHAT_USE_SMILE_PANEL));
221         checkBox_HIDESMILEPANEL->setChecked(WBGET(WB_CHAT_HIDE_SMILE_PANEL));
222     }
223     {//Chat (extended) tab
224         comboBox_DBL_CLICK->setCurrentIndex(WIGET(WI_CHAT_DBLCLICK_ACT));
225         comboBox_MDL_CLICK->setCurrentIndex(WIGET(WI_CHAT_MDLCLICK_ACT));
226         comboBox_DEF_MAGNET_ACTION->setCurrentIndex(WIGET(WI_DEF_MAGNET_ACTION));
227         comboBox_APP_UNIT_BASE->setCurrentIndex(SETTING(APP_UNIT_BASE));
228         checkBox_HIGHLIGHTFAVS->setChecked(WBGET(WB_CHAT_HIGHLIGHT_FAVS));
229         checkBox_CHAT_SHOW_IP->setChecked(BOOLSETTING(USE_IP));
230         checkBox_CHAT_SHOW_CC->setChecked(BOOLSETTING(GET_USER_COUNTRY));
231         checkBox_BB_CODE->setChecked(WBGET("hubframe/use-bb-code", false));
232         lineEdit_TIMESTAMP->setText(WSGET(WS_CHAT_TIMESTAMP));
233 
234         spinBox_OUT_IN_HIST->setValue(WIGET(WI_OUT_IN_HIST));
235         spinBox_PARAGRAPHS->setValue(WIGET(WI_CHAT_MAXPARAGRAPHS));
236 
237         comboBox_CHAT_SEPARATOR->setCurrentIndex(comboBox_CHAT_SEPARATOR->findText(WSGET(WS_CHAT_SEPARATOR)));
238     }
239     {//Color tab
240         QColor c;
241         QPixmap p(10, 10);
242 
243         c.setNamedColor(WSGET(WS_CHAT_LOCAL_COLOR));
244         p.fill(c);
245         new QListWidgetItem(p, tr("Local user"), listWidget_CHATCOLOR);
246 
247         c.setNamedColor(WSGET(WS_CHAT_OP_COLOR));
248         p.fill(c);
249         new QListWidgetItem(p, tr("Operator"), listWidget_CHATCOLOR);
250 
251         c.setNamedColor(WSGET(WS_CHAT_BOT_COLOR));
252         p.fill(c);
253         new QListWidgetItem(p, tr("Bot"), listWidget_CHATCOLOR);
254 
255         c.setNamedColor(WSGET(WS_CHAT_PRIV_LOCAL_COLOR));
256         p.fill(c);
257         new QListWidgetItem(p, tr("Private: local user"), listWidget_CHATCOLOR);
258 
259         c.setNamedColor(WSGET(WS_CHAT_PRIV_USER_COLOR));
260         p.fill(c);
261         new QListWidgetItem(p, tr("Private: user"), listWidget_CHATCOLOR);
262 
263         c.setNamedColor(WSGET(WS_CHAT_SAY_NICK));
264         p.fill(c);
265         new QListWidgetItem(p, tr("Chat: Say nick"), listWidget_CHATCOLOR);
266 
267         c.setNamedColor(WSGET(WS_CHAT_STAT_COLOR));
268         p.fill(c);
269         new QListWidgetItem(p, tr("Status"), listWidget_CHATCOLOR);
270 
271         c.setNamedColor(WSGET(WS_CHAT_USER_COLOR));
272         p.fill(c);
273         new QListWidgetItem(p, tr("User"), listWidget_CHATCOLOR);
274 
275         c.setNamedColor(WSGET(WS_CHAT_FAVUSER_COLOR));
276         p.fill(c);
277         new QListWidgetItem(p, tr("Favorite User"), listWidget_CHATCOLOR);
278 
279         c.setNamedColor(WSGET(WS_CHAT_TIME_COLOR));
280         p.fill(c);
281         new QListWidgetItem(p, tr("Time stamp"), listWidget_CHATCOLOR);
282 
283         c.setNamedColor(WSGET(WS_CHAT_MSG_COLOR));
284         p.fill(c);
285         new QListWidgetItem(p, tr("Message"), listWidget_CHATCOLOR);
286 
287         c.setNamedColor(WSGET(WS_CHAT_FIND_COLOR));
288         h_color = c;
289 
290         c.setAlpha(WIGET(WI_CHAT_FIND_COLOR_ALPHA));
291         p.fill(c);
292         toolButton_H_COLOR->setIcon(p);
293 
294         c.setNamedColor(WSGET(WS_APP_SHARED_FILES_COLOR));
295         shared_files_color = c;
296         c.setAlpha(WIGET(WI_APP_SHARED_FILES_ALPHA));
297         p.fill(c);
298         toolButton_SHAREDFILES->setIcon(p);
299 
300         downloads_clr = qvariant_cast<QColor>(WVGET("transferview/download-bar-color", QColor()));
301         uploads_clr = qvariant_cast<QColor>(WVGET("transferview/upload-bar-color", QColor()));
302 
303         if (downloads_clr.isValid()){
304             c = downloads_clr;
305             p.fill(c);
306 
307             toolButton_DOWNLOADSCLR->setIcon(p);
308         }
309         if (uploads_clr.isValid()){
310             c = uploads_clr;
311             p.fill(c);
312 
313             toolButton_UPLOADSCLR->setIcon(p);
314         }
315 
316         checkBox_CHAT_BACKGROUND_COLOR->setChecked(WBGET("hubframe/change-chat-background-color", false));
317         toolButton_CHAT_BACKGROUND_COLOR->setEnabled(WBGET("hubframe/change-chat-background-color", false));
318         if (!WSGET("hubframe/chat-background-color", "").isEmpty()){
319             c.setNamedColor(WSGET("hubframe/chat-background-color"));
320             chat_background_color = c;
321             c.setAlpha(255);
322             p.fill(c);
323             toolButton_CHAT_BACKGROUND_COLOR->setIcon(p);
324         }
325 
326         horizontalSlider_H_COLOR->setValue(WIGET(WI_CHAT_FIND_COLOR_ALPHA));
327         horizontalSlider_SHAREDFILES->setValue(WIGET(WI_APP_SHARED_FILES_ALPHA));
328     }
329     {// Fonts tab
330         CustomFontModel *model = new CustomFontModel(this);
331         tableView->setModel(model);
332 
333         tableView->horizontalHeader()->restoreState(QByteArray::fromBase64(WSGET(WS_SETTINGS_GUI_FONTS_STATE).toUtf8()));
334 
335         connect(tableView, SIGNAL(doubleClicked(QModelIndex)), model, SLOT(itemDoubleClicked(QModelIndex)));
336         connect(this, SIGNAL(saveFonts()), model, SLOT(ok()));
337     }
338 
339     connect(pushButton_TEST, SIGNAL(clicked()), this, SLOT(slotTestAppTheme()));
340     connect(comboBox_THEMES, SIGNAL(activated(int)), this, SLOT(slotThemeChanged()));
341     connect(listWidget_CHATCOLOR, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(slotChatColorItemClicked(QListWidgetItem*)));
342     connect(toolButton_APPFONTBROWSE, SIGNAL(clicked()), this, SLOT(slotBrowseFont()));
343     connect(toolButton_LANGBROWSE, SIGNAL(clicked()), this, SLOT(slotBrowseLng()));
344     connect(comboBox_LANGS, SIGNAL(activated(int)), this, SLOT(slotLngIndexChanged(int)));
345     connect(comboBox_USERS, SIGNAL(activated(int)), this, SLOT(slotUsersChanged()));
346 	connect(comboBox_ICONS, SIGNAL(activated(int)), this, SLOT(slotIconsChanged()));
347     connect(toolButton_H_COLOR, SIGNAL(clicked()), this, SLOT(slotGetColor()));
348     connect(toolButton_SHAREDFILES, SIGNAL(clicked()), this, SLOT(slotGetColor()));
349     connect(toolButton_CHAT_BACKGROUND_COLOR, SIGNAL(clicked()), this, SLOT(slotGetColor()));
350     connect(toolButton_DOWNLOADSCLR, SIGNAL(clicked()), this, SLOT(slotGetColor()));
351     connect(toolButton_UPLOADSCLR, SIGNAL(clicked()), this, SLOT(slotGetColor()));
352     connect(pushButton_RESET, SIGNAL(clicked()), this, SLOT(slotResetTransferColors()));
353     connect(horizontalSlider_H_COLOR, SIGNAL(valueChanged(int)), this, SLOT(slotSetTransparency(int)));
354     connect(horizontalSlider_SHAREDFILES, SIGNAL(valueChanged(int)), this, SLOT(slotSetTransparency(int)));
355 }
356 
ok()357 void SettingsGUI::ok(){
358     SettingsManager *SM = SettingsManager::getInstance();
359     {//Basic tab
360         if (custom_style && comboBox_THEMES->currentIndex() > 0)
361             WSSET(WS_APP_THEME, comboBox_THEMES->currentText());
362         else if (!comboBox_THEMES->currentIndex())
363             WSSET(WS_APP_THEME, "");
364 
365         if (!lineEdit_APPFONT->text().isEmpty())
366             WSSET(WS_APP_FONT, lineEdit_APPFONT->text());
367 
368         if (!lineEdit_LANGFILE->text().isEmpty() && (lineEdit_LANGFILE->text() != WSGET(WS_TRANSLATION_FILE)))
369             WSSET(WS_TRANSLATION_FILE, lineEdit_LANGFILE->text());
370 
371         WBSET(WB_MAINWINDOW_REMEMBER, radioButton_REMEMBER->isChecked());
372         WBSET(WB_MAINWINDOW_HIDE, radioButton_HIDE->isChecked());
373 
374         if (WBGET(WB_TRAY_ENABLED) != groupBox_TRAY->isChecked()){
375             WBSET(WB_TRAY_ENABLED, groupBox_TRAY->isChecked());
376 
377             Notify->enableTray(WBGET(WB_TRAY_ENABLED));
378         }
379 
380         if (WSGET(WS_APP_EMOTICON_THEME) != comboBox_EMOT->currentText()){
381             WSSET(WS_APP_EMOTICON_THEME, comboBox_EMOT->currentText());
382 
383             if (EmoticonFactory::getInstance())
384                 EmoticonFactory::getInstance()->load();
385         }
386 
387         if (comboBox_TABBAR->currentIndex() == 2){
388             WBSET(WB_MAINWINDOW_USE_SIDEBAR, true);
389             WBSET(WB_MAINWINDOW_USE_M_TABBAR, false);
390         }
391         else if (comboBox_TABBAR->currentIndex() == 1){
392             WBSET(WB_MAINWINDOW_USE_SIDEBAR, false);
393             WBSET(WB_MAINWINDOW_USE_M_TABBAR, true);
394         }
395         else{
396             WBSET(WB_MAINWINDOW_USE_SIDEBAR, false);
397             WBSET(WB_MAINWINDOW_USE_M_TABBAR, false);
398         }
399 
400         WBSET("app/use-icon-theme", checkBox_ICONTHEME->isChecked());
401         WBSET("mainwindow/dont-show-icons-in-menus", checkBox_HIDE_ICONS_IN_MENU->isChecked());
402     }
403     {//Chat tab
404         WBSET(WB_SHOW_HIDDEN_USERS, checkBox_CHATHIDDEN->isChecked());
405         WBSET(WB_CHAT_SHOW_JOINS, checkBox_CHATJOINS->isChecked());
406         WBSET(WB_CHAT_SHOW_JOINS_FAV, checkBox_JOINSFAV->isChecked());
407         WBSET(WB_CHAT_REDIRECT_BOT_PMS, checkBox_REDIRECTPMBOT->isChecked());
408         WBSET("hubframe/redirect-pm-to-main-chat", checkBox_REDIRECT_UNREAD->isChecked());
409         WBSET(WB_CHAT_KEEPFOCUS, checkBox_KEEPFOCUS->isChecked());
410         WBSET("hubframe/unreaden-draw-line", checkBox_UNREADEN_DRAW_LINE->isChecked());
411         WBSET(WB_CHAT_ROTATING_MSGS, checkBox_ROTATING->isChecked());
412         WBSET(WB_USE_CTRL_ENTER, checkBox_USE_CTRL_ENTER->isChecked());
413         WBSET(WB_APP_ENABLE_EMOTICON, checkBox_EMOT->isChecked());
414         WBSET(WB_APP_FORCE_EMOTICONS, checkBox_EMOTFORCE->isChecked());
415         WBSET(WB_CHAT_USE_SMILE_PANEL, checkBox_SMILEPANEL->isChecked());
416         WBSET(WB_CHAT_HIDE_SMILE_PANEL, checkBox_HIDESMILEPANEL->isChecked());
417     }
418     {//Chat (extended) tab
419         WISET(WI_CHAT_DBLCLICK_ACT, comboBox_DBL_CLICK->currentIndex());
420         WISET(WI_CHAT_MDLCLICK_ACT, comboBox_MDL_CLICK->currentIndex());
421         WISET(WI_DEF_MAGNET_ACTION, comboBox_DEF_MAGNET_ACTION->currentIndex());
422         SM->set(SettingsManager::APP_UNIT_BASE, comboBox_APP_UNIT_BASE->currentIndex());
423         WBSET(WB_CHAT_HIGHLIGHT_FAVS, checkBox_HIGHLIGHTFAVS->isChecked());
424         SM->set(SettingsManager::USE_IP, checkBox_CHAT_SHOW_IP->isChecked());
425         WBSET("hubframe/use-bb-code", checkBox_BB_CODE->isChecked());
426 
427         WSSET(WS_CHAT_TIMESTAMP, lineEdit_TIMESTAMP->text());
428 
429         WISET(WI_OUT_IN_HIST, spinBox_OUT_IN_HIST->value());
430         WISET(WI_CHAT_MAXPARAGRAPHS, spinBox_PARAGRAPHS->value());
431 
432         SM->set(SettingsManager::IGNORE_BOT_PMS, checkBox_IGNOREPMBOT->isChecked());
433         SM->set(SettingsManager::IGNORE_HUB_PMS, checkBox_IGNOREPMHUB->isChecked());
434         SM->set(SettingsManager::GET_USER_COUNTRY, checkBox_CHAT_SHOW_CC->isChecked());
435         WSSET(WS_CHAT_SEPARATOR, comboBox_CHAT_SEPARATOR->currentText());
436     }
437     {//Color tab
438         int i = 0;
439 
440         WSSET(WS_CHAT_LOCAL_COLOR,      QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
441         WSSET(WS_CHAT_OP_COLOR,         QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
442         WSSET(WS_CHAT_BOT_COLOR,        QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
443         WSSET(WS_CHAT_PRIV_LOCAL_COLOR, QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
444         WSSET(WS_CHAT_PRIV_USER_COLOR,  QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
445         WSSET(WS_CHAT_SAY_NICK,         QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
446         WSSET(WS_CHAT_STAT_COLOR,       QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
447         WSSET(WS_CHAT_USER_COLOR,       QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
448         WSSET(WS_CHAT_FAVUSER_COLOR,    QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
449         WSSET(WS_CHAT_TIME_COLOR,       QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
450         WSSET(WS_CHAT_MSG_COLOR,        QColor(listWidget_CHATCOLOR->item(i++)->icon().pixmap(10, 10).toImage().pixel(0, 0)).name());
451 
452         WSSET(WS_CHAT_FIND_COLOR,       h_color.name());
453         WISET(WI_CHAT_FIND_COLOR_ALPHA, horizontalSlider_H_COLOR->value());
454 
455         WSSET(WS_APP_SHARED_FILES_COLOR, shared_files_color.name());
456         WISET(WI_APP_SHARED_FILES_ALPHA, horizontalSlider_SHAREDFILES->value());
457 
458         WBSET("hubframe/change-chat-background-color", checkBox_CHAT_BACKGROUND_COLOR->isChecked());
459         if (chat_background_color.isValid())
460             WSSET("hubframe/chat-background-color", chat_background_color.name());
461         if (!checkBox_CHAT_BACKGROUND_COLOR->isChecked())
462             WSSET("hubframe/chat-background-color", QTextEdit().palette().color(QPalette::Active, QPalette::Base).name());
463         if (downloads_clr.isValid())
464             WVSET("transferview/download-bar-color", downloads_clr);
465         if (uploads_clr.isValid())
466             WVSET("transferview/upload-bar-color", uploads_clr);
467     }
468 
469     WSSET(WS_SETTINGS_GUI_FONTS_STATE, tableView->horizontalHeader()->saveState().toBase64());
470 
471     emit saveFonts();
472 }
473 
slotChatColorItemClicked(QListWidgetItem * item)474 void SettingsGUI::slotChatColorItemClicked(QListWidgetItem *item){
475     QPixmap p(10, 10);
476     QColor color(item->icon().pixmap(10, 10).toImage().pixel(0, 0));
477     color = QColorDialog::getColor(color);
478 
479     if (color.isValid()) {
480         p.fill(color);
481         item->setIcon(p);
482     }
483 }
484 
slotGetColor()485 void SettingsGUI::slotGetColor(){
486     QPixmap p(10, 10);
487 
488     if (sender() == toolButton_H_COLOR){
489         QColor color = QColorDialog::getColor(h_color);
490 
491         if (color.isValid()){
492             h_color = color;
493 
494             color.setAlpha(horizontalSlider_H_COLOR->value());
495             p.fill(color);
496             toolButton_H_COLOR->setIcon(p);
497         }
498     }
499     else if (sender() == toolButton_SHAREDFILES){
500         QColor color = QColorDialog::getColor(shared_files_color);
501 
502         if (color.isValid()){
503             shared_files_color = color;
504 
505             color.setAlpha(horizontalSlider_SHAREDFILES->value());
506             p.fill(color);
507             toolButton_SHAREDFILES->setIcon(p);
508         }
509     }
510     else if (sender() == toolButton_CHAT_BACKGROUND_COLOR){
511         QColor color = QColorDialog::getColor(chat_background_color);
512 
513         if (color.isValid()){
514             chat_background_color = color;
515 
516             color.setAlpha(255);
517             p.fill(color);
518             toolButton_CHAT_BACKGROUND_COLOR->setIcon(p);
519         }
520     }
521     else if (sender() == toolButton_DOWNLOADSCLR){
522         QColor color = QColorDialog::getColor(chat_background_color);
523 
524         if (color.isValid()){
525             downloads_clr = color;
526 
527             color.setAlpha(255);
528             p.fill(color);
529             toolButton_DOWNLOADSCLR->setIcon(p);
530         }
531     }
532     else if (sender() == toolButton_UPLOADSCLR){
533         QColor color = QColorDialog::getColor(chat_background_color);
534 
535         if (color.isValid()){
536             uploads_clr = color;
537 
538             color.setAlpha(255);
539             p.fill(color);
540             toolButton_UPLOADSCLR->setIcon(p);
541         }
542     }
543 }
544 
slotSetTransparency(int value)545 void SettingsGUI::slotSetTransparency(int value){
546     QPixmap p(10, 10);
547     QColor color;
548 
549     if (sender() == horizontalSlider_H_COLOR)
550         color = h_color;
551     else
552         color = shared_files_color;
553 
554     color.setAlpha(value);
555 
556     if (color.isValid())
557         p.fill(color);
558 
559     if (sender() == horizontalSlider_H_COLOR)
560         toolButton_H_COLOR->setIcon(p);
561     else
562         toolButton_SHAREDFILES->setIcon(p);
563 }
564 
slotTestAppTheme()565 void SettingsGUI::slotTestAppTheme(){
566     if (!comboBox_THEMES->currentIndex()){ //Default
567         WSSET(WS_APP_THEME, "");
568 
569         return;
570     }
571 
572     custom_style = true;
573 
574     QString s = comboBox_THEMES->currentText();
575 
576     if (s.isEmpty())
577         return;
578 
579     qApp->setStyle(s);
580 
581     WSSET(WS_APP_THEME, s);
582 }
583 
slotThemeChanged()584 void SettingsGUI::slotThemeChanged(){
585     custom_style = true;
586 }
587 
slotBrowseFont()588 void SettingsGUI::slotBrowseFont(){
589     bool ok = false;
590 
591     QFont f = QFontDialog::getFont(&ok, this);
592 
593     if (ok){
594         qApp->setFont(f);
595         lineEdit_APPFONT->setText(f.toString());
596 
597         WSSET(WS_APP_FONT, f.toString());
598     }
599 }
600 
slotBrowseLng()601 void SettingsGUI::slotBrowseLng(){
602     QString file = QFileDialog::getOpenFileName(this, tr("Select translation"), QString(CLIENT_TRANSLATIONS_DIR), tr("Translation (*.qm)"));
603 
604     if (!file.isEmpty()){
605         file = QDir::toNativeSeparators(file);
606 
607         WulforSettings::getInstance()->blockSignals(true);//do not emit signal that translation file has been changed
608         WSSET(WS_TRANSLATION_FILE, file);
609         WulforSettings::getInstance()->blockSignals(false);
610 
611         WulforSettings::getInstance()->loadTranslation();//set language for application
612         MainWindow::getInstance()->retranslateUi();
613 
614         WSSET(WS_TRANSLATION_FILE, file);//emit signals for other widgets
615 
616         lineEdit_LANGFILE->setText(WSGET(WS_TRANSLATION_FILE));
617     }
618 }
619 
slotLngIndexChanged(int index)620 void SettingsGUI::slotLngIndexChanged(int index){
621     QString file = comboBox_LANGS->itemData(index).toString();
622 
623     WSSET(WS_TRANSLATION_FILE, file);
624 
625     WulforSettings::getInstance()->blockSignals(true);//do not emit signal that translation file has been changed
626     WSSET(WS_TRANSLATION_FILE, file);
627     WulforSettings::getInstance()->blockSignals(false);
628 
629     WulforSettings::getInstance()->loadTranslation();
630     MainWindow::getInstance()->retranslateUi();
631 
632     WSSET(WS_TRANSLATION_FILE, file);
633 
634     lineEdit_LANGFILE->setText(WSGET(WS_TRANSLATION_FILE));
635 }
636 
slotIconsChanged()637 void SettingsGUI::slotIconsChanged(){
638     WSSET(WS_APP_ICONTHEME, comboBox_ICONS->currentText());
639 
640     WulforUtil::getInstance()->loadIcons();
641 }
642 
slotUsersChanged()643 void SettingsGUI::slotUsersChanged(){
644     WSSET(WS_APP_USERTHEME, comboBox_USERS->currentText());
645 }
646 
slotResetTransferColors()647 void SettingsGUI::slotResetTransferColors(){
648     WVSET("transferview/download-bar-color", QColor());
649     WVSET("transferview/upload-bar-color", QColor());
650 
651     downloads_clr = QColor();
652     uploads_clr = QColor();
653 
654     toolButton_DOWNLOADSCLR->setIcon(QIcon());
655     toolButton_UPLOADSCLR->setIcon(QIcon());
656 }
657