Commit be0aa5a1 authored by Edric Milaret's avatar Edric Milaret Committed by gerrit2

contact: refactor UI add to contact

- Merge ContactDialog and ContactPicker

Issue: #78235
Change-Id: I9b36668da9974db0dc9eeb4f512182b4ce43ac49
parent 40def4cf
......@@ -48,7 +48,6 @@ SOURCES += main.cpp\
videoview.cpp \
videooverlay.cpp \
imdelegate.cpp \
contactdialog.cpp \
contactpicker.cpp \
contactmethodpicker.cpp
......@@ -74,7 +73,6 @@ HEADERS += mainwindow.h \
videoview.h \
videooverlay.h \
imdelegate.h \
contactdialog.h \
contactpicker.h \
contactmethodpicker.h
......@@ -90,7 +88,6 @@ FORMS += mainwindow.ui \
instantmessagingwidget.ui \
videoview.ui \
videooverlay.ui \
contactdialog.ui \
contactpicker.ui \
contactmethodpicker.ui
......
......@@ -39,7 +39,6 @@
#include "wizarddialog.h"
#include "windowscontactbackend.h"
#include "contactdialog.h"
#include "contactpicker.h"
#include "contactmethodpicker.h"
......@@ -88,7 +87,7 @@ CallWidget::CallWidget(QWidget *parent) :
ui->callList->setModel(callModel_);
ui->callList->setSelectionModel(callModel_->selectionModel());
auto personCollection = PersonModel::instance()->
PersonModel::instance()->
addCollection<WindowsContactBackend>(LoadOptions::FORCE_ENABLED);
CategorizedContactModel::instance()->setSortAlphabetical(false);
......@@ -126,40 +125,13 @@ CallWidget::CallWidget(QWidget *parent) :
connect(copyAction, &QAction::triggered, [=]() {
QApplication::clipboard()->setText(contactMethod->uri());
});
if (not contactMethod->contact()) {
auto addNew = new QAction("Add to new contact", this);
menu.addAction(addNew);
connect(addNew, &QAction::triggered, [=]() {
ContactDialog dialog(contactMethod->uri());
auto ret = dialog.exec();
if (!ret || dialog.getName().isEmpty())
return;
auto *newPerson = new Person();
newPerson->setFormattedName(dialog.getName());
Person::ContactMethods cM;
cM.append(contactMethod);
newPerson->setContactMethods(cM);
newPerson->setUid(Utils::GenGUID().toLocal8Bit());
PersonModel::instance()->addNewPerson(newPerson, personCollection);
});
auto addExisting = new QAction("Add to existing contact", this);
if (not contactMethod->contact() || contactMethod->contact()->isPlaceHolder()) {
auto addExisting = new QAction("Add to contact", this);
menu.addAction(addExisting);
connect(addExisting, &QAction::triggered, [=]() {
/* Force LRC to update contact model as adding a number
to a contact without one didn't render him reachable */
CategorizedContactModel::instance()->setUnreachableHidden(false);
ContactPicker contactPicker;
ContactPicker contactPicker(contactMethod);
contactPicker.move(globalPos.x(), globalPos.y() - (contactPicker.height()/2));
auto ret = contactPicker.exec();
if (!ret)
return;
auto p = contactPicker.getPersonSelected();
Person::ContactMethods cM (p->phoneNumbers());
cM.append(contactMethod);
p->setContactMethods(cM);
p->save();
CategorizedContactModel::instance()->setUnreachableHidden(true);
contactPicker.exec();
});
}
menu.exec(globalPos);
......
/***************************************************************************
* Copyright (C) 2015 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@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 "contactdialog.h"
#include "ui_contactdialog.h"
ContactDialog::ContactDialog(const QString &number, QWidget *parent) :
QDialog(parent),
ui(new Ui::ContactDialog)
{
ui->setupUi(this);
ui->numberLineEdit->setText(number);
}
ContactDialog::~ContactDialog()
{
delete ui;
}
const QString&
ContactDialog::getName()
{
return contactName_;
}
void
ContactDialog::on_nameLineEdit_textChanged(const QString &arg1)
{
contactName_ = arg1;
}
/***************************************************************************
* Copyright (C) 2015 by Savoir-faire Linux *
* Author: Edric Ladent Milaret <edric.ladent-milaret@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 CONTACTDIALOG_H
#define CONTACTDIALOG_H
#include <QDialog>
namespace Ui {
class ContactDialog;
}
class ContactDialog : public QDialog
{
Q_OBJECT
public:
explicit ContactDialog(const QString& number, QWidget *parent = 0);
~ContactDialog();
const QString &getName();
private slots:
void on_nameLineEdit_textChanged(const QString &arg1);
private:
Ui::ContactDialog *ui;
QString contactName_;
};
#endif // CONTACTDIALOG_H
......@@ -19,20 +19,31 @@
#include "contactpicker.h"
#include "ui_contactpicker.h"
#include "categorizedcontactmodel.h"
#include "personmodel.h"
#include "utils.h"
ContactPicker::ContactPicker(QWidget *parent) :
ContactPicker::ContactPicker(ContactMethod *number, QWidget *parent) :
QDialog(parent),
ui(new Ui::ContactPicker),
personSelected_(nullptr)
personSelected_(nullptr),
number_(number)
{
ui->setupUi(this);
this->setWindowFlags(Qt::CustomizeWindowHint);
this->setWindowFlags(Qt::FramelessWindowHint);
this->setWindowFlags(Qt::FramelessWindowHint | Qt::Popup);
auto personModel = PersonModel::instance();
ui->contactView->setModel(personModel);
contactProxyModel_ = new OnlyPersonProxyModel(PersonModel::instance());
contactProxyModel_->setSortRole(static_cast<int>(Qt::DisplayRole));
contactProxyModel_->sort(0,Qt::AscendingOrder);
contactProxyModel_->setFilterRole(Qt::DisplayRole);
ui->contactView->setModel(contactProxyModel_);
ui->numberLineEdit->setText(number->uri());
}
ContactPicker::~ContactPicker()
......@@ -43,18 +54,56 @@ ContactPicker::~ContactPicker()
void
ContactPicker::on_contactView_doubleClicked(const QModelIndex &index)
{
personSelected_ = index.data(static_cast<int>(Person::Role::Object)).value<Person*>();
Q_UNUSED(index)
this->accept();
}
void
ContactPicker::accept()
{
/* Force LRC to update contact model as adding a number
to a contact without one didn't render him reachable */
CategorizedContactModel::instance()->setUnreachableHidden(false);
auto idx = ui->contactView->currentIndex();
//There is only one collection on Windows
auto personCollection = PersonModel::instance()->collections().at(0);
if (not ui->nameLineEdit->text().isEmpty()) {
auto *newPerson = new Person();
newPerson->setFormattedName(ui->nameLineEdit->text());
Person::ContactMethods cM;
cM.append(number_);
newPerson->setContactMethods(cM);
newPerson->setUid(Utils::GenGUID().toLocal8Bit());
PersonModel::instance()->addNewPerson(newPerson, personCollection);
} else if (idx.isValid()) {
auto p = idx.data(static_cast<int>(Person::Role::Object)).value<Person*>();
Person::ContactMethods cM (p->phoneNumbers());
cM.append(number_);
p->setContactMethods(cM);
p->save();
}
CategorizedContactModel::instance()->setUnreachableHidden(true);
QDialog::accept();
}
void
ContactPicker::on_okButton_clicked()
{
this->accept();
}
Person*
ContactPicker::getPersonSelected()
void
ContactPicker::on_createNewButton_clicked()
{
return personSelected_;
ui->stackedWidget->setCurrentIndex(1);
}
void
ContactPicker::on_cancelButton_clicked()
ContactPicker::on_searchBar_textChanged(const QString &arg1)
{
this->reject();
contactProxyModel_->setFilterRegExp(QRegExp(arg1, Qt::CaseInsensitive, QRegExp::FixedString));
}
......@@ -20,31 +20,53 @@
#define CONTACTPICKER_H
#include <QDialog>
#include <QSortFilterProxyModel>
#include "personmodel.h"
#include "contactmethod.h"
namespace Ui {
class ContactPicker;
}
class OnlyPersonProxyModel : public QSortFilterProxyModel
{
public:
OnlyPersonProxyModel(QAbstractItemModel* parent) : QSortFilterProxyModel(parent)
{
setSourceModel(parent);
}
virtual bool filterAcceptsRow(int source_row, const QModelIndex& source_parent) const
{
bool match = filterRegExp().indexIn(sourceModel()->index(source_row,0,source_parent).data(Qt::DisplayRole).toString()) != -1;
return match && !sourceModel()->index(source_row,0,source_parent).parent().isValid();
}
};
class ContactPicker : public QDialog
{
Q_OBJECT
public:
explicit ContactPicker(QWidget *parent = 0);
explicit ContactPicker(ContactMethod* number, QWidget *parent = 0);
~ContactPicker();
Person *getPersonSelected();
protected slots:
void accept();
//UI SLOTS
private slots:
void on_contactView_doubleClicked(const QModelIndex &index);
void on_cancelButton_clicked();
void on_okButton_clicked();
void on_createNewButton_clicked();
void on_searchBar_textChanged(const QString &arg1);
private:
Ui::ContactPicker *ui;
Person *personSelected_;
ContactMethod* number_;
OnlyPersonProxyModel* contactProxyModel_;
};
#endif // CONTACTPICKER_H
......@@ -6,22 +6,133 @@
<rect>
<x>0</x>
<y>0</y>
<width>249</width>
<height>438</height>
<width>271</width>
<height>475</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListView" name="contactView"/>
</item>
<item>
<widget class="QPushButton" name="cancelButton">
<property name="text">
<string>Cancel</string>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0" colspan="2">
<widget class="QStackedWidget" name="stackedWidget">
<property name="currentIndex">
<number>0</number>
</property>
<widget class="QWidget" name="page">
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<widget class="QLabel" name="label_2">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>Existing Contact</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="searchBar">
<property name="placeholderText">
<string>Search...</string>
</property>
<property name="clearButtonEnabled">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QListView" name="contactView"/>
</item>
<item>
<widget class="QPushButton" name="createNewButton">
<property name="text">
<string>Create new contact</string>
</property>
</widget>
</item>
</layout>
</widget>
<widget class="QWidget" name="page_2">
<layout class="QVBoxLayout" name="verticalLayout_3">
<item>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QLabel" name="label">
<property name="font">
<font>
<weight>75</weight>
<bold>true</bold>
</font>
</property>
<property name="text">
<string>New Contact</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<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>
<widget class="QLineEdit" name="nameLineEdit">
<property name="placeholderText">
<string>Enter a name here...</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="numberLineEdit">
<property name="enabled">
<bool>false</bool>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</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>
<widget class="QPushButton" name="okButton">
<property name="text">
<string>Create</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</widget>
</item>
</layout>
......
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