+ if (editable || groups.count() == 0) {
+ QDomElement profiles = doc.documentElement();
+ if (editable && profiles.attribute("version", 0).toInt() < 1) {
+ kDebug() << "// OLD profile version";
+ // this is an old profile version, update it
+ QDomDocument newdoc;
+ QDomElement newprofiles = newdoc.createElement("profiles");
+ newprofiles.setAttribute("version", 1);
+ newdoc.appendChild(newprofiles);
+ QDomNodeList profilelist = doc.elementsByTagName("profile");
+ for (int i = 0; i < profilelist.count(); i++) {
+ QString category = i18n("Custom");
+ QString extension;
+ QDomNode parent = profilelist.at(i).parentNode();
+ if (!parent.isNull()) {
+ QDomElement parentNode = parent.toElement();
+ if (parentNode.hasAttribute("name")) category = parentNode.attribute("name");
+ extension = parentNode.attribute("extension");
+ }
+ profilelist.at(i).toElement().setAttribute("category", category);
+ if (!extension.isEmpty()) profilelist.at(i).toElement().setAttribute("extension", extension);
+ QDomNode n = profilelist.at(i).cloneNode();
+ newprofiles.appendChild(newdoc.importNode(n, true));
+ }
+ if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
+ KMessageBox::sorry(this, i18n("Unable to write to file %1", exportFile));
+ return;
+ }
+ QTextStream out(&file);
+ out << newdoc.toString();
+ file.close();
+ parseFile(exportFile, editable);
+ return;
+ }
+
+ QDomNode node = doc.elementsByTagName("profile").at(0);
+ if (node.isNull()) {
+ kDebug() << "// Export file: " << exportFile << " IS BROKEN";
+ return;
+ }
+ int count = 1;
+ while (!node.isNull()) {
+ QDomElement profile = node.toElement();
+ QString profileName = profile.attribute("name");
+ QString standard = profile.attribute("standard");
+ QString params = profile.attribute("args");
+ QString category = profile.attribute("category", i18n("Custom"));
+ QString dest = profile.attribute("destinationid");
+ QString prof_extension = profile.attribute("extension");
+ if (!prof_extension.isEmpty()) extension = prof_extension;
+
+ QList <QListWidgetItem *> list = m_view.format_list->findItems(category, Qt::MatchExactly);
+ bool exists = false;
+ for (int j = 0; j < list.count(); j++) {
+ if (list.at(j)->data(MetaGroupRole) == dest) {
+ exists = true;
+ break;
+ }
+ }
+ if (!exists) {
+ item = new QListWidgetItem(category, m_view.format_list);
+ item->setData(MetaGroupRole, dest);
+ }
+
+ // Check if item with same name already exists and replace it,
+ // allowing to override default profiles
+
+ list = m_view.size_list->findItems(profileName, Qt::MatchExactly);
+
+ for (int j = 0; j < list.count(); j++) {
+ if (list.at(j)->data(MetaGroupRole) == dest) {
+ QListWidgetItem *duplicate = list.takeAt(j);
+ delete duplicate;
+ j--;
+ }
+ }
+
+ item = new QListWidgetItem(profileName, m_view.size_list);
+ //kDebug() << "// ADDINg item with name: " << profileName << ", GRP" << category << ", DEST:" << dest ;
+ item->setData(GroupRole, category);
+ item->setData(MetaGroupRole, dest);
+ item->setData(ExtensionRole, extension);
+ item->setData(RenderRole, "avformat");
+ item->setData(StandardRole, standard);
+ item->setData(ParamsRole, params);
+ if (profile.hasAttribute("url")) item->setData(ExtraRole, profile.attribute("url"));
+ if (editable) {
+ item->setData(EditableRole, exportFile);
+ if (exportFile.endsWith("customprofiles.xml")) item->setIcon(KIcon("emblem-favorite"));
+ else item->setIcon(KIcon("applications-internet"));
+ }
+ node = doc.elementsByTagName("profile").at(count);
+ count++;
+ }