GnuCash  5.6-150-g038405b370+
gnc-tree-view-sx-list.c
1 
5 /********************************************************************
6  * This program is free software; you can redistribute it and/or *
7  * modify it under the terms of version 2 and/or version 3 of the *
8  * GNU General Public *
9  * License as published by the Free Software Foundation. *
10  * *
11  * As a special exception, permission is granted to link the binary *
12  * module resultant from this code with the OpenSSL project's *
13  * "OpenSSL" library (or modified versions of it that use the same *
14  * license as the "OpenSSL" library), and distribute the linked *
15  * executable. You must obey the GNU General Public License in all *
16  * respects for all of the code used other than "OpenSSL". If you *
17  * modify this file, you may extend this exception to your version *
18  * of the file, but you are not obligated to do so. If you do not *
19  * wish to do so, delete this exception statement from your version *
20  * of this file. *
21  * *
22  * This program is distributed in the hope that it will be useful, *
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
25  * GNU General Public License for more details. *
26  * *
27  * You should have received a copy of the GNU General Public License*
28  * along with this program; if not, contact: *
29  * *
30  * Free Software Foundation Voice: +1-617-542-5942 *
31  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
32  * Boston, MA 02110-1301, USA gnu@gnu.org *
33  * *
34  *******************************************************************/
35 
36 #include <config.h>
37 
38 #include <gtk/gtk.h>
39 #include <glib/gi18n.h>
40 #include <string.h>
41 
42 #include "gnc-tree-view.h"
43 #include "gnc-tree-view-sx-list.h"
44 #include "gnc-sx-list-tree-model-adapter.h"
45 
46 #define LOG_MOD "gnc.ui.tree-view.sx-list"
47 static QofLogModule log_module = LOG_MOD;
48 #undef G_LOG_DOMAIN
49 #define G_LOG_DOMAIN LOG_MOD
50 
51 static void gnc_tree_view_sx_list_dispose (GObject *object);
52 static void gnc_tree_view_sx_list_finalize (GObject *object);
53 
55 {
56  GncTreeView gnc_tree_view;
57 
58  GtkTreeModel *tree_model;
59  gboolean disposed;
60 };
61 
62 G_DEFINE_TYPE(GncTreeViewSxList, gnc_tree_view_sx_list, GNC_TYPE_TREE_VIEW)
63 
64 static void
65 gnc_tree_view_sx_list_class_init (GncTreeViewSxListClass *klass)
66 {
67  GObjectClass *o_class = G_OBJECT_CLASS(klass);
68 
69  o_class->dispose = gnc_tree_view_sx_list_dispose;
70  o_class->finalize = gnc_tree_view_sx_list_finalize;
71 }
72 
73 static void
74 gnc_tree_view_sx_list_init (GncTreeViewSxList *view)
75 {
76  ; /* nop */
77 }
78 
79 static void
80 gnc_tree_view_sx_list_dispose (GObject *object)
81 {
82  GncTreeViewSxList *view;
83 
84  gnc_leave_return_if_fail (object != NULL);
85  gnc_leave_return_if_fail (GNC_IS_TREE_VIEW_SX_LIST(object));
86 
87  view = GNC_TREE_VIEW_SX_LIST(object);
88 
89  if (view->disposed)
90  return;
91  view->disposed = TRUE;
92 
93  g_object_unref (G_OBJECT(view->tree_model));
94  view->tree_model = NULL;
95 
96  G_OBJECT_CLASS(gnc_tree_view_sx_list_parent_class)->dispose (object);
97 }
98 
99 static void
100 gnc_tree_view_sx_list_finalize(GObject *object)
101 {
102  gnc_leave_return_if_fail (object != NULL);
103  gnc_leave_return_if_fail (GNC_IS_TREE_VIEW_SX_LIST(object));
104 
105  G_OBJECT_CLASS(gnc_tree_view_sx_list_parent_class)->finalize (object);
106 }
107 
108 GtkTreeView*
109 gnc_tree_view_sx_list_new (GncSxInstanceModel *sx_instances)
110 {
111  GncTreeViewSxList *view = (GncTreeViewSxList*)g_object_new (GNC_TYPE_TREE_VIEW_SX_LIST, NULL);
112  g_object_set (view, "name", "gnc-id-sx-list-tree", NULL);
113 
114  view->tree_model = GTK_TREE_MODEL(gnc_sx_list_tree_model_adapter_new (sx_instances));
115  gtk_tree_view_set_model (GTK_TREE_VIEW(view), GTK_TREE_MODEL(view->tree_model));
116 
117  GtkTreeViewColumn *col = gnc_tree_view_add_text_column (GNC_TREE_VIEW(view), _("Name"), "name", NULL,
118  "Semi-Monthly Paycheck",
119  SXLTMA_COL_NAME, -1, NULL);
120  g_object_set_data (G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
121 
122  col = gnc_tree_view_add_toggle_column (GNC_TREE_VIEW(view), _("Enabled"),
123  C_("Single-character short column-title form of 'Enabled'", "E"),
124  "enabled", SXLTMA_COL_ENABLED,
125  GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
126  NULL, NULL);
127  g_object_set_data (G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
128 
129  col = gnc_tree_view_add_text_column (GNC_TREE_VIEW(view), _("Frequency"), "frequency", NULL,
130  "Weekly (x3): -------",
131  SXLTMA_COL_FREQUENCY, -1, NULL);
132  g_object_set_data (G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
133 
134  col = gnc_tree_view_add_text_column (GNC_TREE_VIEW(view), _("Last Occur"), "last-occur", NULL,
135  "2007-01-02",
136  SXLTMA_COL_LAST_OCCUR, -1, NULL);
137  g_object_set_data (G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
138 
139  col = gnc_tree_view_add_text_column (GNC_TREE_VIEW(view), _("Next Occur"), "next-occur", NULL,
140  "2007-01-02",
141  SXLTMA_COL_NEXT_OCCUR, -1, NULL);
142  g_object_set_data (G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
143 
144  gnc_tree_view_configure_columns (GNC_TREE_VIEW(view));
145 
146  gtk_widget_show (GTK_WIDGET(view));
147  return GTK_TREE_VIEW(view);
148 }
149 
150 SchedXaction*
151 gnc_tree_view_sx_list_get_sx_from_path (GncTreeViewSxList *view, GtkTreePath *path)
152 {
153  GtkTreeIter iter;
154  gtk_tree_model_get_iter (GTK_TREE_MODEL(view->tree_model), &iter, path);
155  return gnc_sx_list_tree_model_adapter_get_sx_instances(
156  GNC_SX_LIST_TREE_MODEL_ADAPTER(view->tree_model), &iter)->sx;
157 }
GncTreeView implementation for Scheduled Transaction List.
common utilities for manipulating a GtkTreeView within gnucash
GtkTreeViewColumn * gnc_tree_view_add_toggle_column(GncTreeView *view, const gchar *column_title, const gchar *column_short_title, const gchar *pref_name, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn, renderer_toggled toggle_edited_cb)
This function adds a new toggle column to a GncTreeView base view.
void gnc_tree_view_configure_columns(GncTreeView *view)
Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available.
#define gnc_leave_return_if_fail(test)
Replacement for g_return_if_fail, but calls LEAVE if the test fails.
Definition: qoflog.h:300
GtkTreeViewColumn * gnc_tree_view_add_text_column(GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
This function adds a new text column to a GncTreeView base view.