forked from blue/squawk
basic context menu, subscribing unsubscribing to contacts
This commit is contained in:
parent
b845518ced
commit
ee59d92cdc
8 changed files with 137 additions and 4 deletions
|
@ -455,7 +455,6 @@ void Models::Roster::onChildIsAboutToBeRemoved(Models::Item* parent, int first,
|
|||
if (parent != root) {
|
||||
row = parent->row();
|
||||
}
|
||||
qDebug() << "Removing row" << parent->child(first)->getName() << "from" << parent->getName() << "index is" << first;
|
||||
beginRemoveRows(createIndex(row, 0, parent), first, last);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,12 @@ Squawk::Squawk(QWidget *parent) :
|
|||
m_ui(new Ui::Squawk),
|
||||
accounts(0),
|
||||
rosterModel(),
|
||||
conversations()
|
||||
conversations(),
|
||||
contextMenu(new QMenu())
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->roster->setModel(&rosterModel);
|
||||
m_ui->roster->setContextMenuPolicy(Qt::CustomContextMenu);
|
||||
|
||||
for (int i = 0; i < Shared::availabilityNames.size(); ++i) {
|
||||
m_ui->comboBox->addItem(QIcon::fromTheme(Shared::availabilityThemeIcons[i]), Shared::availabilityNames[i]);
|
||||
|
@ -21,11 +23,12 @@ Squawk::Squawk(QWidget *parent) :
|
|||
connect(m_ui->actionAccounts, SIGNAL(triggered()), this, SLOT(onAccounts()));
|
||||
connect(m_ui->comboBox, SIGNAL(activated(int)), this, SLOT(onComboboxActivated(int)));
|
||||
connect(m_ui->roster, SIGNAL(doubleClicked(const QModelIndex&)), this, SLOT(onRosterItemDoubleClicked(const QModelIndex&)));
|
||||
connect(m_ui->roster, SIGNAL(customContextMenuRequested(const QPoint&)), this, SLOT(onRosterContextMenu(const QPoint&)));
|
||||
//m_ui->mainToolBar->addWidget(m_ui->comboBox);
|
||||
}
|
||||
|
||||
Squawk::~Squawk() {
|
||||
|
||||
delete contextMenu;
|
||||
}
|
||||
|
||||
void Squawk::onAccounts()
|
||||
|
@ -272,3 +275,76 @@ void Squawk::removeAccount(const QString& account)
|
|||
}
|
||||
rosterModel.removeAccount(account);
|
||||
}
|
||||
|
||||
void Squawk::onRosterContextMenu(const QPoint& point)
|
||||
{
|
||||
QModelIndex index = m_ui->roster->indexAt(point);
|
||||
if (index.isValid()) {
|
||||
Models::Item* item = static_cast<Models::Item*>(index.internalPointer());
|
||||
|
||||
contextMenu->clear();
|
||||
bool hasMenu = false;
|
||||
switch (item->type) {
|
||||
case Models::Item::account: {
|
||||
Models::Account* acc = static_cast<Models::Account*>(item);
|
||||
hasMenu = true;
|
||||
QString name = acc->getName();
|
||||
|
||||
if (acc->getState() != Shared::disconnected) {
|
||||
QAction* con = contextMenu->addAction(QIcon::fromTheme("network-disconnect"), "Disconnect");
|
||||
connect(con, &QAction::triggered, [this, name]() {
|
||||
emit disconnectAccount(name);
|
||||
});
|
||||
} else {
|
||||
QAction* con = contextMenu->addAction(QIcon::fromTheme("network-connect"), "Connect");
|
||||
connect(con, &QAction::triggered, [this, name]() {
|
||||
emit connectAccount(name);
|
||||
});
|
||||
}
|
||||
|
||||
QAction* remove = contextMenu->addAction(QIcon::fromTheme("edit-delete"), "Remove");
|
||||
connect(remove, &QAction::triggered, [this, name]() {
|
||||
emit removeAccount(name);
|
||||
});
|
||||
|
||||
}
|
||||
break;
|
||||
case Models::Item::contact: {
|
||||
Models::Contact* cnt = static_cast<Models::Contact*>(item);
|
||||
hasMenu = true;
|
||||
|
||||
QAction* remove = contextMenu->addAction(QIcon::fromTheme("mail-message"), "Open dialog");
|
||||
connect(remove, &QAction::triggered, [this, index]() {
|
||||
onRosterItemDoubleClicked(index);
|
||||
});
|
||||
|
||||
Shared::SubscriptionState state = cnt->getState();
|
||||
switch (state) {
|
||||
case Shared::both:
|
||||
case Shared::to: {
|
||||
QAction* remove = contextMenu->addAction(QIcon::fromTheme("news-unsubscribe"), "Unsubscribe");
|
||||
connect(remove, &QAction::triggered, [this, cnt]() {
|
||||
emit unsubscribeContact(cnt->getAccountName(), cnt->getJid(), "");
|
||||
});
|
||||
}
|
||||
break;
|
||||
case Shared::from:
|
||||
case Shared::unknown:
|
||||
case Shared::none: {
|
||||
QAction* remove = contextMenu->addAction(QIcon::fromTheme("news-subscribe"), "Subscribe");
|
||||
connect(remove, &QAction::triggered, [this, cnt]() {
|
||||
emit subscribeContact(cnt->getAccountName(), cnt->getJid(), "");
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (hasMenu) {
|
||||
contextMenu->popup(m_ui->roster->viewport()->mapToGlobal(point));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,6 +35,8 @@ signals:
|
|||
void changeState(int state);
|
||||
void sendMessage(const QString& account, const Shared::Message& data);
|
||||
void requestArchive(const QString& account, const QString& jid, int count, const QString& before);
|
||||
void subscribeContact(const QString& account, const QString& jid, const QString& reason);
|
||||
void unsubscribeContact(const QString& account, const QString& jid, const QString& reason);
|
||||
|
||||
public slots:
|
||||
void newAccount(const QMap<QString, QVariant>& account);
|
||||
|
@ -59,6 +61,7 @@ private:
|
|||
Accounts* accounts;
|
||||
Models::Roster rosterModel;
|
||||
Conversations conversations;
|
||||
QMenu* contextMenu;
|
||||
|
||||
protected:
|
||||
void closeEvent(QCloseEvent * event) override;
|
||||
|
@ -71,6 +74,7 @@ private slots:
|
|||
void onRosterItemDoubleClicked(const QModelIndex& item);
|
||||
void onConversationMessage(const Shared::Message& msg);
|
||||
void onConversationRequestArchive(const QString& before);
|
||||
void onRosterContextMenu(const QPoint& point);
|
||||
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue