|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0"" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 #include "cputility.h" |
|
18 #include <QString> |
|
19 #include <QDir> |
|
20 #include <QFileInfo> |
|
21 #include "cpbasepath.h" |
|
22 #include <cppluginloader.h> |
|
23 #include <cpplugininterface.h> |
|
24 #include <cppluginplatinterface.h> |
|
25 #include <cplogger.h> |
|
26 #include <cpsettingformentryitemdata.h> |
|
27 #include "cpcategorysettingformitemdata.h" |
|
28 #include "cppluginconfigreader.h" |
|
29 #include "cpplaceholderitemdata.h" |
|
30 |
|
31 void CpUtility::buildConfigPluginItems(HbDataFormModelItem *parent, |
|
32 const QString &configFile, |
|
33 CpItemDataHelper &itemDataHelper) |
|
34 { |
|
35 if (!parent) { |
|
36 return; |
|
37 } |
|
38 |
|
39 QString configPath(configFile); |
|
40 QFileInfo fi(configFile); |
|
41 //if it is a relative path, search the config file from device drives. |
|
42 if (!fi.isAbsolute()) { |
|
43 QStringList dirs = CpUtility::configFileDirectories(); |
|
44 foreach(const QString &dir,dirs) { |
|
45 configPath = dir + fi.fileName(); |
|
46 if (QFileInfo(configPath).exists()) { |
|
47 CPFW_LOG(configPath + " has been found."); |
|
48 break; |
|
49 } |
|
50 } |
|
51 } |
|
52 |
|
53 QList<CpPluginConfig> pluginConfigs = CpPluginConfigReader(configPath).readCpPluginConfigs(); |
|
54 |
|
55 foreach(const CpPluginConfig &pluginConfig, pluginConfigs) { |
|
56 CPFW_LOG(QLatin1String("Load plugin: ") + pluginConfig.mPluginFile + " from " + configPath); |
|
57 |
|
58 QList<CpSettingFormItemData*> itemDataList; |
|
59 |
|
60 //firstly, handle CpPluginInterface |
|
61 if (CpPluginInterface *plugin = CpPluginLoader().loadCpPlugin(pluginConfig.mPluginFile)) { |
|
62 CPFW_LOG("Load root component CpPluginInterface succeed."); |
|
63 itemDataList = plugin->createSettingFormItemData(itemDataHelper); |
|
64 } |
|
65 //handle CpPluginPlatInterface |
|
66 else if (CpPluginPlatInterface *plugin = CpPluginLoader().loadPlatCpPlugin(pluginConfig.mPluginFile)) { |
|
67 CPFW_LOG("Load root component CpPluginPlatInterface succeed."); |
|
68 CPFW_LOG("WARNING: CpPluginPlatInterface is deprecated. Please return CpPluginInterface from plugin."); |
|
69 CpSettingFormItemData *itemData = plugin->createSettingFormItemData(itemDataHelper); |
|
70 if (itemData) { |
|
71 itemDataList.append(itemData); |
|
72 } |
|
73 } |
|
74 |
|
75 else { |
|
76 CPFW_LOG(QLatin1String("Load plugin:") + pluginConfig.mPluginFile + QLatin1String(" failed.")); |
|
77 #ifdef _DEBUG |
|
78 CPFW_LOG(QLatin1String("***Add a placeholder.")); |
|
79 parent->appendChild(new CpPlaceHolderItemData(itemDataHelper,pluginConfig)); |
|
80 #endif |
|
81 } |
|
82 |
|
83 if (itemDataList.count()) { |
|
84 foreach(CpSettingFormItemData *itemData,itemDataList) { |
|
85 if (itemData) { |
|
86 //append the new created setting form item to its parent item. |
|
87 parent->appendChild(itemData); |
|
88 |
|
89 if (CpCategorySettingFormItemData *categoryItemData |
|
90 = qobject_cast<CpCategorySettingFormItemData*>(itemData)) { |
|
91 categoryItemData->initialize(itemDataHelper); |
|
92 } |
|
93 |
|
94 //set the description from config if it is empty. |
|
95 if (CpSettingFormEntryItemData *cpEntryItemData |
|
96 = qobject_cast<CpSettingFormEntryItemData*>(itemData)) { |
|
97 if (cpEntryItemData->text().isEmpty()) { |
|
98 cpEntryItemData->setText(pluginConfig.mDisplayName); |
|
99 } |
|
100 if (cpEntryItemData->description().isEmpty()) { |
|
101 cpEntryItemData->setDescription(pluginConfig.mDescription); |
|
102 } |
|
103 } |
|
104 |
|
105 } |
|
106 } //end foreach |
|
107 } |
|
108 |
|
109 } //end foreach |
|
110 } |
|
111 |
|
112 QStringList CpUtility::drives() |
|
113 { |
|
114 static QStringList drives; |
|
115 |
|
116 if (drives.empty()) { |
|
117 CPFW_LOG("device drives:"); |
|
118 #ifdef WIN32 |
|
119 drives.append("C:"); |
|
120 CPFW_LOG("C:"); |
|
121 #else |
|
122 QFileInfoList fileInfoList = QDir::drives(); |
|
123 foreach(const QFileInfo &fileInfo,fileInfoList) { |
|
124 QString str = fileInfo.filePath(); |
|
125 if (str.length() > 2) { |
|
126 str = str.left(2); |
|
127 } |
|
128 drives.append(str); |
|
129 CPFW_LOG(str); |
|
130 } |
|
131 #endif |
|
132 } |
|
133 |
|
134 return drives; |
|
135 } |
|
136 |
|
137 static QStringList directoriesFromAllDrives(const QString &baseDir) |
|
138 { |
|
139 QStringList dirs; |
|
140 |
|
141 QStringList drives = CpUtility::drives(); |
|
142 foreach(const QString &drive,drives) { |
|
143 QString dir = drive + baseDir + QDir::separator(); |
|
144 if (QFileInfo(dir).exists()) { |
|
145 dirs.append(dir); |
|
146 CPFW_LOG(dir); |
|
147 } |
|
148 } |
|
149 |
|
150 return dirs; |
|
151 } |
|
152 |
|
153 QStringList CpUtility::pluginDirectories() |
|
154 { |
|
155 static QStringList dirs; |
|
156 if (dirs.empty()) { |
|
157 CPFW_LOG("ControlPanel plugin derectories:") |
|
158 dirs = directoriesFromAllDrives(CP_PLUGIN_PATH); |
|
159 } |
|
160 return dirs; |
|
161 } |
|
162 |
|
163 QStringList CpUtility::applicationPluginDirectories() |
|
164 { |
|
165 static QStringList dirs; |
|
166 if (dirs.empty()) { |
|
167 CPFW_LOG("ControlPanel application plugin derectories:"); |
|
168 // dirs = directoriesFromAllDrives(CP_APPLICATION_PLUGIN_PATH); |
|
169 } |
|
170 return dirs; |
|
171 } |
|
172 |
|
173 |
|
174 QStringList CpUtility::configFileDirectories() |
|
175 { |
|
176 static QStringList dirs; |
|
177 if (dirs.empty()) { |
|
178 CPFW_LOG("ControlPanel configuration file derectories:"); |
|
179 dirs = directoriesFromAllDrives(CP_PLUGIN_CONFIG_PATH); |
|
180 } |
|
181 return dirs; |
|
182 } |
|
183 |