Skip to content
Snippets Groups Projects
Commit c5b89574 authored by Emmanuel Lepage's avatar Emmanuel Lepage
Browse files

[ #13018,#11953 ] Fix saving contact

parent de857403
Branches
Tags
No related merge requests found
...@@ -105,6 +105,32 @@ Contact* AkonadiBackend::getContactByUid(const QString& uid) ...@@ -105,6 +105,32 @@ Contact* AkonadiBackend::getContactByUid(const QString& uid)
} }
/*****************************************************************************
* *
* Helper *
* *
****************************************************************************/
KABC::PhoneNumber::Type nameToType(QString name)
{
if (name == "Home" ) return KABC::PhoneNumber::Home ;
else if (name == "Work" ) return KABC::PhoneNumber::Work ;
else if (name == "Msg" ) return KABC::PhoneNumber::Msg ;
else if (name == "Pref" ) return KABC::PhoneNumber::Pref ;
else if (name == "Voice" ) return KABC::PhoneNumber::Voice;
else if (name == "Fax" ) return KABC::PhoneNumber::Fax ;
else if (name == "Cell" ) return KABC::PhoneNumber::Cell ;
else if (name == "Video" ) return KABC::PhoneNumber::Video;
else if (name == "Bbs" ) return KABC::PhoneNumber::Bbs ;
else if (name == "Modem" ) return KABC::PhoneNumber::Modem;
else if (name == "Car" ) return KABC::PhoneNumber::Car ;
else if (name == "Isdn" ) return KABC::PhoneNumber::Isdn ;
else if (name == "Pcs" ) return KABC::PhoneNumber::Pcs ;
else if (name == "Pager" ) return KABC::PhoneNumber::Pager;
return KABC::PhoneNumber::Home;
}
/***************************************************************************** /*****************************************************************************
* * * *
* Mutator * * Mutator *
...@@ -159,6 +185,7 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection) ...@@ -159,6 +185,7 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection)
aContact->setPhoto(0); aContact->setPhoto(0);
m_AddrHash[tmp.uid()] = tmp; m_AddrHash[tmp.uid()] = tmp;
m_ItemHash[tmp.uid()] = item;
} }
} }
m_pContacts = m_ContactByUid.values(); m_pContacts = m_ContactByUid.values();
...@@ -169,18 +196,22 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection) ...@@ -169,18 +196,22 @@ ContactList AkonadiBackend::update(Akonadi::Collection collection)
///Edit backend value using an updated frontend contact ///Edit backend value using an updated frontend contact
void AkonadiBackend::editContact(Contact* contact,QWidget* parent) void AkonadiBackend::editContact(Contact* contact,QWidget* parent)
{ {
KABC::Addressee ct = m_AddrHash[contact->getUid()]; Akonadi::Item item = m_ItemHash[contact->getUid()];
if (ct.uid() != contact->getUid()) { if (!(item.hasPayload<KABC::Addressee>() && item.payload<KABC::Addressee>().uid() == contact->getUid())) {
kDebug() << "Contact not found"; kDebug() << "Contact not found";
return; return;
} }
Akonadi::ContactEditorDialog *editor = new Akonadi::ContactEditorDialog( Akonadi::ContactEditorDialog::EditMode, parent ); Akonadi::ContactEditor *editor = new Akonadi::ContactEditor( Akonadi::ContactEditor::EditMode, parent );
Akonadi::Item item(rand());
item.setPayload<KABC::Addressee>(ct);
if ( item.isValid() ) { if ( item.isValid() ) {
editor->setContact(item); editor->loadContact(item);
editor->exec(); KDialog* dlg = new KDialog(parent);
dlg->setMainWidget(editor);
dlg->exec();
if ( !editor->saveContact() ) {
kDebug() << "Unable to save new contact to storage";
return;
}
} }
} //editContact } //editContact
...@@ -198,20 +229,7 @@ void AkonadiBackend::addNewContact(Contact* contact,QWidget* parent) ...@@ -198,20 +229,7 @@ void AkonadiBackend::addNewContact(Contact* contact,QWidget* parent)
foreach (Contact::PhoneNumber* nb, contact->getPhoneNumbers()) { foreach (Contact::PhoneNumber* nb, contact->getPhoneNumbers()) {
KABC::PhoneNumber pn; KABC::PhoneNumber pn;
if (nb->getType() == "Home" ) pn.setType(KABC::PhoneNumber::Home ); pn.setType(nameToType(nb->getType()));
else if (nb->getType() == "Work" ) pn.setType(KABC::PhoneNumber::Work );
else if (nb->getType() == "Msg" ) pn.setType(KABC::PhoneNumber::Msg );
else if (nb->getType() == "Pref" ) pn.setType(KABC::PhoneNumber::Pref );
else if (nb->getType() == "Voice" ) pn.setType(KABC::PhoneNumber::Voice );
else if (nb->getType() == "Fax" ) pn.setType(KABC::PhoneNumber::Fax );
else if (nb->getType() == "Cell" ) pn.setType(KABC::PhoneNumber::Cell );
else if (nb->getType() == "Video" ) pn.setType(KABC::PhoneNumber::Video );
else if (nb->getType() == "Bbs" ) pn.setType(KABC::PhoneNumber::Bbs );
else if (nb->getType() == "Modem" ) pn.setType(KABC::PhoneNumber::Modem );
else if (nb->getType() == "Car" ) pn.setType(KABC::PhoneNumber::Car );
else if (nb->getType() == "Isdn" ) pn.setType(KABC::PhoneNumber::Isdn );
else if (nb->getType() == "Pcs" ) pn.setType(KABC::PhoneNumber::Pcs );
else if (nb->getType() == "Pager" ) pn.setType(KABC::PhoneNumber::Pager );
pn.setNumber(nb->getNumber()); pn.setNumber(nb->getNumber());
newContact.insertPhoneNumber(pn); newContact.insertPhoneNumber(pn);
...@@ -245,6 +263,17 @@ void AkonadiBackend::addNewContact(Contact* contact) ...@@ -245,6 +263,17 @@ void AkonadiBackend::addNewContact(Contact* contact)
addNewContact(contact,0); addNewContact(contact,0);
} }
///Add a new phone number to an existing contact
void AkonadiBackend::addPhoneNumber(Contact* contact, QString number, QString type)
{
KABC::Addressee ct = m_AddrHash[contact->getUid()];
if (ct.uid() != contact->getUid()) {
kDebug() << "Contact not found";
return;
}
ct.insertPhoneNumber(KABC::PhoneNumber(number,nameToType(type)));
}
/***************************************************************************** /*****************************************************************************
* * * *
......
...@@ -39,6 +39,7 @@ namespace Akonadi { ...@@ -39,6 +39,7 @@ namespace Akonadi {
class Session; class Session;
class CollectionModel; class CollectionModel;
class Collection; class Collection;
class Item;
} }
//SFLPhone //SFLPhone
...@@ -53,6 +54,7 @@ public: ...@@ -53,6 +54,7 @@ public:
Contact* getContactByUid ( const QString& uid ); Contact* getContactByUid ( const QString& uid );
void editContact ( Contact* contact , QWidget* parent = 0 ); void editContact ( Contact* contact , QWidget* parent = 0 );
void addNewContact ( Contact* contact , QWidget* parent = 0 ); void addNewContact ( Contact* contact , QWidget* parent = 0 );
virtual void addPhoneNumber( Contact* contact , QString number, QString type );
virtual void editContact ( Contact* contact ); virtual void editContact ( Contact* contact );
virtual void addNewContact ( Contact* contact ); virtual void addNewContact ( Contact* contact );
...@@ -66,6 +68,7 @@ private: ...@@ -66,6 +68,7 @@ private:
Akonadi::Session* m_pSession ; Akonadi::Session* m_pSession ;
Akonadi::Collection m_Collection ; Akonadi::Collection m_Collection ;
QHash<QString,KABC::Addressee> m_AddrHash ; QHash<QString,KABC::Addressee> m_AddrHash ;
QHash<QString,Akonadi::Item> m_ItemHash ;
ContactList m_pContacts ; ContactList m_pContacts ;
protected: protected:
......
...@@ -418,6 +418,12 @@ void ContactItemWidget::editContact() ...@@ -418,6 +418,12 @@ void ContactItemWidget::editContact()
void ContactItemWidget::addPhone() void ContactItemWidget::addPhone()
{ {
kDebug() << "Adding to contact"; kDebug() << "Adding to contact";
bool ok;
//QString number = QInputDialog::getText(0, i18n("Enter a new number"),i18n("New number:"),QLineEdit::Normal,QString(),ok,0);
QString text = QInputDialog::getText(this, i18n("Enter a new number"), i18n("New number:"), QLineEdit::Normal, QString(), &ok);
if (ok && !text.isEmpty()) {
}
} }
///Add this contact to the bookmark list ///Add this contact to the bookmark list
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment