Use GtkBuilder for toolbar.

This commit is contained in:
Arnaud Bonatti 2014-11-05 05:03:46 +01:00 committed by Thomas Debesse
parent cc7a65f743
commit f1bdb23575
5 changed files with 234 additions and 68 deletions

View File

@ -104,6 +104,7 @@ struct filter filters[FILTERS_TOTAL] = {
FILTER_NOT_CHANGED,
&sfilter_pix,
&sfilter_cfg_pix,
"sfilter.xpm",
},
{
N_("Player"),
@ -118,6 +119,7 @@ struct filter filters[FILTERS_TOTAL] = {
FILTER_NOT_CHANGED,
&pfilter_pix,
&pfilter_cfg_pix,
"pfilter.xpm",
},
{
"not visible",
@ -132,6 +134,7 @@ struct filter filters[FILTERS_TOTAL] = {
FILTER_NOT_CHANGED,
NULL,
NULL,
"not visible",
}
};

View File

@ -82,6 +82,7 @@ struct filter {
struct pixmap* pix;
struct pixmap* cfg_pix;
char *icon_name;
};
extern struct filter filters[];

View File

@ -2,3 +2,15 @@ EXTRA_DIST=$(wildcard *.xpm) $(flag_DATA)
flagdir = $(pkgdatadir)/default/flags
flag_DATA = lan.png
xpmdir = $(pkgdatadir)/xpm
xpm_DATA = \
update.xpm \
refresh.xpm \
refrsel.xpm \
stop.xpm \
connect.xpm \
observe.xpm \
record.xpm \
sfilter.xpm \
pfilter.xpm

125
src/xqf.c
View File

@ -3398,45 +3398,12 @@ static GtkWidget *create_player_menu (GtkAccelGroup *accel_group) {
static void populate_main_toolbar (void) {
GtkWidget *pixmap;
GtkWidget *image;
char buf[128];
unsigned mask;
int i;
pixmap = gtk_pixmap_new (update_pix.pix, update_pix.mask);
gtk_widget_show (pixmap);
update_button = gtk_toolbar_append_item (GTK_TOOLBAR (main_toolbar),
_("Update"), _("Update from master"), NULL,
pixmap,
GTK_SIGNAL_FUNC (update_source_callback), NULL);
pixmap = gtk_pixmap_new (refresh_pix.pix, refresh_pix.mask);
gtk_widget_show (pixmap);
refresh_button = gtk_toolbar_append_item (GTK_TOOLBAR (main_toolbar),
_("Refresh"), _("Refresh current list"), NULL,
pixmap,
GTK_SIGNAL_FUNC (refresh_callback), NULL);
pixmap = gtk_pixmap_new (refrsel_pix.pix, refrsel_pix.mask);
gtk_widget_show (pixmap);
refrsel_button = gtk_toolbar_append_item (GTK_TOOLBAR (main_toolbar),
_("Ref.Sel."), _("Refresh selected servers"), NULL,
pixmap,
GTK_SIGNAL_FUNC (refresh_selected_callback), NULL);
pixmap = gtk_pixmap_new (stop_pix.pix, stop_pix.mask);
gtk_widget_show (pixmap);
stop_button = gtk_toolbar_append_item (GTK_TOOLBAR (main_toolbar),
_("Stop"), _("Stop"), NULL,
pixmap,
GTK_SIGNAL_FUNC (stop_callback), NULL);
gtk_toolbar_append_space (GTK_TOOLBAR (main_toolbar));
/* for reference, old code style:
pixmap = gtk_pixmap_new (connect_pix.pix, connect_pix.mask);
gtk_widget_show (pixmap);
@ -3444,26 +3411,48 @@ static void populate_main_toolbar (void) {
_("Connect"), _("Connect"), NULL,
pixmap,
GTK_SIGNAL_FUNC (launch_callback), (gpointer) LAUNCH_NORMAL);
*/
update_button = GTK_WIDGET (gtk_builder_get_object (builder, "update-button"));
refresh_button = GTK_WIDGET (gtk_builder_get_object (builder, "refresh-button"));
refrsel_button = GTK_WIDGET (gtk_builder_get_object (builder, "refrsel-button"));
stop_button = GTK_WIDGET (gtk_builder_get_object (builder, "stop-button"));
connect_button = GTK_WIDGET (gtk_builder_get_object (builder, "connect-button"));
g_signal_connect (G_OBJECT (update_button), "clicked", G_CALLBACK (update_source_callback), NULL);
g_signal_connect (G_OBJECT (refresh_button), "clicked", G_CALLBACK (refresh_callback), NULL);
g_signal_connect (G_OBJECT (refrsel_button), "clicked", G_CALLBACK (refresh_selected_callback), NULL);
g_signal_connect (G_OBJECT (stop_button), "clicked", G_CALLBACK (stop_callback), NULL);
g_signal_connect (G_OBJECT (connect_button), "clicked", G_CALLBACK (launch_callback), (gpointer) LAUNCH_NORMAL); // TODO test... ^^'
gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (builder, "update-image")),
g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", "update.xpm", NULL));
gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (builder, "refresh-image")),
g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", "refresh.xpm", NULL));
gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (builder, "refrsel-image")),
g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", "refrsel.xpm", NULL));
gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (builder, "stop-image")),
g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", "stop.xpm", NULL));
gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (builder, "connect-image")),
g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", "connect.xpm", NULL));
#if 0
pixmap = gtk_pixmap_new (observe_pix.pix, observe_pix.mask);
gtk_widget_show (pixmap);
/* not tested at all */
observe_button = GTK_WIDGET (gtk_builder_get_object (builder, "observe-button"));
record_button = GTK_WIDGET (gtk_builder_get_object (builder, "record-button"));
observe_button = gtk_toolbar_append_item (GTK_TOOLBAR (main_toolbar),
_("Observe"), _("Observe"), NULL,
pixmap,
GTK_SIGNAL_FUNC (launch_callback), (gpointer) LAUNCH_SPECTATE);
g_signal_connect (G_OBJECT (observe_button), "clicked", G_CALLBACK (launch_callback), (gpointer) LAUNCH_SPECTATE);
g_signal_connect (G_OBJECT (record_button), "clicked", G_CALLBACK (launch_callback), (gpointer) LAUNCH_RECORD);
pixmap = gtk_pixmap_new (record_pix.pix, record_pix.mask);
gtk_widget_show (pixmap);
gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (builder, "observe-image")),
g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", "observe.xpm", NULL));
gtk_image_set_from_file (GTK_IMAGE (gtk_builder_get_object (builder, "record-image")),
g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", "record.xpm", NULL));
record_button = gtk_toolbar_append_item (GTK_TOOLBAR (main_toolbar),
_("Record"), _("Record Demo"), NULL,
pixmap,
GTK_SIGNAL_FUNC (launch_callback), (gpointer) LAUNCH_RECORD);
gtk_widget_show (observe_button);
gtk_widget_show (record_button);
#endif
gtk_toolbar_append_space (GTK_TOOLBAR (main_toolbar));
/*
* Filter buttons
*/
@ -3473,20 +3462,32 @@ static void populate_main_toolbar (void) {
filter_buttons[i] = NULL;
continue;
}
// Translators: e.g. Server Filter
g_snprintf (buf, 128, _("%s Filter Enable / Disable"), _(filters[i].name));
pixmap = gtk_pixmap_new (filters[i].pix->pix, filters[i].pix->mask);
/* pixmap = gtk_pixmap_new (filters[i].pix->pix, filters[i].pix->mask);
gtk_widget_show (pixmap);
filter_buttons[i] = gtk_toolbar_append_element (
GTK_TOOLBAR (main_toolbar),
filter_buttons[i] = gtk_toolbar_append_element (GTK_TOOLBAR (main_toolbar),
GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
_(filters[i].short_name), buf, NULL,
pixmap,
GTK_SIGNAL_FUNC (filter_toggle_callback), GINT_TO_POINTER (mask));
*/
filter_buttons[i] = GTK_WIDGET (gtk_toggle_tool_button_new ());
g_signal_connect (G_OBJECT (filter_buttons[i]), "toggled", G_CALLBACK (filter_toggle_callback), GINT_TO_POINTER (mask));
gtk_tool_button_set_label (GTK_TOOL_BUTTON (filter_buttons[i]), _(filters[i].short_name));
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (filter_buttons[i]), ((cur_filter & mask) != 0)? TRUE : FALSE);
// Translators: e.g. Server Filter
g_snprintf (buf, 128, _("%s Filter Enable / Disable"), _(filters[i].name));
gtk_widget_set_tooltip_text (GTK_WIDGET (filter_buttons[i]), buf);
image = gtk_image_new_from_file (g_build_filename (xqf_PACKAGE_DATA_DIR, "xpm", filters[i].icon_name, NULL));
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (filter_buttons[i]), image);
gtk_widget_show (image);
gtk_widget_show (filter_buttons[i]);
gtk_toolbar_insert (GTK_TOOLBAR (main_toolbar), GTK_TOOL_ITEM (filter_buttons[i]), -1);
gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (filter_buttons[i]), ((cur_filter & mask) != 0)? TRUE : FALSE);
}
#if 0
@ -3659,7 +3660,7 @@ static void create_main_window (void) {
GError *error = NULL;
builder = gtk_builder_new ();
gtk_builder_add_from_file (builder, g_strconcat (xqf_PACKAGE_DATA_DIR, "/ui", "/xqf.ui", NULL), &error);
gtk_builder_add_from_file (builder, g_build_filename (xqf_PACKAGE_DATA_DIR, "ui", "xqf.ui", NULL), &error);
if (G_UNLIKELY (error != NULL)) {
fprintf (stderr, "Could not load UI: %s\n", error->message);
g_clear_error (&error);
@ -3684,7 +3685,7 @@ static void populate_main_window (void) {
GtkWidget *main_vbox;
GtkWidget *hbox;
GtkWidget *menu_bar;
GtkWidget *handlebox;
// GtkWidget *handlebox;
GtkWidget *scrollwin;
GtkWidget *entry;
GtkWidget *button;
@ -3793,9 +3794,9 @@ static void populate_main_window (void) {
gtk_box_pack_start (GTK_BOX (main_vbox), GTK_WIDGET (selection_manager), FALSE, FALSE, 0);
gtk_widget_realize (GTK_WIDGET (selection_manager));
handlebox = gtk_handle_box_new ();
/* handlebox = gtk_handle_box_new ();
gtk_box_pack_start (GTK_BOX (main_vbox), handlebox, FALSE, FALSE, 0);
*/
menu_bar = create_menubar (menubar_menu_items, accel_group);
// add server filters to menu
@ -3805,14 +3806,16 @@ static void populate_main_window (void) {
gtk_signal_connect_object (GTK_OBJECT (file_quit_menu_item), "activate", GTK_SIGNAL_FUNC (gtk_widget_destroy), GTK_OBJECT (main_window));
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (view_hostnames_menu_item), show_hostnames);
gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM (view_defport_menu_item), show_default_port);
gtk_box_pack_start (GTK_BOX (main_vbox), menu_bar, FALSE, FALSE, 0);
gtk_widget_show (menu_bar);
/*
gtk_container_add (GTK_CONTAINER (handlebox), menu_bar);
gtk_widget_show (menu_bar);
gtk_widget_show (handlebox);
*/
main_toolbar = GTK_WIDGET (gtk_builder_get_object (builder, "main-toolbar"));
populate_main_toolbar ();
@ -4223,7 +4226,7 @@ int main (int argc, char *argv[]) {
add_pixmap_path_for_theme ("default");
add_pixmap_directory (xqf_PACKAGE_DATA_DIR);
qstat_configfile = g_strconcat (xqf_PACKAGE_DATA_DIR, "/qstat.cfg", NULL);
qstat_configfile = g_build_filename (xqf_PACKAGE_DATA_DIR, "qstat.cfg", NULL);
dns_gtk_init ();

View File

@ -1,6 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- <requires lib="gtk+" version="X.XX"/> -->
<!-- <object class="GtkTreeModel" id="treemodel-sources">
</object> -->
<object class="GtkWindow" id="main-window">
<property name="type">toplevel</property>
<child>
@ -9,18 +11,153 @@
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<placeholder/>
<!-- <child>
<object class="GtkMenuBar" id="main-menubar">
<property name="visible">True</property>
--><!-- <child>
<object class="GtkMenuItem" id="first-menuitem">
<property name="visible">True</property>
<property name="label">test1</property>
<child type="submenu">
<object class="GtkMenu" id="first-menu">
<property name="visible">True</property>
<child>
<object class="GtkMenuItem" id="second-menuitem">
<property name="visible">True</property>
<property name="label">test2</property>
</object>
</child>
</object>
</child>
</object>
</child> -->
<!-- </object>
<packing>
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">0</property>
</packing>
</child>
<child>
--> <child>
<object class="GtkToolbar" id="main-toolbar">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<property name="toolbar-style">both</property>
<child>
<object class="GtkToolButton" id="update-button">
<property name="visible">True</property>
<property name="label" translatable="yes">Update</property>
<property name="tooltip-text" translatable="yes">Update from master</property>
<property name="icon-widget">update-image</property>
<child>
<object class="GtkImage" id="update-image">
<property name="visible">True</property>
<property name="icon-size">1</property>
<!-- <property name="file">/path/to/jhbuild/slash/share/xqf/xpm/xxxx.xpm</property> works -->
</object>
</child>
</object>
</child>
<child>
<object class="GtkToolButton" id="refresh-button">
<property name="visible">True</property>
<property name="label" translatable="yes">Refresh</property>
<property name="tooltip-text" translatable="yes">Refresh current list</property>
<property name="icon-widget">refresh-image</property>
<child>
<object class="GtkImage" id="refresh-image">
<property name="visible">True</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkToolButton" id="refrsel-button">
<property name="visible">True</property>
<property name="label" translatable="yes">Ref.Sel.</property>
<property name="tooltip-text" translatable="yes">Refresh selected servers</property>
<property name="icon-widget">refrsel-image</property>
<child>
<object class="GtkImage" id="refrsel-image">
<property name="visible">True</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkToolButton" id="stop-button">
<property name="visible">True</property>
<property name="label" translatable="yes">Stop</property>
<property name="tooltip-text" translatable="yes">Stop</property><!-- TODO better tooltip -->
<property name="icon-widget">stop-image</property>
<child>
<object class="GtkImage" id="stop-image">
<property name="visible">True</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparatorToolItem" id="first-separator">
<property name="visible">True</property>
<property name="draw">True</property>
</object>
</child>
<child>
<object class="GtkToolButton" id="connect-button">
<property name="visible">True</property>
<property name="label" translatable="yes">Connect</property>
<property name="tooltip-text" translatable="yes">Connect</property><!-- TODO better tooltip -->
<property name="icon-widget">connect-image</property>
<child>
<object class="GtkImage" id="connect-image">
<property name="visible">True</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkToolButton" id="observe-button">
<property name="visible">False</property>
<property name="label" translatable="yes">Observe</property>
<property name="tooltip-text" translatable="yes">Observe</property><!-- TODO better tooltip -->
<property name="icon-widget">observe-image</property>
<child>
<object class="GtkImage" id="observe-image">
<property name="visible">True</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkToolButton" id="record-button">
<property name="visible">False</property>
<property name="label" translatable="yes">Record</property>
<property name="tooltip-text" translatable="yes">Record Demo</property>
<property name="icon-widget">record-image</property>
<child>
<object class="GtkImage" id="record-image">
<property name="visible">True</property>
<property name="icon-size">1</property>
</object>
</child>
</object>
</child>
<child>
<object class="GtkSeparatorToolItem" id="second-separator">
<property name="visible">True</property>
<property name="draw">True</property>
</object>
</child>
</object>
<packing>
<property name="pack-type">end</property>
<property name="position">1</property>
<property name="pack-type">end</property> <!-- remove when menubar is here -->
<property name="position">1</property> <!-- remove when menubar is here -->
<property name="expand">False</property>
<property name="fill">False</property>
<property name="padding">0</property>
@ -40,6 +177,16 @@
<property name="visible">True</property>
<!-- <property name="hadjustment">null</property>
<property name="vadjustment">null</property> -->
<property name="hscrollbar-policy">automatic</property>
<property name="vscrollbar-policy">automatic</property>
<!-- <child>
<object class="GtkTreeView" id="treeview-sources">
<property name="visible">True</property>
<property name="activate-on-single-click">True</property> <!- TODO test -->
<!-- <property name="headers-visible">False</property> <!- there is only one column, called initially "Sources" -->
<!-- <property name="model">treemodel-sources</property>
</object>
</child> -->
</object>
</child>
<child>
@ -168,8 +315,8 @@
</child>
</object>
<packing>
<property name="pack-type">end</property>
<property name="position">0</property>
<property name="pack-type">end</property> <!-- remove when menubar is here -->
<property name="position">0</property> <!-- remove when menubar is here -->
<property name="expand">True</property>
<property name="fill">True</property>
<property name="padding">0</property>