[SCM] ktp-contact-runner packaging branch, master, updated. debian/15.12.1-2-244-g38a1f58
Maximiliano Curia
maxy at moszumanska.debian.org
Sat May 28 17:50:30 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-contact-runner.git;a=commitdiff;h=fb66d0c
The following commit has been merged in the master branch:
commit fb66d0cc50cd5b5b36cf85584bcc3a827c56c326
Author: Dan Vrátil <dan at progdan.cz>
Date: Thu Aug 2 21:13:31 2012 +0200
Revert "Add syntax for changing global presence"
Committed incorrect version and wrong files
This reverts commit 90ee1881b72245424a86bdf529f4bbc8dec3b282.
---
src/contactrunner.cpp | 430 +++++++++++++++++--------------------------------
src/contactrunner.h | 14 +-
src/settingsdialog.cpp | 240 ---------------------------
src/settingsdialog.h | 79 ---------
4 files changed, 148 insertions(+), 615 deletions(-)
diff --git a/src/contactrunner.cpp b/src/contactrunner.cpp
index 3dc15da..84da2fb 100644
--- a/src/contactrunner.cpp
+++ b/src/contactrunner.cpp
@@ -20,6 +20,7 @@
#include "contactrunner.h"
#include <KDebug>
+#include <KIcon>
#include <KFileDialog>
#include <KMimeType>
#include <KToolInvocation>
@@ -42,66 +43,46 @@
#include <KTp/Models/accounts-filter-model.h>
#include <KTp/Models/contact-model-item.h>
#include <KTp/presence.h>
-#include <KTp/global-presence.h>
-struct MatchInfo {
+#include <QAction>
+
+struct ContactInfo {
Tp::AccountPtr account;
Tp::ContactPtr contact;
- KTp::Presence presence;
};
Q_DECLARE_METATYPE(QModelIndex);
-Q_DECLARE_METATYPE(MatchInfo);
+Q_DECLARE_METATYPE(ContactInfo);
ContactRunner::ContactRunner(QObject *parent, const QVariantList &args):
Plasma::AbstractRunner(parent, args),
- m_accountsModel(new AccountsModel(this)),
- m_globalPresence(new KTp::GlobalPresence(this))
+ m_accountsModel(0)
{
Q_UNUSED(args);
- setObjectName(QLatin1String("IM Contacts Runner"));
+ setObjectName("IM Contacts Runner");
- m_loggerDisabled = KStandardDirs::findExe(QLatin1String("ktp-log-viewer")).isEmpty();
+ m_loggerDisabled = KStandardDirs::findExe("ktp-log-viewer").isEmpty();
- addSyntax(Plasma::RunnerSyntax(QLatin1String(":q:"), i18n("Finds all IM contacts matching :q:.")));
- addSyntax(Plasma::RunnerSyntax(QLatin1String("chat :q:"), i18n("Finds all contacts matching :q: that are capable of text chats (default behavior)")));
- addSyntax(Plasma::RunnerSyntax(QLatin1String("audiocall :q:"), i18n("Finds all contacts matching :q: that are capable of audio call and uses audio calls as default action.")));
- addSyntax(Plasma::RunnerSyntax(QLatin1String("videocall :q:"), i18n("Finds all contacts matching :q: that are capable of video call and uses video calls as default action.")));
- addSyntax(Plasma::RunnerSyntax(QLatin1String("sendfile :q:"), i18n("Finds all contacts matching :q: that are capable of receiving files and sends file as default action.")));
- addSyntax(Plasma::RunnerSyntax(QLatin1String("sharedesktop :q:"), i18n("Finds all contacts matching :q: that are capable of sharing desktop and sets desktop sharing as default action.")));
+ addSyntax(Plasma::RunnerSyntax(":q:", i18n("Finds all IM contacts matching :q:.")));
+ addSyntax(Plasma::RunnerSyntax("chat :q:", i18n("Finds all contacts matching :q: that are capable of text chats (default behavior)")));
+ addSyntax(Plasma::RunnerSyntax("audiocall :q:", i18n("Finds all contacts matching :q: that are capable of audio call and uses audio calls as default action.")));
+ addSyntax(Plasma::RunnerSyntax("videocall :q:", i18n("Finds all contacts matching :q: that are capable of video call and uses video calls as default action.")));
+ addSyntax(Plasma::RunnerSyntax("sendfile :q:", i18n("Finds all contacts matching :q: that are capable of receiving files and sends file as default action.")));
+ addSyntax(Plasma::RunnerSyntax("sharedesktop :q:", i18n("Finds all contacts matching :q: that are capable of sharing desktop and sets desktop sharing as default action.")));
- if (!m_loggerDisabled) {
- addSyntax(Plasma::RunnerSyntax(QLatin1String("log :q:"), i18n("Open the log viewer for :q:")));
- }
+ if (!m_loggerDisabled)
+ addSyntax(Plasma::RunnerSyntax("log :q:", i18n("Open the log viewer for :q:")));
- QString imKeyword = i18nc("A keyword to change IM status", "im") + QLatin1String(" :q:");
- QString statusKeyword = i18n("A keyword to change IM status", "status") + QLatin1String(" :q:");
- Plasma::RunnerSyntax presenceSyntax(imKeyword, i18n("Change IM status"));
- presenceSyntax.addExampleQuery(statusKeyword);
- presenceSyntax.setSearchTermDescription(i18nc("Search term description", "status"));
- addSyntax(presenceSyntax);
-
- Plasma::RunnerSyntax presenceMsgSyntax(imKeyword + ' ' + i18nc("Description of a search term, please keep the brackets", "<status message>"),
- i18n("Change IM status and set status message."));
- presenceMsgSyntax.addExampleQuery(statusKeyword + ' ' + i18nc("Description of a search term, please keep the brackets", "<status message>"));
- presenceMsgSyntax.setSearchTermDescription(i18nc("Search term description", "status"));
- addSyntax(presenceMsgSyntax);
-
- addSyntax(Plasma::RunnerSyntax(i18nc("A command to connect all IM accounts", "connect"),
- i18n("Connect all IM accounts")));
- addSyntax(Plasma::RunnerSyntax(i18nc("A command to disconnect all IM accounts", "disconnect"),
- i18n("Disconnect al IM accounts")));;
-
- addAction(QLatin1String("start-text-chat"), QIcon::fromTheme(QLatin1String("text-x-generic")), i18n("Start Chat"));
- addAction(QLatin1String("start-audio-call"), QIcon::fromTheme(QLatin1String("audio-headset")), i18n("Start Audio Call"));
- addAction(QLatin1String("start-video-call"), QIcon::fromTheme(QLatin1String("camera-web")), i18n("Start Video Call"));
- addAction(QLatin1String("start-file-transfer"), QIcon::fromTheme(QLatin1String("mail-attachment")), i18n("Send file(s)"));
- addAction(QLatin1String("start-desktop-sharing"), QIcon::fromTheme(QLatin1String("krfb")), i18n("Share My Desktop"));
-
- if (!m_loggerDisabled) {
- addAction(QLatin1String("show-log-viewer"), QIcon::fromTheme(QLatin1String("view-pim-journal")), i18n("Open the log viewer"));
- }
+
+ addAction("start-text-chat", QIcon::fromTheme("text-x-generic"), i18n("Start Chat"));
+ addAction("start-audio-call", QIcon::fromTheme("audio-headset"), i18n("Start Audio Call"));
+ addAction("start-video-call", QIcon::fromTheme("camera-web"), i18n("Start Video Call"));
+ addAction("start-file-transfer", QIcon::fromTheme("mail-attachment"), i18n("Send file(s)"));
+ addAction("start-desktop-sharing", QIcon::fromTheme("krfb"), i18n("Share My Desktop"));
+
+ if (!m_loggerDisabled)
+ addAction("show-log-viewer", QIcon::fromTheme("view-pim-journal"), i18n("Open the log viewer"));
Tp::registerTypes();
Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
@@ -130,7 +111,7 @@ ContactRunner::ContactRunner(QObject *parent, const QVariantList &args):
ContactRunner::~ContactRunner()
{
-
+ delete m_accountsModel;
}
void ContactRunner::accountManagerReady(Tp::PendingOperation *operation)
@@ -142,15 +123,15 @@ void ContactRunner::accountManagerReady(Tp::PendingOperation *operation)
kDebug() << "Accounts manager is ready!";
+ m_accountsModel = new AccountsModel(this);
m_accountsModel->setAccountManager(m_accountManager);
- m_globalPresence->setAccountManager(m_accountManager);
}
QList< QAction* > ContactRunner::actionsForMatch(const Plasma::QueryMatch &match)
{
QList< QAction* > actions;
- MatchInfo data = match.data().value< MatchInfo >();
+ ContactInfo data = match.data().value< ContactInfo >();
if (!data.contact) {
return actions;
}
@@ -158,27 +139,26 @@ QList< QAction* > ContactRunner::actionsForMatch(const Plasma::QueryMatch &match
Tp::ContactCapabilities capabilities = data.contact->capabilities();
if (capabilities.textChats()) {
- actions.append(action(QLatin1String("start-text-chat")));
+ actions.append(action("start-text-chat"));
- if (!m_loggerDisabled) {
- actions.append(action(QLatin1String("show-log-viewer")));
- }
+ if (!m_loggerDisabled)
+ actions.append(action("show-log-viewer"));
}
if (capabilities.audioCalls()) {
- actions.append(action(QLatin1String("start-audio-call")));
+ actions.append(action("start-audio-call"));
}
if (capabilities.videoCallsWithAudio()) {
- actions.append(action(QLatin1String("start-video-call")));
+ actions.append(action("start-video-call"));
}
if (capabilities.fileTransfers()) {
- actions.append(action(QLatin1String("start-file-transfer")));
+ actions.append(action("start-file-transfer"));
}
- if (capabilities.streamTubes(QLatin1String("rfb"))) {
- actions.append(action(QLatin1String("start-desktop-sharing")));
+ if (capabilities.streamTubes("rfb")) {
+ actions.append(action("start-desktop-sharing"));
}
return actions;
@@ -194,170 +174,39 @@ void ContactRunner::match(Plasma::RunnerContext &context)
return;
}
- if (!m_accountManager->isReady()) {
- return;
- }
-
- /* First check for "im" or "status" keywords */
- matchPresence(context);
-
- /* But always try to match contacts too (in case somebody had a contact
- * names "im..." */
- matchContacts(context);
-}
-
-
-void ContactRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
-{
- Q_UNUSED(context)
-
- MatchInfo data = match.data().value< MatchInfo >();
- if (data.presence.isValid()) {
- data.presence.setStatus(data.presence.type(), data.presence.status(), data.presence.statusMessage());
- m_globalPresence->setPresence(data.presence);
-
- return;
- }
-
- if (!data.account || !data.contact) {
- kWarning() << "Running invalid contact info";
+ if (!m_accountsModel || !m_accountManager->isReady()) {
return;
}
- /* Open chat/call/whaterver with contact */
- Tp::AccountPtr account = data.account;
- Tp::ContactPtr contact = data.contact;
-
- Tp::ChannelRequestHints hints;
- hints.setHint(QLatin1String("org.freedesktop.Telepathy.ChannelRequest"),
- QLatin1String("DelegateToPreferredHandler"),
- QVariant(true));
-
- if (match.selectedAction() == action(QLatin1String("start-text-chat"))) {
-
- account->ensureTextChat(contact,
- QDateTime::currentDateTime(),
- QLatin1String("org.freedesktop.Telepathy.Client.KTp.TextUi"),
- hints);
-
- } else if (match.selectedAction() == action(QLatin1String("start-audio-call"))) {
-
- account->ensureAudioCall(contact,
- QLatin1String("audio"),
- QDateTime::currentDateTime(),
- QLatin1String("org.freedesktop.Telepathy.Client.KTp.CallUi"));
-
- } else if (match.selectedAction() == action("start-video-call")) {
-
- account->ensureAudioVideoCall(contact,
- QLatin1String("audio"), QLatin1String("video"),
- QDateTime::currentDateTime(),
- QLatin1String("org.freedesktop.Telepathy.Client.KTp.CallUi"));
-
- } else if (match.selectedAction() == action("start-file-transfer")) {
-
- QStringList filenames = KFileDialog::getOpenFileNames(
- KUrl("kfiledialog:///FileTransferLastDirectory"),
- QString(),
- 0,
- i18n("Choose files to send to %1", contact->alias()));
-
- if (filenames.isEmpty()) { // User hit cancel button
- return;
- }
-
- foreach (const QString &filename, filenames) {
- Tp::FileTransferChannelCreationProperties properties(
- filename, KMimeType::findByFileContent(filename)->name());
-
- account->createFileTransfer(contact,
- properties,
- QDateTime::currentDateTime(),
- QLatin1String("org.freedesktop.Telepathy.Client.KTp.FileTransfer"));
- }
-
- } else if (match.selectedAction() == action("start-desktop-sharing")) {
-
- account->createStreamTube(contact,
- QLatin1String("rfb"),
- QDateTime::currentDateTime(),
- QLatin1String("org.freedesktop.Telepathy.Client.krfb_rfb_handler"));
-
- } else if (match.selectedAction() == action(QLatin1String("show-log-viewer"))) {
-
- KToolInvocation::kdeinitExec(QLatin1String("ktp-log-viewer"),
- QStringList() << account->uniqueIdentifier() << contact->id());
-
- }
-}
-
-bool ContactRunner::hasCapability(const QModelIndex &contact, AccountsFilterModel::CapabilityFilterFlag capability) const
-{
- if (capability == AccountsFilterModel::DoNotFilterByCapability) {
- return true;
- }
-
- if ((capability == AccountsFilterModel::FilterByTextChatCapability) &&
- contact.data(AccountsModel::TextChatCapabilityRole).toBool()) {
- return true;
- }
-
- if ((capability == AccountsFilterModel::FilterByAudioCallCapability) &&
- contact.data(AccountsModel::AudioCallCapabilityRole).toBool()) {
- return true;
- }
-
- if ((capability == AccountsFilterModel::FilterByVideoCallCapability) &&
- contact.data(AccountsModel::VideoCallCapabilityRole).toBool()) {
- return true;
- }
-
- if ((capability == AccountsFilterModel::FilterByFileTransferCapability) &&
- contact.data(AccountsModel::FileTransferCapabilityRole).toBool()) {
- return true;
- }
-
- if ((capability == AccountsFilterModel::FilterByDesktopSharingCapability) &&
- contact.data(AccountsModel::DesktopSharingCapabilityRole).toBool()) {
- return true;
- }
-
- return false;
-}
-
-void ContactRunner::matchContacts(Plasma::RunnerContext &context)
-{
- QString term = context.query();
-
QAction *defaultAction;
QString contactQuery;
AccountsFilterModel::CapabilityFilterFlag filterFlag;
if (term.startsWith(QLatin1String("chat "), Qt::CaseInsensitive)) {
- defaultAction = action(QLatin1String("start-text-chat"));
+ defaultAction = action("start-text-chat");
filterFlag = AccountsFilterModel::FilterByTextChatCapability;
- contactQuery = term.mid(QString("chat").length()).trimmed();
+ contactQuery = term.mid(5).trimmed();
} else if (term.startsWith(QLatin1String("audiocall "), Qt::CaseInsensitive)) {
- defaultAction = action(QLatin1String("start-audio-call"));
+ defaultAction = action("start-audio-call");
filterFlag = AccountsFilterModel::FilterByAudioCallCapability;
- contactQuery = term.mid(QString("audiocall").length()).trimmed();
+ contactQuery = term.mid(10).trimmed();
} else if (term.startsWith(QLatin1String("videocall "), Qt::CaseInsensitive)) {
- defaultAction = action(QLatin1String("start-video-call"));
+ defaultAction = action("start-video-call");
filterFlag = AccountsFilterModel::FilterByVideoCallCapability;
- contactQuery = term.mid(QString("videocall").length()).trimmed();
+ contactQuery = term.mid(10).trimmed();
} else if (term.startsWith(QLatin1String("sendfile "), Qt::CaseInsensitive)) {
- defaultAction = action(QLatin1String("start-file-transfer"));
+ defaultAction = action("start-file-transfer");
filterFlag = AccountsFilterModel::FilterByFileTransferCapability;
- contactQuery = term.mid(QString("sendfile").length()).trimmed();
+ contactQuery = term.mid(9).trimmed();
} else if (term.startsWith(QLatin1String("sharedesktop "), Qt::CaseInsensitive)) {
- defaultAction = action(QLatin1String("start-desktop-sharing"));
+ defaultAction = action("start-desktop-sharing");
filterFlag = AccountsFilterModel::FilterByDesktopSharingCapability;
- contactQuery = term.mid(QString("sharedesktop").length()).trimmed();
+ contactQuery = term.mid(13).trimmed();
} else if (term.startsWith(QLatin1String("log "), Qt::CaseInsensitive)) {
- defaultAction = action(QLatin1String("show-log-viewer"));
+ defaultAction = action("show-log-viewer");
filterFlag = AccountsFilterModel::DoNotFilterByCapability;
- contactQuery = term.mid(QString("log").length()).trimmed();
+ contactQuery = term.mid(4).trimmed();
} else {
- defaultAction = action(QLatin1String("start-text-chat"));
+ defaultAction = action("start-text-chat");
filterFlag = AccountsFilterModel::DoNotFilterByCapability;
contactQuery = term;
}
@@ -392,33 +241,40 @@ void ContactRunner::matchContacts(Plasma::RunnerContext &context)
/* Store AccountsModelItem and ContactsModelItem as the data of match so that it can
* be retrieved quickly later */
- MatchInfo data;
+ ContactInfo data;
data.account = accountIndex.data(AccountsModel::ItemRole).value< AccountsModelItem* >()->account();
data.contact = contactIndex.data(AccountsModel::ItemRole).value< ContactModelItem* >()->contact();
match.setData(qVariantFromValue(data));
- match.setText(name + QLatin1String(" (") + accountIndex.data(AccountsModel::DisplayNameRole).toString() + ')');
+ match.setText(name.append(" (%1)").arg(accountIndex.data(AccountsModel::DisplayNameRole).toString()));
match.setType(Plasma::QueryMatch::ExactMatch);
+ QString iconName;
KTp::Presence presence = contactIndex.data(AccountsModel::PresenceRole).value< KTp::Presence >();
switch (presence.type()) {
case Tp::ConnectionPresenceTypeAvailable:
+ iconName = "im-user";
relevance *= 10;
break;
case Tp::ConnectionPresenceTypeBusy:
+ iconName = "im-user-busy";
relevance *= 8;
break;
case Tp::ConnectionPresenceTypeAway:
case Tp::ConnectionPresenceTypeExtendedAway:
+ iconName = "im-user-away";
relevance *= 6;
break;
case Tp::ConnectionPresenceTypeHidden:
+ iconName = "im-invisible-user";
relevance *= 4;
break;
case Tp::ConnectionPresenceTypeOffline:
+ iconName = "im-user-offline";
relevance *= 1;
break;
default:
+ iconName = "im-user-offline";
relevance *= 1;
break;
}
@@ -427,11 +283,11 @@ void ContactRunner::matchContacts(Plasma::RunnerContext &context)
if (!iconFile.isEmpty() && QFile::exists(iconFile)) {
match.setIcon(QIcon(iconFile));
} else {
- match.setIcon(presence.icon());
+ match.setIcon(QIcon::fromTheme(iconName));
}
if (!presence.statusMessage().isEmpty()) {
- match.setSubtext(presence.displayString() + QLatin1String(" | ") + presence.statusMessage());
+ match.setSubtext(presence.displayString() + " | " + presence.statusMessage());
} else {
match.setSubtext(presence.displayString());
}
@@ -444,105 +300,113 @@ void ContactRunner::matchContacts(Plasma::RunnerContext &context)
}
}
-void ContactRunner::matchPresence(Plasma::RunnerContext &context)
+void ContactRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
- const QString imKeyword = i18nc("A keyword to change IM status", "im");
- const QString statusKeyword = i18nc("A keyword to change IM status", "status");
- const QString connectCommand = i18nc("A command to connect all IM accounts", "connect");
- const QString disconnectCommand = i18nc("A command to disconnect all IM accounts", "disconnect");
-
- QString term = context.query().trimmed();
+ Q_UNUSED(context)
- if (!term.startsWith(imKeyword) && !term.startsWith(statusKeyword) &&
- (term != connectCommand) && (term != disconnectCommand)) {
+ ContactInfo data = match.data().value< ContactInfo >();
+ if (!data.account || !data.contact) {
+ kWarning() << "Running invalid contact info";
return;
}
- /* Display all available presences? */
- bool all = ((term == imKeyword) || (term == statusKeyword));
- QString presenceString;
- QString statusMessage;
-
- if (!all) {
- /* Get string after the keyword */
- QString cmd = term.mid(term.indexOf(' ')).trimmed();
-
- int pos = cmd.indexOf(' ');
- if (pos > 0) {
- presenceString = cmd.mid(0, pos);
- statusMessage = cmd.mid(pos + 1);
- } else {
- presenceString = cmd;
+ Tp::AccountPtr account = data.account;
+ Tp::ContactPtr contact = data.contact;
+
+ Tp::ChannelRequestHints hints;
+ hints.setHint("org.freedesktop.Telepathy.ChannelRequest", "DelegateToPreferredHandler", QVariant(true));
+
+ if (match.selectedAction() == action("start-text-chat")) {
+
+ account->ensureTextChat(contact,
+ QDateTime::currentDateTime(),
+ "org.freedesktop.Telepathy.Client.KTp.TextUi",
+ hints);
+
+ } else if (match.selectedAction() == action("start-audio-call")) {
+
+ account->ensureAudioCall(contact,
+ QLatin1String("audio"),
+ QDateTime::currentDateTime(),
+ QLatin1String("org.freedesktop.Telepathy.Client.KTp.CallUi"));
+
+ } else if (match.selectedAction() == action("start-video-call")) {
+
+ account->ensureAudioVideoCall(contact,
+ QLatin1String("audio"), QLatin1String("video"),
+ QDateTime::currentDateTime(),
+ QLatin1String("org.freedesktop.Telepathy.Client.KTp.CallUi"));
+
+ } else if (match.selectedAction() == action("start-file-transfer")) {
+
+ QStringList filenames = KFileDialog::getOpenFileNames(
+ KUrl("kfiledialog:///FileTransferLastDirectory"),
+ QString(),
+ 0,
+ i18n("Choose files to send to %1", contact->alias()));
+
+ if (filenames.isEmpty()) { // User hit cancel button
+ return;
}
- }
- if (all || i18nc("IM presence", "online").contains(presenceString, Qt::CaseInsensitive) || (term == connectCommand)) {
- addPresenceMatch(context, Tp::ConnectionPresenceTypeAvailable, statusMessage);
- }
+ foreach (const QString &filename, filenames) {
+ Tp::FileTransferChannelCreationProperties properties(
+ filename, KMimeType::findByFileContent(filename)->name());
+
+ account->createFileTransfer(contact,
+ properties,
+ QDateTime::currentDateTime(),
+ "org.freedesktop.Telepathy.Client.KTp.FileTransfer");
+ }
+
+ } else if (match.selectedAction() == action("start-desktop-sharing")) {
+
+ account->createStreamTube(contact,
+ QLatin1String("rfb"),
+ QDateTime::currentDateTime(),
+ "org.freedesktop.Telepathy.Client.krfb_rfb_handler");
+
+ } else if (match.selectedAction() == action("show-log-viewer")) {
+
+ KToolInvocation::kdeinitExec(QLatin1String("ktp-log-viewer"),
+ QStringList() << account->uniqueIdentifier() << contact->id());
- if (all || i18nc("IM presence", "away").contains(presenceString, Qt::CaseInsensitive)) {
- addPresenceMatch(context, Tp::ConnectionPresenceTypeAway, statusMessage);
}
+}
- if (all || i18nc("IM presence","busy").contains(presenceString, Qt::CaseInsensitive)) {
- addPresenceMatch(context, Tp::ConnectionPresenceTypeBusy, statusMessage);
+bool ContactRunner::hasCapability(const QModelIndex &contact, AccountsFilterModel::CapabilityFilterFlag capability) const
+{
+ if (capability == AccountsFilterModel::DoNotFilterByCapability) {
+ return true;
}
- if (all || i18nc("IM presence","hidden").contains(presenceString, Qt::CaseInsensitive)) {
- addPresenceMatch(context, Tp::ConnectionPresenceTypeHidden, statusMessage);
+ if ((capability == AccountsFilterModel::FilterByTextChatCapability) &&
+ contact.data(AccountsModel::TextChatCapabilityRole).toBool()) {
+ return true;
}
- if (all || i18nc("IM presence","offline").contains(presenceString, Qt::CaseInsensitive) || (term == disconnectCommand)) {
- addPresenceMatch(context, Tp::ConnectionPresenceTypeOffline, statusMessage);
+ if ((capability == AccountsFilterModel::FilterByAudioCallCapability) &&
+ contact.data(AccountsModel::AudioCallCapabilityRole).toBool()) {
+ return true;
}
-}
-void ContactRunner::addPresenceMatch(Plasma::RunnerContext &context, Tp::ConnectionPresenceType presence,
- const QString &statusMessage)
-{
- Plasma::QueryMatch match(this);
- match.setType(Plasma::QueryMatch::ExactMatch);
-
- MatchInfo data;
-
- switch (presence) {
- case Tp::ConnectionPresenceTypeAvailable:
- data.presence = KTp::Presence(Tp::Presence::available());
- match.setIcon(data.presence.icon());
- match.setText(i18nc("Description of runner action", "Set IM status to online"));
- break;
- case Tp::ConnectionPresenceTypeAway:
- data.presence = KTp::Presence(Tp::Presence::away());
- match.setIcon(data.presence.icon());
- match.setText(i18nc("Description of runner action", "Set IM status to away"));
- break;
- case Tp::ConnectionPresenceTypeBusy:
- data.presence = KTp::Presence(Tp::Presence::busy());
- match.setIcon(data.presence.icon());
- match.setText(i18nc("Description of runner action", "Set IM status to busy"));
- break;
- case Tp::ConnectionPresenceTypeHidden:
- data.presence = KTp::Presence(Tp::Presence::hidden());
- match.setIcon(data.presence.icon());
- match.setText(i18nc("Description of runner action", "Set IM status to hidden"));
- break;
- case Tp::ConnectionPresenceTypeOffline:
- data.presence = KTp::Presence(Tp::Presence::offline());
- match.setIcon(data.presence.icon());
- match.setText(i18nc("Description of runner action", "Set IM status to offline"));
- break;
- default:
- return;
+ if ((capability == AccountsFilterModel::FilterByVideoCallCapability) &&
+ contact.data(AccountsModel::VideoCallCapabilityRole).toBool()) {
+ return true;
}
- if (!statusMessage.isEmpty()) {
- match.setSubtext(i18n("Status message: %1", statusMessage));
- data.presence.setStatusMessage(statusMessage);
+ if ((capability == AccountsFilterModel::FilterByFileTransferCapability) &&
+ contact.data(AccountsModel::FileTransferCapabilityRole).toBool()) {
+ return true;
}
- match.setData(qVariantFromValue(data));
+ if ((capability == AccountsFilterModel::FilterByDesktopSharingCapability) &&
+ contact.data(AccountsModel::DesktopSharingCapabilityRole).toBool()) {
+ return true;
+ }
- context.addMatch(context.query(), match);
+ return false;
}
+
#include "contactrunner.moc"
diff --git a/src/contactrunner.h b/src/contactrunner.h
index 55e7e9d..54e151a 100644
--- a/src/contactrunner.h
+++ b/src/contactrunner.h
@@ -31,17 +31,12 @@
#include <TelepathyQt/AccountManager>
-namespace KTp
-{
- class GlobalPresence;
-}
+class QAction;
namespace Tp {
class PendingOperation;
}
-class QAction;
-
class ContactRunner : public Plasma::AbstractRunner
{
Q_OBJECT
@@ -62,14 +57,7 @@ class ContactRunner : public Plasma::AbstractRunner
private:
bool hasCapability(const QModelIndex &contact, AccountsFilterModel::CapabilityFilterFlag capability) const;
- void matchPresence(Plasma::RunnerContext &context);
- void matchContacts(Plasma::RunnerContext &context);
-
- void addPresenceMatch(Plasma::RunnerContext &context, Tp::ConnectionPresenceType presence,
- const QString &statusMessage);
-
AccountsModel *m_accountsModel;
- KTp::GlobalPresence *m_globalPresence;
Tp::AccountManagerPtr m_accountManager;
bool m_loggerDisabled;
diff --git a/src/settingsdialog.cpp b/src/settingsdialog.cpp
deleted file mode 100644
index 8590088..0000000
--- a/src/settingsdialog.cpp
+++ /dev/null
@@ -1,240 +0,0 @@
-/*
- Copyright (C) 2012 Dan Vratil <dan at progdan.cz>
-
- 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 "settingsdialog.h"
-
-#include <QtGui/QGridLayout>
-#include <KPushButton>
-#include <QtGui/QTreeView>
-#include <QtGui/QSortFilterProxyModel>
-#include <QtGui/QHeaderView>
-#include <QtGui/QLabel>
-
-#include <TelepathyQt/AccountFactory>
-#include <TelepathyQt/AccountManager>
-#include <TelepathyQt/PendingReady>
-
-#include <KDebug>
-#include <KComponentData>
-#include <Plasma/AbstractRunner>
-#include <KPushButton>
-#include <KLocalizedString>
-
-K_EXPORT_RUNNER_CONFIG(KtpRunnerSettings, SettingsDialog)
-
-static const int SortRole = AccountsModel::CustomRole;
-
-SettingsDialog::SettingsDialog(QWidget *parent, const QVariantList& args):
- KCModule(ConfigFactory::componentData(), parent, args),
- m_accountsModel(0)
-{
- QGridLayout *layout = new QGridLayout(parent);
- setLayout(layout);
-
- QLabel *label = new QLabel(i18n("Order accounts by your preference:"), this);
- layout->addWidget(label, 0, 0, 1, 2);
-
- m_treeView = new QTreeView(this);
- m_treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
- m_treeView->setSelectionMode(QAbstractItemView::SingleSelection);
- m_treeView->header()->hide();
- m_treeView->setDragDropMode(QAbstractItemView::InternalMove);
- m_treeView->setDragEnabled(true);
- m_treeView->viewport()->setAcceptDrops(true);
- m_treeView->setDropIndicatorShown(true);
- layout->addWidget(m_treeView, 1, 0, 4, 1);
-
- m_topButton = new KPushButton(KIcon("arrow-up-double"), QString(), this);
- m_topButton->setDisabled(true);
- layout->addWidget(m_topButton, 1, 1);
- connect(m_topButton, SIGNAL(clicked(bool)), this, SLOT(moveTop()));
-
- m_upButton = new KPushButton(KIcon("arrow-up"), QString());
- m_upButton->setDisabled(true);
- layout->addWidget(m_upButton, 2, 1);
- connect(m_upButton, SIGNAL(clicked(bool)), this, SLOT(moveUp()));
-
- m_downButton = new KPushButton(KIcon("arrow-down"), QString());
- m_downButton->setDisabled(true);
- layout->addWidget(m_downButton, 3, 1);
- connect(m_downButton, SIGNAL(clicked(bool)), this, SLOT(moveDown()));
-
- m_bottomButton = new KPushButton(KIcon("arrow-down-double"), QString());
- m_bottomButton->setDisabled(true);
- layout->addWidget(m_bottomButton, 4, 1);
- connect(m_bottomButton, SIGNAL(clicked(bool)), this, SLOT(moveBottom()));
-
-
- Tp::registerTypes();
- Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
- QDBusConnection::sessionBus(),
- Tp::Features() << Tp::Account::FeatureCore);
-
- Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(
- QDBusConnection::sessionBus(),
- Tp::Features() << Tp::Connection::FeatureCore
- << Tp::Connection::FeatureSelfContact);
-
-
- m_accountManager = Tp::AccountManager::create(accountFactory, connectionFactory);
- connect(m_accountManager->becomeReady(Tp::AccountManager::FeatureCore),
- SIGNAL(finished(Tp::PendingOperation *)),
- this, SLOT(accountManagerReady(Tp::PendingOperation *)));
-}
-
-SettingsDialog::~SettingsDialog()
-{
-
-}
-
-void SettingsDialog::accountManagerReady(Tp::PendingOperation *operation)
-{
- if (operation->isError()) {
- kWarning() << operation->errorMessage();
- return;
- }
-
- kDebug() << "Accounts manager is ready!";
-
- m_accountsModel = new AccountsModel(this);
- m_accountsModel->setAccountManager(m_accountManager);
-
- load();
-
- m_proxy = new QSortFilterProxyModel(this);
- m_proxy->setSourceModel(m_accountsModel);
- m_proxy->setSortRole(SortRole);
-
- m_treeView->setModel(m_proxy);
- connect(m_treeView->selectionModel(), SIGNAL(currentRowChanged(QModelIndex,QModelIndex)),
- this, SLOT(selectionChanged(QModelIndex,QModelIndex)));
-}
-
-void SettingsDialog::selectionChanged(const QModelIndex ¤t , const QModelIndex &previous)
-{
- if (!current.isValid()) {
- return;
- }
-
- m_topButton->setEnabled(current.row() != 0);
- m_upButton->setEnabled(current.row() != 0);
-
- m_downButton->setEnabled(current.row() < current.model()->rowCount(current.parent()) - 1);
- m_bottomButton->setEnabled(current.row() < current.model()->rowCount(current.parent()) - 1);
-
- Q_UNUSED(previous);
-}
-
-void SettingsDialog::moveTop()
-{
- QItemSelectionModel *selection = m_treeView->selectionModel();
-
- QModelIndex index = selection->currentIndex();
- int r = index.row();
-
- for (int i = 0; i < r; i++) {
- m_proxy->setData(m_proxy->index(i, 0), i + 1, SortRole);
- }
-
- m_proxy->setData(index, 0, SortRole);
-
- m_proxy->sort(0, Qt::AscendingOrder);
-}
-
-void SettingsDialog::moveUp()
-{
- QItemSelectionModel *selection = m_treeView->selectionModel();
-
- QModelIndex index = selection->currentIndex();
- QModelIndex prev = index.sibling(index.row() - 1, 0);
- m_proxy->setData(index, m_proxy->data(index, SortRole).toInt() - 1, SortRole);
- m_proxy->setData(prev, m_proxy->data(prev, SortRole).toInt() + 1, SortRole);
-
- m_proxy->sort(0, Qt::AscendingOrder);
-
- debug();
-}
-
-void SettingsDialog::moveDown()
-{
- QItemSelectionModel *selection = m_treeView->selectionModel();
-
- QModelIndex index = selection->currentIndex();
- QModelIndex prev = index.sibling(index.row() + 1, 0);
- m_proxy->setData(index, m_proxy->data(index, SortRole).toInt() + 1, SortRole);
- m_proxy->setData(prev, m_proxy->data(prev, SortRole).toInt() - 1, SortRole);
-
- m_proxy->sort(0, Qt::AscendingOrder);
-
- debug();
-}
-
-void SettingsDialog::moveBottom()
-{
- QItemSelectionModel *selection = m_treeView->selectionModel();
-
- QModelIndex index = selection->currentIndex();
- int r = index.row();
-
- for (int i = r + 1; i < m_proxy->rowCount(); i++) {
- m_proxy->setData(m_proxy->index(i, 0), i - 1, SortRole);
- }
-
- m_proxy->setData(index, m_proxy->rowCount() - 1, SortRole);
-
- m_proxy->sort(0, Qt::AscendingOrder);
-
- debug();
-}
-
-void SettingsDialog::load()
-{
- if (!m_accountsModel)
- return;
-
- KCModule::load();
-
- KSharedConfig::Ptr cfg = KSharedConfig::openConfig("krunnerrc");
- KConfigGroup grp = cfg->group("Runners");
- grp = KConfigGroup(&grp, "KTp Contact Runner");
-
- for (int i = 0; i < m_accountsModel->rowCount(); i++) {
- m_accountsModel->setData(m_accountsModel->index(i, 0), i, SortRole);
- }
- //QStringList s = grp.readEntry("preferences", QStringList());
-
- debug();
-}
-
-void SettingsDialog::save()
-{
- KCModule::save();
-}
-
-void SettingsDialog::defaults()
-{
- KCModule::defaults();
-}
-
-void SettingsDialog::debug()
-{
- for (int i = 0; i < m_accountsModel->rowCount(); i++) {
- qDebug() << m_accountsModel->data(m_accountsModel->index(i, 0), Qt::DisplayRole) << " - " << m_accountsModel->data(m_accountsModel->index(i, 0), SortRole);
- }
-}
diff --git a/src/settingsdialog.h b/src/settingsdialog.h
deleted file mode 100644
index b4ba730..0000000
--- a/src/settingsdialog.h
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- Copyright (C) 2012 Dan Vratil <dan at progdan.cz>
-
- 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
-*/
-
-
-#ifndef SETTINGSDIALOG_H
-#define SETTINGSDIALOG_H
-
-#include <QtGui/QWidget>
-#include <KConfigGroup>
-
-#include <TelepathyQt/AccountManager>
-#include <TelepathyQt/PendingOperation>
-
-#include <KTp/Models/accounts-model.h>
-
-#include <KCModule>
-
-class QTreeView;
-class QSortFilterProxyModel;
-class QAbstractItemModel;
-class KPushButton;
-
-namespace Ui {
- class SettingsDialog;
-}
-
-class SettingsDialog: public KCModule
-{
- Q_OBJECT
- public:
- explicit SettingsDialog(QWidget *parent = 0, const QVariantList& args = QVariantList());
- virtual ~SettingsDialog();
-
- public Q_SLOTS:
- void load();
- void save();
- void defaults();
-
- private Q_SLOTS:
- void moveTop();
- void moveUp();
- void moveDown();
- void moveBottom();
-
- void selectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
- void accountManagerReady(Tp::PendingOperation *);
-
- private:
- QTreeView *m_treeView;
- QSortFilterProxyModel *m_proxy;
- QAbstractItemModel *m_model;
-
- AccountsModel *m_accountsModel;
- Tp::AccountManagerPtr m_accountManager;
-
- KPushButton *m_topButton;
- KPushButton *m_upButton;
- KPushButton *m_downButton;
- KPushButton *m_bottomButton;
-
- void debug();
-};
-
-#endif // SETTINGSDIALOG_H
--
ktp-contact-runner packaging
More information about the pkg-kde-commits
mailing list