~neon/pykde4/master

« back to all changes in this revision

Viewing changes to extra/kde3920/ksycocafactory.h

  • Committer: Simon Edwards
  • Date: 2007-09-02 19:43:19 UTC
  • Revision ID: git-v1:6b8df0c7009f6b218f54589a9bc313cd8c4f82b9

Initial drop of PyKDE4 - Python bindings for the KDE API. See the README file
for more info about the current state of PyKDE4.


svn path=/trunk/KDE/kdebindings/python/pykde4/; revision=707731

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*  This file is part of the KDE libraries
 
2
 *  Copyright (C) 1999 Waldo Bastian <bastian@kde.org>
 
3
 *
 
4
 *  This library is free software; you can redistribute it and/or
 
5
 *  modify it under the terms of the GNU Library General Public
 
6
 *  License version 2 as published by the Free Software Foundation;
 
7
 *
 
8
 *  This library is distributed in the hope that it will be useful,
 
9
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 *  Library General Public License for more details.
 
12
 *
 
13
 *  You should have received a copy of the GNU Library General Public License
 
14
 *  along with this library; see the file COPYING.LIB.  If not, write to
 
15
 *  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 
16
 *  Boston, MA 02110-1301, USA.
 
17
 **/
 
18
 
 
19
#ifndef KSYCOCAFACTORY_H
 
20
#define KSYCOCAFACTORY_H
 
21
 
 
22
#include <ksycocaentry.h>
 
23
 
 
24
class KSycoca;
 
25
class QString;
 
26
class KSycocaDict;
 
27
class KSycocaResourceList;
 
28
template <typename T> class QList;
 
29
template <typename KT, typename VT> class QHash;
 
30
 
 
31
typedef QHash<QString, KSycocaEntry::Ptr> KSycocaEntryDict;
 
32
 
 
33
/**
 
34
 * @internal
 
35
 * Base class for sycoca factories
 
36
 */
 
37
class KDECORE_EXPORT KSycocaFactory
 
38
{
 
39
public:
 
40
    virtual KSycocaFactoryId factoryId() const = 0;
 
41
 
 
42
protected: // virtual class
 
43
    /**
 
44
     * Create a factory which can be used to lookup from/create a database
 
45
     * (depending on KSycoca::isBuilding())
 
46
     */
 
47
    explicit KSycocaFactory( KSycocaFactoryId factory_id );
 
48
 
 
49
public:
 
50
    virtual ~KSycocaFactory();
 
51
 
 
52
    /**
 
53
     * @return the position of the factory in the sycoca file
 
54
     */
 
55
    int offset() const;
 
56
 
 
57
    /**
 
58
     * @return the dict, for special use by KBuildSycoca
 
59
     */
 
60
    KSycocaEntryDict * entryDict() { return m_entryDict; }
 
61
 
 
62
    /**
 
63
     * Construct an entry from a config file.
 
64
     * To be implemented in the real factories.
 
65
     */
 
66
    virtual KSycocaEntry *createEntry(const QString &file, const char *resource) const = 0;
 
67
 
 
68
    /**
 
69
     * Add an entry
 
70
     */
 
71
    virtual void addEntry(const KSycocaEntry::Ptr& newEntry);
 
72
 
 
73
    /**
 
74
     * Remove all entries with the given name.
 
75
     * Not very fast (O(N)), use with care.
 
76
     */
 
77
    void removeEntry(const QString& entryName);
 
78
 
 
79
    /**
 
80
     * Read an entry from the database
 
81
     */
 
82
    virtual KSycocaEntry *createEntry(int offset) const = 0;
 
83
 
 
84
    /**
 
85
     * Get a list of all entries from the database.
 
86
     */
 
87
    virtual KSycocaEntry::List allEntries() const;
 
88
 
 
89
    /**
 
90
     * Saves all entries it maintains as well as index files
 
91
     * for these entries to the stream 'str'.
 
92
     *
 
93
     * Also sets mOffset to the starting position.
 
94
     *
 
95
     * The stream is positioned at the end of the last index.
 
96
     *
 
97
     * Don't forget to call the parent first when you override
 
98
     * this function.
 
99
     */
 
100
    virtual void save(QDataStream &str);
 
101
 
 
102
    /**
 
103
     * Writes out a header to the stream 'str'.
 
104
     * The baseclass positions the stream correctly.
 
105
     *
 
106
     * Don't forget to call the parent first when you override
 
107
     * this function.
 
108
     */
 
109
    virtual void saveHeader(QDataStream &str);
 
110
 
 
111
    /**
 
112
     * @return the resources for which this factory is responsible.
 
113
     * @internal to kbuildsycoca
 
114
     */
 
115
    const KSycocaResourceList * resourceList() const;
 
116
 
 
117
    /**
 
118
     * @return the sycoca dict, for factories to find entries by name.
 
119
     */
 
120
    const KSycocaDict *sycocaDict() const;
 
121
 
 
122
    /**
 
123
     * @return true if the factory is completely empty - no entries defined
 
124
     */
 
125
    bool isEmpty() const;
 
126
 
 
127
protected:
 
128
    QDataStream *m_str;
 
129
 
 
130
    KSycocaResourceList *m_resourceList;
 
131
    KSycocaEntryDict *m_entryDict;
 
132
 
 
133
private:
 
134
    class Private;
 
135
    Private* const d;
 
136
 
 
137
protected:
 
138
    /** Virtual hook, used to add new "virtual" functions while maintaining
 
139
        binary compatibility. Unused in this class.
 
140
    */
 
141
    virtual void virtual_hook( int id, void* data );
 
142
};
 
143
 
 
144
/** This, instead of a typedef, allows to declare "class ..." in header files
 
145
 * @internal
 
146
 */
 
147
class KDECORE_EXPORT KSycocaFactoryList : public QList<KSycocaFactory*> //krazy:exclude=dpointer (acts as a typedef)
 
148
{
 
149
public:
 
150
   KSycocaFactoryList() { }
 
151
};
 
152
 
 
153
#endif