~siretart/gnucash/ubuntu-fullsource

« back to all changes in this revision

Viewing changes to src/import-export/aqbanking/dialog-daterange.c

  • Committer: Reinhard Tartler
  • Date: 2008-08-03 07:38:54 UTC
  • mfrom: (2.1.2 debian)
  • Revision ID: siretart@tauware.de-20080803073854-23i4uqi1e73no4oz
mergeĀ fromĀ debian/unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * dialog-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
 
 
22
/**
 
23
 * @internal
 
24
 * @file dialog-daterange.c
 
25
 * @brief Dialog for date range entry
 
26
 * @author Copyright (C) 2002 Christian Stimming <stimming@tuhh.de>
 
27
 * @author Copyright (C) 2008 Andreas Koehler <andi5.py@gmx.net>
 
28
 */
 
29
 
 
30
#include "config.h"
 
31
 
 
32
#include "dialog-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
 
 
43
struct _DaterangeInfo
 
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
    GladeXML *xml;
 
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
    xml = gnc_glade_xml_new("aqbanking.glade", "Date Range Dialog");
 
70
 
 
71
    dialog = glade_xml_get_widget(xml, "Date Range Dialog");
 
72
    g_object_set_data_full(G_OBJECT(dialog), "xml", xml, g_object_unref);
 
73
    glade_xml_signal_autoconnect_full(xml, gnc_glade_autoconnect_full_func,
 
74
                                      &info);
 
75
 
 
76
    if (parent)
 
77
        gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(parent));
 
78
 
 
79
    heading_label  = glade_xml_get_widget(xml, "heading_label");
 
80
    first_button  = glade_xml_get_widget(xml, "first_button");
 
81
    last_retrieval_button  = glade_xml_get_widget(xml, "last_retrieval_button");
 
82
    info.enter_from_button  = glade_xml_get_widget(xml, "enter_from_button");
 
83
    now_button  = glade_xml_get_widget(xml, "now_button");
 
84
    info.enter_to_button  = glade_xml_get_widget(xml, "enter_to_button");
 
85
 
 
86
    info.from_dateedit = gnc_date_edit_new_ts(*from_date, FALSE, FALSE);
 
87
    gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(xml, "enter_from_box")),
 
88
                      info.from_dateedit);
 
89
    gtk_widget_show(info.from_dateedit);
 
90
 
 
91
    info.to_dateedit = gnc_date_edit_new_ts(*to_date, FALSE, FALSE);
 
92
    gtk_container_add(GTK_CONTAINER(glade_xml_get_widget(xml, "enter_to_box")),
 
93
                      info.to_dateedit);
 
94
    gtk_widget_show(info.to_dateedit);
 
95
 
 
96
    if (*last_retv_date) {
 
97
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(last_retrieval_button),
 
98
                                     TRUE);
 
99
    } else {
 
100
        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(first_button), TRUE);
 
101
        gtk_widget_set_sensitive(last_retrieval_button, FALSE);
 
102
    }
 
103
 
 
104
    gtk_widget_set_sensitive(info.from_dateedit, FALSE);
 
105
    gtk_widget_set_sensitive(info.to_dateedit, FALSE);
 
106
 
 
107
    gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_OK);
 
108
 
 
109
    if (heading)
 
110
        gtk_label_set_text(GTK_LABEL(heading_label), heading);
 
111
 
 
112
    gtk_widget_show(dialog);
 
113
 
 
114
    result = gtk_dialog_run(GTK_DIALOG(dialog));
 
115
    gtk_widget_hide(dialog);
 
116
 
 
117
    if (result == GTK_RESPONSE_OK) {
 
118
        *from_date = gnc_date_edit_get_date_ts(
 
119
            GNC_DATE_EDIT(info.from_dateedit));
 
120
        *last_retv_date = gtk_toggle_button_get_active(
 
121
            GTK_TOGGLE_BUTTON(last_retrieval_button));
 
122
        *first_possible_date = gtk_toggle_button_get_active(
 
123
            GTK_TOGGLE_BUTTON(first_button));
 
124
        *to_date = gnc_date_edit_get_date_ts(
 
125
            GNC_DATE_EDIT(info.to_dateedit));
 
126
        *to_now = gtk_toggle_button_get_active(
 
127
            GTK_TOGGLE_BUTTON(now_button));
 
128
    }
 
129
 
 
130
    gtk_widget_destroy(dialog);
 
131
 
 
132
    return result == GTK_RESPONSE_OK;
 
133
}
 
134
 
 
135
void
 
136
ddr_toggled_cb(GtkToggleButton *button, gpointer user_data)
 
137
{
 
138
    DaterangeInfo *info = user_data;
 
139
 
 
140
    g_return_if_fail(info);
 
141
 
 
142
    gtk_widget_set_sensitive(info->from_dateedit,
 
143
                             gtk_toggle_button_get_active(
 
144
                                 GTK_TOGGLE_BUTTON(info->enter_from_button)));
 
145
    gtk_widget_set_sensitive(info->to_dateedit,
 
146
                             gtk_toggle_button_get_active(
 
147
                                 GTK_TOGGLE_BUTTON(info->enter_to_button)));
 
148
}