summaryrefslogtreecommitdiffstats
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
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
-rw-r--r--pica-client/contactlistwidget.cpp64
-rw-r--r--pica-client/contactlistwidget.h8
-rw-r--r--pica-client/contacts.cpp14
-rw-r--r--pica-client/contacts.h1
-rw-r--r--pica-client/mainwindow.cpp1
5 files changed, 84 insertions, 4 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);
diff --git a/pica-client/contactlistwidget.h b/pica-client/contactlistwidget.h
index c7bfe8d..12d505e 100644
--- a/pica-client/contactlistwidget.h
+++ b/pica-client/contactlistwidget.h
@@ -37,11 +37,14 @@ public:
QAction *viewcertAct;
QAction *showidAct;
QAction *sendfileAct;
+ QAction *showblacklistAct;
+ QAction *movetoblacklistAct;
+ QAction *removefromblacklistAct;
protected:
void contextMenuEvent(QContextMenuEvent *event);
private:
- void setContactsStorage(Contacts *ct);
+ void setContactsStorage(Contacts *ct, bool show_blacklisted = false);
Contacts* storage;
QList<Contacts::ContactRecord> contact_records;
QMap<QListWidgetItem*, Contacts::ContactRecord*> wgitem_to_recs;
@@ -60,6 +63,9 @@ private slots:
void view_cert();
void show_id();
void send_file();
+ void show_blacklist(bool checked);
+ void move_to_blacklist();
+ void remove_from_blacklist();
//void debug_onmsginput(QString msg, ChatWindow *sender_window);//debug remove after debug
};
diff --git a/pica-client/contacts.cpp b/pica-client/contacts.cpp
index 945b193..fb2467b 100644
--- a/pica-client/contacts.cpp
+++ b/pica-client/contacts.cpp
@@ -126,6 +126,7 @@ QList<Contacts::ContactRecord> Contacts::GetContacts(ContactType type)
{
r.id = query.value(0).toByteArray();
r.name = query.value(1).toString();
+ r.type = type;
//CSTRL.append(" ("+query.value(0).toString()+") "+query.value(1).toString());
L << r;
}
@@ -198,3 +199,16 @@ void Contacts::SetContactName(QByteArray id, QString name)
lasterr = query.lastError();
}
+void Contacts::SetContactType(QByteArray id, ContactType type)
+{
+ QSqlQuery query;
+
+ query.prepare("update contacts set type=:type where id=:id and account_id=:account_id");
+ query.bindValue(":type", type);
+ query.bindValue(":id", id);
+ query.bindValue(":account_id", account_id_);
+ query.exec();
+
+ lasterr = query.lastError();
+}
+
diff --git a/pica-client/contacts.h b/pica-client/contacts.h
index aadf5c9..99044b4 100644
--- a/pica-client/contacts.h
+++ b/pica-client/contacts.h
@@ -52,6 +52,7 @@ public:
QString GetContactName(QByteArray id);
void SetContactCert(QByteArray id, QString &cert_pem);
void SetContactName(QByteArray id, QString name);
+ void SetContactType(QByteArray id, ContactType type);
QString GetLastError();
bool isOK();
diff --git a/pica-client/mainwindow.cpp b/pica-client/mainwindow.cpp
index bb8a94a..3f768b0 100644
--- a/pica-client/mainwindow.cpp
+++ b/pica-client/mainwindow.cpp
@@ -120,6 +120,7 @@ void MainWindow::createMenus()
{
contactsMenu = menuBar()->addMenu(tr("&Contacts"));
contactsMenu->addAction(contact_list->addcontactAct);
+ contactsMenu->addAction(contact_list->showblacklistAct);
contactsMenu->addSeparator();
contactsMenu->addAction(action_center->ExitAct());