comparison pui-application.c @ 2:7172a0db97af

Use GtkBuilder for all widgets
author Guido Berhoerster <guido+pui@berhoerster.name>
date Wed, 13 Jun 2018 20:06:00 +0200
parents 2f04ec9e0506
children 2fa34d6272c6
comparison
equal deleted inserted replaced
1:2f04ec9e0506 2:7172a0db97af
109 static void 109 static void
110 pui_application_show_about_dialog(GSimpleAction *simple, GVariant *parameter, 110 pui_application_show_about_dialog(GSimpleAction *simple, GVariant *parameter,
111 gpointer user_data) 111 gpointer user_data)
112 { 112 {
113 PuiApplication *self = user_data; 113 PuiApplication *self = user_data;
114 const gchar *translators; 114 GtkBuilder *builder;
115 115
116 if (self->about_dialog == NULL) { 116 if (self->about_dialog == NULL) {
117 translators = _("Translators"); 117 /* get dialog from builder */
118 if (strcmp(translators, "Translators") == 0) { 118 builder = gtk_builder_new_from_resource("/org"
119 translators = NULL; 119 "/guido-berhoerster/code/package-update-indicator"
120 } 120 "/pui-about-dialog.ui");
121 121
122 self->about_dialog = gtk_about_dialog_new(); 122 self->about_dialog = GTK_WIDGET(gtk_builder_get_object(builder,
123 g_object_set(G_OBJECT(self->about_dialog), 123 "about-dialog"));
124 "authors", (gchar *[]){ "Guido Berhoerster", NULL }, 124
125 "comments", _("Notify about available software updates"), 125 g_object_unref(builder);
126 "copyright", "Copyright \xc2\xa9 2018 Guido Berhoerster",
127 "license-type", GTK_LICENSE_MIT_X11,
128 "logo-icon-name", "system-software-update",
129 "translator-credits", translators,
130 "version", VERSION,
131 "website", "https://code.guido-berhoerster.org/projects/"
132 "package-update-indicator/",
133 "wrap-license", TRUE,
134 NULL);
135 } 126 }
136 127
137 gtk_dialog_run(GTK_DIALOG(self->about_dialog)); 128 gtk_dialog_run(GTK_DIALOG(self->about_dialog));
138 gtk_widget_hide(self->about_dialog); 129 gtk_widget_hide(self->about_dialog);
139 } 130 }
403 static void 394 static void
404 pui_application_startup(GApplication *application) 395 pui_application_startup(GApplication *application)
405 { 396 {
406 PuiApplication *self = PUI_APPLICATION(application); 397 PuiApplication *self = PUI_APPLICATION(application);
407 gsize i; 398 gsize i;
399 GtkBuilder *builder;
408 GtkWidget *menu; 400 GtkWidget *menu;
409 GtkWidget *menu_item;
410 401
411 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application); 402 G_APPLICATION_CLASS(pui_application_parent_class)->startup(application);
412 403
413 /* create actions */ 404 /* create actions */
414 g_action_map_add_action_entries(G_ACTION_MAP(self), 405 g_action_map_add_action_entries(G_ACTION_MAP(self),
431 /* create indicator */ 422 /* create indicator */
432 self->indicator = app_indicator_new(APPLICATION_ID, 423 self->indicator = app_indicator_new(APPLICATION_ID,
433 "system-software-update", 424 "system-software-update",
434 APP_INDICATOR_CATEGORY_APPLICATION_STATUS); 425 APP_INDICATOR_CATEGORY_APPLICATION_STATUS);
435 426
436 /* build menu */ 427 /* get menu from builder and add it to the indicator */
437 menu = gtk_menu_new(); 428 builder = gtk_builder_new_from_resource("/org/guido-berhoerster/code/"
438 gtk_widget_insert_action_group(GTK_WIDGET(menu), "app", 429 "package-update-indicator/pui-menu.ui");
439 G_ACTION_GROUP(self)); 430 menu = GTK_WIDGET(gtk_builder_get_object(builder, "menu"));
440 431 gtk_widget_insert_action_group(menu, "app", G_ACTION_GROUP(self));
441 menu_item = gtk_menu_item_new_with_label(_("Install "
442 "Updates\342\200\246"));
443 gtk_actionable_set_action_name(GTK_ACTIONABLE(menu_item),
444 "app.install-updates");
445 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
446
447 menu_item = gtk_menu_item_new_with_label(_("About\342\200\246"));
448 gtk_actionable_set_action_name(GTK_ACTIONABLE(menu_item),
449 "app.about");
450 gtk_menu_shell_append(GTK_MENU_SHELL(menu), menu_item);
451
452 gtk_widget_show_all(menu); 432 gtk_widget_show_all(menu);
453 app_indicator_set_menu(self->indicator, GTK_MENU(menu)); 433 app_indicator_set_menu(self->indicator, GTK_MENU(menu));
454 434
455 update_ui(self); 435 update_ui(self);
456 436
457 /* keep GApplication running */ 437 /* keep GApplication running */
458 g_application_hold(application); 438 g_application_hold(application);
439
440 g_object_unref(builder);
459 } 441 }
460 442
461 static void 443 static void
462 pui_application_shutdown(GApplication *application) 444 pui_application_shutdown(GApplication *application)
463 { 445 {