diff --git a/CMakeLists.txt b/CMakeLists.txt index 78c19b3f..4aa24dd3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/modules/FindKTp.cmake b/cmake/modules/FindKTp.cmake new file mode 100644 index 00000000..8facd12f --- /dev/null +++ b/cmake/modules/FindKTp.cmake @@ -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 +# +# 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) diff --git a/krfb/CMakeLists.txt b/krfb/CMakeLists.txt index 76300712..a65eea82 100644 --- a/krfb/CMakeLists.txt +++ b/krfb/CMakeLists.txt @@ -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} diff --git a/krfb/mainwindow.cpp b/krfb/mainwindow.cpp index 062fad1c..f50ab56b 100644 --- a/krfb/mainwindow.cpp +++ b/krfb/mainwindow.cpp @@ -29,6 +29,16 @@ #include #include +#ifdef KRFB_WITH_KDE_TELEPATHY +#include "tubesrfbserver.h" +#include +#include +#include +#include +#include +#include +#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")) { diff --git a/krfb/mainwindow.h b/krfb/mainwindow.h index 88439350..97b8a5a8 100644 --- a/krfb/mainwindow.h +++ b/krfb/mainwindow.h @@ -15,6 +15,17 @@ #include +#ifdef KRFB_WITH_KDE_TELEPATHY +#include +#include +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 diff --git a/krfb/tubesrfbserver.cpp b/krfb/tubesrfbserver.cpp index 575c3cd8..3fba846f 100644 --- a/krfb/tubesrfbserver.cpp +++ b/krfb/tubesrfbserver.cpp @@ -32,6 +32,13 @@ #include #include +#ifdef KRFB_WITH_KDE_TELEPATHY +#include +#include +#include +#include +#include +#endif struct TubesRfbServer::Private { @@ -40,10 +47,16 @@ struct TubesRfbServer::Private QHash 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 + <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" diff --git a/krfb/tubesrfbserver.h b/krfb/tubesrfbserver.h index 596636ca..5e57d73d 100644 --- a/krfb/tubesrfbserver.h +++ b/krfb/tubesrfbserver.h @@ -23,13 +23,23 @@ #include #include +#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 diff --git a/krfb/ui/mainwidget.ui b/krfb/ui/mainwidget.ui index 85a7c5f7..7be30b85 100644 --- a/krfb/ui/mainwidget.ui +++ b/krfb/ui/mainwidget.ui @@ -11,7 +11,7 @@ - + 0 0 @@ -24,7 +24,7 @@ - 600 + 720 340 @@ -344,6 +344,13 @@ + + + + QLayout::SetMinAndMaxSize + + +