]> saetta.ns0.it Git - solipa/organigramma/commitdiff
Migrato l'elenco persone a GdaExGrid (refs #833).
authorAndrea Zagli <azagli@libero.it>
Sat, 12 Nov 2016 11:50:34 +0000 (12:50 +0100)
committerAndrea Zagli <azagli@libero.it>
Sat, 12 Nov 2016 11:50:34 +0000 (12:50 +0100)
data/organigramma/gui/organigramma.gui
src/persone.c

index e540c7d914aa719016e6d852711445f7e49ebb5a..f49fc5397d37cdc610f58f9262a07cde44132a9e 100644 (file)
       <column type="gchararray"/>
     </columns>
   </object>
-  <object class="GtkListStore" id="lstore_persone">
-    <columns>
-      <!-- column-name id -->
-      <column type="guint"/>
-      <!-- column-name cognome_nome -->
-      <column type="gchararray"/>
-    </columns>
-  </object>
-  <object class="GtkWindow" id="w_persone">
-    <property name="can_focus">False</property>
-    <property name="title" translatable="yes">Persone - Gestione organigramma</property>
-    <property name="modal">True</property>
-    <property name="window_position">center-on-parent</property>
-    <property name="default_width">500</property>
-    <property name="default_height">400</property>
-    <property name="destroy_with_parent">True</property>
-    <child>
-      <object class="GtkBox" id="vbx_persone">
-        <property name="visible">True</property>
-        <property name="can_focus">False</property>
-        <property name="border_width">5</property>
-        <property name="orientation">vertical</property>
-        <property name="spacing">5</property>
-        <child>
-          <object class="GtkLabel" id="label139">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="label" translatable="yes">&lt;b&gt;Persone&lt;/b&gt;</property>
-            <property name="use_markup">True</property>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">0</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkScrolledWindow" id="scrolledwindow32">
-            <property name="visible">True</property>
-            <property name="can_focus">True</property>
-            <property name="shadow_type">etched-in</property>
-            <child>
-              <object class="GtkTreeView" id="treeview18">
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="model">lstore_persone</property>
-                <property name="headers_clickable">False</property>
-                <property name="search_column">0</property>
-                <child internal-child="selection">
-                  <object class="GtkTreeSelection"/>
-                </child>
-                <child>
-                  <object class="GtkTreeViewColumn" id="treeviewcolumn28">
-                    <property name="title">Cognome/Nome</property>
-                    <child>
-                      <object class="GtkCellRendererText" id="cellrenderertext39"/>
-                      <attributes>
-                        <attribute name="text">1</attribute>
-                      </attributes>
-                    </child>
-                  </object>
-                </child>
-              </object>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">True</property>
-            <property name="fill">True</property>
-            <property name="position">1</property>
-          </packing>
-        </child>
-        <child>
-          <object class="GtkButtonBox" id="hbuttonbox25">
-            <property name="visible">True</property>
-            <property name="can_focus">False</property>
-            <property name="spacing">5</property>
-            <property name="layout_style">end</property>
-            <child>
-              <object class="GtkButton" id="button102">
-                <property name="label">gtk-new</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">0</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button103">
-                <property name="label">gtk-edit</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">1</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button104">
-                <property name="label">gtk-delete</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">2</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button107">
-                <property name="label">gtk-cancel</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">3</property>
-              </packing>
-            </child>
-            <child>
-              <object class="GtkButton" id="button108">
-                <property name="label">gtk-ok</property>
-                <property name="visible">True</property>
-                <property name="can_focus">True</property>
-                <property name="receives_default">True</property>
-                <property name="use_stock">True</property>
-              </object>
-              <packing>
-                <property name="expand">False</property>
-                <property name="fill">False</property>
-                <property name="position">4</property>
-              </packing>
-            </child>
-          </object>
-          <packing>
-            <property name="expand">False</property>
-            <property name="fill">True</property>
-            <property name="position">2</property>
-          </packing>
-        </child>
-      </object>
-    </child>
-  </object>
   <object class="GtkListStore" id="lstore_posizioni_economiche">
     <columns>
       <!-- column-name id -->
       </object>
     </child>
   </object>
