Skip to content

Commit a2f190d

Browse files
jonasschnelliknst
authored andcommitted
Merge bitcoin-core/gui#115: Replace "Hide tray icon" option with positive "Show tray icon" one
03edb52 qt: Remove redundant BitcoinGUI::setTrayIconVisible (Hennadii Stepanov) 17174f8 gui: Replace "Hide tray icon" option with positive "Show tray icon" one (Hennadii Stepanov) Pull request description: This change makes easier both (1) using this option, and (2) reasoning about the code. ACKs for top commit: jonasschnelli: utACK 03edb52 Tree-SHA512: 38e317492210d4fb13302dea383bd1f4f0ae1219d7ff2fdcb78607f15ac61a51969acaadb59b72c3f075b6356ef54368eb46fb49e6e1bd42db6d5804b97e232b
1 parent 65b80e7 commit a2f190d

File tree

7 files changed

+32
-42
lines changed

7 files changed

+32
-42
lines changed

src/qt/bitcoingui.cpp

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -842,10 +842,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
842842
OptionsModel* optionsModel = _clientModel->getOptionsModel();
843843
if (optionsModel && trayIcon) {
844844
// be aware of the tray icon disable state change reported by the OptionsModel object.
845-
connect(optionsModel, &OptionsModel::hideTrayIconChanged, this, &BitcoinGUI::setTrayIconVisible);
845+
connect(optionsModel, &OptionsModel::showTrayIconChanged, trayIcon, &QSystemTrayIcon::setVisible);
846846

847847
// initialize the disable state of the tray icon with the current value in the model.
848-
setTrayIconVisible(optionsModel->getHideTrayIcon());
848+
trayIcon->setVisible(optionsModel->getShowTrayIcon());
849849

850850
connect(optionsModel, &OptionsModel::coinJoinEnabledChanged, this, &BitcoinGUI::updateCoinJoinVisibility);
851851
}
@@ -1965,14 +1965,6 @@ void BitcoinGUI::showProgress(const QString &title, int nProgress)
19651965
}
19661966
}
19671967

1968-
void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
1969-
{
1970-
if (trayIcon)
1971-
{
1972-
trayIcon->setVisible(!fHideTrayIcon);
1973-
}
1974-
}
1975-
19761968
void BitcoinGUI::showModalOverlay()
19771969
{
19781970
if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))

src/qt/bitcoingui.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,6 @@ public Q_SLOTS:
388388
/** Show progress dialog e.g. for verifychain */
389389
void showProgress(const QString &title, int nProgress);
390390

391-
/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
392-
void setTrayIconVisible(bool);
393-
394391
void showModalOverlay();
395392

396393
void updateCoinJoinVisibility();

src/qt/forms/optionsdialog.ui

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,13 +130,16 @@
130130
</spacer>
131131
</item>
132132
<item>
133-
<widget class="QCheckBox" name="hideTrayIcon">
133+
<widget class="QCheckBox" name="showTrayIcon">
134134
<property name="toolTip">
135-
<string>Hide the icon from the system tray.</string>
135+
<string>Show the icon in the system tray.</string>
136136
</property>
137137
<property name="text">
138-
<string>&amp;Hide tray icon</string>
138+
<string>&amp;Show tray icon</string>
139139
</property>
140+
<property name="checked">
141+
<bool>true</bool>
142+
</property>
140143
</widget>
141144
</item>
142145
<item>

src/qt/optionsdialog.cpp

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
5252

5353
#ifdef Q_OS_MAC
5454
/* Hide some options on Mac */
55-
ui->hideTrayIcon->hide();
55+
ui->showTrayIcon->hide();
5656
ui->minimizeToTray->hide();
5757
ui->minimizeOnClose->hide();
5858
#endif
@@ -198,8 +198,8 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
198198
});
199199

200200
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
201-
ui->hideTrayIcon->setChecked(true);
202-
ui->hideTrayIcon->setEnabled(false);
201+
ui->showTrayIcon->setChecked(false);
202+
ui->showTrayIcon->setEnabled(false);
203203
ui->minimizeToTray->setChecked(false);
204204
ui->minimizeToTray->setEnabled(false);
205205
}
@@ -312,7 +312,7 @@ void OptionsDialog::setMapper()
312312
mapper->addMapping(ui->bitcoinAtStartup, OptionsModel::StartAtStartup);
313313
#ifndef Q_OS_MAC
314314
if (QSystemTrayIcon::isSystemTrayAvailable()) {
315-
mapper->addMapping(ui->hideTrayIcon, OptionsModel::HideTrayIcon);
315+
mapper->addMapping(ui->showTrayIcon, OptionsModel::ShowTrayIcon);
316316
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
317317
}
318318
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
@@ -426,17 +426,14 @@ void OptionsDialog::on_cancelButton_clicked()
426426
reject();
427427
}
428428

