summaryrefslogtreecommitdiffstats
path: root/pica-client/contactlistwidget.cpp
diff options
context:
space:
mode:
authorAnton <anton@picapica>2019-05-16 21:57:53 +0400
committerAnton <anton@picapica>2019-05-16 21:57:53 +0400
commit6e1d6c845ee9b3d11379cee5cec6bcc7f2f9c612 (patch)
tree7d6f275a00a49b6a97e6254b05276bf5eb69e3ae /pica-client/contactlistwidget.cpp
parent850b332e7e591064bd8b3245554a05752240408e (diff)
downloadpica-pica-6e1d6c845ee9b3d11379cee5cec6bcc7f2f9c612.tar.gz
pica-pica-6e1d6c845ee9b3d11379cee5cec6bcc7f2f9c612.zip
pica-client: view blacklisted contacts, move contacts to and from blaclist in contact list
Diffstat (limited to 'pica-client/contactlistwidget.cpp')
-rw-r--r--pica-client/contactlistwidget.cpp64
1 files changed, 61 insertions, 3 deletions
diff --git a/pica-client/contactlistwidget.cpp b/pica-client/contactlistwidget.cpp
index 86d414d..8bba9c5 100644
--- a/pica-client/contactlistwidget.cpp
+++ b/pica-client/contactlistwidget.cpp
@@ -52,6 +52,16 @@ ContactListWidget::ContactListWidget(QWidget *parent) :
sendfileAct = new QAction(tr("Send &File"), this);
connect(sendfileAct, SIGNAL(triggered()), this, SLOT(send_file()));
+ showblacklistAct = new QAction(tr("Show &Blacklisted Contacts"), this);
+ showblacklistAct->setCheckable(true);
+ connect(showblacklistAct, SIGNAL(triggered(bool)), this, SLOT(show_blacklist(bool)));
+
+ movetoblacklistAct = new QAction(tr("&Move to Blacklist"), this);
+ connect(movetoblacklistAct, SIGNAL(triggered()), this, SLOT(move_to_blacklist()));
+
+ removefromblacklistAct = new QAction(tr("&Remove From Blacklist"), this);
+ connect(removefromblacklistAct, SIGNAL(triggered()), this, SLOT(remove_from_blacklist()));
+
connect(this, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(start_chat()));
setContactsStorage(new Contacts(config_dbname, Accounts::GetCurrentAccount().id));
@@ -67,24 +77,34 @@ void ContactListWidget::contextMenuEvent(QContextMenuEvent *event)
{
QMenu menu(this);
- if (this->itemAt(event->pos()))
+ if (this->itemAt(event->pos()) && wgitem_to_recs.contains(this->itemAt(event->pos())))
menu.addAction(delcontactAct);
menu.addAction(addcontactAct);
- if (this->itemAt(event->pos()))
+ if (this->itemAt(event->pos()) && wgitem_to_recs.contains(this->itemAt(event->pos())))
{
menu.addAction(startchatAct);
menu.addAction(viewcertAct);
menu.addAction(showidAct);
menu.addAction(sendfileAct);
+
+ if (wgitem_to_recs[this->itemAt(event->pos())]->type == Contacts::blacklisted)
+ {
+ menu.addAction(removefromblacklistAct);
+ }
+ else
+ {
+ menu.addAction(movetoblacklistAct);
+ }
}
menu.exec(event->globalPos());
}
-void ContactListWidget::setContactsStorage(Contacts *ct)
+void ContactListWidget::setContactsStorage(Contacts *ct, bool show_blacklisted)
{
clear();
+ wgitem_to_recs.clear();
// this->addItems(ct->GetContacts());
storage = ct;
contact_records = ct->GetContacts();
@@ -96,6 +116,27 @@ void ContactListWidget::setContactsStorage(Contacts *ct)
this->item(i)->setStatusTip(contact_records[i].id.toBase64());
this->item(i)->setToolTip(contact_records[i].id.toBase64().constData());
}
+
+ if (show_blacklisted)
+ {
+ QList<Contacts::ContactRecord> bl = ct->GetContacts(Contacts::blacklisted);
+ int offset = contact_records.size();
+
+ if(!bl.empty())
+ {
+ addItem(QString("--Blacklisted Contacts--"));
+ offset++;
+ contact_records.append(bl);
+ }
+
+ for (int i = 0; i < bl.size(); i++)
+ {
+ addItem(QString("(%1...) %2").arg(bl[i].id.toBase64().left(8).constData()).arg(bl[i].name));
+ wgitem_to_recs[this->item(i + offset)] = &contact_records[i + offset - 1];
+ this->item(i + offset)->setStatusTip(bl[i].id.toBase64());
+ this->item(i + offset)->setToolTip(bl[i].id.toBase64().constData());
+ }
+ }
}
void ContactListWidget::add_contact()
@@ -225,6 +266,23 @@ void ContactListWidget::Reload()
setContactsStorage(storage);
}
+void ContactListWidget::show_blacklist(bool checked)
+{
+ setContactsStorage(storage, checked);
+}
+
+void ContactListWidget::move_to_blacklist()
+{
+ storage->SetContactType(wgitem_to_recs[currentItem()]->id, Contacts::blacklisted);
+ setContactsStorage(storage, showblacklistAct->isChecked());
+}
+
+void ContactListWidget::remove_from_blacklist()
+{
+ storage->SetContactType(wgitem_to_recs[currentItem()]->id, Contacts::regular);
+ setContactsStorage(storage, showblacklistAct->isChecked());
+}
+
void ContactListWidget::send_file()
{
ftctrl->send_file(wgitem_to_recs[currentItem()]->id);