diff options
author | Jeffrey Stedfast <fejj@ximian.com> | 2002-11-02 07:22:57 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2002-11-02 07:22:57 +0800 |
commit | e033f54a9044a4288c923e9b2c6d9477da076d26 (patch) | |
tree | e49c07744c18ba0663e15418843a5cc8e6485842 /filter/filter-datespec.c | |
parent | 9bfc63718a9752a4e55cf03f5440dd82df63a758 (diff) | |
download | gsoc2013-evolution-e033f54a9044a4288c923e9b2c6d9477da076d26.tar.gz gsoc2013-evolution-e033f54a9044a4288c923e9b2c6d9477da076d26.tar.zst gsoc2013-evolution-e033f54a9044a4288c923e9b2c6d9477da076d26.zip |
Ported to GObject.
2002-11-01 Jeffrey Stedfast <fejj@ximian.com>
* filter-element.c: Ported to GObject.
* filter-input.c: Same.
* filter-code.c: This too.
* filter-colour.c: And this.
* filter-datespec.c: You guessed it.
* filter-file.c: And again...
svn path=/trunk/; revision=18493
Diffstat (limited to 'filter/filter-datespec.c')
-rw-r--r-- | filter/filter-datespec.c | 176 |
1 files changed, 92 insertions, 84 deletions
diff --git a/filter/filter-datespec.c b/filter/filter-datespec.c index 9ee3b3e2a6..a0ac318f6f 100644 --- a/filter/filter-datespec.c +++ b/filter/filter-datespec.c @@ -1,7 +1,9 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ /* - * Copyright (C) 2000 Ximian Inc. + * Copyright (C) 2000-2002 Ximian Inc. * * Authors: Not Zed <notzed@lostzed.mmc.com.au> + * Jeffrey Stedfast <fejj@ximian.com> * * This program is free software; you can redistribute it and/or * modify it under the terms of version 2 of the GNU General Public @@ -18,7 +20,10 @@ * Boston, MA 02111-1307, USA. */ + +#ifdef HAVE_CONFIG_H #include <config.h> +#endif #include <string.h> #include <stdlib.h> @@ -45,7 +50,7 @@ #define d(x) static gboolean validate (FilterElement *fe); -static int date_eq(FilterElement *fe, FilterElement *cm); +static int date_eq (FilterElement *fe, FilterElement *cm); static void xml_create (FilterElement *fe, xmlNodePtr node); static xmlNodePtr xml_encode (FilterElement *fe); static int xml_decode (FilterElement *fe, xmlNodePtr node); @@ -53,17 +58,17 @@ static GtkWidget *get_widget (FilterElement *fe); static void build_code (FilterElement *fe, GString *out, struct _FilterPart *fds); static void format_sexp (FilterElement *, GString *); -static void filter_datespec_class_init (FilterDatespecClass *class); -static void filter_datespec_init (FilterDatespec *gspaper); -static void filter_datespec_finalise (GtkObject *obj); +static void filter_datespec_class_init (FilterDatespecClass *klass); +static void filter_datespec_init (FilterDatespec *fd); +static void filter_datespec_finalise (GObject *obj); #define PRIV(x) (((FilterDatespec *)(x))->priv) typedef struct _timespan { guint32 seconds; - const gchar *singular; - const gchar *plural; - gfloat max; + const char *singular; + const char *plural; + float max; } timespan; static const timespan timespans[] = { @@ -88,65 +93,66 @@ struct _FilterDatespecPrivate { static FilterElementClass *parent_class; -guint +GType filter_datespec_get_type (void) { - static guint type = 0; + static GType type = 0; if (!type) { - GtkTypeInfo type_info = { - "FilterDatespec", - sizeof (FilterDatespec), + static const GTypeInfo info = { sizeof (FilterDatespecClass), - (GtkClassInitFunc) filter_datespec_class_init, - (GtkObjectInitFunc) filter_datespec_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL + NULL, /* base_class_init */ + NULL, /* base_class_finalize */ + (GClassInitFunc) filter_datespec_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (FilterDatespec), + 0, /* n_preallocs */ + (GInstanceInitFunc) filter_datespec_init, }; - type = gtk_type_unique (filter_element_get_type (), &type_info); + type = g_type_register_static (FILTER_TYPE_ELEMENT, "FilterDatespec", &info, 0); } return type; } static void -filter_datespec_class_init (FilterDatespecClass *class) +filter_datespec_class_init (FilterDatespecClass *klass) { - GtkObjectClass *object_class; - FilterElementClass *filter_element = (FilterElementClass *)class; + GObjectClass *object_class = G_OBJECT_CLASS (klass); + FilterElementClass *fe_class = FILTER_ELEMENT_CLASS (klass); - object_class = (GtkObjectClass *)class; - parent_class = gtk_type_class (filter_element_get_type ()); + parent_class = g_type_class_ref (FILTER_TYPE_ELEMENT); object_class->finalize = filter_datespec_finalise; /* override methods */ - filter_element->validate = validate; - filter_element->eq = date_eq; - filter_element->xml_create = xml_create; - filter_element->xml_encode = xml_encode; - filter_element->xml_decode = xml_decode; - filter_element->get_widget = get_widget; - filter_element->build_code = build_code; - filter_element->format_sexp = format_sexp; + fe_class->validate = validate; + fe_class->eq = date_eq; + fe_class->xml_create = xml_create; + fe_class->xml_encode = xml_encode; + fe_class->xml_decode = xml_decode; + fe_class->get_widget = get_widget; + fe_class->build_code = build_code; + fe_class->format_sexp = format_sexp; } static void -filter_datespec_init (FilterDatespec *o) +filter_datespec_init (FilterDatespec *fd) { - o->priv = g_malloc0 (sizeof (*o->priv)); - o->type = FDST_UNKNOWN; + fd->priv = g_malloc0 (sizeof (*fd->priv)); + fd->type = FDST_UNKNOWN; } static void -filter_datespec_finalise(GtkObject *obj) +filter_datespec_finalise (GtkObject *obj) { - FilterDatespec *o = (FilterDatespec *)obj; + FilterDatespec *fd = (FilterDatespec *) obj; - g_free (o->priv); + g_free (fd->priv); - ((GtkObjectClass *)(parent_class))->finalize(obj); + G_OBJECT_CLASS (parent_class)->finalize (obj); } /** @@ -159,8 +165,7 @@ filter_datespec_finalise(GtkObject *obj) FilterDatespec * filter_datespec_new (void) { - FilterDatespec *o = (FilterDatespec *)gtk_type_new (filter_datespec_get_type ()); - return o; + return (FilterDatespec *) g_object_new (FILTER_TYPE_DATESPEC, NULL, NULL); } static gboolean @@ -179,11 +184,11 @@ validate (FilterElement *fe) } static int -date_eq(FilterElement *fe, FilterElement *cm) +date_eq (FilterElement *fe, FilterElement *cm) { FilterDatespec *fd = (FilterDatespec *)fe, *cd = (FilterDatespec *)cm; - - return ((FilterElementClass *)(parent_class))->eq(fe, cm) + + return FILTER_ELEMENT_CLASS (parent_class)->eq(fe, cm) && (fd->type == cd->type) && (fd->value == cd->value); } @@ -192,7 +197,7 @@ static void xml_create (FilterElement *fe, xmlNodePtr node) { /* parent implementation */ - ((FilterElementClass *)(parent_class))->xml_create(fe, node); + FILTER_ELEMENT_CLASS (parent_class)->xml_create (fe, node); } static xmlNodePtr @@ -200,7 +205,7 @@ xml_encode (FilterElement *fe) { xmlNodePtr value, work; FilterDatespec *fds = (FilterDatespec *)fe; - gchar str[32]; + char str[32]; d(printf ("Encoding datespec as xml\n")); @@ -222,7 +227,7 @@ xml_decode (FilterElement *fe, xmlNodePtr node) { FilterDatespec *fds = (FilterDatespec *)fe; xmlNodePtr n; - gchar *val; + char *val; d(printf ("Decoding datespec from xml %p\n", fe)); @@ -242,28 +247,30 @@ xml_decode (FilterElement *fe, xmlNodePtr node) } n = n->next; } + return 0; } -static int get_best_span(time_t val) +static int +get_best_span (time_t val) { int i; - + for (i=N_TIMESPANS-1;i>=0;i--) { if (val % timespans[i].seconds == 0) return i; } - + return 0; } /* sets button label */ static void -set_button(FilterDatespec *fds) +set_button (FilterDatespec *fds) { char buf[128]; char *label = buf; - + switch (fds->type) { case FDST_UNKNOWN: label = _("<click here to select a date>"); @@ -273,7 +280,7 @@ set_button(FilterDatespec *fds) break; case FDST_SPECIFIED: { struct tm tm; - + localtime_r(&fds->value, &tm); /* strftime for date filter display, only needs to show a day date (i.e. no time) */ strftime(buf, sizeof(buf), _("%d-%b-%Y"), &tm); @@ -283,10 +290,10 @@ set_button(FilterDatespec *fds) label = _("now"); else { int span, count; - + span = get_best_span(fds->value); count = fds->value / timespans[span].seconds; - + if (count == 1) /* 1 (minute|day|...) ago (singular time ago) */ sprintf(buf, _("%d %s ago"), count, timespans[span].singular); @@ -296,20 +303,20 @@ set_button(FilterDatespec *fds) } break; } - + gtk_label_set_text((GtkLabel *)fds->priv->label_button, label); } static void -get_values(FilterDatespec *fds) +get_values (FilterDatespec *fds) { struct _FilterDatespecPrivate *p = PRIV(fds); - + switch(fds->priv->type) { case FDST_SPECIFIED: { guint year, month, day; struct tm tm; - + gtk_calendar_get_date((GtkCalendar *)p->calendar_specify, &year, &month, &day); memset(&tm, 0, sizeof(tm)); tm.tm_mday = day; @@ -320,7 +327,7 @@ get_values(FilterDatespec *fds) break; } case FDST_X_AGO: { int val; - + val = gtk_spin_button_get_value_as_int((GtkSpinButton *)p->spin_relative); fds->value = timespans[p->span].seconds * val; break; } @@ -328,43 +335,45 @@ get_values(FilterDatespec *fds) default: break; } - + fds->type = p->type; } static void -set_values(FilterDatespec *fds) +set_values (FilterDatespec *fds) { struct _FilterDatespecPrivate *p = PRIV(fds); - + p->type = fds->type==FDST_UNKNOWN ? FDST_NOW : fds->type; - + switch (p->type) { case FDST_NOW: case FDST_UNKNOWN: /* noop */ break; - case FDST_SPECIFIED: { + case FDST_SPECIFIED: + { struct tm tm; - + localtime_r(&fds->value, &tm); gtk_calendar_select_month((GtkCalendar*)p->calendar_specify, tm.tm_mon, tm.tm_year + 1900); gtk_calendar_select_day((GtkCalendar*)p->calendar_specify, tm.tm_mday); - break; } + break; + } case FDST_X_AGO: p->span = get_best_span(fds->value); gtk_spin_button_set_value((GtkSpinButton*)p->spin_relative, fds->value/timespans[p->span].seconds); gtk_option_menu_set_history((GtkOptionMenu*)p->option_relative, p->span); break; } - + gtk_notebook_set_page((GtkNotebook*)p->notebook_type, p->type); gtk_option_menu_set_history((GtkOptionMenu*)p->option_type, p->type); } static void -set_option_type(GtkMenu *menu, FilterDatespec *fds) +set_option_type (GtkMenu *menu, FilterDatespec *fds) { GtkWidget *w; @@ -375,10 +384,10 @@ set_option_type(GtkMenu *menu, FilterDatespec *fds) } static void -set_option_relative(GtkMenu *menu, FilterDatespec *fds) +set_option_relative (GtkMenu *menu, FilterDatespec *fds) { GtkWidget *w; - + w = gtk_menu_get_active(menu); fds->priv->span = g_list_index(GTK_MENU_SHELL(menu)->children, w); } @@ -388,7 +397,7 @@ dialogue_clicked(GnomeDialog *gd, int button, FilterDatespec *fds) { if (button != 0) return; - + get_values(fds); set_button(fds); } @@ -400,33 +409,31 @@ button_clicked (GtkButton *button, FilterDatespec *fds) struct _FilterDatespecPrivate *p = PRIV(fds); GtkWidget *w, *x; GladeXML *gui; - + gui = glade_xml_new(FILTER_GLADEDIR "/filter.glade", "filter_datespec"); w = glade_xml_get_widget(gui, "filter_datespec"); - + gd = (GnomeDialog *) gnome_dialog_new (_("Select a time to compare against"), GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); - + p->notebook_type = glade_xml_get_widget(gui, "notebook_type"); p->option_type = glade_xml_get_widget(gui, "option_type"); p->calendar_specify = glade_xml_get_widget(gui, "calendar_specify"); p->spin_relative = glade_xml_get_widget(gui, "spin_relative"); p->option_relative = glade_xml_get_widget(gui, "option_relative"); - + set_values(fds); - - gtk_signal_connect((GtkObject *)GTK_OPTION_MENU(p->option_type)->menu, "deactivate", set_option_type, fds); - gtk_signal_connect((GtkObject *)GTK_OPTION_MENU(p->option_relative)->menu, "deactivate", set_option_relative, fds); - + + g_signal_connect (GTK_OPTION_MENU (p->option_type)->menu, "deactivate", set_option_type, fds); + g_signal_connect (GTK_OPTION_MENU (p->option_relative)->menu, "deactivate", set_option_relative, fds); + gtk_box_pack_start ((GtkBox *)gd->vbox, w, TRUE, TRUE, 3); - - gtk_signal_connect((GtkObject *)gd, "clicked", dialogue_clicked, fds); - + + g_signal_connect (gd, "clicked", dialogue_clicked, fds); + gnome_dialog_run_and_close(gd); - - return; } static GtkWidget * @@ -445,6 +452,7 @@ get_widget (FilterElement *fe) gtk_widget_show (button); gtk_widget_show (fds->priv->label_button); + return button; } |