1 #ident "Kalopa: $Id: getyear.c,v 1.2 2008/01/15 18:10:41 dtynan Exp $"
2
3 /*
4 * $Id: getyear.c,v 1.2 2008/01/15 18:10:41 dtynan Exp $
5 *
6 * Copyright (c) 2005, Kalopa Research Limited. All rights reserved.
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
11 *
12 * It is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
15 * License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this product; see the file COPYING. If not, write to
19 * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139,
20 * USA.
21 *
22 * THIS SOFTWARE IS PROVIDED BY KALOPA RESEARCH LIMITED "AS IS" AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
25 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL KALOPA
26 * RESEARCH LIMITED BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
31 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
33 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 * ABSTRACT
36 *
37 * $Log: getyear.c,v $
38 * Revision 1.2 2008/01/15 18:10:41 dtynan
39 * Changed to use new company name and copyright, also fixed a few old
40 * files with the wrong license.
41 *
42 * Revision 1.1 2006/07/31 09:00:00 dtynan
43 * Added missing files.
44 *
45 */
46 #include <stdio.h>
47 #include <unistd.h>
48 #include <sys/types.h>
49 #include <sys/stat.h>
50 #include <string.h>
51
52 #include <bonobo.h>
53 #include <gnome.h>
54
55 #include "beanie_gui.h"
56
57 #define YBASE 2000
58
59 static int cyear = 0;
60 static int selyear;
61
62 /*
63 *
64 */
65 int
get_current_year()66 get_current_year()
67 {
68 time_t now;
69 struct tm *tmp;
70
71 if (cyear == 0) {
72 time(&now);
73 tmp = localtime(&now);
74 selyear = cyear = tmp->tm_year + 1900;
75 }
76 return(selyear);
77 }
78
79 /*
80 *
81 */
82 int
is_current_year()83 is_current_year()
84 {
85 int i = get_current_year();
86
87 return(i == cyear ? 0 : i);
88 }
89
90 /*
91 *
92 */
93 void
select_year(GtkMenuItem * menuitem,gpointer udata)94 select_year(GtkMenuItem *menuitem, gpointer udata)
95 {
96 int i;
97 char ystr[16];
98 GtkWidget *dialog;
99 GtkWidget *frame;
100 GtkWidget *combo;
101
102 get_current_year();
103 dialog = gtk_dialog_new_with_buttons("Select Fiscal Year", NULL,
104 0,
105 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
106 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
107 NULL);
108 gtk_window_set_default_size(GTK_WINDOW(dialog), 150, -1);
109 gtk_container_border_width(GTK_CONTAINER(dialog), 5);
110 gtk_widget_realize(dialog);
111
112 frame = gtk_frame_new("Select a fiscal year from the list");
113 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame,
114 TRUE, TRUE, 0);
115
116 combo = gtk_combo_box_new_text();
117 for (i = YBASE; i <= cyear; i++) {
118 sprintf(ystr, "%04d", i);
119 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), ystr);
120 }
121 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), cyear - YBASE);
122 gtk_container_add(GTK_CONTAINER(frame), combo);
123 gtk_widget_show(combo);
124 gtk_widget_show(frame);
125 gtk_widget_show(dialog);
126
127 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
128 selyear = gtk_combo_box_get_active(GTK_COMBO_BOX(combo))+YBASE;
129 update_details();
130 }
131 gtk_widget_destroy(dialog);
132 }
133