Back to index

unity  6.0.0
StandaloneHud.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Canonical Ltd.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU General Public License version 3, as published
00006  * by the  Free Software Foundation.
00007  *
00008  * This program is distributed in the hope that it will be useful, but
00009  * WITHOUT ANY WARRANTY; without even the implied warranties of
00010  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00011  * PURPOSE.  See the GNU General Public License for more details.
00012  *
00013  * You should have received a copy of the GNU General Public License
00014  * version 3 along with this program.  If not, see
00015  * <http://www.gnu.org/licenses/>
00016  *
00017  * Authored by: Gordon Allott <gord.allott@canonical.com>
00018  *
00019  */
00020 
00021 #include <sstream>
00022 #include "Nux/Nux.h"
00023 #include "Nux/VLayout.h"
00024 #include "Nux/Button.h"
00025 #include "Nux/TextureArea.h"
00026 #include "Nux/WindowThread.h"
00027 #include "NuxGraphics/GraphicsEngine.h"
00028 #include <gtk/gtk.h>
00029 
00030 #include "HudView.h"
00031 #include "unity-shared/DashStyle.h"
00032 #include "unity-shared/UnitySettings.h"
00033 #include <NuxCore/Logger.h>
00034 
00035 namespace
00036 {
00037   nux::logging::Logger logger("unity.tests.Hud");
00038 }
00039 
00040 class TestRunner
00041 {
00042 public:
00043   TestRunner ();
00044   ~TestRunner ();
00045 
00046   static void InitWindowThread (nux::NThread* thread, void* InitData);
00047   void Init ();
00048   nux::Layout *layout;
00049   unity::hud::View* hud_view_;
00050   unity::Settings dash_settings_;
00051 
00052 private:
00053   unity::hud::Hud hud_service_;
00054 };
00055 
00056 TestRunner::TestRunner ()
00057   : hud_service_("com.canonical.hud", "/com/canonical/hud")
00058 {
00059 }
00060 
00061 TestRunner::~TestRunner ()
00062 {
00063 }
00064 
00065 void TestRunner::Init ()
00066 {
00067   LOG_WARNING(logger) << "test init";
00068   layout = new nux::VLayout();
00069 
00070   hud_view_ = new unity::hud::View();
00071 
00072   layout->AddView (hud_view_, 0, nux::MINOR_POSITION_TOP);
00073   nux::GetWindowCompositor().SetKeyFocusArea(hud_view_->default_focus());
00074 
00075   nux::GetWindowThread()->SetLayout (layout);
00076 
00077   // things the controller normally does
00078   hud_service_.queries_updated.connect([&] (unity::hud::Hud::Queries queries) {
00079     hud_view_->SetQueries(queries);
00080     std::string icon_name = "";
00081     for (auto query = queries.begin(); query != queries.end(); query++)
00082     {
00083       if (!(*query)->icon_name.empty())
00084       {
00085         LOG_DEBUG(logger) << "Setting icon name to: " << (*query)->icon_name;
00086         icon_name = (*query)->icon_name;
00087         break;
00088       }
00089     }
00090  
00091    hud_view_->SetIcon(icon_name, 42, 52, 0);
00092 
00093   });
00094 
00095   hud_view_->query_activated.connect([&] (unity::hud::Query::Ptr query) {
00096     hud_service_.ExecuteQuery(query, 0);
00097   });  
00098   
00099   hud_view_->query_selected.connect([&] (unity::hud::Query::Ptr query) {
00100     hud_view_->SetIcon(query->icon_name, 42, 52, 0);
00101   });
00102 
00103   hud_view_->search_changed.connect([&] (std::string search_string) {
00104     hud_service_.RequestQuery(search_string);
00105   });
00106 
00107   hud_view_->search_activated.connect([&] (std::string search_string) {
00108     hud_service_.ExecuteQueryBySearch(search_string, 0);
00109   });
00110 
00111   hud_service_.RequestQuery("");
00112  
00113   hud_view_->SetWindowGeometry(layout->GetAbsoluteGeometry(), layout->GetGeometry());
00114 
00115 }
00116 
00117 void TestRunner::InitWindowThread(nux::NThread* thread, void* InitData)
00118 {
00119   TestRunner *self =  (TestRunner *) InitData;
00120   self->Init ();
00121 }
00122 
00123 void
00124 ControlThread (nux::NThread* thread,
00125                void*         data)
00126 {
00127   // sleep for 3 seconds
00128   nux::SleepForMilliseconds (3000);
00129   printf ("ControlThread successfully started\n");
00130 }
00131 
00132 
00133 int main(int argc, char **argv)
00134 {
00135   nux::SystemThread* st = NULL;
00136   nux::WindowThread* wt = NULL;
00137 
00138   // no real tests right now, just make sure we don't get any criticals and such
00139   // waiting on nice perceptual diff support before we can build real tests
00140   // for views
00141 
00142   g_type_init ();
00143   gtk_init (&argc, &argv);
00144 
00145   nux::NuxInitialize(0);
00146   
00147   // Slightly higher as we're more likely to test things we know will fail
00148   nux::logging::configure_logging("unity.hud=debug");
00149   
00150   nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
00151   LOG_DEBUG(logger) << "starting the standalone hud";
00152   // The instances for the pseudo-singletons.
00153   unity::Settings settings;
00154   unity::dash::Style dash_style;
00155 
00156   TestRunner *test_runner = new TestRunner ();
00157   wt = nux::CreateGUIThread(TEXT("Hud Prototype Test"),
00158                             1200, 768,
00159                             0,
00160                             &TestRunner::InitWindowThread,
00161                             test_runner);
00162 
00163   st = nux::CreateSystemThread (NULL, ControlThread, wt);
00164 
00165   if (st)
00166     st->Start (NULL);
00167 
00168   wt->Run (NULL);
00169   delete st;
00170   delete wt;
00171   return 0;
00172 }