Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace "Hide tray icon" option with positive "Show tray icon" one #115

Merged
merged 2 commits into from
Dec 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions src/qt/bitcoingui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -615,10 +615,10 @@ void BitcoinGUI::setClientModel(ClientModel *_clientModel, interfaces::BlockAndH
OptionsModel* optionsModel = _clientModel->getOptionsModel();
if (optionsModel && trayIcon) {
// be aware of the tray icon disable state change reported by the OptionsModel object.
connect(optionsModel, &OptionsModel::hideTrayIconChanged, this, &BitcoinGUI::setTrayIconVisible);
connect(optionsModel, &OptionsModel::showTrayIconChanged, trayIcon, &QSystemTrayIcon::setVisible);

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

void BitcoinGUI::setTrayIconVisible(bool fHideTrayIcon)
{
if (trayIcon)
{
trayIcon->setVisible(!fHideTrayIcon);
}
}

void BitcoinGUI::showModalOverlay()
{
if (modalOverlay && (progressBar->isVisible() || modalOverlay->isLayerVisible()))
Expand Down
3 changes: 0 additions & 3 deletions src/qt/bitcoingui.h
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,6 @@ public Q_SLOTS:
/** Show progress dialog e.g. for verifychain */
void showProgress(const QString &title, int nProgress);

/** When hideTrayIcon setting is changed in OptionsModel hide or show the icon accordingly. */
void setTrayIconVisible(bool);

void showModalOverlay();
};

Expand Down
9 changes: 6 additions & 3 deletions src/qt/forms/optionsdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -568,12 +568,15 @@
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_Window">
<item>
<widget class="QCheckBox" name="hideTrayIcon">
<widget class="QCheckBox" name="showTrayIcon">
<property name="toolTip">
<string>Hide the icon from the system tray.</string>
<string>Show the icon in the system tray.</string>
</property>
<property name="text">
<string>&amp;Hide tray icon</string>
<string>&amp;Show tray icon</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
Expand Down
17 changes: 7 additions & 10 deletions src/qt/optionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,8 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
connect(ui->proxyPortTor, &QLineEdit::textChanged, this, &OptionsDialog::updateProxyValidationState);

if (!QSystemTrayIcon::isSystemTrayAvailable()) {
ui->hideTrayIcon->setChecked(true);
ui->hideTrayIcon->setEnabled(false);
ui->showTrayIcon->setChecked(false);
ui->showTrayIcon->setEnabled(false);
ui->minimizeToTray->setChecked(false);
ui->minimizeToTray->setEnabled(false);
}
Expand Down Expand Up @@ -227,7 +227,7 @@ void OptionsDialog::setMapper()
/* Window */
#ifndef Q_OS_MAC
if (QSystemTrayIcon::isSystemTrayAvailable()) {
mapper->addMapping(ui->hideTrayIcon, OptionsModel::HideTrayIcon);
mapper->addMapping(ui->showTrayIcon, OptionsModel::ShowTrayIcon);
mapper->addMapping(ui->minimizeToTray, OptionsModel::MinimizeToTray);
}
mapper->addMapping(ui->minimizeOnClose, OptionsModel::MinimizeOnClose);
Expand Down Expand Up @@ -286,17 +286,14 @@ void OptionsDialog::on_cancelButton_clicked()
reject();
}

void OptionsDialog::on_hideTrayIcon_stateChanged(int fState)
void OptionsDialog::on_showTrayIcon_stateChanged(int state)
{
if(fState)
{
if (state == Qt::Checked) {
ui->minimizeToTray->setEnabled(true);
} else {
ui->minimizeToTray->setChecked(false);
ui->minimizeToTray->setEnabled(false);
}
else
{
ui->minimizeToTray->setEnabled(true);
}
}

void OptionsDialog::togglePruneWarning(bool enabled)
Expand Down
2 changes: 1 addition & 1 deletion src/qt/optionsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private Q_SLOTS:
void on_okButton_clicked();
void on_cancelButton_clicked();

void on_hideTrayIcon_stateChanged(int fState);
void on_showTrayIcon_stateChanged(int state);

void togglePruneWarning(bool enabled);
void showRestartWarning(bool fPersistent = false);
Expand Down
21 changes: 11 additions & 10 deletions src/qt/optionsmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,15 @@ void OptionsModel::Init(bool resetSettings)
// These are Qt-only settings:

// Window
if (!settings.contains("fHideTrayIcon"))
if (!settings.contains("fHideTrayIcon")) {
settings.setValue("fHideTrayIcon", false);
fHideTrayIcon = settings.value("fHideTrayIcon").toBool();
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
}
m_show_tray_icon = !settings.value("fHideTrayIcon").toBool();
Q_EMIT showTrayIconChanged(m_show_tray_icon);

if (!settings.contains("fMinimizeToTray"))
settings.setValue("fMinimizeToTray", false);
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && !fHideTrayIcon;
fMinimizeToTray = settings.value("fMinimizeToTray").toBool() && m_show_tray_icon;

if (!settings.contains("fMinimizeOnClose"))
settings.setValue("fMinimizeOnClose", false);
Expand Down Expand Up @@ -272,8 +273,8 @@ QVariant OptionsModel::data(const QModelIndex & index, int role) const
{
case StartAtStartup:
return GUIUtil::GetStartOnSystemStartup();
case HideTrayIcon:
return fHideTrayIcon;
case ShowTrayIcon:
return m_show_tray_icon;
case MinimizeToTray:
return fMinimizeToTray;
case MapPortUPnP:
Expand Down Expand Up @@ -342,10 +343,10 @@ bool OptionsModel::setData(const QModelIndex & index, const QVariant & value, in
case StartAtStartup:
successful = GUIUtil::SetStartOnSystemStartup(value.toBool());
break;
case HideTrayIcon:
fHideTrayIcon = value.toBool();
settings.setValue("fHideTrayIcon", fHideTrayIcon);
Q_EMIT hideTrayIconChanged(fHideTrayIcon);
case ShowTrayIcon:
m_show_tray_icon = value.toBool();
settings.setValue("fHideTrayIcon", !m_show_tray_icon);
Q_EMIT showTrayIconChanged(m_show_tray_icon);
break;
case MinimizeToTray:
fMinimizeToTray = value.toBool();
Expand Down
8 changes: 4 additions & 4 deletions src/qt/optionsmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class OptionsModel : public QAbstractListModel

enum OptionID {
StartAtStartup, // bool
HideTrayIcon, // bool
ShowTrayIcon, // bool
MinimizeToTray, // bool
MapPortUPnP, // bool
MinimizeOnClose, // bool
Expand Down Expand Up @@ -78,7 +78,7 @@ class OptionsModel : public QAbstractListModel
void setDisplayUnit(const QVariant &value);

/* Explicit getters */
bool getHideTrayIcon() const { return fHideTrayIcon; }
bool getShowTrayIcon() const { return m_show_tray_icon; }
bool getMinimizeToTray() const { return fMinimizeToTray; }
bool getMinimizeOnClose() const { return fMinimizeOnClose; }
int getDisplayUnit() const { return nDisplayUnit; }
Expand All @@ -100,7 +100,7 @@ class OptionsModel : public QAbstractListModel
private:
interfaces::Node* m_node = nullptr;
/* Qt-only settings */
bool fHideTrayIcon;
bool m_show_tray_icon;
bool fMinimizeToTray;
bool fMinimizeOnClose;
QString language;
Expand All @@ -118,7 +118,7 @@ class OptionsModel : public QAbstractListModel
Q_SIGNALS:
void displayUnitChanged(int unit);
void coinControlFeaturesChanged(bool);
void hideTrayIconChanged(bool);
void showTrayIconChanged(bool);
};

#endif // BITCOIN_QT_OPTIONSMODEL_H