From a7f32df98d0fb863b43c04e8664d709f701f2001 Mon Sep 17 00:00:00 2001 From: Thomas Hindoe Paaboel Andersen Date: Sat, 17 Nov 2012 00:34:37 +0100 Subject: [PATCH] Port to Gtk3 Based on basic patch by Marc-Antoine Perennou in bug #41814 * Replaces the gtk2-specific WrapLabel with normal Label. Wrap+resize works reasonably well in gtk3. * Simplifies layout by using Grid instead of Table * Replaces use of various deprecated objects --- Makefile.am | 7 +-- configure.ac | 2 +- src/gnome-ask-password-agent.vala | 5 +- src/systemadm.vala | 117 ++++++++++++++++++++------------------ src/wraplabel.vala | 73 ------------------------ 5 files changed, 67 insertions(+), 137 deletions(-) delete mode 100644 src/wraplabel.vala diff --git a/Makefile.am b/Makefile.am index 211f496..be93f08 100644 --- a/Makefile.am +++ b/Makefile.am @@ -35,8 +35,7 @@ bin_PROGRAMS = \ systemadm_SOURCES = \ src/systemadm.vala \ - src/systemd-interfaces.vala \ - src/wraplabel.vala + src/systemd-interfaces.vala systemadm_CFLAGS = \ $(AM_CFLAGS) \ @@ -49,7 +48,7 @@ systemadm_CFLAGS = \ systemadm_VALAFLAGS = \ --pkg=posix \ - --pkg=gtk+-2.0 \ + --pkg=gtk+-3.0 \ --pkg=$(GEE_PACKAGE) \ -g @@ -84,7 +83,7 @@ systemd_gnome_ask_password_agent_CFLAGS = \ systemd_gnome_ask_password_agent_VALAFLAGS = \ --pkg=posix \ - --pkg=gtk+-2.0 \ + --pkg=gtk+-3.0 \ --pkg=linux \ --pkg=gio-unix-2.0 \ --pkg=libnotify \ diff --git a/configure.ac b/configure.ac index 40e6573..45f7051 100644 --- a/configure.ac +++ b/configure.ac @@ -95,7 +95,7 @@ PKG_CHECK_MODULES(DBUS, [ dbus-1 >= 1.3.2 ]) AC_SUBST(DBUS_CFLAGS) AC_SUBST(DBUS_LIBS) -PKG_CHECK_MODULES(GTK, [ gtk+-2.0 glib-2.0 > 2.26 gio-unix-2.0 ]) +PKG_CHECK_MODULES(GTK, [ gtk+-3.0 glib-2.0 > 2.26 gio-unix-2.0 ]) AC_SUBST(GTK_CFLAGS) AC_SUBST(GTK_LIBS) diff --git a/src/gnome-ask-password-agent.vala b/src/gnome-ask-password-agent.vala index e23aedb..5df27ee 100644 --- a/src/gnome-ask-password-agent.vala +++ b/src/gnome-ask-password-agent.vala @@ -32,7 +32,6 @@ public class PasswordDialog : Dialog { public PasswordDialog(string message, string icon) { set_title("System Password"); - set_has_separator(false); set_border_width(8); set_default_response(ResponseType.OK); set_icon_name(icon); @@ -42,14 +41,14 @@ public class PasswordDialog : Dialog { Container content = (Container) get_content_area(); - Box hbox = new HBox(false, 16); + Box hbox = new Box(Orientation.HORIZONTAL, 16); hbox.set_border_width(8); content.add(hbox); Image image = new Image.from_icon_name(icon, IconSize.DIALOG); hbox.pack_start(image, false, false); - Box vbox = new VBox(false, 8); + Box vbox = new Box(Orientation.VERTICAL, 8); hbox.pack_start(vbox, true, true); Label label = new Label(message); diff --git a/src/systemadm.vala b/src/systemadm.vala index 5971ac0..553633b 100644 --- a/src/systemadm.vala +++ b/src/systemadm.vala @@ -41,16 +41,21 @@ public class LeftLabel : Label { public LeftLabel(string? text = null) { if (text != null) set_markup("%s".printf(text)); - set_alignment(0, 0); - set_padding(6, 0); + halign = Align.START; + valign = Align.START; } } -public class RightLabel : WrapLabel { +public class RightLabel : Label { public RightLabel(string? text = null) { set_selectable(true); set_text_or_na(text); + wrap = true; + wrap_mode = Pango.WrapMode.WORD_CHAR; + halign = Align.START; + valign = Align.START; + hexpand = true; } public void set_text_or_na(string? text = null) { @@ -112,7 +117,7 @@ public class MainWindow : Window { private RightLabel job_state_label; private RightLabel job_type_label; - private ComboBox unit_type_combo_box; + private ComboBoxText unit_type_combo_box; private CheckButton inactive_checkbox; public MainWindow() throws IOError { @@ -125,16 +130,16 @@ public class MainWindow : Window { Notebook notebook = new Notebook(); add(notebook); - Box unit_vbox = new VBox(false, 12); + Box unit_vbox = new Box(Orientation.VERTICAL, 12); notebook.append_page(unit_vbox, new Label("Units")); unit_vbox.set_border_width(12); - Box job_vbox = new VBox(false, 12); + Box job_vbox = new Box(Orientation.VERTICAL, 12); notebook.append_page(job_vbox, new Label("Jobs")); job_vbox.set_border_width(12); - unit_type_combo_box = new ComboBox.text(); - Box type_hbox = new HBox(false, 6); + unit_type_combo_box = new ComboBoxText(); + Box type_hbox = new Box(Orientation.HORIZONTAL, 6); type_hbox.pack_start(unit_type_combo_box, false, false, 0); unit_vbox.pack_start(type_hbox, false, false, 0); @@ -164,7 +169,7 @@ public class MainWindow : Window { unit_load_entry.activate.connect(on_unit_load); unit_load_button.clicked.connect(on_unit_load); - Box unit_load_hbox = new HBox(false, 6); + Box unit_load_hbox = new Box(Orientation.HORIZONTAL, 6); unit_load_hbox.pack_start(unit_load_entry, false, true, 0); unit_load_hbox.pack_start(unit_load_button, false, true, 0); @@ -241,52 +246,52 @@ public class MainWindow : Window { unit_fragment_path_label.set_track_visited_links(false); - Table unit_table = new Table(8, 6, false); - unit_table.set_row_spacings(6); - unit_table.set_border_width(0); - unit_vbox.pack_start(unit_table, false, true, 0); - - Table job_table = new Table(2, 2, false); - job_table.set_row_spacings(6); - job_table.set_border_width(0); - job_vbox.pack_start(job_table, false, true, 0); - - unit_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_id_label, 1, 6, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Description:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_description_label, 1, 6, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Dependencies:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_dependency_label, 1, 6, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Fragment Path:"), 0, 1, 3, 4, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_fragment_path_label, 1, 6, 3, 4, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Control Group:"), 0, 1, 4, 5, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_cgroup_label, 1, 6, 4, 5, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - unit_table.attach(new LeftLabel("Load State:"), 0, 1, 5, 6, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_load_state_label, 1, 2, 5, 6, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Active State:"), 0, 1, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_active_state_label, 1, 2, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Unit State:"), 0, 1, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_sub_state_label, 1, 2, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - unit_table.attach(new LeftLabel("Activated:"), 2, 3, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_active_enter_timestamp_label, 3, 4, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Deactivated:"), 2, 3, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_active_exit_timestamp_label, 3, 4, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - unit_table.attach(new LeftLabel("Can Start/Stop:"), 4, 5, 6, 7, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_can_start_label, 5, 6, 6, 7, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(new LeftLabel("Can Reload:"), 4, 5, 7, 8, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - unit_table.attach(unit_can_reload_label, 5, 6, 7, 8, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - job_table.attach(new LeftLabel("Id:"), 0, 1, 0, 1, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - job_table.attach(job_id_label, 1, 2, 0, 1, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - job_table.attach(new LeftLabel("State:"), 0, 1, 1, 2, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - job_table.attach(job_state_label, 1, 2, 1, 2, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - job_table.attach(new LeftLabel("Type:"), 0, 1, 2, 3, AttachOptions.FILL, AttachOptions.FILL, 0, 0); - job_table.attach(job_type_label, 1, 2, 2, 3, AttachOptions.EXPAND|AttachOptions.FILL, AttachOptions.FILL, 0, 0); - - ButtonBox bbox = new HButtonBox(); + Grid unit_grid = new Grid(); + unit_grid.column_spacing = 6; + unit_grid.row_spacing = 6; + unit_vbox.pack_start(unit_grid, false, true, 0); + + Grid job_grid = new Grid(); + job_grid.column_spacing = 6; + job_grid.column_spacing = 6; + job_vbox.pack_start(job_grid, false, true, 0); + + unit_grid.attach(new LeftLabel("Id:"), 0, 0, 1, 1); + unit_grid.attach(unit_id_label, 1, 0, 5, 1); + unit_grid.attach(new LeftLabel("Description:"), 0, 1, 1, 1); + unit_grid.attach(unit_description_label, 1, 1, 5, 1); + unit_grid.attach(new LeftLabel("Dependencies:"), 0, 2, 1, 1); + unit_grid.attach(unit_dependency_label, 1, 2, 5, 1); + unit_grid.attach(new LeftLabel("Fragment Path:"), 0, 3, 1, 1); + unit_grid.attach(unit_fragment_path_label, 1, 3, 5, 1); + unit_grid.attach(new LeftLabel("Control Group:"), 0, 4, 1, 1); + unit_grid.attach(unit_cgroup_label, 1, 4, 5, 1); + unit_grid.attach(new LeftLabel("Load State:"), 0, 5, 1, 1); + unit_grid.attach(unit_load_state_label, 1, 5, 5, 1); + + unit_grid.attach(new LeftLabel("Active State:"), 0, 6, 1, 1); + unit_grid.attach(unit_active_state_label, 1, 6, 1, 1); + unit_grid.attach(new LeftLabel("Unit State:"), 0, 7, 1, 1); + unit_grid.attach(unit_sub_state_label, 1, 7, 1, 1); + + unit_grid.attach(new LeftLabel("Activated:"), 2, 6, 1, 1); + unit_grid.attach(unit_active_enter_timestamp_label, 3, 6, 1, 1); + unit_grid.attach(new LeftLabel("Deactivated:"), 2, 7, 1, 1); + unit_grid.attach(unit_active_exit_timestamp_label, 3, 7, 1, 1); + + unit_grid.attach(new LeftLabel("Can Start/Stop:"), 4, 6, 1, 1); + unit_grid.attach(unit_can_start_label, 5, 6, 1, 1); + unit_grid.attach(new LeftLabel("Can Reload:"), 4, 7, 1, 1); + unit_grid.attach(unit_can_reload_label, 5, 7, 1, 1); + + job_grid.attach(new LeftLabel("Id:"), 0, 1, 1, 1); + job_grid.attach(job_id_label, 1, 1, 1, 1); + job_grid.attach(new LeftLabel("State:"), 0, 2, 1, 1); + job_grid.attach(job_state_label, 1, 2, 1, 1); + job_grid.attach(new LeftLabel("Type:"), 0, 3, 1, 1); + job_grid.attach(job_type_label, 1, 3, 1, 1); + + ButtonBox bbox = new ButtonBox(Orientation.HORIZONTAL); bbox.set_layout(ButtonBoxStyle.START); bbox.set_spacing(6); unit_vbox.pack_start(bbox, false, true, 0); @@ -306,7 +311,7 @@ public class MainWindow : Window { bbox.pack_start(restart_button, false, true, 0); bbox.pack_start(reload_button, false, true, 0); - bbox = new HButtonBox(); + bbox = new ButtonBox(Orientation.HORIZONTAL); bbox.set_layout(ButtonBoxStyle.START); bbox.set_spacing(6); job_vbox.pack_start(bbox, false, true, 0); diff --git a/src/wraplabel.vala b/src/wraplabel.vala deleted file mode 100644 index 49858c3..0000000 --- a/src/wraplabel.vala +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) 2005 VMware, Inc. - -// This is a translation of http://git.gnome.org/browse/meld/tree/meld/ui/wraplabel.py, -// which in turn is a translation of WrapLabel from libview. - -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -// SOFTWARE. - -// Python translation from wrapLabel.{cc|h} by Gian Mario Tagliaretti -// Vala translation from wraplabel.py by Zbigniew Jędrzejewski-Szmek - -public class WrapLabel : Gtk.Label { - private int _wrap_width; - - public WrapLabel(string? text = null) { - this._wrap_width = 0; - var layout = get_layout(); - layout.set_wrap(Pango.WrapMode.WORD_CHAR); - if (text != null) - this.set_text(text); - this.set_alignment(0, 0); - } - - public override void size_request(out Gtk.Requisition requisition) { - int width, height; - var layout = get_layout(); - layout.get_pixel_size(out width, out height); - requisition.width = 0; - requisition.height = height; - } - - public override void size_allocate(Gdk.Rectangle allocation) { - base.size_allocate (allocation); - this._set_wrap_width(allocation.width); - } - - public new void set_text(string str) { - base.set_text(str); - this._set_wrap_width(this._wrap_width); - } - - public new void set_markup(string str) { - base.set_markup(str); - this._set_wrap_width(this._wrap_width); - } - - private void _set_wrap_width(int width) { - if (width == 0) - return; - - var layout = get_layout(); - layout.set_width(width * Pango.SCALE); - if (_wrap_width != width) { - this._wrap_width = width; - this.queue_resize(); - } - } -} -- 1.8.0