[baobab] Port to GtkListBox



commit 92cfd36a1f0bc8b9763781c88d46e4f83236aafc
Author: Stefano Facchini <stefano facchini gmail com>
Date:   Thu Jun 13 14:54:50 2013 +0200

    Port to GtkListBox
    
    Use a custom vapi for now (copied from GNOME Contacts)

 configure.ac                  |    2 +-
 src/baobab-location-list.vala |   18 ++--
 src/baobab-location-row.ui    |  169 +++++++++++++++++++++--------------------
 src/fixes.vapi                |   48 ++++++++++++
 4 files changed, 145 insertions(+), 92 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index f7e3d58..ec545b9 100644
--- a/configure.ac
+++ b/configure.ac
@@ -44,7 +44,7 @@ AC_PATH_PROG(GLIB_COMPILE_RESOURCES, glib-compile-resources)
 YELP_HELP_INIT
 
 PKG_CHECK_MODULES(BAOBAB, [
-    gtk+-3.0 >= 3.9.0
+    gtk+-3.0 >= 3.9.1
     gio-2.0 >= 2.30.0
 ])
 
diff --git a/src/baobab-location-list.vala b/src/baobab-location-list.vala
index 7aa9033..a069a34 100644
--- a/src/baobab-location-list.vala
+++ b/src/baobab-location-list.vala
@@ -21,7 +21,7 @@
 namespace Baobab {
 
     [GtkTemplate (ui = "/org/gnome/baobab/ui/baobab-location-row.ui")]
-    private class LocationRow : Gtk.Grid {
+    private class LocationRow : LocalGtk.ListBoxRow {
         private static Gtk.SizeGroup name_size_group = null;
         private static Gtk.SizeGroup usage_size_group = null;
 
@@ -77,7 +77,7 @@ namespace Baobab {
         }
     }
 
-    public class LocationList : Egg.ListBox {
+    public class LocationList : LocalGtk.ListBox {
         private const int MAX_RECENT_LOCATIONS = 5;
 
         private VolumeMonitor monitor;
@@ -97,22 +97,22 @@ namespace Baobab {
             monitor.volume_added.connect (volume_added);
 
             set_selection_mode (Gtk.SelectionMode.NONE);
-            set_separator_funcs (update_separator);
+            set_header_func (update_header);
 
             populate ();
         }
 
-        void update_separator (ref Gtk.Widget? separator, Gtk.Widget widget, Gtk.Widget? before_widget) {
-            if (before_widget != null && separator == null) {
-                separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
+        void update_header (LocalGtk.ListBoxRow row, LocalGtk.ListBoxRow? before_row) {
+            if (before_row != null && row.get_header () == null) {
+                row.set_header (new Gtk.Separator (Gtk.Orientation.HORIZONTAL));
             } else {
-                separator = null;
+                row.set_header (null);
             }
         }
 
-        public override void child_activated (Gtk.Widget? widget) {
+        public override void row_activated (LocalGtk.ListBoxRow row) {
             if (location_action != null) {
-                var location_widget = widget as LocationRow;
+                var location_widget = row as LocationRow;
                 location_action (location_widget.location);
             }
         }
diff --git a/src/baobab-location-row.ui b/src/baobab-location-row.ui
index 4f50e2a..3337bba 100644
--- a/src/baobab-location-row.ui
+++ b/src/baobab-location-row.ui
@@ -1,92 +1,97 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <interface>
   <!-- interface-requires gtk+ 3.0 -->
-  <template class="BaobabLocationRow" parent="Gtk.Grid">
+  <template class="BaobabLocationRow" parent="Gtk.ListBoxRow">
     <property name="visible">True</property>
-    <property name="orientation">horizontal</property>
-    <property name="column_spacing">12</property>
-    <property name="margin">6</property>
     <child>
-      <object class="GtkImage" id="image">
+      <object class="GtkGrid" id="grid">
         <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="pixel_size">64</property>
+        <property name="orientation">horizontal</property>
+        <property name="column_spacing">12</property>
+        <property name="margin">6</property>
+        <child>
+          <object class="GtkImage" id="image">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="pixel_size">64</property>
+          </object>
+          <packing>
+            <property name="left_attach">0</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">2</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="name_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="valign">end</property>
+            <property name="hexpand">True</property>
+            <property name="use_markup">True</property>
+            <property name="xalign">0</property>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="path_label">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="halign">start</property>
+            <property name="valign">start</property>
+            <property name="hexpand">True</property>
+            <property name="use_markup">True</property>
+            <property name="xalign">0</property>
+            <style>
+              <class name="dim-label"/>
+            </style>
+          </object>
+          <packing>
+            <property name="left_attach">1</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="usage_label">
+            <property name="visible">False</property>
+            <property name="can_focus">False</property>
+            <property name="no_show_all">True</property>
+            <property name="halign">end</property>
+            <property name="valign">end</property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">0</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLevelBar" id="usage_bar">
+            <property name="visible">False</property>
+            <property name="can_focus">False</property>
+            <property name="no_show_all">True</property>
+            <property name="halign">fill</property>
+            <property name="valign">start</property>
+            <property name="hexpand">True</property>
+          </object>
+          <packing>
+            <property name="left_attach">2</property>
+            <property name="top_attach">1</property>
+            <property name="width">1</property>
+            <property name="height">1</property>
+          </packing>
+        </child>
       </object>
-      <packing>
-        <property name="left_attach">0</property>
-        <property name="top_attach">0</property>
-        <property name="width">1</property>
-        <property name="height">2</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="name_label">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">start</property>
-        <property name="valign">end</property>
-        <property name="hexpand">True</property>
-        <property name="use_markup">True</property>
-        <property name="xalign">0</property>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">0</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="path_label">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="halign">start</property>
-        <property name="valign">start</property>
-        <property name="hexpand">True</property>
-        <property name="use_markup">True</property>
-        <property name="xalign">0</property>
-        <style>
-          <class name="dim-label"/>
-        </style>
-      </object>
-      <packing>
-        <property name="left_attach">1</property>
-        <property name="top_attach">1</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLabel" id="usage_label">
-        <property name="visible">False</property>
-        <property name="can_focus">False</property>
-        <property name="no_show_all">True</property>
-        <property name="halign">end</property>
-        <property name="valign">end</property>
-        <property name="use_markup">True</property>
-      </object>
-      <packing>
-        <property name="left_attach">2</property>
-        <property name="top_attach">0</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
-      </packing>
-    </child>
-    <child>
-      <object class="GtkLevelBar" id="usage_bar">
-        <property name="visible">False</property>
-        <property name="can_focus">False</property>
-        <property name="no_show_all">True</property>
-        <property name="halign">fill</property>
-        <property name="valign">start</property>
-        <property name="hexpand">True</property>
-      </object>
-      <packing>
-        <property name="left_attach">2</property>
-        <property name="top_attach">1</property>
-        <property name="width">1</property>
-        <property name="height">1</property>
-      </packing>
     </child>
   </template>
 </interface>
diff --git a/src/fixes.vapi b/src/fixes.vapi
index 66c0bba..b690fae 100644
--- a/src/fixes.vapi
+++ b/src/fixes.vapi
@@ -6,3 +6,51 @@ namespace GLib2 {
                public void* join ();
        }
 }
+
+[CCode (cprefix = "Gtk", gir_namespace = "Gtk", gir_version = "3.0", lower_case_cprefix = "gtk_")]
+namespace LocalGtk {
+       [CCode (cheader_filename = "gtk/gtk.h", type_id = "gtk_list_box_get_type ()")]
+       public class ListBox : Gtk.Container, Atk.Implementor, Gtk.Buildable {
+               [CCode (has_construct_function = false, type = "GtkWidget*")]
+               public ListBox ();
+               public void drag_highlight_row (LocalGtk.ListBoxRow row);
+               public void drag_unhighlight_row ();
+               public unowned Gtk.Adjustment get_adjustment ();
+               public unowned LocalGtk.ListBoxRow get_row_at_index (int index);
+               public unowned LocalGtk.ListBoxRow get_row_at_y (int y);
+               public unowned LocalGtk.ListBoxRow get_selected_row ();
+               public Gtk.SelectionMode get_selection_mode ();
+               public void invalidate_filter ();
+               public void invalidate_headers ();
+               public void invalidate_sort ();
+               public void select_row (LocalGtk.ListBoxRow? row);
+               public void set_activate_on_single_click (bool single);
+               public void set_adjustment (Gtk.Adjustment? adjustment);
+               public void set_filter_func (owned LocalGtk.ListBoxFilterFunc? filter_func);
+               public void set_header_func (owned LocalGtk.ListBoxUpdateHeaderFunc? update_header);
+               public void set_placeholder (Gtk.Widget? placeholder);
+               public void set_selection_mode (Gtk.SelectionMode mode);
+               public void set_sort_func (owned LocalGtk.ListBoxSortFunc? sort_func);
+               public bool activate_on_single_click { get; set; }
+               public Gtk.SelectionMode selection_mode { get; set; }
+               public virtual signal void activate_cursor_row ();
+               public virtual signal void move_cursor (Gtk.MovementStep step, int count);
+               public virtual signal void row_activated (LocalGtk.ListBoxRow row);
+               public virtual signal void row_selected (LocalGtk.ListBoxRow row);
+               public virtual signal void toggle_cursor_row ();
+       }
+       [CCode (cheader_filename = "gtk/gtk.h", type_id = "gtk_list_box_row_get_type ()")]
+       public class ListBoxRow : Gtk.Bin, Atk.Implementor, Gtk.Buildable {
+               [CCode (has_construct_function = false, type = "GtkWidget*")]
+               public ListBoxRow ();
+               public void changed ();
+               public unowned Gtk.Widget get_header ();
+               public void set_header (Gtk.Widget? header);
+       }
+       [CCode (cheader_filename = "gtk/gtk.h", instance_pos = 1.9)]
+       public delegate bool ListBoxFilterFunc (LocalGtk.ListBoxRow row);
+       [CCode (cheader_filename = "gtk/gtk.h", instance_pos = 2.9)]
+       public delegate int ListBoxSortFunc (LocalGtk.ListBoxRow row1, LocalGtk.ListBoxRow row2);
+       [CCode (cheader_filename = "gtk/gtk.h", instance_pos = 2.9)]
+       public delegate void ListBoxUpdateHeaderFunc (LocalGtk.ListBoxRow row, LocalGtk.ListBoxRow before);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]