~ubuntu-branches/ubuntu/quantal/kde-runtime/quantal

« back to all changes in this revision

Viewing changes to nepomuk/services/backupsync/lib/resourceidentifier.h

  • Committer: Package Import Robot
  • Author(s): Philip Muškovac
  • Date: 2012-06-03 21:50:00 UTC
  • mto: This revision was merged to the branch mainline in revision 21.
  • Revision ID: package-import@ubuntu.com-20120603215000-vn7oarsq0ynrydj5
Tags: upstream-4.8.80
Import upstream version 4.8.80

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
    This file is part of the Nepomuk KDE project.
3
 
    Copyright (C) 2010  Vishesh Handa <handa.vish@gmail.com>
4
 
 
5
 
   This library is free software; you can redistribute it and/or
6
 
   modify it under the terms of the GNU Lesser General Public
7
 
   License as published by the Free Software Foundation; either
8
 
   version 2.1 of the License, or (at your option) version 3, or any
9
 
   later version accepted by the membership of KDE e.V. (or its
10
 
   successor approved by the membership of KDE e.V.), which shall
11
 
   act as a proxy defined in Section 6 of version 3 of the license.
12
 
 
13
 
   This library 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 GNU
16
 
   Lesser General Public License for more details.
17
 
 
18
 
   You should have received a copy of the GNU Lesser General Public
19
 
   License along with this library.  If not, see <http://www.gnu.org/licenses/>.
20
 
*/
21
 
 
22
 
 
23
 
#ifndef NEPOMUK_RESOURCEIDENTIFIER_H
24
 
#define NEPOMUK_RESOURCEIDENTIFIER_H
25
 
 
26
 
#include <QtCore/QObject>
27
 
#include <KUrl>
28
 
 
29
 
#include "nepomuksync_export.h"
30
 
 
31
 
namespace Soprano {
32
 
    class Statement;
33
 
    class Graph;
34
 
    class Model;
35
 
}
36
 
 
37
 
namespace Nepomuk {
38
 
 
39
 
    class Resource;
40
 
 
41
 
    namespace Sync {
42
 
 
43
 
        class SyncResource;
44
 
 
45
 
        /**
46
 
         * \class ResourceIdentifier resourceidentifier.h
47
 
         *
48
 
         * This class is used to identify already existing resources from a set of
49
 
         * properties and objects. It identifies the resources on the basis of the
50
 
         * identifying statements provided.
51
 
         *
52
 
         * \author Vishesh Handa <handa.vish@gmail.com>
53
 
         */
54
 
        class NEPOMUKSYNC_EXPORT ResourceIdentifier
55
 
