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

[ #13018 ] Remove bookmark now work

parent c5b89574
No related branches found
No related tags found
No related merge requests found
......@@ -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);
}
if (dynamic_cast<QTreeWidgetItem*>(parent) && parent->childCount() == 0) /*This should never happen, but it does*/
takeTopLevelItem(indexOfTopLevelItem(parent));
}
......
......@@ -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";
}
}
......
......@@ -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;
......
......@@ -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)
{
......
......@@ -49,6 +49,7 @@ public:
//Mutators
void addBookmark(const QString& phone);
void removeBookmark(const QString& phone);
private:
//Attributes
CategorizedTreeWidget* m_pItemView ;
......
......@@ -181,3 +181,21 @@ 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
......@@ -41,6 +41,7 @@ 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;
......
......@@ -88,6 +88,7 @@ ContactItemWidget::ContactItemWidget(QWidget *parent)
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->setShortcut ( Qt::CTRL + Qt::Key_D );
......@@ -112,12 +113,13 @@ 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 ;
......@@ -125,7 +127,6 @@ ContactItemWidget::~ContactItemWidget()
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");
}
}
......
......@@ -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);
......@@ -120,8 +120,15 @@ HistoryTreeItem::HistoryTreeItem(QWidget *parent ,QString phone)
m_pEmail->setDisabled ( true );
m_pBookmark->setShortcut ( Qt::CTRL + Qt::Key_D );
m_pBookmark->setText ( i18n("Bookmark") );
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()
{
if (!m_IsBookmark)
SFLPhone::app()->bookmarkDock()->addBookmark(m_PhoneNumber);
else
SFLPhone::app()->bookmarkDock()->removeBookmark(m_PhoneNumber);
}
void HistoryTreeItem::removeRecording()
......
......@@ -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);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment