Commit 4f275ffe authored by Camilo higuita's avatar Camilo higuita

use new modeling

parent e8245f2c
......@@ -6,6 +6,7 @@
#include <QtConcurrent/QtConcurrentRun>
#include <QFuture>
#include <QFutureWatcher>
#include "fm.h"
AndroidIntents::AndroidIntents(QObject *parent) : QObject(parent)
{
......@@ -16,6 +17,8 @@ void AndroidIntents::init()
{
this->mauia = new MAUIAndroid(this);
this->m_accounts = this->accounts();
this->contacts();
}
AndroidIntents *AndroidIntents::instance = nullptr;
......@@ -26,7 +29,7 @@ AndroidIntents *AndroidIntents::getInstance()
{
instance = new AndroidIntents();
qDebug() << "getInstance(): First AndroidIntents instance\n";
instance->m_contacts = instance->contacts();
instance->init();
return instance;
} else
......@@ -41,64 +44,80 @@ void AndroidIntents::call(const QString &tel)
this->mauia->call(tel);
}
FMH::MODEL_LIST AndroidIntents::contacts()
void AndroidIntents::contacts()
{
QFutureWatcher<FMH::MODEL_LIST> *watcher = new QFutureWatcher<FMH::MODEL_LIST>;
connect(watcher, &QFutureWatcher<FMH::MODEL_LIST>::finished, [this, watcher]()
{
auto contacts = watcher->future().result();
this->m_contacts = contacts;
emit this->contactsReady();
});
QFuture<FMH::MODEL_LIST> t1 = QtConcurrent::run(AndroidIntents::fetchContacts);
watcher->setFuture(t1);
}
FMH::MODEL_LIST AndroidIntents::fetchContacts()
{
FMH::MODEL_LIST data;
QFutureWatcher<QString> *watcher = new QFutureWatcher<QString>;
connect(watcher, &QFutureWatcher<QString>::finished, [this, watcher]()
{
qDebug()<< "CONTACTS READY: ";
FMH::MODEL_LIST data;
const auto array = watcher->future().result();
auto list = MAUIAndroid::getContacts();
QString xmlData(array);
QDomDocument doc;
for(auto item : list)
data << FM::toModel(item.toMap());
if (!doc.setContent(xmlData)) return data;
// qDebug()<< "CONTACTS READY: 1";
const QDomNodeList nodeList = doc.documentElement().childNodes();
// QString xmlData(MAUIAndroid::getContacts());
// QDomDocument doc;
for (int i = 0; i < nodeList.count(); i++)
{
QDomNode n = nodeList.item(i);
// if (!doc.setContent(xmlData)) return data;
if(n.nodeName() == "item")
{
FMH::MODEL model;
auto contact = n.toElement().childNodes();
// qDebug()<< "CONTACTS READY: 2" << xmlData;
for(int i=0; i < contact.count(); i++)
{
const QDomNode m = contact.item(i);
if(m.nodeName() == "n")
{
const auto name = m.toElement().text();
model.insert(FMH::MODEL_KEY::N, name);
}else if(m.nodeName() == "tel")
{
const auto tel = m.toElement().text();
model.insert(FMH::MODEL_KEY::TEL, tel);
}else if(m.nodeName() == "email")
{
const auto email = m.toElement().text();
model.insert(FMH::MODEL_KEY::EMAIL, email);
}
}
// const QDomNodeList nodeList = doc.documentElement().childNodes();
data << model;
}
}
// for (int i = 0; i < nodeList.count(); i++)
// {
// qDebug()<< "CONTACTS READY: " << i;
this->m_contacts = data;
emit this->contactsReady();
});
// QDomNode n = nodeList.item(i);
QFuture<QString> t1 = QtConcurrent::run(MAUIAndroid::getContacts);
watcher->setFuture(t1);
// if(n.nodeName() == "item")
// {
// FMH::MODEL model;
// auto contact = n.toElement().childNodes();
// for(int i=0; i < contact.count(); i++)
// {
// const QDomNode m = contact.item(i);
// if(m.nodeName() == "n")
// {
// const auto name = m.toElement().text();
// model.insert(FMH::MODEL_KEY::N, name);
// }else if(m.nodeName() == "tel")
// {
// const auto tel = m.toElement().text();
// model.insert(FMH::MODEL_KEY::TEL, tel);
// }else if(m.nodeName() == "email")
// {
// const auto email = m.toElement().text();
// model.insert(FMH::MODEL_KEY::EMAIL, email);
// }
// }
// data << model;
// }
// }
// qDebug()<< "CONTACTS READY: " << data;
return data;
}
void AndroidIntents::addContact(const FMH::MODEL &contact, const FMH::MODEL &account)
......
......@@ -12,9 +12,22 @@ public:
static AndroidIntents *getInstance();
// explicit AndroidIntents(QObject *parent = nullptr);
/**
* @brief call
* @param tel
*/
void call(const QString &tel);
/*!
* \brief init
*/
void init();
//!
//! \brief addContact
//! \param contact
//! \param account
//!
void addContact(const FMH::MODEL &contact, const FMH::MODEL &account);
FMH::MODEL_LIST getAccounts() const;
FMH::MODEL_LIST getContacts() const;
......@@ -27,9 +40,18 @@ private:
FMH::MODEL_LIST m_accounts;
FMH::MODEL_LIST m_contacts;
///
/// \brief accounts
/// \return
///
FMH::MODEL_LIST accounts();
FMH::MODEL_LIST contacts();
void contacts();
///
/// \brief fetchContacts
/// \return
///
static FMH::MODEL_LIST fetchContacts();
signals:
void contactsReady();
......
......@@ -63,7 +63,7 @@ Maui.Page
anchors.centerIn: parent
width: isWide ? control.width * 0.8 : control.width * 0.95
// height: rowHeight
placeholderText: qsTr("Search contacts... ")
placeholderText: listView.count
onAccepted: list.query = text
onCleared: list.reset()
colorScheme.backgroundColor: "#4f5160"
......
......@@ -123,7 +123,7 @@ Maui.Page
visible: dialString.length
Layout.fillWidth: true
Layout.minimumHeight: (unit * 80) * 1.5
Layout.maximumHeight: unit * 1000
Layout.fillHeight: true
model: _contacsView.listModel
......@@ -167,7 +167,10 @@ Maui.Page
id: _dialerPad
Layout.fillHeight: true
Layout.fillWidth: true
Layout.maximumHeight: unit*500
Layout.minimumHeight: unit*300
Layout.maximumHeight: unit*300
Layout.maximumWidth: unit*300
Layout.alignment: Qt.AlignCenter
// visible: true
Dialer
......
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