Changeset View
Changeset View
Standalone View
Standalone View
krusader/BookMan/krbookmarkhandler.cpp
Show First 20 Lines • Show All 226 Lines • ▼ Show 20 Line(s) | 223 | if (file.open(QIODevice::WriteOnly)) { | |||
---|---|---|---|---|---|
227 | file.close(); | 227 | file.close(); | ||
228 | } else { | 228 | } else { | ||
229 | KMessageBox::error(_mainWindow->widget(), i18n("Unable to write to %1", filename), i18n("Error")); | 229 | KMessageBox::error(_mainWindow->widget(), i18n("Unable to write to %1", filename), i18n("Error")); | ||
230 | } | 230 | } | ||
231 | } | 231 | } | ||
232 | 232 | | |||
233 | bool KrBookmarkHandler::importFromFileBookmark(QDomElement &e, KrBookmark *parent, QString path, QString *errorMsg) | 233 | bool KrBookmarkHandler::importFromFileBookmark(QDomElement &e, KrBookmark *parent, QString path, QString *errorMsg) | ||
234 | { | 234 | { | ||
235 | QString url, name, icon; | 235 | QString url, name, iconName; | ||
236 | // verify tag | 236 | // verify tag | ||
237 | if (e.tagName() != "bookmark") { | 237 | if (e.tagName() != "bookmark") { | ||
238 | *errorMsg = i18n("%1 instead of %2", e.tagName(), QLatin1String("bookmark")); | 238 | *errorMsg = i18n("%1 instead of %2", e.tagName(), QLatin1String("bookmark")); | ||
239 | return false; | 239 | return false; | ||
240 | } | 240 | } | ||
241 | // verify href | 241 | // verify href | ||
242 | if (!e.hasAttribute("href")) { | 242 | if (!e.hasAttribute("href")) { | ||
243 | *errorMsg = i18n("missing tag %1", QLatin1String("href")); | 243 | *errorMsg = i18n("missing tag %1", QLatin1String("href")); | ||
244 | return false; | 244 | return false; | ||
245 | } else url = e.attribute("href"); | 245 | } else url = e.attribute("href"); | ||
246 | // verify title | 246 | // verify title | ||
247 | QDomElement te = e.firstChild().toElement(); | 247 | QDomElement te = e.firstChild().toElement(); | ||
248 | if (te.tagName() != "title") { | 248 | if (te.tagName() != "title") { | ||
249 | *errorMsg = i18n("missing tag %1", QLatin1String("title")); | 249 | *errorMsg = i18n("missing tag %1", QLatin1String("title")); | ||
250 | return false; | 250 | return false; | ||
251 | } else name = te.text(); | 251 | } else name = te.text(); | ||
252 | // do we have an icon? | 252 | // do we have an icon? | ||
253 | if (e.hasAttribute("icon")) { | 253 | if (e.hasAttribute("icon")) { | ||
254 | icon = e.attribute("icon"); | 254 | iconName = e.attribute("icon"); | ||
255 | } | 255 | } | ||
256 | // ok: got name and url, let's add a bookmark | 256 | // ok: got name and url, let's add a bookmark | ||
257 | KrBookmark *bm = KrBookmark::getExistingBookmark(path + name, _collection); | 257 | KrBookmark *bm = KrBookmark::getExistingBookmark(path + name, _collection); | ||
258 | if (!bm) { | 258 | if (!bm) { | ||
259 | bm = new KrBookmark(name, QUrl(url), _collection, icon, path + name); | 259 | bm = new KrBookmark(name, QUrl(url), _collection, iconName, path + name); | ||
260 | parent->children().append(bm); | 260 | } else { | ||
261 | bm->setURL(QUrl(url)); | ||||
262 | bm->setIconName(iconName); | ||||
261 | } | 263 | } | ||
264 | parent->children().append(bm); | ||||
262 | 265 | | |||
263 | return true; | 266 | return true; | ||
264 | } | 267 | } | ||
265 | 268 | | |||
266 | bool KrBookmarkHandler::importFromFileFolder(QDomNode &first, KrBookmark *parent, QString path, QString *errorMsg) | 269 | bool KrBookmarkHandler::importFromFileFolder(QDomNode &first, KrBookmark *parent, QString path, QString *errorMsg) | ||
267 | { | 270 | { | ||
268 | QString name; | 271 | QString name; | ||
269 | QDomNode n = first; | 272 | QDomNode n = first; | ||
Show All 23 Lines | 273 | while (!n.isNull()) { | |||
293 | n = n.nextSibling(); | 296 | n = n.nextSibling(); | ||
294 | } | 297 | } | ||
295 | return true; | 298 | return true; | ||
296 | } | 299 | } | ||
297 | 300 | | |||
298 | 301 | | |||
299 | void KrBookmarkHandler::importFromFile() | 302 | void KrBookmarkHandler::importFromFile() | ||
300 | { | 303 | { | ||
301 | clearBookmarks(_root); | 304 | clearBookmarks(_root, false); | ||
302 | 305 | | |||
303 | QString filename = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + BOOKMARKS_FILE; | 306 | QString filename = QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation) + QLatin1Char('/') + BOOKMARKS_FILE; | ||
304 | QFile file(filename); | 307 | QFile file(filename); | ||
305 | if (!file.open(QIODevice::ReadOnly)) | 308 | if (!file.open(QIODevice::ReadOnly)) | ||
306 | return; // no bookmarks file | 309 | return; // no bookmarks file | ||
307 | 310 | | |||
308 | QString errorMsg; | 311 | QString errorMsg; | ||
309 | QDomNode n; | 312 | QDomNode n; | ||
▲ Show 20 Lines • Show All 207 Lines • ▼ Show 20 Line(s) | 436 | #define MAX 15 | |||
517 | 520 | | |||
518 | // make sure the menu is connected to us | 521 | // make sure the menu is connected to us | ||
519 | disconnect(menu, SIGNAL(triggered(QAction*)), 0, 0); | 522 | disconnect(menu, SIGNAL(triggered(QAction*)), 0, 0); | ||
520 | } | 523 | } | ||
521 | 524 | | |||
522 | menu->installEventFilter(this); | 525 | menu->installEventFilter(this); | ||
523 | } | 526 | } | ||
524 | 527 | | |||
525 | void KrBookmarkHandler::clearBookmarks(KrBookmark *root) | 528 | void KrBookmarkHandler::clearBookmarks(KrBookmark *root, bool removeBookmarks) | ||
526 | { | 529 | { | ||
527 | QList<KrBookmark *>::iterator it = root->children().begin(); | 530 | for (auto it = root->children().begin(); it != root->children().end(); it = root->children().erase(it)) { | ||
528 | while (it != root->children().end()) { | | |||
529 | KrBookmark *bm = *it; | 531 | KrBookmark *bm = *it; | ||
530 | 532 | | |||
531 | if (bm->isFolder()) | 533 | if (bm->isFolder()) { | ||
532 | clearBookmarks(bm); | 534 | clearBookmarks(bm, removeBookmarks); | ||
533 | else { | 535 | delete bm; | ||
534 | foreach(QWidget *w, bm->associatedWidgets()) | 536 | } else if (bm->isSeparator()) { | ||
537 | delete bm; | ||||
538 | } else if (removeBookmarks) { | ||||
539 | foreach (QWidget *w, bm->associatedWidgets()) { | ||||
535 | w->removeAction(bm); | 540 | w->removeAction(bm); | ||
541 | } | ||||
536 | delete bm; | 542 | delete bm; | ||
537 | } | 543 | } | ||
538 | | ||||
539 | it = root->children().erase(it); | | |||
540 | } | 544 | } | ||
541 | } | 545 | } | ||
542 | 546 | | |||
543 | void KrBookmarkHandler::bookmarksChanged(const QString&, const QString&) | 547 | void KrBookmarkHandler::bookmarksChanged(const QString&, const QString&) | ||
544 | { | 548 | { | ||
545 | importFromFile(); | 549 | importFromFile(); | ||
546 | } | 550 | } | ||
547 | 551 | | |||
▲ Show 20 Lines • Show All 330 Lines • Show Last 20 Lines |