• 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
  • tools
  • nepomukshow
tools/nepomukshow/main.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2010 Sebastian Trueg <trueg@kde.org>
3  Copyright (c) 2012 Vishesh Handa <me@vhanda.in>
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU General Public License as
7  published by the Free Software Foundation; either version 2 of
8  the License or (at your option) version 3 or any later version
9  accepted by the membership of KDE e.V. (or its successor approved
10  by the membership of KDE e.V.), which shall act as a proxy
11  defined in Section 14 of version 3 of the license.
12 
13  This program is distributed in the hope that it will be useful,
14  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  GNU General Public License for more details.
17 
18  You should have received a copy of the GNU General Public License
19  along with this program. If not, see <http://www.gnu.org/licenses/>.
20 */
21 
22 #include <QtCore/QCoreApplication>
23 #include <QtCore/QHash>
24 #include <QtCore/QUrl>
25 #include <QtCore/QSet>
26 
27 #include <kcmdlineargs.h>
28 #include <kaboutdata.h>
29 #include <KDE/KLocale>
30 #include <KComponentData>
31 #include <KUrl>
32 #include <KDebug>
33 
34 #include <Soprano/Model>
35 #include <Soprano/QueryResultIterator>
36 
37 #include "resourceprinter.h"
38 #include "resource.h"
39 #include "variant.h"
40 #include "property.h"
41 #include "resourcemanager.h"
42 
43 int main( int argc, char *argv[] )
44 {
45  KAboutData aboutData( "nepomukshow",
46  "nepomukshow",
47  ki18n("Nepomuk Show"),
48  "0.1",
49  ki18n("The Nepomuk Resource Viewer - A debugging tool"),
50  KAboutData::License_GPL,
51  ki18n("(c) 2012, Vishesh Handa"),
52  KLocalizedString(),
53  "http://nepomuk.kde.org" );
54  aboutData.addAuthor(ki18n("Vishesh Handa"),ki18n("Maintainer"), "me@vhanda.in");
55  aboutData.addAuthor(ki18n("Sebastian Trüg"),ki18n("Developer"), "trueg@kde.org");
56  aboutData.setProgramIconName( "nepomuk" );
57 
58  KCmdLineArgs::init( argc, argv, &aboutData );
59 
60  KCmdLineOptions options;
61  options.add("+resource", ki18n("The resource URI, a file URL, or a file path."));
62  options.add("depth <depth>", ki18n("The number of sub resources to list"), "0");
63  options.add("graphs", ki18n("Print information about the graphs"));
64  options.add("inference", ki18n("Uses Inference to print additional properties"));
65  options.add("plainText", ki18n("Print the plain text content of the file"));
66  KCmdLineArgs::addCmdLineOptions( options );
67 
68  KCmdLineArgs* args = KCmdLineArgs::parsedArgs();
69 
70  QCoreApplication app( argc, argv );
71  KComponentData comp( aboutData );
72 
73  if( args->count() == 0 )
74  KCmdLineArgs::usage();
75 
76  QTextStream err( stdout );
77 
78  //
79  // The Resource Uri
80  //
81  const QUrl url = args->url( 0 );
82  Nepomuk2::Resource res( url );
83  if ( !res.exists() ) {
84  err << "Resource does not exist: " << args->url( 0 ).url() << endl;
85  return 1;
86  }
87 
88  Soprano::Model* model = Nepomuk2::ResourceManager::instance()->mainModel();
89  QSet<QUrl> uriList;
90 
91  //
92  // If nie:url, then fetch the resources
93  //
94  if( url.scheme() != QLatin1String("nepomuk") ) {
95  QString query = QString::fromLatin1("select ?r where { ?r nie:url %1 . }")
96  .arg( Soprano::Node::resourceToN3( url ) );
97  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
98  while( it.next() ) {
99  uriList << it[0].uri();
100  }
101  }
102  else {
103  uriList << res.uri();
104  }
105 
106  //
107  // Fetch additional resource for the depth
108  //
109  int depth = args->getOption("depth").toInt();
110  int oldSize = uriList.size();
111  for( int i=0; i<depth; i++ ) {
112  QSet<QUrl> newUris;
113  foreach(const QUrl& uri, uriList) {
114  QString query = QString::fromLatin1("select ?o where { %1 ?p ?o. FILTER(REGEX(STR(?o), '^nepomuk')). }")
115  .arg( Soprano::Node::resourceToN3(uri) );
116  Soprano::QueryResultIterator it = model->executeQuery( query, Soprano::Query::QueryLanguageSparql );
117  while( it.next() )
118  newUris << it[0].uri();
119  }
120  uriList.unite( newUris );
121 
122  if( uriList.size() == oldSize )
123  break;
124  else
125  oldSize = uriList.size();
126  }
127 
128  //
129  // Dump to stdout
130  //
131  QTextStream stream( stdout );
132  Nepomuk2::ResourcePrinter printer;
133 
134  if( args->isSet("graphs") )
135  printer.setGraphs( true );
136  if( args->isSet("inference") )
137  printer.setInference( true );
138  if( args->isSet("plainText") )
139  printer.setPlainText( true );
140 
141  foreach( const QUrl& resUri, uriList ) {
142  printer.print( stream, resUri );
143  }
144 
145  return 0;
146 }
Nepomuk2::Resource::exists
bool exists() const
Definition: resource.cpp:322
Nepomuk2::ResourcePrinter
Definition: resourceprinter.h:28
variant.h
Nepomuk2::ResourcePrinter::setGraphs
void setGraphs(bool status)
Definition: resourceprinter.cpp:242
resource.h
Nepomuk2::ResourceManager::instance
static ResourceManager * instance()
Definition: resourcemanager.cpp:270
resourcemanager.h
Nepomuk2::ResourcePrinter::print
void print(QTextStream &stream, const QUrl &uri)
Definition: resourceprinter.cpp:237
resourceprinter.h
main
int main(int argc, char *argv[])
Definition: tools/nepomukshow/main.cpp:43
Nepomuk2::ResourcePrinter::setInference
void setInference(bool status)
Definition: resourceprinter.cpp:247
Nepomuk2::Resource
Resource is the central object type in Nepomuk.
Definition: resource.h:93
Nepomuk2::Resource::uri
QUrl uri() const
The URI of the resource, uniquely identifying it.
Definition: resource.cpp:166
Nepomuk2::ResourcePrinter::setPlainText
void setPlainText(bool status)
Definition: resourceprinter.cpp:252
Nepomuk2::ResourceManager::mainModel
Soprano::Model * mainModel()
Retrieve the main data storage model.
Definition: resourcemanager.cpp:363
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