┌   ┐
54
└   ┘

summaryrefslogtreecommitdiff
path: root/src/panels/information/kmetadatamodel.h
blob: ad8099dade31739f84ab72073614635ed6960fdd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*****************************************************************************
 * Copyright (C) 2010 by Peter Penz <[email protected]>                      *
 *                                                                           *
 * This library is free software; you can redistribute it and/or             *
 * modify it under the terms of the GNU Library General Public               *
 * License version 2 as published by the Free Software Foundation.           *
 *                                                                           *
 * This library is distributed in the hope that it will be useful,           *
 * but WITHOUT ANY WARRANTY; without even the implied warranty of            *
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU         *
 * Library General Public License for more details.                          *
 *                                                                           *
 * You should have received a copy of the GNU Library General Public License *
 * along with this library; see the file COPYING.LIB.  If not, write to      *
 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,      *
 * Boston, MA 02110-1301, USA.                                               *
 *****************************************************************************/

#ifndef KMETADATAMODEL_H
#define KMETADATAMODEL_H

#include <kurl.h>

#include <QHash>
#include <QObject>
#include <QString>

#include <config-nepomuk.h>
#ifdef HAVE_NEPOMUK
    #define DISABLE_NEPOMUK_LEGACY
    #include <nepomuk/variant.h>
#endif

class KFileItemList;
class KUrl;

/**
 * @brief Provides the data for the KMetaDataWidget.
 *
 * The default implementation provides all meta data
 * that are available due to Strigi and Nepomuk. If custom
 * meta data should be added, the method KMetaDataModel::loadData()
 * must be overwritten.
 *
 * @see KMetaDataWidget
 */
class KMetaDataModel : public QObject
{
    Q_OBJECT

public:
    explicit KMetaDataModel(QObject* parent = 0);
    virtual ~KMetaDataModel();

    /**
     * Sets the items, where the meta data should be
     * requested. The loading of the meta data is done
     * asynchronously. The signal loadingFinished() is
     * emitted, as soon as the loading has been finished.
     * The meta data can be retrieved by
     * KMetaDataModel::data() afterwards.
     */
    void setItems(const KFileItemList& items);
    KFileItemList items() const;

    /**
     * @return Returns the name of the group the meta data indicated
     *         by \p metaDataUri belongs to. All meta data items are
     *         sorted by the group. Items within the group are sorted
     *         by their translated labels. The group name is not shown
     *         to the user interface and does not need to get translated.
     */
    virtual QString group(const KUrl& metaDataUri) const;

#ifdef HAVE_NEPOMUK
    /**
     * @return Meta data for the items that have been set by
     *         KMetaDataModel::setItems(). The method should
     *         be invoked after the signal loadingFinished() has
     *         been received (otherwise no data will be returned).
     */
    QHash<KUrl, Nepomuk::Variant> data() const;

protected:
    /**
     * Implement this method if custom meta data should be retrieved
     * and added to the list returned by KMetaDataModel::data().
     * Use KMetaDataModel::items() to get the list of items, where
     * the meta data should be requested. The method is invoked in
     * a custom thread context, so that the user interface won't get
     * blocked if the operation takes longer. The default implementation
     * returns an empty list.
     */
    virtual QHash<KUrl, Nepomuk::Variant> loadData() const;
#endif

signals:
    /**
     * Is emitted after the loading triggered by KMetaDataModel::setItems()
     * has been finished.
     */
    void loadingFinished();

private:
    class Private;
    Private* d;

    Q_PRIVATE_SLOT(d, void slotLoadingFinished())

    friend class KLoadMetaDataThread; // invokes KMetaDataObject::loadData()
};

#endif