comparison pui-application.c @ 56:08747f3a718b

Add new setting to hide indicator menu items The setting hide-menu-items is an array of strings containing the actions associated with menu items that should be hidden from the indicator menu.
author Guido Berhoerster <guido+pui@berhoerster.name>
date Tue, 16 Aug 2022 16:19:02 +0200
parents 24cba399757f
children
comparison
equal deleted inserted replaced
55:24cba399757f 56:08747f3a718b
189 g_error_free(error); 189 g_error_free(error);
190 } 190 }
191 } 191 }
192 192
193 static void 193 static void
194 update_menu_item(GtkWidget* widget, gpointer user_data)
195 {
196 gchar ** hidden_menu_items = user_data;
197 const gchar * action_name;
198 const gchar * name;
199
200 g_return_if_fail(GTK_IS_MENU_ITEM(widget));
201 action_name = gtk_actionable_get_action_name(GTK_ACTIONABLE(widget));
202 if (!g_str_has_prefix(action_name, "app.")) {
203 return;
204 }
205 name = action_name + strlen("app.");
206 gtk_widget_set_visible(widget,
207 !g_strv_contains((const gchar * const *)hidden_menu_items, name));
208 }
209
210 static void
211 update_menu_items(PuiApplication *self)
212 {
213 gchar ** hidden_menu_items;
214 GtkMenu * menu;
215
216 menu = app_indicator_get_menu(self->indicator);
217 hidden_menu_items = g_settings_get_strv(self->settings,
218 "hide-menu-items");
219 g_return_if_fail(hidden_menu_items != NULL);
220 g_return_if_fail((menu != NULL) && GTK_IS_CONTAINER(menu));
221 gtk_container_foreach(GTK_CONTAINER(menu), update_menu_item,
222 hidden_menu_items);
223 g_strfreev(hidden_menu_items);
224 }
225
226 static void
194 update_indicator(PuiApplication *self, const gchar *title) 227 update_indicator(PuiApplication *self, const gchar *title)
195 { 228 {
196 switch (self->state) { 229 switch (self->state) {
197 case PUI_STATE_INITIAL: 230 case PUI_STATE_INITIAL:
198 app_indicator_set_status(self->indicator, 231 app_indicator_set_status(self->indicator,
355 title = g_strdup(self->error_message); 388 title = g_strdup(self->error_message);
356 break; 389 break;
357 } 390 }
358 391
359 update_indicator(self, title); 392 update_indicator(self, title);
393 update_menu_items(self);
360 update_notification(self, title, body); 394 update_notification(self, title, body);
361 395
362 g_debug("indicator icon: %s, notification title: \"%s\", " 396 g_debug("indicator icon: %s, notification title: \"%s\", "
363 "notification body: \"%s\"", icon_names[self->state], title, body); 397 "notification body: \"%s\"", icon_names[self->state], title, body);
364 398
426 g_free(old_state); 460 g_free(old_state);
427 } 461 }
428 } 462 }
429 463
430 static void 464 static void
465 on_hide_menu_items_changed(GSettings *settings, gchar *key, gpointer user_data)
466 {
467 g_debug("setting hide-menu-items changed");
468 update_menu_items(user_data);
469 }
470
471 static void
431 on_backend_restart_required(PuiBackend *backend, gpointer user_data) 472 on_backend_restart_required(PuiBackend *backend, gpointer user_data)
432 { 473 {
433 PuiApplication *self = user_data; 474 PuiApplication *self = user_data;
434 475
435 restart = TRUE; 476 restart = TRUE;
528 */ 569 */
529 g_settings_bind(self->settings, "update-command", self, 570 g_settings_bind(self->settings, "update-command", self,
530 "update-command", G_SETTINGS_BIND_GET); 571 "update-command", G_SETTINGS_BIND_GET);
531 g_settings_bind(self->settings, "always-active", self, 572 g_settings_bind(self->settings, "always-active", self,
532 "always-active", G_SETTINGS_BIND_GET); 573 "always-active", G_SETTINGS_BIND_GET);
574
575 /* watch hide-menu-items setting in order to update the menu */
576 g_signal_connect(self->settings, "changed::hide-menu-items",
577 G_CALLBACK(on_hide_menu_items_changed), self);
533 578
534 /* ensure the ui reflects the current state */ 579 /* ensure the ui reflects the current state */
535 update_ui(self); 580 update_ui(self);
536 581
537 /* keep GApplication running */ 582 /* keep GApplication running */