예제 #1
0
void EntityView::rowsInserted(const QModelIndex &parent, int start, int end)
{
    QTreeView::rowsInserted(parent, start, end);
    static bool loadedCurrentContact = false;

    if (loadedCurrentContact) {
        return;
    }

    QModelIndex selectedIndex;
    QCommandLineParser parser;

    if (QCoreApplication::arguments().count() == 1 && KTp::kpeopleEnabled()) {
        const QString selectedPersonaId = QCoreApplication::arguments().at(0);
        for (int i = start; i <= end; i++) {
            const QModelIndex index = model()->index(i, 0, parent);
            if (index.data(KTp::PersonIdRole).toUrl().toString() == selectedPersonaId) {
                selectedIndex = index;
                break;
            }
        }
    } else if (QCoreApplication::arguments().count() == 2) {
        QString selectAccountId = QCoreApplication::arguments().at(0);
        QString selectContactId = QCoreApplication::arguments().at(1);

        for (int i = start; i <= end; i++) {
            QModelIndex index = model()->index(i, 0, parent);
            Tp::AccountPtr account = index.data(PersonEntityMergeModel::AccountRole).value<Tp::AccountPtr>();
            KTp::LogEntity entity = index.data(PersonEntityMergeModel::EntityRole).value<KTp::LogEntity>();
            if (account.isNull() || !entity.isValid()) {
                continue;
            }

            if (selectAccountId == account->uniqueIdentifier() && selectContactId == entity.id()) {
                selectedIndex = index;
                break;
            }
        }
    }

    if (selectedIndex.isValid()) {
        loadedCurrentContact = true;
        setCurrentIndex(selectedIndex);
        scrollTo(selectedIndex);
    } else {
        Q_EMIT noSuchContact();
    }

    expandAll();

}
예제 #2
0
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);
        }