+  <object class="GtkWindow" id="w_persone">
+    <property name="can_focus">False</property>
+    <property name="title" translatable="yes">Persone - Gestione organigramma</property>
+    <property name="modal">True</property>
+    <property name="window_position">center-on-parent</property>
+    <property name="default_width">500</property>
+    <property name="default_height">400</property>
+    <property name="destroy_with_parent">True</property>
+    <child>
+      <object class="GtkBox" id="vbx_persone">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="border_width">5</property>
+        <property name="orientation">vertical</property>
+        <property name="spacing">5</property>
+        <child>
+          <object class="GtkLabel" id="label139">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">&lt;b&gt;Persone&lt;/b&gt;</property>
+            <property name="use_markup">True</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkScrolledWindow" id="scrolledwindow32">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="shadow_type">etched-in</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">True</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkButtonBox" id="hbuttonbox25">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="spacing">5</property>
+            <property name="layout_style">end</property>
+            <child>
+              <object class="GtkButton" id="button102">
+                <property name="label">gtk-new</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">0</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button103">
+                <property name="label">gtk-edit</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">1</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button104">
+                <property name="label">gtk-delete</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">2</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button107">
+                <property name="label">gtk-cancel</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">3</property>
+              </packing>
+            </child>
+            <child>
+              <object class="GtkButton" id="button108">
+                <property name="label">gtk-ok</property>
+                <property name="visible">True</property>
+                <property name="can_focus">True</property>
+                <property name="receives_default">True</property>
+                <property name="use_stock">True</property>
+              </object>
+              <packing>
+                <property name="expand">False</property>
+                <property name="fill">False</property>
+                <property name="position">4</property>
+              </packing>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">2</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
   <object class="GtkWindow" id="w_posizione_economica">
     <property name="can_focus">False</property>
     <property name="title" translatable="yes">Posizione economica - Gestione organigramma</property>
index 2aad9311625491fc4a80bb028d523db818e1ce22..d6c5ecdfceb529520e7ef8eb4adbf8fda5efd6f3 100644 (file)
@@ -17,6 +17,7 @@
  *
  */
 
+#include <libgdaexgrid/libgdaexgrid.h>
 #include <libzakautho/autoz.h>
 #include <libzakutils/libzakutils.h>
 
@@ -71,8 +72,10 @@ struct _OrganigrammaPersonePrivate
                OrganigrammaCommons *commons;
 
                GtkWidget *widget;
+               GdaExGrid *grid;
+               GtkWidget *wgrid;
                GtkTreeSelection *selection;
-               GtkListStore *lstore_persone;
+               GtkTreeStore *tstore_persone;
 
                gboolean selezione;
                guint id_uffici;
@@ -129,6 +132,8 @@ OrganigrammaPersone
        GError *error;
        ZakAuthoIResource *ires1;
 
+       GdaExGridColumn *gcol;
+
        OrganigrammaPersone *a = ORGANIGRAMMA_PERSONE (g_object_new (organigramma_persone_get_type (), NULL));
 
        OrganigrammaPersonePrivate *priv = ORGANIGRAMMA_PERSONE_GET_PRIVATE (a);
@@ -147,9 +152,8 @@ OrganigrammaPersone
 
        error = NULL;
        gtk_builder_add_objects_from_file (priv->commons->gtkbuilder, priv->commons->guifile,
-                                          g_strsplit (g_strconcat ("lstore_persone|",
-                                          (selezione ? "w_persone" : "vbx_persone"),
-                                          NULL), "|", -1),
+                                          g_strsplit ((selezione ? "w_persone" : "vbx_persone"),
+                                                                                                  "|", -1),
                                           &error);
        if (error != NULL)
                {
@@ -158,8 +162,6 @@ OrganigrammaPersone
                }
 
        priv->widget = GTK_WIDGET (gtk_builder_get_object (priv->commons->gtkbuilder, (selezione ? "w_persone" : "vbx_persone")));
-       priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview18")));
-       priv->lstore_persone = GTK_LIST_STORE (gtk_builder_get_object (priv->commons->gtkbuilder, "lstore_persone"));
 
        if (priv->selezione)
                {
@@ -170,13 +172,33 @@ OrganigrammaPersone
                        priv->wtransient = GTK_WINDOW (gtk_builder_get_object (priv->commons->gtkbuilder, "w_main"));
                }
 
+       /* creo la gdaexgrid */
+       priv->grid = gdaex_grid_new ();
+       gdaex_grid_set_solipa (priv->grid, priv->commons->solipa);
+       gdaex_grid_set_title (priv->grid, gtk_label_get_text (GTK_LABEL (gtk_builder_get_object (priv->commons->gtkbuilder, "label139"))));
+
+       gcol = gdaex_grid_column_new ("ID", "id", G_TYPE_INT, TRUE, TRUE, TRUE, FALSE, -1);
+       gdaex_grid_add_column (priv->grid, gcol);
+
+       gcol = gdaex_grid_column_new_defaults ("Cognome/Nome", "cognome_nome", G_TYPE_STRING);
+       gdaex_grid_add_column (priv->grid, gcol);
+
+       priv->wgrid = gdaex_grid_get_widget (priv->grid);
+
+       gtk_tree_view_set_search_column (GTK_TREE_VIEW (priv->wgrid), 1);
+       gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->commons->gtkbuilder, "scrolledwindow32")), priv->wgrid);
+       gtk_widget_show (priv->wgrid);
+
+       priv->selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (priv->wgrid));
+       priv->tstore_persone = GTK_TREE_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (priv->wgrid)));
+
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button102"),
                          "clicked", G_CALLBACK (organigramma_persone_on_btn_nuovo_clicked), (gpointer)a);
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button103"),
                          "clicked", G_CALLBACK (organigramma_persone_on_btn_modifica_clicked), (gpointer)a);
        g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "button104"),
                          "clicked", G_CALLBACK (organigramma_persone_on_btn_elimina_clicked), (gpointer)a);
