mirror of
https://github.com/KDE/krfb
synced 2026-07-01 07:41:17 -07:00
Show KDE Telepathy contacts if available
Optional dependency on KTP. If available contacts with rfb capability shown in list view.
This commit is contained in:
@@ -26,9 +26,18 @@ if(NOT INSIDE_KDENETWORK)
|
||||
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
|
||||
endif(NOT INSIDE_KDENETWORK)
|
||||
|
||||
set(IS_KTP_INTERNAL_MODULE TRUE)
|
||||
set(CMAKE_MODULE_PATH
|
||||
"${CMAKE_CURRENT_SOURCE_DIR}/cmake/modules"
|
||||
${CMAKE_MODULE_PATH}
|
||||
)
|
||||
|
||||
macro_optional_find_package(TelepathyQt4)
|
||||
macro_log_feature(TelepathyQt4_FOUND "telepathy-qt" "Telepathy Qt Bindings" "http://telepathy.freedesktop.org" FALSE "0.9" "Needed to build Telepathy Tubes support.")
|
||||
|
||||
macro_optional_find_package(KTp)
|
||||
macro_log_feature(KTP_FOUND "KTP" "KDE Telepathy" "https://projects.kde.org/projects/extragear/network/telepathy" FALSE "" "Needed to build KDE IM Contacts Display in KRFB.")
|
||||
|
||||
macro_bool_to_01(X11_Xdamage_FOUND HAVE_XDAMAGE)
|
||||
macro_bool_to_01(X11_XShm_FOUND HAVE_XSHM)
|
||||
|
||||
|
||||
38
cmake/modules/FindKTp.cmake
Normal file
38
cmake/modules/FindKTp.cmake
Normal file
@@ -0,0 +1,38 @@
|
||||
# Try to find the KTp library
|
||||
# KTP_FOUND
|
||||
# KTP_INCLUDE_DIR
|
||||
# KTP_LIBRARIES
|
||||
# KTP_MODELS_LIBRARIES
|
||||
# KTP_WIDGETS_LIBRARIES
|
||||
|
||||
# Copyright (c) 2011, Dario Freddi <drf@kde.org>
|
||||
#
|
||||
# Redistribution and use is allowed according to the terms of the BSD license.
|
||||
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
|
||||
|
||||
if (NOT IS_KTP_INTERNAL_MODULE)
|
||||
message (FATAL_ERROR "KTp can be used just from internal components at this time")
|
||||
endif (NOT IS_KTP_INTERNAL_MODULE)
|
||||
|
||||
SET (KTP_FIND_REQUIRED ${KTp_FIND_REQUIRED})
|
||||
if (KTP_INCLUDE_DIRS AND KTP_LIBRARIES)
|
||||
# Already in cache, be silent
|
||||
set(KTP_FIND_QUIETLY TRUE)
|
||||
endif (KTP_INCLUDE_DIRS AND KTP_LIBRARIES)
|
||||
|
||||
find_path(KTP_INCLUDE_DIR
|
||||
NAMES KTp/presence.h
|
||||
PATHS ${KDE4_INCLUDE_DIR}
|
||||
)
|
||||
|
||||
find_library(KTP_LIBRARIES NAMES ktpcommoninternalsprivate )
|
||||
find_library(KTP_MODELS_LIBRARIES NAMES ktpmodelsprivate )
|
||||
find_library(KTP_WIDGETS_LIBRARIES NAMES ktpwidgetsprivate )
|
||||
|
||||
include(FindPackageHandleStandardArgs)
|
||||
FIND_PACKAGE_HANDLE_STANDARD_ARGS(KTp DEFAULT_MSG
|
||||
KTP_LIBRARIES
|
||||
KTP_MODELS_LIBRARIES
|
||||
KTP_INCLUDE_DIR)
|
||||
|
||||
mark_as_advanced(KTP_INCLUDE_DIRS KTP_LIBRARIES)
|
||||
@@ -46,6 +46,11 @@ if(TelepathyQt4_FOUND)
|
||||
include_directories(${TELEPATHY_QT4_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
if(KTP_FOUND)
|
||||
add_definitions(-DKRFB_WITH_KDE_TELEPATHY)
|
||||
include_directories(${KTP_INCLUDE_DIR})
|
||||
endif()
|
||||
|
||||
set (krfb_SRCS
|
||||
connectiondialog.cpp
|
||||
events.cpp
|
||||
@@ -106,6 +111,14 @@ if(TelepathyQt4_FOUND)
|
||||
)
|
||||
endif()
|
||||
|
||||
if(KTP_FOUND)
|
||||
target_link_libraries(krfb
|
||||
${KTP_LIBRARIES}
|
||||
${KTP_MODELS_LIBRARIES}
|
||||
${KTP_WIDGETS_LIBRARIES}
|
||||
)
|
||||
endif()
|
||||
|
||||
if (X11_XTest_FOUND)
|
||||
target_link_libraries (krfb
|
||||
${X11_XTest_LIB}
|
||||
|
||||
@@ -29,6 +29,16 @@
|
||||
#include <QtGui/QWidget>
|
||||
#include <QtNetwork/QNetworkInterface>
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
#include "tubesrfbserver.h"
|
||||
#include <TelepathyQt/PendingReady>
|
||||
#include <TelepathyQt/PendingChannelRequest>
|
||||
#include <KTp/actions.h>
|
||||
#include <KTp/Widgets/contact-view-widget.h>
|
||||
#include <KTp/Models/contacts-list-model.h>
|
||||
#include <KTp/Models/contacts-filter-model.h>
|
||||
#endif
|
||||
|
||||
class TCP: public QWidget, public Ui::TCP
|
||||
{
|
||||
public:
|
||||
@@ -97,11 +107,39 @@ MainWindow::MainWindow(QWidget *parent)
|
||||
m_ui.passwordDisplayLabel->setText(
|
||||
InvitationsRfbServer::instance->desktopPassword());
|
||||
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
|
||||
m_contactViewWidget = new KTp::ContactViewWidget(
|
||||
TubesRfbServer::instance->contactsListModel(), this);
|
||||
|
||||
m_contactViewWidget->setEnabled(false);
|
||||
connect(m_ui.enableSharingCheckBox, SIGNAL(toggled(bool)),
|
||||
m_contactViewWidget, SLOT(setEnabled(bool)));
|
||||
m_contactViewWidget->setIconSize(QSize(32,32));
|
||||
m_contactViewWidget->setMaximumWidth(120);
|
||||
m_contactViewWidget->setMaximumHeight(300);
|
||||
m_contactViewWidget->contactFilterLineEdit()->setClickMessage(i18n("Search in Contacts..."));
|
||||
m_contactViewWidget->filter()->setPresenceTypeFilterFlags(KTp::ContactsFilterModel::ShowOnlyConnected);
|
||||
m_contactViewWidget->filter()->setTubesFilterStrings(QStringList("rfb"));
|
||||
m_contactViewWidget->filter()->setCapabilityFilterFlags(KTp::ContactsFilterModel::FilterByTubes);
|
||||
|
||||
m_ui.tpContactsLayout->addWidget(m_contactViewWidget);
|
||||
connect(m_contactViewWidget, SIGNAL(contactDoubleClicked(const Tp::AccountPtr &, const KTp::ContactPtr &)),
|
||||
this, SLOT(onContactDoubleClicked(const Tp::AccountPtr &, const KTp::ContactPtr &)));
|
||||
#endif
|
||||
|
||||
|
||||
KStandardAction::quit(QCoreApplication::instance(), SLOT(quit()), actionCollection());
|
||||
KStandardAction::preferences(this, SLOT(showConfiguration()), actionCollection());
|
||||
|
||||
setupGUI();
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
setFixedSize(QSize(720, 360));
|
||||
#else
|
||||
setFixedSize(QSize(600, 360));
|
||||
#endif
|
||||
|
||||
setAutoSaveSettings();
|
||||
}
|
||||
@@ -141,7 +179,6 @@ void MainWindow::editUnattendedPassword()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void MainWindow::toggleDesktopSharing(bool enable)
|
||||
{
|
||||
if(enable) {
|
||||
@@ -183,6 +220,25 @@ void MainWindow::aboutUnattendedMode()
|
||||
i18n("KDE Desktop Sharing"));
|
||||
}
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
|
||||
void MainWindow::onContactDoubleClicked(const Tp::AccountPtr &account, const KTp::ContactPtr &contact)
|
||||
{
|
||||
Tp::PendingOperation *op = KTp::Actions::startDesktopSharing(account, contact);
|
||||
connect(op, SIGNAL(finished(Tp::PendingOperation*)),
|
||||
this, SLOT(pendingDesktopShareFinished(Tp::PendingOperation*)));
|
||||
}
|
||||
|
||||
void MainWindow::pendingDesktopShareFinished(Tp::PendingOperation *operation)
|
||||
{
|
||||
if(operation->isError()) {
|
||||
KMessageBox::error(0,
|
||||
operation->errorName() + ": " + operation->errorMessage());
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void MainWindow::showConfiguration()
|
||||
{
|
||||
if (KConfigDialog::showDialog("settings")) {
|
||||
|
||||
@@ -15,6 +15,17 @@
|
||||
|
||||
#include <KXmlGuiWindow>
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
#include <KTp/contact.h>
|
||||
#include <TelepathyQt/PendingReady>
|
||||
namespace KTp {
|
||||
class ContactViewWidget;
|
||||
}
|
||||
namespace Tp {
|
||||
class PendingOperation;
|
||||
}
|
||||
#endif
|
||||
|
||||
class KLineEdit;
|
||||
|
||||
class MainWindow : public KXmlGuiWindow
|
||||
@@ -24,6 +35,7 @@ class MainWindow : public KXmlGuiWindow
|
||||
public:
|
||||
MainWindow(QWidget *parent = 0);
|
||||
~MainWindow();
|
||||
|
||||
public Q_SLOTS:
|
||||
void showConfiguration();
|
||||
|
||||
@@ -38,11 +50,19 @@ class MainWindow : public KXmlGuiWindow
|
||||
void passwordChanged(const QString&);
|
||||
void aboutConnectionAddress();
|
||||
void aboutUnattendedMode();
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
void onContactDoubleClicked(const Tp::AccountPtr &, const KTp::ContactPtr &);
|
||||
void pendingDesktopShareFinished(Tp::PendingOperation*);
|
||||
#endif
|
||||
|
||||
private:
|
||||
Ui::MainWidget m_ui;
|
||||
bool m_passwordEditable;
|
||||
KLineEdit *m_passwordLineEdit;
|
||||
};
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
KTp::ContactViewWidget *m_contactViewWidget;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -32,6 +32,13 @@
|
||||
#include <TelepathyQt/OutgoingStreamTubeChannel>
|
||||
#include <TelepathyQt/StreamTubeServer>
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
#include <TelepathyQt/AccountSet>
|
||||
#include <TelepathyQt/AccountManager>
|
||||
#include <TelepathyQt/PendingReady>
|
||||
#include <KTp/Models/contacts-list-model.h>
|
||||
#include <KTp/contact-factory.h>
|
||||
#endif
|
||||
|
||||
struct TubesRfbServer::Private
|
||||
{
|
||||
@@ -40,10 +47,16 @@ struct TubesRfbServer::Private
|
||||
QHash<quint16, PendingTubesRfbClient*> clientsPerPort;
|
||||
};
|
||||
|
||||
//static
|
||||
TubesRfbServer *TubesRfbServer::instance;
|
||||
|
||||
//static
|
||||
void TubesRfbServer::init()
|
||||
{
|
||||
new TubesRfbServer();
|
||||
instance = new TubesRfbServer;
|
||||
//RfbServerManager takes care of deletion
|
||||
|
||||
instance->startAndCheck();
|
||||
}
|
||||
|
||||
TubesRfbServer::TubesRfbServer(QObject *parent)
|
||||
@@ -56,14 +69,51 @@ TubesRfbServer::TubesRfbServer(QObject *parent)
|
||||
Tp::registerTypes();
|
||||
|
||||
Tp::AccountFactoryPtr accountFactory = Tp::AccountFactory::create(
|
||||
QDBusConnection::sessionBus(), Tp::Account::FeatureCore);
|
||||
QDBusConnection::sessionBus(),
|
||||
Tp::Features() << Tp::Account::FeatureCore
|
||||
<< Tp::Account::FeatureAvatar
|
||||
<< Tp::Account::FeatureCapabilities
|
||||
<< Tp::Account::FeatureProtocolInfo
|
||||
<< Tp::Account::FeatureProfile);
|
||||
|
||||
Tp::ConnectionFactoryPtr connectionFactory = Tp::ConnectionFactory::create(
|
||||
QDBusConnection::sessionBus(), Tp::Connection::FeatureCore);
|
||||
QDBusConnection::sessionBus(),
|
||||
Tp::Features() << Tp::Connection::FeatureCore
|
||||
<< Tp::Connection::FeatureSelfContact);
|
||||
|
||||
Tp::ChannelFactoryPtr channelFactory = Tp::ChannelFactory::create(
|
||||
QDBusConnection::sessionBus());
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
Tp::ContactFactoryPtr contactFactory = KTp::ContactFactory::create(
|
||||
Tp::Features() << Tp::Contact::FeatureAlias
|
||||
<<Tp::Contact::FeatureAvatarToken
|
||||
<<Tp::Contact::FeatureAvatarData
|
||||
<<Tp::Contact::FeatureSimplePresence
|
||||
<<Tp::Contact::FeatureCapabilities
|
||||
<<Tp::Contact::FeatureClientTypes);
|
||||
|
||||
m_accountManager = Tp::AccountManager::create(
|
||||
QDBusConnection::sessionBus(),
|
||||
accountFactory,
|
||||
connectionFactory,
|
||||
channelFactory,
|
||||
contactFactory);
|
||||
|
||||
d->stubeServer = Tp::StreamTubeServer::create(
|
||||
m_accountManager,
|
||||
QStringList() << QLatin1String("rfb"),
|
||||
QStringList(),
|
||||
QLatin1String("krfb_rfb_handler"),
|
||||
true);
|
||||
|
||||
connect(m_accountManager->becomeReady(),
|
||||
SIGNAL(finished(Tp::PendingOperation*)),
|
||||
this,
|
||||
SLOT(onAccountManagerReady()));
|
||||
|
||||
m_contactsListModel = new KTp::ContactsListModel(this);
|
||||
#else
|
||||
Tp::ContactFactoryPtr contactFactory = Tp::ContactFactory::create(
|
||||
Tp::Contact::FeatureAlias);
|
||||
|
||||
@@ -76,6 +126,7 @@ TubesRfbServer::TubesRfbServer(QObject *parent)
|
||||
connectionFactory,
|
||||
channelFactory,
|
||||
contactFactory);
|
||||
#endif //KRFB_WITH_KDE_TELEPATHY
|
||||
|
||||
connect(d->stubeServer.data(),
|
||||
SIGNAL(tubeRequested(Tp::AccountPtr,Tp::OutgoingStreamTubeChannelPtr,
|
||||
@@ -101,8 +152,6 @@ TubesRfbServer::TubesRfbServer(QObject *parent)
|
||||
// Listen only on the loopback network interface
|
||||
setListeningAddress("127.0.0.1");
|
||||
setPasswordRequired(false);
|
||||
|
||||
QTimer::singleShot(0, this, SLOT(startAndCheck()));
|
||||
}
|
||||
|
||||
TubesRfbServer::~TubesRfbServer()
|
||||
@@ -111,6 +160,13 @@ TubesRfbServer::~TubesRfbServer()
|
||||
delete d;
|
||||
}
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
KTp::ContactsListModel *TubesRfbServer::contactsListModel()
|
||||
{
|
||||
return m_contactsListModel;
|
||||
}
|
||||
#endif
|
||||
|
||||
void TubesRfbServer::startAndCheck()
|
||||
{
|
||||
if (!start()) {
|
||||
@@ -130,6 +186,7 @@ void TubesRfbServer::startAndCheck()
|
||||
//TODO listeningAddress() should be a QHostAddress
|
||||
d->stubeServer->exportTcpSocket(QHostAddress(QString::fromAscii(listeningAddress())),
|
||||
listeningPort());
|
||||
connect(qApp, SIGNAL(aboutToQuit()), this, SLOT(stop()));
|
||||
}
|
||||
|
||||
void TubesRfbServer::onTubeRequested()
|
||||
@@ -195,4 +252,11 @@ PendingRfbClient* TubesRfbServer::newClient(rfbClientPtr client)
|
||||
return c;
|
||||
}
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
void TubesRfbServer::onAccountManagerReady()
|
||||
{
|
||||
m_contactsListModel->setAccountManager(m_accountManager);
|
||||
}
|
||||
#endif
|
||||
|
||||
#include "tubesrfbserver.moc"
|
||||
|
||||
@@ -23,13 +23,23 @@
|
||||
#include <QtNetwork/QHostAddress>
|
||||
#include <TelepathyQt/Types>
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
namespace KTp {
|
||||
class ContactsListModel;
|
||||
}
|
||||
#endif
|
||||
|
||||
class TubesRfbServer : public RfbServer
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
static TubesRfbServer *instance;
|
||||
static void init();
|
||||
|
||||
virtual ~TubesRfbServer();
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
KTp::ContactsListModel *contactsListModel();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
TubesRfbServer(QObject *parent = 0);
|
||||
@@ -58,9 +68,19 @@ private Q_SLOTS:
|
||||
const QString &message,
|
||||
const Tp::OutgoingStreamTubeChannelPtr &tube);
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
void onAccountManagerReady();
|
||||
#endif
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
Private *const d;
|
||||
|
||||
#ifdef KRFB_WITH_KDE_TELEPATHY
|
||||
KTp::ContactsListModel *m_contactsListModel;
|
||||
Tp::AccountManagerPtr m_accountManager;
|
||||
#endif
|
||||
|
||||
};
|
||||
|
||||
#endif // TUBESRFBSERVER_H
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
</rect>
|
||||
</property>
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
|
||||
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
|
||||
<horstretch>0</horstretch>
|
||||
<verstretch>0</verstretch>
|
||||
</sizepolicy>
|
||||
@@ -24,7 +24,7 @@
|
||||
</property>
|
||||
<property name="maximumSize">
|
||||
<size>
|
||||
<width>600</width>
|
||||
<width>720</width>
|
||||
<height>340</height>
|
||||
</size>
|
||||
</property>
|
||||
@@ -344,6 +344,13 @@
|
||||
</item>
|
||||
</layout>
|
||||
</item>
|
||||
<item>
|
||||
<layout class="QVBoxLayout" name="tpContactsLayout">
|
||||
<property name="sizeConstraint">
|
||||
<enum>QLayout::SetMinAndMaxSize</enum>
|
||||
</property>
|
||||
</layout>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
|
||||
Reference in New Issue
Block a user