diff options
Diffstat (limited to 'kmrml/kmrml/lib')
-rw-r--r-- | kmrml/kmrml/lib/Makefile.am | 11 | ||||
-rw-r--r-- | kmrml/kmrml/lib/kmrml_config.cpp | 339 | ||||
-rw-r--r-- | kmrml/kmrml/lib/kmrml_config.h | 123 | ||||
-rw-r--r-- | kmrml/kmrml/lib/mrml_shared.cpp | 235 | ||||
-rw-r--r-- | kmrml/kmrml/lib/mrml_shared.h | 166 | ||||
-rw-r--r-- | kmrml/kmrml/lib/mrml_utils.cpp | 89 | ||||
-rw-r--r-- | kmrml/kmrml/lib/mrml_utils.h | 50 | ||||
-rw-r--r-- | kmrml/kmrml/lib/version.h | 6 | ||||
-rw-r--r-- | kmrml/kmrml/lib/watcher_stub.cpp | 95 | ||||
-rw-r--r-- | kmrml/kmrml/lib/watcher_stub.h | 36 |
10 files changed, 1150 insertions, 0 deletions
diff --git a/kmrml/kmrml/lib/Makefile.am b/kmrml/kmrml/lib/Makefile.am new file mode 100644 index 00000000..4201f04f --- /dev/null +++ b/kmrml/kmrml/lib/Makefile.am @@ -0,0 +1,11 @@ +noinst_LTLIBRARIES = libkmrmlstuff.la +libkmrmlstuff_la_SOURCES = kmrml_config.cpp mrml_shared.cpp mrml_utils.cpp\ +watcher_stub.cpp +noinst_HEADERS = kmrml_config.h mrml_shared.h mrml_utils.h watcher_stub.h + +METASOURCES = AUTO + +libkmrmlstuff_la_LDFLAGS = $(all_libraries) -no-undefined +libkmrmlstuff_la_LIBADD = $(LIB_KDECORE) + +INCLUDES = -I$(top_srcdir) $(all_includes) diff --git a/kmrml/kmrml/lib/kmrml_config.cpp b/kmrml/kmrml/lib/kmrml_config.cpp new file mode 100644 index 00000000..a88e8404 --- /dev/null +++ b/kmrml/kmrml/lib/kmrml_config.cpp @@ -0,0 +1,339 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <qdir.h> +#include <qfile.h> +#include <qtextcodec.h> + +#include <kconfig.h> +#include <kdebug.h> +#include <kglobal.h> +#include <kprocess.h> +#include <kstandarddirs.h> + +#include "kmrml_config.h" + +#include <kdeversion.h> +#if KDE_VERSION < 307 + #define QUOTE( x ) x +#else + #define QUOTE( x ) KProcess::quote( x ) +#endif + +using namespace KMrml; + +// #define DEFAULT_ADDCOLLECTION_CMD "gift-add-collection.pl --thumbnail-dir=%t --local-encoding %d" +#define DEFAULT_ADDCOLLECTION_CMD "gift-add-collection.pl --gift-home=%h --thumbnail-dir=%t --local-encoding=%e %d" +#define DEFAULT_REMOVECOLLECTION_CMD "gift-add-collection.pl --gift-home=%h --local-encoding=%e --remove-collection %d" + +#define DEFAULT_MRMLD_CMD "gift --port %p --datadir %d" +#define DEFAULT_MRMLD_CMD_AUTOPORT "gift --datadir %d" + +#define CONFIG_GROUP "MRML Settings" +#define DEFAULT_HOST "localhost" +#define DEFAULT_USER "kmrml" +#define DEFAULT_PASS "none" +#define DEFAULT_AUTH false +#define DEFAULT_AUTOPORT true +const int DEFAULT_PORT = 12789; + +Config::Config() +{ + m_ownConfig = new KConfig( "kio_mrmlrc", false, false ); + m_config = m_ownConfig; + + init(); +} + +Config::Config( KConfig *config ) + : m_config( config ), + m_ownConfig( 0L ) +{ + init(); +} + +Config::~Config() +{ + delete m_ownConfig; +} + +void Config::init() +{ + m_config->setGroup( CONFIG_GROUP ); + m_defaultHost = m_config->readEntry( "Default Host" ); + if ( m_defaultHost.isEmpty() ) + m_defaultHost = DEFAULT_HOST; + + m_hostList = m_config->readListEntry( "Host List" ); + if ( m_hostList.isEmpty() ) + m_hostList.append( DEFAULT_HOST ); + + m_serverStartedIndividually = + m_config->readBoolEntry( "ServerStartedIndividually", false ); +} + +bool Config::sync() +{ + bool notifySlaves = m_config->isDirty(); + m_config->sync(); + return notifySlaves; + + // This moved to kcontrol/MainPage::save() so we don't have to link against + // KIO and need a full KApplication instance to work (so that the tiny + // mrmlsearch binary can also use this class) + // tell the ioslaves about the new configuration +// if ( notifySlaves ) +// KIO::SlaveConfig::self()->reset(); +} + +void Config::setDefaultHost( const QString& host ) +{ + m_defaultHost = host.isEmpty() ? + QString::fromLatin1(DEFAULT_HOST) : host; + + m_config->setGroup( CONFIG_GROUP ); + m_config->writeEntry( "Default Host", m_defaultHost ); +} + +ServerSettings Config::settingsForLocalHost() const +{ + return settingsForHost( "localhost" ); +} + +ServerSettings Config::settingsForHost( const QString& host ) const +{ + KConfigGroup config( m_config, settingsGroup( host ) ); + ServerSettings settings; + + settings.host = host; + settings.configuredPort = config.readUnsignedNumEntry( "Port", + DEFAULT_PORT ); + settings.autoPort = (host == "localhost") && + config.readBoolEntry("Automatically determine Port", + DEFAULT_AUTOPORT ); + settings.user = config.readEntry( "Username", DEFAULT_USER ); + settings.pass = config.readEntry( "Password", DEFAULT_PASS ); + settings.useAuth = config.readBoolEntry( "Perform Authentication", + DEFAULT_AUTH ); + + return settings; +} + +void Config::addSettings( const ServerSettings& settings ) +{ + QString host = settings.host; + if ( m_hostList.find( host ) == m_hostList.end() ) + m_hostList.append( host ); + + m_config->setGroup( CONFIG_GROUP ); + m_config->writeEntry( "Host List", m_hostList ); + + m_config->setGroup( settingsGroup( host ) ); + m_config->writeEntry( "Host", host ); + m_config->writeEntry( "Port", settings.configuredPort ); + m_config->writeEntry( "Automatically determine Port", settings.autoPort ); + m_config->writeEntry( "Username", settings.user ); + m_config->writeEntry( "Password", settings.pass ); + m_config->writeEntry( "Perform Authentication", settings.useAuth ); +} + +bool Config::removeSettings( const QString& host ) +{ + bool success = m_config->deleteGroup( settingsGroup( host ) ); + if ( success ) + { + m_hostList.remove( host ); + m_config->setGroup( CONFIG_GROUP ); + } + + return success; +} + +QStringList Config::indexableDirectories() const +{ + m_config->setGroup( CONFIG_GROUP ); + return m_config->readListEntry( "Indexable Directories" ); +} + +void Config::setIndexableDirectories( const QStringList& dirs ) +{ + m_config->setGroup( CONFIG_GROUP ); + m_config->writeEntry( "Indexable Directories", dirs ); +} + +QString Config::addCollectionCommandLine() const +{ + m_config->setGroup( CONFIG_GROUP ); + QString cmd = m_config->readEntry( "AddCollection Commandline", + DEFAULT_ADDCOLLECTION_CMD ); + int index = cmd.find( "%h" ); + if ( index != -1 ) + cmd.replace( index, 2, QUOTE( mrmldDataDir() ) ); + + index = cmd.find( "%e" ); + if ( index != -1 ) + cmd.replace( index, 2, QTextCodec::codecForLocale()->mimeName() ); + + return cmd; +} + +void Config::setAddCollectionCommandLine( const QString& cmd ) +{ + m_config->setGroup( CONFIG_GROUP ); + m_config->writeEntry( "AddCollection Commandline", cmd ); +} + +QString Config::removeCollectionCommandLine() const +{ + m_config->setGroup( CONFIG_GROUP ); + QString cmd = m_config->readEntry( "RemoveCollection Commandline", + DEFAULT_REMOVECOLLECTION_CMD ); + int index = cmd.find( "%h" ); + if ( index != -1 ) + cmd.replace( index, 2, QUOTE( mrmldDataDir() ) ); + + index = cmd.find( "%e" ); + if ( index != -1 ) + cmd.replace( index, 2, QTextCodec::codecForLocale()->mimeName() ); + + return cmd; +} + +void Config::setRemoveCollectionCommandLine( const QString& cmd ) +{ + m_config->setGroup( CONFIG_GROUP ); + m_config->writeEntry( "RemoveCollection Commandline", cmd ); +} + +QString Config::mrmldCommandline() const +{ + ServerSettings settings = settingsForLocalHost(); + + m_config->setGroup( CONFIG_GROUP ); + QString cmd = m_config->readEntry( "MrmmlDaemon Commandline", + settings.autoPort ? + DEFAULT_MRMLD_CMD_AUTOPORT : + DEFAULT_MRMLD_CMD ); + + // add data directory and port to the commandline + int index = cmd.find( "%p" ); + if ( index != -1 ) + { + QString port = settings.autoPort ? + QString::null : QString::number( settings.configuredPort ); + cmd.replace( index, 2, port ); + } + index = cmd.find( "%d" ); + if ( index != -1 ) + { + cmd.replace( index, 2, QUOTE( mrmldDataDir() ) ); + } + + qDebug("***** commandline: %s", cmd.latin1()); + + return cmd; +} + +QString Config::mrmldDataDir() +{ + QString dir = KGlobal::dirs()->saveLocation( "data", + "kmrml/mrmld-data/" ); + if ( dir.isEmpty() ) // fallback + dir = QDir::homeDirPath() + "/"; + + return dir; +} + +void Config::setMrmldCommandLine( const QString& cmd ) +{ + m_config->setGroup( CONFIG_GROUP ); + m_config->writeEntry( "MrmmlDaemon Commandline", cmd ); +} + +/////////////////////////////////////////////////////////////////// +/////////////////////////////////////////////////////////////////// + +ServerSettings::ServerSettings() + : configuredPort( 0 ), + autoPort( true ), + useAuth( false ) +{ +} + +ServerSettings::ServerSettings( const QString& host, unsigned short int port, + bool autoPort, bool useAuth, + const QString& user, const QString& pass ) +{ + this->host = host; + this->configuredPort = port; + this->autoPort = autoPort; + this->useAuth = useAuth; + this->user = user; + this->pass = pass; +} + +// static +ServerSettings ServerSettings::defaults() +{ + return ServerSettings( DEFAULT_HOST, DEFAULT_PORT, + (!strcmp(DEFAULT_HOST, "localhost") && DEFAULT_PORT), + DEFAULT_AUTH, DEFAULT_USER, DEFAULT_PASS ); +} + +KURL ServerSettings::getUrl() const +{ + KURL url; + url.setProtocol( "mrml" ); + url.setHost( host ); + if ( !autoPort ) + url.setPort( configuredPort ); + + if ( useAuth && user.isEmpty() ) + { + url.setUser( user ); + url.setPass( pass ); + } + + return url; +} + +unsigned short int ServerSettings::port() const +{ + if ( autoPort ) + { + QString portsFile = Config::mrmldDataDir() + "gift-port.txt"; + QFile file( portsFile ); + if ( file.open( IO_ReadOnly ) ) + { + QString line; + (void) file.readLine( line, 6 ); +// qDebug("**** read: %s", line.latin1()); + + file.close(); + + bool ok; + unsigned short int p = line.toUShort( &ok ); + if ( ok ) + return p; + } + else + kdWarning() << "Can't open \"" << portsFile << "\" to automatically determine the gift port" << endl; + } + + return configuredPort; +} diff --git a/kmrml/kmrml/lib/kmrml_config.h b/kmrml/kmrml/lib/kmrml_config.h new file mode 100644 index 00000000..3b6baa40 --- /dev/null +++ b/kmrml/kmrml/lib/kmrml_config.h @@ -0,0 +1,123 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef KMRML_CONFIG_H +#define KMRML_CONFIG_H + +class KConfig; + +#include <qstringlist.h> +#include <kurl.h> + +namespace KMrml +{ + class ServerSettings + { + public: + ServerSettings(); + ServerSettings(const QString& host, unsigned short int port, + bool autoPort, bool useAuth, const + QString& user, const QString& pass); + + // does NOT set the port in the KURL object, if autoPort is selected + // kio_mrml is going to determine itself (via ServerSettings::port()). + // This deuglifies the mrml:/ url a bit (no port is shown) + KURL getUrl() const; + + QString host; + QString user; + QString pass; + unsigned short int configuredPort; + bool autoPort :1; // only possible with host == localhost + bool useAuth :1; + + static ServerSettings defaults(); + + // returns configuredPort or the automatically determined port, + // depending on the value of autoPort + unsigned short int port() const; + }; + + class Config + { + public: + Config(); + Config( KConfig *config ); // does not take ownership of KConfig + ~Config(); + + bool sync(); + + ServerSettings defaultSettings() const + { + return settingsForHost( m_defaultHost ); + } + + ServerSettings settingsForLocalHost() const; + ServerSettings settingsForHost( const QString& host ) const; + + void setDefaultHost( const QString& host ); + + /** + * Indexed by the hostname -- ensures there are no dupes + */ + void addSettings( const ServerSettings& settings ); + + bool removeSettings( const QString& host ); + + QStringList hosts() const { return m_hostList; } + + /** + * The list of indexable directories -- only applicable to "localhost" + */ + QStringList indexableDirectories() const; + void setIndexableDirectories( const QStringList& dirs ); + + QString addCollectionCommandLine() const; + void setAddCollectionCommandLine( const QString& cmd ); + + QString removeCollectionCommandLine() const; + void setRemoveCollectionCommandLine( const QString& cmd ); + + void setMrmldCommandLine( const QString& cmd ); + QString mrmldCommandline() const; + + // e.g. Wolfgang needs this :) + bool serverStartedIndividually() const { + return m_serverStartedIndividually; + } + + static QString mrmldDataDir(); + + private: + void init(); + + QString settingsGroup( const QString& host ) const + { + return QString::fromLatin1( "SettingsFor: " ).append( host ); + } + + bool m_serverStartedIndividually; + QString m_defaultHost; + QStringList m_hostList; + + KConfig *m_config; + KConfig *m_ownConfig; + }; +} + +#endif // KMRML_CONFIG_H diff --git a/kmrml/kmrml/lib/mrml_shared.cpp b/kmrml/kmrml/lib/mrml_shared.cpp new file mode 100644 index 00000000..0c5b692b --- /dev/null +++ b/kmrml/kmrml/lib/mrml_shared.cpp @@ -0,0 +1,235 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include "mrml_shared.h" + +// mrml stuff +const QString * MrmlShared::m_sessionId = 0L; +const QString * MrmlShared::m_transactionId = 0L; +const QString * MrmlShared::m_algorithm = 0L; +const QString * MrmlShared::m_algorithmId = 0L; +const QString * MrmlShared::m_algorithmName = 0L; +const QString * MrmlShared::m_algorithmList = 0L; +const QString * MrmlShared::m_algorithmType = 0L; +const QString * MrmlShared::m_collectionId = 0L; +const QString * MrmlShared::m_collectionList = 0L; +const QString * MrmlShared::m_collection = 0L; +const QString * MrmlShared::m_collectionName = 0L; +const QString * MrmlShared::m_queryParadigm = 0L; +const QString * MrmlShared::m_queryParadigmList = 0L; +const QString * MrmlShared::m_configureSession = 0L; + +const QString * MrmlShared::m_propertySheet = 0L; +const QString * MrmlShared::m_propertySheetId = 0L; +const QString * MrmlShared::m_propertySheetType = 0L; +const QString * MrmlShared::m_sendName = 0L; +const QString * MrmlShared::m_sendType = 0L; +const QString * MrmlShared::m_sendValue = 0L; +const QString * MrmlShared::m_maxSubsetSize = 0L; +const QString * MrmlShared::m_minSubsetSize = 0L; +const QString * MrmlShared::m_caption = 0L; +const QString * MrmlShared::m_from = 0L; +const QString * MrmlShared::m_to = 0L; +const QString * MrmlShared::m_step = 0L; +const QString * MrmlShared::m_sendBooleanInverted = 0L; + +const QString * MrmlShared::m_element = 0L; +const QString * MrmlShared::m_attribute = 0L; +const QString * MrmlShared::m_attributeName = 0L; +const QString * MrmlShared::m_attributeValue = 0L; +const QString * MrmlShared::m_children = 0L; +const QString * MrmlShared::m_none = 0L; + +const QString * MrmlShared::m_multiSet = 0L; +const QString * MrmlShared::m_subset = 0L; +const QString * MrmlShared::m_setElement = 0L; +const QString * MrmlShared::m_boolean = 0L; +const QString * MrmlShared::m_numeric = 0L; +const QString * MrmlShared::m_textual = 0L; +const QString * MrmlShared::m_panel = 0L; +const QString * MrmlShared::m_clone = 0L; +const QString * MrmlShared::m_reference = 0L; + +const QString * MrmlShared::m_visibility = 0L; +const QString * MrmlShared::m_visible = 0L; +const QString * MrmlShared::m_invisible = 0L; +const QString * MrmlShared::m_popup = 0L; +// const QString * MrmlShared::m_ = 0L; + +// meta-data +const QString * MrmlShared::m_mrml_data = 0L; + +// kio_mrml tasks +const QString * MrmlShared::m_kio_task = 0L; +const QString * MrmlShared::m_kio_initialize = 0L; +const QString * MrmlShared::m_kio_startQuery = 0L; + + +int MrmlShared::s_references = 0; + +void MrmlShared::ref() +{ + if ( s_references == 0 ) + init(); + + s_references++; +} + +bool MrmlShared::deref() +{ + if ( s_references > 0 ) + s_references--; + + if ( s_references == 0 ) + { + // ### delete all strings here... + + return true; + } + + return false; +} + +void MrmlShared::init() +{ + m_sessionId = new QString ( "session-id" ) ; + m_transactionId = new QString ( "transaction-id" ) ; + m_algorithm = new QString ( "algorithm" ) ; + m_algorithmId = new QString ( "algorithm-id" ) ; + m_algorithmName = new QString ( "algorithm-name" ) ; + m_algorithmList = new QString ( "algorithm-list" ) ; + m_algorithmType = new QString ( "algorithm-type" ) ; + m_collectionId = new QString ( "collection-id" ) ; + m_collectionList = new QString ( "collection-list" ) ; + m_collection = new QString ( "collection" ) ; + m_collectionName = new QString ( "collection-name" ) ; + m_queryParadigm = new QString ( "query-paradigm" ) ; + m_queryParadigmList = new QString ( "query-paradigm-list" ) ; + m_configureSession = new QString ( "configure-session" ) ; + + m_propertySheet = new QString ( "property-sheet" ) ; + m_propertySheetId = new QString ( "property-sheet-id" ) ; + m_propertySheetType = new QString ( "property-sheet-type" ) ; + m_sendName = new QString ( "send-name" ) ; + m_sendType = new QString ( "send-type" ) ; + m_sendValue = new QString ( "send-value" ) ; + m_maxSubsetSize = new QString ( "maxsubsetsize" ) ; + m_minSubsetSize = new QString ( "minsubsetsize" ) ; + m_caption = new QString ( "caption" ) ; + m_from = new QString ( "from" ) ; + m_to = new QString ( "to" ) ; + m_step = new QString ( "step" ) ; + m_sendBooleanInverted = new QString ( "send-boolean-inverted" ) ; + + m_element = new QString ( "element" ) ; + m_attribute = new QString ( "attribute" ) ; + m_attributeName = new QString ( "attribute-name" ) ; + m_attributeValue = new QString ( "attribute-value" ) ; + m_children = new QString ( "children" ) ; + m_none = new QString ( "none" ) ; + + m_multiSet = new QString ( "multi-set" ) ; + m_subset = new QString ( "subset" ) ; + m_setElement = new QString ( "set-element" ) ; + m_boolean = new QString ( "boolean" ) ; + m_numeric = new QString ( "numeric" ) ; + m_textual = new QString ( "textual" ) ; + m_panel = new QString ( "panel" ) ; + m_clone = new QString ( "clone" ) ; + m_reference = new QString ( "reference" ) ; + + m_visibility = new QString ( "visibility" ) ; + m_visible = new QString ( "visible" ) ; + m_invisible = new QString ( "invisible" ) ; + m_popup = new QString ( "popup" ) ; +// m_ = new QString ( "" ) ; + +// meta-data + m_mrml_data = new QString ( "mrml_data" ) ; + +// kio_mrml tasks + m_kio_task = new QString ( "kio_task" ) ; + m_kio_initialize = new QString ( "kio_initialize" ) ; + m_kio_startQuery = new QString ( "kio_startQuery" ) ; +} + +void MrmlShared::cleanup() +{ + delete m_sessionId; + delete m_transactionId; + delete m_algorithm; + delete m_algorithmId; + delete m_algorithmName; + delete m_algorithmList; + delete m_algorithmType; + delete m_collectionId; + delete m_collectionList; + delete m_collection; + delete m_collectionName; + delete m_queryParadigm; + delete m_queryParadigmList; + delete m_configureSession; + + // property sheet stuff + delete m_propertySheet; + delete m_propertySheetId; + delete m_propertySheetType; + delete m_sendName; + delete m_sendType; + delete m_sendValue; + delete m_maxSubsetSize; + delete m_minSubsetSize; + delete m_caption; + delete m_from; + delete m_to; + delete m_step; + delete m_sendBooleanInverted; + + delete m_multiSet; + delete m_subset; + delete m_setElement; + delete m_boolean; + delete m_numeric; + delete m_textual; + delete m_panel; + delete m_clone; + delete m_reference; + + delete m_element; + delete m_attribute; + delete m_attributeName; + delete m_attributeValue; + delete m_children; + delete m_none; + + delete m_visibility; + delete m_visible; + delete m_invisible; + delete m_popup; +// delete m_; + + // meta-data + delete m_mrml_data; + + // kio_mrml tasks + delete m_kio_task; + delete m_kio_initialize; + delete m_kio_startQuery; + +} diff --git a/kmrml/kmrml/lib/mrml_shared.h b/kmrml/kmrml/lib/mrml_shared.h new file mode 100644 index 00000000..aff2a98d --- /dev/null +++ b/kmrml/kmrml/lib/mrml_shared.h @@ -0,0 +1,166 @@ +/* This file is part of the KDE project + Copyright (C) 2001,2002 Carsten Pfeiffer <pfeiffer@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#ifndef SHARED_H +#define SHARED_H + +// maybe use mrml_const.h from libMRML, unfortunately not installed +// by gift 0.1.6pre2 + +#include <qshared.h> +#include <qstring.h> + +class MrmlShared +{ +public: +// attribute/element names for mrml + static void ref(); + static bool deref(); + + static const QString& sessionId() { return *m_sessionId; } + static const QString& transactionId() { return *m_transactionId; } + static const QString& algorithm() { return *m_algorithm; } + static const QString& algorithmId() { return *m_algorithmId; } + static const QString& algorithmName() { return *m_algorithmName; } + static const QString& algorithmList() { return *m_algorithmList; } + static const QString& algorithmType() { return *m_algorithmType; } + static const QString& collectionId() { return *m_collectionId; } + static const QString& collectionList() { return *m_collectionList; } + static const QString& collection() { return *m_collection; } + static const QString& collectionName() { return *m_collectionName; } + static const QString& queryParadigm() { return *m_queryParadigm; } + static const QString& queryParadigmList() { return *m_queryParadigmList; } + static const QString& configureSession() { return *m_configureSession; } + + // property sheet stuff + static const QString& propertySheet() { return *m_propertySheet; } + static const QString& propertySheetId() { return *m_propertySheetId; } + static const QString& propertySheetType() { return *m_propertySheetType; } + static const QString& sendName() { return *m_sendName; } + static const QString& sendType() { return *m_sendType; } + static const QString& sendValue() { return *m_sendValue; } + static const QString& maxSubsetSize() { return *m_maxSubsetSize; } + static const QString& minSubsetSize() { return *m_minSubsetSize; } + static const QString& caption() { return *m_caption; } + static const QString& from() { return *m_from; } + static const QString& to() { return *m_to; } + static const QString& step() { return *m_step; } + static const QString& sendBooleanInverted() { return *m_sendBooleanInverted; } + + static const QString& multiSet() { return *m_multiSet; } + static const QString& subset() { return *m_subset; } + static const QString& setElement() { return *m_setElement; } + static const QString& boolean() { return *m_boolean; } + static const QString& numeric() { return *m_numeric; } + static const QString& textual() { return *m_textual; } + static const QString& panel() { return *m_panel; } + static const QString& clone() { return *m_clone; } + static const QString& reference() { return *m_reference; } + + static const QString& element() { return *m_element; } + static const QString& attribute() { return *m_attribute; } + static const QString& attributeName() { return *m_attributeName; } + static const QString& attributeValue() { return *m_attributeValue; } + static const QString& children() { return *m_children; } + static const QString& none() { return *m_none; } + + static const QString& visibility() { return *m_visibility; } + static const QString& visible() { return *m_visible; } + static const QString& invisible() { return *m_invisible; } + static const QString& popup() { return *m_popup; } +// static const QString& () { return *m_; } + + // meta-data + static const QString& mrml_data() { return *m_mrml_data; } + + // kio_mrml tasks + static const QString& kio_task() { return *m_kio_task; } + static const QString& kio_initialize() { return *m_kio_initialize; } + static const QString& kio_startQuery() { return *m_kio_startQuery; } + + +private: + static const QString * m_sessionId; + static const QString * m_transactionId; + static const QString * m_algorithm; + static const QString * m_algorithmId; + static const QString * m_algorithmName; + static const QString * m_algorithmList; + static const QString * m_algorithmType; + static const QString * m_collectionId; + static const QString * m_collectionList; + static const QString * m_collection; + static const QString * m_collectionName; + static const QString * m_queryParadigm; + static const QString * m_queryParadigmList; + static const QString * m_configureSession; + + // property sheet stuff + static const QString * m_propertySheet; + static const QString * m_propertySheetId; + static const QString * m_propertySheetType; + static const QString * m_sendName; + static const QString * m_sendType; + static const QString * m_sendValue; + static const QString * m_maxSubsetSize; + static const QString * m_minSubsetSize; + static const QString * m_caption; + static const QString * m_from; + static const QString * m_to; + static const QString * m_step; + static const QString * m_sendBooleanInverted; + + static const QString * m_multiSet; + static const QString * m_subset; + static const QString * m_setElement; + static const QString * m_boolean; + static const QString * m_numeric; + static const QString * m_textual; + static const QString * m_panel; + static const QString * m_clone; + static const QString * m_reference; + + static const QString * m_element; + static const QString * m_attribute; + static const QString * m_attributeName; + static const QString * m_attributeValue; + static const QString * m_children; + static const QString * m_none; + + static const QString * m_visibility; + static const QString * m_visible; + static const QString * m_invisible; + static const QString * m_popup; +// static const QString * m_; + + // meta-data + static const QString * m_mrml_data; + + // kio_mrml tasks + static const QString * m_kio_task; + static const QString * m_kio_initialize; + static const QString * m_kio_startQuery; + +private: + static void cleanup(); + static void init(); + + static int s_references; +}; + +#endif // SHARED_H diff --git a/kmrml/kmrml/lib/mrml_utils.cpp b/kmrml/kmrml/lib/mrml_utils.cpp new file mode 100644 index 00000000..f20dad6a --- /dev/null +++ b/kmrml/kmrml/lib/mrml_utils.cpp @@ -0,0 +1,89 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +#include <dcopclient.h> +#include <kapplication.h> +#include <kprocess.h> +#include <kstaticdeleter.h> + +#include "watcher_stub.h" + +#include "mrml_utils.h" + +// after 100 of no use, terminate the mrmld +#define TIMEOUT 100 +// how often to restart the mrmld in case of failure +#define NUM_RESTARTS 5 + +using namespace KMrml; + +KStaticDeleter<Util> utils_sd; + +Util *Util::s_self = 0L; + +Util::Util() +{ + // we need our own dcopclient, when used in kio_mrml + if ( !DCOPClient::mainClient() ) + { + DCOPClient::setMainClient( new DCOPClient() ); + if ( !DCOPClient::mainClient()->attach() ) + qWarning( "kio_mrml: Can't attach to DCOP Server."); + } +} + +Util::~Util() +{ + if ( this == s_self ) + s_self = 0L; +} + +Util *Util::self() +{ + if ( !s_self ) + s_self = utils_sd.setObject( new Util() ); + return s_self; +} + +bool Util::requiresLocalServerFor( const KURL& url ) +{ + return url.host().isEmpty() || url.host() == "localhost"; +} + +bool Util::startLocalServer( const Config& config ) +{ + if ( config.serverStartedIndividually() ) + return true; + + DCOPClient *client = DCOPClient::mainClient(); + + // ### check if it's already running (add dcop method to Watcher) + Watcher_stub watcher( client, "kded", "daemonwatcher"); + return ( watcher.requireDaemon( client->appId(), + "mrmld", config.mrmldCommandline(), + TIMEOUT, NUM_RESTARTS ) + && watcher.ok() ); +} + +void Util::unrequireLocalServer() +{ + DCOPClient *client = DCOPClient::mainClient(); + + Watcher_stub watcher( client, "kded", "daemonwatcher"); + watcher.unrequireDaemon( client->appId(), "mrmld" ); +} diff --git a/kmrml/kmrml/lib/mrml_utils.h b/kmrml/kmrml/lib/mrml_utils.h new file mode 100644 index 00000000..25f39d98 --- /dev/null +++ b/kmrml/kmrml/lib/mrml_utils.h @@ -0,0 +1,50 @@ +/* This file is part of the KDE project + Copyright (C) 2002 Carsten Pfeiffer <pfeiffer@kde.org> + + This program is free software; you can redistribute it and/or + modify it under the terms of the GNU General Public + License as published by the Free Software Foundation, version 2. + + This program 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 + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; see the file COPYING. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + + +#ifndef MRML_UTILS_H +#define MRML_UTILS_H + +#include <qobject.h> + +#include <kurl.h> + +#include "kmrml_config.h" + +namespace KMrml +{ + class Util : public QObject + { + public: + static Util * self(); + ~Util(); + + bool requiresLocalServerFor( const KURL& url ); + bool startLocalServer( const Config& config ); + void unrequireLocalServer(); +// bool isLocalServerRunning(); + + private: + static Util *s_self; + Util(); + }; + + +} + +#endif // MRML_UTILS_H diff --git a/kmrml/kmrml/lib/version.h b/kmrml/kmrml/lib/version.h new file mode 100644 index 00000000..5cf8e270 --- /dev/null +++ b/kmrml/kmrml/lib/version.h @@ -0,0 +1,6 @@ +#ifndef VERSION_H +#define VERSION_H + +#define KMRML_VERSION "0.3.2" + +#endif // VERSION_H diff --git a/kmrml/kmrml/lib/watcher_stub.cpp b/kmrml/kmrml/lib/watcher_stub.cpp new file mode 100644 index 00000000..cf84818b --- /dev/null +++ b/kmrml/kmrml/lib/watcher_stub.cpp @@ -0,0 +1,95 @@ +// +// Generated in ../server/ via dcopidl -- needs to be in the lib tho. +// Regenerate when necessary by uncommenting the watcher.stub in +// ../server/Makefile.am +// + +#include "watcher_stub.h" +#include <dcopclient.h> + +#include <kdatastream.h> + +namespace KMrml { + +Watcher_stub::Watcher_stub( const QCString& app, const QCString& obj ) + : DCOPStub( app, obj ) +{ +} + +Watcher_stub::Watcher_stub( DCOPClient* client, const QCString& app, const QCString& obj ) + : DCOPStub( client, app, obj ) +{ +} + +bool Watcher_stub::requireDaemon( const QCString& arg0, const QString& arg1, const QString& arg2, uint arg3, int arg4 ) +{ + bool result; + if ( !dcopClient() ) { + setStatus( CallFailed ); + return false; + } + QByteArray data, replyData; + QCString replyType; + QDataStream arg( data, IO_WriteOnly ); + arg << arg0; + arg << arg1; + arg << arg2; + arg << arg3; + arg << arg4; + if ( dcopClient()->call( app(), obj(), "requireDaemon(QCString,QString,QString,uint,int)", data, replyType, replyData ) ) { + if ( replyType == "bool" ) { + QDataStream _reply_stream( replyData, IO_ReadOnly ); + _reply_stream >> result; + setStatus( CallSucceeded ); + } else { + callFailed(); + } + } else { + callFailed(); + } + return result; +} + +void Watcher_stub::unrequireDaemon( const QCString& arg0, const QString& arg1 ) +{ + if ( !dcopClient() ) { + setStatus( CallFailed ); + return; + } + QByteArray data, replyData; + QCString replyType; + QDataStream arg( data, IO_WriteOnly ); + arg << arg0; + arg << arg1; + if ( dcopClient()->call( app(), obj(), "unrequireDaemon(QCString,QString)", data, replyType, replyData ) ) { + setStatus( CallSucceeded ); + } else { + callFailed(); + } +} + +QStringList Watcher_stub::runningDaemons() +{ + QStringList result; + if ( !dcopClient() ) { + setStatus( CallFailed ); + return result; + } + QByteArray data, replyData; + QCString replyType; + if ( dcopClient()->call( app(), obj(), "runningDaemons()", data, replyType, replyData ) ) { + if ( replyType == "QStringList" ) { + QDataStream _reply_stream( replyData, IO_ReadOnly ); + _reply_stream >> result; + setStatus( CallSucceeded ); + } else { + callFailed(); + } + } else { + callFailed(); + } + return result; +} + +} // namespace + diff --git a/kmrml/kmrml/lib/watcher_stub.h b/kmrml/kmrml/lib/watcher_stub.h new file mode 100644 index 00000000..04b1292e --- /dev/null +++ b/kmrml/kmrml/lib/watcher_stub.h @@ -0,0 +1,36 @@ +// +// Generated in ../server/ via dcopidl -- needs to be in the lib tho. +// Regenerate when necessary by uncommenting the watcher.stub in +// ../server/Makefile.am +// + +#ifndef __WATCHER_STUB__ +#define __WATCHER_STUB__ + +#include <dcopstub.h> +#include <qdict.h> +#include <qptrlist.h> +#include <qmap.h> +#include <qstrlist.h> +#include <qstringlist.h> +#include <qtimer.h> +#include <kdedmodule.h> +#include <kprocess.h> + +namespace KMrml { + +class Watcher_stub : public DCOPStub +{ +public: + Watcher_stub( const QCString& app, const QCString& id ); + Watcher_stub( DCOPClient* client, const QCString& app, const QCString& id ); + virtual bool requireDaemon( const QCString& clientAppId, const QString& daemonKey, const QString& commandline, uint timeout, int numRestarts ); + virtual void unrequireDaemon( const QCString& clientAppId, const QString& daemonKey ); + virtual QStringList runningDaemons(); +protected: + Watcher_stub() : DCOPStub( never_use ) {}; +}; + +} // namespace + +#endif |