2
* Copyright (C) 2012 Canonical, Ltd.
5
* Gerry Boland <gerry.boland@canonical.com>
7
* This program is free software; you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation; version 3.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
32
static const char* HUD_DBUS_SERVICE = "com.canonical.hud";
33
static const char* HUD_DBUS_PATH = "/com/canonical/hud";
35
Hud::Hud(QObject *parent) :
36
QAbstractListModel(parent),
39
QHash<int, QByteArray> names;
40
names[ResultIdRole] = "resultId";
41
names[FormattedTextRole] = "formattedText";
42
names[IconNameRole] = "iconName";
43
names[ItemIconRole] = "itemIcon";
44
names[CompletionTextRole] = "completionText";
45
names[ShortcutRole] = "shortcut";
48
m_unityHud = new unity::hud::Hud(HUD_DBUS_SERVICE, HUD_DBUS_PATH);
50
m_unityHud->target.changed.connect(sigc::mem_fun(this, &Hud::onTargetChanged));
51
m_unityHud->connected.changed.connect(sigc::mem_fun(this, &Hud::onConnectedChanged));
52
m_unityHud->queries_updated.connect(sigc::mem_fun(this, &Hud::onResultsUpdated));
60
int Hud::rowCount(const QModelIndex& parent) const
63
if (m_searchQuery.isEmpty()) {
66
return m_unityHudResults.size();
69
QVariant Hud::data(const QModelIndex& index, int role) const
71
if (!index.isValid() || m_searchQuery.isEmpty()) {
75
std::shared_ptr<unity::hud::Query> result;
78
result = m_unityHudResults.at(index.row());
79
} catch (std::out_of_range) {
80
UQ_DEBUG << "HUD query id invalid";
85
case Hud::ResultIdRole:
87
case Hud::FormattedTextRole:
88
return QString::fromStdString(result->formatted_text);
89
case Hud::IconNameRole:
90
return QString::fromStdString(result->icon_name);
91
case Hud::ItemIconRole:
92
return QString::fromStdString(result->item_icon);
93
case Hud::CompletionTextRole:
94
return QString::fromStdString(result->completion_text);
95
case Hud::ShortcutRole:
96
return QString::fromStdString(result->shortcut);
97
/* TODO (?) Hud returns more information in a "key" struct containing
98
* lower-level information than we seem not to need right now. */
104
QString Hud::searchQuery() const
106
return m_searchQuery;
109
void Hud::setSearchQuery(const QString& searchQuery)
111
if (searchQuery != m_searchQuery) {
112
m_searchQuery = searchQuery;
113
m_unityHud->RequestQuery(m_searchQuery.toStdString());
115
Q_EMIT searchQueryChanged();
119
void Hud::executeResult(const int id) const
121
std::shared_ptr<unity::hud::Query> result;
124
result = m_unityHudResults.at(id);
125
} catch (std::out_of_range) {
126
UQ_DEBUG << "HUD query id invalid";
130
m_unityHud->ExecuteQuery(result,
131
QDateTime::currentDateTime().toTime_t());
134
void Hud::executeResultBySearch(const QString& searchQuery) const
136
m_unityHud->ExecuteQueryBySearch(searchQuery.toStdString(),
137
QDateTime::currentDateTime().toTime_t());
140
void Hud::endSearch()
142
m_unityHud->CloseQuery();
143
m_searchQuery.clear();
146
void Hud::onResultsUpdated(const unity::hud::Hud::Queries results)
148
m_unityHudResults = results;
152
QString Hud::target() const {
153
return QString::fromStdString(m_unityHud->target);
156
bool Hud::connected() const{
160
void Hud::onConnectedChanged(const bool connected) {
161
m_connected = connected;
162
Q_EMIT connectedChanged();
165
void Hud::onTargetChanged(const std::string target) {
166
Q_EMIT targetChanged();