~ubuntu-branches/ubuntu/gutsy/kdebase-workspace/gutsy

« back to all changes in this revision

Viewing changes to kcontrol/input/xcursor/thememodel.h

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Riddell
  • Date: 2007-09-05 20:45:14 UTC
  • Revision ID: james.westby@ubuntu.com-20070905204514-632hhspl0nvrc84i
Tags: upstream-3.93.0
Import upstream version 3.93.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright © 2005-2007 Fredrik Höglund <fredrik@kde.org>
 
3
 *
 
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 as published by the Free Software Foundation.
 
7
 *
 
8
 * This program 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
 * General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU General Public License
 
14
 * along with this program; see the file COPYING.  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 THEMEMODEL_H
 
20
#define THEMEMODEL_H
 
21
 
 
22
#include <QAbstractTableModel>
 
23
#include <QStringList>
 
24
 
 
25
class QDir;
 
26
class CursorTheme;
 
27
 
 
28
// The two TableView/TreeView columns provided by the model
 
29
enum Columns { NameColumn = 0, DescColumn };
 
30
 
 
31
 
 
32
/**
 
33
 * The CursorThemeModel class provides a model for all locally installed
 
34
 * Xcursor themes, and the KDE/Qt legacy bitmap theme.
 
35
 *
 
36
 * This class automatically scans the locations in the file system from
 
37
 * which Xcursor loads cursors, and creates an internal list of all
 
38
 * available cursor themes.
 
39
 *
 
40
 * The model provides this theme list to item views in the form of a list
 
41
 * of rows with two columns; the first column has the theme's descriptive
 
42
 * name and its sample cursor as its icon, and the second column contains
 
43
 * the theme's description.
 
44
 *
 
45
 * Additional Xcursor themes can be added to a model after it's been
 
46
 * created, by calling addTheme(), which takes QDir as a parameter,
 
47
 * with the themes location. The intention is for this function to be
 
48
 * called when a new Xcursor theme has been installed, after the model
 
49
 * was instantiated.
 
50
 *
 
51
 * The KDE legacy theme is a read-only entry, with the descriptive name
 
52
 * "KDE Classic", and the internal name "#kde_legacy#".
 
53
 *
 
54
 * Calling defaultIndex() will return the index of the theme Xcursor
 
55
 * will use if the user hasn't explicitly configured a cursor theme.
 
56
 */
 
57
class CursorThemeModel : public QAbstractTableModel
 
58
{
 
59
    Q_OBJECT
 
60
 
 
61
    public:
 
62
        CursorThemeModel(QObject *parent = 0);
 
63
        inline int columnCount(const QModelIndex &parent = QModelIndex()) const;
 
64
        inline int rowCount(const QModelIndex &parent = QModelIndex()) const;
 
65
        QVariant headerData(int section, Qt::Orientation orientation, int role) const;
 
66
        QVariant data(const QModelIndex &index, int role) const;
 
67
        void sort(int column, Qt::SortOrder order = Qt::AscendingOrder);
 
68
 
 
69
        /// Returns the CursorTheme at @p index.
 
70
        const CursorTheme *theme(const QModelIndex &index);
 
71
 
 
72
        /// Returns the index for the CursorTheme with the internal name @p name,
 
73
        /// or an invalid index if no matching theme can be found.
 
74
        QModelIndex findIndex(const QString &name);
 
75
 
 
76
        /// Returns the index for the default theme.
 
77
        QModelIndex defaultIndex();
 
78
 
 
79
        /// Adds the theme in @p dir, and returns @a true if successful or @a false otherwise.
 
80
        bool addTheme(const QDir &dir);
 
81
        void removeTheme(const QModelIndex &index);
 
82
 
 
83
        /// Returns the list of base dirs Xcursor looks for themes in.
 
84
        const QStringList searchPaths();
 
85
 
 
86
    private:
 
87
        bool handleDefault(const QDir &dir);
 
88
        void processThemeDir(const QDir &dir);
 
89
        void insertThemes();
 
90
        bool hasTheme(const QString &theme) const;
 
91
        bool isCursorTheme(const QString &theme, const int depth = 0);
 
92
 
 
93
    private:
 
94
        QList<CursorTheme*> list;
 
95
        QStringList baseDirs;
 
96
        QString defaultName;
 
97
};
 
98
 
 
99
int CursorThemeModel::rowCount(const QModelIndex &) const
 
100
{
 
101
    return list.count();
 
102
}
 
103
 
 
104
int CursorThemeModel::columnCount(const QModelIndex &) const
 
105
{
 
106
    return 2;
 
107
}
 
108
 
 
109
#endif // THEMEMODEL_H