Commit 5d4a1ffa authored by Olivier SOLDANO's avatar Olivier SOLDANO Committed by Anthony Léonard

add tab to accountdetails managing banned contacts

implements banned account, add a tab at the end of account details
that shows a list of banned contacts, and on click displays a pannel
with detailed contact informations, providing the option to deban
this contact.

Change-Id: Icc2a0e315830bc3f7beb23797bedf12ecfd9a074
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent 19193410
......@@ -78,7 +78,8 @@ SOURCES += main.cpp\
contactrequestitemdelegate.cpp \
quickactcontactrequestwidget.cpp \
contactrequestlistwidget.cpp \
deleteaccountdialog.cpp
deleteaccountdialog.cpp \
bannedcontactswidget.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -120,7 +121,8 @@ HEADERS += mainwindow.h \
contactrequestitemdelegate.h \
quickactcontactrequestwidget.h \
contactrequestlistwidget.h \
deleteaccountdialog.h
deleteaccountdialog.h \
bannedcontactswidget.h
contains(DEFINES, URI_PROTOCOL) {
HEADERS += shmclient.h
......@@ -148,7 +150,8 @@ FORMS += mainwindow.ui \
currentaccountwidget.ui \
contactrequestwidget.ui \
quickactcontactrequestwidget.ui \
deleteaccountdialog.ui
deleteaccountdialog.ui \
bannedcontactswidget.ui
win32: LIBS += -lole32 -luuid -lshlwapi
LIBS += -lqrencode
......
......@@ -242,6 +242,7 @@ AccountDetails::setAccount(Account* currentAccount) {
ui->cipherListView->setVisible(true);
ui->tableView->setModel((QAbstractItemModel*)currentAccount_->ringDeviceModel());
ui->bannedContactsWidget->setAccount(currentAccount_);
}
void
......
......@@ -2395,6 +2395,9 @@
<layout class="QVBoxLayout" name="verticalLayout_15">
<item>
<widget class="QStackedWidget" name="devicesStackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="devicesListPage">
<layout class="QVBoxLayout" name="verticalLayout_16">
<item>
......@@ -2645,6 +2648,21 @@
</item>
</layout>
</widget>
<widget class="QWidget" name="bannedContactsTab">
<attribute name="title">
<string>Banned Contacts</string>
</attribute>
<widget class="BannedContactsWidget" name="bannedContactsWidget" native="true">
<property name="geometry">
<rect>
<x>0</x>
<y>-1</y>
<width>841</width>
<height>691</height>
</rect>
</property>
</widget>
</widget>
</widget>
</item>
</layout>
......@@ -2655,6 +2673,12 @@
<extends>QPushButton</extends>
<header location="global">ringbutton.h</header>
</customwidget>
<customwidget>
<class>BannedContactsWidget</class>
<extends>QWidget</extends>
<header location="global">bannedcontactswidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
......@@ -2806,7 +2830,7 @@
</connection>
</connections>
<buttongroups>
<buttongroup name="dtmfGroup"/>
<buttongroup name="publishGroup"/>
<buttongroup name="dtmfGroup"/>
</buttongroups>
</ui>
/**************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#include "bannedcontactswidget.h"
#include "ui_bannedcontactswidget.h"
#include <QAbstractItemModel>
#include <QPainter>
#include "ringthemeutils.h"
// LRC
#include "account.h"
#include "bannedcontactmodel.h"
/* Widget */
BannedContactsWidget::BannedContactsWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::BannedContactsWidget)
{
ui->setupUi(this);
bannedItemDelegate_ = new BannedContactItemDelegate();
ui->bannedList->setItemDelegate(bannedItemDelegate_);
connect(ui->bannedList, &QAbstractItemView::clicked, this, &BannedContactsWidget::setCurrentContact);
connect(ui->bannedList, &QAbstractItemView::clicked, this, [this](){ui->debanStack->setCurrentWidget(ui->debanPage);});
connect(ui->debanButton, &QPushButton::clicked, this, &BannedContactsWidget::debanContact);
}
BannedContactsWidget::~BannedContactsWidget()
{
delete ui;
}
void BannedContactsWidget::setAccount(Account *ac)
{
account_ = ac;
// Configure banned list to display banned contacts
ui->bannedList->setModel(account_->bannedContactModel());
// deban page hidden when model changes
ui->debanStack->setCurrentWidget(ui->cleanPage);
}
void BannedContactsWidget::setCurrentContact(const QModelIndex index)
{
ui->bannedIdLabel->setText(index.data().toString());
bannedContact_ = index.data(static_cast<int>(ContactMethod::Role::Object)).value<ContactMethod*>();
qDebug() << "banned contact method = " << bannedContact_;
}
void BannedContactsWidget::debanContact()
{
if (bannedContact_){
account_->bannedContactModel()->remove(bannedContact_);
ui->debanStack->setCurrentWidget(ui->cleanPage);
} else {
qDebug() << "banned contact: contactMethod not set!";
}
}
/* List Item Delegate */
BannedContactItemDelegate::BannedContactItemDelegate(QObject *parent):
QItemDelegate(parent)
{
}
void BannedContactItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const
{
painter->setRenderHint(QPainter::Antialiasing);
QStyleOptionViewItem opt(option);
// Not having focus removes dotted lines around the item
if (opt.state & QStyle::State_HasFocus)
opt.state ^= QStyle::State_HasFocus;
// First, we draw the control itself
QStyle* style = opt.widget ? opt.widget->style() : QApplication::style();
style->drawControl(QStyle::CE_ItemViewItem, &opt, painter, opt.widget);
// Then, we print the text
QFont font(painter->font());
font.setPointSize(10);
font.setBold(true);
painter->setFont(font);
QFontMetrics fontMetrics(font);
QRect rectText(opt.rect);
rectText.setLeft(opt.rect.left() + dxText_);
rectText.setBottom(rectText.top() + dyText_ + fontMetrics.height()/2);
rectText.setTop(rectText.bottom() - fontMetrics.height());
QString text(index.data().toString());
text = fontMetrics.elidedText(text, Qt::ElideRight, rectText.width());
QPen pen(painter->pen());
pen.setColor(RingTheme::lightBlack_);
painter->setPen(pen);
painter->drawText(rectText,text);
// Draw separator when item is not selected
if (not (opt.state & QStyle::State_Selected)) {
QRect rect(opt.rect);
pen.setColor(RingTheme::lightGrey_);
painter->setPen(pen);
painter->drawLine(rect.left() + separatorYPadding_, rect.bottom(),
rect.right() - separatorYPadding_,
rect.bottom());
}
}
QSize BannedContactItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const
{
QSize size = QItemDelegate::sizeHint(option, index);
size.setHeight(cellHeight_);
return size;
}
/**************************************************************************
* Copyright (C) 2015-2017 by Savoir-faire Linux *
* Author: Olivier Soldano <olivier.soldano@savoirfairelinux.com> *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 3 of the License, or *
* (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
**************************************************************************/
#ifndef BANNEDCONTACTSWIDGET_H
#define BANNEDCONTACTSWIDGET_H
#include <QWidget>
#include <QAbstractItemModel>
#include <QObject>
#include <QItemDelegate>
// LRC
#include "account.h"
#include "contactmethod.h"
/* item delegate */
class BannedContactItemDelegate : public QItemDelegate
{
public:
BannedContactItemDelegate(QObject* parent = 0);
protected:
void paint(QPainter* painter, const QStyleOptionViewItem& option, const QModelIndex& index) const;
QSize sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const;
private:
constexpr static int cellHeight_ = 60;
constexpr static int sizeImage_ = 48;
constexpr static int dxImage_ = 16;
constexpr static int dyImage_ = 6;
constexpr static int dxText_ = dxImage_;
constexpr static int dyText_ = cellHeight_/2;
constexpr static int separatorYPadding_ = 20;
};
/* widget */
namespace Ui {
class BannedContactsWidget;
}
class BannedContactsWidget : public QWidget
{
Q_OBJECT
public:
explicit BannedContactsWidget(QWidget *parent = 0);
~BannedContactsWidget();
void setAccount(Account *ac);
private slots:
void setCurrentContact(const QModelIndex index);
void debanContact();
private:
Account* account_ {};
BannedContactItemDelegate* bannedItemDelegate_;
ContactMethod* bannedContact_;
Ui::BannedContactsWidget *ui;
};
#endif // BANNEDCONTACTSWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>BannedContactsWidget</class>
<widget class="QWidget" name="BannedContactsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>712</width>
<height>544</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<layout class="QHBoxLayout" name="horizontalLayout" stretch="1,2">
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<widget class="QListView" name="bannedList">
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
<item>
<widget class="QStackedWidget" name="debanStack">
<property name="currentIndex">
<number>1</number>
</property>
<widget class="QWidget" name="cleanPage"/>
<widget class="QWidget" name="debanPage">
<layout class="QVBoxLayout" name="verticalLayout" stretch="1,0,0,0,1">
<item>
<spacer name="verticalSpacer">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QLabel" name="bannedIdLabel">
<property name="text">
<string>Banned ID</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_2">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QPushButton" name="debanButton">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>265</width>
<height>30</height>
</size>
</property>
<property name="text">
<string>Deban contact, and add to contact list</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_3">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>20</width>
<height>40</height>
</size>
</property>
</spacer>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -958,9 +958,9 @@ void
CallWidget::on_sendContactRequestPageButton_clicked()
{
ui->sendContactRequestWidget->sendCR(RecentModel::instance().selectionModel()->currentIndex());
// temporarly changed comportment waiting for message in payload implementation
/*ui->sendContactRequestWidget->setup(RecentModel::instance().selectionModel()->currentIndex());
slidePage(ui->sendContactRequestPage);*/
// temporarly changed comportment waiting for message in payload implementation
/*ui->sendContactRequestWidget->setup(RecentModel::instance().selectionModel()->currentIndex());
slidePage(ui->sendContactRequestPage);*/
}
void
......
......@@ -1124,7 +1124,7 @@
<item row="0" column="1">
<layout class="QVBoxLayout" name="accountDetailLayout">
<property name="bottomMargin">
<number>13</number>
<number>0</number>
</property>
</layout>
</item>
......
......@@ -107,13 +107,13 @@ QListView#cipherListView::item:disabled
}
SmartList::item:selected, QListView#accountView::item:selected, QListView#contactView::item:selected,
QTreeView#contactRequestList::item:selected{
QTreeView#contactRequestList::item:selected, QListView#BannedList::item:selected{
background-color: rgba(220, 220, 220, 255);
border: none;
}
SmartList::item:hover, QListView#accountView::item:hover, QListView#contactView::item:hover,
QTreeView#contactRequestList::item:hover{
QTreeView#contactRequestList::item:hover, QListView#BannedList::item:hover{
background-color: rgba(242, 242, 242, 255);
}
......@@ -303,7 +303,7 @@ QPushButton#sendContactRequestButton, QPushButton#acceptCRButton, QPushButton#di
font: 14px;
}
QPushButton#blockCRButton, QPushButton#deleteAcceptBtn{
QPushButton#blockCRButton, QPushButton#deleteAcceptBtn, QPushButton#debanButton{
background-color: rgb(251, 72, 71);
border: 0px;
color: white;
......@@ -322,7 +322,7 @@ QPushButton#deleteCancelBtn:hover{
background-color: #4dc6d6;
}
QPushButton#blockCRButton:hover, QPushButton#deleteAcceptBtn:hover{
QPushButton#blockCRButton:hover, QPushButton#deleteAcceptBtn:hover, QPushButton#debanButton:hover{
background-color: rgb(252, 91, 90);
}
......@@ -338,7 +338,7 @@ QPushButton#sendContactRequestButton:pressed, QPushButton#acceptCRButton:pressed
QPushButton#deleteCancelBtn:pressed{
background-color: #34acbd;
}
QPushButton#blockCRButton:pressed, QPushButton#deleteAcceptBtn:pressed{
QPushButton#blockCRButton:pressed, QPushButton#deleteAcceptBtn:pressed, QPushButton#debanButton:pressed{
background-color: rgb(219, 55, 54);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment