From 7192286aeb69a20c8ecd4f5337f7ea5a59935c71 Mon Sep 17 00:00:00 2001 From: blue Date: Fri, 3 Jun 2022 09:44:48 +0300 Subject: [PATCH] fix some bugs about disabled menus --- CHANGELOG.md | 17 +++++++++++++---- CMakeLists.txt | 2 +- main/main.cpp | 2 +- ui/models/accounts.cpp | 26 +++++++++++++++++++++++--- ui/models/accounts.h | 4 +++- ui/squawk.cpp | 8 +++++--- ui/squawk.h | 2 +- ui/widgets/joinconference.cpp | 11 +++++------ ui/widgets/newcontact.cpp | 8 ++++---- 9 files changed, 56 insertions(+), 24 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4fb579..600c795 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,18 @@ # Changelog +## Squawk 0.2.3 (UNRELEASED) +### Bug fixes +- "Add contact" and "Join conference" menu are enabled once again (pavavno)! + +### Improvements +- deactivated accounts now don't appear in combobox of "Add contact" and "Join conference" dialogues + +### New features + ## Squawk 0.2.2 (May 05, 2022) ### Bug fixes - now when you remove an account it actually gets removed -- segfault on unitialized Availability in some rare occesions +- segfault on uninitialized Availability in some rare occasions - fixed crash when you open a dialog with someone that has only error messages in archive - message height is now calculated correctly on Chinese and Japanese paragraphs - the app doesn't crash on SIGINT anymore @@ -12,13 +21,13 @@ - there is a way to disable an account and it wouldn't connect when you change availability - if you cancel password query an account becomes inactive and doesn't annoy you anymore - if you filled password field and chose KWallet as a storage Squawk wouldn't ask you again for the same password -- if left the password field empty and chose KWallet as a storage Squawk will try to get that passord from KWallet before asking you to input it -- accounts now connect to the server asyncronously - if one is stopped on password prompt another is connecting +- if left the password field empty and chose KWallet as a storage Squawk will try to get that password from KWallet before asking you to input it +- accounts now connect to the server asynchronously - if one is stopped on password prompt another is connecting - actualized translations, added English localization file ### New features - new "About" window with links, license, gratitudes -- if the authentication failed Squawk will ask againg for your password and login +- if the authentication failed Squawk will ask again for your password and login - now there is an amount of unread messages showing on top of Squawk launcher icon - notifications now have buttons to open a conversation or to mark that message as read diff --git a/CMakeLists.txt b/CMakeLists.txt index 75011d8..bbae079 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,5 +1,5 @@ cmake_minimum_required(VERSION 3.4) -project(squawk VERSION 0.2.2 LANGUAGES CXX) +project(squawk VERSION 0.2.3 LANGUAGES CXX) cmake_policy(SET CMP0076 NEW) cmake_policy(SET CMP0079 NEW) diff --git a/main/main.cpp b/main/main.cpp index 60b3c83..3368e0a 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -49,7 +49,7 @@ int main(int argc, char *argv[]) QApplication::setApplicationName("squawk"); QApplication::setOrganizationName("macaw.me"); QApplication::setApplicationDisplayName("Squawk"); - QApplication::setApplicationVersion("0.2.2"); + QApplication::setApplicationVersion("0.2.3"); app.setDesktopFileName("squawk"); QTranslator qtTranslator; diff --git a/ui/models/accounts.cpp b/ui/models/accounts.cpp index 463ab40..8a9e5d9 100644 --- a/ui/models/accounts.cpp +++ b/ui/models/accounts.cpp @@ -69,6 +69,23 @@ int Models::Accounts::rowCount ( const QModelIndex& parent ) const return accs.size(); } +unsigned int Models::Accounts::size() const +{ + return rowCount(QModelIndex()); +} + +unsigned int Models::Accounts::activeSize() const +{ + unsigned int size = 0; + for (const Models::Account* acc : accs) { + if (acc->getActive()) { + ++size; + } + } + + return size; +} + QVariant Models::Accounts::headerData(int section, Qt::Orientation orientation, int role) const { if (role == Qt::DisplayRole && orientation == Qt::Horizontal) { @@ -97,6 +114,7 @@ void Models::Accounts::addAccount(Account* account) endInsertRows(); emit sizeChanged(accs.size()); + emit changed(); } void Models::Accounts::onAccountChanged(Item* item, int row, int col) @@ -157,12 +175,14 @@ void Models::Accounts::removeAccount(int index) emit sizeChanged(accs.size()); } -std::deque Models::Accounts::getNames() const +std::deque Models::Accounts::getActiveNames() const { std::deque res; - for (std::deque::const_iterator i = accs.begin(), end = accs.end(); i != end; ++i) { - res.push_back((*i)->getName()); + for (const Models::Account* acc : accs) { + if (acc->getActive()) { + res.push_back(acc->getName()); + } } return res; diff --git a/ui/models/accounts.h b/ui/models/accounts.h index e8be07c..c5d59af 100644 --- a/ui/models/accounts.h +++ b/ui/models/accounts.h @@ -39,11 +39,13 @@ public: QVariant data ( const QModelIndex& index, int role ) const override; int columnCount ( const QModelIndex& parent ) const override; int rowCount ( const QModelIndex& parent ) const override; + unsigned int size () const; + unsigned int activeSize () const; QVariant headerData(int section, Qt::Orientation orientation, int role) const override; Account* getAccount(int index); - std::deque getNames() const; + std::deque getActiveNames() const; signals: void changed(); diff --git a/ui/squawk.cpp b/ui/squawk.cpp index 9b6158c..db92e93 100644 --- a/ui/squawk.cpp +++ b/ui/squawk.cpp @@ -63,7 +63,7 @@ Squawk::Squawk(Models::Roster& p_rosterModel, QWidget *parent) : connect(m_ui->roster, &QTreeView::collapsed, this, &Squawk::onItemCollepsed); connect(m_ui->roster->selectionModel(), &QItemSelectionModel::currentRowChanged, this, &Squawk::onRosterSelectionChanged); - connect(rosterModel.accountsModel, &Models::Accounts::sizeChanged, this, &Squawk::onAccountsSizeChanged); + connect(rosterModel.accountsModel, &Models::Accounts::changed, this, &Squawk::onAccountsChanged); connect(contextMenu, &QMenu::aboutToHide, this, &Squawk::onContextAboutToHide); connect(m_ui->actionAboutSquawk, &QAction::triggered, this, &Squawk::onAboutSquawkCalled); //m_ui->mainToolBar->addWidget(m_ui->comboBox); @@ -87,6 +87,8 @@ Squawk::Squawk(Models::Roster& p_rosterModel, QWidget *parent) : m_ui->splitter->restoreState(settings.value("splitter").toByteArray()); } settings.endGroup(); + + onAccountsChanged(); } Squawk::~Squawk() { @@ -129,9 +131,9 @@ void Squawk::onPreferences() } } - -void Squawk::onAccountsSizeChanged(unsigned int size) +void Squawk::onAccountsChanged() { + unsigned int size = rosterModel.accountsModel->activeSize(); if (size > 0) { m_ui->actionAddContact->setEnabled(true); m_ui->actionAddConference->setEnabled(true); diff --git a/ui/squawk.h b/ui/squawk.h index 15a73dd..f55a000 100644 --- a/ui/squawk.h +++ b/ui/squawk.h @@ -116,7 +116,7 @@ private slots: void onNewConference(); void onNewContactAccepted(); void onJoinConferenceAccepted(); - void onAccountsSizeChanged(unsigned int size); + void onAccountsChanged(); void onAccountsClosed(); void onPreferencesClosed(); void onVCardClosed(); diff --git a/ui/widgets/joinconference.cpp b/ui/widgets/joinconference.cpp index 648de25..890e4e2 100644 --- a/ui/widgets/joinconference.cpp +++ b/ui/widgets/joinconference.cpp @@ -26,10 +26,10 @@ JoinConference::JoinConference(const Models::Accounts* accounts, QWidget* parent m_ui(new Ui::JoinConference()) { m_ui->setupUi ( this ); - std::deque names = accounts->getNames(); + std::deque names = accounts->getActiveNames(); - for (std::deque::const_iterator i = names.begin(), end = names.end(); i != end; i++) { - m_ui->account->addItem(*i); + for (const QString& name : names) { + m_ui->account->addItem(name); } m_ui->account->setCurrentIndex(0); @@ -40,12 +40,11 @@ JoinConference::JoinConference(const QString& acc, const Models::Accounts* accou m_ui(new Ui::JoinConference()) { m_ui->setupUi ( this ); - std::deque names = accounts->getNames(); + std::deque names = accounts->getActiveNames(); int index = 0; bool found = false; - for (std::deque::const_iterator i = names.begin(), end = names.end(); i != end; i++) { - const QString& name = *i; + for (const QString& name : names) { m_ui->account->addItem(name); if (!found) { if (name == acc) { diff --git a/ui/widgets/newcontact.cpp b/ui/widgets/newcontact.cpp index 920c757..9303963 100644 --- a/ui/widgets/newcontact.cpp +++ b/ui/widgets/newcontact.cpp @@ -25,10 +25,10 @@ NewContact::NewContact(const Models::Accounts* accounts, QWidget* parent): m_ui(new Ui::NewContact()) { m_ui->setupUi ( this ); - std::deque names = accounts->getNames(); + std::deque names = accounts->getActiveNames(); - for (std::deque::const_iterator i = names.begin(), end = names.end(); i != end; i++) { - m_ui->account->addItem(*i); + for (const QString& name : names) { + m_ui->account->addItem(name); } m_ui->account->setCurrentIndex(0); @@ -40,7 +40,7 @@ NewContact::NewContact(const QString& acc, const Models::Accounts* accounts, QWi { m_ui->setupUi ( this ); - std::deque names = accounts->getNames(); + std::deque names = accounts->getActiveNames(); int index = 0; bool found = false;