diff --git a/kde/src/CallView.cpp b/kde/src/CallView.cpp index aef80d40d9b560e0876192a66931f01bf65fecc8..7fdf6151a20d24d8bcf909cc3531c9cea171ac0b 100644 --- a/kde/src/CallView.cpp +++ b/kde/src/CallView.cpp @@ -588,9 +588,7 @@ void CallView::destroyCall(Call* toDestroy) else if (SFLPhone::model()->getIndex(toDestroy)->parent()) { QTreeWidgetItem* callIndex = SFLPhone::model()->getIndex(toDestroy); QTreeWidgetItem* parent = callIndex->parent(); - if (dynamic_cast<QTreeWidgetItem*>(parent) && parent->indexOfChild(callIndex) >= 0) { - parent->removeChild(callIndex); - } + parent->removeChild(callIndex); if (dynamic_cast<QTreeWidgetItem*>(parent) && parent->childCount() == 0) /*This should never happen, but it does*/ takeTopLevelItem(indexOfTopLevelItem(parent)); } diff --git a/kde/src/klib/AkonadiBackend.cpp b/kde/src/klib/AkonadiBackend.cpp index 591759d6c271f66d82247f97a2b3b8a96fa50ae5..2e330882a68f14fd7f524411da6a2043aa856f96 100644 --- a/kde/src/klib/AkonadiBackend.cpp +++ b/kde/src/klib/AkonadiBackend.cpp @@ -65,6 +65,7 @@ AkonadiBackend::AkonadiBackend(QObject* parent) : ContactBackend(parent) AkonadiBackend::~AkonadiBackend() { CallModel<>::destroy(); + delete m_pSession; } @@ -202,8 +203,8 @@ void AkonadiBackend::editContact(Contact* contact,QWidget* parent) return; } - Akonadi::ContactEditor *editor = new Akonadi::ContactEditor( Akonadi::ContactEditor::EditMode, parent ); if ( item.isValid() ) { + Akonadi::ContactEditor *editor = new Akonadi::ContactEditor( Akonadi::ContactEditor::EditMode, parent ); editor->loadContact(item); KDialog* dlg = new KDialog(parent); dlg->setMainWidget(editor); @@ -212,6 +213,8 @@ void AkonadiBackend::editContact(Contact* contact,QWidget* parent) kDebug() << "Unable to save new contact to storage"; return; } + delete editor; + delete dlg; } } //editContact @@ -266,12 +269,30 @@ void AkonadiBackend::addNewContact(Contact* contact) ///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()) { + Akonadi::Item item = m_ItemHash[contact->getUid()]; + if (!(item.hasPayload<KABC::Addressee>() && item.payload<KABC::Addressee>().uid() == contact->getUid())) { kDebug() << "Contact not found"; return; } - ct.insertPhoneNumber(KABC::PhoneNumber(number,nameToType(type))); + if ( item.isValid() ) { + KABC::Addressee payload = item.payload<KABC::Addressee>(); + payload.insertPhoneNumber(KABC::PhoneNumber(number,nameToType(type))); + item.setPayload<KABC::Addressee>(payload); + Akonadi::ContactEditor *editor = new Akonadi::ContactEditor( Akonadi::ContactEditor::EditMode, (QWidget*)nullptr ); + editor->loadContact(item); + + KDialog* dlg = new KDialog(0); + dlg->setMainWidget(editor); + dlg->exec(); + if ( !editor->saveContact() ) { + kDebug() << "Unable to save new contact to storage"; + return; + } + delete editor; + } + else { + kDebug() << "Invalid item"; + } } diff --git a/kde/src/lib/ContactBackend.h b/kde/src/lib/ContactBackend.h index c55f846bf58d9a64069716fc303c234f09bec3c6..fbeca06c437ccc153491a85e6fb8fbef4b9b85d1 100644 --- a/kde/src/lib/ContactBackend.h +++ b/kde/src/lib/ContactBackend.h @@ -52,6 +52,9 @@ public: virtual void editContact ( Contact* contact ) = 0; ///Add a new contact to the backend virtual void addNewContact ( Contact* contact ) = 0; + + ///Add a new phone number to an existing contact + virtual void addPhoneNumber( Contact* contact , QString number, QString type )=0; protected: virtual ContactList update_slot ( ) = 0; diff --git a/kde/src/widgets/BookmarkDock.cpp b/kde/src/widgets/BookmarkDock.cpp index fd22816c4cece10b7a329abf6a6414b760db9da4..24e37d242e70f072bdad6bb7de49e92fd7efec1f 100644 --- a/kde/src/widgets/BookmarkDock.cpp +++ b/kde/src/widgets/BookmarkDock.cpp @@ -126,7 +126,7 @@ BookmarkDock::~BookmarkDock() ///Add a new bookmark void BookmarkDock::addBookmark_internal(const QString& phone) { - HistoryTreeItem* widget = new HistoryTreeItem(m_pItemView,phone); + HistoryTreeItem* widget = new HistoryTreeItem(m_pItemView,phone,true); QTreeWidgetItem* item = NULL; if (widget->getName() == i18n("Unknown") || widget->getName().isEmpty()) { @@ -149,6 +149,25 @@ void BookmarkDock::addBookmark(const QString& phone) ConfigurationSkeleton::setBookmarkList(ConfigurationSkeleton::bookmarkList() << phone); } +///Remove a bookmark +void BookmarkDock::removeBookmark(const QString& phone) +{ + foreach (HistoryTreeItem* w,m_pBookmark) { + if (w->getPhoneNumber() == phone) { + QTreeWidgetItem* item = w->getItem(); + m_pItemView->removeItem(item); + QStringList bookmarks = ConfigurationSkeleton::bookmarkList(); + if (bookmarks.indexOf(phone)!= -1) { + bookmarks.removeAt(bookmarks.indexOf(phone)); + ConfigurationSkeleton::setBookmarkList(bookmarks); + } + if (m_pBookmark.indexOf(w)!=-1) { + m_pBookmark.removeAt(m_pBookmark.indexOf(w)); + } + } + } +} + ///Filter the list void BookmarkDock::filter(QString text) { diff --git a/kde/src/widgets/BookmarkDock.h b/kde/src/widgets/BookmarkDock.h index 8dfbad2eed102a9d5f6b7a4bcac8080b74bc16d6..efe3686fcda37951a3542532c83f803775f1b072 100644 --- a/kde/src/widgets/BookmarkDock.h +++ b/kde/src/widgets/BookmarkDock.h @@ -49,6 +49,7 @@ public: //Mutators void addBookmark(const QString& phone); + void removeBookmark(const QString& phone); private: //Attributes CategorizedTreeWidget* m_pItemView ; diff --git a/kde/src/widgets/CategorizedTreeWidget.cpp b/kde/src/widgets/CategorizedTreeWidget.cpp index 75f6498bb96140443bb6594c53b49fb6e9346807..e32c6c9a3ed35d6315abf0ca8600264418f10d18 100644 --- a/kde/src/widgets/CategorizedTreeWidget.cpp +++ b/kde/src/widgets/CategorizedTreeWidget.cpp @@ -180,4 +180,22 @@ void CategorizedTreeWidget::drawBranches(QPainter* painter, const QRect& rect, c QVector<QTreeWidgetItem*> CategorizedTreeWidget::realItems() const { return m_lItems; +} + +void CategorizedTreeWidget::removeItem(QTreeWidgetItem* item) +{ + for (int i=0;i<topLevelItemCount();i++) { + QTreeWidgetItem* topL = topLevelItem(i); + if (topL == item) { + takeTopLevelItem(i); + } + else { + for (int k=0;k<topL->childCount();k++) { + QTreeWidgetItem* childL = topL->child(k); + if (childL == item) { + topL->removeChild(childL); + } + } + } + } } \ No newline at end of file diff --git a/kde/src/widgets/CategorizedTreeWidget.h b/kde/src/widgets/CategorizedTreeWidget.h index c8cf482a3fbd52a18b9f804bb48fe59ece33f351..d44124bc59d8c578e465612675ec3d164dbe2116 100644 --- a/kde/src/widgets/CategorizedTreeWidget.h +++ b/kde/src/widgets/CategorizedTreeWidget.h @@ -41,7 +41,8 @@ class CategorizedTreeWidget : public QTreeWidget public: template <class T = QTreeWidgetItem> T* addItem(QString category); template <class T = QTreeWidgetItem> T* addCategory(QString name); - + void removeItem(QTreeWidgetItem* item); + QVector<QTreeWidgetItem*> realItems() const; Q_SIGNALS: diff --git a/kde/src/widgets/ContactItemWidget.cpp b/kde/src/widgets/ContactItemWidget.cpp index 9912a824e07a3fb32a6d9e41790c442d0f4432b4..1485ee633d719886bf6c5403d9d88d61b50bfa9b 100644 --- a/kde/src/widgets/ContactItemWidget.cpp +++ b/kde/src/widgets/ContactItemWidget.cpp @@ -62,7 +62,7 @@ ContactItemWidget::ContactItemWidget(QWidget *parent) setContextMenuPolicy(Qt::CustomContextMenu); setAcceptDrops(true); - m_pCallAgain = new KAction(this); + m_pCallAgain = new KAction(this); m_pCallAgain->setShortcut ( Qt::CTRL + Qt::Key_Enter ); m_pCallAgain->setText ( i18n("Call Again") ); m_pCallAgain->setIcon ( KIcon("call-start") ); @@ -73,23 +73,24 @@ ContactItemWidget::ContactItemWidget(QWidget *parent) m_pEditContact->setText ( i18n("Edit contact") ); m_pEditContact->setIcon ( KIcon("contact-new") ); - m_pCopy = new KAction(this); + m_pCopy = new KAction(this); m_pCopy->setShortcut ( Qt::CTRL + Qt::Key_C ); m_pCopy->setText ( i18n("Copy") ); m_pCopy->setIcon ( KIcon("edit-copy") ); - m_pEmail = new KAction(this); + m_pEmail = new KAction(this); m_pEmail->setShortcut ( Qt::CTRL + Qt::Key_M ); m_pEmail->setText ( i18n("Send Email") ); m_pEmail->setIcon ( KIcon("mail-message-new") ); m_pEmail->setEnabled ( false ); - m_pAddPhone = new KAction(this); + m_pAddPhone = new KAction(this); m_pAddPhone->setShortcut ( Qt::CTRL + Qt::Key_N ); m_pAddPhone->setText ( i18n("Add Phone Number") ); m_pAddPhone->setIcon ( KIcon("list-resource-add") ); + m_pEmail->setEnabled ( false ); - m_pBookmark = new KAction(this); + m_pBookmark = new KAction(this); m_pBookmark->setShortcut ( Qt::CTRL + Qt::Key_D ); m_pBookmark->setText ( i18n("Bookmark") ); m_pBookmark->setIcon ( KIcon("bookmarks") ); @@ -112,20 +113,20 @@ ContactItemWidget::ContactItemWidget(QWidget *parent) ///Destructor ContactItemWidget::~ContactItemWidget() { - /*delete m_pIconL ; - delete m_pContactNameL ; - delete m_pCallNumberL ; - delete m_pOrganizationL; - delete m_pEmailL ; - delete m_pItem ; - + if (m_pIconL) delete m_pIconL ; + if (m_pContactNameL) delete m_pContactNameL ; + if (m_pCallNumberL) delete m_pCallNumberL ; + if (m_pOrganizationL) delete m_pOrganizationL; + if (m_pEmailL) delete m_pEmailL ; + if (m_pMenu) delete m_pMenu ; +// delete m_pItem ; + delete m_pCallAgain ; delete m_pEditContact ; delete m_pCopy ; delete m_pEmail ; delete m_pAddPhone ; delete m_pBookmark ; - delete m_pMenu ;*/ } @@ -422,7 +423,7 @@ void ContactItemWidget::addPhone() //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()) { - + AkonadiBackend::getInstance()->addPhoneNumber(m_pContactKA,text,"work"); } } diff --git a/kde/src/widgets/HistoryTreeItem.cpp b/kde/src/widgets/HistoryTreeItem.cpp index 7f10dd22585a2c5425557d85e82b84e2c6017316..044a2e3639d81e4d2a00dbdbc901e1177b72e942 100644 --- a/kde/src/widgets/HistoryTreeItem.cpp +++ b/kde/src/widgets/HistoryTreeItem.cpp @@ -83,9 +83,9 @@ protected: ///Constructor -HistoryTreeItem::HistoryTreeItem(QWidget *parent ,QString phone) +HistoryTreeItem::HistoryTreeItem(QWidget *parent ,QString phone,bool isBookmark) : QWidget(parent), m_pItemCall(0), m_pMenu(0) , m_pAudioSlider(0) , m_pTimeLeftL(0) , m_pTimePlayedL(0),m_pPlayer(0), - m_pContact(0) , m_pPause(0) , m_pStop(0) , m_pNote(0) , m_SeekPos(0) , m_Paused(false) + m_pContact(0) , m_pPause(0) , m_pStop(0) , m_pNote(0) , m_SeekPos(0) , m_Paused(false) ,m_IsBookmark(isBookmark) { setContextMenuPolicy(Qt::CustomContextMenu); setAcceptDrops(true); @@ -121,7 +121,14 @@ HistoryTreeItem::HistoryTreeItem(QWidget *parent ,QString phone) m_pBookmark->setShortcut ( Qt::CTRL + Qt::Key_D ); m_pBookmark->setText ( i18n("Bookmark") ); - m_pBookmark->setIcon ( KIcon("bookmarks") ); + if (!m_IsBookmark) { + m_pBookmark->setText ( i18n("Bookmark") ); + m_pBookmark->setIcon ( KIcon("bookmarks") ); + } + else { + m_pBookmark->setText ( i18n("Remove bookmark") ); + m_pBookmark->setIcon ( KIcon("edit-delete") ); + } m_pPlay = new QToolButton(this); @@ -316,7 +323,10 @@ void HistoryTreeItem::addToContact() ///Bookmark this contact void HistoryTreeItem::bookmark() { - SFLPhone::app()->bookmarkDock()->addBookmark(m_PhoneNumber); + if (!m_IsBookmark) + SFLPhone::app()->bookmarkDock()->addBookmark(m_PhoneNumber); + else + SFLPhone::app()->bookmarkDock()->removeBookmark(m_PhoneNumber); } void HistoryTreeItem::removeRecording() diff --git a/kde/src/widgets/HistoryTreeItem.h b/kde/src/widgets/HistoryTreeItem.h index 5ec0fe7fa52a8244a8544f301aa2d3a9273f9320..462cab9eee78a3b26ecdb68d424ee5b3ccd90e34 100644 --- a/kde/src/widgets/HistoryTreeItem.h +++ b/kde/src/widgets/HistoryTreeItem.h @@ -55,7 +55,7 @@ class HistoryTreeItem : public QWidget Q_OBJECT public: //Constructor - HistoryTreeItem(QWidget* parent =0, QString phone = ""); + HistoryTreeItem(QWidget* parent =0, QString phone = "",bool isBookmark=false); ~HistoryTreeItem(); //Getters @@ -114,6 +114,8 @@ class HistoryTreeItem : public QWidget TranslucentButtons* m_pBtnTrans; + bool m_IsBookmark; + protected: virtual void resizeEvent(QResizeEvent* event); virtual void mouseDoubleClickEvent(QMouseEvent* event);