2
* Copyright 2010 Canonical Ltd.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU General Public License version 3, as published
6
* by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the GNU General Public License for more details.
13
* You should have received a copy of the GNU General Public License
14
* version 3 along with this program. If not, see
15
* <http://www.gnu.org/licenses/>
17
* Authored by: Gordon Allott <gord.allott@canonical.com>
23
#include "Nux/VLayout.h"
24
#include "Nux/Button.h"
25
#include "Nux/TextureArea.h"
26
#include "Nux/WindowThread.h"
27
#include "NuxGraphics/GraphicsEngine.h"
31
#include "DashStyle.h"
32
#include "DashSettings.h"
33
#include <NuxCore/Logger.h>
37
nux::logging::Logger logger("unity.tests.Hud");
46
static void InitWindowThread (nux::NThread* thread, void* InitData);
49
unity::hud::View* hud_view_;
50
unity::dash::Settings dash_settings_;
53
unity::hud::Hud hud_service_;
56
TestRunner::TestRunner ()
57
: hud_service_("com.canonical.hud", "/com/canonical/hud")
61
TestRunner::~TestRunner ()
65
void TestRunner::Init ()
67
LOG_WARNING(logger) << "test init";
68
layout = new nux::VLayout();
70
hud_view_ = new unity::hud::View();
72
layout->AddView (hud_view_, 0, nux::MINOR_POSITION_TOP);
73
nux::GetWindowCompositor().SetKeyFocusArea(hud_view_->default_focus());
75
nux::GetWindowThread()->SetLayout (layout);
77
// things the controller normally does
78
hud_service_.queries_updated.connect([&] (unity::hud::Hud::Queries queries) {
79
hud_view_->SetQueries(queries);
80
std::string icon_name = "";
81
for (auto query = queries.begin(); query != queries.end(); query++)
83
if (!(*query)->icon_name.empty())
85
LOG_DEBUG(logger) << "Setting icon name to: " << (*query)->icon_name;
86
icon_name = (*query)->icon_name;
91
hud_view_->SetIcon(icon_name);
95
hud_view_->query_activated.connect([&] (unity::hud::Query::Ptr query) {
96
hud_service_.ExecuteQuery(query, 0);
99
hud_view_->query_selected.connect([&] (unity::hud::Query::Ptr query) {
100
hud_view_->SetIcon(query->icon_name);
103
hud_view_->search_changed.connect([&] (std::string search_string) {
104
hud_service_.RequestQuery(search_string);
107
hud_view_->search_activated.connect([&] (std::string search_string) {
108
hud_service_.ExecuteQueryBySearch(search_string, 0);
111
hud_service_.RequestQuery("");
113
hud_view_->SetWindowGeometry(layout->GetAbsoluteGeometry(), layout->GetGeometry());
117
void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
119
TestRunner *self = (TestRunner *) InitData;
124
ControlThread (nux::NThread* thread,
127
// sleep for 3 seconds
128
nux::SleepForMilliseconds (3000);
129
printf ("ControlThread successfully started\n");
133
int main(int argc, char **argv)
135
nux::SystemThread* st = NULL;
136
nux::WindowThread* wt = NULL;
138
// no real tests right now, just make sure we don't get any criticals and such
139
// waiting on nice perceptual diff support before we can build real tests
143
gtk_init (&argc, &argv);
145
nux::NuxInitialize(0);
147
// Slightly higher as we're more likely to test things we know will fail
148
nux::logging::configure_logging("unity.hud=debug");
150
nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
151
LOG_DEBUG(logger) << "starting the standalone hud";
152
// The instances for the pseudo-singletons.
153
unity::dash::Style dash_style;
155
TestRunner *test_runner = new TestRunner ();
156
wt = nux::CreateGUIThread(TEXT("Hud Prototype Test"),
159
&TestRunner::InitWindowThread,
162
st = nux::CreateSystemThread (NULL, ControlThread, wt);