File indexing completed on 2024-05-05 16:08:26

0001 /*****************************************************************************
0002  * Copyright (C) 2011 by Peter Penz <peter.penz19@gmail.com>                 *
0003  *                                                                           *
0004  * This library is free software; you can redistribute it and/or             *
0005  * modify it under the terms of the GNU Library General Public               *
0006  * License as published by the Free Software Foundation; either              *
0007  * version 2 of the License, or (at your option) any later version.          *
0008  *                                                                           *
0009  * This library is distributed in the hope that it will be useful,           *
0010  * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
0011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
0012  * Library General Public License for more details.                          *
0013  *                                                                           *
0014  * You should have received a copy of the GNU Library General Public License *
0015  * along with this library; see the file COPYING.LIB.  If not, write to      *
0016  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
0017  * Boston, MA 02110-1301, USA.                                               *
0018  *****************************************************************************/
0019 
0020 #ifndef KFILEMETADATAREADER_H
0021 #define KFILEMETADATAREADER_H
0022 
0023 #include <nepomuk/core/variant.h>
0024 
0025 #include <QHash>
0026 #include <QList>
0027 #include <QObject>
0028 #include <QProcess>
0029 #include <QString>
0030 #include <QUrl>
0031 
0032 /**
0033  * @brief Provides metadata extracted from files.
0034  *
0035  * The reading of the metadata is done asynchronously in a process.
0036  * This assures that the caller won't get blocked and also prevents
0037  * that the caller crashes in case if a metadata-analyzer plugin is instable.
0038  *
0039  * @since 4.7
0040  * @internal
0041  */
0042 class KFileMetaDataReader : public QObject
0043 {
0044     Q_OBJECT
0045 
0046 public:
0047     /**
0048      * @param urls   List of files where the metadata should be extracted from.
0049      * @param parent Parent object.
0050      */
0051     KDELIBS4SUPPORT_DEPRECATED explicit KFileMetaDataReader(const QList<QUrl> &urls, QObject *parent = 0);
0052     virtual ~KFileMetaDataReader();
0053 
0054     /**
0055      * If \p read is set to true also metadata that is persisted outside the
0056      * files itself (like e.g. rating, comments or tags) are read. Per
0057      * default the reading of context data is enabled. Pass false if only the metadata
0058      * persisted inside the file should be read.
0059      */
0060     void setReadContextData(bool read);
0061     bool readContextData() const;
0062 
0063     /**
0064      * Starts the reading of the metadata inside a custom process.
0065      * The signal finished() will get emitted if the reading has been finished.
0066      * Use metaData() to access the read metadata.
0067      */
0068     void start();
0069 
0070     /**
0071      * @return The read metadata of the given files. The method provides valid values
0072      *         after the signal finished() has been emitted. If it is invoked before
0073      *         an empty hash-table will be returned.
0074      */
0075     QHash<QUrl, Nepomuk::Variant> metaData() const;
0076 
0077 Q_SIGNALS:
0078     /**
0079      * Is emitted if the reading of the metadata inside a custom process has been finished.
0080      * The method metaData() can be used afterwards to access the metadata.
0081      */
0082     void finished();
0083 
0084 private:
0085     class Private;
0086     Private *d;
0087 
0088     Q_PRIVATE_SLOT(d, void slotLoadingFinished(int, QProcess::ExitStatus))
0089 };
0090 
0091 #endif