|
GnuCash 2.4.99
|
00001 /* 00002 * dialog-ab-daterange.c -- 00003 * 00004 * This program is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU General Public License as 00006 * published by the Free Software Foundation; either version 2 of 00007 * the License, or (at your option) any later version. 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, contact: 00016 * 00017 * Free Software Foundation Voice: +1-617-542-5942 00018 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 00019 * Boston, MA 02110-1301, USA gnu@gnu.org 00020 */ 00021 00030 #include "config.h" 00031 00032 #include "dialog-ab-daterange.h" 00033 #include "dialog-utils.h" 00034 #include "gnc-date-edit.h" 00035 00036 /* This static indicates the debugging module that this .o belongs to. */ 00037 static QofLogModule log_module = G_LOG_DOMAIN; 00038 00039 typedef struct _DaterangeInfo DaterangeInfo; 00040 00041 void ddr_toggled_cb(GtkToggleButton *button, gpointer user_data); 00042 00043 struct _DaterangeInfo 00044 { 00045 GtkWidget *enter_from_button; 00046 GtkWidget *enter_to_button; 00047 GtkWidget *from_dateedit; 00048 GtkWidget *to_dateedit; 00049 }; 00050 00051 gboolean 00052 gnc_ab_enter_daterange(GtkWidget *parent, 00053 const char *heading, 00054 Timespec *from_date, 00055 gboolean *last_retv_date, 00056 gboolean *first_possible_date, 00057 Timespec *to_date, 00058 gboolean *to_now) 00059 { 00060 GtkBuilder *builder; 00061 GtkWidget *dialog; 00062 GtkWidget *heading_label; 00063 GtkWidget *first_button; 00064 GtkWidget *last_retrieval_button; 00065 GtkWidget *now_button; 00066 DaterangeInfo info; 00067 gint result; 00068 00069 ENTER(""); 00070 00071 builder = gtk_builder_new(); 00072 gnc_builder_add_from_file (builder, "dialog-ab.glade", "Date Range Dialog"); 00073 00074 dialog = GTK_WIDGET(gtk_builder_get_object (builder, "Date Range Dialog")); 00075 00076 /* Connect the signals */ 00077 gtk_builder_connect_signals_full (builder, gnc_builder_connect_full_func, &info ); 00078 00079 if (parent) 00080 gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent)); 00081 00082 heading_label = GTK_WIDGET(gtk_builder_get_object (builder, "heading_label")); 00083 first_button = GTK_WIDGET(gtk_builder_get_object (builder, "first_button")); 00084 last_retrieval_button = GTK_WIDGET(gtk_builder_get_object (builder, "last_retrieval_button")); 00085 info.enter_from_button = GTK_WIDGET(gtk_builder_get_object (builder, "enter_from_button")); 00086 now_button = GTK_WIDGET(gtk_builder_get_object (builder, "now_button")); 00087 info.enter_to_button = GTK_WIDGET(gtk_builder_get_object (builder, "enter_to_button")); 00088 00089 info.from_dateedit = gnc_date_edit_new_ts(*from_date, FALSE, FALSE); 00090 gtk_container_add(GTK_CONTAINER(gtk_builder_get_object (builder, "enter_from_box")), 00091 info.from_dateedit); 00092 gtk_widget_show(info.from_dateedit); 00093 00094 info.to_dateedit = gnc_date_edit_new_ts(*to_date, FALSE, FALSE); 00095 gtk_container_add(GTK_CONTAINER(gtk_builder_get_object (builder, "enter_to_box")), 00096 info.to_dateedit); 00097 gtk_widget_show(info.to_dateedit); 00098 00099 if (*last_retv_date) 00100 { 00101 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(last_retrieval_button), 00102 TRUE); 00103 } 00104 else 00105 { 00106 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(first_button), TRUE); 00107 gtk_widget_set_sensitive(last_retrieval_button, FALSE); 00108 } 00109 00110 gtk_widget_set_sensitive(info.from_dateedit, FALSE); 00111 gtk_widget_set_sensitive(info.to_dateedit, FALSE); 00112 00113 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK); 00114 00115 if (heading) 00116 gtk_label_set_text(GTK_LABEL(heading_label), heading); 00117 00118 gtk_widget_show(dialog); 00119 00120 result = gtk_dialog_run(GTK_DIALOG(dialog)); 00121 gtk_widget_hide(dialog); 00122 00123 if (result == GTK_RESPONSE_OK) 00124 { 00125 *from_date = gnc_date_edit_get_date_ts( 00126 GNC_DATE_EDIT(info.from_dateedit)); 00127 *last_retv_date = gtk_toggle_button_get_active( 00128 GTK_TOGGLE_BUTTON(last_retrieval_button)); 00129 *first_possible_date = gtk_toggle_button_get_active( 00130 GTK_TOGGLE_BUTTON(first_button)); 00131 *to_date = gnc_date_edit_get_date_ts( 00132 GNC_DATE_EDIT(info.to_dateedit)); 00133 *to_now = gtk_toggle_button_get_active( 00134 GTK_TOGGLE_BUTTON(now_button)); 00135 } 00136 00137 g_object_unref(G_OBJECT(builder)); 00138 00139 gtk_widget_destroy(dialog); 00140 00141 LEAVE(""); 00142 return result == GTK_RESPONSE_OK; 00143 } 00144 00145 void 00146 ddr_toggled_cb(GtkToggleButton *button, gpointer user_data) 00147 { 00148 DaterangeInfo *info = user_data; 00149 00150 g_return_if_fail(info); 00151 00152 gtk_widget_set_sensitive(info->from_dateedit, 00153 gtk_toggle_button_get_active( 00154 GTK_TOGGLE_BUTTON(info->enter_from_button))); 00155 gtk_widget_set_sensitive(info->to_dateedit, 00156 gtk_toggle_button_get_active( 00157 GTK_TOGGLE_BUTTON(info->enter_to_button))); 00158 }
1.7.4