From 03cb6db972d9848c0f054d0b8de714847a5c1213 Mon Sep 17 00:00:00 2001 From: Marco Biscaro Date: Thu, 10 May 2012 15:27:07 -0300 Subject: Fixing custom BG color issues Fixed bugs: - LP: #975350 - LP: #924586 (bzr r2353.5.1) --- launcher/Launcher.cpp | 5 ++++- unity-shared/BGHash.cpp | 12 ++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/launcher/Launcher.cpp b/launcher/Launcher.cpp index b0c4bc516..6424a7384 100644 --- a/launcher/Launcher.cpp +++ b/launcher/Launcher.cpp @@ -1086,7 +1086,10 @@ float Launcher::DragLimiter(float x) nux::Color FullySaturateColor (nux::Color color) { float max = std::max(color.red, std::max(color.green, color.blue)); - color = color * (1.0f / max); + if (max != 0) + { + color = color * (1.0f / max); + } return color; } diff --git a/unity-shared/BGHash.cpp b/unity-shared/BGHash.cpp index f22e7a058..1479e5538 100644 --- a/unity-shared/BGHash.cpp +++ b/unity-shared/BGHash.cpp @@ -99,6 +99,12 @@ void BGHash::OverrideColor (nux::Color color) void BGHash::RefreshColor() { + if (_override_color.alpha) + { + TransitionToNewColor (_override_color); + return; + } + Atom real_type; gint result; gint real_format; @@ -154,12 +160,6 @@ void BGHash::OnGSettingsChanged (GSettings *settings, gchar *key) void BGHash::OnBackgroundChanged (GnomeBG *bg) { - if (_override_color.alpha) - { - TransitionToNewColor (_override_color); - return; - } - RefreshColor(); } -- cgit v1.2.3 From 3c378bdfc46fe898ee6a588fd31525a30efa4f2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Mon, 2 Jul 2012 19:31:02 +0200 Subject: a11y: Port to atk-bridge gtk3 and gnome-shell already did that. Now the prefered way to initialize the bridge is using atk-bridge library, instead of load a module (bzr r2455.4.1) --- CMakeLists.txt | 2 +- plugins/unityshell/src/unitya11y.cpp | 78 +----------------------------------- 2 files changed, 3 insertions(+), 77 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e86aae33a..bc69a74b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -127,7 +127,7 @@ endif (DISABLE_MAINTAINER_CFLAGS) # # Compiz Plugins # -set (UNITY_PLUGIN_DEPS "compiz;nux-2.0>=2.0.0;libbamf3;dee-1.0;gio-2.0;gio-unix-2.0;dbusmenu-glib-0.4;x11;libstartup-notification-1.0;gthread-2.0;indicator3-0.4>=0.4.90;atk;unity-misc>=0.4.0;gconf-2.0;libutouch-geis;gtk+-3.0>=3.1;sigc++-2.0;json-glib-1.0;libnotify;gnome-desktop-3.0;xfixes") +set (UNITY_PLUGIN_DEPS "compiz;nux-2.0>=2.0.0;libbamf3;dee-1.0;gio-2.0;gio-unix-2.0;dbusmenu-glib-0.4;x11;libstartup-notification-1.0;gthread-2.0;indicator3-0.4>=0.4.90;atk;atk-bridge-2.0;unity-misc>=0.4.0;gconf-2.0;libutouch-geis;gtk+-3.0>=3.1;sigc++-2.0;json-glib-1.0;libnotify;gnome-desktop-3.0;xfixes") find_package (PkgConfig) pkg_check_modules (CACHED_UNITY_DEPS REQUIRED ${UNITY_PLUGIN_DEPS}) add_subdirectory(unity-shared) diff --git a/plugins/unityshell/src/unitya11y.cpp b/plugins/unityshell/src/unitya11y.cpp index 9f2117d5d..53843785b 100644 --- a/plugins/unityshell/src/unitya11y.cpp +++ b/plugins/unityshell/src/unitya11y.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "unitya11y.h" #include "unitya11ytests.h" @@ -65,8 +66,6 @@ static gboolean a11y_initialized = FALSE; #define INIT_METHOD "gnome_accessibility_module_init" #define DESKTOP_SCHEMA "org.gnome.desktop.interface" #define ACCESSIBILITY_ENABLED_KEY "toolkit-accessibility" -#define AT_SPI_SCHEMA "org.a11y.atspi" -#define ATK_BRIDGE_LOCATION_KEY "atk-bridge-location" static void unity_a11y_restore_environment(void) @@ -121,62 +120,6 @@ should_enable_a11y(void) return value; } -static gchar* -get_atk_bridge_path(void) -{ - GSettings* atspi_settings = NULL; - GVariant *variant = NULL; - char* value = NULL; - - if (!has_gsettings_schema(AT_SPI_SCHEMA)) - return NULL; - - atspi_settings = g_settings_new(AT_SPI_SCHEMA); - variant = g_settings_get_value (atspi_settings, ATK_BRIDGE_LOCATION_KEY); - value = g_variant_dup_bytestring (variant, NULL); - - g_variant_unref (variant); - g_object_unref(atspi_settings); - - return value; -} - -static gboolean -a11y_invoke_module(const char* module_path) -{ - GModule* handle; - void (*invoke_fn)(void); - - if (!module_path) - { - g_warning("Accessibility: invalid module path (NULL)"); - - return FALSE; - } - - if (!(handle = g_module_open(module_path, (GModuleFlags)0))) - { - g_warning("Accessibility: failed to load module '%s': '%s'", - module_path, g_module_error()); - - return FALSE; - } - - if (!g_module_symbol(handle, INIT_METHOD, (gpointer*)&invoke_fn)) - { - g_warning("Accessibility: error library '%s' does not include " - "method '%s' required for accessibility support", - module_path, INIT_METHOD); - g_module_close(handle); - - return FALSE; - } - - invoke_fn(); - - return TRUE; -} - /********************************************************************************/ /* * In order to avoid the atk-bridge loading and the GAIL @@ -194,15 +137,10 @@ unity_a11y_preset_environment(void) /* * Initializes the accessibility (ATK) support on Unity * - * It loads the atk-bridge if required. It checks: - * * If the proper gsettings keys are set - * * Loads the proper AtkUtil implementation */ void unity_a11y_init(nux::WindowThread* wt) { - gchar* bridge_path = NULL; - unity_a11y_restore_environment(); if (!should_enable_a11y()) @@ -210,19 +148,7 @@ unity_a11y_init(nux::WindowThread* wt) load_unity_atk_util(wt); - bridge_path = get_atk_bridge_path(); - - if (a11y_invoke_module(bridge_path)) - { - g_debug("Unity Oneiric accessibility started, using bridge on %s", - bridge_path); - - atk_get_root(); - - a11y_initialized = TRUE; - } - - g_free(bridge_path); + atk_bridge_adaptor_init (NULL, NULL); // NOTE: we run manually the unit tests while developing by // uncommenting this. Take a look to the explanation on -- cgit v1.2.3 From ac23e16a636b4ce60d813cf49de6edc6129f98b9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Mon, 2 Jul 2012 19:59:54 +0200 Subject: a11y: Don't check 'toolkit-accessibility' gsettings variable So accessibility is always on, like in gtk3 and gnome-shell (bzr r2455.4.2) --- plugins/unityshell/src/unitya11y.cpp | 46 ------------------------------------ 1 file changed, 46 deletions(-) diff --git a/plugins/unityshell/src/unitya11y.cpp b/plugins/unityshell/src/unitya11y.cpp index 53843785b..79ad37516 100644 --- a/plugins/unityshell/src/unitya11y.cpp +++ b/plugins/unityshell/src/unitya11y.cpp @@ -64,8 +64,6 @@ static GHashTable* accessible_table = NULL; static gboolean a11y_initialized = FALSE; #define INIT_METHOD "gnome_accessibility_module_init" -#define DESKTOP_SCHEMA "org.gnome.desktop.interface" -#define ACCESSIBILITY_ENABLED_KEY "toolkit-accessibility" static void unity_a11y_restore_environment(void) @@ -81,45 +79,6 @@ load_unity_atk_util(nux::WindowThread* wt) g_type_class_unref(g_type_class_ref(UNITY_TYPE_UTIL_ACCESSIBLE)); } -/* This method is required because g_setting_new abort if the schema - is not present. */ -static gboolean -has_gsettings_schema(const gchar* schema) -{ - const char* const* list_schemas = NULL; - gboolean found = FALSE; - int i = 0; - - list_schemas = g_settings_list_schemas(); - for (i = 0; list_schemas [i]; i++) - { - if (!g_strcmp0(list_schemas[i], schema)) - { - found = TRUE; - break; - } - } - - return found; -} - -static gboolean -should_enable_a11y(void) -{ - GSettings* desktop_settings = NULL; - gboolean value = FALSE; - - if (!has_gsettings_schema(DESKTOP_SCHEMA)) - return FALSE; - - desktop_settings = g_settings_new(DESKTOP_SCHEMA); - value = g_settings_get_boolean(desktop_settings, ACCESSIBILITY_ENABLED_KEY); - - g_object_unref(desktop_settings); - - return value; -} - /********************************************************************************/ /* * In order to avoid the atk-bridge loading and the GAIL @@ -142,12 +101,7 @@ void unity_a11y_init(nux::WindowThread* wt) { unity_a11y_restore_environment(); - - if (!should_enable_a11y()) - return; - load_unity_atk_util(wt); - atk_bridge_adaptor_init (NULL, NULL); // NOTE: we run manually the unit tests while developing by -- cgit v1.2.3 From 9ebbb72f6b16441b72b8f94352a9cf430becdb93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Tue, 3 Jul 2012 18:50:13 +0200 Subject: a11y: Port the panel service accessibility support to atk-bridge As Unity plugin itself, moving to atk-bridge library. Also solving minor issues (bzr r2455.4.3) --- plugins/unityshell/src/unitya11y.cpp | 10 ++- services/CMakeLists.txt | 2 +- services/panel-a11y.c | 118 +---------------------------------- 3 files changed, 10 insertions(+), 120 deletions(-) diff --git a/plugins/unityshell/src/unitya11y.cpp b/plugins/unityshell/src/unitya11y.cpp index 79ad37516..fb0016f0d 100644 --- a/plugins/unityshell/src/unitya11y.cpp +++ b/plugins/unityshell/src/unitya11y.cpp @@ -63,8 +63,6 @@ static GHashTable* accessible_table = NULL; static gboolean a11y_initialized = FALSE; -#define INIT_METHOD "gnome_accessibility_module_init" - static void unity_a11y_restore_environment(void) { @@ -100,9 +98,15 @@ unity_a11y_preset_environment(void) void unity_a11y_init(nux::WindowThread* wt) { + if (a11y_initialized) + return; + unity_a11y_restore_environment(); load_unity_atk_util(wt); - atk_bridge_adaptor_init (NULL, NULL); + atk_bridge_adaptor_init(NULL, NULL); + atk_get_root(); + + a11y_initialized = TRUE; // NOTE: we run manually the unit tests while developing by // uncommenting this. Take a look to the explanation on diff --git a/services/CMakeLists.txt b/services/CMakeLists.txt index 214abde27..ee0c39389 100644 --- a/services/CMakeLists.txt +++ b/services/CMakeLists.txt @@ -2,7 +2,7 @@ # Panel Service # find_package(PkgConfig) -pkg_check_modules(SERVICE_DEPS REQUIRED gtk+-3.0>=3.3 gobject-2.0 gio-2.0 gthread-2.0 indicator3-0.4>=0.4.90 x11 gconf-2.0) +pkg_check_modules(SERVICE_DEPS REQUIRED gtk+-3.0>=3.3 gobject-2.0 gio-2.0 gthread-2.0 indicator3-0.4>=0.4.90 x11 gconf-2.0 atk-bridge-2.0) execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} indicator3-0.4 --variable indicatordir OUTPUT_VARIABLE _indicatordir OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process (COMMAND ${PKG_CONFIG_EXECUTABLE} indicator3-0.4 --variable iconsdir OUTPUT_VARIABLE _iconsdir OUTPUT_STRIP_TRAILING_WHITESPACE) diff --git a/services/panel-a11y.c b/services/panel-a11y.c index 6f870555b..a22b39b87 100644 --- a/services/panel-a11y.c +++ b/services/panel-a11y.c @@ -17,119 +17,16 @@ */ #include +#include #include "panel-a11y.h" #include "panel-util-accessible.h" static gboolean a11y_initialized = FALSE; -#define INIT_METHOD "gnome_accessibility_module_init" -#define DESKTOP_SCHEMA "org.gnome.desktop.interface" -#define ACCESSIBILITY_ENABLED_KEY "toolkit-accessibility" -#define AT_SPI_SCHEMA "org.a11y.atspi" -#define ATK_BRIDGE_LOCATION_KEY "atk-bridge-location" - - -/* This method is required because g_setting_new abort if the schema - is not present. */ -static gboolean -has_gsettings_schema (const gchar *schema) -{ - const char * const *list_schemas = NULL; - gboolean found = FALSE; - int i = 0; - - list_schemas = g_settings_list_schemas (); - for (i = 0; list_schemas [i]; i++) - { - if (!g_strcmp0 (list_schemas[i], schema)) - { - found = TRUE; - break; - } - } - - return found; -} - -static gboolean -should_enable_a11y (void) -{ - GSettings *desktop_settings = NULL; - gboolean value = FALSE; - - if (!has_gsettings_schema (DESKTOP_SCHEMA)) - return FALSE; - - desktop_settings = g_settings_new (DESKTOP_SCHEMA); - value = g_settings_get_boolean (desktop_settings, ACCESSIBILITY_ENABLED_KEY); - - g_object_unref (desktop_settings); - - return value; -} - -static gchar* -get_atk_bridge_path (void) -{ - GSettings *atspi_settings = NULL; - GVariant *variant = NULL; - char *value = NULL; - - if (!has_gsettings_schema (AT_SPI_SCHEMA)) - return NULL; - - atspi_settings = g_settings_new(AT_SPI_SCHEMA); - variant = g_settings_get_value (atspi_settings, ATK_BRIDGE_LOCATION_KEY); - value = g_variant_dup_bytestring (variant, NULL); - - g_variant_unref (variant); - g_object_unref (atspi_settings); - - return value; -} - -static gboolean -a11y_invoke_module (const char *module_path) -{ - GModule *handle; - void (*invoke_fn) (void); - - if (!module_path) - { - g_warning ("Accessibility: invalid module path (NULL)"); - - return FALSE; - } - - if (!(handle = g_module_open (module_path, (GModuleFlags)0))) - { - g_warning ("Accessibility: failed to load module '%s': '%s'", - module_path, g_module_error ()); - - return FALSE; - } - - if (!g_module_symbol (handle, INIT_METHOD, (gpointer *)&invoke_fn)) - { - g_warning ("Accessibility: error library '%s' does not include " - "method '%s' required for accessibility support", - module_path, INIT_METHOD); - g_module_close (handle); - - return FALSE; - } - - invoke_fn (); - - return TRUE; -} - void panel_a11y_init (void) { - gchar *bridge_path = NULL; - if (a11y_initialized) return; @@ -137,20 +34,9 @@ panel_a11y_init (void) g_unsetenv ("NO_AT_BRIDGE"); g_unsetenv ("NO_GAIL"); - if (!should_enable_a11y ()) - return; - /* Load PanelUtilAccessible class */ g_type_class_unref (g_type_class_ref (PANEL_TYPE_UTIL_ACCESSIBLE)); - - bridge_path = get_atk_bridge_path (); - if (a11y_invoke_module (bridge_path)) - { - g_debug ("Unity accessibility started, using bridge on %s", bridge_path); - } - - g_free (bridge_path); - atk_get_root (); + atk_bridge_adaptor_init(NULL, NULL); a11y_initialized = TRUE; } -- cgit v1.2.3 From 6e4b84de96de4af8dc9394e7363b347502fd01fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Pi=C3=B1eiro?= Date: Tue, 3 Jul 2012 19:03:57 +0200 Subject: Reflect on HACKING the new dependency to libatk-adaptor (bzr r2455.4.4) --- HACKING | 1 + 1 file changed, 1 insertion(+) diff --git a/HACKING b/HACKING index f01837ed5..690929c03 100644 --- a/HACKING +++ b/HACKING @@ -7,6 +7,7 @@ If you want to hack on unity you need the following packages - gthread-2.0 - indicator - atk + - libatk-adaptor - libutouch-geis Or if you are on ubuntu run the command, apt-get build-dep unity -- cgit v1.2.3 From 9f0dcffa7dff2e040c187022b4fb71ab656d4d6b Mon Sep 17 00:00:00 2001 From: Marco Biscaro Date: Thu, 12 Jul 2012 11:03:12 -0300 Subject: Fixing float comparison (bzr r2353.5.6) --- launcher/Launcher.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/launcher/Launcher.cpp b/launcher/Launcher.cpp index 90b1639fc..ecaccc80f 100644 --- a/launcher/Launcher.cpp +++ b/launcher/Launcher.cpp @@ -964,7 +964,7 @@ float Launcher::DragLimiter(float x) nux::Color FullySaturateColor (nux::Color color) { float max = std::max(color.red, std::max(color.green, color.blue)); - if (max != 0) + if (max > 0.0f) { color = color * (1.0f / max); } -- cgit v1.2.3 From 1027e012407bd3072e850ec85dc9568afef994e6 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Wed, 8 Aug 2012 16:30:44 +0200 Subject: Add unity::launcher::Volume interface class with its implementation. (bzr r2540.12.1) --- launcher/Volume.h | 46 +++++++++++++ launcher/VolumeImpl.cpp | 120 ++++++++++++++++++++++++++++++++ launcher/VolumeImpl.h | 54 +++++++++++++++ tests/CMakeLists.txt | 3 + tests/gmockmount.c | 167 +++++++++++++++++++++++++++++++++++++++++++++ tests/gmockmount.h | 52 ++++++++++++++ tests/gmockvolume.c | 88 +++++++++++++++++++++--- tests/gmockvolume.h | 14 +++- tests/test_volume_impl.cpp | 80 ++++++++++++++++++++++ 9 files changed, 614 insertions(+), 10 deletions(-) create mode 100644 launcher/Volume.h create mode 100644 launcher/VolumeImpl.cpp create mode 100644 launcher/VolumeImpl.h create mode 100644 tests/gmockmount.c create mode 100644 tests/gmockmount.h create mode 100644 tests/test_volume_impl.cpp diff --git a/launcher/Volume.h b/launcher/Volume.h new file mode 100644 index 000000000..a51b8aeb6 --- /dev/null +++ b/launcher/Volume.h @@ -0,0 +1,46 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authored by: Andrea Azzarone + */ + +#ifndef UNITYSHELL_VOLUME_H +#define UNITYSHELL_VOLUME_H + +#include +#include + +namespace unity +{ +namespace launcher +{ + +class Volume : boost::noncopyable +{ +public: + virtual ~Volume() {} + + virtual std::string GetName() const = 0; + virtual std::string GetIconName() const = 0; + virtual std::string GetIdentifer() const = 0; + virtual bool IsMounted() const = 0; + virtual void MountAndOpenInFileManager() = 0; +}; + +} // namespace launcher +} // namespace unity + +#endif // UNITYSHELL_DEVICE_H \ No newline at end of file diff --git a/launcher/VolumeImpl.cpp b/launcher/VolumeImpl.cpp new file mode 100644 index 000000000..394d652d9 --- /dev/null +++ b/launcher/VolumeImpl.cpp @@ -0,0 +1,120 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authored by: Andrea Azzarone + */ + +#include "VolumeImpl.h" + +namespace unity +{ +namespace launcher +{ + +// +// Start private implementation +// + +class VolumeImpl::Impl +{ +public: + Impl(glib::Object const& volume) + : volume_(volume) + {} + + std::string GetName() const + { + return glib::String(g_volume_get_name(volume_)).Str(); + } + + std::string GetIconName() const + { + glib::Object icon(g_volume_get_icon(volume_)); + return glib::String(g_icon_to_string(icon)).Str(); + } + + std::string GetIdentifer() const + { + return glib::String(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UUID)).Str(); + } + + bool IsMounted() const + { + glib::Object mount(g_volume_get_mount(volume_)); + return static_cast(mount); + } + + void MountAndOpenInFileManager() + { + if (not IsMounted()) + Mount(); + OpenInFileManager(); + } + + void Mount() + { + // TODO: Implement it + } + + void OpenInFileManager() + { + // TODO: Implement it + } + + glib::Object volume_; +}; + +// +// End private implementation +// + +VolumeImpl::VolumeImpl(glib::Object const& volume) + : pimpl(new Impl(volume)) +{} + +VolumeImpl::~VolumeImpl() +{ + // For some weird reasons there are building issues removing this + // apparently useless dtor. +} + +std::string VolumeImpl::GetName() const +{ + return pimpl->GetName(); +} + +std::string VolumeImpl::GetIconName() const +{ + return pimpl->GetIconName(); +} + +std::string VolumeImpl::GetIdentifer() const +{ + return pimpl->GetIdentifer(); +} + +bool VolumeImpl::IsMounted() const +{ + return pimpl->IsMounted(); +} + +void VolumeImpl::MountAndOpenInFileManager() +{ + return pimpl->MountAndOpenInFileManager(); +} + +} // namespace launcher +} // namespace unity diff --git a/launcher/VolumeImpl.h b/launcher/VolumeImpl.h new file mode 100644 index 000000000..d836efea0 --- /dev/null +++ b/launcher/VolumeImpl.h @@ -0,0 +1,54 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright (C) 2012 Canonical Ltd + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 3 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * Authored by: Andrea Azzarone + */ + +#ifndef UNITYSHELL_VOLUME_IMPL_H +#define UNITYSHELL_VOLUME_IMPL_H + +#include + +#include + +#include "Volume.h" + +namespace unity +{ +namespace launcher +{ + +class VolumeImpl : public Volume +{ +public: + VolumeImpl(glib::Object const& volume); + virtual ~VolumeImpl(); + + virtual std::string GetName() const; + virtual std::string GetIconName() const; + virtual std::string GetIdentifer() const; + virtual bool IsMounted() const; + virtual void MountAndOpenInFileManager(); + +private: + class Impl; + std::unique_ptr pimpl; +}; + +} // namespace launcher +} // namespace unity + +#endif // UNITYSHELL_VOLUME_IMPL_H \ No newline at end of file diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7eb276781..8e84d0e87 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -225,6 +225,8 @@ if (GTEST_SRC_DIR AND test_switcher_controller.cpp test_switcher_model.cpp test_texture_cache.cpp + test_volume_impl.cpp + gmockmount.c gmockvolume.c ${CMAKE_SOURCE_DIR}/dash/AbstractPlacesGroup.cpp ${CMAKE_SOURCE_DIR}/dash/DashViewPrivate.cpp @@ -284,6 +286,7 @@ if (GTEST_SRC_DIR AND ${CMAKE_SOURCE_DIR}/launcher/SwitcherView.cpp ${CMAKE_SOURCE_DIR}/launcher/Tooltip.cpp ${CMAKE_SOURCE_DIR}/launcher/TrashLauncherIcon.cpp + ${CMAKE_SOURCE_DIR}/launcher/VolumeImpl.cpp ${CMAKE_SOURCE_DIR}/launcher/VolumeMonitorWrapper.cpp ${CMAKE_SOURCE_DIR}/unity-shared/Animator.cpp ${CMAKE_SOURCE_DIR}/unity-shared/BackgroundEffectHelper.cpp diff --git a/tests/gmockmount.c b/tests/gmockmount.c new file mode 100644 index 000000000..be72b713d --- /dev/null +++ b/tests/gmockmount.c @@ -0,0 +1,167 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * + * + * Authored by: Andrea Azzarone + * + */ + +#include + +#include "gmockmount.h" + +static void g_mock_mount_iface_init (GMountIface *iface); + +G_DEFINE_TYPE_WITH_CODE (GMockMount, g_mock_mount, G_TYPE_OBJECT, + G_IMPLEMENT_INTERFACE (G_TYPE_MOUNT, + g_mock_mount_iface_init)) + +static void +g_mock_mount_finalize (GObject *object) +{ + G_OBJECT_CLASS (g_mock_mount_parent_class)->finalize (object); +} + +static void +g_mock_mount_dispose (GObject *object) +{ + G_OBJECT_CLASS (g_mock_mount_parent_class)->dispose (object); +} + + +static void +g_mock_mount_class_init (GMockMountClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + + gobject_class->finalize = g_mock_mount_finalize; + gobject_class->dispose = g_mock_mount_dispose; +} + +static void +g_mock_mount_init (GMockMount *mock_mount) +{} + +GMockMount * +g_mock_mount_new () +{ + GMockMount *mount; + + mount = g_object_new (G_TYPE_MOCK_MOUNT, NULL); + + return mount; +} + +static GFile * +g_mock_mount_get_root (GMount *mount) +{ + return NULL; +} + +static GIcon * +g_mock_mount_get_icon (GMount *mount) +{ + return NULL; +} + +static char * +g_mock_mount_get_uuid (GMount *mount) +{ + return g_strdup (""); +} + +static char * +g_mock_mount_get_name (GMount *mount) +{ + return g_strdup (""); +} + +static GDrive * +g_mock_mount_get_drive (GMount *mount) +{ + return NULL; +} + +static GVolume * +g_mock_mount_get_volume (GMount *mount) +{ + return NULL; +} + +static gboolean +g_mock_mount_can_unmount (GMount *mount) +{ + return TRUE; +} + +static gboolean +g_mock_mount_can_eject (GMount *mount) +{ + return FALSE; +} + +static void +g_mock_mount_unmount (GMount *mount, + GMountUnmountFlags flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ +} + +static gboolean +g_mock_mount_unmount_finish (GMount *mount, + GAsyncResult *result, + GError **error) +{ + return TRUE; +} + +static void +g_mock_mount_eject (GMount *mount, + GMountUnmountFlags flags, + GCancellable *cancellable, + GAsyncReadyCallback callback, + gpointer user_data) +{ +} + +static gboolean +g_mock_mount_eject_finish (GMount *mount, + GAsyncResult *result, + GError **error) +{ + return TRUE; +} + + +static void +g_mock_mount_iface_init (GMountIface *iface) +{ + iface->get_root = g_mock_mount_get_root; + iface->get_name = g_mock_mount_get_name; + iface->get_icon = g_mock_mount_get_icon; + iface->get_uuid = g_mock_mount_get_uuid; + iface->get_drive = g_mock_mount_get_drive; + iface->get_volume = g_mock_mount_get_volume; + iface->can_unmount = g_mock_mount_can_unmount; + iface->can_eject = g_mock_mount_can_eject; + iface->unmount = g_mock_mount_unmount; + iface->unmount_finish = g_mock_mount_unmount_finish; + iface->eject = g_mock_mount_eject; + iface->eject_finish = g_mock_mount_eject_finish; +} diff --git a/tests/gmockmount.h b/tests/gmockmount.h new file mode 100644 index 000000000..1910445e6 --- /dev/null +++ b/tests/gmockmount.h @@ -0,0 +1,52 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License version 3, as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the applicable version of the GNU Lesser General Public + * License for more details. + * + * You should have received a copy of both the GNU Lesser General Public + * License version 3 along with this program. If not, see + * + * + * Authored by: Andrea Azzarone + * + */ + +#ifndef UNITYSHELL_G_MOCK_MOUNT_H +#define UNITYSHELL_G_MOCK_MOUNT_H + +#include + +G_BEGIN_DECLS + +#define G_TYPE_MOCK_MOUNT (g_mock_mount_get_type ()) +#define G_MOCK_MOUNT(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), G_TYPE_MOCK_MOUNT, GMockMount)) +#define G_MOCK_MOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), G_TYPE_MOCK_MOUNT, GMockMountClass)) +#define G_IS_MOCK_MOUNT(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), G_TYPE_MOCK_MOUNT)) +#define G_IS_MOCK_MOUNT_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), G_TYPE_MOCK_MOUNT)) + +typedef struct _GMockMount GMockMount; +typedef struct _GMockMountClass GMockMountClass; + +struct _GMockMount { + GObject parent; +}; + +struct _GMockMountClass { + GObjectClass parent_class; +}; + +GType g_mock_mount_get_type (void) G_GNUC_CONST; +GMockMount * g_mock_mount_new (); + +G_END_DECLS + +#endif // UNITYSHELL_G_MOCK_MOUNT_H diff --git a/tests/gmockvolume.c b/tests/gmockvolume.c index 5ee2d23a1..8e46a7d86 100644 --- a/tests/gmockvolume.c +++ b/tests/gmockvolume.c @@ -24,11 +24,11 @@ #include "gmockvolume.h" -static void g_mock_volume_volume_iface_init (GVolumeIface *iface); +static void g_mock_volume_iface_init (GVolumeIface *iface); G_DEFINE_TYPE_WITH_CODE (GMockVolume, g_mock_volume, G_TYPE_OBJECT, G_IMPLEMENT_INTERFACE (G_TYPE_VOLUME, - g_mock_volume_volume_iface_init)) + g_mock_volume_iface_init)) static void g_mock_volume_finalize (GObject *object) @@ -36,17 +36,43 @@ g_mock_volume_finalize (GObject *object) G_OBJECT_CLASS (g_mock_volume_parent_class)->finalize (object); } +static void +g_mock_volume_dispose (GObject *object) +{ + GMockVolume *self = G_MOCK_VOLUME (object); + + if (self->name) + g_free(self->name); + + if (self->icon) + g_object_unref(self->icon); + + if (self->uuid) + g_free(self->uuid); + + if (self->mount) + g_object_unref(self->mount); + + G_OBJECT_CLASS (g_mock_volume_parent_class)->dispose (object); +} + + static void g_mock_volume_class_init (GMockVolumeClass *klass) { GObjectClass *gobject_class = G_OBJECT_CLASS (klass); gobject_class->finalize = g_mock_volume_finalize; + gobject_class->dispose = g_mock_volume_dispose; } static void g_mock_volume_init (GMockVolume *mock_volume) { + mock_volume->name = g_strdup(""); + mock_volume->icon = g_icon_new_for_string("", NULL); + mock_volume->uuid = g_strdup(""); + mock_volume->mount = NULL; } GMockVolume * @@ -59,22 +85,53 @@ g_mock_volume_new () return volume; } +void +g_mock_volume_set_name (GMockVolume *volume, const char* name) +{ + if (volume->name) + g_free(volume->name); + + volume->name = g_strdup (name); +} + static char * g_mock_volume_get_name (GVolume *volume) { - return g_strdup (""); + GMockVolume *self = G_MOCK_VOLUME (volume); + return g_strdup (self->name); +} + +void +g_mock_volume_set_icon (GMockVolume *volume, GIcon *icon) +{ + if (volume->icon) + g_object_unref(volume->icon); + + volume->icon = icon; } + static GIcon * g_mock_volume_get_icon (GVolume *volume) { - return g_icon_new_for_string("", NULL); + GMockVolume *self = G_MOCK_VOLUME (volume); + return g_object_ref (self->icon); +} + +void +g_mock_volume_set_uuid (GMockVolume *volume, const char* uuid) +{ + if (volume->uuid) + g_free(volume->uuid); + + volume->uuid = g_strdup (uuid); } static char * g_mock_volume_get_uuid (GVolume *volume) { - return NULL; + GMockVolume *self = G_MOCK_VOLUME (volume); + return g_strdup (self->uuid); } static GDrive * @@ -83,10 +140,20 @@ g_mock_volume_get_drive (GVolume *volume) return NULL; } +void +g_mock_volume_set_mount (GMockVolume *volume, GMount *mount) +{ + if (volume->mount) + g_object_unref(volume->mount); + + volume->mount = mount; +} + static GMount * g_mock_volume_get_mount (GVolume *volume) { - return NULL; + GMockVolume *self = G_MOCK_VOLUME (volume); + return self->mount; } static gboolean @@ -115,6 +182,7 @@ g_mock_volume_mount (GVolume *volume, GAsyncReadyCallback callback, gpointer user_data) { + callback(NULL, NULL, user_data); } static gboolean @@ -146,6 +214,11 @@ static gchar * g_mock_volume_get_identifier (GVolume *volume, const gchar *kind) { + GMockVolume *self = G_MOCK_VOLUME (volume); + + if (!g_strcmp0 (kind, G_VOLUME_IDENTIFIER_KIND_UUID)) + return g_strdup (self->uuid); + return NULL; } @@ -156,7 +229,7 @@ g_mock_volume_enumerate_identifiers (GVolume *volume) } static void -g_mock_volume_volume_iface_init (GVolumeIface *iface) +g_mock_volume_iface_init (GVolumeIface *iface) { iface->get_name = g_mock_volume_get_name; iface->get_icon = g_mock_volume_get_icon; @@ -173,4 +246,3 @@ g_mock_volume_volume_iface_init (GVolumeIface *iface) iface->get_identifier = g_mock_volume_get_identifier; iface->enumerate_identifiers = g_mock_volume_enumerate_identifiers; } - diff --git a/tests/gmockvolume.h b/tests/gmockvolume.h index 0c9ee118a..a1846087c 100644 --- a/tests/gmockvolume.h +++ b/tests/gmockvolume.h @@ -38,14 +38,24 @@ typedef struct _GMockVolumeClass GMockVolumeClass; struct _GMockVolume { GObject parent; + + char *name; + GIcon *icon; + char *uuid; + GMount *mount; }; struct _GMockVolumeClass { GObjectClass parent_class; }; -GType g_mock_volume_get_type (void) G_GNUC_CONST; -GMockVolume * g_mock_volume_new (); +GType g_mock_volume_get_type (void) G_GNUC_CONST; +GMockVolume * g_mock_volume_new (); + +void g_mock_volume_set_name (GMockVolume *volume, const char *name); +void g_mock_volume_set_icon (GMockVolume *volume, GIcon *icon); +void g_mock_volume_set_uuid (GMockVolume *volume, const char *uuid); +void g_mock_volume_set_mount (GMockVolume *volume, GMount *mount); G_END_DECLS diff --git a/tests/test_volume_impl.cpp b/tests/test_volume_impl.cpp new file mode 100644 index 000000000..b4fa042cb --- /dev/null +++ b/tests/test_volume_impl.cpp @@ -0,0 +1,80 @@ +/* + * Copyright 2012 Canonical Ltd. + * + * This program is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 3, as published + * by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranties of + * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR + * PURPOSE. See the GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * version 3 along with this program. If not, see + * + * + * Authored by: Andrea Azzarone + */ + +#include + +#include +using namespace testing; + +#include "gmockmount.h" +#include "gmockvolume.h" +#include "launcher/VolumeImpl.h" +#include "test_utils.h" +using namespace unity; + +namespace +{ + +class TestVolumeImpl : public Test +{ +public: + void SetUp() + { + gvolume_ = g_mock_volume_new(); + volume_.reset(new launcher::VolumeImpl(glib::Object(G_VOLUME(gvolume_.RawPtr())))); + } + + glib::Object gvolume_; + std::unique_ptr volume_; +}; + +TEST_F(TestVolumeImpl, TestGetName) +{ + std::string const volume_name("Test Device"); + + g_mock_volume_set_name(gvolume_, volume_name.c_str()); + EXPECT_EQ(volume_->GetName(), volume_name); +} + +TEST_F(TestVolumeImpl, TestGetIconName) +{ + std::string const icon_name("gnome-dev-cdrom"); + + g_mock_volume_set_icon(gvolume_, g_icon_new_for_string(icon_name.c_str(), NULL)); + EXPECT_EQ(volume_->GetIconName(), icon_name); +} + +TEST_F(TestVolumeImpl, TestGetIdentifer) +{ + std::string const uuid("0123456789abc"); + + g_mock_volume_set_uuid(gvolume_, uuid.c_str()); + EXPECT_EQ(volume_->GetIdentifer(), uuid); +} + +TEST_F(TestVolumeImpl, TestIsMounted) +{ + g_mock_volume_set_mount(gvolume_, nullptr); + ASSERT_FALSE(volume_->IsMounted()); + + g_mock_volume_set_mount(gvolume_, G_MOUNT(g_mock_mount_new())); + EXPECT_TRUE(volume_->IsMounted()); +} + +} -- cgit v1.2.3 From 875179cd8d13a9d3e5bcfe353d18aa5b129b8e60 Mon Sep 17 00:00:00 2001 From: Andrea Azzarone Date: Wed, 8 Aug 2012 17:56:23 +0200 Subject: Remove device options in ccsm. Refactor DeviceSettings. Will add a unit test later. (bzr r2540.12.2) --- launcher/DeviceLauncherIcon.cpp | 46 +++----- launcher/DevicesSettings.cpp | 201 ++++++++++++++++++++-------------- launcher/DevicesSettings.h | 43 +++----- launcher/VolumeImpl.h | 1 + plugins/unityshell/src/unityshell.cpp | 5 - plugins/unityshell/unityshell_xml.in | 20 ---- 6 files changed, 145 insertions(+), 171 deletions(-) diff --git a/launcher/DeviceLauncherIcon.cpp b/launcher/DeviceLauncherIcon.cpp index fe5b46d8f..35129d17a 100644 --- a/launcher/DeviceLauncherIcon.cpp +++ b/launcher/DeviceLauncherIcon.cpp @@ -54,10 +54,7 @@ DeviceLauncherIcon::DeviceLauncherIcon(glib::Object const& volume) // Checks if in favorites! glib::String uuid(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UUID)); - DeviceList favorites = DevicesSettings::GetDefault().GetFavorites(); - DeviceList::iterator pos = std::find(favorites.begin(), favorites.end(), uuid.Str()); - - keep_in_launcher_ = pos != favorites.end(); + keep_in_launcher_ = DevicesSettings::GetDefault().IsAFavoriteDevice(uuid.Str()); UpdateDeviceIcon(); UpdateVisibility(); @@ -77,26 +74,15 @@ void DeviceLauncherIcon::OnVolumeChanged(GVolume* volume) void DeviceLauncherIcon::UpdateVisibility() { - switch (DevicesSettings::GetDefault().GetDevicesOption()) - { - case DevicesSettings::NEVER: - SetQuirk(QUIRK_VISIBLE, false); - break; - case DevicesSettings::ONLY_MOUNTED: - if (keep_in_launcher_) - { - SetQuirk(QUIRK_VISIBLE, true); - } - else - { - glib::Object mount(g_volume_get_mount(volume_)); - SetQuirk(QUIRK_VISIBLE, mount); - } - break; - case DevicesSettings::ALWAYS: - SetQuirk(QUIRK_VISIBLE, true); - break; - } + if (keep_in_launcher_) + { + SetQuirk(QUIRK_VISIBLE, true); + } + else + { + glib::Object mount(g_volume_get_mount(volume_)); + SetQuirk(QUIRK_VISIBLE, mount); + } } void DeviceLauncherIcon::UpdateDeviceIcon() @@ -126,8 +112,7 @@ std::list DeviceLauncherIcon::GetMenus() glib::Object drive(g_volume_get_drive(volume_)); // "Lock to Launcher"/"Unlock from Launcher" item - if (DevicesSettings::GetDefault().GetDevicesOption() == DevicesSettings::ONLY_MOUNTED - && drive && !g_drive_is_media_removable (drive)) + if (drive && !g_drive_is_media_removable (drive)) { menu_item = dbusmenu_menuitem_new(); @@ -437,16 +422,15 @@ void DeviceLauncherIcon::StopDrive() void DeviceLauncherIcon::OnSettingsChanged() { - // Checks if in favourites! glib::String uuid(g_volume_get_identifier(volume_, G_VOLUME_IDENTIFIER_KIND_UUID)); - DeviceList favorites = DevicesSettings::GetDefault().GetFavorites(); - DeviceList::iterator pos = std::find(favorites.begin(), favorites.end(), uuid.Str()); - - keep_in_launcher_ = pos != favorites.end(); + keep_in_launcher_ = DevicesSettings::GetDefault().IsAFavoriteDevice(uuid.Str()); UpdateVisibility(); } +// +// Introspection +// std::string DeviceLauncherIcon::GetName() const { return "DeviceLauncherIcon"; diff --git a/launcher/DevicesSettings.cpp b/launcher/DevicesSettings.cpp index 7b09bf070..34e7eafab 100644 --- a/launcher/DevicesSettings.cpp +++ b/launcher/DevicesSettings.cpp @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-12 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -14,130 +14,161 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * Authored by: Andrea Azzarone + * Authored by: Andrea Azzarone */ -#include "DevicesSettings.h" - -#include +#include +#include -namespace unity { +#include "DevicesSettings.h" +#include +#include -namespace { +namespace unity +{ +namespace +{ -const char* SETTINGS_NAME = "com.canonical.Unity.Devices"; +nux::logging::Logger logger("unity.device_settings"); -void on_settings_updated(GSettings* settings, - const gchar* key, - DevicesSettings* self); +const std::string SETTINGS_NAME = "com.canonical.Unity.Devices"; +const std::string KEY_NAME = "favorites"; -} // anonymous namespace +} // unnamed namespace +// +// Singleton +// DevicesSettings& DevicesSettings::GetDefault() { static DevicesSettings instance; return instance; } -DevicesSettings::DevicesSettings() - : settings_(g_settings_new(SETTINGS_NAME)) - , ignore_signals_(false) - , devices_option_(ONLY_MOUNTED) +// +// Start private implementation +// +class DevicesSettings::Impl { +public: + Impl(DevicesSettings* parent) + : parent_(parent) + , settings_(g_settings_new(SETTINGS_NAME.c_str())) + , ignore_signals_(false) + { + DownloadFavorites(); + ConnectSignals(); + } - g_signal_connect(settings_, "changed", G_CALLBACK(on_settings_updated), this); + void ConnectSignals() + { + settings_changed_signal_.Connect(settings_, "changed::" + KEY_NAME, + [this] (GSettings*, gchar*) { + if (ignore_signals_) + return; + + DownloadFavorites(); + parent_->changed.emit(); + }); + } - Refresh(); -} + void DownloadFavorites() + { + std::shared_ptr downloaded_favorites(g_settings_get_strv(settings_, KEY_NAME.c_str()), g_strfreev); -void DevicesSettings::Refresh() -{ - gchar** favs = g_settings_get_strv(settings_, "favorites"); + favorites_.clear(); - favorites_.clear(); + auto downloaded_favorites_raw = downloaded_favorites.get(); + for (int i = 0; downloaded_favorites_raw[i]; ++i) + favorites_.push_back(downloaded_favorites_raw[i]); + } - for (int i = 0; favs[i] != NULL; i++) - favorites_.push_back(favs[i]); + void UploadFavorites() + { + const int size = favorites_.size(); + const char* favorites_to_be_uploaded[size+1]; + + int index = 0; + for (auto favorite : favorites_) + favorites_to_be_uploaded[index++] = favorite.c_str(); + favorites_to_be_uploaded[index] = nullptr; + + ignore_signals_ = true; + if (!g_settings_set_strv(settings_, KEY_NAME.c_str(), favorites_to_be_uploaded)) + { + LOG_WARNING(logger) << "Saving favorites failed."; + } + ignore_signals_ = false; + } - g_strfreev(favs); -} + DeviceList GetFavorites() const + { + return favorites_; + } -void DevicesSettings::AddFavorite(std::string const& uuid) -{ - if (uuid.empty()) - return; + bool IsAFavoriteDevice(std::string const& uuid) const + { + auto begin = std::begin(favorites_); + auto end = std::end(favorites_); + return std::find(begin, end, uuid) == end; + } + + void AddFavorite(std::string const& uuid) + { + if (uuid.empty()) + return; - favorites_.push_back(uuid); + favorites_.push_back(uuid); - SaveFavorites(favorites_); - Refresh(); -} + UploadFavorites(); + } -void DevicesSettings::RemoveFavorite(std::string const& uuid) -{ - if (uuid.empty()) - return; + void RemoveFavorite(std::string const& uuid) + { + if (uuid.empty()) + return; - DeviceList::iterator pos = std::find(favorites_.begin(), favorites_.end(), uuid); - if (pos == favorites_.end()) - return; + if (!IsAFavoriteDevice(uuid)) + return; - favorites_.erase(pos); - SaveFavorites(favorites_); - Refresh(); -} + favorites_.remove(uuid); + UploadFavorites(); + } -void DevicesSettings::SaveFavorites(DeviceList const& favorites) -{ - const int size = favorites.size(); - const char* favs[size + 1]; - favs[size] = NULL; + DevicesSettings* parent_; + glib::Object settings_; + DeviceList favorites_; + bool ignore_signals_; + glib::Signal settings_changed_signal_; - int index = 0; - for (DeviceList::const_iterator i = favorites.begin(), end = favorites.end(); - i != end; ++i, ++index) - { - favs[index] = i->c_str(); - } +}; - ignore_signals_ = true; - if (!g_settings_set_strv(settings_, "favorites", favs)) - g_warning("Saving favorites failed."); - ignore_signals_ = false; -} +// +// End private implementation +// +DevicesSettings::DevicesSettings() + : pimpl(new Impl(this)) +{} -void DevicesSettings::Changed(std::string const& key) +DeviceList DevicesSettings::GetFavorites() const { - if (ignore_signals_) - return; - - Refresh(); - - changed.emit(); + return pimpl->GetFavorites(); } -void DevicesSettings::SetDevicesOption(DevicesOption devices_option) +bool DevicesSettings::IsAFavoriteDevice(std::string const& uuid) const { - if (devices_option == devices_option_) - return; - - devices_option_ = devices_option; - - changed.emit(); + return pimpl->IsAFavoriteDevice(uuid); } -namespace { - -void on_settings_updated(GSettings* settings, - const gchar* key, - DevicesSettings* self) +void DevicesSettings::AddFavorite(std::string const& uuid) { - if (settings and key) { - self->Changed(key); - } + pimpl->AddFavorite(uuid); } -} // anonymous namespace +void DevicesSettings::RemoveFavorite(std::string const& uuid) +{ + pimpl->RemoveFavorite(uuid); +} } // namespace unity diff --git a/launcher/DevicesSettings.h b/launcher/DevicesSettings.h index ad2a24de8..8c911f50b 100644 --- a/launcher/DevicesSettings.h +++ b/launcher/DevicesSettings.h @@ -1,6 +1,6 @@ // -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- /* - * Copyright (C) 2010 Canonical Ltd + * Copyright (C) 2010-12 Canonical Ltd * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License version 3 as @@ -14,59 +14,42 @@ * You should have received a copy of the GNU General Public License * along with this program. If not, see . * - * Authored by: Andrea Azzarone + * Authored by: Andrea Azzarone */ -#ifndef DEVICES_SETTINGS_H -#define DEVICES_SETTINGS_H +#ifndef UNITYSHELL_DEVICES_SETTINGS_H +#define UNITYSHELLDEVICES_SETTINGS_H +#include +#include #include #include -#include -#include -#include -#include +#include -namespace unity { +namespace unity +{ typedef std::list DeviceList; class DevicesSettings : boost::noncopyable { public: - typedef enum - { - NEVER = 0, - ONLY_MOUNTED, - ALWAYS - - } DevicesOption; - DevicesSettings(); static DevicesSettings& GetDefault(); - void SetDevicesOption(DevicesOption devices_option); - DevicesOption GetDevicesOption() { return devices_option_; }; - - DeviceList const& GetFavorites() { return favorites_; }; + DeviceList GetFavorites() const; + bool IsAFavoriteDevice(std::string const& uuid) const; void AddFavorite(std::string const& uuid); void RemoveFavorite(std::string const& uuid); - - void Changed(std::string const& key); // Signals sigc::signal changed; private: - void Refresh(); - void SaveFavorites(DeviceList const& favorites); - - glib::Object settings_; - DeviceList favorites_; - bool ignore_signals_; - DevicesOption devices_option_; + class Impl; + std::unique_ptr pimpl; }; } // namespace unity diff --git a/launcher/VolumeImpl.h b/launcher/VolumeImpl.h index d836efea0..e46d2602b 100644 --- a/launcher/VolumeImpl.h +++ b/launcher/VolumeImpl.h @@ -22,6 +22,7 @@ #include +#include #include #include "Volume.h" diff --git a/plugins/unityshell/src/unityshell.cpp b/plugins/unityshell/src/unityshell.cpp index 4ea5106f2..c8efc79aa 100644 --- a/plugins/unityshell/src/unityshell.cpp +++ b/plugins/unityshell/src/unityshell.cpp @@ -29,7 +29,6 @@ #include "Launcher.h" #include "LauncherIcon.h" #include "LauncherController.h" -#include "DevicesSettings.h" #include "PluginAdapter.h" #include "QuicklistManager.h" #include "StartupNotifyService.h" @@ -286,7 +285,6 @@ UnityScreen::UnityScreen(CompScreen* screen) optionSetIconSizeNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); optionSetAutohideAnimationNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); optionSetDashBlurExperimentalNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); - optionSetDevicesOptionNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); optionSetShortcutOverlayNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); optionSetShowDesktopIconNotify(boost::bind(&UnityScreen::optionChanged, this, _1, _2)); optionSetShowLauncherInitiate(boost::bind(&UnityScreen::showLauncherKeyInitiate, this, _1, _2, _3)); @@ -2880,9 +2878,6 @@ void UnityScreen::optionChanged(CompOption* opt, UnityshellOptions::Options num) case UnityshellOptions::AutomaximizeValue: PluginAdapter::Default()->SetCoverageAreaBeforeAutomaximize(optionGetAutomaximizeValue() / 100.0f); break; - case UnityshellOptions::DevicesOption: - unity::DevicesSettings::GetDefault().SetDevicesOption((unity::DevicesSettings::DevicesOption) optionGetDevicesOption()); - break; case UnityshellOptions::AltTabTimeout: switcher_controller_->detail_on_timeout = optionGetAltTabTimeout(); case UnityshellOptions::AltTabBiasViewport: diff --git a/plugins/unityshell/unityshell_xml.in b/plugins/unityshell/unityshell_xml.in index 5b89d6543..7b34bf4fe 100644 --- a/plugins/unityshell/unityshell_xml.in +++ b/plugins/unityshell/unityshell_xml.in @@ -394,26 +394,6 @@ 75 - -