30 #include <Soprano/Vocabulary/NRL>
31 #include <Soprano/Vocabulary/RDF>
33 #include <QtCore/QFileInfo>
34 #include <QtCore/QDateTime>
41 using namespace Nepomuk2::Vocabulary;
42 using namespace Soprano::Vocabulary;
53 , m_mimeType( mimeType )
59 SimpleResource m_res = createSimpleResource( m_nieUrl, &m_mimeType );
60 m_resUri = m_res.
uri();
66 additionalMetadata.insert( RDF::type(), NRL::DiscardableInstanceBase() );
72 KComponentData component = KGlobal::mainComponent();
73 if( component.componentName() != QLatin1String(
"nepomukindexer") ) {
74 component = KComponentData( QByteArray(
"nepomukindexer"),
75 QByteArray(), KComponentData::SkipMainComponentRegistration );
80 connect( job, SIGNAL(finished(
KJob*)),
this, SLOT(slotJobFinished(
KJob*)) );
83 void Nepomuk2::SimpleIndexingJob::slotJobFinished(
KJob* job_)
87 kError() <<
"SimpleIndexError: " << job->errorString();
89 setError( job->error() );
90 setErrorText( job->errorString() );
93 m_resUri = job->
mappings().value( m_resUri );
104 res.
addProperty(NFO::fileName(), fileUrl.fileName());
106 res.
addType(NFO::FileDataObject());
107 res.
addType(NIE::InformationElement());
109 QFileInfo fileInfo(fileUrl.toLocalFile());
110 if( fileInfo.isDir() ) {
122 if( mime.isEmpty() ) {
123 mime = KMimeType::findByUrl( fileUrl )->name();
127 QSet<QUrl> types = typesForMimeType( mime );
128 foreach(
const QUrl& type, types)
133 res.
setProperty(NIE::created(), fileInfo.created());
134 res.
setProperty(NIE::lastModified(), fileInfo.lastModified());
140 QSet<QUrl> Nepomuk2::SimpleIndexingJob::typesForMimeType(
const QString& mimeType)
145 if( mimeType.contains(QLatin1String(
"audio")) )
146 types << NFO::Audio();
147 if( mimeType.contains(QLatin1String(
"video")) )
148 types << NFO::Video();
149 if( mimeType.contains(QLatin1String(
"image")) )
150 types << NFO::Image();
151 if( mimeType.contains(QLatin1String(
"text")) )
152 types << NFO::PlainTextDocument();
153 if( mimeType.contains(QLatin1String(
"document")) )
154 types << NFO::Document();
155 if( mimeType.contains(QLatin1String(
"font")) )
156 types << NFO::Font();
159 if( mimeType.contains(QLatin1String(
"powerpoint") ) )
160 types << NFO::Presentation();
162 if( mimeType.contains(QLatin1String(
"excel")) )
163 types << NFO::Spreadsheet();
165 if( mimeType.contains(QLatin1String(
"text/html") ) )
166 types << NFO::HtmlDocument();
169 if( typeMapper.isEmpty() ) {
171 typeMapper.insert( QLatin1String(
"application/msword"), NFO::PaginatedTextDocument() );
172 typeMapper.insert( QLatin1String(
"application/vnd.ms-powerpoint"), NFO::Presentation() );
173 typeMapper.insert( QLatin1String(
"application/vnd.ms-excel"), NFO::Spreadsheet() );
176 typeMapper.insert( QLatin1String(
"application/vnd.openxmlformats-officedocument.wordprocessingml.document"),
177 NFO::PaginatedTextDocument() );
178 typeMapper.insert( QLatin1String(
"application/vnd.openxmlformats-officedocument.presentationml.presentation"),
179 NFO::Presentation() );
180 typeMapper.insert( QLatin1String(
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"),
181 NFO::Spreadsheet() );
184 typeMapper.insert( QLatin1String(
"application/vnd.oasis.opendocument.text"), NFO::PaginatedTextDocument() );
185 typeMapper.insert( QLatin1String(
"application/vnd.oasis.opendocument.presentation"), NFO::Presentation() );
186 typeMapper.insert( QLatin1String(
"application/vnd.oasis.opendocument.spreadsheet"), NFO::Spreadsheet() );
189 typeMapper.insert( QLatin1String(
"application/pdf"), NFO::PaginatedTextDocument() );
190 typeMapper.insert( QLatin1String(
"application/postscript"), NFO::PaginatedTextDocument() );
191 typeMapper.insert( QLatin1String(
"application/x-dvi"), NFO::PaginatedTextDocument() );
192 typeMapper.insert( QLatin1String(
"application/rtf"), NFO::PaginatedTextDocument() );
195 typeMapper.insert( QLatin1String(
"application/epub+zip"), NFO::PaginatedTextDocument() );
196 typeMapper.insert( QLatin1String(
"application/x-mobipocket-ebook"), NFO::PaginatedTextDocument() );
199 typeMapper.insert( QLatin1String(
"application/x-tar"), NFO::Archive() );
200 typeMapper.insert( QLatin1String(
"application/x-bzip2"), NFO::Archive() );
201 typeMapper.insert( QLatin1String(
"application/x-gzip"), NFO::Archive() );
202 typeMapper.insert( QLatin1String(
"application/x-lzip"), NFO::Archive() );
203 typeMapper.insert( QLatin1String(
"application/x-lzma"), NFO::Archive() );
204 typeMapper.insert( QLatin1String(
"application/x-lzop"), NFO::Archive() );
205 typeMapper.insert( QLatin1String(
"application/x-compress"), NFO::Archive() );
206 typeMapper.insert( QLatin1String(
"application/x-7z-compressed"), NFO::Archive() );
207 typeMapper.insert( QLatin1String(
"application/x-ace-compressed"), NFO::Archive() );
208 typeMapper.insert( QLatin1String(
"application/x-astrotite-afa"), NFO::Archive() );
209 typeMapper.insert( QLatin1String(
"application/x-alz-compressed"), NFO::Archive() );
210 typeMapper.insert( QLatin1String(
"application/vnd.android.package-archive"), NFO::Archive() );
211 typeMapper.insert( QLatin1String(
"application/x-arj"), NFO::Archive() );
212 typeMapper.insert( QLatin1String(
"application/vnd.ms-cab-compressed"), NFO::Archive() );
213 typeMapper.insert( QLatin1String(
"application/x-cfs-compressed"), NFO::Archive() );
214 typeMapper.insert( QLatin1String(
"application/x-dar"), NFO::Archive() );
215 typeMapper.insert( QLatin1String(
"application/x-lzh"), NFO::Archive() );
216 typeMapper.insert( QLatin1String(
"application/x-lzx"), NFO::Archive() );
217 typeMapper.insert( QLatin1String(
"application/x-rar-compressed"), NFO::Archive() );
218 typeMapper.insert( QLatin1String(
"application/x-stuffit"), NFO::Archive() );
219 typeMapper.insert( QLatin1String(
"application/x-stuffitx"), NFO::Archive() );
220 typeMapper.insert( QLatin1String(
"application/x-gtar"), NFO::Archive() );
221 typeMapper.insert( QLatin1String(
"application/zip"), NFO::Archive() );
224 typeMapper.insert( QLatin1String(
"image/vnd.microsoft.icon"), NFO::Icon() );
225 typeMapper.insert( QLatin1String(
"image/svg+xml"), NFO::VectorImage() );
228 typeMapper.insert( QLatin1String(
"application/vnd.ms-fontobject"), NFO::Font() );
229 typeMapper.insert( QLatin1String(
"application/vnd.ms-opentype"), NFO::Font() );
233 if( it != typeMapper.constEnd() )
void setProperty(const QUrl &property, const QVariant &value)
Set a property overwriting existing values.
SimpleIndexingJob(const QUrl &fileUrl, QObject *parent=0)
Represents a snapshot of one Nepomuk resource.
static SimpleResource createSimpleResource(const KUrl &fileUrl, QString *mimeType)
Fills a new SimpleResource with the basic data of the fileUrl such as type, mimetype, and other stat info.
void addProperty(const QUrl &property, const QVariant &value)
Add a property.
StoreResourcesJob * storeResources(const Nepomuk2::SimpleResourceGraph &resources, Nepomuk2::StoreIdentificationMode identificationMode=Nepomuk2::IdentifyNew, Nepomuk2::StoreResourcesFlags flags=Nepomuk2::NoStoreResourcesFlags, const QHash< QUrl, QVariant > &additionalMetadata=QHash< QUrl, QVariant >(), const KComponentData &component=KGlobal::mainComponent())
Store many resources at once.
This is the default mode.
QHash< QUrl, QUrl > mappings() const
void addType(const QUrl &type)
A convenience method which adds a property of type rdf:type.
No flags - default behaviour.