GnuCash c935c2f+
Loading...
Searching...
No Matches
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 gnu@gnu.org
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. */
37static QofLogModule log_module = G_LOG_DOMAIN;
38
39typedef struct _DaterangeInfo DaterangeInfo;
40
41void 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
51gboolean
52gnc_ab_enter_daterange(GtkWidget *parent,
53 const char *heading,
54 time64 *from_date,
55 gboolean *last_retv_date,
56 gboolean *first_possible_date,
57 time64 *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", "aqbanking_date_range_dialog");
73
74 dialog = GTK_WIDGET(gtk_builder_get_object (builder, "aqbanking_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, "date_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 (*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 (*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(GNC_DATE_EDIT(info.from_dateedit));
126 *last_retv_date = gtk_toggle_button_get_active(
127 GTK_TOGGLE_BUTTON(last_retrieval_button));
128 *first_possible_date = gtk_toggle_button_get_active(
129 GTK_TOGGLE_BUTTON(first_button));
130 *to_date = gnc_date_edit_get_date (GNC_DATE_EDIT(info.to_dateedit));
131 *to_now = gtk_toggle_button_get_active(
132 GTK_TOGGLE_BUTTON(now_button));
133 }
134
135 g_object_unref(G_OBJECT(builder));
136
137 gtk_widget_destroy(dialog);
138
139 LEAVE("");
140 return result == GTK_RESPONSE_OK;
141}
142
143void
144ddr_toggled_cb(GtkToggleButton *button, gpointer user_data)
145{
146 DaterangeInfo *info = user_data;
147
148 g_return_if_fail(info);
149
150 gtk_widget_set_sensitive(info->from_dateedit,
151 gtk_toggle_button_get_active(
152 GTK_TOGGLE_BUTTON(info->enter_from_button)));
153 gtk_widget_set_sensitive(info->to_dateedit,
154 gtk_toggle_button_get_active(
155 GTK_TOGGLE_BUTTON(info->enter_to_button)));
156}
gboolean gnc_ab_enter_daterange(GtkWidget *parent, const char *heading, time64 *from_date, gboolean *last_retv_date, gboolean *first_possible_date, time64 *to_date, gboolean *to_now)
Show a dialog to pick a time frame using a sensible set of default options.
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
Definition gnc-date.h:87
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272