Skip to content

Commit

Permalink
Merge branch '425-custom-tray-icon-color' into v1.5-development
Browse files Browse the repository at this point in the history
UI: allow setting custom tray icon color

Fixes #425
Fixes #232

Connected: #369
  • Loading branch information
szszszsz committed Aug 14, 2021
2 parents 9a0fcc2 + 7ff77a7 commit 63e1b03
Show file tree
Hide file tree
Showing 10 changed files with 137 additions and 27 deletions.
8 changes: 8 additions & 0 deletions i18n/nitrokey_arabic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,14 @@ Select &quot;Initialize device&quot; option from context menu.</source>
<source>Would you like to revert the changes?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tray icon color:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change color</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinDialog</name>
Expand Down
8 changes: 8 additions & 0 deletions i18n/nitrokey_de_DE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1088,6 +1088,14 @@ Wählen Sie im Kontextmenü &quot;Gerät initialisieren&quot;.</translation>
<source>Would you like to revert the changes?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tray icon color:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change color</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinDialog</name>
Expand Down
8 changes: 8 additions & 0 deletions i18n/nitrokey_en.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1021,6 +1021,14 @@ Select &quot;Initialize device&quot; option from context menu.</translation>
<source>Would you like to revert the changes?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tray icon color:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change color</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinDialog</name>
Expand Down
8 changes: 8 additions & 0 deletions i18n/nitrokey_fr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,14 @@ Veuillez sélectionner l&apos;option &quot;Initialiser la clef&quot; dans le men
<source>Would you like to revert the changes?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tray icon color:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change color</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinDialog</name>
Expand Down
8 changes: 8 additions & 0 deletions i18n/nitrokey_it.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,6 +1099,14 @@ Seleziona l&apos;opzione &quot;Inizializza dispositivo&quot; dal menu contestual
<source>Would you like to revert the changes?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tray icon color:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change color</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinDialog</name>
Expand Down
8 changes: 8 additions & 0 deletions i18n/nitrokey_pl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1107,6 +1107,14 @@ wybierz &quot;Zainicjalizuj urządzenie&quot; z menu kontekstowego.</translation
<source>Would you like to revert the changes?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Tray icon color:</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Change color</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>PinDialog</name>
Expand Down
5 changes: 4 additions & 1 deletion src/GUI/graphicstools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <QStyle>
#include <QProcess>
#include <QApplication>
#include <QSettings>

