patch to access resource->units from GUI
Lee Baylis <lee-gZngeWTYz/[email protected]> Wed, 19 Nov 2008 03:59:51 +0000
| Newsgroups | gmane.comp.gnome.apps.planner.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all, Here is my set of patches to make the units property on a resource available through the GUI. These patches don't make the units property do anything - they just allow for it to be set and changed. I plan to start replacing both: - instances of the figure 100 (where it references a maximum number of units), - the temporary USAGE_MAX_UNITS flag I put in mrp-resource.c in my last set of patches, with this new property. thanks, lee _______________________________________________ Planner-dev-list mailing list [email protected] http://mail.gnome.org/mailman/listinfo/planner-dev-list
planner-resource-dialog.c.patch
(text/x-diff, 6 KB)
Index: src/planner-resource-dialog.c =================================================================== --- src/planner-resource-dialog.c (revision 940) +++ src/planner-resource-dialog.c (working copy) @@ -5,6 +5,7 @@ * Copyright (C) 2001-2002 Richard Hult <[email protected]> * Copyright (C) 2001-2002 Mikael Hallendal <[email protected]> * Copyright (C) 2001-2004 Alvaro del Castillo <[email protected]> + * Copyright (C) 2008 Lee Baylis <lee-gZngeWTYz/[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -46,6 +47,7 @@ GtkWidget *email_entry; GtkWidget *group_menu; GtkWidget *cost_entry; + GtkWidget *units_spinbutton; GtkWidget *calendar_tree_view; GtkWidget *note_textview; GtkTextBuffer *note_buffer; @@ -123,6 +125,17 @@ static gboolean resource_dialog_resource_cost_focus_out_cb (GtkWidget *w, GdkEventFocus *event, DialogData *data); +static void resource_dialog_units_changed_cb (GtkWidget *w, + DialogData *data); +static void resource_dialog_notify_units_cb (MrpResource *resource, + GParamSpec *pspec, + GtkWidget *dialog); +static gboolean resource_dialog_resource_units_focus_in_cb (GtkWidget *w, + GdkEventFocus *event, + DialogData *data); +static gboolean resource_dialog_resource_units_focus_out_cb (GtkWidget *w, + GdkEventFocus *event, + DialogData *data); static void resource_dialog_notify_calendar_cb (MrpResource *resource, GParamSpec *pspec, GtkWidget *dialog); @@ -411,6 +424,12 @@ 0); g_signal_connect_object (resource, + "notify::units", + G_CALLBACK (resource_dialog_notify_units_cb), + data->dialog, + 0); + + g_signal_connect_object (resource, "notify::calendar", G_CALLBACK (resource_dialog_notify_calendar_cb), data->dialog, @@ -1250,6 +1269,97 @@ dialog); } +static void +resource_dialog_units_changed_cb (GtkWidget *w, + DialogData *data) +{ + gint units; + + units = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (w)); + + g_signal_handlers_block_by_func (data->resource, + resource_dialog_notify_units_cb, + data->dialog); + + g_object_set (data->resource, "units", units, NULL); + + g_signal_handlers_unblock_by_func (data->resource, + resource_dialog_notify_units_cb, + data->dialog); +} + +static void +resource_dialog_notify_units_cb (MrpResource *resource, + GParamSpec *pspec, + GtkWidget *dialog) +{ + DialogData *data; + gint units; + + data = DIALOG_GET_DATA (dialog); + + g_object_get (resource, "units", &units, NULL); + + g_signal_handlers_block_by_func (data->units_spinbutton, + resource_dialog_units_changed_cb, + data); + + gtk_spin_button_set_value (GTK_SPIN_BUTTON (data->units_spinbutton), + units); + + g_signal_handlers_unblock_by_func (data->units_spinbutton, + resource_dialog_units_changed_cb, + data); +} + +static gboolean +resource_dialog_resource_units_focus_out_cb (GtkWidget *w, + GdkEventFocus *event, + DialogData *data) +{ + gint current_units; + gint focus_in_units; + GValue value = { 0 }; + PlannerCmd *cmd; + + g_assert (MRP_IS_RESOURCE (data->resource)); + + focus_in_units = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (data->resource), + "focus_in_units")); + + gtk_spin_button_update (GTK_SPIN_BUTTON (w)); + current_units = gtk_spin_button_get_value (GTK_SPIN_BUTTON (w)); + + if (focus_in_units == current_units) { + return FALSE; + } + + g_object_set (data->resource, "units", current_units, NULL); + + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, focus_in_units); + + cmd = resource_cmd_edit_property_focus (data->main_window, + data->resource, "units", &value); + + return FALSE; +} + +static gboolean +resource_dialog_resource_units_focus_in_cb (GtkWidget *w, + GdkEventFocus *event, + DialogData *data) +{ + gint units; + + units = gtk_spin_button_get_value (GTK_SPIN_BUTTON (w)); + + g_object_set_data (G_OBJECT (data->resource), + "focus_in_units", GINT_TO_POINTER (units)); + + return FALSE; +} + static void resource_dialog_notify_calendar_cb (MrpResource *resource, GParamSpec *pspec, @@ -1687,6 +1797,7 @@ MrpGroup *group; MrpResourceType type; gfloat cost; + gint units; GList *groups; gint index = 0; gchar *note; @@ -1751,6 +1862,7 @@ data->group_menu = glade_xml_get_widget (glade, "menu_group"); data->email_entry = glade_xml_get_widget (glade, "entry_email"); data->cost_entry = glade_xml_get_widget (glade, "entry_cost"); + data->units_spinbutton = glade_xml_get_widget (glade, "units_spinbutton"); data->calendar_tree_view = glade_xml_get_widget (glade, "calendar_treeview"); data->note_textview = glade_xml_get_widget (glade, "note_textview"); @@ -1809,6 +1921,7 @@ "group", &group, "email", &email, "cost", &cost, + "units", &units, NULL); gtk_entry_set_text (GTK_ENTRY (data->name_entry), name); @@ -1921,8 +2034,26 @@ "focus_in_event", G_CALLBACK (resource_dialog_resource_cost_focus_in_cb), data); - + gtk_spin_button_set_value (GTK_SPIN_BUTTON (data->units_spinbutton), + units); + + g_signal_connect (data->units_spinbutton, + "changed", + G_CALLBACK (resource_dialog_units_changed_cb), + data); + + g_signal_connect (data->units_spinbutton, + "focus_out_event", + G_CALLBACK (resource_dialog_resource_units_focus_out_cb), + data); + + g_signal_connect (data->units_spinbutton, + "focus_in_event", + G_CALLBACK (resource_dialog_resource_units_focus_in_cb), + data); + + g_free (name); g_free (short_name); g_free (email);
planner-resource-view.c.patch
(text/x-diff, 4.9 KB)
Index: src/planner-resource-view.c =================================================================== --- src/planner-resource-view.c (revision 940) +++ src/planner-resource-view.c (working copy) @@ -5,6 +5,7 @@ * Copyright (C) 2002 Richard Hult <[email protected]> * Copyright (C) 2002 Mikael Hallendal <[email protected]> * Copyright (C) 2002-2004 Alvaro del Castillo <[email protected]> + * Copyright (C) 2008 Lee Baylis <lee-gZngeWTYz/[email protected]> * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -119,6 +120,10 @@ gchar *path_string, gchar *new_text, gpointer user_data); +static void resource_view_cell_units_edited (GtkCellRendererText *cell, + gchar *path_string, + gchar *new_text, + gpointer user_data); static void resource_view_property_value_edited (GtkCellRendererText *cell, gchar *path_string, gchar *new_text, @@ -185,6 +190,11 @@ GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data); +static void resource_view_units_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data); static void resource_view_popup_menu (GtkWidget *widget, PlannerView *view); static void resource_view_edit_resource_cb (GtkAction *action, @@ -1335,6 +1345,33 @@ G_CALLBACK (resource_view_cell_cost_edited), view); + /* Units */ + cell = gtk_cell_renderer_text_new (); + g_object_set (cell, "editable", TRUE, NULL); + + col = gtk_tree_view_column_new_with_attributes (_("Available Units"), + cell, NULL); + gtk_tree_view_column_set_resizable (col, TRUE); + /*gtk_tree_view_column_set_min_width (col, 150);*/ + + gtk_tree_view_column_set_cell_data_func (col, cell, + resource_view_units_data_func, + NULL, NULL); + g_object_set_data (G_OBJECT (col), + "data-func", resource_view_units_data_func); + g_object_set_data (G_OBJECT (col), "id", "units"); + + gtk_tree_view_append_column (tree_view, col); + g_signal_connect (col, + "notify::width", + G_CALLBACK (resource_view_column_notify_width_cb), + view); + + g_signal_connect (cell, + "edited", + G_CALLBACK (resource_view_cell_units_edited), + view); + /* project = planner_window_get_project (view->main_window); properties = mrp_project_get_properties_from_type (project, @@ -1666,6 +1703,43 @@ } static void +resource_view_cell_units_edited (GtkCellRendererText *cell, + gchar *path_string, + gchar *new_text, + gpointer user_data) +{ + PlannerView *view; + PlannerCmd *cmd; + MrpResource *resource; + GtkTreeView *tree_view; + GtkTreeModel *model; + GtkTreePath *path; + GtkTreeIter iter; + GValue value = { 0 }; + gint ivalue; + + view = PLANNER_VIEW (user_data); + + tree_view = PLANNER_RESOURCE_VIEW (view)->priv->tree_view; + + model = gtk_tree_view_get_model (tree_view); + + path = gtk_tree_path_new_from_string (path_string); + + gtk_tree_model_get_iter (model, &iter, path); + + gtk_tree_model_get (model, &iter, COL_RESOURCE, &resource, -1); + + ivalue = planner_parse_int (new_text); + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, ivalue); + cmd = resource_cmd_edit_property (view, resource, "units", &value); + g_value_unset (&value); + + gtk_tree_path_free (path); +} + +static void resource_view_cell_type_edited (PlannerCellRendererList *cell, gchar *path_string, gchar *new_text, @@ -2287,6 +2361,26 @@ } static void +resource_view_units_data_func (GtkTreeViewColumn *tree_column, + GtkCellRenderer *cell, + GtkTreeModel *tree_model, + GtkTreeIter *iter, + gpointer data) +{ + MrpResource *resource; + gint units; + gchar *units_text; + + gtk_tree_model_get (tree_model, iter, COL_RESOURCE, &resource, -1); + + g_object_get (resource, "units", &units, NULL); + units_text = planner_format_int (units); + + g_object_set (cell, "text", units_text, NULL); + g_free (units_text); +} + +static void resource_view_property_data_func (GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, GtkTreeModel *model,
resource-dialog.glade.patch
(text/x-diff, 2.9 KB)
Index: data/glade/resource-dialog.glade =================================================================== --- data/glade/resource-dialog.glade (revision 940) +++ data/glade/resource-dialog.glade (working copy) @@ -60,7 +60,7 @@ <widget class="GtkTable" id="table1"> <property name="border_width">12</property> <property name="visible">True</property> - <property name="n_rows">6</property> + <property name="n_rows">7</property> <property name="n_columns">2</property> <property name="homogeneous">False</property> <property name="row_spacing">6</property> @@ -334,6 +334,56 @@ <property name="y_options"></property> </packing> </child> + <child> + <widget class="GtkLabel" id="label_units"> + <property name="visible">True</property> + <property name="label" translatable="yes">Available _Units:</property> + <property name="use_underline">True</property> + <property name="use_markup">False</property> + <property name="justify">GTK_JUSTIFY_LEFT</property> + <property name="wrap">False</property> + <property name="selectable">False</property> + <property name="xalign">0</property> + <property name="yalign">0.5</property> + <property name="xpad">0</property> + <property name="ypad">0</property> + <property name="mnemonic_widget">units_spinbutton</property> + <property name="ellipsize">PANGO_ELLIPSIZE_NONE</property> + <property name="width_chars">-1</property> + <property name="single_line_mode">False</property> + <property name="angle">0</property> + </widget> + <packing> + <property name="left_attach">0</property> + <property name="right_attach">1</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> + <property name="x_options">fill</property> + <property name="y_options"></property> + </packing> + </child> + <child> + <widget class="GtkSpinButton" id="units_spinbutton"> + <property name="visible">True</property> + <property name="tooltip" translatable="yes">The maximum units available for a resource without overloading it.</property> + <property name="can_focus">True</property> + <property name="climb_rate">1</property> + <property name="digits">0</property> + <property name="numeric">False</property> + <property name="update_policy">GTK_UPDATE_ALWAYS</property> + <property name="snap_to_ticks">False</property> + <property name="wrap">False</property> + <property name="adjustment">100 0 9999 1 10 10</property> + </widget> + <packing> + <property name="left_attach">1</property> + <property name="right_attach">2</property> + <property name="top_attach">6</property> + <property name="bottom_attach">7</property> + <property name="y_options"></property> + </packing> + </child> + </widget> <packing> <property name="tab_expand">False</property>