void writePreserving(QFile& inFile, QTextStream& out, const AttributeMap& data) { FNTRACE("ini", "", "writePreserving", QString("in, out, %1 rows of data").arg(data.size())); int i, j; QChar c; QString name; size_t lineNumber = 0; QString line; typedef QSet<AttributeMap::key_type> KeySet; KeySet unwrittenKeys = KeySet::fromList(data.keys()); if (!inFile.open(QIODevice::ReadOnly | QIODevice::Text)) ETHROW(Exception(QString("Unable to open %1 for reading.").arg(inFile.fileName()))); QTextStream in(&inFile); while (!(line = in.readLine()).isNull()) { ++lineNumber; //std::cout << lineNumber << ": " << line.toStdString() << ":\n"; for (i = 0; line[i].isSpace(); ++i) { out << line[i]; } if (line[i].isNull()) { out << '\n'; continue; } else if (line[i] == COMMENT_BEGIN) { out << line.mid(i) << '\n'; continue; } for (j = i; !(c = line[i]).isNull() && c!=COMMENT_BEGIN && c!=ASSIGNER; ++i) ; //std::cout << "non-empty, "; if (c != ASSIGNER) // non-empty line that isn't assignment -> invalid ETHROW(ParseError(inFile.fileName(), lineNumber, "Unknown non-empty line.")); for (--i; line[i].isSpace(); --i) ; // last character of name name = line.mid(j, i - j + 1); //std::cout << "name: " << name.toStdString() << ' '; for ( ; line[j]!=ASSIGNER; ++j) out << line[j]; out << ASSIGNER; i = j + 1; for ( ; line[i].isSpace(); ++i) out << line[i]; if (data.contains(name)) { //std::cout << "known "; out << data.value(name); unwrittenKeys.remove(name); for (j = i; !line[i].isNull() && line[i]!=COMMENT_BEGIN; ++i) ; // EOL || comment for (--i; line[i].isSpace(); --i) ; // last character of value ++i; // first character after value } out << line.mid(i) << '\n'; //std::cout << '\n'; } if (unwrittenKeys.size()) { out << '\n' << COMMENT_BEGIN << "Following lines were generated by Ds1edit Loader:\n"; for (KeySet::iterator key = unwrittenKeys.begin(); key != unwrittenKeys.end(); ++key) out << (*key) << ' ' << ASSIGNER << ' ' << data.value(*key) << '\n'; } //in.resize(in.pos()+1); inFile.close(); }
bool WidgetRegistrationS60::registerAppL(const QString& appId, const QString& appTitle, const QString& appPath, const QString& dataPath, const QString& iconPath, const AttributeMap& attr, const QString& type, unsigned long size, const QString& startPath, int& widgetUid, QString& convertedIconPath, bool hideIcon) { LOG("WidgetRegistrationS60::registerAppL()" << " appId : " << appId << " appTitle : " << appTitle << " appPath : " << appPath << " iconPath : " << iconPath << " startPath : " << startPath); if (appId.isEmpty() || appTitle.isEmpty() || appPath.isEmpty()) return false; // S60 requires widgetProps as CWidgetPropertyValue RPointerArray<CWidgetPropertyValue> propertyValues(EWidgetPropertyIdCount); CleanupStack::PushL(TCleanupItem(PointerArrayCleanup, &propertyValues)); // pushed 1 RWidgetRegistryClientSession registryClient; User::LeaveIfError(registryClient.Connect()); CleanupClosePushL( registryClient ); // pushed 2 RFs rfs; User::LeaveIfError(rfs.Connect()); CleanupClosePushL(rfs); // pushed 3 User::LeaveIfError(rfs.ShareProtected()); // empty values for (TInt i = 0; i < EWidgetPropertyIdCount; ++i) { CWidgetPropertyValue* value = CWidgetPropertyValue::NewL(); CleanupStack::PushL(value); // pushed 4 propertyValues.AppendL(value); CleanupStack::Pop(value); // pushed 3 } *(propertyValues[EWidgetPropertyListVersion]) = KWidgetPropertyListVersion71CWRT; *(propertyValues[EFileSize]) = size; SwiUI::CWidgetRegistrationS60Apparc* appArc = SwiUI::CWidgetRegistrationS60Apparc::NewL(rfs); CleanupStack::PushL(appArc); // pushed 4 // get drive letter from appPath TUint driveLetter = appPath[0].unicode(); // Generate our UID based on UIDs in the Qt WidgetRegistry int iUid = WebAppRegistry::instance()->nextAvailableUid(); widgetUid = iUid; if (iUid == 0) { LOG("WidgetRegistrationS60::registerAppL() - registryClient.GetAvailableUidL() failed"); CleanupStack::PopAndDestroy( 4, &propertyValues ); return false; } // convert icon to required format and sizes QString newIconPath = ""; if (!processIconL(iUid, newIconPath, iconPath, QDir::toNativeSeparators(dataPath))) { LOG("WidgetRegistrationS60::registerAppL() - processIconL() failed"); CleanupStack::PopAndDestroy( 4, &propertyValues ); return false; } // FIXME this translation doesn't cover all cases, if generalized // must cover S60 WRT names and W3C names QString appPathNative = QDir::toNativeSeparators(appPath); // FIXME enforce canonicalization in caller // must end in QDir::separator() if (QDir::separator() != appPathNative.at(appPathNative.count()-1)) { appPathNative.append(QDir::separator()); } TPtrC16 basePathSymbian(reinterpret_cast<const TUint16*> (appPathNative.constData())); *(propertyValues[EBasePath]) = basePathSymbian; QString driveName = appPathNative.left(2); TPtrC16 driveNameSymbian(reinterpret_cast<const TUint16*> (driveName.constData())); *(propertyValues[EDriveName]) = driveNameSymbian; TPtrC16 mainHtmlSymbian(reinterpret_cast<const TUint16*> (startPath.constData())); *(propertyValues[EMainHTML]) = mainHtmlSymbian; TPtrC16 identifierSymbian(reinterpret_cast<const TUint16*> (appId.constData())); *(propertyValues[EBundleIdentifier]) = identifierSymbian; if (attr.contains(W3CSettingsKey::WIDGET_VERSION)) { QString ver = attr.value(W3CSettingsKey::WIDGET_VERSION).toString(); if(!(ver.isEmpty())) { TPtrC16 version(reinterpret_cast<const TUint16*> (attr.value(W3CSettingsKey::WIDGET_VERSION).toString().constData())); *(propertyValues[EBundleVersion]) = version; } } if (appTitle.isEmpty()) { // FIXME this probably should cause registration failure *(propertyValues[EBundleDisplayName]) = identifierSymbian; } else { TPtrC16 titleSymbian(reinterpret_cast<const TUint16*> (appTitle.constData())); *(propertyValues[EBundleDisplayName]) = titleSymbian; } // TODO: We decided to drop BundleName and just use // DisplayName but the registry code has errors in it and uses // BundleName when it should use DisplayName so as a workaround, // set BundleName to DisplayName. Should eventually remove // BundleName from set of registry values. const TDesC& name = *(propertyValues[EBundleDisplayName]); *(propertyValues[EBundleName]) = name; convertedIconPath = newIconPath; if (!newIconPath.isEmpty()) { // FIXME enforce canonicalization in caller // strangely icon path doesn't include icon file name int li = newIconPath.lastIndexOf(QDir::separator()); if (li > 0) { newIconPath = newIconPath.left(li+1); TPtrC16 iconPathSymbian(reinterpret_cast<const TUint16*> (newIconPath.constData())); *(propertyValues[EIconPath]) = iconPathSymbian; } } *(propertyValues[EUid]) = iUid; *(propertyValues[EMiniViewEnable]) = 0; if (attr.contains(W3CSettingsKey::WIDGET_VIEWMODES)) { QStringList viewModeList = attr.value(W3CSettingsKey::WIDGET_VIEWMODES).toString().split(" "); foreach (const QString &str, viewModeList) { if (str.contains("minimized", Qt::CaseInsensitive)) { *(propertyValues[EMiniViewEnable]) = 1; break; } } }