-       g_signal_connect (gtk_builder_get_object (priv->commons->gtkbuilder, "treeview18"),
+       g_signal_connect (priv->wgrid,
                          "row-activated", G_CALLBACK (organigramma_persone_on_trv_organigramma_persone_row_activated), (gpointer)a);
 
        if (priv->selezione)
@@ -235,7 +257,7 @@ organigramma_persone_carica (OrganigrammaPersone *persone)
 
        OrganigrammaPersonePrivate *priv = ORGANIGRAMMA_PERSONE_GET_PRIVATE (persone);
 
-       gtk_list_store_clear (priv->lstore_persone);
+       gtk_tree_store_clear (priv->tstore_persone);
 
        sql_where = g_strdup ("");
        sql_join = g_strdup ("");
@@ -277,23 +299,10 @@ organigramma_persone_carica (OrganigrammaPersone *persone)
                          sql_join,
                          sql_where);
        dm = gdaex_query (priv->commons->gdaex, sql);
+       gdaex_fill_treemodel_from_sql (priv->commons->gdaex, GTK_TREE_MODEL (priv->tstore_persone), sql, NULL, NULL);
        g_free (sql_join);
        g_free (sql_where);
        g_free (sql);
-       if (dm != NULL)
-               {
-                       rows = gda_data_model_get_n_rows (dm);
-                       for (row = 0; row < rows; row++)
-                               {
-                                       gtk_list_store_append (priv->lstore_persone, &iter);
-                                       gtk_list_store_set (priv->lstore_persone, &iter,
-                                                           COL_ID, gdaex_data_model_get_field_value_integer_at (dm, row, "id"),
-                                                           COL_NOME, gdaex_data_model_get_field_value_stringify_at (dm, row, "cognome_nome"),
-                                                           -1);
-                               }
-
-                       g_object_unref (dm);
-               }
 }
 
 static void
@@ -308,7 +317,7 @@ organigramma_persone_modifica (OrganigrammaPersone *persone)
                {
                        GtkWidget *w;
 
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_persone), &iter,
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_persone), &iter,
                                            COL_ID, &id,
                                            -1);
 
@@ -326,7 +335,7 @@ organigramma_persone_modifica (OrganigrammaPersone *persone)
                        solipa_message_dialog (GTK_WIDGET (priv->wtransient),
                                               GTK_MESSAGE_WARNING,
                                               GTK_BUTTONS_OK,
-                                              "Occorre prima selezionare una persona");
+                                              "Occorre prima selezionare una persona.");
                }
 }
 
@@ -341,7 +350,7 @@ organigramma_persone_selezionato (OrganigrammaPersone *persone)
 
        if (gtk_tree_selection_get_selected (priv->selection, NULL, &iter))
                {
-                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_persone), &iter,
+                       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_persone), &iter,
                                            COL_ID, &id,
                                            -1);
 
@@ -355,7 +364,7 @@ organigramma_persone_selezionato (OrganigrammaPersone *persone)
                        solipa_message_dialog (GTK_WIDGET (priv->wtransient),
                                               GTK_MESSAGE_WARNING,
                                               GTK_BUTTONS_OK,
-                                              "Occorre prima selezionare una persona");
+                                              "Occorre prima selezionare una persona.");
                }
 }
 
@@ -437,7 +446,7 @@ organigramma_persone_on_btn_elimina_clicked (GtkButton *button,
                                                   GTK_BUTTONS_YES_NO,
                                                   "Sicuro di voler eliminare la persona selezionata?") == GTK_RESPONSE_YES)
                                {
-                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->lstore_persone), &iter,
+                                       gtk_tree_model_get (GTK_TREE_MODEL (priv->tstore_persone), &iter,
                                                            COL_ID, &id,
                                                            -1);
 
@@ -452,7 +461,7 @@ organigramma_persone_on_btn_elimina_clicked (GtkButton *button,
                        solipa_message_dialog (GTK_WIDGET (priv->wtransient),
                                               GTK_MESSAGE_WARNING,
                                               GTK_BUTTONS_OK,
-                                              "Occorre prima selezionare una persona");
+                                              "Occorre prima selezionare una persona.");
                }
 }