Commit 8e9a351a authored by Emmanuel Lepage's avatar Emmanuel Lepage

Fix bug, add "add contact" option, fix warning

parent 95dc9d44
...@@ -10,8 +10,11 @@ ...@@ -10,8 +10,11 @@
#include <akonadi/itemfetchscope.h> #include <akonadi/itemfetchscope.h>
#include <akonadi/collectionfetchjob.h> #include <akonadi/collectionfetchjob.h>
#include <akonadi/collectionfetchscope.h> #include <akonadi/collectionfetchscope.h>
#include <akonadi/contact/contacteditor.h>
#include <kdialog.h>
#include "lib/Contact.h" #include "lib/Contact.h"
#include "SFLPhone.h"
AkonadiBackend* AkonadiBackend::m_pInstance = 0; AkonadiBackend* AkonadiBackend::m_pInstance = 0;
...@@ -62,6 +65,7 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection) ...@@ -62,6 +65,7 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection)
if ( item.hasPayload<KABC::Addressee>() ) { if ( item.hasPayload<KABC::Addressee>() ) {
KABC::Addressee tmp = item.payload<KABC::Addressee>(); KABC::Addressee tmp = item.payload<KABC::Addressee>();
Contact* aContact = new Contact(); Contact* aContact = new Contact();
m_pAddrHash[tmp.uid()] = tmp;
KABC::PhoneNumber::List numbers = tmp.phoneNumbers(); KABC::PhoneNumber::List numbers = tmp.phoneNumbers();
PhoneNumbers newNumbers; PhoneNumbers newNumbers;
...@@ -113,4 +117,49 @@ void AkonadiBackend::collectionsReceived( const Akonadi::Collection::List& list ...@@ -113,4 +117,49 @@ void AkonadiBackend::collectionsReceived( const Akonadi::Collection::List& list
update(coll); update(coll);
emit collectionChanged(); emit collectionChanged();
} }
}
void AkonadiBackend::editContact(Contact* contact)
{
KABC::Addressee ct = m_pAddrHash[contact->getUid()];
if (ct.uid() != contact->getUid()) {
qDebug() << "Contact not found";
return;
}
Akonadi::ContactEditor *editor = new Akonadi::ContactEditor( Akonadi::ContactEditor::EditMode, SFLPhone::app()->view() );
Akonadi::Item item;
item.setPayload<KABC::Addressee>(ct);
editor->loadContact(item);
KDialog* dlg = new KDialog(SFLPhone::app()->view());
dlg->setMainWidget(editor);
dlg->exec();
}
void AkonadiBackend::addNewContact(Contact* contact)
{
KABC::Addressee newContact;
newContact.setNickName ( contact->getNickName() );
newContact.setFormattedName ( contact->getFormattedName() );
newContact.setGivenName ( contact->getFirstName() );
newContact.setFamilyName ( contact->getSecondName() );
newContact.setOrganization ( contact->getOrganization() );
//newContact.setPreferredEmail ( contact->getPreferredEmail() );//TODO
//aContact->setPhoneNumbers (newNumbers );//TODO
Akonadi::ContactEditor *editor = new Akonadi::ContactEditor( Akonadi::ContactEditor::CreateMode, SFLPhone::app()->view() );
editor->setContactTemplate(newContact);
KDialog* dlg = new KDialog(SFLPhone::app()->view());
dlg->setMainWidget(editor);
dlg->exec();
if ( !editor->saveContact() ) {
qDebug() << "Unable to save new contact to storage";
return;
}
} }
\ No newline at end of file
...@@ -9,24 +9,31 @@ ...@@ -9,24 +9,31 @@
class Contact; class Contact;
namespace KABC {
class Addressee;
}
typedef QList<Contact*> ContactList; typedef QList<Contact*> ContactList;
class AkonadiBackend : public QObject { class AkonadiBackend : public QObject {
Q_OBJECT Q_OBJECT
public: public:
static AkonadiBackend* getInstance(); static AkonadiBackend* getInstance();
Contact* getContactByPhone(QString phoneNumber); Contact* getContactByPhone ( QString phoneNumber );
Contact* getContactByUid(QString uid); Contact* getContactByUid ( QString uid );
void editContact ( Contact* contact );
void addNewContact ( Contact* contact );
private: private:
AkonadiBackend(QObject* parent); AkonadiBackend(QObject* parent);
virtual ~AkonadiBackend(); virtual ~AkonadiBackend();
//Attributes //Attributes
static AkonadiBackend* m_pInstance; static AkonadiBackend* m_pInstance ;
Akonadi::Session* m_pSession; Akonadi::Session* m_pSession ;
Akonadi::Collection m_pCollection; Akonadi::Collection m_pCollection ;
QHash<QString,Contact*> m_pContactByPhone; QHash<QString,Contact*> m_pContactByPhone ;
QHash<QString,Contact*> m_pContactByUid; QHash<QString,Contact*> m_pContactByUid ;
QHash<QString,KABC::Addressee> m_pAddrHash ;
public slots: public slots:
ContactList update(); ContactList update();
ContactList update(Akonadi::Collection collection); ContactList update(Akonadi::Collection collection);
......
...@@ -360,6 +360,7 @@ void DlgAccounts::loadAccount(QListWidgetItem * item) ...@@ -360,6 +360,7 @@ void DlgAccounts::loadAccount(QListWidgetItem * item)
} }
updateStatusLabel(account); updateStatusLabel(account);
enablePublished();
frame2_editAccounts->setEnabled(true); frame2_editAccounts->setEnabled(true);
} }
......
...@@ -341,6 +341,7 @@ QString Call::getCallNumber() const ...@@ -341,6 +341,7 @@ QString Call::getCallNumber() const
void Call::setCallNumber(QString number) void Call::setCallNumber(QString number)
{ {
callNumber = number; callNumber = number;
emit changed();
} }
......
...@@ -108,8 +108,7 @@ void CallTreeItem::setCall(Call *call) ...@@ -108,8 +108,7 @@ void CallTreeItem::setCall(Call *call)
setLayout(mainLayout); setLayout(mainLayout);
setMinimumSize(QSize(50, 30)); setMinimumSize(QSize(50, 30));
connect(itemCall, SIGNAL(changed()), connect(itemCall, SIGNAL(changed()), this, SLOT(updated()));
this, SLOT(updated()));
updated(); updated();
} }
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "lib/sflphone_const.h" #include "lib/sflphone_const.h"
#include "ContactItemWidget.h" #include "ContactItemWidget.h"
#include "AkonadiBackend.h"
ContactItemWidget::ContactItemWidget(QWidget *parent) ContactItemWidget::ContactItemWidget(QWidget *parent)
: QWidget(parent), m_pMenu(0),init(false) : QWidget(parent), m_pMenu(0),init(false)
...@@ -218,7 +219,8 @@ void ContactItemWidget::copy() ...@@ -218,7 +219,8 @@ void ContactItemWidget::copy()
void ContactItemWidget::editContact() void ContactItemWidget::editContact()
{ {
qDebug() << "Adding contact"; qDebug() << "Edit contact";
AkonadiBackend::getInstance()->editContact(m_pContactKA);
} }
void ContactItemWidget::addPhone() void ContactItemWidget::addPhone()
......
...@@ -276,6 +276,7 @@ bool HistoryTree::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeDa ...@@ -276,6 +276,7 @@ bool HistoryTree::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeDa
{ {
Q_UNUSED(index) Q_UNUSED(index)
Q_UNUSED(action) Q_UNUSED(action)
Q_UNUSED(parent)
QByteArray encodedData = data->data(MIME_CALLID); QByteArray encodedData = data->data(MIME_CALLID);
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
#include "HistoryTreeItem.h" #include "HistoryTreeItem.h"
#include "AkonadiBackend.h" #include "AkonadiBackend.h"
#include "lib/Contact.h" #include "lib/Contact.h"
#include "SFLPhone.h"
const char * HistoryTreeItem::callStateIcons[12] = {ICON_INCOMING, ICON_RINGING, ICON_CURRENT, ICON_DIALING, ICON_HOLD, ICON_FAILURE, ICON_BUSY, ICON_TRANSFER, ICON_TRANSF_HOLD, "", "", ICON_CONFERENCE}; const char * HistoryTreeItem::callStateIcons[12] = {ICON_INCOMING, ICON_RINGING, ICON_CURRENT, ICON_DIALING, ICON_HOLD, ICON_FAILURE, ICON_BUSY, ICON_TRANSFER, ICON_TRANSF_HOLD, "", "", ICON_CONFERENCE};
...@@ -51,11 +52,11 @@ HistoryTreeItem::HistoryTreeItem(QWidget *parent) ...@@ -51,11 +52,11 @@ HistoryTreeItem::HistoryTreeItem(QWidget *parent)
m_pCallAgain->setIcon (KIcon(ICON_DIALING) ); m_pCallAgain->setIcon (KIcon(ICON_DIALING) );
m_pAddToContact->setShortcut (Qt::CTRL + Qt::Key_E ); m_pAddToContact->setShortcut (Qt::CTRL + Qt::Key_E );
m_pAddToContact->setText ("Add to contact" ); m_pAddToContact->setText ("Add Number to Contact" );
m_pAddToContact->setIcon (KIcon("list-resource-add") ); m_pAddToContact->setIcon (KIcon("list-resource-add") );
m_pAddContact->setShortcut (Qt::CTRL + Qt::Key_E ); m_pAddContact->setShortcut (Qt::CTRL + Qt::Key_E );
m_pAddContact->setText ("Add to contact" ); m_pAddContact->setText ("Add Contact" );
m_pAddContact->setIcon (KIcon("contact-new") ); m_pAddContact->setIcon (KIcon("contact-new") );
m_pCopy->setShortcut (Qt::CTRL + Qt::Key_C ); m_pCopy->setShortcut (Qt::CTRL + Qt::Key_C );
...@@ -220,6 +221,8 @@ void HistoryTreeItem::sendEmail() ...@@ -220,6 +221,8 @@ void HistoryTreeItem::sendEmail()
void HistoryTreeItem::callAgain() void HistoryTreeItem::callAgain()
{ {
qDebug() << "Calling "<< itemCall->getPeerPhoneNumber(); qDebug() << "Calling "<< itemCall->getPeerPhoneNumber();
SFLPhone::app()->model()->addDialingCall(m_pName, SFLPhone::app()->model()->getCurrentAccountId())->setCallNumber(m_pPhoneNumber);
} }
void HistoryTreeItem::copy() void HistoryTreeItem::copy()
...@@ -230,6 +233,10 @@ void HistoryTreeItem::copy() ...@@ -230,6 +233,10 @@ void HistoryTreeItem::copy()
void HistoryTreeItem::addContact() void HistoryTreeItem::addContact()
{ {
qDebug() << "Adding contact"; qDebug() << "Adding contact";
Contact* aContact = new Contact();
aContact->setPhoneNumbers(PhoneNumbers() << new Contact::PhoneNumber(m_pPhoneNumber, "Home"));
aContact->setFormattedName(m_pName);
AkonadiBackend::getInstance()->addNewContact(aContact);
} }
void HistoryTreeItem::addToContact() void HistoryTreeItem::addToContact()
......
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