~smspillaz/unity/untiy.less-paint-insanity

« back to all changes in this revision

Viewing changes to standalone-clients/StandaloneHud.cpp

  • Committer: Daniel van Vugt
  • Date: 2012-03-14 06:24:18 UTC
  • mfrom: (2108 unity)
  • mto: This revision was merged to the branch mainline in revision 2146.
  • Revision ID: daniel.van.vugt@canonical.com-20120314062418-nprucpbr0m7qky5e
MergedĀ latestĀ lp:unity

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2010 Canonical Ltd.
 
3
 *
 
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.
 
7
 *
 
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.
 
12
 *
 
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/>
 
16
 *
 
17
 * Authored by: Gordon Allott <gord.allott@canonical.com>
 
18
 *
 
19
 */
 
20
 
 
21
#include <sstream>
 
22
#include "Nux/Nux.h"
 
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"
 
28
#include <gtk/gtk.h>
 
29
 
 
30
#include "HudView.h"
 
31
#include "DashStyle.h"
 
32
#include "DashSettings.h"
 
33
#include <NuxCore/Logger.h>
 
34
 
 
35
namespace
 
36
{
 
37
  nux::logging::Logger logger("unity.tests.Hud");
 
38
}
 
39
 
 
40
class TestRunner
 
41
{
 
42
public:
 
43
  TestRunner ();
 
44
  ~TestRunner ();
 
45
 
 
46
  static void InitWindowThread (nux::NThread* thread, void* InitData);
 
47
  void Init ();
 
48
  nux::Layout *layout;
 
49
  unity::hud::View* hud_view_;
 
50
  unity::dash::Settings dash_settings_;
 
51
 
 
52
private:
 
53
  unity::hud::Hud hud_service_;
 
54
};
 
55
 
 
56
TestRunner::TestRunner ()
 
57
  : hud_service_("com.canonical.hud", "/com/canonical/hud")
 
58
{
 
59
}
 
60
 
 
61
TestRunner::~TestRunner ()
 
62
{
 
63
}
 
64
 
 
65
void TestRunner::Init ()
 
66
{
 
67
  LOG_WARNING(logger) << "test init";
 
68
  layout = new nux::VLayout();
 
69
 
 
70
  hud_view_ = new unity::hud::View();
 
71
 
 
72
  layout->AddView (hud_view_, 0, nux::MINOR_POSITION_TOP);
 
73
  nux::GetWindowCompositor().SetKeyFocusArea(hud_view_->default_focus());
 
74
 
 
75
  nux::GetWindowThread()->SetLayout (layout);
 
76
 
 
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++)
 
82
    {
 
83
      if (!(*query)->icon_name.empty())
 
84
      {
 
85
        LOG_DEBUG(logger) << "Setting icon name to: " << (*query)->icon_name;
 
86
        icon_name = (*query)->icon_name;
 
87
        break;
 
88
      }
 
89
    }
 
90
 
 
91
   hud_view_->SetIcon(icon_name);
 
92
 
 
93
  });
 
94
 
 
95
  hud_view_->query_activated.connect([&] (unity::hud::Query::Ptr query) {
 
96
    hud_service_.ExecuteQuery(query, 0);
 
97
  });  
 
98
  
 
99
  hud_view_->query_selected.connect([&] (unity::hud::Query::Ptr query) {
 
100
    hud_view_->SetIcon(query->icon_name);
 
101
  });
 
102
 
 
103
  hud_view_->search_changed.connect([&] (std::string search_string) {
 
104
    hud_service_.RequestQuery(search_string);
 
105
  });
 
106
 
 
107
  hud_view_->search_activated.connect([&] (std::string search_string) {
 
108
    hud_service_.ExecuteQueryBySearch(search_string, 0);
 
109
  });
 
110
 
 
111
  hud_service_.RequestQuery("");
 
112
 
 
113
  hud_view_->SetWindowGeometry(layout->GetAbsoluteGeometry(), layout->GetGeometry());
 
114
 
 
115
}
 
116
 
 
117
void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
 
118
{
 
119
  TestRunner *self =  (TestRunner *) InitData;
 
120
  self->Init ();
 
121
}
 
122
 
 
123
void
 
124
ControlThread (nux::NThread* thread,
 
125
               void*         data)
 
126
{
 
127
  // sleep for 3 seconds
 
128
  nux::SleepForMilliseconds (3000);
 
129
  printf ("ControlThread successfully started\n");
 
130
}
 
131
 
 
132
 
 
133
int main(int argc, char **argv)
 
134
{
 
135
  nux::SystemThread* st = NULL;
 
136
  nux::WindowThread* wt = NULL;
 
137
 
 
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
 
140
  // for views
 
141
 
 
142
  g_type_init ();
 
143
  gtk_init (&argc, &argv);
 
144
 
 
145
  nux::NuxInitialize(0);
 
146
  
 
147
  // Slightly higher as we're more likely to test things we know will fail
 
148
  nux::logging::configure_logging("unity.hud=debug");
 
149
  
 
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;
 
154
 
 
155
  TestRunner *test_runner = new TestRunner ();
 
156
  wt = nux::CreateGUIThread(TEXT("Hud Prototype Test"),
 
157
                            1200, 768,
 
158
                            0,
 
159
                            &TestRunner::InitWindowThread,
 
160
                            test_runner);
 
161
 
 
162
  st = nux::CreateSystemThread (NULL, ControlThread, wt);
 
163
 
 
164
  if (st)
 
165
    st->Start (NULL);
 
166
 
 
167
  wt->Run (NULL);
 
168
  delete st;
 
169
  delete wt;
 
170
  return 0;
 
171
}