• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

Nepomuk-Core

  • sources
  • kde-4.12
  • kdelibs
  • nepomuk-core
  • services
  • fileindexer
  • indexer
  • mobipocket
mobiextractor.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013 Vishesh Handa <me@vhanda.in>
3 
4  Code adapted from kdegraphics-mobipocket/strigi/
5  Copyright (C) 2008 by Jakub Stachowski <qbast@go2.pl>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Lesser General Public
9  License as published by the Free Software Foundation; either
10  version 2.1 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Lesser General Public License for more details.
16 
17  You should have received a copy of the GNU Lesser General Public
18  License along with this library; if not, write to the Free Software
19  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21 
22 
23 #include "mobiextractor.h"
24 
25 #include <qmobipocket/mobipocket.h>
26 #include "qfilestream.h"
27 
28 #include "nie.h"
29 #include "nfo.h"
30 #include "nco.h"
31 
32 #include <Soprano/Vocabulary/NAO>
33 
34 #include <KDebug>
35 #include <QtCore/QDateTime>
36 #include <QTextDocument>
37 
38 using namespace Nepomuk2::Vocabulary;
39 using namespace Soprano::Vocabulary;
40 
41 namespace Nepomuk2 {
42 
43 MobiExtractor::MobiExtractor(QObject* parent, const QVariantList& )
44  : ExtractorPlugin(parent)
45 {
46 
47 }
48 
49 QStringList MobiExtractor::mimetypes()
50 {
51  QStringList types;
52  types << QLatin1String("application/x-mobipocket-ebook");
53 
54  return types;
55 }
56 
57 SimpleResourceGraph MobiExtractor::extract(const QUrl& resUri, const QUrl& fileUrl, const QString& mimeType)
58 {
59  Q_UNUSED( mimeType );
60 
61  SimpleResource fileRes(resUri);
62  SimpleResourceGraph graph;
63 
64  Mobipocket::QFileStream stream( fileUrl.toLocalFile() );
65  Mobipocket::Document doc(&stream);
66  if( !doc.isValid() )
67  return graph;
68 
69  QMapIterator<Mobipocket::Document::MetaKey,QString> it(doc.metadata());
70  while (it.hasNext()) {
71  it.next();
72  switch (it.key()) {
73  case Mobipocket::Document::Title:
74  fileRes.addProperty( NIE::title(), it.value() );
75  break;
76  case Mobipocket::Document::Author: {
77  SimpleResource con;
78  con.addType( NCO::Contact() );
79  con.addProperty( NCO::fullname(), it.value() );
80 
81  fileRes.addProperty( NCO::creator(), con );
82  graph << con;
83  break;
84  }
85  case Mobipocket::Document::Description: {
86  QTextDocument document;
87  document.setHtml( it.value() );
88 
89  QString plain = document.toPlainText();
90  if( !plain.isEmpty() )
91  fileRes.addProperty( NIE::comment(), plain );
92  break;
93  }
94  case Mobipocket::Document::Subject:
95  fileRes.addProperty( NIE::subject(), it.value() );
96  break;
97  case Mobipocket::Document::Copyright:
98  fileRes.addProperty( NIE::copyright(), it.value() );
99  break;
100  }
101  }
102 
103  if (!doc.hasDRM()) {
104  QString html = doc.text( maxPlainTextSize() );
105 
106  QTextDocument document;
107  document.setHtml(html);
108 
109  QString plainText = document.toPlainText();
110  if( !plainText.isEmpty() )
111  fileRes.addProperty( NIE::plainTextContent(), plainText );
112  }
113 
114  graph << fileRes;
115  return graph;
116 }
117 
118 }
119 
120 NEPOMUK_EXPORT_EXTRACTOR( Nepomuk2::MobiExtractor, "nepomukmobiextractor" )
Nepomuk2::ExtractorPlugin
The ExtractorPlugin is the base class for all file metadata extractors.
Definition: extractorplugin.h:60
Nepomuk2::MobiExtractor::MobiExtractor
MobiExtractor(QObject *parent, const QVariantList &)
Definition: mobiextractor.cpp:43
Nepomuk2::SimpleResource
Represents a snapshot of one Nepomuk resource.
Definition: simpleresource.h:46
mobiextractor.h
Nepomuk2::MobiExtractor
Definition: mobiextractor.h:28
QObject
Nepomuk2::SimpleResource::addProperty
void addProperty(const QUrl &property, const QVariant &value)
Add a property.
Definition: simpleresource.cpp:206
Nepomuk2::SimpleResourceGraph
Definition: simpleresourcegraph.h:48
Mobipocket::QFileStream
Definition: qfilestream.h:18
Nepomuk2::MobiExtractor::mimetypes
virtual QStringList mimetypes()
Provide a list of mimetypes which are supported by this plugin.
Definition: mobiextractor.cpp:49
NEPOMUK_EXPORT_EXTRACTOR
#define NEPOMUK_EXPORT_EXTRACTOR(classname, libname)
Export a Nepomuk file extractor.
Definition: extractorplugin.h:163
Nepomuk2::MobiExtractor::extract
virtual SimpleResourceGraph extract(const QUrl &resUri, const QUrl &fileUrl, const QString &mimeType)
The main function of the plugin that is responsible for extracting the data from the file url and ret...
Definition: mobiextractor.cpp:57
Nepomuk2::ExtractorPlugin::maxPlainTextSize
static int maxPlainTextSize()
Virtuoso does not support streaming operators, and does not accept queries above a certain size...
Definition: extractorplugin.cpp:124
qfilestream.h
Nepomuk2::SimpleResource::addType
void addType(const QUrl &type)
A convenience method which adds a property of type rdf:type.
Definition: simpleresource.cpp:257
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:48:08 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Nepomuk-Core

Skip menu "Nepomuk-Core"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal