Changeset View
Changeset View
Standalone View
Standalone View
runners/bookmarks/bookmarkmatch.cpp
Show All 15 Lines | |||||
16 | * License along with this program; if not, write to the | 16 | * License along with this program; if not, write to the | ||
17 | * Free Software Foundation, Inc., | 17 | * Free Software Foundation, Inc., | ||
18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 18 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | 21 | | |||
22 | #include "bookmarkmatch.h" | 22 | #include "bookmarkmatch.h" | ||
23 | #include <QVariant> | 23 | #include <QVariant> | ||
24 | #include "favicon.h" | | |||
25 | 24 | | |||
26 | // TODO: test | 25 | // TODO: test | ||
27 | 26 | | |||
28 | BookmarkMatch::BookmarkMatch(Favicon *favicon, const QString& searchTerm, const QString& bookmarkTitle, const QString& bookmarkURL, const QString& description ) | 27 | BookmarkMatch::BookmarkMatch(const QIcon &icon, const QString& searchTerm, const QString& bookmarkTitle, const QString& bookmarkURL, const QString& description ) | ||
29 | : m_favicon(favicon), m_searchTerm(searchTerm), m_bookmarkTitle(bookmarkTitle), m_bookmarkURL(bookmarkURL), m_description(description) | 28 | : m_icon(icon), m_searchTerm(searchTerm), m_bookmarkTitle(bookmarkTitle), m_bookmarkURL(bookmarkURL), m_description(description) | ||
30 | { | 29 | { | ||
31 | } | 30 | } | ||
32 | 31 | | |||
33 | Plasma::QueryMatch BookmarkMatch::asQueryMatch( Plasma::AbstractRunner* runner ) | 32 | Plasma::QueryMatch BookmarkMatch::asQueryMatch( Plasma::AbstractRunner* runner ) | ||
34 | { | 33 | { | ||
35 | Plasma::QueryMatch::Type type = Plasma::QueryMatch::NoMatch; | 34 | Plasma::QueryMatch::Type type; | ||
36 | qreal relevance = 0; | 35 | qreal relevance = 0; | ||
37 | 36 | | |||
38 | if (m_bookmarkTitle.compare(m_searchTerm, Qt::CaseInsensitive) == 0 || | 37 | if (m_bookmarkTitle.compare(m_searchTerm, Qt::CaseInsensitive) == 0 || | ||
39 | (!m_description.isEmpty() && m_description.compare(m_searchTerm, Qt::CaseInsensitive) == 0) | 38 | (!m_description.isEmpty() && m_description.compare(m_searchTerm, Qt::CaseInsensitive) == 0) | ||
40 | ) { | 39 | ) { | ||
41 | type = Plasma::QueryMatch::ExactMatch; | 40 | type = Plasma::QueryMatch::ExactMatch; | ||
42 | relevance = 1.0; | 41 | relevance = 1.0; | ||
43 | } else if (m_bookmarkTitle.contains(m_searchTerm, Qt::CaseInsensitive)) { | 42 | } else if (m_bookmarkTitle.contains(m_searchTerm, Qt::CaseInsensitive)) { | ||
Show All 11 Lines | |||||
55 | } | 54 | } | ||
56 | 55 | | |||
57 | bool isNameEmpty = m_bookmarkTitle.isEmpty(); | 56 | bool isNameEmpty = m_bookmarkTitle.isEmpty(); | ||
58 | bool isDescriptionEmpty = m_description.isEmpty(); | 57 | bool isDescriptionEmpty = m_description.isEmpty(); | ||
59 | 58 | | |||
60 | Plasma::QueryMatch match(runner); | 59 | Plasma::QueryMatch match(runner); | ||
61 | match.setType(type); | 60 | match.setType(type); | ||
62 | match.setRelevance(relevance); | 61 | match.setRelevance(relevance); | ||
63 | match.setIcon(m_favicon->iconFor(m_bookmarkURL)); | 62 | match.setIcon(m_icon); | ||
64 | match.setSubtext(m_bookmarkURL); | 63 | match.setSubtext(m_bookmarkURL); | ||
65 | 64 | | |||
66 | // Try to set the following as text in this order: name, description, url | 65 | // Try to set the following as text in this order: name, description, url | ||
67 | match.setText( isNameEmpty | 66 | match.setText( isNameEmpty | ||
68 | ? | 67 | ? | ||
69 | (!isDescriptionEmpty ? m_description : m_bookmarkURL) | 68 | (!isDescriptionEmpty ? m_description : m_bookmarkURL) | ||
70 | : | 69 | : | ||
71 | m_bookmarkTitle ); | 70 | m_bookmarkTitle ); | ||
Show All 23 Lines |