Commit 233111b2 authored by Robert Ancell's avatar Robert Ancell Committed by Georges Basile Stavracas Neto

search: Use GtkTemplate

parent 6b2ed3a4
Pipeline #13729 passed with stages
in 10 minutes and 27 seconds
......@@ -26,16 +26,16 @@
#include <gio/gdesktopappinfo.h>
#include <glib/gi18n.h>
#define WID(s) GTK_WIDGET (gtk_builder_get_object (self->builder, s))
struct _CcSearchPanel
{
CcPanel parent_instance;
GtkBuilder *builder;
GtkWidget *list_box;
GtkWidget *up_button;
GtkWidget *down_button;
GtkWidget *search_vbox;
GtkWidget *search_frame;
GtkWidget *settings_button;
GCancellable *load_cancellable;
GSettings *search_settings;
......@@ -675,7 +675,6 @@ cc_search_panel_finalize (GObject *object)
{
CcSearchPanel *self = CC_SEARCH_PANEL (object);
g_clear_object (&self->builder);
g_clear_object (&self->search_settings);
g_hash_table_destroy (self->sort_order);
......@@ -689,12 +688,11 @@ static void
cc_search_panel_constructed (GObject *object)
{
CcSearchPanel *self = CC_SEARCH_PANEL (object);
GtkWidget *box, *widget, *search_box;
GtkWidget *box, *widget;
G_OBJECT_CLASS (cc_search_panel_parent_class)->constructed (object);
/* add the disable all switch */
search_box = WID ("search_vbox");
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
widget = gtk_switch_new ();
......@@ -707,7 +705,7 @@ cc_search_panel_constructed (GObject *object)
G_SETTINGS_BIND_INVERT_BOOLEAN);
g_object_bind_property (widget, "active",
search_box, "sensitive",
self->search_vbox, "sensitive",
G_BINDING_DEFAULT |
G_BINDING_SYNC_CREATE);
......@@ -718,54 +716,31 @@ cc_search_panel_constructed (GObject *object)
static void
cc_search_panel_init (CcSearchPanel *self)
{
GError *error;
GtkWidget *widget;
GtkWidget *frame;
guint res;
g_resources_register (cc_search_get_resource ());
self->builder = gtk_builder_new ();
error = NULL;
res = gtk_builder_add_from_resource (self->builder,
"/org/gnome/control-center/search/search.ui",
&error);
if (res == 0)
{
g_warning ("Could not load interface file: %s",
(error != NULL) ? error->message : "unknown error");
g_clear_error (&error);
return;
}
gtk_widget_init_template (GTK_WIDGET (self));
frame = WID ("search_frame");
widget = GTK_WIDGET (gtk_list_box_new ());
gtk_list_box_set_sort_func (GTK_LIST_BOX (widget),
self->list_box = GTK_WIDGET (gtk_list_box_new ());
gtk_list_box_set_sort_func (GTK_LIST_BOX (self->list_box),
(GtkListBoxSortFunc)list_sort_func, self, NULL);
gtk_list_box_set_header_func (GTK_LIST_BOX (widget), cc_list_box_update_header_func, NULL, NULL);
gtk_container_add (GTK_CONTAINER (frame), widget);
self->list_box = widget;
gtk_widget_show (widget);
gtk_list_box_set_header_func (GTK_LIST_BOX (self->list_box), cc_list_box_update_header_func, NULL, NULL);
gtk_container_add (GTK_CONTAINER (self->search_frame), self->list_box);
gtk_widget_show (self->list_box);
g_signal_connect_swapped (widget, "row-selected",
g_signal_connect_swapped (self->list_box, "row-selected",
G_CALLBACK (search_panel_invalidate_button_state), self);
self->up_button = WID ("up_button");
g_signal_connect (self->up_button, "clicked",
G_CALLBACK (up_button_clicked), self);
gtk_widget_set_sensitive (self->up_button, FALSE);
self->down_button = WID ("down_button");
g_signal_connect (self->down_button, "clicked",
G_CALLBACK (down_button_clicked), self);
gtk_widget_set_sensitive (self->down_button, FALSE);
widget = WID ("settings_button");
g_signal_connect (widget, "clicked",
g_signal_connect (self->settings_button, "clicked",
G_CALLBACK (settings_button_clicked), self);
gtk_widget_set_sensitive (widget, cc_search_locations_dialog_is_available ());
gtk_widget_set_sensitive (self->settings_button, cc_search_locations_dialog_is_available ());
self->search_settings = g_settings_new ("org.gnome.desktop.search-providers");
self->sort_order = g_hash_table_new_full (g_str_hash, g_str_equal,
......@@ -775,17 +750,24 @@ cc_search_panel_init (CcSearchPanel *self)
search_panel_invalidate_sort_order (self);
populate_search_providers (self);
widget = WID ("search_vbox");
gtk_container_add (GTK_CONTAINER (self), widget);
}
static void
cc_search_panel_class_init (CcSearchPanelClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GObjectClass *oclass = G_OBJECT_CLASS (klass);
oclass->constructed = cc_search_panel_constructed;
oclass->dispose = cc_search_panel_dispose;
oclass->finalize = cc_search_panel_finalize;
gtk_widget_class_set_template_from_resource (widget_class,
"/org/gnome/control-center/search/search.ui");
gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, up_button);
gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, down_button);
gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, search_vbox);
gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, search_frame);
gtk_widget_class_bind_template_child (widget_class, CcSearchPanel, settings_button);
}
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkScrolledWindow" id="search_vbox">
<template class="CcSearchPanel" parent="CcPanel">
<property name="visible">True</property>
<property name="hscrollbar_policy">never</property>
<property name="min_content_height">450</property>
<property name="can_focus">True</property>
<child>
<object class="GtkBox">
<object class="GtkScrolledWindow" id="search_vbox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<!-- Stub boxes to make the content cover 1/3 of the screen -->
<property name="hscrollbar_policy">never</property>
<property name="min_content_height">450</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
</object>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
<!-- Content -->
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="margin">32</property>
<property name="hexpand">True</property>
<!-- Stub boxes to make the content cover 1/3 of the screen -->
<child>
<object class="GtkFrame" id="search_frame">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="hexpand">True</property>
</object>
</child>
<child>
<object class="GtkToolbar" id="search_toolbar">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">icons</property>
<property name="show_arrow">False</property>
<property name="icon_size">1</property>
<style>
<class name="inline-toolbar"/>
</style>
<property name="hexpand">True</property>
</object>
<packing>
<property name="pack_type">end</property>
</packing>
</child>
<!-- Content -->
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="margin">32</property>
<property name="hexpand">True</property>
<child>
<object class="GtkToolItem" id="up_down_item">
<object class="GtkFrame" id="search_frame">
<property name="visible">True</property>
</object>
</child>
<child>
<object class="GtkToolbar" id="search_toolbar">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="toolbar_style">icons</property>
<property name="show_arrow">False</property>
<property name="icon_size">1</property>
<style>
<class name="inline-toolbar"/>
</style>
<child>
<object class="GtkBox" id="up_down_box">
<object class="GtkToolItem" id="up_down_item">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="up_button">
<property name="visible">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="up_button_a11y">
<property name="accessible-name" translatable="yes">Move Up</property>
<object class="GtkBox" id="up_down_box">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="up_button">
<property name="visible">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="up_button_a11y">
<property name="accessible-name" translatable="yes">Move Up</property>
</object>
</child>
<child>
<object class="GtkImage" id="up_image">
<property name="visible">True</property>
<property name="icon-name">go-up-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkImage" id="up_image">
<property name="visible">True</property>
<property name="icon-name">go-up-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkButton" id="down_button">
<property name="visible">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="down_button_a11y">
<property name="accessible-name" translatable="yes">Move Down</property>
</child>
<child>
<object class="GtkButton" id="down_button">
<property name="visible">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="down_button_a11y">
<property name="accessible-name" translatable="yes">Move Down</property>
</object>
</child>
<child>
<object class="GtkImage" id="down_image">
<property name="visible">True</property>
<property name="icon-name">go-down-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkImage" id="down_image">
<property name="visible">True</property>
<property name="icon-name">go-down-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparatorToolItem" id="sep1">
<property name="visible">True</property>
<property name="draw">False</property>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
<child>
<object class="GtkToolItem" id="settings_item">
<property name="visible">True</property>
<child>
<object class="GtkBox" id="i_s_ud_box">
<object class="GtkSeparatorToolItem" id="sep1">
<property name="visible">True</property>
<property name="draw">False</property>
</object>
<packing>
<property name="expand">True</property>
</packing>
</child>
<child>
<object class="GtkToolItem" id="settings_item">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="settings_button">
<property name="visible">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="settings_button_a11y">
<property name="accessible-name" translatable="yes">Preferences</property>
<object class="GtkBox" id="i_s_ud_box">
<property name="visible">True</property>
<child>
<object class="GtkButton" id="settings_button">
<property name="visible">True</property>
<child internal-child="accessible">
<object class="AtkObject" id="settings_button_a11y">
<property name="accessible-name" translatable="yes">Preferences</property>
</object>
</child>
<child>
<object class="GtkImage" id="settings_image">
<property name="visible">True</property>
<property name="icon-name">emblem-system-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkImage" id="settings_image">
<property name="visible">True</property>
<property name="icon-name">emblem-system-symbolic</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
</child>
</object>
</child>
</child>
</object>
</child>
</object>
</template>
</interface>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment