GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 GNU General Public *
8  * License as published by the Free Software Foundation. *
9  *
10  * As a special exception, permission is granted to link the binary
11  * module resultant from this code with the OpenSSL project's
12  * "OpenSSL" library (or modified versions of it that use the same
13  * license as the "OpenSSL" library), and distribute the linked
14  * executable. You must obey the GNU General Public License in all
15  * respects for all of the code used other than "OpenSSL". If you
16  * modify this file, you may extend this exception to your version
17  * of the file, but you are not obligated to do so. If you do not
18  * wish to do so, delete this exception statement from your version
19  * of this file.
20  * *
21  * This program is distributed in the hope that it will be useful, *
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
24  * GNU General Public License for more details. *
25  * *
26  * You should have received a copy of the GNU General Public License*
27  * along with this program; if not, contact: *
28  * *
29  * Free Software Foundation Voice: +1-617-542-5942 *
30  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
31  * Boston, MA 02110-1301, USA [email protected] *
32  * *
33  *******************************************************************/
34 
35 #include "config.h"
36 
37 #include <gtk/gtk.h>
38 #include <glib/gi18n.h>
39 #include <string.h>
40 
41 #include "gnc-tree-view.h"
42 #include "gnc-tree-view-sx-list.h"
43 #include "gnc-sx-list-tree-model-adapter.h"
44 
45 #define LOG_MOD "gnc.ui.tree-view.sx-list"
46 static QofLogModule log_module = LOG_MOD;
47 #undef G_LOG_DOMAIN
48 #define G_LOG_DOMAIN LOG_MOD
49 
50 static void gnc_tree_view_sx_list_class_init(GncTreeViewSxListClass *klass);
51 static void gnc_tree_view_sx_list_init(GncTreeViewSxList *view);
52 static void gnc_tree_view_sx_list_dispose(GObject *object);
53 static void gnc_tree_view_sx_list_finalize(GObject *object);
54 
56 {
57  GtkTreeModel *tree_model;
58  gboolean disposed;
60 
61 #define GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(o) \
62  (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_VIEW_SX_LIST, GncTreeViewSxListPrivate))
63 
64 static GObjectClass *parent_class = NULL;
65 
66 GType
67 gnc_tree_view_sx_list_get_type(void)
68 {
69  static GType gnc_tree_view_sx_list_type = 0;
70 
71  if (gnc_tree_view_sx_list_type == 0)
72  {
73  static const GTypeInfo our_info =
74  {
75  sizeof (GncTreeViewSxListClass),
76  NULL,
77  NULL,
78  (GClassInitFunc) gnc_tree_view_sx_list_class_init,
79  NULL,
80  NULL,
81  sizeof (GncTreeViewSxList),
82  0,
83  (GInstanceInitFunc) gnc_tree_view_sx_list_init
84  };
85 
86  gnc_tree_view_sx_list_type = g_type_register_static (GNC_TYPE_TREE_VIEW,
87  "GncTreeViewSxList",
88  &our_info, 0);
89  }
90 
91  return gnc_tree_view_sx_list_type;
92 }
93 
94 static void
95 gnc_tree_view_sx_list_class_init(GncTreeViewSxListClass *klass)
96 {
97  GObjectClass *o_class;
98 
99  parent_class = g_type_class_peek_parent (klass);
100 
101  o_class = G_OBJECT_CLASS (klass);
102 
103  o_class->dispose = gnc_tree_view_sx_list_dispose;
104  o_class->finalize = gnc_tree_view_sx_list_finalize;
105 
106  g_type_class_add_private(klass, sizeof(GncTreeViewSxListPrivate));
107 }
108 
109 static void
110 gnc_tree_view_sx_list_init (GncTreeViewSxList *view)
111 {
112  ; /* nop */
113 }
114 
115 static void
116 gnc_tree_view_sx_list_dispose(GObject *object)
117 {
118  GncTreeViewSxList *view;
120 
121  gnc_leave_return_if_fail (object != NULL);
122  gnc_leave_return_if_fail (GNC_IS_TREE_VIEW_SX_LIST (object));
123 
124  view = GNC_TREE_VIEW_SX_LIST (object);
125  priv = GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(view);
126 
127  if (priv->disposed)
128  return;
129  priv->disposed = TRUE;
130 
131  g_object_unref(G_OBJECT(priv->tree_model));
132  priv->tree_model = NULL;
133 
134  if (G_OBJECT_CLASS (parent_class)->dispose)
135  (* G_OBJECT_CLASS (parent_class)->dispose) (object);
136 }
137 
138 static void
139 gnc_tree_view_sx_list_finalize(GObject *object)
140 {
141  gnc_leave_return_if_fail(object != NULL);
142  gnc_leave_return_if_fail(GNC_IS_TREE_VIEW_SX_LIST (object));
143 
144  if (G_OBJECT_CLASS(parent_class)->finalize)
145  (* G_OBJECT_CLASS(parent_class)->finalize) (object);
146 }
147 
148 GtkTreeView*
149 gnc_tree_view_sx_list_new(GncSxInstanceModel *sx_instances)
150 {
151  GncTreeView *view;
152  GtkTreeViewColumn *col;
154 
155  view = (GncTreeView*)g_object_new(GNC_TYPE_TREE_VIEW_SX_LIST, NULL);
156  g_object_set(view, "name", "sx_list_tree", NULL);
157 
158  priv = GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(view);
159 
160  priv->tree_model = GTK_TREE_MODEL(gnc_sx_list_tree_model_adapter_new(sx_instances));
161  gtk_tree_view_set_model (GTK_TREE_VIEW (view), GTK_TREE_MODEL(priv->tree_model));
162 
163  col = gnc_tree_view_add_text_column(view, _("Name"), "name", NULL,
164  "Semi-Monthly Paycheck",
165  SXLTMA_COL_NAME, -1, NULL);
166  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
167 
168  col = gnc_tree_view_add_toggle_column(view, _("Enabled"),
169  /* Translators: This string has a context prefix; the translation
170  must only contain the part after the | character. */
171  Q_("Single-character short column-title form of 'Enabled'|E"),
172  "enabled", SXLTMA_COL_ENABLED,
173  GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
174  NULL, NULL);
175  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
176 
177  col = gnc_tree_view_add_text_column(view, _("Frequency"), "frequency", NULL,
178  "Weekly (x3): -------",
179  SXLTMA_COL_FREQUENCY, -1, NULL);
180  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
181 
182  col = gnc_tree_view_add_text_column(view, _("Last Occur"), "last-occur", NULL,
183  "2007-01-02",
184  SXLTMA_COL_LAST_OCCUR, -1, NULL);
185  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
186 
187  col = gnc_tree_view_add_text_column(view, _("Next Occur"), "next-occur", NULL,
188  "2007-01-02",
189  SXLTMA_COL_NEXT_OCCUR, -1, NULL);
190  g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
191 
193 
194  gtk_widget_show(GTK_WIDGET(view));
195  return GTK_TREE_VIEW(view);
196 }
197 
199 gnc_tree_view_sx_list_get_sx_from_path(GncTreeViewSxList *view, GtkTreePath *path)
200 {
201  GtkTreeIter iter;
202  GncTreeViewSxListPrivate *priv = GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(view);
203  gtk_tree_model_get_iter(GTK_TREE_MODEL(priv->tree_model), &iter, path);
204  return gnc_sx_list_tree_model_adapter_get_sx_instances(
205  GNC_SX_LIST_TREE_MODEL_ADAPTER(priv->tree_model), &iter)->sx;
206 }
GtkTreeViewColumn * gnc_tree_view_add_text_column(GncTreeView *view, const gchar *column_title, const gchar *pref_name, const gchar *stock_icon_name, const gchar *sizing_text, gint model_data_column, gint model_visibility_column, GtkTreeIterCompareFunc column_sort_fn)
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)
void gnc_tree_view_configure_columns(GncTreeView *view)
#define gnc_leave_return_if_fail(test)
Definition: qoflog.h:289
const gchar * QofLogModule
Definition: qofid.h:89