Back to index

unity  6.0.0
StandaloneUnity.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  *              Neil Jagdish Patel <neil.patel@canonical.com>
00019  *
00020  */
00021 #include <gtk/gtk.h>
00022 
00023 #include "Nux/Nux.h"
00024 #include "Nux/VLayout.h"
00025 #include "Nux/WindowThread.h"
00026 #include "NuxGraphics/GraphicsEngine.h"
00027 #include <NuxCore/Logger.h>
00028 
00029 #include "dash/DashController.h"
00030 #include "dash/DashView.h"
00031 #include "launcher/FavoriteStoreGSettings.h"
00032 #include "launcher/Launcher.h"
00033 #include "launcher/LauncherController.h"
00034 #include "panel/PanelController.h"
00035 #include "panel/PanelView.h"
00036 #include "unity-shared/BGHash.h"
00037 #include "unity-shared/BackgroundEffectHelper.h"
00038 #include "unity-shared/DashStyle.h"
00039 #include "unity-shared/FontSettings.h"
00040 #include "unity-shared/PanelStyle.h"
00041 #include "unity-shared/PluginAdapter.h"
00042 #include "unity-shared/UBusMessages.h"
00043 #include "unity-shared/UBusWrapper.h"
00044 #include "unity-shared/UnitySettings.h"
00045 
00046 namespace
00047 {
00048   static int display_width = 1280;
00049   static int display_height = 720;
00050   static gboolean no_window_decorations = FALSE;
00051   static gboolean force_tv = FALSE;
00052 
00053   static GOptionEntry entries[] =
00054   {
00055     {"width", 'w', 0, G_OPTION_ARG_INT, &display_width, "Display width", NULL},
00056     {"height", 'h', 0, G_OPTION_ARG_INT, &display_height, "Display height", NULL},
00057     {"no-window-decorations", 'd', 0, G_OPTION_ARG_NONE, &no_window_decorations, "Disables the window decorations", NULL},
00058     {"force-tv", 't', 0, G_OPTION_ARG_NONE, &force_tv, "Forces the TV interface", NULL},
00059     {NULL}
00060   };
00061 }
00062 
00063 using namespace unity;
00064 
00065 class UnityStandalone
00066 {
00067 public:
00068   UnityStandalone ();
00069   ~UnityStandalone ();
00070 
00071   static void InitWindowThread (nux::NThread* thread, void* InitData);
00072   void Init ();
00073 
00074   launcher::Controller::Ptr launcher_controller;
00075   dash::Controller::Ptr dash_controller;
00076   panel::Controller::Ptr panel_controller;
00077 };
00078 
00079 UnityStandalone::UnityStandalone ()
00080 {
00081 }
00082 
00083 UnityStandalone::~UnityStandalone ()
00084 {
00085 }
00086 
00087 void UnityStandalone::Init ()
00088 {
00089   launcher_controller.reset(new launcher::Controller(0));
00090   panel_controller.reset(new panel::Controller());
00091   dash_controller.reset(new dash::Controller());
00092   dash_controller->launcher_width = launcher_controller->launcher().GetAbsoluteWidth() - 1;
00093 }
00094 
00095 void UnityStandalone::InitWindowThread(nux::NThread* thread, void* InitData)
00096 {
00097   UnityStandalone *self = static_cast<UnityStandalone*>(InitData);
00098   self->Init();
00099 }
00100 
00101 
00102 class UnityStandaloneTV
00103 {
00104 public:
00105   UnityStandaloneTV();
00106   ~UnityStandaloneTV();
00107 
00108   static void InitWindowThread (nux::NThread* thread, void* InitData);
00109   void Init();
00110 
00111   launcher::Controller::Ptr launcher_controller;
00112   dash::Controller::Ptr dash_controller;
00113 };
00114 
00115 UnityStandaloneTV::UnityStandaloneTV() {};
00116 UnityStandaloneTV::~UnityStandaloneTV() {};
00117 
00118 void UnityStandaloneTV::Init()
00119 {
00120   launcher_controller.reset(new launcher::Controller(0));
00121   dash_controller.reset(new dash::Controller());
00122   dash_controller->launcher_width = launcher_controller->launcher().GetAbsoluteWidth() - 1;
00123 
00124   UBusManager().SendMessage(UBUS_DASH_EXTERNAL_ACTIVATION, nullptr);
00125 }
00126 
00127 void UnityStandaloneTV::InitWindowThread(nux::NThread* thread, void* InitData)
00128 {
00129   UnityStandaloneTV *self = static_cast<UnityStandaloneTV*>(InitData);
00130   self->Init();
00131 }
00132 
00133 int main(int argc, char **argv)
00134 {
00135   nux::WindowThread* wt = NULL;
00136   GError *error = NULL;
00137   GOptionContext *context;
00138 
00139   nux::NuxInitialize(0);
00140   nux::logging::configure_logging(::getenv("UNITY_LOG_SEVERITY"));
00141   
00142   context = g_option_context_new("- Unity standalone");
00143   g_option_context_add_main_entries(context, entries, GETTEXT_PACKAGE);
00144   g_option_context_add_group(context, gtk_get_option_group(TRUE));
00145   g_option_context_parse(context, &argc, &argv, &error);
00146   if (error != NULL)
00147   {
00148     g_print("Option parsiong failed: %s\n", error->message);
00149     g_error_free(error);
00150     exit(1);
00151   }
00152 
00153   gtk_init(&argc, &argv);
00154 
00155   BGHash bghash;
00156   FontSettings font_settings;
00157 
00158   // The instances for the pseudo-singletons.
00159   Settings settings;
00160   settings.is_standalone = true;
00161   if (force_tv) Settings::Instance().SetFormFactor(FormFactor::TV);
00162   
00163   PluginAdapter::Initialize(NULL);
00164   dash::Style dash_style;
00165   panel::Style panel_style;
00166 
00167   GeisAdapter geis_adapter;
00168   internal::FavoriteStoreGSettings favorite_store;
00169   BackgroundEffectHelper::blur_type = BLUR_NONE;
00170 
00171   if (!force_tv)
00172   {
00173     UnityStandalone *standalone_runner = new UnityStandalone();
00174     wt = nux::CreateNuxWindow("standalone-unity",
00175                               display_width, display_height,
00176                               (no_window_decorations) ? nux::WINDOWSTYLE_NOBORDER : nux::WINDOWSTYLE_NORMAL,
00177                               0, /* no parent */
00178                               false,
00179                               &UnityStandalone::InitWindowThread,
00180                               standalone_runner);
00181   }
00182   else
00183   {
00184     //TODO - we should be able to pass in a monitor so that we can make the window
00185     //the size of the monitor and position the window on the monitor correctly.
00186     UnityStandaloneTV *standalone_runner = new UnityStandaloneTV();
00187     wt = nux::CreateNuxWindow("standalone-unity-tv",
00188                               display_width, display_height,
00189                               (no_window_decorations) ? nux::WINDOWSTYLE_NOBORDER : nux::WINDOWSTYLE_NORMAL,
00190                               0, /* no parent */
00191                               false,
00192                               &UnityStandaloneTV::InitWindowThread,
00193                               standalone_runner);
00194   }
00195   wt->Run(NULL);
00196   delete wt;
00197   return 0;
00198 }