| 1251 | } |
| 1252 | |
| 1253 | QString UBGraphicsW3CWidgetItem::createNPAPIWrapperInDir(const QString& pUrl, const QDir& pDir, const QString& pMimeType, const QSize& sizeHint, const QString& pName) |
| 1254 | { |
| 1255 | QString url = pUrl; |
| 1256 | url = UBFileSystemUtils::removeLocalFilePrefix(url); |
| 1257 | QString name = pName; |
| 1258 | |
| 1259 | QFileInfo fi(url); |
| 1260 | |
| 1261 | if (name.length() == 0) |
| 1262 | name = fi.baseName(); |
| 1263 | |
| 1264 | if (fi.exists()) |
| 1265 | url = fi.fileName(); |
| 1266 | |
| 1267 | loadNPAPIWrappersTemplates(); |
| 1268 | |
| 1269 | QString htmlTemplate; |
| 1270 | |
| 1271 | if (pMimeType.length() > 0 && sNPAPIWrapperTemplates.contains(pMimeType)) |
| 1272 | htmlTemplate = sNPAPIWrapperTemplates.value(pMimeType); |
| 1273 | else { |
| 1274 | QString extension = UBFileSystemUtils::extension(url); |
| 1275 | if (sNPAPIWrapperTemplates.contains(extension)) |
| 1276 | htmlTemplate = sNPAPIWrapperTemplates.value(extension); |
| 1277 | } |
| 1278 | |
| 1279 | if (htmlTemplate.length() > 0) { |
| 1280 | htmlTemplate = htmlTemplate.replace(QString("{in.url}"), url) |
| 1281 | .replace(QString("{in.width}"), QString("%1").arg(sizeHint.width())) |
| 1282 | .replace(QString("{in.height}"), QString("%1").arg(sizeHint.height())); |
| 1283 | |
| 1284 | QString configTemplate = sNPAPIWrappperConfigTemplate |
| 1285 | .replace(QString("{in.id}"), url) |
| 1286 | .replace(QString("{in.width}"), QString("%1").arg(sizeHint.width())) |
| 1287 | .replace(QString("{in.height}"), QString("%1").arg(sizeHint.height())) |
| 1288 | .replace(QString("{in.name}"), name) |
| 1289 | .replace(QString("{in.startFile}"), QString("index.htm")); |
| 1290 | |
| 1291 | QString dirPath = pDir.path(); |
| 1292 | if (!pDir.exists()) |
| 1293 | pDir.mkpath(dirPath); |
| 1294 | |
| 1295 | QString widgetLibraryPath = dirPath + "/" + name + ".wgt"; |
| 1296 | QDir widgetLibraryDir(widgetLibraryPath); |
| 1297 | |
| 1298 | if (widgetLibraryDir.exists()) |
| 1299 | if (!UBFileSystemUtils::deleteDir(widgetLibraryDir.path())) |
| 1300 | qWarning() << "Cannot delete old widget " << widgetLibraryDir.path(); |
| 1301 | |
| 1302 | widgetLibraryDir.mkpath(widgetLibraryPath); |
| 1303 | if (fi.exists()) { |
| 1304 | QString target = widgetLibraryPath + "/" + fi.fileName(); |
| 1305 | QString source = pUrl; |
| 1306 | source = UBFileSystemUtils::removeLocalFilePrefix(source); |
| 1307 | QFile::copy(source, target); |
| 1308 | } |
| 1309 | |
| 1310 | QFile configFile(widgetLibraryPath + "/config.xml"); |