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

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

parent 95dc9d44
......@@ -10,8 +10,11 @@
#include <akonadi/itemfetchscope.h>
#include <akonadi/collectionfetchjob.h>
#include <akonadi/collectionfetchscope.h>
#include <akonadi/contact/contacteditor.h>
#include <kdialog.h>
#include "lib/Contact.h"
#include "SFLPhone.h"
AkonadiBackend* AkonadiBackend::m_pInstance = 0;
......@@ -62,6 +65,7 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection)
if ( item.hasPayload<KABC::Addressee>() ) {
KABC::Addressee tmp = item.payload<KABC::Addressee>();
Contact* aContact = new Contact();
m_pAddrHash[tmp.uid()] = tmp;
KABC::PhoneNumber::List numbers = tmp.phoneNumbers();
PhoneNumbers newNumbers;
......@@ -113,4 +117,49 @@ void AkonadiBackend::collectionsReceived( const Akonadi::Collection::List& list
update(coll);
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 @@
class Contact;
namespace KABC {
class Addressee;
}
typedef QList<Contact*> ContactList;
class AkonadiBackend : public QObject {
Q_OBJECT
public:
static AkonadiBackend* getInstance();
Contact* getContactByPhone(QString phoneNumber);
Contact* getContactByUid(QString uid);
static AkonadiBackend* getInstance();
Contact* getContactByPhone ( QString phoneNumber );
Contact* getContactByUid ( QString uid );
void editContact ( Contact* contact );
void addNewContact ( Contact* contact );
private:
AkonadiBackend(QObject* parent);
virtual ~AkonadiBackend();
//Attributes
static AkonadiBackend* m_pInstance;
Akonadi::Session* m_pSession;
Akonadi::Collection m_pCollection;
QHash<QString,Contact*> m_pContactByPhone;
QHash<QString,Contact*> m_pContactByUid;
static AkonadiBackend* m_pInstance ;
Akonadi::Session* m_pSession ;
Akonadi::Collection m_pCollection ;
QHash<QString,Contact*> m_pContactByPhone ;
QHash<QString,Contact*> m_pContactByUid ;
QHash<QString,KABC::Addressee> m_pAddrHash ;
public slots:
ContactList update();
ContactList update(Akonadi::Collection collection);
......
......@@ -360,6 +360,7 @@ void DlgAccounts::loadAccount(QListWidgetItem * item)
}
updateStatusLabel(account);
enablePublished();
frame2_editAccounts->setEnabled(true);
}
......
......@@ -341,6 +341,7 @@ QString Call::getCallNumber() const
void Call::setCallNumber(QString number)
{
callNumber = number;
emit changed();
}
......
......@@ -108,8 +108,7 @@ void CallTreeItem::setCall(Call *call)
setLayout(mainLayout);
setMinimumSize(QSize(50, 30));
connect(itemCall, SIGNAL(changed()),
this, SLOT(updated()));
connect(itemCall, SIGNAL(changed()), this, SLOT(updated()));
updated();
}
......
......@@ -32,6 +32,7 @@
#include "lib/sflphone_const.h"
#include "ContactItemWidget.h"
#include "AkonadiBackend.h"
ContactItemWidget::ContactItemWidget(QWidget *parent)
: QWidget(parent), m_pMenu(0),init(false)
......@@ -218,7 +219,8 @@ void ContactItemWidget::copy()
void ContactItemWidget::editContact()
{
qDebug() << "Adding contact";
qDebug() << "Edit contact";
AkonadiBackend::getInstance()->editContact(m_pContactKA);
}
void ContactItemWidget::addPhone()
......
......@@ -276,6 +276,7 @@ bool HistoryTree::dropMimeData(QTreeWidgetItem *parent, int index, const QMimeDa
{
Q_UNUSED(index)
Q_UNUSED(action)
Q_UNUSED(parent)
QByteArray encodedData = data->data(MIME_CALLID);
......
......@@ -32,6 +32,7 @@
#include "HistoryTreeItem.h"
#include "AkonadiBackend.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};
......@@ -51,11 +52,11 @@ HistoryTreeItem::HistoryTreeItem(QWidget *parent)
m_pCallAgain->setIcon (KIcon(ICON_DIALING) );
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_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_pCopy->setShortcut (Qt::CTRL + Qt::Key_C );
......@@ -220,6 +221,8 @@ void HistoryTreeItem::sendEmail()
void HistoryTreeItem::callAgain()
{
qDebug() << "Calling "<< itemCall->getPeerPhoneNumber();
SFLPhone::app()->model()->addDialingCall(m_pName, SFLPhone::app()->model()->getCurrentAccountId())->setCallNumber(m_pPhoneNumber);
}
void HistoryTreeItem::copy()
......@@ -230,6 +233,10 @@ void HistoryTreeItem::copy()
void HistoryTreeItem::addContact()
{
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()
......
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