Make a branch to make krunner Good Enough For Aaron™.
[kdebase/uwolfer.git] / workspace / plasma / applets / kickoff / core / models.h
blobb773cfa43c781d5199f92a8ec63d86fcfc2b4246
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 * Additional data roles for data which the Kickoff models supply with their items
50 * for use when rendering the items and launching them.
52 enum DataRole
54 /** A sub title to be displayed below the text from the item's Qt::DisplayRole data */
55 SubTitleRole = Qt::UserRole+1,
56 FirstDataRole = SubTitleRole,
57 /** The URL to be opened when executing the item. */
58 UrlRole = Qt::UserRole + 2,
59 /** The Solid device identifier for items which represent devices. */
60 DeviceUdiRole = Qt::UserRole + 3,
61 /** The amount of space (in Kilobytes) used for items which represent storage. */
62 DiskUsedSpaceRole = Qt::UserRole + 4,
63 /** The amount of free space (in Kilobytes) for items which represent storage. */
64 DiskFreeSpaceRole = Qt::UserRole + 5,
65 SubTitleMandatoryRole = Qt::UserRole + 6,
66 LastDataRole = SubTitleMandatoryRole
69 /**
70 * Factory for creating QStandardItems with appropriate text, icons, URL
71 * and other Kickoff-specific information for a given URL or Service.
73 class StandardItemFactory
75 public:
76 static QStandardItem *createItemForUrl(const QString& url);
77 static QStandardItem *createItemForService(KService::Ptr service);
79 private:
80 static void setSpecialUrlProperties(const KUrl& url,QStandardItem *item);
83 /**
84 * Abstract base class for delegates which provide information about a model
85 * item's state in a particular view.
87 class ItemStateProvider
89 public:
90 virtual ~ItemStateProvider() {}
92 /**
93 * Returns true if a @p index should be drawn in the view or
94 * false if it should be hidden.
96 virtual bool isVisible(const QModelIndex& index) const = 0;
99 // returns true if 'first' represents a more recent version of
100 // an application than 'second'
102 // eg. isLaterVersion(myapp_kde4,myapp_kde3) returns true
103 bool isLaterVersion(KService::Ptr first , KService::Ptr second);
105 #if 0
106 /** Swaps the data for two indexes in a QAbstractItemModel */
107 void swapModelIndexes(QModelIndex& first,QModelIndex& second);
108 #endif
110 // returns the Kickoff component data, this is mainly used
111 // to access the Kickoff shared config data
112 KComponentData componentData();
115 #endif //MODELS_H