[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=90ee188
The following commit has been merged in the master branch:
commit 90ee1881b72245424a86bdf529f4bbc8dec3b282
Author: Dan Vrátil <dan at progdan.cz>
Date: Thu Aug 2 21:08:35 2012 +0200
Add syntax for changing global presence
REVIEW: 105407
---
src/contactrunner.cpp | 430 ++++++++++++++++++++----------
src/contactrunner.h | 14 +-
src/settingsdialog.cpp | 240 +++++++++++++++++
src/{contactrunner.h => settingsdialog.h} | 65 +++--
4 files changed, 574 insertions(+), 175 deletions(-)
diff --git a/src/contactrunner.cpp b/src/contactrunner.cpp
index 84da2fb..3dc15da 100644
--- a/src/contactrunner.cpp
+++ b/src/contactrunner.cpp
@@ -20,7 +20,6 @@
#include "contactrunner.h"
#include <KDebug>
-#include <KIcon>
#include <KFileDialog>
#include <KMimeType>
#include <KToolInvocation>
@@ -43,46 +42,66 @@
#include <KTp/Models/accounts-filter-model.h>
#include <KTp/Models/contact-model-item.h>
#include <KTp/presence.h>
+#include <KTp/global-presence.h>
-#include <QAction>
-
-struct ContactInfo {
+struct MatchInfo {
Tp::AccountPtr account;
Tp::ContactPtr contact;
+ KTp::Presence presence;
};
Q_DECLARE_METATYPE(QModelIndex);
-Q_DECLARE_METATYPE(ContactInfo);
+Q_DECLARE_METATYPE(MatchInfo);
ContactRunner::ContactRunner(QObject *parent, const QVariantList &args):
Plasma::AbstractRunner(parent, args),
- m_accountsModel(0)
+ m_accountsModel(new AccountsModel(this)),
+ m_globalPresence(new KTp::GlobalPresence(this))
{
Q_UNUSED(args);
- setObjectName("IM Contacts Runner");
-
- m_loggerDisabled = KStandardDirs::findExe("ktp-log-viewer").isEmpty();
+ setObjectName(QLatin1String("IM Contacts Runner"));
- 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.")));
+ m_loggerDisabled = KStandardDirs::findExe(QLatin1String("ktp-log-viewer")).isEmpty();
- if (!m_loggerDisabled)
- addSyntax(Plasma::RunnerSyntax("log :q:", i18n("Open the log viewer for :q:")));
+ 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.")));
+ if (!m_loggerDisabled) {
+ addSyntax(Plasma::RunnerSyntax(QLatin1String("log :q:"), i18n("Open the log viewer for :q:")));
+ }
- 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"));
+ 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"));
+ }
Tp::registerTypes();
Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
@@ -111,7 +130,7 @@ ContactRunner::ContactRunner(QObject *parent, const QVariantList &args):
ContactRunner::~ContactRunner()
{
- delete m_accountsModel;
+
}
void ContactRunner::accountManagerReady(Tp::PendingOperation *operation)
@@ -123,15 +142,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;
- ContactInfo data = match.data().value< ContactInfo >();
+ MatchInfo data = match.data().value< MatchInfo >();
if (!data.contact) {
return actions;
}
@@ -139,26 +158,27 @@ QList< QAction* > ContactRunner::actionsForMatch(const Plasma::QueryMatch &match
Tp::ContactCapabilities capabilities = data.contact->capabilities();
if (capabilities.textChats()) {
- actions.append(action("start-text-chat"));
+ actions.append(action(QLatin1String("start-text-chat")));
- if (!m_loggerDisabled)
- actions.append(action("show-log-viewer"));
+ if (!m_loggerDisabled) {
+ actions.append(action(QLatin1String("show-log-viewer")));
+ }
}
if (capabilities.audioCalls()) {
- actions.append(action("start-audio-call"));
+ actions.append(action(QLatin1String("start-audio-call")));
}
if (capabilities.videoCallsWithAudio()) {
- actions.append(action("start-video-call"));
+ actions.append(action(QLatin1String("start-video-call")));
}
if (capabilities.fileTransfers()) {
- actions.append(action("start-file-transfer"));
+ actions.append(action(QLatin1String("start-file-transfer")));
}
- if (capabilities.streamTubes("rfb")) {
- actions.append(action("start-desktop-sharing"));
+ if (capabilities.streamTubes(QLatin1String("rfb"))) {
+ actions.append(action(QLatin1String("start-desktop-sharing")));
}
return actions;
@@ -174,39 +194,170 @@ void ContactRunner::match(Plasma::RunnerContext &context)
return;
}
- if (!m_accountsModel || !m_accountManager->isReady()) {
+ 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";
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("start-text-chat");
+ defaultAction = action(QLatin1String("start-text-chat"));
filterFlag = AccountsFilterModel::FilterByTextChatCapability;
- contactQuery = term.mid(5).trimmed();
+ contactQuery = term.mid(QString("chat").length()).trimmed();
} else if (term.startsWith(QLatin1String("audiocall "), Qt::CaseInsensitive)) {
- defaultAction = action("start-audio-call");
+ defaultAction = action(QLatin1String("start-audio-call"));
filterFlag = AccountsFilterModel::FilterByAudioCallCapability;
- contactQuery = term.mid(10).trimmed();
+ contactQuery = term.mid(QString("audiocall").length()).trimmed();
} else if (term.startsWith(QLatin1String("videocall "), Qt::CaseInsensitive)) {
- defaultAction = action("start-video-call");
+ defaultAction = action(QLatin1String("start-video-call"));
filterFlag = AccountsFilterModel::FilterByVideoCallCapability;
- contactQuery = term.mid(10).trimmed();
+ contactQuery = term.mid(QString("videocall").length()).trimmed();
} else if (term.startsWith(QLatin1String("sendfile "), Qt::CaseInsensitive)) {
- defaultAction = action("start-file-transfer");
+ defaultAction = action(QLatin1String("start-file-transfer"));
filterFlag = AccountsFilterModel::FilterByFileTransferCapability;
- contactQuery = term.mid(9).trimmed();
+ contactQuery = term.mid(QString("sendfile").length()).trimmed();
} else if (term.startsWith(QLatin1String("sharedesktop "), Qt::CaseInsensitive)) {
- defaultAction = action("start-desktop-sharing");
+ defaultAction = action(QLatin1String("start-desktop-sharing"));
filterFlag = AccountsFilterModel::FilterByDesktopSharingCapability;
- contactQuery = term.mid(13).trimmed();
+ contactQuery = term.mid(QString("sharedesktop").length()).trimmed();
} else if (term.startsWith(QLatin1String("log "), Qt::CaseInsensitive)) {
- defaultAction = action("show-log-viewer");
+ defaultAction = action(QLatin1String("show-log-viewer"));
filterFlag = AccountsFilterModel::DoNotFilterByCapability;
- contactQuery = term.mid(4).trimmed();
+ contactQuery = term.mid(QString("log").length()).trimmed();
} else {
- defaultAction = action("start-text-chat");
+ defaultAction = action(QLatin1String("start-text-chat"));
filterFlag = AccountsFilterModel::DoNotFilterByCapability;
contactQuery = term;
}
@@ -241,40 +392,33 @@ void ContactRunner::match(Plasma::RunnerContext &context)
/* Store AccountsModelItem and ContactsModelItem as the data of match so that it can
* be retrieved quickly later */
- ContactInfo data;
+ MatchInfo 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.append(" (%1)").arg(accountIndex.data(AccountsModel::DisplayNameRole).toString()));
+ match.setText(name + QLatin1String(" (") + 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;
}
@@ -283,11 +427,11 @@ void ContactRunner::match(Plasma::RunnerContext &context)
if (!iconFile.isEmpty() && QFile::exists(iconFile)) {
match.setIcon(QIcon(iconFile));
} else {
- match.setIcon(QIcon::fromTheme(iconName));
+ match.setIcon(presence.icon());
}
if (!presence.statusMessage().isEmpty()) {
- match.setSubtext(presence.displayString() + " | " + presence.statusMessage());
+ match.setSubtext(presence.displayString() + QLatin1String(" | ") + presence.statusMessage());
} else {
match.setSubtext(presence.displayString());
}
@@ -300,113 +444,105 @@ void ContactRunner::match(Plasma::RunnerContext &context)
}
}
-void ContactRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
+void ContactRunner::matchPresence(Plasma::RunnerContext &context)
{
- Q_UNUSED(context)
+ 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");
- ContactInfo data = match.data().value< ContactInfo >();
- if (!data.account || !data.contact) {
- kWarning() << "Running invalid contact info";
+ QString term = context.query().trimmed();
+
+ if (!term.startsWith(imKeyword) && !term.startsWith(statusKeyword) &&
+ (term != connectCommand) && (term != disconnectCommand)) {
return;
}
- 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;
- }
-
- 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");
+ /* 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;
}
+ }
- } 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", "online").contains(presenceString, Qt::CaseInsensitive) || (term == connectCommand)) {
+ addPresenceMatch(context, Tp::ConnectionPresenceTypeAvailable, statusMessage);
}
-}
-bool ContactRunner::hasCapability(const QModelIndex &contact, AccountsFilterModel::CapabilityFilterFlag capability) const
-{
- if (capability == AccountsFilterModel::DoNotFilterByCapability) {
- return true;
+ if (all || i18nc("IM presence", "away").contains(presenceString, Qt::CaseInsensitive)) {
+ addPresenceMatch(context, Tp::ConnectionPresenceTypeAway, statusMessage);
}
- if ((capability == AccountsFilterModel::FilterByTextChatCapability) &&
- contact.data(AccountsModel::TextChatCapabilityRole).toBool()) {
- return true;
+ if (all || i18nc("IM presence","busy").contains(presenceString, Qt::CaseInsensitive)) {
+ addPresenceMatch(context, Tp::ConnectionPresenceTypeBusy, statusMessage);
}
- if ((capability == AccountsFilterModel::FilterByAudioCallCapability) &&
- contact.data(AccountsModel::AudioCallCapabilityRole).toBool()) {
- return true;
+ if (all || i18nc("IM presence","hidden").contains(presenceString, Qt::CaseInsensitive)) {
+ addPresenceMatch(context, Tp::ConnectionPresenceTypeHidden, statusMessage);
}
- if ((capability == AccountsFilterModel::FilterByVideoCallCapability) &&
- contact.data(AccountsModel::VideoCallCapabilityRole).toBool()) {
- return true;
+ if (all || i18nc("IM presence","offline").contains(presenceString, Qt::CaseInsensitive) || (term == disconnectCommand)) {
+ addPresenceMatch(context, Tp::ConnectionPresenceTypeOffline, statusMessage);
}
+}
- if ((capability == AccountsFilterModel::FilterByFileTransferCapability) &&
- contact.data(AccountsModel::FileTransferCapabilityRole).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::FilterByDesktopSharingCapability) &&
- contact.data(AccountsModel::DesktopSharingCapabilityRole).toBool()) {
- return true;
+ if (!statusMessage.isEmpty()) {
+ match.setSubtext(i18n("Status message: %1", statusMessage));
+ data.presence.setStatusMessage(statusMessage);
}
- return false;
-}
+ match.setData(qVariantFromValue(data));
+ context.addMatch(context.query(), match);
+}
#include "contactrunner.moc"
diff --git a/src/contactrunner.h b/src/contactrunner.h
index 54e151a..55e7e9d 100644
--- a/src/contactrunner.h
+++ b/src/contactrunner.h
@@ -31,12 +31,17 @@
#include <TelepathyQt/AccountManager>
-class QAction;
+namespace KTp
+{
+ class GlobalPresence;
+}
namespace Tp {
class PendingOperation;
}
+class QAction;
+
class ContactRunner : public Plasma::AbstractRunner
{
Q_OBJECT
@@ -57,7 +62,14 @@ 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
new file mode 100644
index 0000000..8590088
--- /dev/null
+++ b/src/settingsdialog.cpp
@@ -0,0 +1,240 @@
+/*
+ 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/contactrunner.h b/src/settingsdialog.h
similarity index 50%
copy from src/contactrunner.h
copy to src/settingsdialog.h
index 54e151a..b4ba730 100644
--- a/src/contactrunner.h
+++ b/src/settingsdialog.h
@@ -1,5 +1,4 @@
/*
- KTp Contact Runner
Copyright (C) 2012 Dan Vratil <dan at progdan.cz>
This library is free software; you can redistribute it and/or
@@ -17,52 +16,64 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef KTPCONTACTRUNNER_H
-#define KTPCONTACTRUNNER_H
-#include <QtCore/QModelIndex>
+#ifndef SETTINGSDIALOG_H
+#define SETTINGSDIALOG_H
-#include <Plasma/AbstractRunner>
-#include <KIcon>
+#include <QtGui/QWidget>
+#include <KConfigGroup>
+
+#include <TelepathyQt/AccountManager>
+#include <TelepathyQt/PendingOperation>
#include <KTp/Models/accounts-model.h>
-#include <KTp/Models/groups-model.h>
-#include <KTp/Models/accounts-filter-model.h>
-#include <TelepathyQt/AccountManager>
+#include <KCModule>
-class QAction;
+class QTreeView;
+class QSortFilterProxyModel;
+class QAbstractItemModel;
+class KPushButton;
-namespace Tp {
- class PendingOperation;
+namespace Ui {
+ class SettingsDialog;
}
-class ContactRunner : public Plasma::AbstractRunner
+class SettingsDialog: public KCModule
{
Q_OBJECT
-
public:
- ContactRunner( QObject *parent, const QVariantList& args );
- ~ContactRunner();
+ explicit SettingsDialog(QWidget *parent = 0, const QVariantList& args = QVariantList());
+ virtual ~SettingsDialog();
- void match(Plasma::RunnerContext &context);
- void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match);
-
- protected:
- QList< QAction* > actionsForMatch(const Plasma::QueryMatch &match);
+ public Q_SLOTS:
+ void load();
+ void save();
+ void defaults();
private Q_SLOTS:
- void accountManagerReady(Tp::PendingOperation *operation);
+ void moveTop();
+ void moveUp();
+ void moveDown();
+ void moveBottom();
+
+ void selectionChanged(const QModelIndex ¤t, const QModelIndex &previous);
+ void accountManagerReady(Tp::PendingOperation *);
private:
- bool hasCapability(const QModelIndex &contact, AccountsFilterModel::CapabilityFilterFlag capability) const;
+ QTreeView *m_treeView;
+ QSortFilterProxyModel *m_proxy;
+ QAbstractItemModel *m_model;
AccountsModel *m_accountsModel;
Tp::AccountManagerPtr m_accountManager;
- bool m_loggerDisabled;
-};
+ KPushButton *m_topButton;
+ KPushButton *m_upButton;
+ KPushButton *m_downButton;
+ KPushButton *m_bottomButton;
-K_EXPORT_PLASMA_RUNNER(ktp_contacts, ContactRunner)
+ void debug();
+};
-#endif /* KTPCONTACTRUNNER_H */
+#endif // SETTINGSDIALOG_H
--
ktp-contact-runner packaging
More information about the pkg-kde-commits
mailing list