429-
void OptionsDialog::on_hideTrayIcon_stateChanged(int fState)
429+
void OptionsDialog::on_showTrayIcon_stateChanged(int state)
430430
{
431-
if(fState)
432-
{
431+
if (state == Qt::Checked) {
432+
ui->minimizeToTray->setEnabled(true);
433+
} else {
433434
ui->minimizeToTray->setChecked(false);
434435
ui->minimizeToTray->setEnabled(false);
435436
}
436-
else
437-
{
438-
ui->minimizeToTray->setEnabled(true);
439-
}
440437
}
441438

442439
void OptionsDialog::togglePruneWarning(bool enabled)

src/qt/optionsdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ private Q_SLOTS:
6464
void on_okButton_clicked();
6565
void on_cancelButton_clicked();
6666

67-
void on_hideTrayIcon_stateChanged(int fState);
67+
void on_showTrayIcon_stateChanged(int state);
6868

6969
void togglePruneWarning(bool enabled);
7070
void showRestartWarning(bool fPersistent = false);

src/qt/optionsmodel.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,15 @@ void OptionsModel::Init(bool resetSettings)
6060
// These are Qt-only settings:
6161

6262
// Window
63-
if (!settings.contains("fHideTrayIcon"))
63+
if (!settings.contains("fHideTrayIcon")) {
6464
settings.setValue("fHideTrayIcon", false);
65-
fHideTrayIcon = settings.value("fHideTrayIcon").toBool();
66-
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
65+
}
66+
m_show_tray_icon = !settings.value("fHideTrayIcon").toBool();
67+
Q_EMIT showTrayIconChanged(m_show_tray_icon);
6768

6869
if (!settings.contains("fMinimizeToTray"))
6970
settings.setValue("fMinimizeToTray", false);
70-
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && !fHideTrayIcon;
71+
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && m_show_tray_icon;
7172

7273
if (!settings.contains("fMinimizeOnClose"))
7374
settings.setValue("fMinimizeOnClose", false);
@@ -417,8 +418,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
417418
{
418419
case StartAtStartup:
419420
return GUIUtil::GetStartOnSystemStartup();
420-
case HideTrayIcon:
421-
return fHideTrayIcon;
421+
case ShowTrayIcon:
422+
return m_show_tray_icon;
422423
case MinimizeToTray:
423424
return fMinimizeToTray;
424425
case MapPortUPnP:
@@ -545,10 +546,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
545546
case StartAtStartup:
546547
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
547548
break;
548-
case HideTrayIcon:
549-
fHideTrayIcon = value.toBool();
550-
settings.setValue("fHideTrayIcon", fHideTrayIcon);
551-
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
549+
case ShowTrayIcon:
550+
m_show_tray_icon = value.toBool();
551+
settings.setValue("fHideTrayIcon", !m_show_tray_icon);
552+
Q_EMIT showTrayIconChanged(m_show_tray_icon);
552553
break;
553554
case MinimizeToTray:
554555
fMinimizeToTray = value.toBool();

src/qt/optionsmodel.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class OptionsModel : public QAbstractListModel
4646

4747
enum OptionID {
4848
StartAtStartup, // bool
49-
HideTrayIcon, // bool
49+
ShowTrayIcon, // bool
5050
MinimizeToTray, // bool
5151
MapPortUPnP, // bool
5252
MapPortNatpmp, // bool
@@ -99,7 +99,7 @@ class OptionsModel : public QAbstractListModel
9999
void setDisplayUnit(const QVariant &value);
100100

101101
/* Explicit getters */
102-
bool getHideTrayIcon() const { return fHideTrayIcon; }
102+
bool getShowTrayIcon() const { return m_show_tray_icon; }
103103
bool getMinimizeToTray() const { return fMinimizeToTray; }
104104
bool getMinimizeOnClose() const { return fMinimizeOnClose; }
105105
int getDisplayUnit() const { return nDisplayUnit; }
@@ -125,7 +125,7 @@ class OptionsModel : public QAbstractListModel
125125
private:
126126
interfaces::Node* m_node = nullptr;
127127
/* Qt-only settings */
128-
bool fHideTrayIcon;
128+
bool m_show_tray_icon;
129129
bool fMinimizeToTray;
130130
bool fMinimizeOnClose;
131131
QString language;
@@ -150,7 +150,7 @@ class OptionsModel : public QAbstractListModel
150150
void AdvancedCJUIChanged(bool);
151151
void coinControlFeaturesChanged(bool);
152152
void keepChangeAddressChanged(bool);
153-
void hideTrayIconChanged(bool);
153+
void showTrayIconChanged(bool);
154154
};
155155

156156
#endif // BITCOIN_QT_OPTIONSMODEL_H

0 commit comments

Comments
 (0)