12 * Contributors: |
12 * Contributors: |
13 * |
13 * |
14 * Description: |
14 * Description: |
15 * |
15 * |
16 */ |
16 */ |
|
17 #include <QString> |
17 |
18 |
18 #include "cpthemechanger.h" |
19 #include "cpthemechanger.h" |
19 #include "cpthemechanger_p.h" |
20 #include "cpthemeutil.h" |
20 #include "cpthemelistmodel.h" |
21 #include "cpthemeinfo.h" |
|
22 |
|
23 #include <hbinstance.h> |
|
24 #include <restricted/hbthemeservices_r.h> |
21 |
25 |
22 /*! |
26 /*! |
23 @alpha |
|
24 \class CpThemeChanger |
27 \class CpThemeChanger |
25 |
28 |
26 \brief CpThemeChanger provides an interface for changing the current |
29 \brief CpThemeChanger provides an interface for changing the current |
27 theme and enumerating the available themes (e.g., for the UI to provide |
30 theme. |
28 a list of themes to show). |
|
29 |
|
30 This API is only for use with the control panel and its theme |
31 This API is only for use with the control panel and its theme |
31 changing plugin. |
32 changing plugin. |
32 */ |
33 */ |
33 |
34 |
34 /*! |
35 /*! |
35 Constructor. |
36 Constructor. |
36 */ |
37 */ |
37 CpThemeChanger::CpThemeChanger(QObject* p) : |
38 CpThemeChanger::CpThemeChanger(QObject* p) : |
38 QObject(p), |
39 QObject(p), |
39 d_ptr(new CpThemeChangerPrivate(this)) |
40 mCurrentTheme(0) |
40 { |
41 { |
|
42 connect(hbInstance->theme(),SIGNAL(changeFinished()), this, SLOT(changeFinished())); |
|
43 |
|
44 setCurrentTheme(); |
41 } |
45 } |
42 |
46 |
43 /*! |
47 /*! |
44 Provides a list of themes as a const QAbstractItemModel*. |
48 Returns a ThemeInfo object containing the current theme name and |
|
49 corresponding icons. |
|
50 |
|
51 If no repersentative icons exist, the HbIcon returned will be |
|
52 uninitialized. |
45 */ |
53 */ |
46 QAbstractItemModel& CpThemeChanger::model() |
54 const CpThemeInfo* CpThemeChanger::currentTheme() const |
47 { |
55 { |
48 Q_D(CpThemeChanger); |
56 return mCurrentTheme; |
|
57 } |
49 |
58 |
50 return d->mModel; |
59 /*! |
|
60 * Private helper function that gets the current theme from hbinstance and s |
|
61 * ets class' current theme. |
|
62 */ |
|
63 void CpThemeChanger::setCurrentTheme() |
|
64 { |
|
65 QString themeName = ""; |
|
66 if (HbInstance::instance()) { |
|
67 HbTheme *hbTheme = HbInstance::instance()->theme(); |
|
68 if(hbTheme) { |
|
69 themeName = hbTheme->name(); |
|
70 } |
|
71 |
|
72 } |
|
73 |
|
74 if(mCurrentTheme && mCurrentTheme->name() == themeName) { |
|
75 return; |
|
76 } |
|
77 else { |
|
78 //buildThemeInfo creates new theme info. |
|
79 CpThemeInfo* tmpTheme = CpThemeUtil::buildThemeInfo(HbThemeServices::themePath(), themeName); |
|
80 |
|
81 //delete old value. set the new value. |
|
82 if(tmpTheme) { |
|
83 if(mCurrentTheme){ |
|
84 delete mCurrentTheme; |
|
85 } |
|
86 mCurrentTheme = tmpTheme; |
|
87 } |
|
88 } |
51 } |
89 } |
52 |
90 |
53 |
91 |
54 /*! |
92 /*! |
55 Creates a connection to the theme server for the purpose of |
|
56 changing the theme. |
|
57 */ |
|
58 bool CpThemeChanger::connectToServer() |
|
59 { |
|
60 Q_D(CpThemeChanger); |
|
61 |
|
62 return d->connectToServer(); |
|
63 } |
|
64 |
|
65 /*! |
|
66 Indicates if the client is connected to the theme server. |
|
67 */ |
|
68 bool CpThemeChanger::isConnected() const |
|
69 { |
|
70 Q_D(const CpThemeChanger); |
|
71 |
|
72 return d->isConnected(); |
|
73 } |
|
74 |
|
75 |
|
76 /*! |
|
77 Returns a ThemeInfo struct containing the current theme name and |
|
78 a repersentative HbIcon. |
|
79 |
|
80 If no repersentative icon exists, the HbIcon returned will be |
|
81 uninitialized. |
|
82 */ |
|
83 const CpThemeChanger::ThemeInfo& CpThemeChanger::currentTheme() const |
|
84 { |
|
85 Q_D(const CpThemeChanger); |
|
86 |
|
87 return d->currentTheme(); |
|
88 } |
|
89 |
|
90 /* |
|
91 * Returns index of theme from the theme list (not the model). |
|
92 */ |
|
93 int CpThemeChanger::indexOf(const ThemeInfo& theme) const |
|
94 { |
|
95 Q_D(const CpThemeChanger); |
|
96 |
|
97 return d->indexOf(theme); |
|
98 } |
|
99 |
|
100 /*! |
|
101 Change a theme. Returns true on success, false otherwise. |
93 Change a theme. Returns true on success, false otherwise. |
102 */ |
94 */ |
103 bool CpThemeChanger::changeTheme(const QString& newtheme) |
95 bool CpThemeChanger::changeTheme(const QString& newTheme) |
104 { |
96 { |
105 Q_D(CpThemeChanger); |
97 bool result = false; |
|
98 // Skip doing this if the request is for the current theme |
|
99 if (newTheme.isEmpty() || newTheme == mCurrentTheme->name()) { |
|
100 return result; |
|
101 } |
106 |
102 |
107 return d->changeTheme(newtheme); |
103 QString themePath = CpThemeUtil::themePath(newTheme); |
|
104 |
|
105 if(!themePath.isEmpty()) { |
|
106 HbThemeServices::setTheme(themePath); |
|
107 result = true; |
|
108 } |
|
109 return result; |
108 } |
110 } |
109 |
111 |
110 /*! |
112 /*! |
111 Destructor |
113 Destructor |
112 */ |
114 */ |
113 CpThemeChanger::~CpThemeChanger() |
115 CpThemeChanger::~CpThemeChanger() |
114 { |
116 { |
115 delete d_ptr; |
117 delete mCurrentTheme; |
116 d_ptr = 0; |
118 mCurrentTheme = 0; |
117 } |
119 } |
118 |
120 |
119 #include "moc_cpthemechanger.cpp" |
121 /*! |
|
122 * Slot to handle notification from theme server that theme change |
|
123 * is done. Notify the owner. |
|
124 */ |
|
125 void CpThemeChanger::changeFinished() |
|
126 { |
|
127 |
|
128 setCurrentTheme(); |
|
129 |
|
130 emit themeChangeFinished(); |
|
131 } |
120 |
132 |
121 // End of file |
133 // End of file |
122 |
134 |