void ChromeImporter::readBookmarks(const QVariantList &list, BookmarkItem* parent) { Q_ASSERT(parent); foreach (const QVariant &entry, list) { const QVariantMap map = entry.toMap(); const QString typeString = map.value("type").toString(); BookmarkItem::Type type; if (typeString == QLatin1String("url")) { type = BookmarkItem::Url; } else if (typeString == QLatin1String("folder")) { type = BookmarkItem::Folder; } else { continue; } BookmarkItem* item = new BookmarkItem(type, parent); item->setTitle(map.value("name").toString()); if (item->isUrl()) { item->setUrl(QUrl::fromEncoded(map.value("url").toByteArray())); } if (map.contains("children")) { readBookmarks(map.value("children").toList(), item); } } }
QVariant BookmarksModel::data(const QModelIndex &index, int role) const { BookmarkItem* itm = item(index); if (!itm) { return QVariant(); } switch (role) { case TypeRole: return itm->type(); case UrlRole: return itm->url(); case UrlStringRole: return itm->urlString(); case TitleRole: return itm->title(); case DescriptionRole: return itm->description(); case KeywordRole: return itm->keyword(); case VisitCountRole: return -1; case ExpandedRole: return itm->isExpanded(); case SidebarExpandedRole: return itm->isSidebarExpanded(); case Qt::ToolTipRole: if (index.column() == 0 && itm->isUrl()) { return QString("%1\n%2").arg(itm->title(), QString::fromUtf8(itm->url().toEncoded())); } case Qt::DisplayRole: switch (index.column()) { case 0: return itm->title(); case 1: return itm->url().toEncoded(); default: return QVariant(); } case Qt::DecorationRole: if (index.column() == 0) { return itm->icon(); } return QVariant(); default: return QVariant(); } }