Skip to content

Commit 7c8558d

Browse files
committed
Merge #8006: Qt: Add option to disable the system tray icon
8b0e497 Qt: Add option to hide the system tray icon (Tyler Hardin)
2 parents 2efe38b + 8b0e497 commit 7c8558d

File tree

7 files changed

+65
-2
lines changed

7 files changed

+65
-2
lines changed

src/qt/bitcoingui.cpp

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,6 +474,16 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
474474
}
475475
#endif // ENABLE_WALLET
476476
unitDisplayControl->setOptionsModel(clientModel->getOptionsModel());
477+
478+
OptionsModel* optionsModel = clientModel->getOptionsModel();
479+
if(optionsModel)
480+
{
481+
// be aware of the tray icon disable state change reported by the OptionsModel object.
482+
connect(optionsModel,SIGNAL(hideTrayIconChanged(bool)),this,SLOT(setTrayIconVisible(bool)));
483+
484+
// initialize the disable state of the tray icon with the current value in the model.
485+
setTrayIconVisible(optionsModel->getHideTrayIcon());
486+
}
477487
} else {
478488
// Disable possibility to show main window via action
479489
toggleHideAction->setEnabled(false);
@@ -535,7 +545,7 @@ void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
535545
QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + networkStyle->getTitleAddText();
536546
trayIcon->setToolTip(toolTip);
537547
trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
538-
trayIcon->show();
548+
trayIcon->hide();
539549
#endif
540550

541551
notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
@@ -1044,6 +1054,14 @@ void BitcoinGUI::showProgress(const QString &title, int nProgress)
10441054
progressDialog->setValue(nProgress);
10451055
}
10461056

1057+
void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
1058+
{
1059+
if (trayIcon)
1060+
{
1061+
trayIcon->setVisible(!fHideTrayIcon);
1062+
}
1063+
}
1064+
10471065
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
10481066
{
10491067
bool modal = (style & CClientUIInterface::MODAL);

src/qt/bitcoingui.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ private Q_SLOTS:
218218

219219
/** Show progress dialog e.g. for verifychain */
220220
void showProgress(const QString &title, int nProgress);
221+
222+
/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
223+
void setTrayIconVisible(bool);
221224
};
222225

223226
class UnitDisplayStatusBarControl : public QLabel

src/qt/forms/optionsdialog.ui

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,16 @@
504504
<string>&amp;Window</string>
505505
</attribute>
506506
<layout class="QVBoxLayout" name="verticalLayout_Window">
507+
<item>
508+
<widget class="QCheckBox" name="hideTrayIcon">
509+
<property name="toolTip">
510+
<string>&amp;Hide the icon from the system tray.</string>
511+
</property>
512+
<property name="text">
513+
<string>Hide tray icon</string>
514+
</property>
515+
</widget>
516+
</item>
507517
<item>
508518
<widget class="QCheckBox" name="minimizeToTray">
509519
<property name="toolTip">

src/qt/optionsdialog.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ void OptionsDialog::setMapper()
198198

199199
/* Window */
200200
#ifndef Q_OS_MAC
201+
mapper->addMapping(ui->hideTrayIcon, OptionsModel::HideTrayIcon);
201202
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
202203
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
203204
#endif
@@ -243,6 +244,19 @@ void OptionsDialog::on_cancelButton_clicked()
243244
reject();
244245
}
245246

247+
void OptionsDialog::on_hideTrayIcon_stateChanged(int fState)
248+
{
249+
if(fState)
250+
{
251+
ui->minimizeToTray->setChecked(false);
252+
ui->minimizeToTray->setEnabled(false);
253+
}
254+
else
255+
{
256+
ui->minimizeToTray->setEnabled(true);
257+
}
258+
}
259+
246260
void OptionsDialog::showRestartWarning(bool fPersistent)
247261
{
248262
ui->statusLabel->setStyleSheet("QLabel { color: red; }");

src/qt/optionsdialog.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ private Q_SLOTS:
4949
void on_resetButton_clicked();
5050
void on_okButton_clicked();
5151
void on_cancelButton_clicked();
52+
53+
void on_hideTrayIcon_stateChanged(int fState);
5254

5355
void showRestartWarning(bool fPersistent = false);
5456
void clearStatusLabel();

src/qt/optionsmodel.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,14 @@ void OptionsModel::Init(bool resetSettings)
5151
// These are Qt-only settings:
5252

5353
// Window
54+
if (!settings.contains("fHideTrayIcon"))
55+
settings.setValue("fHideTrayIcon", false);
56+
fHideTrayIcon = settings.value("fHideTrayIcon").toBool();
57+
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
58+
5459
if (!settings.contains("fMinimizeToTray"))
5560
settings.setValue("fMinimizeToTray", false);
56-
fMinimizeToTray = settings.value("fMinimizeToTray").toBool();
61+
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && !fHideTrayIcon;
5762

5863
if (!settings.contains("fMinimizeOnClose"))
5964
settings.setValue("fMinimizeOnClose", false);
@@ -166,6 +171,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
166171
{
167172
case StartAtStartup:
168173
return GUIUtil::GetStartOnSystemStartup();
174+
case HideTrayIcon:
175+
return fHideTrayIcon;
169176
case MinimizeToTray:
170177
return fMinimizeToTray;
171178
case MapPortUPnP:
@@ -242,6 +249,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
242249
case StartAtStartup:
243250
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
244251
break;
252+
case HideTrayIcon:
253+
fHideTrayIcon = value.toBool();
254+
settings.setValue("fHideTrayIcon", fHideTrayIcon);
255+
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
256+
break;
245257
case MinimizeToTray:
246258
fMinimizeToTray = value.toBool();
247259
settings.setValue("fMinimizeToTray", fMinimizeToTray);

src/qt/optionsmodel.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class OptionsModel : public QAbstractListModel
2828

2929
enum OptionID {
3030
StartAtStartup, // bool
31+
HideTrayIcon, // bool
3132
MinimizeToTray, // bool
3233
MapPortUPnP, // bool
3334
MinimizeOnClose, // bool
@@ -58,6 +59,7 @@ class OptionsModel : public QAbstractListModel
5859
void setDisplayUnit(const QVariant &value);
5960

6061
/* Explicit getters */
62+
bool getHideTrayIcon() { return fHideTrayIcon; }
6163
bool getMinimizeToTray() { return fMinimizeToTray; }
6264
bool getMinimizeOnClose() { return fMinimizeOnClose; }
6365
int getDisplayUnit() { return nDisplayUnit; }
@@ -72,6 +74,7 @@ class OptionsModel : public QAbstractListModel
7274

7375
private:
7476
/* Qt-only settings */
77+
bool fHideTrayIcon;
7578
bool fMinimizeToTray;
7679
bool fMinimizeOnClose;
7780
QString language;
@@ -87,6 +90,7 @@ class OptionsModel : public QAbstractListModel
8790
Q_SIGNALS:
8891
void displayUnitChanged(int unit);
8992
void coinControlFeaturesChanged(bool);
93+
void hideTrayIconChanged(bool);
9094
};
9195

9296
#endif // BITCOIN_QT_OPTIONSMODEL_H

0 commit comments

Comments
 (0)