mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Refactor: remove unused GncRecurrenceComp
This commit is contained in:
parent
fa3043a631
commit
4191c6a859
@ -374,202 +374,4 @@ gnc_recurrence_new()
|
|||||||
return GTK_WIDGET(gr);
|
return GTK_WIDGET(gr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* TODO: Maybe this stuff should go into another file.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
struct _GncRecurrenceComp
|
|
||||||
{
|
|
||||||
GtkScrolledWindow widget;
|
|
||||||
|
|
||||||
GtkWidget *vbox;
|
|
||||||
GtkWidget *hbox;
|
|
||||||
GtkWidget *hbb;
|
|
||||||
gint num_rec;
|
|
||||||
GtkButton *buttRemove;
|
|
||||||
GtkButton *buttAdd;
|
|
||||||
|
|
||||||
GList *rlist;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GtkScrolledWindowClass parent_class;
|
|
||||||
void (*changed) (GncRecurrenceComp *gr);
|
|
||||||
} GncRecurrenceCompClass;
|
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
|
||||||
{
|
|
||||||
GNCRECURRENCECOMP_CHANGED,
|
|
||||||
GNCRC_LAST_SIGNAL
|
|
||||||
} GNCRC_Signals;
|
|
||||||
|
|
||||||
|
|
||||||
static void grc_changed(GtkWidget *w, gpointer data)
|
|
||||||
{
|
|
||||||
g_signal_emit_by_name(data, "changed");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void addRecurrence(GncRecurrenceComp *grc, GncRecurrence *gr)
|
|
||||||
{
|
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(grc->vbox), GTK_WIDGET(gr),
|
|
||||||
FALSE, FALSE, 3);
|
|
||||||
g_signal_connect( G_OBJECT(gr), "changed",
|
|
||||||
G_CALLBACK(grc_changed), grc );
|
|
||||||
grc->num_rec++;
|
|
||||||
|
|
||||||
gtk_widget_set_sensitive(GTK_WIDGET(grc->buttRemove), (grc->num_rec > 1));
|
|
||||||
g_signal_emit_by_name(G_OBJECT(grc), "changed");
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void removeRecurrence(GncRecurrenceComp *grc)
|
|
||||||
{
|
|
||||||
GList *children, *last;
|
|
||||||
|
|
||||||
grc->num_rec--;
|
|
||||||
|
|
||||||
children = gtk_container_get_children(GTK_CONTAINER(grc->vbox));
|
|
||||||
last = g_list_last(children);
|
|
||||||
gtk_widget_destroy(GTK_WIDGET(last->data));
|
|
||||||
g_list_free(children);
|
|
||||||
g_signal_emit_by_name(G_OBJECT(grc), "changed");
|
|
||||||
|
|
||||||
|
|
||||||
gtk_widget_set_sensitive(GTK_WIDGET(grc->buttRemove), (grc->num_rec > 1));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void addClicked(GtkButton *b, gpointer data)
|
|
||||||
{
|
|
||||||
GncRecurrenceComp *grc = data;
|
|
||||||
GncRecurrence *gr;
|
|
||||||
|
|
||||||
gr = GNC_RECURRENCE(gnc_recurrence_new());
|
|
||||||
addRecurrence(grc, gr);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void removeClicked(GtkButton *b, gpointer data)
|
|
||||||
{
|
|
||||||
GncRecurrenceComp *grc = data;
|
|
||||||
|
|
||||||
if (grc->num_rec > 1)
|
|
||||||
removeRecurrence(grc);
|
|
||||||
}
|
|
||||||
|
|
||||||
G_DEFINE_TYPE (GncRecurrenceComp, gnc_recurrence_comp, GTK_TYPE_SCROLLED_WINDOW)
|
|
||||||
|
|
||||||
void
|
|
||||||
gnc_recurrence_comp_set_list(GncRecurrenceComp *grc, const GList *rlist)
|
|
||||||
{
|
|
||||||
const GList *iter;
|
|
||||||
|
|
||||||
g_return_if_fail(grc);
|
|
||||||
|
|
||||||
while (grc->num_rec > 0)
|
|
||||||
removeRecurrence(grc);
|
|
||||||
|
|
||||||
for (iter = rlist; iter; iter = iter->next)
|
|
||||||
{
|
|
||||||
GncRecurrence *gr = GNC_RECURRENCE(gnc_recurrence_new());
|
|
||||||
|
|
||||||
gnc_recurrence_set(gr, (Recurrence *)iter->data);
|
|
||||||
addRecurrence(grc, gr);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
GList *
|
|
||||||
gnc_recurrence_comp_get_list(GncRecurrenceComp *grc)
|
|
||||||
{
|
|
||||||
GList *rlist = NULL, *children;
|
|
||||||
|
|
||||||
children = gtk_container_get_children(GTK_CONTAINER(grc->vbox));
|
|
||||||
for (GList *n = children; n; n = n->next)
|
|
||||||
{
|
|
||||||
const Recurrence *r = gnc_recurrence_get (GNC_RECURRENCE (n->data));
|
|
||||||
rlist = g_list_prepend (rlist, (gpointer)r);
|
|
||||||
}
|
|
||||||
g_list_free(children);
|
|
||||||
return g_list_reverse (rlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_recurrence_comp_init(GncRecurrenceComp *grc)
|
|
||||||
{
|
|
||||||
GtkWidget *vb;
|
|
||||||
|
|
||||||
gtk_orientable_set_orientation (GTK_ORIENTABLE(grc), GTK_ORIENTATION_VERTICAL);
|
|
||||||
|
|
||||||
grc->hbb = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
|
|
||||||
grc->vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
|
|
||||||
gtk_box_set_homogeneous (GTK_BOX (grc->vbox), FALSE);
|
|
||||||
grc->rlist = NULL;
|
|
||||||
|
|
||||||
grc->buttAdd = GTK_BUTTON(gtk_button_new_with_mnemonic(_("_Add")));
|
|
||||||
g_signal_connect(G_OBJECT(grc->buttAdd), "clicked",
|
|
||||||
G_CALLBACK(addClicked), grc);
|
|
||||||
grc->buttRemove = GTK_BUTTON(gtk_button_new_with_mnemonic(_("_Remove")));
|
|
||||||
g_signal_connect(G_OBJECT(grc->buttRemove), "clicked",
|
|
||||||
G_CALLBACK(removeClicked), grc);
|
|
||||||
|
|
||||||
gtk_box_pack_start(GTK_BOX(grc->hbb), GTK_WIDGET(grc->buttAdd),
|
|
||||||
FALSE, FALSE, 3);
|
|
||||||
gtk_box_pack_start(GTK_BOX(grc->hbb), GTK_WIDGET(grc->buttRemove),
|
|
||||||
FALSE, FALSE, 3);
|
|
||||||
|
|
||||||
vb = gtk_box_new (GTK_ORIENTATION_VERTICAL, 1);
|
|
||||||
gtk_box_set_homogeneous (GTK_BOX (vb), FALSE);
|
|
||||||
gtk_box_pack_start(GTK_BOX(vb), GTK_WIDGET(grc->hbb),
|
|
||||||
FALSE, FALSE, 3);
|
|
||||||
gtk_box_pack_start(GTK_BOX(vb), GTK_WIDGET(grc->vbox),
|
|
||||||
FALSE, FALSE, 3);
|
|
||||||
|
|
||||||
gtk_container_add (GTK_CONTAINER(grc), GTK_WIDGET(vb));
|
|
||||||
|
|
||||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(grc),
|
|
||||||
GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC);
|
|
||||||
|
|
||||||
grc->num_rec = 0;
|
|
||||||
gtk_widget_show_all(GTK_WIDGET(grc));
|
|
||||||
addClicked(NULL, grc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_recurrence_comp_class_init( GncRecurrenceCompClass *klass )
|
|
||||||
{
|
|
||||||
GObjectClass *object_class;
|
|
||||||
|
|
||||||
object_class = G_OBJECT_CLASS (klass);
|
|
||||||
g_signal_new ("changed",
|
|
||||||
G_OBJECT_CLASS_TYPE (object_class),
|
|
||||||
G_SIGNAL_RUN_FIRST,
|
|
||||||
G_STRUCT_OFFSET (GncRecurrenceCompClass, changed),
|
|
||||||
NULL,
|
|
||||||
NULL,
|
|
||||||
g_cclosure_marshal_VOID__VOID,
|
|
||||||
G_TYPE_NONE,
|
|
||||||
0);
|
|
||||||
|
|
||||||
//object_class->finalize = gnc_recurrence_finalize;
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkWidget *
|
|
||||||
gnc_recurrence_comp_new()
|
|
||||||
{
|
|
||||||
GncRecurrenceComp *grc;
|
|
||||||
grc = g_object_new(gnc_recurrence_comp_get_type(), NULL);
|
|
||||||
return GTK_WIDGET(grc);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* ========================= END OF FILE =========================== */
|
/* ========================= END OF FILE =========================== */
|
||||||
|
@ -41,7 +41,6 @@
|
|||||||
(obj, GNC_TYPE_RECURRENCE)
|
(obj, GNC_TYPE_RECURRENCE)
|
||||||
|
|
||||||
typedef struct _GncRecurrence GncRecurrence;
|
typedef struct _GncRecurrence GncRecurrence;
|
||||||
typedef struct _GncRecurrenceComp GncRecurrenceComp;
|
|
||||||
|
|
||||||
GType gnc_recurrence_get_type(void);
|
GType gnc_recurrence_get_type(void);
|
||||||
GtkWidget * gnc_recurrence_new(void);
|
GtkWidget * gnc_recurrence_new(void);
|
||||||
@ -52,15 +51,4 @@ void gnc_recurrence_set(GncRecurrence *gr, const Recurrence *r);
|
|||||||
long as the GncRecurrence is around. */
|
long as the GncRecurrence is around. */
|
||||||
const Recurrence * gnc_recurrence_get(GncRecurrence *gr);
|
const Recurrence * gnc_recurrence_get(GncRecurrence *gr);
|
||||||
|
|
||||||
/* "composite" recurrences */
|
|
||||||
void gnc_recurrence_comp_set_list(GncRecurrenceComp *grc, const GList *r);
|
|
||||||
|
|
||||||
/* The GList is newly-allocated, but the Recurrences are internally
|
|
||||||
owned. */
|
|
||||||
GList * gnc_recurrence_comp_get_list(GncRecurrenceComp *grc);
|
|
||||||
|
|
||||||
/* This works, but is not used. Kind of experimental... */
|
|
||||||
GtkWidget * gnc_recurrence_comp_new(void);
|
|
||||||
GType gnc_recurrence_comp_get_type(void);
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -9,11 +9,7 @@ set(GNOME_UTILS_GUI_TEST_LIBS
|
|||||||
test-core
|
test-core
|
||||||
gnc-gnome-utils
|
gnc-gnome-utils
|
||||||
)
|
)
|
||||||
#This is a GUI test
|
|
||||||
#gnc_add_test(test-gnc-recurrence test-gnc-recurrence.c
|
|
||||||
# GNOME_UTILS_GUI_TEST_INCLUDE_DIRS
|
|
||||||
# GNOME_UTILS_GUI_TEST_LIBS
|
|
||||||
#
|
|
||||||
set(GUILE_DEPENDS
|
set(GUILE_DEPENDS
|
||||||
scm-gnome-utils
|
scm-gnome-utils
|
||||||
test-core
|
test-core
|
||||||
|
@ -1,126 +0,0 @@
|
|||||||
/********************************************************************\
|
|
||||||
* Copyright (C) 2005, Chris Shoemaker <c.shoemaker@cox.net> *
|
|
||||||
* This program is free software; you can redistribute it and/or *
|
|
||||||
* modify it under the terms of the GNU General Public License as *
|
|
||||||
* published by the Free Software Foundation; either version 2 of *
|
|
||||||
* the License, or (at your option) any later version. *
|
|
||||||
* *
|
|
||||||
* This program is distributed in the hope that it will be useful, *
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
|
||||||
* GNU General Public License for more details. *
|
|
||||||
* *
|
|
||||||
* You should have received a copy of the GNU General Public License*
|
|
||||||
* along with this program; if not, contact: *
|
|
||||||
* *
|
|
||||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
|
||||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
|
||||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
|
||||||
* *
|
|
||||||
\********************************************************************/
|
|
||||||
|
|
||||||
|
|
||||||
/* test-gnc-recurrence.c:
|
|
||||||
*
|
|
||||||
* When you close the window, a text description of the
|
|
||||||
* recurrence is printed.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
#include <glib.h>
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include <stdio.h>
|
|
||||||
#include "gnc-recurrence.h"
|
|
||||||
#include "Recurrence.h"
|
|
||||||
|
|
||||||
static GtkWidget * mainwin;
|
|
||||||
static GncRecurrence *rw;
|
|
||||||
static GncRecurrenceComp *grc;
|
|
||||||
|
|
||||||
static void get_list(GtkWidget *w)
|
|
||||||
{
|
|
||||||
gchar *s;
|
|
||||||
GList *rlist;
|
|
||||||
rlist = gnc_recurrence_comp_get_list(grc);
|
|
||||||
s = recurrenceListToString(rlist);
|
|
||||||
printf("%s\n", s);
|
|
||||||
|
|
||||||
g_free(s);
|
|
||||||
g_list_free(rlist);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void changed(GtkWidget *widget)
|
|
||||||
{
|
|
||||||
gchar *s;
|
|
||||||
const Recurrence *r;
|
|
||||||
|
|
||||||
r = gnc_recurrence_get(rw);
|
|
||||||
s = recurrenceToString(r);
|
|
||||||
printf("%s\n", s);
|
|
||||||
g_free(s);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void die(GtkWidget *widget)
|
|
||||||
{
|
|
||||||
gtk_main_quit();
|
|
||||||
}
|
|
||||||
|
|
||||||
static void show_gnc_recurrence()
|
|
||||||
{
|
|
||||||
GDate d;
|
|
||||||
Recurrence *r;
|
|
||||||
GList *rl = NULL;
|
|
||||||
|
|
||||||
rw = GNC_RECURRENCE(gnc_recurrence_new());
|
|
||||||
|
|
||||||
r = g_new(Recurrence, 1);
|
|
||||||
rl = g_list_append(rl, r);
|
|
||||||
g_date_set_dmy(&d, 17, 4, 2005);
|
|
||||||
recurrenceSet(r, 1, PERIOD_WEEK, &d, WEEKEND_ADJ_NONE);
|
|
||||||
|
|
||||||
gnc_recurrence_set(rw, r);
|
|
||||||
g_free(r);
|
|
||||||
|
|
||||||
gtk_container_add(GTK_CONTAINER(mainwin), GTK_WIDGET(rw));
|
|
||||||
g_signal_connect(rw, "changed", G_CALLBACK(changed), NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void show_gnc_recurrence_comp()
|
|
||||||
{
|
|
||||||
GList *rlist = NULL;
|
|
||||||
Recurrence r[2];
|
|
||||||
|
|
||||||
grc = (GncRecurrenceComp *)gnc_recurrence_comp_new();
|
|
||||||
|
|
||||||
gtk_container_add(GTK_CONTAINER(mainwin), GTK_WIDGET(grc));
|
|
||||||
|
|
||||||
recurrenceSet(&r[0], 1, PERIOD_MONTH, NULL, WEEKEND_ADJ_NONE);
|
|
||||||
rlist = g_list_append(rlist, &r[0]);
|
|
||||||
recurrenceSet(&r[1], 1, PERIOD_YEAR, NULL, WEEKEND_ADJ_NONE);
|
|
||||||
rlist = g_list_append(rlist, &r[1]);
|
|
||||||
|
|
||||||
gnc_recurrence_comp_set_list(grc, rlist);
|
|
||||||
g_list_free(rlist);
|
|
||||||
|
|
||||||
g_signal_connect(grc, "changed", G_CALLBACK(get_list), NULL);
|
|
||||||
//rlist = gnc_recurrence_comp_get_list(grc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
int main (int argc, char ** argv)
|
|
||||||
{
|
|
||||||
gtk_init(&argc, &argv);
|
|
||||||
|
|
||||||
mainwin = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
|
||||||
g_signal_connect(mainwin, "delete-event", G_CALLBACK(die), NULL);
|
|
||||||
|
|
||||||
if (argc > 1)
|
|
||||||
show_gnc_recurrence();
|
|
||||||
else
|
|
||||||
show_gnc_recurrence_comp();
|
|
||||||
|
|
||||||
gtk_widget_show_all(mainwin);
|
|
||||||
gtk_main();
|
|
||||||
return 0;
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user