|
1 /* |
|
2 * ============================================================================ |
|
3 * Name : cpthemelistmodel_p.cpp |
|
4 * Part of : LibHb / theme |
|
5 * Description : Private implementation of the theme listmodel. |
|
6 * Version : %version: 1 % << Don't touch! Updated by Synergy at check-out. |
|
7 * |
|
8 * Copyright (c) 2008-2009 Nokia. All rights reserved. |
|
9 * This material, including documentation and any related computer |
|
10 * programs, is protected by copyright controlled by Nokia. All |
|
11 * rights are reserved. Copying, including reproducing, storing, |
|
12 * adapting or translating, any or all of this material requires the |
|
13 * prior written consent of Nokia. This material also contains |
|
14 * confidential information which may not be disclosed to others |
|
15 * without the prior written consent of Nokia. |
|
16 * ============================================================================ |
|
17 */ |
|
18 |
|
19 #include "cpthemelistmodel.h" |
|
20 #include "cpthemechanger_p.h" |
|
21 #include <QFileSystemWatcher> |
|
22 |
|
23 /* |
|
24 CpThemeChangerModel provides an interface to the data contained in the |
|
25 CpThemeChanger using QAbstractListModel. |
|
26 */ |
|
27 |
|
28 /* |
|
29 Constructor |
|
30 */ |
|
31 CpThemeListModel::CpThemeListModel(CpThemeChangerPrivate *dd, QObject* parent) |
|
32 : QAbstractListModel(parent) |
|
33 , mThemeChangerPrivate(dd) |
|
34 { |
|
35 connect(dd->mFileWatcher, SIGNAL(directoryChanged(const QString&)), |
|
36 this, SLOT(themeListChanged())); |
|
37 } |
|
38 |
|
39 /* |
|
40 Destructor |
|
41 */ |
|
42 CpThemeListModel::~CpThemeListModel() |
|
43 { |
|
44 |
|
45 } |
|
46 |
|
47 /* |
|
48 Reimplemented from QAbstractListModel. |
|
49 */ |
|
50 int CpThemeListModel::rowCount(const QModelIndex&) const |
|
51 { |
|
52 return mThemeChangerPrivate->mThemeList.size(); |
|
53 } |
|
54 |
|
55 /* |
|
56 Reimplemented from QAbstractListModel. Provides the data for Qt::DisplayRole and |
|
57 Qt::DecorationRole. |
|
58 */ |
|
59 QVariant CpThemeListModel::data(const QModelIndex& index, int role) const |
|
60 { |
|
61 QVariant retVal = QVariant(); |
|
62 |
|
63 if (index.isValid()) { |
|
64 switch (role) { |
|
65 case Qt::DisplayRole: |
|
66 retVal = mThemeChangerPrivate->mThemeList.at(index.row()).name; |
|
67 break; |
|
68 |
|
69 case Qt::DecorationRole: |
|
70 retVal = mThemeChangerPrivate->mThemeList.at(index.row()).icon; |
|
71 break; |
|
72 |
|
73 case Qt::SizeHintRole: |
|
74 retVal = mThemeChangerPrivate->mThemeList.at(index.row()).icon.size(); |
|
75 break; |
|
76 |
|
77 case CpThemeChanger::PortraitPreviewRole: |
|
78 retVal = mThemeChangerPrivate->mThemeList.at(index.row()).portraitPreviewIcon; |
|
79 break; |
|
80 |
|
81 case CpThemeChanger::LandscapePreviewRole: |
|
82 retVal = mThemeChangerPrivate->mThemeList.at(index.row()).landscapePreviewIcon; |
|
83 break; |
|
84 |
|
85 default: |
|
86 // do nothing |
|
87 qt_noop(); |
|
88 } |
|
89 } |
|
90 |
|
91 return retVal; |
|
92 } |
|
93 |
|
94 /* |
|
95 Responds appropriately when the underlying data in the theme changer is modified. |
|
96 |
|
97 Unfortunately the directory watcher from QFileWatcher only says when something changed |
|
98 not what changed. Therefore the model is considered reset rather than having rows |
|
99 with dataChanged. |
|
100 */ |
|
101 void CpThemeListModel::themeListChanged() |
|
102 { |
|
103 beginResetModel(); |
|
104 |
|
105 mThemeChangerPrivate->themes(); |
|
106 |
|
107 endResetModel(); |
|
108 } |