Commit 5341ae8c authored by Alex Merry's avatar Alex Merry

Port to KDE Frameworks 5

parent b2419952
project(kdnssd)
cmake_minimum_required(VERSION 2.8.12)
if(NOT INSIDE_KDENETWORK)
message("Not building inside KDENetwork, loading KDE CMake Macros.")
project(kdnssd)
find_package(KDE4 REQUIRED)
find_package(ECM 0.0.10 REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR})
include(KDE4Defaults)
include(MacroLibrary)
include(KDEInstallDirs)
include(KDECompilerSettings)
include(KDECMakeSettings)
include(CheckIncludeFile)
include(CheckIncludeFiles)
include(CheckSymbolExists)
include(CheckFunctionExists)
include(CheckLibraryExists)
include(CheckPrototypeExists)
include(CheckTypeSize)
include(FeatureSummary)
set(CMAKE_REQUIRED_DEFINITIONS ${_KDE4_PLATFORM_DEFINITIONS})
if(WIN32)
set(CMAKE_REQUIRED_LIBRARIES ${KDEWIN32_LIBRARIES})
set(CMAKE_REQUIRED_INCLUDES ${KDEWIN32_INCLUDES})
endif(WIN32)
add_definitions(${QT_DEFINITIONS} ${QT_QTDBUS_DEFINITIONS} ${KDE4_DEFINITIONS})
add_definitions(-DQT_USE_FAST_CONCATENATION -DQT_USE_FAST_OPERATOR_PLUS)
include_directories(${CMAKE_SOURCE_DIR} ${CMAKE_BINARY_DIR} ${KDE4_INCLUDES})
endif(NOT INSIDE_KDENETWORK)
find_package(KF5 COMPONENTS DBusAddons DNSSD I18n KIO)
add_subdirectory( ioslave )
add_subdirectory( kdedmodule )
add_subdirectory(ioslave)
add_subdirectory(kdedmodule)
if (NOT INSIDE_KDENETWORK)
macro_display_feature_log()
endif ()
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
########### next target ###############
set(kio_zeroconf_PART_SRCS dnssd.cpp )
kde4_add_plugin(kio_zeroconf ${kio_zeroconf_PART_SRCS})
target_link_libraries(kio_zeroconf ${KDE4_KIO_LIBS} ${KDE4_KDNSSD_LIBS} )
install(TARGETS kio_zeroconf DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES zeroconf.protocol DESTINATION ${SERVICES_INSTALL_DIR})
install( FILES zeroconf.desktop DESTINATION ${DATA_INSTALL_DIR}/remoteview)
add_library(kio_zeroconf MODULE dnssd.cpp)
target_link_libraries(kio_zeroconf PRIVATE
KF5::DNSSD
KF5::I18n
KF5::KIOCore
)
install(TARGETS kio_zeroconf
DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES zeroconf.protocol
DESTINATION ${SERVICES_INSTALL_DIR})
install(FILES zeroconf.desktop
DESTINATION ${DATA_INSTALL_DIR}/remoteview)
......@@ -23,21 +23,21 @@
// io-slave
#include "zeroconfurl.h"
// KDE
#include <KComponentData>
#include <KProtocolInfo>
// Qt
#include <QtCore/QCoreApplication>
#include <QCoreApplication>
#include <qplatformdefs.h> // S_IFDIR
void ProtocolData::feedUrl( KUrl* url, const RemoteService* remoteService ) const
void ProtocolData::feedUrl( QUrl* url, const RemoteService* remoteService ) const
{
const QMap<QString,QByteArray> serviceTextData = remoteService->textData();
url->setProtocol( protocol );
url->setScheme( protocol );
if (!userEntry.isNull())
url->setUser( serviceTextData[userEntry] );
url->setUserName( serviceTextData[userEntry] );
if (!passwordEntry.isNull())
url->setPass( serviceTextData[passwordEntry] );
url->setPassword( serviceTextData[passwordEntry] );
if (!pathEntry.isNull())
url->setPath( serviceTextData[pathEntry] );
......@@ -62,7 +62,7 @@ ZeroConfProtocol::~ZeroConfProtocol()
delete serviceToResolve;
}
void ZeroConfProtocol::get( const KUrl& url )
void ZeroConfProtocol::get( const QUrl& url )
{
if (!dnssdOK())
return;
......@@ -73,15 +73,15 @@ void ZeroConfProtocol::get( const KUrl& url )
if (type==ZeroConfUrl::Service)
resolveAndRedirect( zeroConfUrl );
else
error( ERR_MALFORMED_URL, url.prettyUrl() );
error( ERR_MALFORMED_URL, url.toDisplayString() );
}
void ZeroConfProtocol::mimetype( const KUrl& url )
void ZeroConfProtocol::mimetype( const QUrl& url )
{
resolveAndRedirect( ZeroConfUrl(url) );
}
void ZeroConfProtocol::stat( const KUrl& url )
void ZeroConfProtocol::stat( const QUrl& url )
{
if (!dnssdOK())
return;
......@@ -105,11 +105,11 @@ void ZeroConfProtocol::stat( const KUrl& url )
resolveAndRedirect( zeroConfUrl );
break;
default:
error( ERR_MALFORMED_URL, url.prettyUrl() );
error( ERR_MALFORMED_URL, url.toDisplayString() );
}
}
void ZeroConfProtocol::listDir( const KUrl& url )
void ZeroConfProtocol::listDir( const QUrl& url )
{
if (!dnssdOK())
return;
......@@ -134,8 +134,8 @@ void ZeroConfProtocol::listDir( const KUrl& url )
break;
}
serviceBrowser = new ServiceBrowser( zeroConfUrl.serviceType(), false, zeroConfUrl.domain() );
connect( serviceBrowser, SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),
SLOT(addService(DNSSD::RemoteService::Ptr)) );
connect( serviceBrowser, SIGNAL(serviceAdded(KDNSSD::RemoteService::Ptr)),
SLOT(addService(KDNSSD::RemoteService::Ptr)) );
connect( serviceBrowser, SIGNAL(finished()), SLOT(onBrowserFinished()) );
serviceBrowser->startBrowse();
enterLoop();
......@@ -144,7 +144,7 @@ void ZeroConfProtocol::listDir( const KUrl& url )
resolveAndRedirect( zeroConfUrl );
break;
default:
error( ERR_MALFORMED_URL, url.prettyUrl() );
error( ERR_MALFORMED_URL, url.toDisplayString() );
}
}
......@@ -199,7 +199,7 @@ void ZeroConfProtocol::resolveAndRedirect( const ZeroConfUrl& zeroConfUrl )
// action
const ProtocolData& protocolData = knownProtocols[zeroConfUrl.serviceType()];
KUrl destUrl;
QUrl destUrl;
protocolData.feedUrl( &destUrl, serviceToResolve );
redirection( destUrl );
......@@ -218,10 +218,10 @@ void ZeroConfProtocol::addServiceType( const QString& serviceType )
// action
UDSEntry entry;
feedEntryAsDir( &entry, serviceType, knownProtocols[serviceType].name );
listEntry( entry, false );
listEntry( entry );
}
void ZeroConfProtocol::addService( DNSSD::RemoteService::Ptr service )
void ZeroConfProtocol::addService( KDNSSD::RemoteService::Ptr service )
{
UDSEntry entry;
entry.insert( UDSEntry::UDS_NAME, service->serviceName() );
......@@ -231,13 +231,11 @@ void ZeroConfProtocol::addService( DNSSD::RemoteService::Ptr service )
if (!iconName.isNull())
entry.insert( UDSEntry::UDS_ICON_NAME, iconName );
listEntry( entry, false );
listEntry( entry );
}
void ZeroConfProtocol::onBrowserFinished()
{
UDSEntry entry;
listEntry( entry, true );
finished();
// cleanup
......@@ -274,17 +272,19 @@ void ZeroConfProtocol::enterLoop()
}
extern "C"
extern "C" Q_DECL_EXPORT int kdemain( int argc, char **argv )
{
int KDE_EXPORT kdemain( int argc, char **argv )
{
// necessary to use other kio slaves
KComponentData componentData("kio_zeroconf");
QCoreApplication app(argc,argv);
// start the slave
ZeroConfProtocol slave(argv[1],argv[2],argv[3]);
slave.dispatchLoop();
return 0;
// necessary to use other kio slaves
QCoreApplication app(argc,argv);
app.setApplicationName(QStringLiteral("kio_zeroconf"));
if (argc != 4) {
fprintf(stderr, "Usage: %s protocol domain-socket1 domain-socket2\n", argv[0]);
exit(-1);
}
// start the slave
ZeroConfProtocol slave(argv[1],argv[2],argv[3]);
slave.dispatchLoop();
return 0;
}
......@@ -23,15 +23,15 @@
// KDE
#include <DNSSD/ServiceBrowser>
#include <dnssd/servicetypebrowser.h> // missing CamelCase version, can be fixed beginning 02.02.09
#include <DNSSD/ServiceTypeBrowser>
#include <DNSSD/RemoteService>
#include <KIO/SlaveBase>
// Qt
#include <QtCore/QObject>
#include <QObject>
using namespace KIO;
using namespace DNSSD;
using namespace KDNSSD;
class ZeroConfUrl;
......@@ -43,7 +43,7 @@ struct ProtocolData
: name(_name), protocol(proto), pathEntry(path), userEntry(user), passwordEntry(passwd)
{}
void feedUrl( KUrl* url, const RemoteService* remoteService ) const;
void feedUrl( QUrl* url, const RemoteService* remoteService ) const;
QString name;
QString protocol;
......@@ -60,10 +60,10 @@ public:
virtual ~ZeroConfProtocol();
public: // KIO::SlaveBase API
virtual void get( const KUrl& url );
virtual void mimetype( const KUrl& url );
virtual void stat( const KUrl& url );
virtual void listDir( const KUrl& url );
virtual void get( const QUrl& url );
virtual void mimetype( const QUrl& url );
virtual void stat( const QUrl& url );
virtual void listDir( const QUrl& url );
Q_SIGNALS:
void leaveModality();
......@@ -80,7 +80,7 @@ private:
private Q_SLOTS:
void addServiceType( const QString& );
void addService( DNSSD::RemoteService::Ptr );
void addService( KDNSSD::RemoteService::Ptr );
void onBrowserFinished();
private: // data
......
......@@ -23,7 +23,7 @@
// KDE
#include <DNSSD/RemoteService>
#include <KUrl>
#include <QUrl>
// URL zeroconf:/_http._tcp/some%20service
......@@ -33,7 +33,7 @@ class ZeroConfUrl
enum Type { InvalidUrl, RootDir, ServiceDir, Service };
public:
explicit ZeroConfUrl( const KUrl& url );
explicit ZeroConfUrl( const QUrl& url );
public:
const QString& serviceType() const;
......@@ -49,7 +49,7 @@ class ZeroConfUrl
};
inline ZeroConfUrl::ZeroConfUrl( const KUrl& url )
inline ZeroConfUrl::ZeroConfUrl( const QUrl& url )
{
mServiceType = url.path().section('/',1,1);
mServiceName = url.path().section('/',2,-1);
......
########### next target ###############
set(kded_dnssdwatcher_PART_SRCS dnssdwatcher.cpp watcher.cpp )
qt4_add_dbus_adaptor( kded_dnssdwatcher_PART_SRCS org.kde.kdnssd.xml dnssdwatcher.h DNSSDWatcher )
kde4_add_plugin(kded_dnssdwatcher ${kded_dnssdwatcher_PART_SRCS})
target_link_libraries(kded_dnssdwatcher ${KDE4_KIO_LIBS} ${KDE4_KDNSSD_LIBS} )
install(TARGETS kded_dnssdwatcher DESTINATION ${PLUGIN_INSTALL_DIR})
########### install files ###############
install( FILES dnssdwatcher.desktop DESTINATION ${SERVICES_INSTALL_DIR}/kded)
install( FILES org.kde.kdnssd.xml DESTINATION ${DBUS_INTERFACES_INSTALL_DIR} )
set(kded_dnssdwatcher_PART_SRCS
dnssdwatcher.cpp
watcher.cpp
)
qt5_add_dbus_adaptor(kded_dnssdwatcher_PART_SRCS
org.kde.kdnssd.xml
dnssdwatcher.h
DNSSDWatcher)
add_library(kded_dnssdwatcher MODULE ${kded_dnssdwatcher_PART_SRCS})
target_link_libraries(kded_dnssdwatcher PRIVATE
KF5::DBusAddons
KF5::KIOCore
KF5::DNSSD
)
install(TARGETS kded_dnssdwatcher
DESTINATION ${PLUGIN_INSTALL_DIR})
install(FILES dnssdwatcher.desktop
DESTINATION ${SERVICES_INSTALL_DIR}/kded)
install(FILES org.kde.kdnssd.xml
DESTINATION ${DBUS_INTERFACES_INSTALL_DIR})
......@@ -18,18 +18,13 @@
#include "dnssdwatcher.h"
#include "kdnssdadaptor.h"
#include <kglobal.h>
#include <kurl.h>
#include "watcher.h"
#include <kpluginfactory.h>
#include <kpluginloader.h>
#include <KPluginFactory>
K_PLUGIN_FACTORY(DNSSDWatcherFactory,
registerPlugin<DNSSDWatcher>();
)
K_EXPORT_PLUGIN(DNSSDWatcherFactory("dnssdwatcher"))
DNSSDWatcher::DNSSDWatcher(QObject* parent, const QList<QVariant>&)
: KDEDModule(parent)
......@@ -48,7 +43,7 @@ QStringList DNSSDWatcher::watchedDirectories()
// from ioslave
void DNSSDWatcher::dissect(const KUrl& url,QString& name,QString& type)
void DNSSDWatcher::dissect(const QUrl& url,QString& name,QString& type)
{
type = url.path().section('/',1,1);
name = url.path().section('/',2,-1);
......@@ -58,8 +53,8 @@ void DNSSDWatcher::dissect(const KUrl& url,QString& name,QString& type)
void DNSSDWatcher::enteredDirectory(const QString& _dir)
{
KUrl dir(_dir);
if (dir.protocol() != QLatin1String("zeroconf")) {
QUrl dir(_dir);
if (dir.scheme() != QLatin1String("zeroconf")) {
return;
}
if (watchers.contains(dir.url())) {
......@@ -73,8 +68,8 @@ void DNSSDWatcher::enteredDirectory(const QString& _dir)
void DNSSDWatcher::leftDirectory(const QString& _dir)
{
KUrl dir(_dir);
if (dir.protocol() != QLatin1String("zeroconf")) {
QUrl dir(_dir);
if (dir.scheme() != QLatin1String("zeroconf")) {
return;
}
Watcher* watcher = watchers.value(dir.url());
......@@ -90,7 +85,7 @@ void DNSSDWatcher::leftDirectory(const QString& _dir)
}
void DNSSDWatcher::createNotifier(const KUrl& url)
void DNSSDWatcher::createNotifier(const QUrl& url)
{
QString type,name;
dissect(url,name,type);
......@@ -107,4 +102,4 @@ DNSSDWatcher::~DNSSDWatcher()
qDeleteAll( watchers );
}
#include "dnssdwatcher.moc"
#include <dnssdwatcher.moc>
......@@ -19,11 +19,12 @@
#ifndef _DNSSDWATCHER_H_
#define _DNSSDWATCHER_H_
#include <qhash.h>
#include <kdedmodule.h>
#include <QHash>
#include <QStringList>
#include <KDEDModule>
class Watcher;
class KUrl;
class QUrl;
class DNSSDWatcher : public KDEDModule
{
Q_OBJECT
......@@ -31,7 +32,7 @@ public:
DNSSDWatcher(QObject* parent, const QList<QVariant>&);
~DNSSDWatcher();
public slots:
public Q_SLOTS:
QStringList watchedDirectories();
void enteredDirectory(const QString& dir);
void leftDirectory(const QString& dir);
......@@ -39,8 +40,8 @@ public slots:
private:
QHash<QString, Watcher *> watchers;
void createNotifier(const KUrl& url);
void dissect(const KUrl& url,QString& name,QString& type);
void createNotifier(const QUrl& url);
void dissect(const QUrl& url,QString& name,QString& type);
};
......
......@@ -18,10 +18,11 @@
#include "watcher.h"
#include <kdirnotify.h>
#include <dnssd/remoteservice.h>
#include <dnssd/servicebrowser.h>
#include <dnssd/servicetypebrowser.h>
#include <KDirNotify>
#include <DNSSD/RemoteService>
#include <DNSSD/ServiceBrowser>
#include <DNSSD/ServiceTypeBrowser>
#include <QUrl>
Watcher::Watcher()
: refcount(1), updateNeeded(false)
......@@ -30,11 +31,11 @@ Watcher::Watcher()
ServiceWatcher::ServiceWatcher(const QString& type) : Watcher(), m_type(type)
{
browser = new DNSSD::ServiceBrowser(type);
browser = new KDNSSD::ServiceBrowser(type);
browser->setParent(this);
connect(browser,SIGNAL(serviceAdded(DNSSD::RemoteService::Ptr)),
connect(browser,SIGNAL(serviceAdded(KDNSSD::RemoteService::Ptr)),
SLOT(scheduleUpdate()));
connect(browser,SIGNAL(serviceRemoved(DNSSD::RemoteService::Ptr)),
connect(browser,SIGNAL(serviceRemoved(KDNSSD::RemoteService::Ptr)),
SLOT(scheduleUpdate()));
connect(browser,SIGNAL(finished()),SLOT(finished()));
browser->startBrowse();
......@@ -43,7 +44,7 @@ ServiceWatcher::ServiceWatcher(const QString& type) : Watcher(), m_type(type)
TypeWatcher::TypeWatcher() : Watcher()
{
typebrowser = new DNSSD::ServiceTypeBrowser();
typebrowser = new KDNSSD::ServiceTypeBrowser();
typebrowser->setParent(this);
connect(typebrowser,SIGNAL(serviceTypeAdded(QString)),
this,SLOT(scheduleUpdate()));
......@@ -53,14 +54,16 @@ TypeWatcher::TypeWatcher() : Watcher()
typebrowser->startBrowse();
}
QString TypeWatcher::constructUrl()
QUrl TypeWatcher::constructUrl() const
{
return QString("zeroconf:/");
return QUrl(QStringLiteral("zeroconf:/"));
}
QString ServiceWatcher::constructUrl()
QUrl ServiceWatcher::constructUrl() const
{
return QString("zeroconf:/")+m_type+'/';
QUrl url(QStringLiteral("zeroconf:/"));
url.setPath(m_type + '/');
return url;
}
void Watcher::scheduleUpdate()
......@@ -74,4 +77,3 @@ void Watcher::finished()
updateNeeded=false;
}
#include "watcher.moc"
......@@ -19,11 +19,11 @@
#ifndef _WATCHER_H_
#define _WATCHER_H_
#include <qobject.h>
#include <QObject>
class QString;
namespace DNSSD {
namespace KDNSSD {
class ServiceBrowser;
class ServiceTypeBrowser;
}
......@@ -36,11 +36,11 @@ public:
unsigned int refcount;
protected:
virtual QString constructUrl()=0;
virtual QUrl constructUrl() const = 0;
private:
bool updateNeeded;
private slots:
private Q_SLOTS:
void scheduleUpdate();
void finished();
};
......@@ -51,9 +51,9 @@ Q_OBJECT
public:
TypeWatcher();
protected:
virtual QString constructUrl();
QUrl constructUrl() const Q_DECL_OVERRIDE;
private:
DNSSD::ServiceTypeBrowser* typebrowser;
KDNSSD::ServiceTypeBrowser* typebrowser;
};
class ServiceWatcher : public Watcher
......@@ -62,9 +62,9 @@ Q_OBJECT
public:
ServiceWatcher(const QString& type);
protected:
virtual QString constructUrl();
QUrl constructUrl() const Q_DECL_OVERRIDE;
private:
DNSSD::ServiceBrowser* browser;
KDNSSD::ServiceBrowser* browser;
QString m_type;
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment