• 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
services/fileindexer/indexer/main.cpp
Go to the documentation of this file.
1 /*
2  This file is part of the Nepomuk KDE project.
3  Copyright (C) 2010-11 Vishesh Handa <handa.vish@gmail.com>
4  Copyright (C) 2010-2011 Sebastian Trueg <trueg@kde.org>
5 
6  This library is free software; you can redistribute it and/or
7  modify it under the terms of the GNU Lesser General Public
8  License as published by the Free Software Foundation; either
9  version 2.1 of the License, or (at your option) version 3, or any
10  later version accepted by the membership of KDE e.V. (or its
11  successor approved by the membership of KDE e.V.), which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #include "indexer.h"
24 #include "extractorplugin.h"
25 #include "../util.h"
26 #include "../../../servicestub/priority.h"
27 #include "nepomukversion.h"
28 #include "nie.h"
29 #include "simpleresourcegraph.h"
30 
31 #include <KAboutData>
32 #include <KCmdLineArgs>
33 #include <KLocale>
34 #include <KComponentData>
35 #include <KApplication>
36 
37 #include <QApplication>
38 #include <QtCore/QDir>
39 #include <QtCore/QTextStream>
40 
41 #include <iostream>
42 #include <KDebug>
43 #include <KUrl>
44 #include <KJob>
45 
46 using namespace Nepomuk2::Vocabulary;
47 
48 int main(int argc, char *argv[])
49 {
50  lowerIOPriority();
51  lowerSchedulingPriority();
52  lowerPriority();
53 
54  KAboutData aboutData("nepomukindexer", 0, ki18n("NepomukIndexer"),
55  NEPOMUK_VERSION_STRING,
56  ki18n("NepomukIndexer indexes the contents of a file and saves the results in Nepomuk"),
57  KAboutData::License_LGPL_V2,
58  ki18n("(C) 2011, Vishesh Handa, Sebastian Trueg"));
59  aboutData.addAuthor(ki18n("Vishesh Handa"), ki18n("Current maintainer"), "handa.vish@gmail.com");
60  aboutData.addCredit(ki18n("Sebastian TrĂ¼g"), ki18n("Developer"), "trueg@kde.org");
61 
62  KCmdLineArgs::init(argc, argv, &aboutData);
63 
64  KCmdLineOptions options;
65  options.add("+[url]", ki18n("The URL of the file to be indexed"));
66  options.add("clear", ki18n("Remove all indexed data of the URL provided"));
67  options.add("data", ki18n("Streams the indexed data to stdout"));
68 
69  KCmdLineArgs::addCmdLineOptions(options);
70  const KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
71 
72  // Application
73  QApplication app( argc, argv );
74  KComponentData data( aboutData, KComponentData::RegisterAsMainComponent );
75 
76  if( args->count() == 0 ) {
77  QTextStream err( stderr );
78  err << "Must input url of the file to be indexed";
79 
80  return 1;
81  }
82 
83  if( args->isSet("clear") ) {
84  KJob* job = Nepomuk2::clearIndexedData( args->url(0) );
85  job->exec();
86  if( job->error() ) {
87  kDebug() << job->errorString();
88  return 1;
89  }
90  kDebug() << "Removed indexed data for" << args->url(0);
91  return 0;
92  }
93 
94  Nepomuk2::Indexer indexer;
95 
96  if( args->isSet("data") ) {
97  // We tell the plugins not to extract any plain text
98  Nepomuk2::ExtractorPlugin::setMaxPlainTextSize(0);
99  Nepomuk2::SimpleResourceGraph graph = indexer.indexFileGraph( args->url(0) );
100  Nepomuk2::ExtractorPlugin::resetMaxPlainTextSize();
101 
102  // Optimization, in this case we generally don't care about the plain text content
103  graph.removeAll( QUrl(), NIE::plainTextContent() );
104 
105  QByteArray byteArray;
106  QDataStream s(&byteArray, QIODevice::WriteOnly);
107  s << graph;
108 
109  std::cout << byteArray.toBase64().constData();
110 
111  return 0;
112  }
113 
114  // Normal Indexing
115  if( !indexer.indexFile( args->url(0) ) ) {
116  QTextStream s(stdout);
117  s << indexer.lastError();
118 
119  return 1;
120  }
121 
122  return 0;
123 }
lowerSchedulingPriority
bool lowerSchedulingPriority()
Definition: priority.cpp:95
Nepomuk2::SimpleResourceGraph
Definition: simpleresourcegraph.h:48
Nepomuk2::clearIndexedData
KJob * clearIndexedData(const QUrl &url)
remove all indexed data for url the datamanagement way
Definition: util.cpp:42
Nepomuk2::Indexer
The one entry point to indexing files.
Definition: indexer.h:36
indexer.h
Nepomuk2::SimpleResourceGraph::removeAll
void removeAll(const QUrl &uri, const QUrl &property, const QVariant &value=QVariant())
Remove all properties matching the provided parameters.
Definition: simpleresourcegraph.cpp:131
lowerPriority
bool lowerPriority()
Definition: priority.cpp:84
Nepomuk2::Indexer::lastError
QString lastError() const
Definition: indexer.cpp:216
Nepomuk2::Indexer::indexFileGraph
Nepomuk2::SimpleResourceGraph indexFileGraph(const QUrl &url)
Extracts the SimpleResourceGraph of the local file or folder and returns it.
Definition: indexer.cpp:195
Nepomuk2::Indexer::indexFile
bool indexFile(const KUrl &url)
Index a single local file or folder (files in a folder will not be indexed recursively).
Definition: indexer.cpp:67
simpleresourcegraph.h
Nepomuk2::ExtractorPlugin::setMaxPlainTextSize
static void setMaxPlainTextSize(int size)
Definition: extractorplugin.cpp:134
Nepomuk2::ExtractorPlugin::resetMaxPlainTextSize
static void resetMaxPlainTextSize()
Definition: extractorplugin.cpp:129
main
int main(int argc, char *argv[])
Definition: services/fileindexer/indexer/main.cpp:48
lowerIOPriority
bool lowerIOPriority()
Definition: priority.cpp:67
extractorplugin.h
KJob
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