        {
56
 
        public:
57
 
            ResourceIdentifier( Soprano::Model * model = 0 );
58
 
            virtual ~ResourceIdentifier();
59
 
 
60
 
            Soprano::Model * model();
61
 
            void setModel( Soprano::Model * model );
62
 
 
63
 
            //
64
 
            // Processing
65
 
            //
66
 
            void identifyAll();
67
 
 
68
 
            bool identify( const KUrl & uri );
69
 
 
70
 
            /**
71
 
             * Identifies all the resources present in the \p uriList.
72
 
             */
73
 
            void identify( const KUrl::List & uriList );
74
 
 
75
 
            /**
76
 
             * This returns true if ALL the external ResourceUris have been identified.
77
 
             * If this is false, you should manually identify some of the resources by
78
 
             * providing the resource.
79
 
             *
80
 
             * \sa forceResource
81
 
             */
82
 
            bool allIdentified() const;
83
 
 
84
 
            virtual void addStatement( const Soprano::Statement & st );
85
 
            virtual void addStatements( const Soprano::Graph& graph );
86
 
            virtual void addStatements( const QList<Soprano::Statement> & stList );
87
 
            virtual void addSyncResource( const SyncResource & res );
88
 
 
89
 
            //
90
 
            // Getting the info
91
 
            //
92
 
            /**
93
 
             * Returns the detected uri for the given resourceUri.
94
 
             * This method useful only after identifyAll() method was called
95
 
             */
96
 
            KUrl mappedUri( const KUrl & resourceUri ) const;
97
 
 
98
 
            KUrl::List mappedUris() const;
99
 
 
100
 
            /**
101
 
             * Returns mappings of the identified uri
102
 
             */
103
 
            QHash<QUrl, QUrl> mappings() const;
104
 
 
105
 
            /**
106
 
             * Returns urls that were not successfully identified
107
 
             */
108
 
            QSet<KUrl> unidentified() const;
109
 
 
110
 
            QSet< QUrl > identified() const;
111
 
 
112
 
            /**
113
 
             * Returns all the statements that are being used to identify \p uri
114
 
             */
115
 
            Soprano::Graph statements( const KUrl & uri );
116
 
 
117
 
            QList<Soprano::Statement> identifyingStatements() const;
118
 
 
119
 
            SyncResource simpleResource( const KUrl & uri );
120
 
            //
121
 
            // Property Settings
122
 
            //
123
 
            /**
124
 
             * The property \p prop will be matched during identification, but it will
125
 
             * not contribute to the actual score if it cannot be matched.
126
 
             */
127
 
            void addOptionalProperty( const QUrl & property );
128
 
 
129
 
            void clearOptionalProperties();
130
 
 
131
 
            KUrl::List optionalProperties() const;
132
 
 
133
 
            //
134
 
            // Manual Identification
135
 
            //
136
 
            /**
137
 
            * Used for manual identification when both the old Resource uri, and
138
 
            * the new resource Uri is provided.
139
 
            *
140
 
            * If the resource \p res provided is of type nfo:FileDataObject and has
141
 
            * a nie:url. That url will be used to attempt to identify the unidentified
142
 
            * resources having a similar nie:url ( same directory or common base directory )
143
 
            * It does not perform the actual identification, but changes the internal identification
144
 
            * statements so that the unidentified resources may be identified during the next
145
 
            * call to identifyAll
146
 
            *
147
 
            * This method should typically be called after identifyAll has been called at least once.
148
 
            */
149
 
            void forceResource( const KUrl & oldUri, const Resource & res);
150
 
 
151
 
            /**
152
 
             * Ignores resourceUri (It will no longer play a part in identification )
153
 
             * if @p ignoreSub is true and resourceUri is a Folder, all the sub folders
154
 
             * and files are also ignored.
155
 
             *
156
 
             * This is an expensive method. It will also remove all the statements which
157
 
             * contain \p uri as the object.
158
 
             */
159
 
            bool ignore( const KUrl& uri, bool ignoreSub = false );
160
 
 
161
 
            //
162
 
            // Identification Statement generator
163
 
            //
164
 
            static Soprano::Graph createIdentifyingStatements( const KUrl::List & uriList );
165
 
 
166
 
            virtual bool isIdentifyingProperty( const QUrl & uri );
167
 
        private:
168
 
            class Private;
169
 
            Private * d;
170
 
 
171
 
        protected:
172
 
            /**
173
 
            * Called during identification if there is more than one match for one resource.
174
 
            *
175
 
            * The default behavior is to return an empty uri, which depicts identification failure
176
 
            */
177
 
            virtual KUrl duplicateMatch( const KUrl & uri, const QSet<KUrl> & matchedUris );
178
 
 
179
 
            /**
180
 
             * This function returns true if identification was successful, and false if it was not.
181
 
             * If you need to customize the identification process, you will need to overload this
182
 
             * function.
183
 
             */
184
 
            virtual bool runIdentification( const KUrl& uri );
185
 
 
186
 
            /**
187
 
             * Sets oldUri -> newUri in the mappings.
188
 
             * This is useful when runIdentification has been reimplemented.
189
 
             */
190
 
            void manualIdentification( const KUrl & oldUri, const KUrl & newUri );
191
 
        };
192
 
    }
193
 
}
194
 
 
195
 
#endif // NEPOMUK_RESOURCEIDENTIFIER_H