void ConnectionsModel::onAccountManagerReady(Tp::PendingOperation* ) { InfTubeConnectionRetriever r; const ChannelList channels = r.retrieveChannels(); if ( channels.size() > 0 ){ beginInsertRows(QModelIndex(), 0, channels.size() - 1); m_connections = channels; endInsertRows(); } kDebug() << "channels:" << m_connections; foreach ( const QVariantMap& channelData, m_connections ) { kDebug() << "constructing tube for channel" << channelData; kDebug() << "accounts:" << m_accountManager->allAccounts(); foreach ( const Tp::AccountPtr account, m_accountManager->allAccounts() ) { kDebug() << account->objectPath(); } Tp::AccountPtr account = m_accountManager->accountForPath(channelData["accountPath"].toString()); Tp::StreamTubeChannelPtr channel = Tp::StreamTubeChannel::create(account->connection(), channelData["channelIdentifier"].toString(), QVariantMap()); m_channels << channel; connect(channel->becomeReady(Tp::Features() << Tp::StreamTubeChannel::FeatureCore), SIGNAL(finished(Tp::PendingOperation*)), SLOT(onChannelReady(Tp::PendingOperation*))); }
void CDTpController::maybeStartOfflineOperations(CDTpAccountPtr accountWrapper) { if (!accountWrapper->hasRoster()) { return; } Tp::AccountPtr account = accountWrapper->account(); // Start removal operation mOfflineRosterBuffer->beginGroup(offlineRemovals); QStringList idsToRemove = mOfflineRosterBuffer->value(account->objectPath()).toStringList(); mOfflineRosterBuffer->endGroup(); if (!idsToRemove.isEmpty()) { CDTpRemovalOperation *op = new CDTpRemovalOperation(accountWrapper, idsToRemove); connect(op, SIGNAL(finished(Tp::PendingOperation *)), SLOT(onRemovalFinished(Tp::PendingOperation *))); } // Start invitation operation mOfflineRosterBuffer->beginGroup(offlineInvitations); QStringList idsToInvite = mOfflineRosterBuffer->value(account->objectPath()).toStringList(); mOfflineRosterBuffer->endGroup(); if (!idsToInvite.isEmpty()) { // FIXME: We should also save the localId for offline operations CDTpInvitationOperation *op = new CDTpInvitationOperation(mStorage, accountWrapper, idsToInvite, 0); connect(op, SIGNAL(finished(Tp::PendingOperation *)), SLOT(onInvitationFinished(Tp::PendingOperation *))); } }
void GlobalPresence::onAccountAdded(const Tp::AccountPtr &account) { connect(account.data(), SIGNAL(connectionStatusChanged(Tp::ConnectionStatus)), SLOT(onConnectionStatusChanged())); connect(account.data(), SIGNAL(requestedPresenceChanged(Tp::Presence)), SLOT(onRequestedPresenceChanged())); connect(account.data(), SIGNAL(currentPresenceChanged(Tp::Presence)), SLOT(onCurrentPresenceChanged())); Q_EMIT enabledAccountsChanged(); }
ConnectProtocolPtr KDEConnectTelepathyProtocolFactory::interface() { if (s_interface.isNull()) { // Note that specifying QDBusConnection::sessionBus() is the same as not // specifying it ConnectProtocolPtr protocol = Tp::BaseProtocol::create<KDEConnectTelepathyProtocol>( QDBusConnection::sessionBus(), QLatin1String("kdeconnect")); s_interface = protocol; static Tp::BaseConnectionManagerPtr cm = Tp::BaseConnectionManager::create( QDBusConnection::sessionBus(), QLatin1String("kdeconnect")); protocol->setConnectionManagerName(cm->name()); protocol->setEnglishName(QLatin1String("KDE Connect")); protocol->setIconName(QLatin1String("kdeconnect")); protocol->setVCardField(QLatin1String("phone_number")); cm->addProtocol(protocol); cm->registerObject(); //fake being a client and create an account to use this connection //maybe this should be per device.. with a device ID as a parameter, but lets keep it connect for now Tp::AccountManagerPtr am = Tp::AccountManager::create(QDBusConnection::sessionBus()); Tp::PendingReady *pr = am->becomeReady(); QObject::connect(pr, &Tp::PendingOperation::finished, [pr,am]() { if (pr->isError()) { return; } Tp::AccountSetPtr accounts = am->accountsByProtocol("kdeconnect"); if (!accounts) { return; } QVariantMap parameters; parameters["device_id"] = "Dummy Device ID"; if (accounts->accounts().isEmpty()) { Tp::PendingAccount* pa = am->createAccount("kdeconnect", "kdeconnect", "kdeconnect", parameters, QVariantMap()); QObject::connect(pa, &Tp::PendingOperation::finished, pa, [pa](){ if (pa->isError() || !pa->account()) { return; } pa->account()->setEnabled(true); pa->account()->setRequestedPresence(Tp::Presence::available()); pa->account()->setConnectsAutomatically(true); }); } else { Tp::AccountPtr account = accounts->accounts().first(); account->setRequestedPresence(Tp::Presence::available()); account->setConnectsAutomatically(true); account->updateParameters(parameters, QStringList()); } }); } return s_interface.toStrongRef(); }
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(); }
PresenceSource::PresenceSource(const Tp::AccountPtr &account, QObject *parent) : Plasma::DataContainer(parent), m_account(account) { kDebug() << "PresenceSource created for account:" << account->objectPath(); setData("DisplayName", ""); setData("Nickname", ""); setData("AccountAvatar", ""); setData("AccountIcon", ""); setData("PresenceType", ""); setData("PresenceTypeID", 0); setData("PresenceStatus", ""); setData("PresenceStatusMessage", ""); setData("Enabled", false); // Set the object name (which will be the name of the source) setObjectName(m_account->objectPath()); // Make the account become ready with the desired features connect(m_account->becomeReady(Tp::Account::FeatureProtocolInfo|Tp::Account::FeatureAvatar), SIGNAL(finished(Tp::PendingOperation*)), this, SLOT(onAccountReady(Tp::PendingOperation*))); }
void ContactWrapper::setAccount(const Tp::AccountPtr& relatedAccount) { kDebug() << "setting account to: " << relatedAccount->displayName(); undoAccountConnects(); m_account = relatedAccount; setupAccountConnects(); }
void PendingClear::clearAccount(const Tp::AccountPtr &account) { QDBusObjectPath path = QDBusObjectPath(account->objectPath()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( mInterface->ClearAccount(path)); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(onLogCleared(QDBusPendingCallWatcher*))); }
void PendingClear::clearRoom(const Tp::AccountPtr &account, const QString &objectId) { QDBusObjectPath path = QDBusObjectPath(account->objectPath()); QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher( mInterface->ClearEntity(path, objectId, EntityTypeRoom)); connect(watcher, SIGNAL(finished(QDBusPendingCallWatcher*)), this, SLOT(onLogCleared(QDBusPendingCallWatcher*))); }
CDTpAccountPtr CDTpController::insertAccount(const Tp::AccountPtr &account, bool newAccount) { debug() << "Creating wrapper for account" << account->objectPath(); // Get the list of contact ids waiting to be removed from server mOfflineRosterBuffer->beginGroup(offlineRemovals); QStringList idsToRemove = mOfflineRosterBuffer->value(account->objectPath()).toStringList(); mOfflineRosterBuffer->endGroup(); CDTpAccountPtr accountWrapper = CDTpAccountPtr(new CDTpAccount(account, idsToRemove, newAccount, this)); mAccounts.insert(account->objectPath(), accountWrapper); maybeStartOfflineOperations(accountWrapper); // Connect change notifications connect(accountWrapper.data(), SIGNAL(rosterChanged(CDTpAccountPtr)), SLOT(onRosterChanged(CDTpAccountPtr))); connect(accountWrapper.data(), SIGNAL(changed(CDTpAccountPtr, CDTpAccount::Changes)), mStorage, SLOT(updateAccount(CDTpAccountPtr, CDTpAccount::Changes))); connect(accountWrapper.data(), SIGNAL(rosterUpdated(CDTpAccountPtr, const QList<CDTpContactPtr> &, const QList<CDTpContactPtr> &)), mStorage, SLOT(syncAccountContacts(CDTpAccountPtr, const QList<CDTpContactPtr> &, const QList<CDTpContactPtr> &))); connect(accountWrapper.data(), SIGNAL(rosterContactChanged(CDTpContactPtr, CDTpContact::Changes)), mStorage, SLOT(updateContact(CDTpContactPtr, CDTpContact::Changes))); connect(accountWrapper.data(), SIGNAL(syncStarted(Tp::AccountPtr)), SLOT(onSyncStarted(Tp::AccountPtr))); connect(accountWrapper.data(), SIGNAL(syncEnded(Tp::AccountPtr, int, int)), SLOT(onSyncEnded(Tp::AccountPtr, int, int))); return accountWrapper; }
void CDTpController::onAccountAdded(const Tp::AccountPtr &account) { if (mAccounts.contains(account->objectPath())) { warning() << "Internal error, account was already in controller"; return; } CDTpAccountPtr accountWrapper = insertAccount(account, true); mStorage->createAccount(accountWrapper); }
void WhosThere::onNewAccount(const Tp::AccountPtr &account) { qDebug() << "WhosThere::OnNewAccount " << account->normalizedName(); if(mAccount.isNull()) { emit accountOk(); mAccount = account; connect(mAccount->becomeReady(), &PendingOperation::finished, this, &WhosThere::onAccountFinished); } else { emit alert("Multiple acccounts detected. Use mc-tool to remove all but one!"); } }
XTelepathyPasswordPrompt::XTelepathyPasswordPrompt(const Tp::AccountPtr &account, QWidget *parent) : QDialog(parent), ui(new Ui::XTelepathyPasswordPrompt) { ui->setupUi(this); setAttribute(Qt::WA_ShowWithoutActivating); setWindowIcon(QIcon::fromTheme(QLatin1String("telepathy-kde"))); ui->accountName->setText(account->displayName()); ui->accountIcon->setPixmap(QIcon::fromTheme(QLatin1String("dialog-password")).pixmap(60, 60)); ui->title->setPixmap(QIcon::fromTheme(account->iconName()).pixmap(22, 22)); ui->passwordLineEdit->setFocus(); ui->savePassword->setEnabled(true); QDialogButtonBox *dbb = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel); connect(dbb, SIGNAL(accepted()), this, SLOT(accept())); connect(dbb, SIGNAL(rejected()), this, SLOT(reject())); ui->mainLayout->addWidget(dbb); }
void CDTpController::onAccountRemoved(const Tp::AccountPtr &account) { CDTpAccountPtr accountWrapper(mAccounts.take(account->objectPath())); if (not accountWrapper) { warning() << "Internal error, account was not in controller"; return; } mStorage->removeAccount(accountWrapper); // Drop pending offline operations QString accountPath = accountWrapper->account()->objectPath(); mOfflineRosterBuffer->beginGroup(offlineRemovals); mOfflineRosterBuffer->remove(accountPath); mOfflineRosterBuffer->endGroup(); mOfflineRosterBuffer->beginGroup(offlineInvitations); mOfflineRosterBuffer->remove(accountPath); mOfflineRosterBuffer->endGroup(); mOfflineRosterBuffer->sync(); }
void CDTpController::onSyncStarted(Tp::AccountPtr account) { Q_EMIT importStarted(account->serviceName(), account->objectPath()); }
void CDTpController::onSyncEnded(Tp::AccountPtr account, int contactsAdded, int contactsRemoved) { Q_EMIT importEnded(account->serviceName(), account->objectPath(), contactsAdded, contactsRemoved, 0); }
ContactInfoDialog::ContactInfoDialog(const Tp::AccountPtr &account, const Tp::ContactPtr &contact, QWidget *parent) : QDialog(parent) , d(new Private(this)) { #if 0 // Editing contacts is not yet supported in TpQt /* Whether contact is the user himself */ d->editable = (contact == account->connection()->selfContact()); #endif d->editable = false; d->account = account; d->contact = KTp::ContactPtr::qObjectCast(contact); d->buttonBox = new QDialogButtonBox(this); if (d->editable) { d->buttonBox->setStandardButtons(QDialogButtonBox::Save | QDialogButtonBox::Close); } else { d->buttonBox->setStandardButtons(QDialogButtonBox::Close); } connect(d->buttonBox, &QDialogButtonBox::clicked, this, &ContactInfoDialog::slotButtonClicked); setMaximumSize(sizeHint()); QVBoxLayout *layout = new QVBoxLayout(this); layout->setSpacing(30); /* Title - presence icon, alias, id */ KTitleWidget *titleWidget = new KTitleWidget(this); KTp::Presence presence(contact->presence()); titleWidget->setPixmap(presence.icon().pixmap(32, 32), KTitleWidget::ImageLeft); titleWidget->setText(contact->alias()); titleWidget->setComment(contact->id()); layout->addWidget(titleWidget); /* 1st column: avatar; 2nd column: details */ d->columnsLayout = new QHBoxLayout(); d->columnsLayout->setSpacing(30); layout->addLayout(d->columnsLayout); /* Make sure the contact has all neccessary features ready */ Tp::PendingContacts *op = contact->manager()->upgradeContacts( QList<Tp::ContactPtr>() << contact, Tp::Features() << Tp::Contact::FeatureAvatarData << Tp::Contact::FeatureInfo); connect(op, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onContactUpgraded(Tp::PendingOperation*))); /* State Info - there is no point showing this information when it's about ourselves */ if (!d->editable) { d->stateLayout = new QFormLayout(); d->stateLayout->setSpacing(10); layout->addLayout(d->stateLayout); // Fetch roster feature, if it is supported, but not loaded Tp::ConnectionPtr conn = contact->manager()->connection(); if(!conn->actualFeatures().contains(Tp::Connection::FeatureRoster) && !conn->missingFeatures().contains(Tp::Connection::FeatureRoster)) { Tp::PendingReady *pr = conn->becomeReady(Tp::Features() << Tp::Connection::FeatureRoster); connect(pr, SIGNAL(finished(Tp::PendingOperation*)), SLOT(onFeatureRosterReady(Tp::PendingOperation*))); } else { d->loadStateRows(); } } layout->addWidget(d->buttonBox); }
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); }