Commit 72cd6229 authored by camilo higuita's avatar camilo higuita

remove template models and use mauikit base models instead, and now more fixes on the dialer ui

parent e796f267
......@@ -30,8 +30,6 @@ include_directories(
set(dialer_SRCS
src/main.cpp
src/models/baselist.cpp
src/models/basemodel.cpp
src/models/contacts/contactsmodel.cpp
src/models/contacts/calllogs.cpp
src/interfaces/linuxinterface.cpp
......@@ -40,8 +38,6 @@ set(dialer_SRCS
set(dialer_HDRS
src/union.h
src/models/baselist.h
src/models/basemodel.h
src/models/contacts/contactsmodel.h
src/models/contacts/calllogs.h
src/interfaces/abstractinterface.h
......
......@@ -8,7 +8,6 @@
#include <MauiKit/fmh.h>
#endif
/**
* This is an abstract class for handling the contacts,
* it describes tha basic methods needed for Maui Dialer
......
......@@ -159,7 +159,9 @@ bool LinuxInterface::insertContact(const FMH::MODEL &contact)
QCryptographicHash hash(QCryptographicHash::Sha1);
hash.addData(adr.name().toUtf8());
QFile file(this->path + "/" + hash.result().toHex() + ".vcf");
if (!file.open(QFile::WriteOnly)) {
if (!file.open(QFile::WriteOnly))
{
qWarning() << "Couldn't save vCard: Couldn't open file for writing.";
return false;
}
......@@ -291,6 +293,7 @@ bool LinuxInterface::removeContact(const QString &id)
return QFile::remove(QString(id).remove("vcard:/"));
}
QImage LinuxInterface::contactPhoto(const QString &id)
{
auto personUri = id;
......
......@@ -13,13 +13,9 @@
#include <QApplication>
#endif
#include <memory>
#include "src/union.h"
#include "./src/models/basemodel.h"
#include "./src/models/baselist.h"
#include "./src/models/contacts/contactsmodel.h"
#include "./src/models/contacts/calllogs.h"
#include "models/contacts/contactsmodel.h"
#include "models/contacts/calllogs.h"
#include "interfaces/contactimage.h"
#ifdef STATIC_KIRIGAMI
......@@ -81,8 +77,6 @@ int main(int argc, char *argv[])
#endif
engine.addImageProvider("contact", new ContactImage(QQuickImageProvider::ImageType::Image));
qmlRegisterUncreatableType<BaseList>("UnionModels", 1, 0, "BaseList", QStringLiteral("BaseList should not be created in QML"));
qmlRegisterType<BaseModel>("UnionModels", 1, 0, "BaseModel");
qmlRegisterType<ContactsModel>("UnionModels", 1, 0, "ContactsList");
qmlRegisterType<CallLogs>("UnionModels", 1, 0, "CallLogs");
......
......@@ -92,7 +92,7 @@ Maui.ApplicationWindow
headBar.rightContent: ToolButton
{
id: _dialerButton
icon.name: "show-grid"
icon.name: "call-start"
// icon.name: "dialer-pad"
// icon.color: currentView === views.dialer ? Kirigami.Theme.highlightColor : Kirigami.Theme.textColor
// text: qsTr("Dialer")
......
#include "baselist.h"
BaseList::BaseList(QObject *parent) : QObject(parent)
{
}
#ifndef BASELIST_H
#define BASELIST_H
#ifdef STATIC_MAUIKIT
#include "fm.h"
#include "fmh.h"
#else
#include <MauiKit/fm.h>
#include <MauiKit/fmh.h>
#endif
class BaseList : public QObject
{
Q_OBJECT
public:
explicit BaseList(QObject *parent = nullptr);
//* To be overrided *//
virtual FMH::MODEL_LIST items() const {return FMH::MODEL_LIST({{}});}
protected:
signals:
void preItemAppended();
void postItemAppended();
void preItemAppendedAt(int index);
void preItemRemoved(int index);
void postItemRemoved();
void updateModel(int index, QVector<int> roles);
void preListChanged();
void postListChanged();
public slots:
virtual QVariantMap get(const int &index) const
{
Q_UNUSED(index);
return QVariantMap();
}
virtual bool update(const int &index, const QVariant &value, const int &role)
{
Q_UNUSED(index);
Q_UNUSED(value);
Q_UNUSED(role);
return false;
}
virtual bool update(const QVariantMap &data, const int &index)
{
Q_UNUSED(index);
Q_UNUSED(data);
return false;
}
virtual bool update(const FMH::MODEL &data)
{
Q_UNUSED(data);
return false;
}
virtual bool insert(const QVariantMap &map)
{
Q_UNUSED(map);
return false;
}
virtual bool remove(const int &index)
{
Q_UNUSED(index);
return false;
}
};
#endif // BASELIST_H
#include "basemodel.h"
#include "baselist.h"
BaseModel::BaseModel(QObject *parent)
: QAbstractListModel(parent),
mList(nullptr)
{}
int BaseModel::rowCount(const QModelIndex &parent) const
{
if (parent.isValid() || !mList)
return 0;
return mList->items().size();
}
QVariant BaseModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid() || !mList)
return QVariant();
return mList->items().at(index.row())[static_cast<FMH::MODEL_KEY>(role)];
}
bool BaseModel::setData(const QModelIndex &index, const QVariant &value, int role)
{
if (!mList)
return false;
if (mList->update(index.row(), value, role))
{
emit dataChanged(index, index, QVector<int>() << role);
return true;
}
return false;
}
Qt::ItemFlags BaseModel::flags(const QModelIndex &index) const
{
if (!index.isValid())
return Qt::NoItemFlags;
return Qt::ItemIsEditable; // FIXME: Implement me!
}
QHash<int, QByteArray> BaseModel::roleNames() const
{
QHash<int, QByteArray> names;
for(auto key : FMH::MODEL_NAME.keys())
names[key] = QString(FMH::MODEL_NAME[key]).toUtf8();
return names;
}
BaseList *BaseModel::getList() const
{
return this->mList;
}
void BaseModel::setList(BaseList *value)
{
beginResetModel();
if(mList)
mList->disconnect(this);
mList = value;
if(mList)
{
connect(this->mList, &BaseList::preItemAppended, this, [=]()
{
const int index = mList->items().size();
beginInsertRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemAppended, this, [=]()
{
endInsertRows();
});
connect(this->mList, &BaseList::preItemAppendedAt, this, [=](int index)
{
beginInsertRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::preItemRemoved, this, [=](int index)
{
beginRemoveRows(QModelIndex(), index, index);
});
connect(this->mList, &BaseList::postItemRemoved, this, [=]()
{
endRemoveRows();
});
connect(this->mList, &BaseList::updateModel, this, [=](int index, QVector<int> roles)
{
emit this->dataChanged(this->index(index), this->index(index), roles);
});
connect(this->mList, &BaseList::preListChanged, this, [=]()
{
beginResetModel();
});
connect(this->mList, &BaseList::postListChanged, this, [=]()
{
endResetModel();
});
}
endResetModel();
}
QVariantMap BaseModel::get(const int &index) const
{
return this->mList->get(index);
}
#ifndef BASEMODEL_H
#define BASEMODEL_H
#include <QAbstractListModel>
#include <QList>
class BaseList;
class BaseModel : public QAbstractListModel
{
Q_OBJECT
Q_PROPERTY(BaseList *list READ getList WRITE setList)
public:
explicit BaseModel(QObject *parent = nullptr);
// Basic functionality:
int rowCount(const QModelIndex &parent = QModelIndex()) const override;
QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override;
// Editable:
bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole) override;
Qt::ItemFlags flags(const QModelIndex& index) const override;
virtual QHash<int, QByteArray> roleNames() const override;
BaseList* getList() const;
void setList(BaseList *value);
private:
BaseList *mList;
signals:
void listChanged();
public slots:
QVariantMap get(const int &index) const;
};
#endif // NOTESMODEL_H
......@@ -9,9 +9,7 @@
#include "mauiandroid.h"
#endif
#define ORDER(a) a == 0 ? > : <
CallLogs::CallLogs(QObject *parent) : BaseList(parent)
CallLogs::CallLogs(QObject *parent) : MauiList(parent)
{
this->getList();
}
......
......@@ -2,9 +2,15 @@
#define CALLLOGS_H
#include <QObject>
#include "../baselist.h"
#ifdef STATIC_MAUIKIT
#include "fm.h"
#include "mauilist.h"
#else
#include <MauiKit/fm.h>
#include <MauiKit/mauilist.h>
#endif
class CallLogs : public BaseList
class CallLogs : public MauiList
{
Q_OBJECT
Q_PROPERTY(CallLogs::SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
......@@ -30,7 +36,8 @@ public:
}; Q_ENUM(ORDER)
explicit CallLogs(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override;
FMH::MODEL_LIST items() const override final;
void setSortBy(const CallLogs::SORTBY &sort);
CallLogs::SORTBY getSortBy() const;
......@@ -50,7 +57,7 @@ signals:
void orderChanged();
public slots:
QVariantMap get(const int &index) const override;
QVariantMap get(const int &index) const;
void refresh();
};
......
......@@ -6,6 +6,7 @@
#else
#include "linuxinterface.h"
#endif
#ifdef STATIC_MAUIKIT
#include "fm.h"
#else
......@@ -15,7 +16,7 @@
#ifdef Q_OS_ANDROID
ContactsModel::ContactsModel(QObject *parent) : BaseList(parent), syncer(new AndroidInterface(this))
#else
ContactsModel::ContactsModel(QObject *parent) : BaseList(parent), syncer(new LinuxInterface(this))
ContactsModel::ContactsModel(QObject *parent) : MauiList(parent), syncer(new LinuxInterface(this))
#endif
{
connect(syncer, &AbstractInterface::contactsReady, [this](FMH::MODEL_LIST contacts)
......@@ -310,7 +311,6 @@ void ContactsModel::appendQuery(const QString &query)
this->query = query;
emit this->preListChanged();
emit this->postListChanged();
}
......@@ -318,9 +318,7 @@ void ContactsModel::appendQuery(const QString &query)
void ContactsModel::clear()
{
emit this->preListChanged();
this->list.clear();
emit this->postListChanged();
}
......@@ -338,7 +336,10 @@ void ContactsModel::refresh()
QVariantList ContactsModel::getAccounts()
{
QVariantList res;
for(const auto &account : syncer->getAccounts())
res << FM::toMap(account);
auto accounts= syncer->getAccounts();
// for(const auto &account : syncer->getAccounts())
// res << FM::toMap(account);
std::transform(accounts.begin(), accounts.end(), res.begin(), FM::toMap);
return res;
}
......@@ -2,10 +2,15 @@
#define CONTACTSMODEL_H
#include <QObject>
#include "baselist.h"
#ifdef STATIC_MAUIKIT
#include "mauilist.h"
#else
#include <MauiKit/mauilist.h>
#endif
class AbstractInterface;
class ContactsModel : public BaseList
class ContactsModel : public MauiList
{
Q_OBJECT
Q_PROPERTY(QString query READ getQuery WRITE setQuery NOTIFY queryChanged)
......@@ -33,7 +38,7 @@ public:
explicit ContactsModel(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override;
FMH::MODEL_LIST items() const override final;
QString getQuery() const;
void setQuery(const QString &query);
......@@ -75,10 +80,10 @@ signals:
void sortByChanged();
public slots:
QVariantMap get(const int &index) const override final;
bool insert(const QVariantMap &map) override final;
bool update(const QVariantMap &map, const int &index) override final;
bool remove(const int &index) override final;
QVariantMap get(const int &index) const;
bool insert(const QVariantMap &map);
bool update(const QVariantMap &map, const int &index);
bool remove(const int &index);
void append(const QVariantMap &item, const int &at);
void append(const QVariantMap &item);
......
......@@ -10,5 +10,6 @@
<file>widgets/MessageComposer.qml</file>
<file>views/contacts/GridContactDelegate.qml</file>
<file>views/logs/LogsView.qml</file>
<file>views/dialer/DialerButton.qml</file>
</qresource>
</RCC>
#ifndef UNION_H
#define UNION_H
#if (defined (Q_OS_LINUX) && !defined (Q_OS_ANDROID))
#include <MauiKit/fmh.h>
#else
#include "fmh.h"
#endif
#include <QString>
#define APPNAME "Communicator"
#define APPVERSION "1.0.0"
......@@ -15,19 +11,6 @@ namespace UNI
const QString AppName = APPNAME;
const QString AppVersion = APPVERSION;
const QString AppComment = "Contacs manager and dialer";
const QString DBName = "collection.db";
const QString CollectionDBPath = FMH::DataPath + QString("/%1/").arg(APPNAME);
enum class TABLE : uint8_t
{
CONTACTS
};
static const QMap<TABLE,QString> TABLEMAP =
{
{TABLE::CONTACTS,"contacts"}
};
};
#endif // UNION_H
......@@ -310,7 +310,7 @@ Maui.Dialog
{
Layout.fillWidth: true
spacing: space.small
visible: contact.n
visible: contact.account
Label
{
Layout.fillHeight: true
......
......@@ -20,7 +20,7 @@ Maui.Page
property bool showAccountFilter: false
padding: space.big
BaseModel
Maui.BaseModel
{
id: _contactsModel
list: _contactsList
......
......@@ -2,7 +2,6 @@ import QtQuick 2.9
import QtQuick.Controls 2.3
import org.kde.mauikit 1.0 as Maui
import QtQuick.Layouts 1.3
import UnionModels 1.0
GridLayout
{
......@@ -27,20 +26,12 @@ GridLayout
Layout.fillHeight: true
Layout.fillWidth: true
Button
DialerButton
{
height: buttonSize
width: height
anchors.centerIn: parent
// bg.radius: Math.max(width, height)
text: modelData
font.bold: true
font.weight: Font.Bold
font.pointSize: buttonFontSize
onClicked:
{
dialString += text;
}
}
}
}
......
import QtQuick 2.0
import QtQuick.Controls 2.3
import org.kde.kirigami 2.7 as Kirigami
Button
{
id: control
// bg.radius: Math.max(width, height)
font.bold: true
font.weight: Font.Bold
font.pointSize: buttonFontSize
onClicked:
{
dialString += text;
}
contentItem: Label
{
id: _text
anchors.fill: parent
visible: text
text: control.text
font: control.font
color: !control.enabled ? Kirigami.Theme.disabledTextColor :
control.highlighted || control.down ? Kirigami.Theme.highlightedTextColor : Kirigami.Theme.textColor
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle
{
radius: Math.max(parent.height, parent.width)
color: !control.enabled ? Kirigami.Theme.backgroundColor :
control.highlighted || control.down ? Kirigami.Theme.highlightColor : Kirigami.Theme.backgroundColor
border.color: Qt.tint(Kirigami.Theme.textColor, Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.7))
}
}
import QtQuick 2.9
import QtQuick.Controls 2.3
import org.kde.mauikit 1.0 as Maui
import org.kde.kirigami 2.6 as Kirigami
import org.kde.kirigami 2.7 as Kirigami
import QtQuick.Layouts 1.3
import UnionModels 1.0
import "../contacts"
Maui.Page
......@@ -17,8 +16,7 @@ Maui.Page
// Qt.inputMethod.hide();
_contacsView.list.query = "tel=" + dialString
}
// colorScheme.backgroundColor: backgroundColor
headBar.visible: false
// colorScheme.backgroundColor: backgroundColor
// footBar.middleContent: Maui.ToolButton
// {
......@@ -33,7 +31,31 @@ Maui.Page
// footBarOverlap: true
// footBarAligment: Qt.AlignRight
footBar.drawBorder:false
headBar.middleContent: Maui.TextField
{
id: _textField
Layout.fillWidth: true
inputMethodHints: Qt.ImhDialableCharactersOnly
placeholderText: qsTr("Number...")
readOnly: true
font.bold: true
font.weight: Font.Bold
font.pointSize: fontSizes.huge
font.letterSpacing: space.tiny
horizontalAlignment: TextInput.AlignHCenter
background: Rectangle
{
color: "transparent"
}
// enabled: false
}
footBar.background: Rectangle
{
color: "transparent"
}
footBar.implicitHeight: iconSizes.big * 3
footBar.middleContent: [
......@@ -44,12 +66,12 @@ Maui.Page
Button
{
icon.name: "send-sms"
icon.name: "message-new"
icon.color: Kirigami.Theme.textColor
height: buttonSize
width: height
anchors.centerIn: parent
// bg.radius: Math.max(width, height)
// bg.radius: Math.max(width, height)
// colorScheme.backgroundColor: infoColor
onClicked:
{
......@@ -67,12 +89,14 @@ Maui.Page
Button
{
icon.name: "dialer-call"
icon.name: "call-start"
icon.color: "white"
icon.width: iconSizes.big
icon.height: iconSizes.big
height: buttonSize
width: height
anchors.centerIn: parent
// bg.radius: Math.max(width, height)
// bg.radius: Math.max(width, height)
Kirigami.Theme.backgroundColor: suggestedColor
onClicked:
......@@ -97,7 +121,7 @@ Maui.Page
height: iconSizes.big * 2
width: height
anchors.centerIn: parent
// bg.radius: Math.max(width, height)
// bg.radius: Math.max(width, height)
// colorScheme.backgroundColor: warningColor
onClicked:
......@@ -112,47 +136,19 @@ Maui.Page
{
id: _layout
width: Math.min(isWide ? control.width * 0.8 : control.width * 0.95, unit * 500)
height: parent.height
// height: parent.height
anchors.centerIn: parent
spacing: space.big
Rectangle
{
Layout.preferredHeight: toolBarHeight * 1.3
Layout.fillWidth: true
Layout.alignment: Qt.AlignTop
color: cardColor
// border.color: borderColor
radius: radiusV * 2
Maui.TextField
{
id: _textField
anchors.fill: parent
inputMethodHints: Qt.ImhDialableCharactersOnly
placeholderText: qsTr("Number...")
readOnly: true
font.bold: true
font.weight: Font.Bold
font.pointSize: fontSizes.huge
font.letterSpacing: space.tiny
// enabled: false
}
}
ListView
{
id: _suggestionListView
spacing: space.big
clip: true
visible: dialString.length
Layout.fillWidth: true
Layout.minimumHeight: (unit * 80) * 1.5
Layout.fillHeight: true
Layout.preferredHeight: control.height * 0.3
visible: count
Layout.fillWidth: visible
Layout.minimumHeight: visible ? _60 : 0
Layout.preferredHeight: visible ? 60 * 2 : 0
model: _contacsView.listModel
......
......@@ -27,7 +27,7 @@ Maui.Page
onActionTriggered: _newContactDialog.open()
}
BaseModel
Maui.BaseModel