1 /* BEGIN_COMMON_COPYRIGHT_HEADER
2  * (c)LGPL2+
3  *
4  * LXQt - a lightweight, Qt based, desktop toolset
5  * https://lxqt.org
6  *
7  * Copyright: 2010-2011 Razor team
8  * Authors:
9  *   Alexander Sokoloff <sokoloff.a@gmail.com>
10  *
11  * This program or library is free software; you can redistribute it
12  * and/or modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation; either
14  * version 2.1 of the License, or (at your option) any later version.
15  *
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20 
21  * You should have received a copy of the GNU Lesser General
22  * Public License along with this library; if not, write to the
23  * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA 02110-1301 USA
25  *
26  * END_COMMON_COPYRIGHT_HEADER */
27 
28 #include "xdgmenu.h"
29 #include <QObject>
30 #include <QFileSystemWatcher>
31 #include <QTimer>
32 
33 #define REBUILD_DELAY 3000
34 
35 class QDomElement;
36 class QStringList;
37 class QString;
38 class QDomDocument;
39 
40 class XdgMenuPrivate : public QObject
41 {
42 Q_OBJECT
43 public:
44     XdgMenuPrivate(XdgMenu* parent);
45 
46     void simplify(QDomElement& element);
47     void mergeMenus(QDomElement& element);
48     void moveMenus(QDomElement& element);
49     void deleteDeletedMenus(QDomElement& element);
50     void processDirectoryEntries(QDomElement& element, const QStringList& parentDirs);
51     void processApps(QDomElement& element);
52     void deleteEmpty(QDomElement& element);
53     void processLayouts(QDomElement& element);
54     void fixSeparators(QDomElement& element);
55 
56     bool loadDirectoryFile(const QString& fileName, QDomElement& element);
57     void prependChilds(QDomElement& srcElement, QDomElement& destElement);
58     void appendChilds(QDomElement& srcElement, QDomElement& destElement);
59 
60     void saveLog(const QString& logFileName);
61     void load(const QString& fileName);
62 
63     void clearWatcher();
64 
65     QString mErrorString;
66     QStringList mEnvironments;
67     QString mMenuFileName;
68     QString mLogDir;
69     QDomDocument mXml;
70     QByteArray mHash;
71     QTimer mRebuildDelayTimer;
72 
73     QFileSystemWatcher mWatcher;
74     bool mOutDated;
75 
76 public Q_SLOTS:
77     void rebuild();
78 
79 Q_SIGNALS:
80     void changed();
81 
82 
83 private:
84     XdgMenu* const q_ptr;
85     Q_DECLARE_PUBLIC(XdgMenu)
86 };
87