GnuCash 2.4.99
gnc-tree-view-sx-list.c
00001 
00005 /********************************************************************
00006  * This program is free software; you can redistribute it and/or    *
00007  * modify it under the terms of version 2 and/or version 3 of the GNU General Public *
00008  * License as published by the Free Software Foundation.            *
00009  *
00010  * As a special exception, permission is granted to link the binary
00011  * module resultant from this code with the OpenSSL project's
00012  * "OpenSSL" library (or modified versions of it that use the same
00013  * license as the "OpenSSL" library), and distribute the linked
00014  * executable.  You must obey the GNU General Public License in all
00015  * respects for all of the code used other than "OpenSSL". If you
00016  * modify this file, you may extend this exception to your version
00017  * of the file, but you are not obligated to do so. If you do not
00018  * wish to do so, delete this exception statement from your version
00019  * of this file.
00020  *                                                                  *
00021  * This program is distributed in the hope that it will be useful,  *
00022  * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
00023  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
00024  * GNU General Public License for more details.                     *
00025  *                                                                  *
00026  * You should have received a copy of the GNU General Public License*
00027  * along with this program; if not, contact:                        *
00028  *                                                                  *
00029  * Free Software Foundation           Voice:  +1-617-542-5942       *
00030  * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652       *
00031  * Boston, MA  02110-1301,  USA       gnu@gnu.org                   *
00032  *                                                                  *
00033  *******************************************************************/
00034 
00035 #include "config.h"
00036 
00037 #include <gtk/gtk.h>
00038 #include <glib/gi18n.h>
00039 #include <string.h>
00040 
00041 #include "gnc-tree-view.h"
00042 #include "gnc-tree-view-sx-list.h"
00043 #include "gnc-sx-list-tree-model-adapter.h"
00044 #include "gnc-gconf-utils.h"
00045 
00046 #define LOG_MOD "gnc.ui.tree-view.sx-list"
00047 static QofLogModule log_module = LOG_MOD;
00048 #undef G_LOG_DOMAIN
00049 #define G_LOG_DOMAIN LOG_MOD
00050 
00051 static void gnc_tree_view_sx_list_class_init(GncTreeViewSxListClass *klass);
00052 static void gnc_tree_view_sx_list_init(GncTreeViewSxList *view);
00053 static void gnc_tree_view_sx_list_dispose(GObject *object);
00054 static void gnc_tree_view_sx_list_finalize(GObject *object);
00055 
00056 typedef struct GncTreeViewSxListPrivate
00057 {
00058     GtkTreeModel *tree_model;
00059     gboolean disposed;
00060 } GncTreeViewSxListPrivate;
00061 
00062 #define GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(o)  \
00063    (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_VIEW_SX_LIST, GncTreeViewSxListPrivate))
00064 
00065 static GObjectClass *parent_class = NULL;
00066 
00067 GType
00068 gnc_tree_view_sx_list_get_type(void)
00069 {
00070     static GType gnc_tree_view_sx_list_type = 0;
00071 
00072     if (gnc_tree_view_sx_list_type == 0)
00073     {
00074         static const GTypeInfo our_info =
00075         {
00076             sizeof (GncTreeViewSxListClass),
00077             NULL,
00078             NULL,
00079             (GClassInitFunc) gnc_tree_view_sx_list_class_init,
00080             NULL,
00081             NULL,
00082             sizeof (GncTreeViewSxList),
00083             0,
00084             (GInstanceInitFunc) gnc_tree_view_sx_list_init
00085         };
00086 
00087         gnc_tree_view_sx_list_type = g_type_register_static (GNC_TYPE_TREE_VIEW,
00088                                      "GncTreeViewSxList",
00089                                      &our_info, 0);
00090     }
00091 
00092     return gnc_tree_view_sx_list_type;
00093 }
00094 
00095 static void
00096 gnc_tree_view_sx_list_class_init(GncTreeViewSxListClass *klass)
00097 {
00098     GObjectClass *o_class;
00099 
00100     parent_class = g_type_class_peek_parent (klass);
00101 
00102     o_class = G_OBJECT_CLASS (klass);
00103 
00104     o_class->dispose =  gnc_tree_view_sx_list_dispose;
00105     o_class->finalize = gnc_tree_view_sx_list_finalize;
00106 
00107     g_type_class_add_private(klass, sizeof(GncTreeViewSxListPrivate));
00108 }
00109 
00110 static void
00111 gnc_tree_view_sx_list_init (GncTreeViewSxList *view)
00112 {
00113     ; /* nop */
00114 }
00115 
00116 static void
00117 gnc_tree_view_sx_list_dispose(GObject *object)
00118 {
00119     GncTreeViewSxList *view;
00120     GncTreeViewSxListPrivate *priv;
00121 
00122     gnc_leave_return_if_fail (object != NULL);
00123     gnc_leave_return_if_fail (GNC_IS_TREE_VIEW_SX_LIST (object));
00124 
00125     view = GNC_TREE_VIEW_SX_LIST (object);
00126     priv = GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(view);
00127 
00128     if (priv->disposed)
00129         return;
00130     priv->disposed = TRUE;
00131 
00132     g_object_unref(G_OBJECT(priv->tree_model));
00133     priv->tree_model = NULL;
00134 
00135     if (G_OBJECT_CLASS (parent_class)->dispose)
00136         (* G_OBJECT_CLASS (parent_class)->dispose) (object);
00137 }
00138 
00139 static void
00140 gnc_tree_view_sx_list_finalize(GObject *object)
00141 {
00142     GncTreeViewSxList *view;
00143 
00144     gnc_leave_return_if_fail(object != NULL);
00145     gnc_leave_return_if_fail(GNC_IS_TREE_VIEW_SX_LIST (object));
00146 
00147     view = GNC_TREE_VIEW_SX_LIST(object);
00148 
00149     if (G_OBJECT_CLASS(parent_class)->finalize)
00150         (* G_OBJECT_CLASS(parent_class)->finalize) (object);
00151 }
00152 
00153 GtkTreeView*
00154 gnc_tree_view_sx_list_new(GncSxInstanceModel *sx_instances)
00155 {
00156     GncTreeView *view;
00157     GtkTreeViewColumn *col;
00158     GncTreeViewSxListPrivate *priv;
00159 
00160     view = (GncTreeView*)g_object_new(GNC_TYPE_TREE_VIEW_SX_LIST, NULL);
00161     g_object_set(view, "name", "sx_list_tree", NULL);
00162 
00163     priv = GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(view);
00164 
00165     priv->tree_model = GTK_TREE_MODEL(gnc_sx_list_tree_model_adapter_new(sx_instances));
00166     gnc_tree_view_set_model(view, GTK_TREE_MODEL(priv->tree_model));
00167 
00168     col = gnc_tree_view_add_text_column(view, _("Name"), "name", NULL,
00169                                         "Semi-Monthly Paycheck",
00170                                         SXLTMA_COL_NAME, -1, NULL);
00171     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00172 
00173     col = gnc_tree_view_add_toggle_column(view, _("Enabled"),
00174                                           /* Translators: This string has a context prefix; the translation
00175                                              must only contain the part after the | character. */
00176                                           Q_("Single-character short column-title form of 'Enabled'|E"),
00177                                           "enabled", SXLTMA_COL_ENABLED,
00178                                           GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
00179                                           NULL, NULL);
00180     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00181 
00182     col = gnc_tree_view_add_text_column(view, _("Frequency"), "frequency", NULL,
00183                                         "Weekly (x3): -------",
00184                                         SXLTMA_COL_FREQUENCY, -1, NULL);
00185     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00186 
00187     col = gnc_tree_view_add_text_column(view, _("Last Occur"), "last-occur", NULL,
00188                                         "2007-01-02",
00189                                         SXLTMA_COL_LAST_OCCUR, -1, NULL);
00190     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00191 
00192     col = gnc_tree_view_add_text_column(view, _("Next Occur"), "next-occur", NULL,
00193                                         "2007-01-02",
00194                                         SXLTMA_COL_NEXT_OCCUR, -1, NULL);
00195     g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
00196 
00197     gnc_tree_view_configure_columns(view);
00198 
00199     gtk_widget_show(GTK_WIDGET(view));
00200     return GTK_TREE_VIEW(view);
00201 }
00202 
00203 SchedXaction*
00204 gnc_tree_view_sx_list_get_sx_from_path(GncTreeViewSxList *view, GtkTreePath *path)
00205 {
00206     GtkTreeIter iter;
00207     GncTreeViewSxListPrivate *priv = GNC_TREE_VIEW_SX_LIST_GET_PRIVATE(view);
00208     gtk_tree_model_get_iter(GTK_TREE_MODEL(priv->tree_model), &iter, path);
00209     return gnc_sx_list_tree_model_adapter_get_sx_instances(
00210                GNC_SX_LIST_TREE_MODEL_ADAPTER(priv->tree_model), &iter)->sx;
00211 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines