Skip to content

Commit 33d6337

Browse files
committed
Merge bitcoin-core#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
2 parents 94a9cd2 + 03edb52 commit 33d6337

File tree

7 files changed

+31
-41
lines changed

7 files changed

+31
-41
lines changed

src/qt/bitcoingui.cpp

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

620620
// initialize the disable state of the tray icon with the current value in the model.
621-
setTrayIconVisible(optionsModel->getHideTrayIcon());
621+
trayIcon->setVisible(optionsModel->getShowTrayIcon());
622622
}
623623
} else {
624624
// Disable possibility to show main window via action
@@ -1387,14 +1387,6 @@ void BitcoinGUI::showProgress(const QString &title, int nProgress)
13871387
}
13881388
}
13891389

1390-
void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
1391-
{
1392-
if (trayIcon)
1393-
{
1394-
trayIcon->setVisible(!fHideTrayIcon);
1395-
}
1396-
}
1397-
13981390
void BitcoinGUI::showModalOverlay()
13991391
{
14001392
if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))

src/qt/bitcoingui.h

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

321-
/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
322-
void setTrayIconVisible(bool);
323-
324321
void showModalOverlay();
325322
};
326323

src/qt/forms/optionsdialog.ui

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -568,12 +568,15 @@
568568
</attribute>
569569
<layout class="QVBoxLayout" name="verticalLayout_Window">
570570
<item>
571-
<widget class="QCheckBox" name="hideTrayIcon">
571+
<widget class="QCheckBox" name="showTrayIcon">
572572
<property name="toolTip">
573-
<string>Hide the icon from the system tray.</string>
573+
<string>Show the icon in the system tray.</string>
574574
</property>
575575
<property name="text">
576-
<string>&amp;Hide tray icon</string>
576+
<string>&amp;Show tray icon</string>
577+
</property>
578+
<property name="checked">
579+
<bool>true</bool>
577580
</property>
578581
</widget>
579582
</item>

src/qt/optionsdialog.cpp

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,8 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
130130
connect(ui->proxyPortTor, &QLineEdit::textChanged, this, &OptionsDialog::updateProxyValidationState);
131131

132132
if (!QSystemTrayIcon::isSystemTrayAvailable()) {
133-
ui->hideTrayIcon->setChecked(true);
134-
ui->hideTrayIcon->setEnabled(false);
133+
ui->showTrayIcon->setChecked(false);
134+
ui->showTrayIcon->setEnabled(false);
135135
ui->minimizeToTray->setChecked(false);
136136
ui->minimizeToTray->setEnabled(false);
137137
}
@@ -227,7 +227,7 @@ void OptionsDialog::setMapper()
227227
/* Window */
228228
#ifndef Q_OS_MAC
229229
if (QSystemTrayIcon::isSystemTrayAvailable()) {
230-
mapper->addMapping(ui->hideTrayIcon, OptionsModel::HideTrayIcon);
230+
mapper->addMapping(ui->showTrayIcon, OptionsModel::ShowTrayIcon);
231231
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
232232
}
233233
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
@@ -286,17 +286,14 @@ void OptionsDialog::on_cancelButton_clicked()
286286
reject();
287287
}
288288

