mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-02-02 09:46:52 -05:00
Qt: Add option to hide the system tray icon
My changes leave all tray icon and menu creation/initialization logic untouched. It only shows or hides the icon according to the setting. A new checkbox was added to the OptionsDialog under the Window tab. A bool option named "hideTrayIcon" was added to OptionsModel. This checkbox was mapped like other all options to the OptionsModel. A signal was added to the OptionsModel for broadcasting changes the the hideTrayIcon option. This signal was connected to a new slot added to BitcoinGUI named setTrayIconVisible(bool). The slot simply hides or shows the trayIcon in BitcoinGUI according to the parameter recieved.
This commit is contained in:
parent
42a6753382
commit
8b0e497028
7 changed files with 65 additions and 2 deletions
|
@ -474,6 +474,16 @@ void BitcoinGUI::setClientModel(ClientModel *clientModel)
|
||||||
}
|
}
|
||||||
#endif // ENABLE_WALLET
|
#endif // ENABLE_WALLET
|
||||||
unitDisplayControl->setOptionsModel(clientModel->getOptionsModel());
|
unitDisplayControl->setOptionsModel(clientModel->getOptionsModel());
|
||||||
|
|
||||||
|
OptionsModel* optionsModel = clientModel->getOptionsModel();
|
||||||
|
if(optionsModel)
|
||||||
|
{
|
||||||
|
// be aware of the tray icon disable state change reported by the OptionsModel object.
|
||||||
|
connect(optionsModel,SIGNAL(hideTrayIconChanged(bool)),this,SLOT(setTrayIconVisible(bool)));
|
||||||
|
|
||||||
|
// initialize the disable state of the tray icon with the current value in the model.
|
||||||
|
setTrayIconVisible(optionsModel->getHideTrayIcon());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// Disable possibility to show main window via action
|
// Disable possibility to show main window via action
|
||||||
toggleHideAction->setEnabled(false);
|
toggleHideAction->setEnabled(false);
|
||||||
|
@ -535,7 +545,7 @@ void BitcoinGUI::createTrayIcon(const NetworkStyle *networkStyle)
|
||||||
QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + networkStyle->getTitleAddText();
|
QString toolTip = tr("%1 client").arg(tr(PACKAGE_NAME)) + " " + networkStyle->getTitleAddText();
|
||||||
trayIcon->setToolTip(toolTip);
|
trayIcon->setToolTip(toolTip);
|
||||||
trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
|
trayIcon->setIcon(networkStyle->getTrayAndWindowIcon());
|
||||||
trayIcon->show();
|
trayIcon->hide();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
|
notificator = new Notificator(QApplication::applicationName(), trayIcon, this);
|
||||||
|
@ -1044,6 +1054,14 @@ void BitcoinGUI::showProgress(const QString &title, int nProgress)
|
||||||
progressDialog->setValue(nProgress);
|
progressDialog->setValue(nProgress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
|
||||||
|
{
|
||||||
|
if (trayIcon)
|
||||||
|
{
|
||||||
|
trayIcon->setVisible(!fHideTrayIcon);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
|
static bool ThreadSafeMessageBox(BitcoinGUI *gui, const std::string& message, const std::string& caption, unsigned int style)
|
||||||
{
|
{
|
||||||
bool modal = (style & CClientUIInterface::MODAL);
|
bool modal = (style & CClientUIInterface::MODAL);
|
||||||
|
|
|
@ -218,6 +218,9 @@ private Q_SLOTS:
|
||||||
|
|
||||||
/** Show progress dialog e.g. for verifychain */
|
/** Show progress dialog e.g. for verifychain */
|
||||||
void showProgress(const QString &title, int nProgress);
|
void showProgress(const QString &title, int nProgress);
|
||||||
|
|
||||||
|
/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
|
||||||
|
void setTrayIconVisible(bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
class UnitDisplayStatusBarControl : public QLabel
|
class UnitDisplayStatusBarControl : public QLabel
|
||||||
|
|
|
@ -504,6 +504,16 @@
|
||||||
<string>&Window</string>
|
<string>&Window</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_Window">
|
<layout class="QVBoxLayout" name="verticalLayout_Window">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="hideTrayIcon">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>&Hide the icon from the system tray.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Hide tray icon</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="minimizeToTray">
|
<widget class="QCheckBox" name="minimizeToTray">
|
||||||
<property name="toolTip">
|
<property name="toolTip">
|
||||||
|
|
|
@ -198,6 +198,7 @@ void OptionsDialog::setMapper()
|
||||||
|
|
||||||
/* Window */
|
/* Window */
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
|
mapper->addMapping(ui->hideTrayIcon, OptionsModel::HideTrayIcon);
|
||||||
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
|
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
|
||||||
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
|
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
|
||||||
#endif
|
#endif
|
||||||
|
@ -243,6 +244,19 @@ void OptionsDialog::on_cancelButton_clicked()
|
||||||
reject();
|
reject();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OptionsDialog::on_hideTrayIcon_stateChanged(int fState)
|
||||||
|
{
|
||||||
|
if(fState)
|
||||||
|
{
|
||||||
|
ui->minimizeToTray->setChecked(false);
|
||||||
|
ui->minimizeToTray->setEnabled(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ui->minimizeToTray->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OptionsDialog::showRestartWarning(bool fPersistent)
|
void OptionsDialog::showRestartWarning(bool fPersistent)
|
||||||
{
|
{
|
||||||
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
ui->statusLabel->setStyleSheet("QLabel { color: red; }");
|
||||||
|
|
|
@ -49,6 +49,8 @@ private Q_SLOTS:
|
||||||
void on_resetButton_clicked();
|
void on_resetButton_clicked();
|
||||||
void on_okButton_clicked();
|
void on_okButton_clicked();
|
||||||
void on_cancelButton_clicked();
|
void on_cancelButton_clicked();
|
||||||
|
|
||||||
|
void on_hideTrayIcon_stateChanged(int fState);
|
||||||
|
|
||||||
void showRestartWarning(bool fPersistent = false);
|
void showRestartWarning(bool fPersistent = false);
|
||||||
void clearStatusLabel();
|
void clearStatusLabel();
|
||||||
|
|
|
@ -51,9 +51,14 @@ void OptionsModel::Init(bool resetSettings)
|
||||||
// These are Qt-only settings:
|
// These are Qt-only settings:
|
||||||
|
|
||||||
// Window
|
// Window
|
||||||
|
if (!settings.contains("fHideTrayIcon"))
|
||||||
|
settings.setValue("fHideTrayIcon", false);
|
||||||
|
fHideTrayIcon = settings.value("fHideTrayIcon").toBool();
|
||||||
|
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
|
||||||
|
|
||||||
if (!settings.contains("fMinimizeToTray"))
|
if (!settings.contains("fMinimizeToTray"))
|
||||||
settings.setValue("fMinimizeToTray", false);
|
settings.setValue("fMinimizeToTray", false);
|
||||||
fMinimizeToTray = settings.value("fMinimizeToTray").toBool();
|
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && !fHideTrayIcon;
|
||||||
|
|
||||||
if (!settings.contains("fMinimizeOnClose"))
|
if (!settings.contains("fMinimizeOnClose"))
|
||||||
settings.setValue("fMinimizeOnClose", false);
|
settings.setValue("fMinimizeOnClose", false);
|
||||||
|
@ -166,6 +171,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
|
||||||
{
|
{
|
||||||
case StartAtStartup:
|
case StartAtStartup:
|
||||||
return GUIUtil::GetStartOnSystemStartup();
|
return GUIUtil::GetStartOnSystemStartup();
|
||||||
|
case HideTrayIcon:
|
||||||
|
return fHideTrayIcon;
|
||||||
case MinimizeToTray:
|
case MinimizeToTray:
|
||||||
return fMinimizeToTray;
|
return fMinimizeToTray;
|
||||||
case MapPortUPnP:
|
case MapPortUPnP:
|
||||||
|
@ -242,6 +249,11 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
|
||||||
case StartAtStartup:
|
case StartAtStartup:
|
||||||
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
|
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
|
||||||
break;
|
break;
|
||||||
|
case HideTrayIcon:
|
||||||
|
fHideTrayIcon = value.toBool();
|
||||||
|
settings.setValue("fHideTrayIcon", fHideTrayIcon);
|
||||||
|
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
|
||||||
|
break;
|
||||||
case MinimizeToTray:
|
case MinimizeToTray:
|
||||||
fMinimizeToTray = value.toBool();
|
fMinimizeToTray = value.toBool();
|
||||||
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
settings.setValue("fMinimizeToTray", fMinimizeToTray);
|
||||||
|
|
|
@ -28,6 +28,7 @@ public:
|
||||||
|
|
||||||
enum OptionID {
|
enum OptionID {
|
||||||
StartAtStartup, // bool
|
StartAtStartup, // bool
|
||||||
|
HideTrayIcon, // bool
|
||||||
MinimizeToTray, // bool
|
MinimizeToTray, // bool
|
||||||
MapPortUPnP, // bool
|
MapPortUPnP, // bool
|
||||||
MinimizeOnClose, // bool
|
MinimizeOnClose, // bool
|
||||||
|
@ -58,6 +59,7 @@ public:
|
||||||
void setDisplayUnit(const QVariant &value);
|
void setDisplayUnit(const QVariant &value);
|
||||||
|
|
||||||
/* Explicit getters */
|
/* Explicit getters */
|
||||||
|
bool getHideTrayIcon() { return fHideTrayIcon; }
|
||||||
bool getMinimizeToTray() { return fMinimizeToTray; }
|
bool getMinimizeToTray() { return fMinimizeToTray; }
|
||||||
bool getMinimizeOnClose() { return fMinimizeOnClose; }
|
bool getMinimizeOnClose() { return fMinimizeOnClose; }
|
||||||
int getDisplayUnit() { return nDisplayUnit; }
|
int getDisplayUnit() { return nDisplayUnit; }
|
||||||
|
@ -72,6 +74,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/* Qt-only settings */
|
/* Qt-only settings */
|
||||||
|
bool fHideTrayIcon;
|
||||||
bool fMinimizeToTray;
|
bool fMinimizeToTray;
|
||||||
bool fMinimizeOnClose;
|
bool fMinimizeOnClose;
|
||||||
QString language;
|
QString language;
|
||||||
|
@ -87,6 +90,7 @@ private:
|
||||||
Q_SIGNALS:
|
Q_SIGNALS:
|
||||||
void displayUnitChanged(int unit);
|
void displayUnitChanged(int unit);
|
||||||
void coinControlFeaturesChanged(bool);
|
void coinControlFeaturesChanged(bool);
|
||||||
|
void hideTrayIconChanged(bool);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // BITCOIN_QT_OPTIONSMODEL_H
|
#endif // BITCOIN_QT_OPTIONSMODEL_H
|
||||||
|
|
Loading…
Add table
Reference in a new issue