1/* This file is part of the KDE libraries
2 * Copyright (C) 1999 David Faure <faure@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#ifndef KDED_KBUILDSYCOCA_H
19#define KDED_KBUILDSYCOCA_H
20
21#include "kbuildsycocainterface.h"
22
23#include <sys/stat.h>
24
25#include <QtCore/QObject>
26#include <QtCore/QString>
27
28#include <kservice.h>
29#include <ksycoca.h>
30#include <ksycocatype.h>
31#include <ksycocaentry.h>
32#include <kservicegroup.h>
33
34#include "vfolder_menu.h"
35
36class QDataStream;
37
38// No need for this in libkio - apps only get readonly access
39class KBuildSycoca : public KSycoca, public KBuildSycocaInterface
40{
41 Q_OBJECT
42public:
43 KBuildSycoca();
44 virtual ~KBuildSycoca();
45
46 /**
47 * Recreate the database file
48 */
49 bool recreate();
50
51 static bool checkTimestamps( quint32 timestamp, const QStringList &dirs );
52
53 static QStringList existingResourceDirs();
54
55 void setTrackId(const QString &id) { m_trackId = id; }
56
57 QStringList changedResources() const { return m_changedResources; }
58
59 // Use our friendly-access-to-KSycoca to make this public
60 static void clearCaches() { KSycoca::clearCaches(); }
61
62private:
63 /**
64 * Add single entry to the sycoca database.
65 * Either from a previous database or regenerated from file.
66 */
67 KSycocaEntry::Ptr createEntry(const QString &file, bool addToFactory);
68
69 /**
70 * Implementation of KBuildSycocaInterface
71 * Create service and return it. The caller must add it to the servicefactory.
72 */
73 /*! \reimp */ KService::Ptr createService(const QString& path);
74
75 /**
76 * Convert a VFolderMenu::SubMenu to KServiceGroups.
77 */
78 void createMenu(const QString &caption, const QString &name, VFolderMenu::SubMenu *menu);
79
80 /**
81 * Build the whole system cache, from .desktop files
82 */
83 bool build();
84
85 /**
86 * Save the ksycoca file
87 */
88 void save(QDataStream* str);
89
90 /**
91 * Clear the factories
92 */
93 void clear();
94
95 static bool checkDirTimestamps( const QString& dir, const QDateTime& stamp, bool top );
96
97 /**
98 * @internal
99 * @return true if building (i.e. if a KBuildSycoca);
100 */
101 virtual bool isBuilding() { return true; }
102
103 QStringList m_changedResources;
104 QStringList m_allResourceDirs;
105 QString m_trackId;
106};
107
108#endif
109