diff options
Diffstat (limited to 'tdeioslave/metainfo')
-rw-r--r-- | tdeioslave/metainfo/CMakeLists.txt | 43 | ||||
-rw-r--r-- | tdeioslave/metainfo/Makefile.am | 24 | ||||
-rw-r--r-- | tdeioslave/metainfo/metainfo.cpp | 103 | ||||
-rw-r--r-- | tdeioslave/metainfo/metainfo.h | 38 | ||||
-rw-r--r-- | tdeioslave/metainfo/metainfo.protocol | 9 |
5 files changed, 217 insertions, 0 deletions
diff --git a/tdeioslave/metainfo/CMakeLists.txt b/tdeioslave/metainfo/CMakeLists.txt new file mode 100644 index 000000000..9b27a8652 --- /dev/null +++ b/tdeioslave/metainfo/CMakeLists.txt @@ -0,0 +1,43 @@ +################################################# +# +# (C) 2010 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${TQT_INCLUDE_DIRS} + ${CMAKE_BINARY_DIR}/tdecore + ${CMAKE_SOURCE_DIR}/dcop + ${CMAKE_SOURCE_DIR}/tdecore + ${CMAKE_SOURCE_DIR}/tdeio + ${CMAKE_SOURCE_DIR}/tdeio/tdeio +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### other data ################################ + +install( FILES metainfo.protocol DESTINATION ${SERVICES_INSTALL_DIR} ) + + +##### kio_metainfo ############################## + +set( target kio_metainfo ) + +set( ${target}_SRCS + metainfo.cpp +) + +tde_add_kpart( ${target} AUTOMOC + SOURCES ${${target}_SRCS} + LINK tdeio-shared + DESTINATION ${PLUGIN_INSTALL_DIR} +) diff --git a/tdeioslave/metainfo/Makefile.am b/tdeioslave/metainfo/Makefile.am new file mode 100644 index 000000000..a5575d9ff --- /dev/null +++ b/tdeioslave/metainfo/Makefile.am @@ -0,0 +1,24 @@ +## $Id$ +## Makefile.am of tdebase/tdeioslave/metainfo + +INCLUDES = $(all_includes) +AM_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_KIO) -ltdetexteditor +METASOURCES = AUTO + +kde_module_LTLIBRARIES = kio_metainfo.la + +kio_metainfo_la_SOURCES = metainfo.cpp +kio_metainfo_la_LIBADD = $(LIB_KIO) $(LIB_QT) $(LIB_TDECORE) +kio_metainfo_la_LDFLAGS = $(all_libraries) -module $(KDE_PLUGIN) + +noinst_HEADERS = metainfo.h + +kdelnk_DATA = metainfo.protocol +kdelnkdir = $(kde_servicesdir) + +#servicetypes_DATA = thumbcreator.desktop +#servicetypesdir = $(kde_servicetypesdir) + +#services_DATA = imagethumbnail.desktop textthumbnail.desktop +# htmlthumbnail.desktop gsthumbnail.desktop +#servicesdir = $(kde_servicesdir) diff --git a/tdeioslave/metainfo/metainfo.cpp b/tdeioslave/metainfo/metainfo.cpp new file mode 100644 index 000000000..abc5cdd96 --- /dev/null +++ b/tdeioslave/metainfo/metainfo.cpp @@ -0,0 +1,103 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation version 2.0 + + 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// $Id$ + +#include <kdatastream.h> // Do not remove, needed for correct bool serialization +#include <kurl.h> +#include <kapplication.h> +#include <kmimetype.h> +#include <kdebug.h> +#include <tdefilemetainfo.h> +#include <klocale.h> +#include <stdlib.h> + +#include "metainfo.h" + +// Recognized metadata entries: +// mimeType - the mime type of the file, so we need not extra determine it +// what - what to load + +using namespace TDEIO; + +extern "C" +{ + KDE_EXPORT int kdemain(int argc, char **argv); +} + +int kdemain(int argc, char **argv) +{ + TDEApplication app(argc, argv, "kio_metainfo", false, true); + + if (argc != 4) + { + kdError() << "Usage: kio_metainfo protocol domain-socket1 domain-socket2" << endl; + exit(-1); + } + + MetaInfoProtocol slave(argv[2], argv[3]); + slave.dispatchLoop(); + + return 0; +} + +MetaInfoProtocol::MetaInfoProtocol(const TQCString &pool, const TQCString &app) + : SlaveBase("metainfo", pool, app) +{ +} + +MetaInfoProtocol::~MetaInfoProtocol() +{ +} + +void MetaInfoProtocol::get(const KURL &url) +{ + TQString mimeType = metaData("mimeType"); + KFileMetaInfo info(url.path(), mimeType); + + TQByteArray arr; + TQDataStream stream(arr, IO_WriteOnly); + + stream << info; + + data(arr); + finished(); +} + +void MetaInfoProtocol::put(const KURL& url, int, bool, bool) +{ + TQString mimeType = metaData("mimeType"); + KFileMetaInfo info; + + TQByteArray arr; + readData(arr); + TQDataStream stream(arr, IO_ReadOnly); + + stream >> info; + + if (info.isValid()) + { + info.applyChanges(); + } + else + { + error(ERR_NO_CONTENT, i18n("No metainfo for %1").arg(url.path())); + return; + } + finished(); +} diff --git a/tdeioslave/metainfo/metainfo.h b/tdeioslave/metainfo/metainfo.h new file mode 100644 index 000000000..cc179cc98 --- /dev/null +++ b/tdeioslave/metainfo/metainfo.h @@ -0,0 +1,38 @@ +/* This file is part of the KDE libraries + Copyright (C) 2002 Rolf Magnus <ramagnus@kde.org> + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation version 2.0 + + 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 + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ + +// $Id$ + +#ifndef _METAINFO_H_ +#define _METAINFO_H_ + +#include <tdeio/slavebase.h> + +class MetaInfoProtocol : public TDEIO::SlaveBase +{ +public: + MetaInfoProtocol(const TQCString &pool, const TQCString &app); + virtual ~MetaInfoProtocol(); + + virtual void get(const KURL &url); + virtual void put(const KURL& url, int permissions, + bool overwrite, bool resume); + +}; + +#endif diff --git a/tdeioslave/metainfo/metainfo.protocol b/tdeioslave/metainfo/metainfo.protocol new file mode 100644 index 000000000..f1fa9adac --- /dev/null +++ b/tdeioslave/metainfo/metainfo.protocol @@ -0,0 +1,9 @@ +[Protocol] +exec=kio_metainfo +protocol=metainfo +input=stream +output=stream +reading=true +writing=true +source=false +Icon=help |