Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/browsers/firefox.cpp
Show First 20 Lines • Show All 93 Lines • ▼ Show 20 Line(s) | 93 | } else { | |||
---|---|---|---|---|---|
94 | const QString escapedTerm = tmpTerm.replace('\'', QLatin1String("\\'")); | 94 | const QString escapedTerm = tmpTerm.replace('\'', QLatin1String("\\'")); | ||
95 | query = QString("SELECT moz_bookmarks.fk, moz_bookmarks.title, moz_places.url " \ | 95 | query = QString("SELECT moz_bookmarks.fk, moz_bookmarks.title, moz_places.url " \ | ||
96 | "FROM moz_bookmarks, moz_places WHERE " \ | 96 | "FROM moz_bookmarks, moz_places WHERE " \ | ||
97 | "moz_bookmarks.type = 1 AND moz_bookmarks.fk = moz_places.id AND " \ | 97 | "moz_bookmarks.type = 1 AND moz_bookmarks.fk = moz_places.id AND " \ | ||
98 | "(moz_bookmarks.title LIKE '%" + escapedTerm + "%' or moz_places.url LIKE '%" | 98 | "(moz_bookmarks.title LIKE '%" + escapedTerm + "%' or moz_places.url LIKE '%" | ||
99 | + escapedTerm + "%')"); | 99 | + escapedTerm + "%')"); | ||
100 | } | 100 | } | ||
101 | QList<QVariantMap> results = m_fetchsqlite->query(query, QMap<QString, QVariant>()); | 101 | QList<QVariantMap> results = m_fetchsqlite->query(query, QMap<QString, QVariant>()); | ||
102 | QMultiMap<QString, QString> uniqueResults; | ||||
102 | foreach(QVariantMap result, results) { | 103 | foreach(QVariantMap result, results) { | ||
103 | const QString title = result.value(QStringLiteral("title")).toString(); | 104 | const QString title = result.value(QStringLiteral("title")).toString(); | ||
104 | const QUrl url = result.value(QStringLiteral("url")).toUrl(); | 105 | const QUrl url = result.value(QStringLiteral("url")).toUrl(); | ||
105 | if (url.isEmpty() || url.scheme() == QLatin1String("place")) { | 106 | if (url.isEmpty() || url.scheme() == QLatin1String("place")) { | ||
106 | // Don't use bookmarks with empty url or Firefox's "place:" scheme, | 107 | // Don't use bookmarks with empty url or Firefox's "place:" scheme, | ||
107 | // e.g. used for "Most Visited" or "Recent Tags" | 108 | // e.g. used for "Most Visited" or "Recent Tags" | ||
108 | //qDebug() << "element " << url << " was not added"; | 109 | //qDebug() << "element " << url << " was not added"; | ||
109 | continue; | 110 | continue; | ||
110 | } | 111 | } | ||
111 | 112 | | |||
112 | BookmarkMatch bookmarkMatch( m_favicon, term, title, url.toString()); | 113 | auto urlString = url.toString(); | ||
114 | auto keyRange = uniqueResults.equal_range(urlString); | ||||
115 | auto it = keyRange.first; | ||||
116 | if (!title.isEmpty()) { | ||||
117 | while (it != keyRange.second) { | ||||
118 | if (*it == title) { | ||||
119 | // duplicate entry | ||||
120 | break; | ||||
121 | } | ||||
122 | if (it->isEmpty()) { | ||||
123 | // add a title if there was none for the URL | ||||
124 | *it = title; | ||||
125 | break; | ||||
126 | } | ||||
127 | ++it; | ||||
128 | } | ||||
129 | } | ||||
130 | if (it == keyRange.second) { | ||||
131 | // first or unique entry | ||||
132 | uniqueResults.insert(urlString, title); | ||||
133 | } | ||||
134 | } | ||||
135 | | ||||
136 | for (auto result = uniqueResults.constKeyValueBegin(); result != uniqueResults.constKeyValueEnd(); result++) { | ||||
zzag: Why postfix increment? | |||||
bruns: Because modern compilers are clever enough do avoid any temporaries | |||||
zzag: Does the C++ standard guarantee that? | |||||
bruns: It neither guarantees prefix is more efficient than postfix. | |||||
zzag: Please use prefix increment. | |||||
bruns: If there are more required changes, yes, else - no. | |||||
137 | BookmarkMatch bookmarkMatch(m_favicon, term, (*result).second, (*result).first); | ||||
113 | bookmarkMatch.addTo(matches, addEverything); | 138 | bookmarkMatch.addTo(matches, addEverything); | ||
114 | } | 139 | } | ||
115 | 140 | | |||
116 | return matches; | 141 | return matches; | ||
117 | } | 142 | } | ||
118 | 143 | | |||
119 | 144 | | |||
120 | void Firefox::teardown() | 145 | void Firefox::teardown() | ||
▲ Show 20 Lines • Show All 68 Lines • Show Last 20 Lines |
Why postfix increment?