Compare commits

...

2 Commits

Author SHA1 Message Date
21c0fe728d style: remove useless code 2022-05-31 23:16:39 +04:00
93e6af3e20 feat: hide to tray on closing 2022-05-31 23:00:00 +04:00
5 changed files with 81 additions and 20 deletions

View File

@ -51,12 +51,13 @@ Squawk::Squawk(Models::Roster& p_rosterModel, QWidget *parent) :
m_ui->comboBox->addItem(Shared::availabilityIcon(av), Shared::Global::getName(av));
}
m_ui->comboBox->setCurrentIndex(static_cast<int>(Shared::Availability::offline));
createTrayIcon();
connect(m_ui->actionAccounts, &QAction::triggered, this, &Squawk::onAccounts);
connect(m_ui->actionPreferences, &QAction::triggered, this, &Squawk::onPreferences);
connect(m_ui->actionAddContact, &QAction::triggered, this, &Squawk::onNewContact);
connect(m_ui->actionAddConference, &QAction::triggered, this, &Squawk::onNewConference);
connect(m_ui->actionQuit, &QAction::triggered, this, &Squawk::close);
connect(m_ui->actionQuit, &QAction::triggered, [this]() { hide(); close(); }); // Actually closing
connect(m_ui->comboBox, qOverload<int>(&QComboBox::activated), this, &Squawk::onComboboxActivated);
//connect(m_ui->roster, &QTreeView::doubleClicked, this, &Squawk::onRosterItemDoubleClicked);
connect(m_ui->roster, &QTreeView::customContextMenuRequested, this, &Squawk::onRosterContextMenu);
@ -89,10 +90,35 @@ Squawk::Squawk(Models::Roster& p_rosterModel, QWidget *parent) :
settings.endGroup();
}
QSystemTrayIcon* Squawk::trayIcon;
Squawk::~Squawk() {
delete contextMenu;
delete trayIcon;
}
void Squawk::createTrayIcon()
{
QSettings settings;
trayIcon = new QSystemTrayIcon(this);
trayIcon->setIcon(QApplication::windowIcon());
QMenu * menu = new QMenu(this);
QAction * viewWindow = new QAction("Open Main Window", this);//TODO add translations
QAction * quitAction = new QAction("Quit", this);
connect(viewWindow, SIGNAL(triggered()), this, SLOT(show()));
connect(quitAction, &QAction::triggered, [this]() { hide(); close(); }); // Actually closing
menu->addAction(viewWindow);
menu->addAction(quitAction);
trayIcon->setContextMenu(menu);
if(settings.value("trayIconCheckbox").toBool())
trayIcon->show();
}
void Squawk::onAccounts()
{
if (accounts == nullptr) {
@ -183,25 +209,32 @@ void Squawk::onJoinConferenceAccepted()
void Squawk::closeEvent(QCloseEvent* event)
{
if (accounts != nullptr) {
accounts->close();
}
if (preferences != nullptr) {
preferences->close();
}
if (about != nullptr) {
about->close();
}
for (std::map<QString, VCard*>::const_iterator itr = vCards.begin(), end = vCards.end(); itr != end; ++itr) {
disconnect(itr->second, &VCard::destroyed, this, &Squawk::onVCardClosed);
itr->second->close();
}
vCards.clear();
writeSettings();
emit closing();;
QSettings settings;
if(this->isVisible() && settings.value("trayIconCheckbox").toBool()){
event->ignore();
this->hide();
QMainWindow::closeEvent(event);
} else {
if (accounts != nullptr) {
accounts->close();
}
if (preferences != nullptr) {
preferences->close();
}
if (about != nullptr) {
about->close();
}
for (std::map<QString, VCard*>::const_iterator itr = vCards.begin(), end = vCards.end(); itr != end; ++itr) {
disconnect(itr->second, &VCard::destroyed, this, &Squawk::onVCardClosed);
itr->second->close();
}
vCards.clear();
writeSettings();
emit closing();
QMainWindow::closeEvent(event);
}
}
void Squawk::onAccountsClosed() {

View File

@ -24,6 +24,7 @@
#include <QCloseEvent>
#include <QSettings>
#include <QInputDialog>
#include <QSystemTrayIcon>
#include <deque>
#include <map>
@ -85,6 +86,7 @@ signals:
public:
Models::Roster::ElId currentConversationId() const;
void closeCurrentConversation();
static QSystemTrayIcon *trayIcon;
public slots:
void writeSettings();
@ -93,6 +95,8 @@ public slots:
void select(QModelIndex index);
private:
void createTrayIcon();
QScopedPointer<Ui::Squawk> m_ui;
Accounts* accounts;

View File

@ -18,6 +18,7 @@
#include "pagegeneral.h"
#include "ui_pagegeneral.h"
#include "ui/squawk.h"
PageGeneral::PageGeneral(QWidget* parent):
QWidget(parent),
@ -28,7 +29,10 @@ PageGeneral::PageGeneral(QWidget* parent):
QSettings settings;
m_ui->downloadsPathInput->setText(settings.value("downloadsPath").toString());
m_ui->trayIconCheckbox->setChecked(settings.value("trayIconCheckbox").toBool());
connect(m_ui->downloadsPathButton, &QPushButton::clicked, this, &PageGeneral::onBrowseButtonClicked);
connect(m_ui->trayIconCheckbox, &QCheckBox::stateChanged, this, &PageGeneral::onTrayIconCheckboxChecked);
}
PageGeneral::~PageGeneral()
@ -76,3 +80,9 @@ void PageGeneral::onDialogDestroyed()
{
dialog = nullptr;
}
void PageGeneral::onTrayIconCheckboxChecked(){
QSettings settings;
settings.setValue("trayIconCheckbox", m_ui->trayIconCheckbox->isChecked());
Squawk::trayIcon->setVisible(m_ui->trayIconCheckbox->isChecked());
}

View File

@ -47,6 +47,7 @@ private slots:
void onBrowseButtonClicked();
void onDialogAccepted();
void onDialogDestroyed();
void onTrayIconCheckboxChecked();
private:
QScopedPointer<Ui::PageGeneral> m_ui;

View File

@ -39,6 +39,19 @@
</item>
</layout>
</item>
<item row="2" column="0" colspan="2">
<widget class="QCheckBox" name="trayIconCheckbox">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Hide Squawk to tray</string>
</property>
<property name="tristate">
<bool>false</bool>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>