[SCM] ktp-common-internals packaging branch, master, updated. debian/15.12.1-2-1839-gf0635e9
Maximiliano Curia
maxy at moszumanska.debian.org
Mon May 9 09:07:05 UTC 2016
Gitweb-URL: http://git.debian.org/?p=pkg-kde/applications/ktp-common-internals.git;a=commitdiff;h=b06c466
The following commit has been merged in the master branch:
commit b06c46676497e2b2634daa53b8654e23f46f7952
Author: Anant Kamath <kamathanant at gmail.com>
Date: Wed Sep 4 16:00:09 2013 +0530
Add startChatDialog to start chat with contact ids
---
KTp/Widgets/CMakeLists.txt | 3 +
KTp/Widgets/start-chat-dialog.cpp | 124 +++++++++++++++++++++
.../{add-contact-dialog.h => start-chat-dialog.h} | 20 ++--
...{add-contact-dialog.ui => start-chat-dialog.ui} | 4 +-
KTp/actions.cpp | 23 ++++
KTp/actions.h | 4 +
6 files changed, 165 insertions(+), 13 deletions(-)
diff --git a/KTp/Widgets/CMakeLists.txt b/KTp/Widgets/CMakeLists.txt
index f9bdc33..8c42029 100644
--- a/KTp/Widgets/CMakeLists.txt
+++ b/KTp/Widgets/CMakeLists.txt
@@ -10,6 +10,7 @@ set (ktp_widgets_private_SRCS
join-chat-room-dialog.cpp
notification-config-dialog.cpp
accounts-combo-box.cpp
+ start-chat-dialog.cpp
)
set (ktp_widgets_private_HDRS
@@ -19,11 +20,13 @@ set (ktp_widgets_private_HDRS
join-chat-room-dialog.h
notification-config-dialog.h
accounts-combo-box.h
+ start-chat-dialog.h
)
kde4_add_ui_files (ktp_widgets_private_SRCS
add-contact-dialog.ui
join-chat-room-dialog.ui
+ start-chat-dialog.ui
)
kde4_add_library (ktpwidgetsprivate SHARED
diff --git a/KTp/Widgets/start-chat-dialog.cpp b/KTp/Widgets/start-chat-dialog.cpp
new file mode 100644
index 0000000..083da50
--- /dev/null
+++ b/KTp/Widgets/start-chat-dialog.cpp
@@ -0,0 +1,124 @@
+/*
+ * Start chat dialog
+ *
+ * Copyright (C) 2013 Anant Kamath <kamathanant at gmail.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "start-chat-dialog.h"
+#include "ui_start-chat-dialog.h"
+
+#include <QObject>
+#include <QCloseEvent>
+
+#include <KMessageBox>
+#include <KPushButton>
+#include <KDebug>
+
+#include <TelepathyQt/AccountManager>
+#include <TelepathyQt/Account>
+#include <TelepathyQt/Connection>
+#include <TelepathyQt/PendingChannelRequest>
+#include <TelepathyQt/AccountSet>
+
+#include <KTp/actions.h>
+
+namespace KTp {
+
+struct KTP_NO_EXPORT StartChatDialog::Private
+{
+ Private() :
+ ui(new Ui::StartChatDialog),
+ acceptInProgress(false)
+ {}
+
+ Ui::StartChatDialog *ui;
+ bool acceptInProgress;
+};
+
+StartChatDialog::StartChatDialog(const Tp::AccountManagerPtr &accountManager, QWidget *parent) :
+ KDialog(parent),
+ d(new Private)
+{
+ setWindowTitle(i18n("Start a chat"));
+ setWindowIcon(QIcon::fromTheme(QLatin1String("telepathy-kde")));
+
+ QWidget *widget = new QWidget(this);
+ d->ui->setupUi(widget);
+ setMainWidget(widget);
+
+ d->ui->accountCombo->setAccountSet(accountManager->onlineAccounts());
+
+ d->ui->screenNameLineEdit->setFocus();
+}
+
+StartChatDialog::~StartChatDialog()
+{
+ delete d->ui;
+ delete d;
+}
+
+void StartChatDialog::accept()
+{
+ Tp::AccountPtr account = d->ui->accountCombo->currentAccount();
+ const QString contactIdentifier = d->ui->screenNameLineEdit->text();
+ if (account.isNull()) {
+ KMessageBox::sorry(this, i18n("No account selected."));
+ } else if (account->connection().isNull()) {
+ KMessageBox::sorry(this, i18n("The requested account has been disconnected "
+ "and so a chat could not be initiated."));
+ } else if (contactIdentifier.isEmpty()) {
+ KMessageBox::sorry(this, i18n("You did not specify the name of the contact to start a chat with."));
+ } else {
+ Tp::PendingChannelRequest *op = KTp::Actions::startChat(account, contactIdentifier, true);
+ connect(op, SIGNAL(finished(Tp::PendingOperation*)),
+ SLOT(_k_onStartChatFinished(Tp::PendingOperation*)));
+
+ setInProgress(true);
+ }
+}
+
+void StartChatDialog::closeEvent(QCloseEvent *e)
+{
+ // ignore close event if we are in the middle of an operation
+ if (!d->acceptInProgress) {
+ KDialog::closeEvent(e);
+ }
+}
+
+void StartChatDialog::_k_onStartChatFinished(Tp::PendingOperation *op)
+{
+ if (op->isError()) {
+ kWarning() << "Failed to start a text channel with the contact for the given identifier"
+ << op->errorName() << op->errorMessage();
+ KMessageBox::sorry(this, i18n("Failed to start a chat with the contact."));
+ setInProgress(false);
+ } else {
+ QDialog::accept();
+ }
+}
+
+void StartChatDialog::setInProgress(bool inProgress)
+{
+ d->acceptInProgress = inProgress;
+ mainWidget()->setEnabled(!inProgress);
+ button(KDialog::Ok)->setEnabled(!inProgress);
+ button(KDialog::Cancel)->setEnabled(!inProgress);
+}
+
+} //namespace KTp
+
+#include "start-chat-dialog.moc"
diff --git a/KTp/Widgets/add-contact-dialog.h b/KTp/Widgets/start-chat-dialog.h
similarity index 65%
copy from KTp/Widgets/add-contact-dialog.h
copy to KTp/Widgets/start-chat-dialog.h
index c12834a..2155b24 100644
--- a/KTp/Widgets/add-contact-dialog.h
+++ b/KTp/Widgets/start-chat-dialog.h
@@ -1,8 +1,7 @@
/*
- * Add contact dialog
+ * Start chat dialog
*
- * Copyright (C) 2011 David Edmundson <kde at davidedmundson.co.uk>
- * Copyright (C) 2012 George Kiagiadakis <kiagiadakis.george at gmail.com>
+ * Copyright (C) 2013 Anant Kamath <kamathanant at gmail.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
@@ -19,8 +18,8 @@
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-#ifndef ADDCONTACTDIALOG_H
-#define ADDCONTACTDIALOG_H
+#ifndef STARTCHATDIALOG_H
+#define STARTCHATDIALOG_H
#include <KDialog>
@@ -34,13 +33,13 @@ namespace Tp {
namespace KTp
{
-class KTP_EXPORT AddContactDialog : public KDialog
+class KTP_EXPORT StartChatDialog : public KDialog
{
Q_OBJECT
public:
- explicit AddContactDialog(const Tp::AccountManagerPtr &accountManager, QWidget *parent = 0);
- virtual ~AddContactDialog();
+ explicit StartChatDialog(const Tp::AccountManagerPtr &accountManager, QWidget *parent = 0);
+ virtual ~StartChatDialog();
virtual void accept();
@@ -48,8 +47,7 @@ protected:
virtual void closeEvent(QCloseEvent *e);
private Q_SLOTS:
- KTP_NO_EXPORT void _k_onContactsForIdentifiersFinished(Tp::PendingOperation *op);
- KTP_NO_EXPORT void _k_onRequestPresenceSubscriptionFinished(Tp::PendingOperation *op);
+ KTP_NO_EXPORT void _k_onStartChatFinished(Tp::PendingOperation *op);
private:
KTP_NO_EXPORT void setInProgress(bool inProgress);
@@ -59,4 +57,4 @@ private:
};
}
-#endif // ADDCONTACTDIALOG_H
+#endif // STARTCHATDIALOG_H
diff --git a/KTp/Widgets/add-contact-dialog.ui b/KTp/Widgets/start-chat-dialog.ui
similarity index 93%
copy from KTp/Widgets/add-contact-dialog.ui
copy to KTp/Widgets/start-chat-dialog.ui
index f3ba71a..213479f 100644
--- a/KTp/Widgets/add-contact-dialog.ui
+++ b/KTp/Widgets/start-chat-dialog.ui
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
- <class>AddContactDialog</class>
- <widget class="QWidget" name="AddContactDialog">
+ <class>StartChatDialog</class>
+ <widget class="QWidget" name="StartChatDialog">
<property name="geometry">
<rect>
<x>0</x>
diff --git a/KTp/actions.cpp b/KTp/actions.cpp
index f410183..15d284a 100644
--- a/KTp/actions.cpp
+++ b/KTp/actions.cpp
@@ -38,6 +38,29 @@
using namespace KTp;
Tp::PendingChannelRequest* Actions::startChat(const Tp::AccountPtr &account,
+ const QString &contactIdentifier,
+ bool delegateToPreferredHandler)
+{
+ if (account.isNull() || contactIdentifier.isEmpty()) {
+ kWarning() << "Parameters invalid";
+ }
+
+ kDebug() << "Requesting text channel for contact id: " << contactIdentifier;
+
+ Tp::ChannelRequestHints hints;
+ if (delegateToPreferredHandler) {
+ hints.setHint(QLatin1String("org.freedesktop.Telepathy.ChannelRequest"),
+ QLatin1String("DelegateToPreferredHandler"),
+ QVariant(true));
+ }
+
+ return account->ensureTextChat(contactIdentifier,
+ QDateTime::currentDateTime(),
+ PREFERRED_TEXT_CHAT_HANDLER,
+ hints);
+}
+
+Tp::PendingChannelRequest* Actions::startChat(const Tp::AccountPtr &account,
const Tp::ContactPtr &contact,
bool delegateToPreferredHandler)
{
diff --git a/KTp/actions.h b/KTp/actions.h
index 7cd12ac..4a2bd54 100644
--- a/KTp/actions.h
+++ b/KTp/actions.h
@@ -36,6 +36,10 @@ namespace Actions {
typedef QList<KUrl> DocumentList;
KTP_EXPORT Tp::PendingChannelRequest* startChat(const Tp::AccountPtr &account,
+ const QString &contactIdentifier,
+ bool delegateToPreferredHandler = true);
+
+ KTP_EXPORT Tp::PendingChannelRequest* startChat(const Tp::AccountPtr &account,
const Tp::ContactPtr &contact,
bool delegateToPreferredHandler = true);
--
ktp-common-internals packaging
More information about the pkg-kde-commits
mailing list