void BookmarksManager::renameBookmark(const QString &url, const QString &oldName, const QString &newName) { QStringList currentBookmarks = bookmarks(url); for (int i = 0; i < currentBookmarks.count(); i++) { if (bookmarkName(currentBookmarks.at(i)) == oldName) { QString newBookMark = QString("%1:::%2").arg(newName).arg(bookmarkTime(currentBookmarks.at(i))); currentBookmarks.replace(i,newBookMark); writeBookmarks(bookmarkFile(url), currentBookmarks); break; } } }
void BookmarksManager::removeBookmark(const QString &url, const QString &bookmark) { QStringList currentBookmarks = bookmarks(url); if (currentBookmarks.count() > 0) { int indexOfBookmark = currentBookmarks.indexOf(bookmark); if (indexOfBookmark != -1) { currentBookmarks.removeAt(indexOfBookmark); } if (currentBookmarks.count() > 0) { writeBookmarks(bookmarkFile(url), currentBookmarks); } else { removeBookmarks(url); } } }
void BookmarksManager::removeBookmarks(const QString &url) { QFile *file = bookmarkFile(url); file->remove(); QStringList fileIndex = bookmarkFileIndex(); QStringList newFileIndex; for (int i = 0; i < fileIndex.count(); i++) { QStringList urlBookmarkFile = fileIndex.at(i).split(":::"); if (urlBookmarkFile.count() == 2) { if (urlBookmarkFile.at(0) != url) { newFileIndex.append(fileIndex.at(i)); } } } writeBookmarkFileIndex(newFileIndex); }
void HelpBrowser::closeEvent(QCloseEvent * event) { delete menuModel; // no need to delete child widgets, Qt does it all for us // bookmarks QFile bookFile(bookmarkFile()); if (bookFile.open(QIODevice::WriteOnly)) { QTextStream stream(&bookFile); stream.setCodec("UTF-8"); stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; stream << "<bookmarks>\n"; QTreeWidgetItemIterator it(helpNav->bookmarksView); while (*it) { if (bookmarkIndex.contains((*it)->text(0))) { QString pagetitle(bookmarkIndex.value((*it)->text(0)).first); QString filename(bookmarkIndex.value((*it)->text(0)).second); stream << "\t<item title=\"" << (*it)->text(0) << "\" pagetitle=\"" << pagetitle << "\" url=\"" << filename << "\" />\n"; } ++it; } stream << "</bookmarks>\n"; bookFile.close(); } // history QFile histFile(historyFile()); if (histFile.open(QIODevice::WriteOnly)) { QTextStream stream(&histFile); stream.setCodec("UTF-8"); stream << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"; stream << "<history>\n"; for (QMap<QAction*,histd2>::Iterator it = mHistory.begin() ; it != mHistory.end(); ++it) stream << "\t<item title=\"" << it.value().title << "\" url=\"" << it.value().url << "\" />\n"; stream << "</history>\n"; histFile.close(); } // size prefs->set("xsize", width()); prefs->set("ysize", height()); emit closed(); }
QStringList BookmarksManager::bookmarks(const QString &url) { QStringList bookmarksList; if( url == "-" ) return bookmarksList; //Load bookmarks for specified url QFile *file = bookmarkFile(url); if (file->open(QIODevice::ReadOnly | QIODevice::Text)) { QTextStream bmin(file); while (!bmin.atEnd()) { QString line = bmin.readLine(); QStringList nameTime = line.split(":::"); if (nameTime.count() == 2) { bookmarksList.append(line); } } } return bookmarksList; }
void BookmarksManager::addBookmark(const QString &url, const QString &name, int time) { QStringList currentBookmarks = bookmarks(url); currentBookmarks.append(QString("%1:::%2").arg(name).arg(time)); writeBookmarks(bookmarkFile(url, true), currentBookmarks); }