bool test_if_gnome(){
#ifdef Q_OS_LINUX
Expand All @@ -26,7 +27,9 @@ QPixmap GraphicsTools::loadColorize(const QString& path, bool loadForTray, bool
QColor text_color;

if (mainTrayIcon){
text_color.setRgb(255, 0, 0);
QSettings settings;
auto color = settings.value("main/tray_icon_color", "#FF0000").toString();
text_color.setNamedColor(color);
} else {
text_color = QGuiApplication::palette().color(QPalette::WindowText);
}
Expand Down
15 changes: 15 additions & 0 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ void MainWindow::load_settings_page(){
emit ui->cb_debug_enabled->toggled(settings_debug_enabled);
ui->spin_PWS_time->setValue(settings.value("clipboard/PWS_time", 60).toInt());
ui->spin_OTP_time->setValue(settings.value("clipboard/OTP_time", 120).toInt());
ui->trayIconColorEdit->setText(settings.value("main/tray_icon_color", "#FF0000").toString());

ui->cb_device_connection_message->setChecked(settings.value("main/connection_message", true).toBool());
ui->cb_show_main_window_on_connection->setChecked(settings.value("main/show_main_on_connection", true).toBool());
ui->cb_hide_main_window_on_connection->setChecked(settings.value("main/close_main_on_connection", false).toBool());
Expand Down Expand Up @@ -1876,6 +1878,9 @@ void MainWindow::on_btn_writeSettings_clicked()
settings.setValue("main/hide_on_close", ui->cb_hide_main_window_on_close->isChecked());
settings.setValue("main/show_on_start", ui->cb_show_window_on_start->isChecked());

restart_required |= ui->trayIconColorEdit->text() != settings.value("main/tray_icon_color").toString();
settings.setValue("main/tray_icon_color", ui->trayIconColorEdit->text());

settings.setValue("storage/check_symlink", ui->cb_check_symlink->isChecked());

// inform user and quit if asked
Expand Down Expand Up @@ -1931,3 +1936,13 @@ void MainWindow::on_hotpRadioButton_clicked(bool checked)
if (checked)
ui->slotComboBox->setCurrentIndex(TOTP_SlotCount + 1);
}

void MainWindow::on_btn_trayColorChange_clicked()
{
QColorDialog d;
d.setCurrentColor(ui->trayIconColorEdit->text());
auto res = d.exec();
if (res == QDialog::Accepted) {
ui->trayIconColorEdit->setText(d.currentColor().name());
}
}
2 changes: 2 additions & 0 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,8 @@ private slots:

void on_hotpRadioButton_clicked(bool checked);

void on_btn_trayColorChange_clicked();

public:
void generateOTPConfig(OTPSlot *slot);
unsigned int get_supported_secret_length_base32() const;
Expand Down
94 changes: 68 additions & 26 deletions src/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -1331,14 +1331,55 @@
</layout>
</item>
<item>
<widget class="QCheckBox" name="cb_show_main_window_on_connection">
<property name="text">
<string>Show main window when device connects</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_10">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_13">
<item>
<widget class="QLabel" name="label_8">
<property name="text">
<string>Tray icon color:</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btn_trayColorChange">
<property name="text">
<string>Change color</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="trayIconColorEdit">
<property name="sizePolicy">
<sizepolicy hsizetype="Minimum" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string notr="true">#FF0000</string>
</property>
<property name="maxLength">
<number>7</number>
</property>
<property name="placeholderText">
<string notr="true">#FF0000</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cb_show_main_window_on_connection">
<property name="text">
<string>Show main window when device connects</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="cb_check_symlink">
Expand Down Expand Up @@ -1608,22 +1649,22 @@
<x>0</x>
<y>0</y>
<width>932</width>
<height>27</height>
<height>29</height>
</rect>
</property>
</widget>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
<tabstop>btn_dial_PWS</tabstop>
<tabstop>btn_dial_EV</tabstop>
<tabstop>btn_dial_HV</tabstop>
<tabstop>btn_dial_lock</tabstop>
<tabstop>btn_dial_help</tabstop>
<tabstop>btn_dial_quit</tabstop>
<tabstop>totpRadioButton</tabstop>
<tabstop>hotpRadioButton</tabstop>
<tabstop>slotComboBox</tabstop>
<tabstop>cb_first_run_message</tabstop>
<tabstop>cb_show_window_on_start</tabstop>
<tabstop>cb_hide_main_window_on_close</tabstop>
<tabstop>cb_hide_main_window_on_connection</tabstop>
<tabstop>trayIconColorEdit</tabstop>
<tabstop>cb_show_main_window_on_connection</tabstop>
<tabstop>cb_check_symlink</tabstop>
<tabstop>cb_device_connection_message</tabstop>
<tabstop>combo_languages</tabstop>
<tabstop>nameEdit</tabstop>
<tabstop>eraseButton</tabstop>
<tabstop>base32RadioButton</tabstop>
Expand Down Expand Up @@ -1652,14 +1693,13 @@
<tabstop>PWS_Lock</tabstop>
<tabstop>PWS_ButtonClose</tabstop>
<tabstop>PWS_ButtonSaveSlot</tabstop>
<tabstop>cb_first_run_message</tabstop>
<tabstop>cb_show_window_on_start</tabstop>
<tabstop>cb_check_symlink</tabstop>
<tabstop>cb_device_connection_message</tabstop>
<tabstop>cb_show_main_window_on_connection</tabstop>
<tabstop>cb_hide_main_window_on_connection</tabstop>
<tabstop>cb_hide_main_window_on_close</tabstop>
<tabstop>combo_languages</tabstop>
<tabstop>btn_dial_PWS</tabstop>
<tabstop>btn_dial_EV</tabstop>
<tabstop>totpRadioButton</tabstop>
<tabstop>hotpRadioButton</tabstop>
<tabstop>btn_dial_lock</tabstop>
<tabstop>btn_dial_HV</tabstop>
<tabstop>slotComboBox</tabstop>
<tabstop>cb_debug_enabled</tabstop>
<tabstop>edit_debug_file_path</tabstop>
<tabstop>btn_select_debug_console</tabstop>
Expand All @@ -1675,6 +1715,8 @@
<tabstop>secret_key_generated_len</tabstop>
<tabstop>randomSecretButton</tabstop>
<tabstop>btn_copyToClipboard</tabstop>
<tabstop>btn_dial_quit</tabstop>
<tabstop>btn_dial_help</tabstop>
</tabstops>
<resources>
<include location="../../resources.qrc"/>
Expand Down

0 comments on commit 63e1b03

Please sign in to comment.