not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / plasma / applets / kickoff / core / models.h
blob0a19bdcf05db99e64b93af2046d45fca6adfa88d
1 /*
2 Copyright 2007 Robert Knight <robertknight@gmail.com>
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 as published by the Free Software Foundation; either
7 version 2 of the License, or (at your option) any later version.
9 This library 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 Library General Public License for more details.
14 You should have received a copy of the GNU Library General Public License
15 along with this library; see the file COPYING.LIB. If not, write to
16 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17 Boston, MA 02110-1301, USA.
20 #ifndef MODELS_H
21 #define MODELS_H
23 // Qt
24 #include <QtGlobal>
26 // KDE
27 #include <KService>
29 class QStandardItem;
30 class KUrl;
31 class QModelIndex;
33 namespace Solid
35 class Device;
38 namespace Kickoff
40 class StandardItemFactoryData
42 public:
43 QHash<QString, Solid::Device> deviceByUrl;
46 StandardItemFactoryData* deviceFactoryData();
48 /**
49 * List of applications contained in the DesktopFiles key in the
50 * SystemApplications group, used to populate the System model
51 * @return list of desktop entry names
53 QStringList systemApplicationList();
55 /**
56 * Additional data roles for data which the Kickoff models supply with their items
57 * for use when rendering the items and launching them.
59 enum DataRole {
60 /** A sub title to be displayed below the text from the item's Qt::DisplayRole data */
61 SubTitleRole = Qt::UserRole + 1,
62 FirstDataRole = SubTitleRole,
63 /** The URL to be opened when executing the item. */
64 UrlRole = Qt::UserRole + 2,
65 /** The Solid device identifier for items which represent devices. */
66 DeviceUdiRole = Qt::UserRole + 3,
67 /** The amount of space (in Kilobytes) used for items which represent storage. */
68 DiskUsedSpaceRole = Qt::UserRole + 4,
69 /** The amount of free space (in Kilobytes) for items which represent storage. */
70 DiskFreeSpaceRole = Qt::UserRole + 5,
71 SubTitleMandatoryRole = Qt::UserRole + 6,
72 LastDataRole = SubTitleMandatoryRole
75 /**
76 * Factory for creating QStandardItems with appropriate text, icons, URL
77 * and other Kickoff-specific information for a given URL or Service.
79 class StandardItemFactory
81 public:
82 static QStandardItem *createItemForUrl(const QString& url);
83 static QStandardItem *createItemForService(KService::Ptr service);
85 private:
86 static void setSpecialUrlProperties(const KUrl& url, QStandardItem *item);
89 /**
90 * Abstract base class for delegates which provide information about a model
91 * item's state in a particular view.
93 class ItemStateProvider
95 public:
96 virtual ~ItemStateProvider() {}
98 /**
99 * Returns true if a @p index should be drawn in the view or
100 * false if it should be hidden.
102 virtual bool isVisible(const QModelIndex& index) const = 0;
105 // returns true if 'first' represents a more recent version of
106 // an application than 'second'
108 // eg. isLaterVersion(myapp_kde4,myapp_kde3) returns true
109 bool isLaterVersion(KService::Ptr first , KService::Ptr second);
111 #if 0
112 /** Swaps the data for two indexes in a QAbstractItemModel */
113 void swapModelIndexes(QModelIndex& first, QModelIndex& second);
114 #endif
116 // returns the Kickoff component data, this is mainly used
117 // to access the Kickoff shared config data
118 KComponentData componentData();
121 #endif //MODELS_H