Commit 9657fd1f authored by Olivier SOLDANO's avatar Olivier SOLDANO Committed by Anthony Léonard

implements current account selection

This patch implements the ui and logic of selecting the
current account used in the ring-win32 client

The selector is contained in a new dedicated widget
which displays an image representing the account selected
(for the moment there is no account related avatar so
the picture is the one from the profile) and the alias of the account
through a QComboBox

Finally, some css styling and search bar behaviour are fixed.

Change-Id: I60be8e352e15c7ffdd969f66df7e011f8212e40c
Reviewed-by: default avatarAnthony Léonard <anthony.leonard@savoirfairelinux.com>
parent dd87866f
......@@ -72,7 +72,8 @@ SOURCES += main.cpp\
ringbutton.cpp \
pathpassworddialog.cpp \
photoboothdialog.cpp \
sendcontactrequestwidget.cpp
sendcontactrequestwidget.cpp \
currentaccountwidget.cpp
HEADERS += mainwindow.h \
callwidget.h \
......@@ -108,7 +109,8 @@ HEADERS += mainwindow.h \
ringbutton.h \
pathpassworddialog.h \
photoboothdialog.h \
sendcontactrequestwidget.h
sendcontactrequestwidget.h \
currentaccountwidget.h
contains(DEFINES, URI_PROTOCOL) {
HEADERS += shmclient.h
......@@ -132,7 +134,8 @@ FORMS += mainwindow.ui \
ringbutton.ui \
pathpassworddialog.ui \
photoboothdialog.ui \
sendcontactrequestwidget.ui
sendcontactrequestwidget.ui \
currentaccountwidget.ui
win32: LIBS += -lole32 -luuid -lshlwapi
LIBS += -lqrencode
......
......@@ -32,6 +32,7 @@
#undef interface
#include "audio/settings.h"
#include "accountmodel.h"
#include "personmodel.h"
#include "person.h"
#include "fallbackpersoncollection.h"
......@@ -55,6 +56,7 @@
#include "settingskey.h"
#include "profilemodel.h"
#include "profile.h"
#include "peerprofilecollection.h"
#include "localprofilecollection.h"
......@@ -137,8 +139,14 @@ CallWidget::CallWidget(QWidget* parent) :
ui->smartList->clearSelection();
});
connect(&NameDirectory::instance(), SIGNAL(registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
this, SLOT(contactLineEdit_registeredNameFound(const Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
connect(&NameDirectory::instance(), SIGNAL(registeredNameFound(Account*,NameDirectory::LookupStatus,const QString&,const QString&)),
this, SLOT(contactLineEdit_registeredNameFound(Account*,NameDirectory::LookupStatus,const QString&,const QString&)));
connect(&AccountModel::instance(), SIGNAL(dataChanged(QModelIndex,QModelIndex,QVector<int>)),
ui->currentAccountWidget, SLOT(update()));
connect(&ProfileModel::instance(), SIGNAL(ProfileModel::dataChanged(const QModelIndex&,const QModelIndex&, const QVector<int>&)),
ui->currentAccountWidget, SLOT(update()));
connect(ui->sendContactRequestWidget, &SendContactRequestWidget::sendCRclicked, [=]{slidePage(ui->messagingPage);});
......@@ -197,7 +205,8 @@ CallWidget::setupOutOfCallIM()
}
void
CallWidget::onIncomingMessage(::Media::TextRecording* t, ContactMethod* cm) {
CallWidget::onIncomingMessage(::Media::TextRecording* t, ContactMethod* cm)
{
Q_UNUSED(cm)
if (!QApplication::focusWidget()) {
......@@ -212,7 +221,8 @@ CallWidget::onIncomingMessage(::Media::TextRecording* t, ContactMethod* cm) {
}
void
CallWidget::setupSmartListMenu() {
CallWidget::setupSmartListMenu()
{
ui->smartList->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->smartList, &QListView::customContextMenuRequested, [=](const QPoint& pos){
auto idx = ui->smartList->currentIndex();
......@@ -357,11 +367,15 @@ CallWidget::findRingAccount()
}
}
}
if (ui->ringIdLabel->text().isEmpty()) {
ui->ringIdLabel->setText(tr("NO RING ACCOUNT FOUND"));
WizardDialog wizardDialog;
wizardDialog.exec();
}
ui->currentAccountWidget->update();
}
void
......@@ -435,7 +449,8 @@ CallWidget::atExit()
{
}
void CallWidget::callStateToView(Call* value)
void
CallWidget::callStateToView(Call* value)
{
if (value) {
switch (value->state()) {
......@@ -497,6 +512,14 @@ CallWidget::on_cancelButton_clicked()
}
}
void
CallWidget::on_smartList_clicked(const QModelIndex& index)
{
RecentModel::instance().selectionModel()->setCurrentIndex(
RecentModel::instance().peopleProxy()->mapToSource(index),
QItemSelectionModel::ClearAndSelect);
}
void
CallWidget::on_smartList_doubleClicked(const QModelIndex& index)
{
......@@ -739,7 +762,7 @@ CallWidget::slotAccountMessageReceived(const QMap<QString,QString> message,
void
CallWidget::on_ringContactLineEdit_textChanged(const QString& text)
{
RecentModel::instance().peopleProxy()->setFilterWildcard(text);
RecentModel::instance().peopleProxy()->setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString));
}
void
......@@ -762,14 +785,6 @@ CallWidget::slidePage(QWidget* widget, bool toRight)
pageAnim_->start();
}
void
CallWidget::on_smartList_clicked(const QModelIndex& index)
{
RecentModel::instance().selectionModel()->setCurrentIndex(
RecentModel::instance().peopleProxy()->mapToSource(index),
QItemSelectionModel::ClearAndSelect);
}
void
CallWidget::on_copyCMButton_clicked()
{
......@@ -790,7 +805,7 @@ CallWidget::on_shareButton_clicked()
}
void
CallWidget::contactLineEdit_registeredNameFound(const Account* account,NameDirectory::LookupStatus status,
CallWidget::contactLineEdit_registeredNameFound(Account* account,NameDirectory::LookupStatus status,
const QString& address,const QString& name)
{
URI uri = URI(ui->ringContactLineEdit->text());
......@@ -810,7 +825,7 @@ CallWidget::contactLineEdit_registeredNameFound(const Account* account,NameDirec
qDebug() << uri;
searchContactLineEditEntry(uri);
auto cm = PhoneDirectoryModel::instance().getNumber(uri);
//cm->setAccount(account);
cm->setAccount(account);
break;
}
case NameDirectory::LookupStatus::INVALID_NAME:
......
......@@ -91,7 +91,7 @@ private slots:
void slotAccountMessageReceived(const QMap<QString,QString> message,ContactMethod* cm,Media::Media::Direction dir);
void onIncomingMessage(::Media::TextRecording* t, ContactMethod* cm);
void callChangedSlot();
void contactLineEdit_registeredNameFound(const Account* account,NameDirectory::LookupStatus status,const QString& address,const QString& name);
void contactLineEdit_registeredNameFound(Account *account, NameDirectory::LookupStatus status, const QString& address, const QString& name);
private:
Ui::CallWidget* ui;
......
......@@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>1024</width>
<width>1046</width>
<height>724</height>
</rect>
</property>
......@@ -112,13 +112,29 @@
<number>0</number>
</property>
<item row="0" column="0">
<layout class="QVBoxLayout" name="verticalLayout_2">
<layout class="QVBoxLayout" name="verticalLayout_2" stretch="3,1,18">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetDefaultConstraint</enum>
</property>
<item>
<widget class="CurrentAccountWidget" name="currentAccountWidget" native="true">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
</widget>
</item>
<item>
<widget class="QWidget" name="selectBar" native="true">
<property name="maximumSize">
......@@ -236,7 +252,7 @@
</property>
<property name="icon">
<iconset resource="ressources.qrc">
<normaloff>:/images/icons/ic_videocam_white.png</normaloff>:/images/icons/ic_videocam_white.png</iconset>
<normaloff>:/images/icons/ic_search_black_18dp_2x.png</normaloff>:/images/icons/ic_search_black_18dp_2x.png</iconset>
</property>
<property name="iconSize">
<size>
......@@ -1697,6 +1713,12 @@
<header>sendcontactrequestwidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>CurrentAccountWidget</class>
<extends>QWidget</extends>
<header>currentaccountwidget.h</header>
<container>1</container>
</customwidget>
</customwidgets>
<resources>
<include location="ressources.qrc"/>
......
/***************************************************************************
* Copyright (C) 2015-2016 by Savoir-faire Linux *
* Author: Anthony Léonard <anthony.leonard@savoirfairelinux.com> *
* 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 "currentaccountwidget.h"
#include "ui_currentaccountwidget.h"
#include "globalinstances.h"
#include "accountmodel.h"
#include "account.h"
#include "qstandarditemmodel.h"
#include "profilemodel.h"
#include "profile.h"
#include "person.h"
#include "utils.h"
CurrentAccountWidget::CurrentAccountWidget(QWidget *parent) :
QWidget(parent),
ui(new Ui::CurrentAccountWidget)
{
ui->setupUi(this);
setup();
}
CurrentAccountWidget::~CurrentAccountWidget()
{
delete ui;
}
void
CurrentAccountWidget::setup()
{
ui->accountsStatus->setText("No enabled account: impossible to communicate!");
ui->accountsStatus->hide();
updateAccounts();
if (ui->currentAccountSelector->count() > 0) {
ui->currentAccountSelector->setCurrentIndex(0);
emit ui->currentAccountSelector->currentIndexChanged(0);
qDebug() << "CurrentAccount : setup over";
} else {
qDebug() << "CurrentAccount : No account available";
}
}
void
CurrentAccountWidget::update()
{
updateAccounts();
}
void
CurrentAccountWidget::updateAccounts()
{
auto selector = ui->currentAccountSelector;
AccountModel* model = &(AccountModel::instance());
QModelIndex qIndex;
selector->clear();
for (int idx = 0; idx <= model->rowCount() - 1; idx++){
qIndex = model->index(idx);
if (! model->getAccountByModelIndex(qIndex)->isEnabled()) {
qDebug() << model->getAccountByModelIndex(qIndex)->alias() << " Account is not enabled";
} else {
selector->addItem(model->getAccountByModelIndex(qIndex)->alias());
}
}
if (selector->count() <= 1){
selector->hide();
if (selector->count() < 1) {
ui->accountsStatus->show();
setPhoto();
} else {
ui->accountsStatus->hide();
}
} else {
selector->show();
ui->accountsStatus->hide();
}
}
void
CurrentAccountWidget::setPhoto()
{
auto selector = ui->currentAccountSelector;
if (selector->count() > 0) {
if(&ProfileModel::instance()){
if (ProfileModel::instance().selectedProfile()) {
if (ProfileModel::instance().selectedProfile()->person()){
QImage img = Utils::getCirclePhoto(ProfileModel::instance().selectedProfile()->person()->photo().value<QImage>(),
ui->idDisplayLayout->contentsRect().height());
ui->currentAccountPixmap->setPixmap(QPixmap::fromImage(img));
qDebug() << "CurrentAccount : Photo set";
} else {
qDebug() << "CurrentAccount : selected profile has no person";
}
} else {
qDebug() << "CurrentAccount : Profilemodel: no selected profile";
}
} else {
qDebug() << "CurrentAccount : Profilemodel not set";
}
} else {
qDebug() << "CurrentAccount : account not set";
ui->currentAccountPixmap->setPixmap(QPixmap());
}
}
void
CurrentAccountWidget::on_currentAccountSelector_currentIndexChanged(int index)
{
QModelIndex idx = ui->currentAccountSelector->model()->index(index,0);
Account* ac = AccountModel::instance().getAccountByModelIndex(idx);
if (ac) {
AccountModel::instance().setUserChosenAccount(ac);
setPhoto();
} else {
qDebug() << "CurrentAccount : account not referenced correctly";
//null for now
}
}
#ifndef CURRENTACCOUNTWIDGET_H
#define CURRENTACCOUNTWIDGET_H
#include <QWidget>
namespace Ui {
class CurrentAccountWidget;
}
class CurrentAccountWidget : public QWidget
{
Q_OBJECT
public:
explicit CurrentAccountWidget(QWidget *parent = 0);
~CurrentAccountWidget();
public slots:
void update();
private slots:
void on_currentAccountSelector_currentIndexChanged(int index);
private:
Ui::CurrentAccountWidget *ui;
void setup();
void setPhoto();
void updateAccounts();
};
#endif // CURRENTACCOUNTWIDGET_H
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>CurrentAccountWidget</class>
<widget class="QWidget" name="CurrentAccountWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>294</width>
<height>184</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>100</height>
</size>
</property>
<property name="windowTitle">
<string>Form</string>
</property>
<property name="autoFillBackground">
<bool>false</bool>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<property name="spacing">
<number>0</number>
</property>
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<number>0</number>
</property>
<item>
<layout class="QVBoxLayout" name="fullLayout" stretch="4,0,0">
<property name="spacing">
<number>0</number>
</property>
<item>
<layout class="QHBoxLayout" name="idDisplayLayout" stretch="0,0,0">
<property name="leftMargin">
<number>10</number>
</property>
<property name="topMargin">
<number>3</number>
</property>
<property name="rightMargin">
<number>10</number>
</property>
<property name="bottomMargin">
<number>3</number>
</property>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item alignment="Qt::AlignHCenter|Qt::AlignVCenter">
<widget class="QLabel" name="currentAccountPixmap">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>0</width>
<height>60</height>
</size>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item alignment="Qt::AlignHCenter">
<widget class="QLabel" name="accountsStatus">
<property name="minimumSize">
<size>
<width>20</width>
<height>10</height>
</size>
</property>
<property name="styleSheet">
<string notr="true">text: centered;</string>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item>
<widget class="QComboBox" name="currentAccountSelector"/>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
......@@ -195,8 +195,8 @@ QPushButton#sendCRBackButton:hover, QPushButton#copyCMButton:hover{
background-color: #515151;
}
QPushButton#exitSettingsButton:pressed, QPushButton#settingsButton:pressed, QToolButton#imBackButton:pressed,
QToolButton#sendCRBackButton:pressed, QPushButton#copyCMButton:pressed{
QPushButton#exitSettingsButton:pressed, QPushButton#settingsButton:pressed, QPushButton#imBackButton:pressed,
QPushButton#sendCRBackButton:pressed, QPushButton#copyCMButton:pressed{
background-color: #313131;
}
......@@ -509,7 +509,7 @@ QLineEdit#lrcfg_alias, QLineEdit#lrcfg_hostname, QLineEdit#lrcfg_password, QLine
QLineEdit#lrcfg_mailbox, QLineEdit#lrcfg_tlsPassword, QLineEdit#lrcfg_tlsServerName,
QLineEdit#lrcfg_turnServerRealm, QLineEdit#lrcfg_turnServerUsername, QLineEdit#lrcfg_turnServerPassword,
QLineEdit#lrcfg_turnServer, QLineEdit#lrcfg_publishedAddress, QLineEdit#lrcfg_registeredName,
QLineEdit#lrcfg_nameServiceURL, QLineEdit#lrcfg_username{
QLineEdit#lrcfg_nameServiceURL, QLineEdit#lrcfg_username, QLineEdit#profileNameEdit{
background: transparent;
border-radius: 0px;
border-style: solid;
......@@ -533,7 +533,8 @@ QLineEdit#lrcfg_alias:focus, QLineEdit#lrcfg_hostname:focus, QLineEdit#lrcfg_pas
QLineEdit#lrcfg_proxy:focus, QLineEdit#lrcfg_mailbox:focus, QLineEdit#lrcfg_tlsPassword:focus,
QLineEdit#lrcfg_tlsServerName:focus, QLineEdit#lrcfg_turnServerRealm:focus, QLineEdit#lrcfg_turnServerUsername:focus,
QLineEdit#lrcfg_turnServerPassword:focus, QLineEdit#lrcfg_turnServer:focus, QLineEdit#lrcfg_publishedAddress:focus,
QLineEdit#lrcfg_registeredName:focus, QLineEdit#lrcfg_nameServiceURL:focus, QLineEdit#lrcfg_username:focus{
QLineEdit#lrcfg_registeredName:focus, QLineEdit#lrcfg_nameServiceURL:focus, QLineEdit#lrcfg_username:focus,
QLineEdit#profileNameEdit:focus{
border-color: #3AC0D2;
}
......
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