289-
void OptionsDialog::on_hideTrayIcon_stateChanged(int fState)
289+
void OptionsDialog::on_showTrayIcon_stateChanged(int state)
290290
{
291-
if(fState)
292-
{
291+
if (state == Qt::Checked) {
292+
ui->minimizeToTray->setEnabled(true);
293+
} else {
293294
ui->minimizeToTray->setChecked(false);
294295
ui->minimizeToTray->setEnabled(false);
295296
}
296-
else
297-
{
298-
ui->minimizeToTray->setEnabled(true);
299-
}
300297
}
301298

302299
void OptionsDialog::togglePruneWarning(bool enabled)

src/qt/optionsdialog.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ private Q_SLOTS:
5757
void on_okButton_clicked();
5858
void on_cancelButton_clicked();
5959

60-
void on_hideTrayIcon_stateChanged(int fState);
60+
void on_showTrayIcon_stateChanged(int state);
6161

6262
void togglePruneWarning(bool enabled);
6363
void showRestartWarning(bool fPersistent = false);

src/qt/optionsmodel.cpp

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

5656
// Window
57-
if (!settings.contains("fHideTrayIcon"))
57+
if (!settings.contains("fHideTrayIcon")) {
5858
settings.setValue("fHideTrayIcon", false);
59-
fHideTrayIcon = settings.value("fHideTrayIcon").toBool();
60-
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
59+
}
60+
m_show_tray_icon = !settings.value("fHideTrayIcon").toBool();
61+
Q_EMIT showTrayIconChanged(m_show_tray_icon);
6162

6263
if (!settings.contains("fMinimizeToTray"))
6364
settings.setValue("fMinimizeToTray", false);
64-
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && !fHideTrayIcon;
65+
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && m_show_tray_icon;
6566

6667
if (!settings.contains("fMinimizeOnClose"))
6768
settings.setValue("fMinimizeOnClose", false);
@@ -272,8 +273,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
272273
{
273274
case StartAtStartup:
274275
return GUIUtil::GetStartOnSystemStartup();
275-
case HideTrayIcon:
276-
return fHideTrayIcon;
276+
case ShowTrayIcon:
277+
return m_show_tray_icon;
277278
case MinimizeToTray:
278279
return fMinimizeToTray;
279280
case MapPortUPnP:
@@ -342,10 +343,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
342343
case StartAtStartup:
343344
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
344345
break;
345-
case HideTrayIcon:
346-
fHideTrayIcon = value.toBool();
347-
settings.setValue("fHideTrayIcon", fHideTrayIcon);
348-
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
346+
case ShowTrayIcon:
347+
m_show_tray_icon = value.toBool();
348+
settings.setValue("fHideTrayIcon", !m_show_tray_icon);
349+
Q_EMIT showTrayIconChanged(m_show_tray_icon);
349350
break;
350351
case MinimizeToTray:
351352
fMinimizeToTray = value.toBool();

src/qt/optionsmodel.h

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

4646
enum OptionID {
4747
StartAtStartup, // bool
48-
HideTrayIcon, // bool
48+
ShowTrayIcon, // bool
4949
MinimizeToTray, // bool
5050
MapPortUPnP, // bool
5151
MinimizeOnClose, // bool
@@ -78,7 +78,7 @@ class OptionsModel : public QAbstractListModel
7878
void setDisplayUnit(const QVariant &value);
7979

8080
/* Explicit getters */
81-
bool getHideTrayIcon() const { return fHideTrayIcon; }
81+
bool getShowTrayIcon() const { return m_show_tray_icon; }
8282
bool getMinimizeToTray() const { return fMinimizeToTray; }
8383
bool getMinimizeOnClose() const { return fMinimizeOnClose; }
8484
int getDisplayUnit() const { return nDisplayUnit; }
@@ -100,7 +100,7 @@ class OptionsModel : public QAbstractListModel
100100
private:
101101
interfaces::Node* m_node = nullptr;
102102
/* Qt-only settings */
103-
bool fHideTrayIcon;
103+
bool m_show_tray_icon;
104104
bool fMinimizeToTray;
105105
bool fMinimizeOnClose;
106106
QString language;
@@ -118,7 +118,7 @@ class OptionsModel : public QAbstractListModel
118118
Q_SIGNALS:
119119
void displayUnitChanged(int unit);
120120
void coinControlFeaturesChanged(bool);
121-
void hideTrayIconChanged(bool);
121+
void showTrayIconChanged(bool);
122122
};
123123

124124
#endif // BITCOIN_QT_OPTIONSMODEL_H

0 commit comments

Comments
 (0)