1
0
Fork 0
forked from blue/squawk

fix some bugs about disabled menus

This commit is contained in:
Blue 2022-06-03 09:44:48 +03:00
parent 645b92ba51
commit 7192286aeb
Signed by untrusted user: blue
GPG key ID: 9B203B252A63EE38
9 changed files with 56 additions and 24 deletions

View file

@ -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<QString> Models::Accounts::getNames() const
std::deque<QString> Models::Accounts::getActiveNames() const
{
std::deque<QString> res;
for (std::deque<Models::Account*>::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;

View file

@ -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<QString> getNames() const;
std::deque<QString> getActiveNames() const;
signals:
void changed();

View file

@ -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);

View file

@ -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();

View file

@ -26,10 +26,10 @@ JoinConference::JoinConference(const Models::Accounts* accounts, QWidget* parent
m_ui(new Ui::JoinConference())
{
m_ui->setupUi ( this );
std::deque<QString> names = accounts->getNames();
std::deque<QString> names = accounts->getActiveNames();
for (std::deque<QString>::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<QString> names = accounts->getNames();
std::deque<QString> names = accounts->getActiveNames();
int index = 0;
bool found = false;
for (std::deque<QString>::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) {

View file

@ -25,10 +25,10 @@ NewContact::NewContact(const Models::Accounts* accounts, QWidget* parent):
m_ui(new Ui::NewContact())
{
m_ui->setupUi ( this );
std::deque<QString> names = accounts->getNames();
std::deque<QString> names = accounts->getActiveNames();
for (std::deque<QString>::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<QString> names = accounts->getNames();
std::deque<QString> names = accounts->getActiveNames();
int index = 0;
bool found = false;