add more spacing
[personal-kdebase.git] / workspace / kcontrol / input / xcursor / thememodel.h
blob0e20c1e9943f7c2b2e3857ac43ada370357d7336
1 /*
2 * Copyright © 2005-2007 Fredrik Höglund <fredrik@kde.org>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License version 2 or at your option version 3 as published
7 * by the Free Software Foundation.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; see the file COPYING. If not, write to
16 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 * Boston, MA 02110-1301, USA.
20 #ifndef THEMEMODEL_H
21 #define THEMEMODEL_H
23 #include <QAbstractTableModel>
24 #include <QStringList>
26 class QDir;
27 class CursorTheme;
29 // The two TableView/TreeView columns provided by the model
30 enum Columns { NameColumn = 0, DescColumn };
33 /**
34 * The CursorThemeModel class provides a model for all locally installed
35 * Xcursor themes, and the KDE/Qt legacy bitmap theme.
37 * This class automatically scans the locations in the file system from
38 * which Xcursor loads cursors, and creates an internal list of all
39 * available cursor themes.
41 * The model provides this theme list to item views in the form of a list
42 * of rows with two columns; the first column has the theme's descriptive
43 * name and its sample cursor as its icon, and the second column contains
44 * the theme's description.
46 * Additional Xcursor themes can be added to a model after it's been
47 * created, by calling addTheme(), which takes QDir as a parameter,
48 * with the themes location. The intention is for this function to be
49 * called when a new Xcursor theme has been installed, after the model
50 * was instantiated.
52 * The KDE legacy theme is a read-only entry, with the descriptive name
53 * "KDE Classic", and the internal name "#kde_legacy#".
55 * Calling defaultIndex() will return the index of the theme Xcursor
56 * will use if the user hasn't explicitly configured a cursor theme.
58 class CursorThemeModel : public QAbstractTableModel
60 Q_OBJECT
62 public:
63 CursorThemeModel(QObject *parent = 0);
64 ~CursorThemeModel();
65 inline int columnCount(const QModelIndex &parent = QModelIndex()) const;
66 inline int rowCount(const QModelIndex &parent = QModelIndex()) const;
67 QVariant headerData(int section, Qt::Orientation orientation, int role) const;
68 QVariant data(const QModelIndex &index, int role) const;
69 void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
71 /// Returns the CursorTheme at @p index.
72 const CursorTheme *theme(const QModelIndex &index);
74 /// Returns the index for the CursorTheme with the internal name @p name,
75 /// or an invalid index if no matching theme can be found.
76 QModelIndex findIndex(const QString &name);
78 /// Returns the index for the default theme.
79 QModelIndex defaultIndex();
81 /// Adds the theme in @p dir, and returns @a true if successful or @a false otherwise.
82 bool addTheme(const QDir &dir);
83 void removeTheme(const QModelIndex &index);
85 /// Returns the list of base dirs Xcursor looks for themes in.
86 const QStringList searchPaths();
88 private:
89 bool handleDefault(const QDir &dir);
90 void processThemeDir(const QDir &dir);
91 void insertThemes();
92 bool hasTheme(const QString &theme) const;
93 bool isCursorTheme(const QString &theme, const int depth = 0);
95 private:
96 QList<CursorTheme*> list;
97 QStringList baseDirs;
98 QString defaultName;
101 int CursorThemeModel::rowCount(const QModelIndex &) const
103 return list.count();
106 int CursorThemeModel::columnCount(const QModelIndex &) const
108 return 2;
111 #endif // THEMEMODEL_H