QStringList BookmarksManager::find_tag_urls(BookmarkNode *start_node, const QString& tag) { if (!m_loaded) load(); if (!start_node) start_node = m_bookmarkRootNode; QStringList tags; for (int i = start_node->children().count() - 1; i >= 0; --i) { BookmarkNode *node = start_node->children().at(i); if (node) { if (node->type() == BookmarkNode::Bookmark) { QStringList node_tags = node->tags.split(QRegExp("\\W+"), QString::SkipEmptyParts); foreach(QString node_tag, node_tags) { if (tag.toLower() == node_tag.toLower()) { tags.append(node->url); break; } } } if (node->type() == BookmarkNode::Folder) { tags += find_tag_urls(node, tag); } } }
void BookmarksManager::load() { if (m_loaded) return; m_loaded = true; QString dir = QDesktopServices::storageLocation(QDesktopServices::DataLocation); QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel"); if (!QFile::exists(bookmarkFile)) bookmarkFile = QLatin1String(":defaultbookmarks.xbel"); XbelReader reader; m_bookmarkRootNode = reader.read(bookmarkFile); if (reader.error() != QXmlStreamReader::NoError) { QMessageBox::warning(0, QLatin1String("Loading Bookmark"), tr("Error when loading bookmarks on line %1, column %2:\n" "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString())); } QList<BookmarkNode*> others; for (int i = m_bookmarkRootNode->children().count() - 1; i >= 0; --i) { BookmarkNode *node = m_bookmarkRootNode->children().at(i); if (node->type() == BookmarkNode::Folder) { // Automatically convert if ((node->title == tr("Toolbar Bookmarks") || node->title == QLatin1String(BOOKMARKBAR)) && !m_toolbar) { node->title = tr(BOOKMARKBAR); m_toolbar = node; } // Automatically convert if ((node->title == tr("Menu") || node->title == QLatin1String(BOOKMARKMENU)) && !m_menu) { node->title = tr(BOOKMARKMENU); m_menu = node; } } else { others.append(node); } m_bookmarkRootNode->remove(node); } Q_ASSERT(m_bookmarkRootNode->children().count() == 0); if (!m_toolbar) { m_toolbar = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode); m_toolbar->title = tr(BOOKMARKBAR); } else { m_bookmarkRootNode->add(m_toolbar); } if (!m_menu) { m_menu = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode); m_menu->title = tr(BOOKMARKMENU); } else { m_bookmarkRootNode->add(m_menu); } for (int i = 0; i < others.count(); ++i) m_menu->add(others.at(i)); }
Qt::ItemFlags BookmarksModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; BookmarkNode *bookmarkNode = node(index); if (bookmarkNode != m_bookmarksManager->menu() && bookmarkNode != m_bookmarksManager->toolbar()) { flags |= Qt::ItemIsDragEnabled; if (bookmarkNode->type() != BookmarkNode::Separator) flags |= Qt::ItemIsEditable; } if (hasChildren(index)) flags |= Qt::ItemIsDropEnabled; return flags; }
Qt::ItemFlags BookmarksModel::flags(const QModelIndex &index) const { if (!index.isValid()) return Qt::NoItemFlags; BookmarkNode *node = this->node(index); BookmarkNode::Type type = node->type(); Qt::ItemFlags flags = Qt::ItemIsSelectable | Qt::ItemIsEnabled; if (hasChildren(index)) flags |= Qt::ItemIsDropEnabled; if (node == m_bookmarksManager->menu() || node == m_bookmarksManager->toolbar()) return flags; flags |= Qt::ItemIsDragEnabled; if ((index.column() == 0 && type != BookmarkNode::Separator) || (index.column() == 1 && type == BookmarkNode::Bookmark)) flags |= Qt::ItemIsEditable; return flags; }
void BookmarksManager::load() { if (m_loaded) return; m_loaded = true; QString dir = BrowserApplication::dataLocation(); QString bookmarkFile = dir + QLatin1String("/bookmarks.xbel"); if (!QFile::exists(bookmarkFile)) #ifdef WINPE bookmarkFile = QLatin1String(":defaultbookmarks_winpe.xbel"); #else bookmarkFile = QLatin1String(":defaultbookmarks.xbel"); #endif XbelReader reader; m_bookmarkRootNode = reader.read(bookmarkFile); if (reader.error() != QXmlStreamReader::NoError) { QMessageBox::warning(0, tr("Loading Bookmark"), tr("Error when loading bookmarks on line %1, column %2:\n" "%3").arg(reader.lineNumber()).arg(reader.columnNumber()).arg(reader.errorString())); } BookmarkNode *toolbar = 0; BookmarkNode *menu = 0; QList<BookmarkNode*> others; for (int i = m_bookmarkRootNode->children().count() - 1; i >= 0; --i) { BookmarkNode *node = m_bookmarkRootNode->children().at(i); if (node->type() == BookmarkNode::Folder) { // Automatically convert if (node->title == ("Bookmarks Bar") && !toolbar) { node->title = tr("Bookmarks Bar"); } if (node->title == tr("Bookmarks Bar") && !toolbar) { toolbar = node; } // Automatically convert if (node->title == ("Bookmarks Menu") && !menu) { node->title = tr("Bookmarks Menu"); } if (node->title == tr("Bookmarks Menu") && !menu) { menu = node; } } else { others.append(node); } m_bookmarkRootNode->remove(node); } Q_ASSERT(m_bookmarkRootNode->children().count() == 0); if (!toolbar) { toolbar = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode); toolbar->title = tr("Bookmarks Bar"); } else { m_bookmarkRootNode->add(toolbar); } if (!menu) { menu = new BookmarkNode(BookmarkNode::Folder, m_bookmarkRootNode); menu->title = tr("Bookmarks Menu"); } else { m_bookmarkRootNode->add(menu); } for (int i = 0; i < others.count(); ++i) menu->add(others.at(i)); }