[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [nepomuk-core/KDE/4.10] /: Add a Okular extractor plugin that uses Okular API to index files
From: Rohan Garg <rohangarg () kubuntu ! org>
Date: 2012-12-30 14:20:39
Message-ID: 20121230142039.00993A6091 () git ! kde ! org
[Download RAW message or body]
Git commit 76255d27a5f052a8517f9ca0c91441725f1be621 by Rohan Garg.
Committed on 27/12/2012 at 10:38.
Pushed by garg into branch 'KDE/4.10'.
Add a Okular extractor plugin that uses Okular API to index files
M +3 -0 CMakeLists.txt
M +21 -0 services/fileindexer/indexer/CMakeLists.txt
M +4 -2 services/fileindexer/indexer/main.cpp
A +5 -0 services/fileindexer/indexer/nepomukokularextractor.desktop
A +117 -0 services/fileindexer/indexer/okularextractor.cpp [License: LGPL \
(v2.1+)] A +34 -0 services/fileindexer/indexer/okularextractor.h [License: \
LGPL (v2.1+)]
http://commits.kde.org/nepomuk-core/76255d27a5f052a8517f9ca0c91441725f1be621
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 6766e4b..4d7d1f7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -45,6 +45,9 @@ macro_log_feature(EXIV2_FOUND "Exiv2" "Image Tag reader" \
"http://www.exiv2.org" macro_optional_find_package(FFmpeg)
macro_log_feature(FFMPEG_FOUND "FFmpeg" "Video Tag reader" "http://ffmpeg.org" FALSE \
"" "Support for video metadata")
+macro_optional_find_package(Okular)
+macro_log_feature(OKULAR_FOUND "Okular" "Various formats supported by Okular" \
"http://okular.kde.org" FALSE "" "Support for various file formats supported by \
Okular") +
# Some definitions
# ===============================================================================================
add_definitions (${QT_DEFINITIONS} ${KDE4_DEFINITIONS})
diff --git a/services/fileindexer/indexer/CMakeLists.txt \
b/services/fileindexer/indexer/CMakeLists.txt index f7b5d2a..60aa4d0 100644
--- a/services/fileindexer/indexer/CMakeLists.txt
+++ b/services/fileindexer/indexer/CMakeLists.txt
@@ -128,6 +128,27 @@ if(FFMPEG_FOUND)
endif(FFMPEG_FOUND)
+if(OKULAR_FOUND)
+ include_directories( ${OKULAR_INCLUDE_DIRS} )
+
+ kde4_add_plugin( nepomukokularextractor okularextractor.cpp extractorplugin.cpp \
) +
+ target_link_libraries( nepomukokularextractor
+ nepomukcore
+ ${OKULAR_LIBRARIES}
+ )
+
+ install(
+ FILES nepomukokularextractor.desktop
+ DESTINATION ${SERVICES_INSTALL_DIR})
+
+ install(
+ TARGETS nepomukokularextractor
+ DESTINATION ${PLUGIN_INSTALL_DIR})
+
+endif(OKULAR_FOUND)
+
+
kde4_add_plugin( nepomukplaintextextractor plaintextextractor.cpp \
extractorplugin.cpp )
diff --git a/services/fileindexer/indexer/main.cpp \
b/services/fileindexer/indexer/main.cpp index 4d6fcfd..a26a038 100644
--- a/services/fileindexer/indexer/main.cpp
+++ b/services/fileindexer/indexer/main.cpp
@@ -31,6 +31,7 @@
#include <KCmdLineArgs>
#include <KLocale>
#include <KComponentData>
+#include <KApplication>
#include <QtCore/QCoreApplication>
#include <QtCore/QDir>
@@ -68,8 +69,9 @@ int main(int argc, char *argv[])
const KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
// Application
- QCoreApplication app( argc, argv );
- KComponentData data( aboutData, KComponentData::RegisterAsMainComponent );
+ KApplication app;
+// QCoreApplication app( argc, argv );
+// KComponentData data( aboutData, KComponentData::RegisterAsMainComponent );
if( args->count() == 0 ) {
QTextStream err( stderr );
diff --git a/services/fileindexer/indexer/nepomukokularextractor.desktop \
b/services/fileindexer/indexer/nepomukokularextractor.desktop new file mode 100644
index 0000000..79c44ad
--- /dev/null
+++ b/services/fileindexer/indexer/nepomukokularextractor.desktop
@@ -0,0 +1,5 @@
+[Desktop Entry]
+Type=Service
+X-KDE-ServiceTypes=NepomukFileExtractor
+X-KDE-Library=nepomukokularextractor
+Name=Nepomuk Extractor using Okular
diff --git a/services/fileindexer/indexer/okularextractor.cpp \
b/services/fileindexer/indexer/okularextractor.cpp new file mode 100644
index 0000000..ffc27cb
--- /dev/null
+++ b/services/fileindexer/indexer/okularextractor.cpp
@@ -0,0 +1,117 @@
+/*
+ * Copyright (C) 2012 Rohan Garg <rohangarg@kubuntu.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+
+#include "okularextractor.h"
+
+#include <okular/core/document.h>
+#include <okular/core/settings_core.h>
+
+#include "nfo.h"
+#include "nie.h"
+#include "nco.h"
+
+#include <KService>
+#include <KServiceTypeTrader>
+#include <KTemporaryFile>
+
+using namespace Nepomuk2::Vocabulary;
+
+namespace Nepomuk2 {
+
+okularExtractor::okularExtractor(QObject* parent, const QVariantList&)
+ : ExtractorPlugin(parent)
+{
+}
+
+QStringList okularExtractor::mimetypes()
+{
+ /*
+ * Copied from Okular::Document::supportedMimeTypes
+ */
+ QStringList supportedMimeTypes;
+ QString constraint( "(Library == 'okularpart')" );
+ QLatin1String basePartService( "KParts/ReadOnlyPart" );
+ KService::List offers = KServiceTypeTrader::self()->query( basePartService, \
constraint ); + KService::List::ConstIterator it = offers.constBegin(), itEnd = \
offers.constEnd(); + for ( ; it != itEnd; ++it )
+ {
+ KService::Ptr service = *it;
+ QStringList mimeTypes = service->serviceTypes();
+ foreach ( const QString& mimeType, mimeTypes )
+ if ( mimeType != basePartService )
+ supportedMimeTypes.append( mimeType );
+ }
+
+ // Remove the pdf mimetype since the poppler plugin does this
+ if (supportedMimeTypes.contains("application/pdf")) {
+ supportedMimeTypes.removeAt(supportedMimeTypes.indexOf("application/pdf"));
+ }
+
+ return supportedMimeTypes;
+}
+
+SimpleResourceGraph okularExtractor::extract(const QUrl& resUri, const QUrl& \
fileUrl, const QString& mimeType) +{
+ Nepomuk2::SimpleResourceGraph graph;
+ Okular::SettingsCore::instance("");
+ Okular::Document *document = new Okular::Document(0);
+
+ if ( document->openDocument(fileUrl.path(), fileUrl, \
KMimeType::mimeType(mimeType)) ) { + SimpleResource fileRes( resUri );
+
+ // Basic Data
+ const Okular::DocumentInfo* docInfo = document->documentInfo();
+ fileRes.addType(NFO::PaginatedTextDocument());
+
+ QString author = docInfo->get(QLatin1String("author"));
+ if (!author.isEmpty()) {
+ SimpleResource res;
+ res.addType( NCO::Contact() );
+ res.addProperty( NCO::fullname(), author );
+ graph << res;
+
+ fileRes.addProperty( NCO::creator(), res );
+ }
+
+ QString subject = docInfo->get(QLatin1String("subject"));
+ if (!subject.isEmpty()) {
+ fileRes.addProperty( NIE::subject(), subject );
+ }
+
+ QString pages = docInfo->get(QLatin1String("pages"));
+ if (!pages.isEmpty()) {
+ fileRes.addProperty( NFO::pageCount(), pages );
+ }
+
+ if (document->canExportToText()) {
+ KTemporaryFile tempFile;
+ tempFile.open();
+ document->exportToText( tempFile.fileName() );
+ fileRes.addProperty( NIE::plainTextContent(), tempFile.readAll() );
+ }
+
+ graph << fileRes;
+ }
+
+ delete document;
+ return graph;
+}
+}
+NEPOMUK_EXPORT_EXTRACTOR( Nepomuk2::okularExtractor, "nepomukokularextractor" )
diff --git a/services/fileindexer/indexer/okularextractor.h \
b/services/fileindexer/indexer/okularextractor.h new file mode 100644
index 0000000..7c1f899
--- /dev/null
+++ b/services/fileindexer/indexer/okularextractor.h
@@ -0,0 +1,34 @@
+/*
+ * Copyright (C) 2012 Rohan Garg <rohangarg@kubuntu.org>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#ifndef OKULAREXTRACTOR_H
+#define OKULAREXTRACTOR_H
+
+#include "extractorplugin.h"
+
+namespace Nepomuk2 {
+class okularExtractor : public ExtractorPlugin
+{
+public:
+ okularExtractor(QObject *parent, const QVariantList&);
+ virtual QStringList mimetypes();
+ virtual SimpleResourceGraph extract(const QUrl& resUri, const QUrl& fileUrl, \
const QString& mimeType); +};
+}
+#endif // OKULAREXTRACTOR_H
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic