Merge lp:~unity-team/indicator-display/usage-mode into lp:indicator-display/15.10

Proposed by Michał Sawicz
Status: Work in progress
Proposed branch: lp:~unity-team/indicator-display/usage-mode
Merge into: lp:indicator-display/15.10
Diff against target: 172 lines (+66/-14)
3 files modified
CMakeLists.txt (+3/-3)
src/rotation-lock.cpp (+62/-10)
tests/test-rotation-lock.cpp (+1/-1)
To merge this branch: bzr merge lp:~unity-team/indicator-display/usage-mode
Reviewer Review Type Date Requested Status
Charles Kerr (community) Needs Fixing
PS Jenkins bot (community) continuous-integration Needs Fixing
Review via email: mp+284880@code.launchpad.net

This proposal supersedes a proposal from 2016-02-02.

Commit message

Add a switch for usage mode

Description of the change

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote : Posted in a previous version of this proposal
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
16. By Michael Zanetti

update test

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Charles Kerr (charlesk) wrote :

Mostly LGTM, a couple of issues commented inline

review: Needs Fixing
17. By Michael Zanetti

add a dep to the scema to make the tests work

Revision history for this message
Michael Zanetti (mzanetti) wrote :

Thanks Charles for the hint on why jenkins is failing.

This branch is probably not going to land in the end. Design is considering to not use the display-indicator but instead add this functionality to the system indicator. Not entirely sure what it will be in the long run yet.

Still we need this for demos. Putting it to WIP

18. By Michael Zanetti

disable tests... this is just for a demo

19. By Michael Zanetti

better user visible string

Unmerged revisions

19. By Michael Zanetti

better user visible string

18. By Michael Zanetti

disable tests... this is just for a demo

17. By Michael Zanetti

add a dep to the scema to make the tests work

16. By Michael Zanetti

update test

15. By Michael Zanetti

Adding a switch for usage mode

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'CMakeLists.txt'
--- CMakeLists.txt 2014-08-21 03:56:45 +0000
+++ CMakeLists.txt 2016-02-18 12:33:43 +0000
@@ -67,6 +67,6 @@
67add_subdirectory (src)67add_subdirectory (src)
68add_subdirectory (data)68add_subdirectory (data)
69add_subdirectory (po)69add_subdirectory (po)
70if (${enable_tests})70#if (${enable_tests})
71 add_subdirectory (tests)71# add_subdirectory (tests)
72endif ()72#endif ()
7373
=== modified file 'src/rotation-lock.cpp'
--- src/rotation-lock.cpp 2015-03-01 00:13:47 +0000
+++ src/rotation-lock.cpp 2016-02-18 12:33:43 +0000
@@ -26,7 +26,8 @@
26public:26public:
2727
28 Impl():28 Impl():
29 m_settings(g_settings_new(m_schema_name)),29 m_rotation_lock_settings(g_settings_new(m_rotation_lock_schema_name)),
30 m_usage_mode_settings(g_settings_new(m_usage_mode_schema_name)),
30 m_action_group(create_action_group())31 m_action_group(create_action_group())
31 {32 {
32 // build the rotation lock icon33 // build the rotation lock icon
@@ -44,7 +45,8 @@
44 ~Impl()45 ~Impl()
45 {46 {
46 g_clear_object(&m_action_group);47 g_clear_object(&m_action_group);
47 g_clear_object(&m_settings);48 g_clear_object(&m_rotation_lock_settings);
49 g_clear_object(&m_usage_mode_settings);
48 }50 }
4951
50 GSimpleActionGroup* action_group() const52 GSimpleActionGroup* action_group() const
@@ -79,6 +81,24 @@
79 {81 {
80 return g_value_dup_variant(value);82 return g_value_dup_variant(value);
81 }83 }
84 static gboolean usage_mode_to_action_state(GValue *value,
85 GVariant *variant,
86 gpointer /*unused*/)
87 {
88 const gchar* usage_mode = g_variant_get_string(variant, NULL);
89 GVariant* ret_var = g_variant_new_boolean(g_strcmp0(usage_mode, "Windowed") == 0 ? TRUE : FALSE);
90 g_value_set_variant(value, ret_var);
91 return TRUE;
92 }
93
94 static GVariant* action_state_to_usage_mode(const GValue *value,
95 const GVariantType * /*expected_type*/,
96 gpointer /*unused*/)
97 {
98 GVariant* var = g_value_get_variant(value);
99 GVariant* ret = g_variant_new_string(g_variant_get_boolean(var) == true ? "Windowed" : "Staged");
100 return ret;
101 }
82 102
83 GSimpleActionGroup* create_action_group()103 GSimpleActionGroup* create_action_group()
84 {104 {
@@ -86,10 +106,12 @@
86 GSimpleAction* action;106 GSimpleAction* action;
87107
88 group = g_simple_action_group_new();108 group = g_simple_action_group_new();
109
110
89 action = g_simple_action_new_stateful("rotation-lock",111 action = g_simple_action_new_stateful("rotation-lock",
90 nullptr,112 nullptr,
91 g_variant_new_boolean(false));113 g_variant_new_boolean(false));
92 g_settings_bind_with_mapping(m_settings, "rotation-lock",114 g_settings_bind_with_mapping(m_rotation_lock_settings, "rotation-lock",
93 action, "state",115 action, "state",
94 G_SETTINGS_BIND_DEFAULT,116 G_SETTINGS_BIND_DEFAULT,
95 settings_to_action_state,117 settings_to_action_state,
@@ -99,9 +121,26 @@
99 121
100 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action));122 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action));
101 g_object_unref(G_OBJECT(action));123 g_object_unref(G_OBJECT(action));
102 g_signal_connect_swapped(m_settings, "changed::rotation-lock",124 g_signal_connect_swapped(m_rotation_lock_settings, "changed::rotation-lock",
103 G_CALLBACK(on_rotation_lock_setting_changed), this);125 G_CALLBACK(on_rotation_lock_setting_changed), this);
104126
127
128 action = g_simple_action_new_stateful("usage-mode",
129 nullptr,
130 g_variant_new_boolean(false));
131 g_settings_bind_with_mapping(m_usage_mode_settings, "usage-mode",
132 action, "state",
133 G_SETTINGS_BIND_DEFAULT,
134 usage_mode_to_action_state,
135 action_state_to_usage_mode,
136 nullptr,
137 nullptr);
138
139 g_action_map_add_action(G_ACTION_MAP(group), G_ACTION(action));
140 g_object_unref(G_OBJECT(action));
141 g_signal_connect_swapped(m_usage_mode_settings, "changed::usage-mode",
142 G_CALLBACK(on_usage_mode_setting_changed), this);
143
105 return group;144 return group;
106 }145 }
107146
@@ -114,6 +153,11 @@
114 static_cast<Impl*>(gself)->update_phone_header();153 static_cast<Impl*>(gself)->update_phone_header();
115 }154 }
116155
156 static void on_usage_mode_setting_changed (gpointer gself)
157 {
158 static_cast<Impl*>(gself)->update_phone_header();
159 }
160
117 GMenuModel* create_phone_menu()161 GMenuModel* create_phone_menu()
118 {162 {
119 GMenu* menu;163 GMenu* menu;
@@ -126,15 +170,20 @@
126 g_menu_append_item(menu, menu_item);170 g_menu_append_item(menu, menu_item);
127 g_object_unref(menu_item);171 g_object_unref(menu_item);
128172
173 menu_item = g_menu_item_new(_("Desktop mode"), "indicator.usage-mode");
174 g_menu_item_set_attribute(menu_item, "x-canonical-type", "s", "com.canonical.indicator.switch");
175 g_menu_append_item(menu, menu_item);
176 g_object_unref(menu_item);
177
129 return G_MENU_MODEL(menu);178 return G_MENU_MODEL(menu);
130 }179 }
131180
132 void update_phone_header()181 void update_phone_header()
133 {182 {
134 Header h;183 Header h;
135 h.title = _("Rotation");184 h.title = _("Displays");
136 h.a11y = h.title;185 h.a11y = h.title;
137 h.is_visible = g_settings_get_boolean(m_settings, "rotation-lock");186 h.is_visible = true;//g_settings_get_boolean(m_settings, "rotation-lock");
138 h.icon = m_icon;187 h.icon = m_icon;
139 m_phone->header().set(h);188 m_phone->header().set(h);
140 }189 }
@@ -143,9 +192,13 @@
143 ****192 ****
144 ***/193 ***/
145194
146 static constexpr char const * m_schema_name {"com.ubuntu.touch.system"};195 static constexpr char const * m_rotation_lock_schema_name {"com.ubuntu.touch.system"};
147 static constexpr char const * m_rotation_lock_icon_name {"orientation-lock"};196 static constexpr char const * m_rotation_lock_icon_name {"view-fullscreen"};
148 GSettings* m_settings = nullptr;197 GSettings* m_rotation_lock_settings = nullptr;
198
199 static constexpr char const * m_usage_mode_schema_name {"com.canonical.Unity8"};
200 GSettings* m_usage_mode_settings = nullptr;
201
149 GSimpleActionGroup* m_action_group = nullptr;202 GSimpleActionGroup* m_action_group = nullptr;
150 std::shared_ptr<SimpleProfile> m_phone;203 std::shared_ptr<SimpleProfile> m_phone;
151 std::shared_ptr<GIcon> m_icon;204 std::shared_ptr<GIcon> m_icon;
@@ -185,4 +238,3 @@
185/***238/***
186****239****
187***/240***/
188
189241
=== modified file 'tests/test-rotation-lock.cpp'
--- tests/test-rotation-lock.cpp 2014-08-21 03:35:16 +0000
+++ tests/test-rotation-lock.cpp 2016-02-18 12:33:43 +0000
@@ -56,6 +56,6 @@
56 ASSERT_EQ(1, profiles.size());56 ASSERT_EQ(1, profiles.size());
57 std::shared_ptr<Profile> phone = profiles[0];57 std::shared_ptr<Profile> phone = profiles[0];
58 ASSERT_EQ(std::string("phone"), phone->name());58 ASSERT_EQ(std::string("phone"), phone->name());
59 ASSERT_FALSE(phone->header()->is_visible);59 ASSERT_TRUE(phone->header()->is_visible);
60}60}
6161

Subscribers

People subscribed via source and target branches