Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

Commit 45ca06c9 authored by Camilo higuita's avatar Camilo higuita

awork on the logs view

parent 92e537aa
......@@ -33,6 +33,7 @@ set(union_SRCS
src/models/baselist.cpp
src/models/basemodel.cpp
src/models/contacts/contactsmodel.cpp
src/models/contacts/calllogs.cpp
src/interfaces/kcontactsinterface.cpp
src/interfaces/contactimage.cpp
)
......@@ -45,6 +46,7 @@ set(union_HDRS
src/models/baselist.h
src/models/basemodel.h
src/models/contacts/contactsmodel.h
src/models/contacts/calllogs.h
src/interfaces/kcontactsinterface.h
src/interfaces/contactimage.h
)
......
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
<!-- Written by QtCreator 4.9.0, 2019-05-04T08:22:14. -->
<!-- Written by QtCreator 4.9.0, 2019-05-17T14:13:37. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
......
......@@ -18,9 +18,6 @@ void AndroidIntents::init()
this->mauia = new MAUIAndroid(this);
}
AndroidIntents *AndroidIntents::instance = nullptr;
AndroidIntents *AndroidIntents::getInstance()
......@@ -85,6 +82,11 @@ void AndroidIntents::getContacts(const GET_TYPE &type)
this->fetchContacts();
}
void AndroidIntents::getCallLogs()
{
const auto logs = MAUIAndroid::getCallLogs();
}
QVariantMap AndroidIntents::getContact(const QString &id) const
{
return this->mauia->getContact(id);
......
......@@ -24,6 +24,7 @@ public:
FMH::MODEL_LIST getAccounts(const GET_TYPE &type = GET_TYPE::CACHED);
void getContacts(const GET_TYPE &type = GET_TYPE::CACHED);
void getCallLogs();
QVariantMap getContact(const QString &id) const;
......
......@@ -29,7 +29,6 @@ Synchroniser::Synchroniser(QObject *parent) : QObject (parent)
#endif
}
void Synchroniser::getContacts(const bool &cached)
{
#ifdef Q_OS_ANDROID
......
......@@ -37,6 +37,7 @@ private:
signals:
void contactsReady(FMH::MODEL_LIST contacts);
void callLogsReady();
public slots:
};
......
......@@ -18,6 +18,7 @@
#include "./src/models/basemodel.h"
#include "./src/models/baselist.h"
#include "./src/models/contacts/contactsmodel.h"
#include "./src/models/contacts/calllogs.h"
#include "interfaces/contactimage.h"
#ifdef STATIC_KIRIGAMI
......@@ -62,6 +63,7 @@ int main(int argc, char *argv[])
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");
engine.load(QUrl(QStringLiteral("qrc:/main.qml")));
if (engine.rootObjects().isEmpty())
......
......@@ -5,6 +5,7 @@ import QtQuick.Layouts 1.3
import "views/contacts"
import "views/dialer"
import "views/logs"
import "widgets"
//import "views/favs"
......@@ -15,7 +16,7 @@ Maui.ApplicationWindow
about.appDescription: qsTr("Union lists your contacts and keeps them synced across devices.")
about.appIcon: "qrc:/smartphone.svg"
property int currentView : views.contacts
property int currentView : views.favs
readonly property var views : ({
favs: 0,
log: 1,
......@@ -141,9 +142,9 @@ Maui.ApplicationWindow
}
Maui.Page
LogsView
{
id: _logView
id: _logView
}
ContactsView
......
#include "calllogs.h"
#ifdef STATIC_MAUIKIT
#include "mauiandroid.h"
#endif
#define ORDER(a) a == 0 ? > : <
CallLogs::CallLogs(QObject *parent) : BaseList(parent)
{
this->getList();
}
FMH::MODEL_LIST CallLogs::items() const
{
return this->list;
}
void CallLogs::setSortBy(const CallLogs::SORTBY &sort)
{
if(this->sort == sort)
return;
this->sort = sort;
this->preListChanged();
this->sortList();
this->postListChanged();
emit this->sortByChanged();
}
CallLogs::SORTBY CallLogs::getSortBy() const
{
return this->sort;
}
void CallLogs::setOrder(const CallLogs::ORDER &order)
{
if(this->order == order)
return;
this->order = order;
this->preListChanged();
this->sortList();
this->postListChanged();
emit this->orderChanged();
}
CallLogs::ORDER CallLogs::getOrder() const
{
return this->order;
}
void CallLogs::getList(const bool &cached)
{
emit this->preListChanged();
#ifdef STATIC_MAUIKIT
for(const auto &item : MAUIAndroid::getCallLogs())
this->list << FM::toModel(item.toMap());
#endif
this->sortList();
emit this->postListChanged();
}
template<typename T>
static bool OP(const T &t1, const T &t2, const CallLogs::ORDER &order)
{
switch(order)
{
case CallLogs::ORDER::ASC:
return t1 < t2;
case CallLogs::ORDER::DESC:
return t1 > t2;
}
return false;
};
void CallLogs::sortList()
{
if(this->sort == CallLogs::SORTBY::NONE)
return;
const auto key = static_cast<FMH::MODEL_KEY>(this->sort);
const auto order = this->order;
std::sort(this->list.begin(), this->list.end(), [&key, &order](const FMH::MODEL &e1, const FMH::MODEL &e2) -> bool
{
switch(key)
{
case FMH::MODEL_KEY::DATE:
{
auto currentTime = QDateTime::currentDateTime();
auto date1 = QDateTime::fromString(e1[key], "dd-MM-yyyy HH:mm");
auto date2 = QDateTime::fromString(e2[key], "dd-MM-yyyy HH:mm");
if (OP(date1.secsTo(currentTime), date2.secsTo(currentTime), order))
return true;
break;
}
case FMH::MODEL_KEY::N:
case FMH::MODEL_KEY::TYPE:
case FMH::MODEL_KEY::TEL:
{
const auto str1 = QString(e1[key]).toLower();
const auto str2 = QString(e2[key]).toLower();
if(OP(str1, str2, order))
return true;
break;
}
default:
if(OP(e1[key], e2[key], order))
return true;
}
return false;
});
}
QVariantMap CallLogs::get(const int &index) const
{
if(index >= this->list.size() || index < 0)
return QVariantMap();
QVariantMap res;
const auto item = this->list.at(index);
res = FM::toMap(item);
return res;
}
void CallLogs::refresh()
{
this->getList();
}
#ifndef CALLLOGS_H
#define CALLLOGS_H
#include <QObject>
#include "../baselist.h"
class CallLogs : public BaseList
{
Q_OBJECT
Q_PROPERTY(CallLogs::SORTBY sortBy READ getSortBy WRITE setSortBy NOTIFY sortByChanged)
Q_PROPERTY(CallLogs::ORDER order READ getOrder WRITE setOrder NOTIFY orderChanged)
public:
enum SORTBY : uint_fast8_t
{
DATE = FMH::MODEL_KEY::DATE, //when the contact was last contacted
N = FMH::MODEL_KEY::N, //contact name
TEL = FMH::MODEL_KEY::TEL, //contact phone
DURATION = FMH::MODEL_KEY::DURATION, //how many times contacts has been messaged or called
TYPE = FMH::MODEL_KEY::TYPE,
NONE
}; Q_ENUM(SORTBY)
enum ORDER : uint_fast8_t
{
ASC,
DESC
}; Q_ENUM(ORDER)
explicit CallLogs(QObject *parent = nullptr);
FMH::MODEL_LIST items() const override;
void setSortBy(const CallLogs::SORTBY &sort);
CallLogs::SORTBY getSortBy() const;
void setOrder(const CallLogs::ORDER &order);
CallLogs::ORDER getOrder() const;
private:
FMH::MODEL_LIST list;
void getList(const bool &cached = false);
void sortList();
CallLogs::SORTBY sort = CallLogs::SORTBY::DATE;
CallLogs::ORDER order = CallLogs::ORDER::ASC;
signals:
void sortByChanged();
void orderChanged();
public slots:
QVariantMap get(const int &index) const override;
void refresh();
};
#endif // CALLLOGS_H
......@@ -10,5 +10,6 @@
<file>db/script.sql</file>
<file>widgets/MessageComposer.qml</file>
<file>views/contacts/GridContactDelegate.qml</file>
<file>views/logs/LogsView.qml</file>
</qresource>
</RCC>
......@@ -17,6 +17,12 @@ SwipeDelegate
signal favClicked(int index)
property alias label1 : _label1
property alias label2 : _label2
property alias label3 : _label3
property alias label4 : _label4
background: Rectangle
{
color: hovered ? Qt.lighter(cardColor) : cardColor
......@@ -153,7 +159,8 @@ SwipeDelegate
Label
{
visible: (model.n && model.n.length)
id: _label1
visible: text.length
Layout.fillHeight: visible
Layout.fillWidth: visible
text: model.n
......@@ -166,7 +173,8 @@ SwipeDelegate
Label
{
visible: (model.tel && model.tel.length)
id: _label2
visible: text.length
Layout.fillHeight: visible
Layout.fillWidth: visible
text: model.tel
......@@ -192,7 +200,8 @@ SwipeDelegate
Label
{
visible: (model.email && model.email.length)
id: _label3
visible: text.length
Layout.fillHeight: visible
Layout.fillWidth: visible
Layout.alignment: Qt.AlignRight
......@@ -208,7 +217,8 @@ SwipeDelegate
Label
{
visible: (model.title && model.tel.title)
id: _label4
visible: text.length
Layout.fillHeight: visible
Layout.fillWidth: visible
Layout.alignment: Qt.AlignRight
......
......@@ -18,6 +18,7 @@ Maui.Page
property bool gridView : false
property bool showAccountFilter: false
BaseModel
{
id: _contactsModel
......
import QtQuick 2.9
import QtQuick.Controls 2.3
import org.kde.mauikit 1.0 as Maui
import UnionModels 1.0
import "../contacts"
Maui.Page
{
id: control
headBarExit: false
headBar.visible: false
colorScheme.accentColor: "#615f7d"
colorScheme.backgroundColor: backgroundColor
colorScheme.textColor: textColor
BaseModel
{
id: _contactsModel
list: _callLogsModel
}
CallLogs
{
id: _callLogsModel
}
ListView
{
anchors.fill: parent
spacing: space.big
clip: true
section.property: "date"
section.criteria: ViewSection.FullString
section.labelPositioning: ViewSection.InlineLabels
section.delegate: Maui.LabelDelegate
{
label: Maui.FM.formatDate(section, "MM/dd/yyyy", "dd-MM-yyyy HH:mm")
isSection: true
boldLabel: true
// colorScheme.backgroundColor: "#333"
// colorScheme.textColor: "#fafafa"
// width: iconSize
// background: Rectangle
// {
// color: colorScheme.backgroundColor
// radius: radiusV
// }
}
model: _contactsModel
delegate: ContactDelegate
{
id: _delegate
label1.text: model.n + " / " + model.tel
label2.text: model.date
label3.text: model.type
height: unit * 60
width: isWide ? control.width * 0.8 : control.width * 0.95
anchors.horizontalCenter: parent.horizontalCenter
showMenuIcon: false
quickButtons: Maui.ToolButton
{
iconName: switch (model.type)
{
case "INCOMING" : return "go-bottom";
case "OUTGOING" : return "go-top";
case "MISSED" : return "dialog-close";
}
}
Connections
{
target: _delegate
onClicked:
{
view.currentIndex = index
_contactDialog.show(list.get(index))
}
onFavClicked:
{
var item = _contactsList.get(index)
item["fav"] = item.fav == "1" ? "0" : "1"
_contactsList.update(item, index)
}
}
}
ScrollBar.vertical: ScrollBar {}
}
}
......@@ -46,6 +46,7 @@ SOURCES += \
src/interfaces/contactimage.cpp \
src/models/baselist.cpp \
src/models/basemodel.cpp \
src/models/contacts/calllogs.cpp \
src/models/contacts/contactsmodel.cpp \
src/interfaces/synchroniser.cpp \
src/db/db.cpp \
......@@ -61,6 +62,7 @@ else: unix:!android: target.path = /opt/$${TARGET}/bin
HEADERS += \
src/interfaces/contactimage.h \
src/models/contacts/calllogs.h \
src/union.h \
src/db/db.h \
src/db/dbactions.h \
......
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