File: context-menu.cpp

package info (click to toggle)
ktp-contact-list 22.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,720 kB
  • sloc: cpp: 4,704; sh: 3; makefile: 2
file content (640 lines) | stat: -rw-r--r-- 23,583 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
/*
    Contact list context menu
    Copyright (C) 2011  Martin Klapetek <martin.klapetek@gmail.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "context-menu.h"

#include <QDebug>
#include <QMenu>
#include <QAction>
#include <QInputDialog>
#include <QDesktopServices>

#include <KLocalizedString>
#include <KMessageBox>

#include <KTp/text-parser.h>
#include <KTp/Widgets/notification-config-dialog.h>
#include <KTp/Widgets/contact-info-dialog.h>
#include <KTp/types.h>
#include <KTp/Models/contacts-model.h>
#include <KTp/Logger/log-manager.h>
#include <KTp/Logger/log-entity.h>

#include <TelepathyQt/ContactManager>
#include <TelepathyQt/Account>
#include <TelepathyQt/PendingOperation>

#ifdef HAVE_KPEOPLE
#include <kpeople/widgets/persondetailsdialog.h>
#include <kpeople/widgets/actions.h>
#include <kpeople/global.h>
#include <kpeople/personsmodel.h>
#include <kpeople/persondata.h>
#endif

#include "dialogs/remove-contact-dialog.h"

#include "contact-list-widget_p.h"

ContextMenu::ContextMenu(ContactListWidget *mainWidget)
    : QObject(mainWidget)
{
    m_mainWidget = mainWidget;
}


ContextMenu::~ContextMenu()
{

}

void ContextMenu::setAccountManager(const Tp::AccountManagerPtr &accountManager)
{
    m_accountManager = accountManager;
    KTp::LogManager::instance()->setAccountManager(accountManager);
}

QMenu* ContextMenu::contactContextMenu(const QModelIndex &index)
{
    if (!index.isValid()) {
        return 0;
    }

    if (m_accountManager.isNull()) {
        return 0;
    }

    m_currentIndex = index;

    QAction *action;
    QMenu *menu = new QMenu();
    KTp::ContactPtr contact = index.data(KTp::ContactRole).value<KTp::ContactPtr>();

    if (contact.isNull()) {
        qWarning() << "Contact is nulled";
    }

    Tp::AccountPtr account = index.data(KTp::AccountRole).value<Tp::AccountPtr>();

    if (account.isNull()) {
        qWarning() << "Account is nulled";
    }

    if (KTp::kpeopleEnabled()) {
    #ifdef HAVE_KPEOPLE
        menu->setTitle(index.data(Qt::DisplayRole).toString());
        if (index.parent().isValid()) {
            menu->addActions(KPeople::actionsForPerson(index.data(KTp::ContactUriRole).toString(), menu));
        } else {
            menu->addActions(KPeople::actionsForPerson(index.data(KTp::PersonIdRole).toString(), menu));
        }
    #endif
    } else {
        menu->setTitle(contact->alias());
        //must be a QAction because menu->addAction returns QAction, breaks compilation otherwise
        action = menu->addAction(i18n("Start Chat..."));
        action->setIcon(QIcon::fromTheme("text-x-generic"));
        action->setDisabled(true);
        connect(action, SIGNAL(triggered(bool)),
                SLOT(onStartTextChatTriggered()));

        if (index.data(KTp::ContactCanTextChatRole).toBool()) {
            action->setEnabled(true);
        }

        action = menu->addAction(i18n("Start Audio Call..."));
        action->setIcon(QIcon::fromTheme("audio-headset"));
        action->setDisabled(true);
        connect(action, SIGNAL(triggered(bool)),
                SLOT(onStartAudioChatTriggered()));

        if (index.data(KTp::ContactCanAudioCallRole).toBool()) {
            action->setEnabled(true);
        }

        action = menu->addAction(i18n("Start Video Call..."));
        action->setIcon(QIcon::fromTheme("camera-web"));
        action->setDisabled(true);
        connect(action, SIGNAL(triggered(bool)),
                SLOT(onStartVideoChatTriggered()));

        if (index.data(KTp::ContactCanVideoCallRole).toBool()) {
            action->setEnabled(true);
        }

        action = menu->addAction(i18n("Send File..."));
        action->setIcon(QIcon::fromTheme("mail-attachment"));
        action->setDisabled(true);
        connect(action, SIGNAL(triggered(bool)),
                SLOT(onStartFileTransferTriggered()));

        if (index.data(KTp::ContactCanFileTransferRole).toBool()) {
            action->setEnabled(true);
        }

        action = menu->addAction(i18n("Share my desktop..."));
        action->setIcon(QIcon::fromTheme("krfb"));
        action->setDisabled(true);
        connect(action, SIGNAL(triggered(bool)),
                SLOT(onStartDesktopSharingTriggered()));

        if (index.data(KTp::ContactTubesRole).toStringList().contains(QLatin1String("rfb"))) {
            action->setEnabled(true);
        }

        action = menu->addAction(i18n("Open Log..."));
        action->setIcon(QIcon::fromTheme("documentation"));
        action->setDisabled(true);
        connect(action, SIGNAL(triggered(bool)),
                SLOT(onOpenLogViewerTriggered()));

        KTp::LogEntity entity(Tp::HandleTypeContact, contact->id());
        if (KTp::LogManager::instance()->logsExist(account, entity)) {
            action->setEnabled(true);
        }
    }

    menu->addSeparator();
    action = menu->addAction(QIcon::fromTheme("dialog-information"), i18n("Configure Notifications..."));
    action->setEnabled(true);
    connect(action, SIGNAL(triggered()),
                           SLOT(onNotificationConfigureTriggered()));

    // add "goto" submenu for navigating to links the contact has in presence message
    // first check to see if there are any links in the contact's presence message
    QStringList contactLinks;
    QString presenceMsg = index.data(KTp::ContactPresenceMessageRole).toString();
    if (presenceMsg.isEmpty()) {
        contactLinks = QStringList();
    } else {
        KTp::TextUrlData urls = KTp::TextParser::instance()->extractUrlData(presenceMsg);
        contactLinks = urls.fixedUrls;
    }

    if (!contactLinks.empty()) {
        QMenu *subMenu = new QMenu(i18np("Presence message link", "Presence message links", contactLinks.count()));

        foreach(const QString &link, contactLinks) {
            action = subMenu->addAction(link);
            action->setData(link);
        }
        connect(subMenu, SIGNAL(triggered(QAction*)), this, SLOT(onOpenLinkTriggered(QAction*)));
        menu->addMenu(subMenu);
    }

    menu->addSeparator();

    Tp::ConnectionPtr accountConnection = account->connection();
    if (accountConnection.isNull()) {
        qWarning() << "Account connection is nulled.";
    }

    if (m_mainWidget->d_ptr->model->groupMode() == KTp::ContactsModel::GroupGrouping) {
        // remove contact from group action, must be QAction because menu->addAction returns QAction
        QAction *groupRemoveAction = menu->addAction(QIcon(), i18n("Remove Contact From This Group"));
        connect(groupRemoveAction, SIGNAL(triggered(bool)), this, SLOT(onRemoveContactFromGroupTriggered()));

        if (accountConnection.isNull()) {
            groupRemoveAction->setDisabled(true);
        } else if (accountConnection->actualFeatures().contains(Tp::Connection::FeatureRosterGroups)) {
            QMenu* groupAddMenu = menu->addMenu(i18n("Move to Group"));

            QStringList groupList;
            QList<Tp::AccountPtr> accounts = m_accountManager->allAccounts();
            foreach (const Tp::AccountPtr &account, accounts) {
                if (!account->connection().isNull()) {
                    groupList.append(account->connection()->contactManager()->allKnownGroups());
                }
            }

            groupList.removeDuplicates();

            QStringList currentGroups = contact->groups();

            foreach (const QString &group, currentGroups) {
                groupList.removeAll(group);
            }

            connect(groupAddMenu->addAction(i18n("Create New Group...")), SIGNAL(triggered(bool)),
                    this, SLOT(onCreateNewGroupTriggered()));

            groupAddMenu->addSeparator();

            foreach (const QString &group, groupList) {
                connect(groupAddMenu->addAction(group), SIGNAL(triggered(bool)),
                        SLOT(onAddContactToGroupTriggered()));
            }
        } else {
            qWarning() << "Unable to support Groups";
        }
    }

    menu->addSeparator();

    if (!contact.isNull()) {
        if (contact->manager()->canRequestPresenceSubscription()) {
            if (contact->subscriptionState() != Tp::Contact::PresenceStateYes) {
                action = menu->addAction(i18n("Re-request Contact Authorization"));
                connect(action, SIGNAL(triggered(bool)), SLOT(onRerequestAuthorization()));
            }
        }
        if (contact->manager()->canAuthorizePresencePublication()) {
            if (contact->publishState() != Tp::Contact::PresenceStateYes) {
                action = menu->addAction(i18n("Resend Contact Authorization"));
                connect(action, SIGNAL(triggered(bool)), SLOT(onResendAuthorization()));
            }
        }

        action = menu->addSeparator(); //prevent two seperators in a row

        if (contact->isBlocked()) {
            action = menu->addAction(i18n("Unblock Contact"));
            connect(action, SIGNAL(triggered(bool)), SLOT(onUnblockContactTriggered()));
            action->setEnabled(contact->manager()->canBlockContacts());
        } else {
            action = menu->addAction(i18n("Block Contact"));
            connect(action, SIGNAL(triggered(bool)), SLOT(onBlockContactTriggered()));
            action->setEnabled(contact->manager()->canBlockContacts());
        }

        // remove contact action, must be QAction because that's what menu->addAction returns
        //TODO find an "if canRemove"
        QAction *removeAction = menu->addAction(QIcon::fromTheme("list-remove-user"), i18n("Remove Contact..."));
        connect(removeAction, SIGNAL(triggered(bool)), this, SLOT(onDeleteContactTriggered()));

        menu->addSeparator();
    }

    action = menu->addAction(i18n("Show Contact Information..."));
    action->setIcon(QIcon::fromTheme(""));
    connect(action, SIGNAL(triggered()), SLOT(onShowInfoTriggered()));

    return menu;
}

QMenu* ContextMenu::groupContextMenu(const QModelIndex &index)
{
    if (!index.isValid()) {
        return 0;
    }

    m_currentIndex = index;

    const QString groupName = index.data(Qt::DisplayRole).toString();

    QMenu *menu = new QMenu();
    menu->setTitle(groupName);

    //must be QAction, because menu->addAction returns QAction, otherwise compilation dies horribly
    QAction *action = menu->addAction(i18n("Rename Group..."));
    action->setIcon(QIcon::fromTheme("edit-rename"));

    connect(action, SIGNAL(triggered(bool)),
            this, SLOT(onRenameGroupTriggered()));

    action = menu->addAction(i18n("Delete Group"));
    action->setIcon(QIcon::fromTheme("edit-delete"));

    connect(action, SIGNAL(triggered(bool)),
            this, SLOT(onDeleteGroupTriggered()));

    return menu;
}

void ContextMenu::onRemoveContactFromGroupTriggered()
{
    if (m_currentIndex.parent().data(KTp::RowTypeRole).toUInt() != KTp::GroupRowType) {
        return;
    }

    const QString groupName = m_currentIndex.parent().data(Qt::DisplayRole).toString();
    Tp::ContactPtr contact =  m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();

    Tp::PendingOperation *operation = contact->removeFromGroup(groupName);

    if (operation) {
        connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
    }
}

void ContextMenu::onOpenLinkTriggered(QAction *action)
{
    QDesktopServices::openUrl(QUrl(action->data().toString()));
}

void ContextMenu::onShowInfoTriggered()
{
    if (!m_currentIndex.isValid()) {
        qWarning() << "Invalid index provided.";
        return;
    }

    if (KTp::kpeopleEnabled()) {
    #ifdef HAVE_KPEOPLE
        QString personId = m_currentIndex.data(KTp::PersonIdRole).toString();
        if (!personId.isEmpty()) {
            KPeople::PersonDetailsDialog *view = new KPeople::PersonDetailsDialog(m_mainWidget);
            KPeople::PersonData *person = new KPeople::PersonData(personId, view);
            view->setPerson(person);
            view->setAttribute(Qt::WA_DeleteOnClose);
            view->show();
        }
    #endif
    } else {
        const Tp::AccountPtr &account = m_currentIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();
        const Tp::ContactPtr &contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
        if (account && contact) {
            KTp::ContactInfoDialog* contactInfoDialog = new KTp::ContactInfoDialog(account, contact, m_mainWidget);
            contactInfoDialog->setAttribute(Qt::WA_DeleteOnClose);
            contactInfoDialog->show();
        }
    }
}

void ContextMenu::onStartTextChatTriggered()
{
    if (!m_currentIndex.isValid()) {
        qWarning() << "Invalid index provided.";
        return;
    }

    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::AccountPtr account = m_currentIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();

    if (contact && account) {
        m_mainWidget->startTextChannel(account, contact);
    }
}

void ContextMenu::onStartAudioChatTriggered()
{
    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::AccountPtr account = m_currentIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();

    if (contact && account) {
        m_mainWidget->startAudioChannel(account, contact);
    }
}

void ContextMenu::onStartVideoChatTriggered()
{
    if (!m_currentIndex.isValid()) {
        qWarning() << "Invalid index provided.";
        return;
    }

    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::AccountPtr account = m_currentIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();

    if (contact && account) {
        m_mainWidget->startVideoChannel(account, contact);
    }
}

void ContextMenu::onStartFileTransferTriggered()
{
    if (!m_currentIndex.isValid()) {
        qWarning() << "Invalid index provided.";
        return;
    }

    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::AccountPtr account = m_currentIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();

    if (contact && account) {
        m_mainWidget->startFileTransferChannel(account, contact);
    }
}

void ContextMenu::onStartDesktopSharingTriggered()
{
    if (!m_currentIndex.isValid()) {
        qWarning() << "Invalid index provided.";
        return;
    }

    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::AccountPtr account = m_currentIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();

    if (contact && account) {
        m_mainWidget->startDesktopSharing(account, contact);
    }
}

void ContextMenu::onOpenLogViewerTriggered()
{
    if (!m_currentIndex.isValid()) {
      qWarning() << "Invalid index provided.";
      return;
    }

    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::AccountPtr account = m_currentIndex.data(KTp::AccountRole).value<Tp::AccountPtr>();

    if (contact && account) {
        m_mainWidget->startLogViewer(account, contact);
    }
}

void ContextMenu::onUnblockContactTriggered()
{
    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();

    Tp::PendingOperation *operation = contact->unblock(); //FIXME
    connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
            m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
}

void ContextMenu::onAddContactToGroupTriggered()
{
    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();

    QAction *action = qobject_cast<QAction*>(sender());
    if (!action) {
        qWarning() << "Invalid action";
        return;
    }

    const QStringList currentGroups = contact->groups();

    Tp::PendingOperation* operation = contact->addToGroup(action->text().remove('&'));

    if (operation) {
        connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));

        foreach (const QString &group, currentGroups) {
            Tp::PendingOperation* operation = contact->removeFromGroup(group);
            connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                    m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
        }
    }
}

void ContextMenu::onCreateNewGroupTriggered()
{
    bool ok = false;

    QString newGroupName = QInputDialog::getText(0, i18n("New Group Name"),
                                                 i18n("Please enter the new group name"),
                                                 QLineEdit::Normal,
                                                 QString(),
                                                 &ok);

    if (ok) {
        Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
        Tp::PendingOperation *operation = contact->addToGroup(newGroupName);

        connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
    }
}

void ContextMenu::onRenameGroupTriggered()
{
    if (m_currentIndex.data(KTp::RowTypeRole).toUInt() != KTp::GroupRowType) {
        return;
    }

    const QString groupName = m_currentIndex.data(Qt::DisplayRole).toString();
    const QAbstractItemModel *model = m_currentIndex.model();

    bool ok = false;

    QString newGroupName = QInputDialog::getText(0, i18n("New Group Name"),
                                                 i18n("Please enter the new group name"),
                                                 QLineEdit::Normal,
                                                 groupName,
                                                 &ok);

    if (ok && groupName != newGroupName) {
        //loop through all child indexes of m_currentIndex
        for(int i = 0; i < model->rowCount(m_currentIndex); i++) {
            Tp::ContactPtr contact = model->index(i, 0 , m_currentIndex).data(KTp::ContactRole).value<KTp::ContactPtr>();
            Q_ASSERT(contact);

            Tp::PendingOperation *operation = contact->addToGroup(newGroupName);
            connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                    m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));

            operation = contact->removeFromGroup(groupName);
            connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                    m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
        }
    }
}

void ContextMenu::onDeleteGroupTriggered()
{
    if (m_accountManager.isNull() ||
        (m_currentIndex.data(KTp::RowTypeRole).toUInt() != KTp::GroupRowType)) {
        return;
    }

    const QString groupName = m_currentIndex.data(Qt::DisplayRole).toString();
    const QAbstractItemModel *model = m_currentIndex.model();


    if (KMessageBox::warningContinueCancel(m_mainWidget,
                                           i18n("Do you really want to remove group %1?\n\n"
                                                "Note that all contacts will be moved to group 'Ungrouped'", groupName),
                                           i18n("Remove Group")) == KMessageBox::Continue) {

        for(int i = 0; i < model->rowCount(m_currentIndex); i++) {
            Tp::ContactPtr contact = model->index(i, 0 , m_currentIndex).data(KTp::ContactRole).value<KTp::ContactPtr>();

            Q_ASSERT(contact);

            Tp::PendingOperation *operation = contact->removeFromGroup(groupName);
            connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                    m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
        }

        foreach (const Tp::AccountPtr &account, m_accountManager->allAccounts()) {
            if (account->connection()) {
                Tp::PendingOperation *operation = account->connection()->contactManager()->removeGroup(groupName);
                connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
                        m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
            }
        }
    }
}

void ContextMenu::onBlockContactTriggered()
{
    Tp::ContactPtr contact =  m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();

    Tp::PendingOperation *operation = contact->block();
    connect(operation, SIGNAL(finished(Tp::PendingOperation*)),
            m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
}

void ContextMenu::onDeleteContactTriggered()
{
    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();

    QList<Tp::ContactPtr>contactList;
    contactList.append(contact);

    // ask for confirmation
    QPointer<RemoveContactDialog> removeDialog = new RemoveContactDialog(contact, m_mainWidget);

    if (removeDialog.data()->exec() == QDialog::Accepted) {
        if (!removeDialog.isNull()) {
            // remove from contact list
            Tp::PendingOperation *deleteOp = contact->manager()->removeContacts(contactList);
            connect(deleteOp, SIGNAL(finished(Tp::PendingOperation*)),
                    m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));

            if (removeDialog.data()->blockContact()) {
                // block contact
                Tp::PendingOperation *blockOp = contact->manager()->blockContacts(contactList);
                connect(blockOp, SIGNAL(finished(Tp::PendingOperation*)),
                        m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
            }
        }
    }

    delete removeDialog.data();
}

void ContextMenu::onRerequestAuthorization()
{
    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::PendingOperation *op = contact->manager()->requestPresenceSubscription(QList<Tp::ContactPtr>() << contact);
    connect(op, SIGNAL(finished(Tp::PendingOperation*)),
            m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
}

void ContextMenu::onResendAuthorization()
{
    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();
    Tp::PendingOperation *op = contact->manager()->authorizePresencePublication(QList<Tp::ContactPtr>() << contact);
    connect(op, SIGNAL(finished(Tp::PendingOperation*)),
            m_mainWidget, SIGNAL(genericOperationFinished(Tp::PendingOperation*)));
}

void ContextMenu::onNotificationConfigureTriggered()
{
    Tp::ContactPtr contact = m_currentIndex.data(KTp::ContactRole).value<KTp::ContactPtr>();

    KTp::NotificationConfigDialog *notificationDialog = new KTp::NotificationConfigDialog(contact, m_mainWidget);
    notificationDialog->show();
}