export to file using the xbel standard Developer Web Site Title of this folder KDE Web Site My own bookmarks Calligra Suite W
| 202 | // </folder> |
| 203 | // </xbel> |
| 204 | void KrBookmarkHandler::exportToFile() |
| 205 | { |
| 206 | QDomDocument doc("xbel"); |
| 207 | QDomElement root = doc.createElement("xbel"); |
| 208 | doc.appendChild(root); |
| 209 | |
| 210 | exportToFileFolder(doc, root, _root); |
| 211 | if (!doc.firstChild().isProcessingInstruction()) { |
| 212 | // adding: <?xml version="1.0" encoding="UTF-8" ?> if not already present |
| 213 | QDomProcessingInstruction instr = doc.createProcessingInstruction("xml", "version=\"1.0\" encoding=\"UTF-8\" "); |
| 214 | doc.insertBefore(instr, doc.firstChild()); |
| 215 | } |
| 216 | |
| 217 | QString filename = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + BOOKMARKS_FILE; |
| 218 | QFile file(filename); |
| 219 | if (file.open(QIODevice::WriteOnly)) { |
| 220 | QTextStream stream(&file); |
| 221 | // By default, UTF-8 is used for reading and writing in QTextStream |
| 222 | stream << doc.toString(); |
| 223 | file.close(); |
| 224 | } else { |
| 225 | KMessageBox::error(_mainWindow->widget(), i18n("Unable to write to %1", filename), i18n("Error")); |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | bool KrBookmarkHandler::importFromFileBookmark(QDomElement &e, KrBookmark *parent, const QString &path, QString *errorMsg) |
| 230 | { |