GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
dialog-ab-daterange.c
1 /*
2  * dialog-ab-daterange.c --
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, contact:
16  *
17  * Free Software Foundation Voice: +1-617-542-5942
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
19  * Boston, MA 02110-1301, USA [email protected]
20  */
21 
30 #include "config.h"
31 
32 #include "dialog-ab-daterange.h"
33 #include "dialog-utils.h"
34 #include "gnc-date-edit.h"
35 
36 /* This static indicates the debugging module that this .o belongs to. */
37 static QofLogModule log_module = G_LOG_DOMAIN;
38 
39 typedef struct _DaterangeInfo DaterangeInfo;
40 
41 void ddr_toggled_cb(GtkToggleButton *button, gpointer user_data);
42 
44 {
45  GtkWidget *enter_from_button;
46  GtkWidget *enter_to_button;
47  GtkWidget *from_dateedit;
48  GtkWidget *to_dateedit;
49 };
50 
51 gboolean
52 gnc_ab_enter_daterange(GtkWidget *parent,
53  const char *heading,
54  Timespec *from_date,
55  gboolean *last_retv_date,
56  gboolean *first_possible_date,
57  Timespec *to_date,
58  gboolean *to_now)
59 {
60  GtkBuilder *builder;
61  GtkWidget *dialog;
62  GtkWidget *heading_label;
63  GtkWidget *first_button;
64  GtkWidget *last_retrieval_button;
65  GtkWidget *now_button;
66  DaterangeInfo info;
67  gint result;
68 
69  ENTER("");
70 
71  builder = gtk_builder_new();
72  gnc_builder_add_from_file (builder, "dialog-ab.glade", "Date Range Dialog");
73 
74  dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Date Range Dialog"));
75 
76  /* Connect the signals */
77  gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, &info );
78 
79  if (parent)
80  gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
81 
82  heading_label = GTK_WIDGET(gtk_builder_get_object (builder, "heading_label"));
83  first_button = GTK_WIDGET(gtk_builder_get_object (builder, "first_button"));
84  last_retrieval_button = GTK_WIDGET(gtk_builder_get_object (builder, "last_retrieval_button"));
85  info.enter_from_button = GTK_WIDGET(gtk_builder_get_object (builder, "enter_from_button"));
86  now_button = GTK_WIDGET(gtk_builder_get_object (builder, "now_button"));
87  info.enter_to_button = GTK_WIDGET(gtk_builder_get_object (builder, "enter_to_button"));
88 
89  info.from_dateedit = gnc_date_edit_new_ts(*from_date, FALSE, FALSE);
90  gtk_container_add(GTK_CONTAINER(gtk_builder_get_object (builder, "enter_from_box")),
91  info.from_dateedit);
92  gtk_widget_show(info.from_dateedit);
93 
94  info.to_dateedit = gnc_date_edit_new_ts(*to_date, FALSE, FALSE);
95  gtk_container_add(GTK_CONTAINER(gtk_builder_get_object (builder, "enter_to_box")),
96  info.to_dateedit);
97  gtk_widget_show(info.to_dateedit);
98 
99  if (*last_retv_date)
100  {
101  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(last_retrieval_button),
102  TRUE);
103  }
104  else
105  {
106  gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(first_button), TRUE);
107  gtk_widget_set_sensitive(last_retrieval_button, FALSE);
108  }
109 
110  gtk_widget_set_sensitive(info.from_dateedit, FALSE);
111  gtk_widget_set_sensitive(info.to_dateedit, FALSE);
112 
113  gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
114 
115  if (heading)
116  gtk_label_set_text(GTK_LABEL(heading_label), heading);
117 
118  gtk_widget_show(dialog);
119 
120  result = gtk_dialog_run(GTK_DIALOG(dialog));
121  gtk_widget_hide(dialog);
122 
123  if (result == GTK_RESPONSE_OK)
124  {
125  *from_date = gnc_date_edit_get_date_ts(
126  GNC_DATE_EDIT(info.from_dateedit));
127  *last_retv_date = gtk_toggle_button_get_active(
128  GTK_TOGGLE_BUTTON(last_retrieval_button));
129  *first_possible_date = gtk_toggle_button_get_active(
130  GTK_TOGGLE_BUTTON(first_button));
131  *to_date = gnc_date_edit_get_date_ts(
132  GNC_DATE_EDIT(info.to_dateedit));
133  *to_now = gtk_toggle_button_get_active(
134  GTK_TOGGLE_BUTTON(now_button));
135  }
136 
137  g_object_unref(G_OBJECT(builder));
138 
139  gtk_widget_destroy(dialog);
140 
141  LEAVE("");
142  return result == GTK_RESPONSE_OK;
143 }
144 
145 void
146 ddr_toggled_cb(GtkToggleButton *button, gpointer user_data)
147 {
148  DaterangeInfo *info = user_data;
149 
150  g_return_if_fail(info);
151 
152  gtk_widget_set_sensitive(info->from_dateedit,
153  gtk_toggle_button_get_active(
154  GTK_TOGGLE_BUTTON(info->enter_from_button)));
155  gtk_widget_set_sensitive(info->to_dateedit,
156  gtk_toggle_button_get_active(
157  GTK_TOGGLE_BUTTON(info->enter_to_button)));
158 }
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
Use a 64-bit unsigned int timespec.
Definition: gnc-date.h:299
#define ENTER(format, args...)
Definition: qoflog.h:261
gboolean gnc_ab_enter_daterange(GtkWidget *parent, const char *heading, Timespec *from_date, gboolean *last_retv_date, gboolean *first_possible_date, Timespec *to_date, gboolean *to_now)
#define LEAVE(format, args...)
Definition: qoflog.h:271
const gchar * QofLogModule
Definition: qofid.h:89