aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gncal.c
blob: 5aa911aed9d5b4673c26eafb3552120b6928bf75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
/*
 * gnlp.c: LPQ/LPR stuff
 */

#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <time.h>
#include <string.h>

#include <gnome.h>
#include <config.h>

#include "gncal.h"
#include "calcs.h"
#include "clist.h"
#include "gtkcalendar.h"

/* Function declarations */
void parse_args(int argc, char *argv[]);
static int save_state      (GnomeClient        *client,
                gint                phase,
                GnomeRestartStyle   save_style,
                gint                shutdown,
                GnomeInteractStyle  interact_style,
                gint                fast,
                gpointer            client_data);
static void connect_client (GnomeClient *client, 
                gint         was_restarted, 
                gpointer     client_data);

void discard_session (gchar *id);

static GtkMenuEntry menu_items[] =
{
        { N_("File/Exit"), N_("<control>Q"), menu_file_quit, NULL},
        { N_("Help/About"), N_("<control>A"), menu_help_about, NULL},
};

#define DAY_ARRAY_MAX 35
/* The naughty global variables */
int curr_day, old_day;
int curr_month, old_month;
int curr_year, old_year;
GtkWidget *month_label;
GtkWidget *year_label;
GtkWidget *dailylist;
GtkWidget *calendar_days[DAY_ARRAY_MAX];
GtkWidget *calendar_buttons[DAY_ARRAY_MAX];
GtkWidget *app;
GtkWidget *calendar;

int restarted = 0;
/* Stuff we use for session state */
int os_x = 0,
    os_y = 0,
    os_w = 0,
    os_h = 0;


/* True if parsing determined that all the work is already done.  */
int just_exit = 0;

/* These are the arguments that our application supports.  */
static struct argp_option arguments[] =
{
#define DISCARD_KEY -1
  { "discard-session", DISCARD_KEY, N_("ID"), 0, N_("Discard session"), 1 },
  { NULL, 0, NULL, 0, NULL, 0 }
};

/* Forward declaration of the function that gets called when one of
   our arguments is recognized.  */
static error_t parse_an_arg (int key, char *arg, struct argp_state *state);

/* This structure defines our parser.  It can be used to specify some
   options for how our parsing function should be called.  */
static struct argp parser =
{
  arguments,            /* Options.  */
  parse_an_arg,         /* The parser function.  */
  NULL,             /* Some docs.  */
  NULL,             /* Some more docs.  */
  NULL,             /* Child arguments -- gnome_init fills
                   this in for us.  */
  NULL,             /* Help filter.  */
  NULL              /* Translation domain; for the app it
                   can always be NULL.  */
};

#define ELEMENTS(x) (sizeof (x) / sizeof (x [0]))

GtkMenuFactory *
create_menu () 
{
  GtkMenuFactory *subfactory;
  int i;

  subfactory = gtk_menu_factory_new  (GTK_MENU_FACTORY_MENU_BAR);
  gtk_menu_factory_add_entries (subfactory, menu_items, ELEMENTS(menu_items));

  return subfactory;
}

/* place marker until i get get something better */
void print_error(char *text)
{
    GtkWidget *msgbox;
    char buf[512];

    if (errno == 0)
        sprintf(buf, "%s", text);
    else
        sprintf(buf, "%s (%s)", text, g_strerror(errno));

    g_warning("%s\n", buf);
    msgbox = gnome_message_box_new(buf, "error", "OK", NULL, NULL);

    gtk_widget_show(msgbox);
}


void menu_file_quit(GtkWidget *widget, gpointer data)
{
    gtk_main_quit();
}

void menu_help_about(GtkWidget *widget, gpointer data)
{
    GtkWidget *about;
    gchar *authors[] = {
        "Craig Small <csmall@small.dropbear.id.au>",
        NULL };
    about = gnome_about_new( _("Gnome Calendar"), VERSION,
                "(C) 1998",
                authors,
                /* Comments */
                _("This program shows a nice pretty "
                "calendar and will do scheduling "
                "real soon now!"),
                NULL);
                
    gtk_widget_show(about);
}

void dailylist_item_select(GtkWidget *widget, gpointer data)
{
    int *x = (int*)data;

    g_print("Selected %d\n", x);
}

void update_today_list(void)
{
    GtkWidget *listitem;
    GtkWidget *list_hbox;
    GtkWidget *hour_label;
    GtkWidget *event_label;
    char buf[50];
    int tmphr, tmpmin,i;

}

/*
 * updates the calendar that appears in the left collumn
 */
void month_changed(GtkWidget *widget, gpointer data)
{
    curr_month = GTK_CALENDAR(widget)->month;
    curr_year = GTK_CALENDAR(widget)->year;
}

void update_calendar()
{
    int tmpday;
    int i;
    char buf[50];
    int month_changed;
    static int offset;

    gtk_calendar_unmark_day(GTK_CALENDAR(calendar),old_day);
    gtk_calendar_mark_day(GTK_CALENDAR(calendar), curr_day);
    printf("Date changed (nothing happens much\n");
/*  gtk_calendar_select_day(GTK_CALENDAR(calendar), curr_day); */
#ifdef 0
    /* Only update the whole calendar if the year or month has changed */
    tmpday=1;
    month_changed = FALSE;
    if (curr_month != old_month || curr_year != old_year)  {
        month_changed = TRUE;
        offset = weekday_of_date(tmpday, curr_month, curr_year) - 1;
    }

    for(i=0; i < DAY_ARRAY_MAX; i++) {
            tmpday = i - offset +1;
        if (valid_date(tmpday, curr_month, curr_year)) {
            sprintf(buf, "%2d", tmpday);
            /*if (month_changed) {*/
                gtk_label_set(GTK_LABEL(calendar_days[i]), buf);
                gtk_widget_show(calendar_buttons[i]);
            /*}*/
            if (tmpday == curr_day) {
                gtk_container_border_width(GTK_CONTAINER(calendar_buttons[i]), 2);
                gtk_widget_show(calendar_buttons[i]);
            } else {
                gtk_container_border_width(GTK_CONTAINER(calendar_buttons[i]), 0);
            }
        } else if (month_changed) {
            gtk_label_set(GTK_LABEL(calendar_days[i]), "");
            gtk_widget_hide(calendar_buttons[i]);
            gtk_container_border_width(GTK_CONTAINER(calendar_buttons[i]), 0);
        }
    } /* for i */   
#endif /* 0 */
}

/*
 * Updates all the main window widgets when the current day of interest is
 * changed
 */
void update_today(void)
{
    char buf[50];

    /* This needs to be fixed to get the right date order for the country*/
/*  if (curr_month != old_month) {
        gtk_label_set(GTK_LABEL(month_label), month_name(curr_month));
    }
    if (curr_year != old_year) {
        sprintf(buf, "%4d", curr_year);
        gtk_label_set(GTK_LABEL(year_label), buf);
    }*/
    update_today_list();
    update_calendar();
}

void next_day_but_clicked(GtkWidget *widget, gpointer data)
{
    old_day = curr_day;
    old_month = curr_month;
    old_year = curr_year;
    next_date(&curr_day, &curr_month, &curr_year);
    update_today();
}

void prev_day_but_clicked(GtkWidget *widget, gpointer data)
{
    old_day = curr_day;
    old_month = curr_month;
    old_year = curr_year;
    prev_date(&curr_day, &curr_month, &curr_year);
    update_today();
}

void today_but_clicked(GtkWidget *widget, gpointer data)
{
    old_day = curr_day;
    old_month = curr_month;
    old_year = curr_year;
    get_system_date(&curr_day, &curr_month, &curr_year);
    update_today();
}

void prev_month_but_clicked(GtkWidget *widget, gpointer data)
{
    if (curr_year == 0 && curr_month == MONTH_MIN) 
        return;
    old_day = curr_day;
    old_month = curr_month;
    old_year = curr_year;
    curr_month--;
    if (curr_month < MONTH_MIN) {
        curr_month = MONTH_MAX;
        curr_year--;
    }
    update_today();
}

void next_month_but_clicked(GtkWidget *widget, gpointer data)
{
    if (curr_year == 3000 && curr_month == MONTH_MAX) 
        return;
    old_day = curr_day;
    old_month = curr_month;
    old_year = curr_year;
    curr_month++;
    if (curr_month > MONTH_MAX ) {
        curr_month = MONTH_MIN;
        curr_year++;
    }
    update_today();
}

void prev_year_but_clicked(GtkWidget *widget, gpointer data)
{
    if (curr_year == 0) 
        return;

    old_day = curr_day;
    old_month = curr_month;
    old_year = curr_year;
    curr_year--;
    update_today();
}

    
void next_year_but_clicked(GtkWidget *widget, gpointer data)
{
    if (curr_year == 3000) 
        return;

    old_day = curr_day;
    old_month = curr_month;
    old_year = curr_year;
    curr_year++;
    update_today();
}


void calendar_but_clicked(GtkWidget *widget, gpointer data)
{
    char *ptr; 
    int x;

    ptr = GTK_LABEL(GTK_BUTTON(widget)->child)->label;
    x = atoi(ptr);

    if (valid_date(x, curr_month, curr_year)) {
        old_day = curr_day;
        old_month = curr_month;
        old_year = curr_year;
        curr_day = x;
        update_today();
    }
}

void test_foreach(GtkWidget *widget, gpointer data)
{
    char *ptr;

    ptr = GTK_LABEL(GTK_BUTTON(widget)->child)->label;
    g_print("%s\n", ptr);
}

void show_main_window()
{
    GtkWidget *main_vbox;
    /*GtkWidget *menubar;
    GtkAcceleratorTable *accel;*/
    GtkMenuFactory *menuf;
    GtkWidget *main_hbox;
    GtkWidget *left_vbox;
    GtkWidget *right_vbox;
    GtkWidget *date_hbox;
    GtkWidget *prev_mth_but;
    GtkWidget *next_mth_but;
    GtkWidget *prev_year_but;
    GtkWidget *next_year_but;
    GtkWidget *day_but_hbox;
    GtkWidget *prev_day_but;
    GtkWidget *today_but;
    GtkWidget *next_day_but;
    GtkWidget *separator;
    GtkWidget *cal_table;
    GtkWidget *day_name_label;
    GtkWidget *scrolledwindow;
    GtkWidget *scroll_hbox;
    GtkWidget *hour_list;
    GtkWidget *list_item;
    GtkWidget *dailylist_item;
    GtkWidget *event_label;
    int i,j;
    struct tm tm;
    char buf[50];

    bzero((char*)&tm, sizeof(struct tm));
    app = gnome_app_new("gncal", "Gnome Calendar");
    gtk_widget_realize(app);
    gtk_signal_connect(GTK_OBJECT(app), "delete_event",
               GTK_SIGNAL_FUNC(menu_file_quit), NULL);
    if (restarted) {
        gtk_widget_set_uposition(app, os_x, os_y);
        gtk_widget_set_usize(app, os_w, os_h);
    } else {
        gtk_widget_set_usize(app,300,300);
    }
    main_vbox = gtk_vbox_new(FALSE, 1);
    gnome_app_set_contents(GNOME_APP(app), main_vbox);
    gtk_widget_show(main_vbox);

    menuf = create_menu();
    gnome_app_set_menus(GNOME_APP(app), GTK_MENU_BAR(menuf->widget));

    main_hbox = gtk_hbox_new(FALSE,1);
    gtk_box_pack_start(GTK_BOX(main_vbox), main_hbox, TRUE, TRUE, 0);
    gtk_widget_show(main_hbox);

    left_vbox = gtk_vbox_new(FALSE, 1);
    gtk_box_pack_start(GTK_BOX(main_hbox), left_vbox, FALSE, TRUE,0);
    gtk_widget_show(left_vbox);

    separator = gtk_vseparator_new();
    gtk_box_pack_start(GTK_BOX(main_hbox), separator, FALSE, TRUE, 0);
    gtk_widget_show(separator);

    right_vbox = gtk_vbox_new(FALSE, 1);
    gtk_box_pack_start(GTK_BOX(main_hbox), right_vbox, TRUE, TRUE, 0);
    gtk_widget_show(right_vbox);

    date_hbox = gtk_hbox_new(FALSE, 1);
    gtk_box_pack_start(GTK_BOX(left_vbox), date_hbox, FALSE, FALSE, 0);
    gtk_widget_show(date_hbox);
/*
    prev_mth_but = gtk_button_new_with_label("<");
    gtk_box_pack_start(GTK_BOX(date_hbox), prev_mth_but, FALSE, FALSE, 0);
    gtk_signal_connect(GTK_OBJECT(prev_mth_but), "clicked", GTK_SIGNAL_FUNC(prev_month_but_clicked), NULL);
    gtk_widget_show(prev_mth_but);

    month_label = gtk_label_new("Fooary");
    gtk_box_pack_start(GTK_BOX(date_hbox), month_label, TRUE, FALSE, 0);
    gtk_widget_show(month_label);

    next_mth_but = gtk_button_new_with_label(">");
    gtk_box_pack_start(GTK_BOX(date_hbox), next_mth_but, FALSE, FALSE, 0);
    gtk_signal_connect(GTK_OBJECT(next_mth_but), "clicked", GTK_SIGNAL_FUNC(next_month_but_clicked), NULL);
    gtk_widget_show(next_mth_but);

    prev_year_but = gtk_button_new_with_label("<");
    gtk_box_pack_start(GTK_BOX(date_hbox), prev_year_but, FALSE, FALSE, 0);
    gtk_signal_connect(GTK_OBJECT(prev_year_but), "clicked", GTK_SIGNAL_FUNC(prev_year_but_clicked), NULL);
    gtk_widget_show(prev_year_but);

    year_label = gtk_label_new("1971");
    gtk_box_pack_start(GTK_BOX(date_hbox), year_label, TRUE, FALSE, 0);
    gtk_widget_show(year_label);
    
    next_year_but = gtk_button_new_with_label(">");
    gtk_box_pack_start(GTK_BOX(date_hbox), next_year_but, FALSE, FALSE, 0);
    gtk_signal_connect(GTK_OBJECT(next_year_but), "clicked", GTK_SIGNAL_FUNC(next_year_but_clicked), NULL);
    gtk_widget_show(next_year_but);
*/
    /* Build up the calendar table */
/*  cal_table = gtk_table_new(7,7,TRUE);
    gtk_box_pack_start(GTK_BOX(left_vbox), cal_table, FALSE, FALSE, 0);
    gtk_widget_show(cal_table);

    for(i=DAY_MIN; i <= DAY_MAX; i++) {
        day_name_label = gtk_label_new(short3_day_name(i));
        gtk_table_attach_defaults(GTK_TABLE(cal_table), day_name_label, i-1, i, 0, 1);
        gtk_widget_show(day_name_label);
    }
    for(j=0; j < 5; j++) {
        for(i=0; i < 7; i++) {
            calendar_buttons[i+j*7] = gtk_button_new();
            gtk_container_border_width(GTK_CONTAINER(calendar_buttons[i+j*7]), 0);
            gtk_table_attach_defaults(GTK_TABLE(cal_table), calendar_buttons[i+j*7], i, i+1, j+2, j+3);
            gtk_signal_connect(GTK_OBJECT(calendar_buttons[i+j*7]), "clicked",  GTK_SIGNAL_FUNC(calendar_but_clicked), NULL);
            gtk_widget_show(calendar_buttons[i+j*7]);
            calendar_days[i+j*7] = gtk_label_new("");
            gtk_container_add(GTK_CONTAINER(calendar_buttons[i+j*7]), calendar_days[i+j*7]);
            gtk_widget_show(calendar_days[i+j*7]);
        }
    }
*/
    calendar = gtk_calendar_new();
    gtk_calendar_display_options(GTK_CALENDAR(calendar), GTK_CALENDAR_SHOW_DAY_NAMES | GTK_CALENDAR_SHOW_HEADING);
    gtk_box_pack_start(GTK_BOX(left_vbox), calendar, FALSE, FALSE, 0);
    gtk_signal_connect(GTK_OBJECT(calendar), "month_changed",
        GTK_SIGNAL_FUNC(month_changed), NULL);
    gtk_widget_show(calendar);


    day_but_hbox = gtk_hbox_new(TRUE, 1);
    gtk_box_pack_start(GTK_BOX(left_vbox), day_but_hbox, FALSE, FALSE, 0);
    gtk_widget_show(day_but_hbox);

    prev_day_but = gtk_button_new_with_label("Prev");
    gtk_box_pack_start(GTK_BOX(day_but_hbox), prev_day_but, TRUE, TRUE, 0);
    gtk_signal_connect(GTK_OBJECT(prev_day_but), "clicked", GTK_SIGNAL_FUNC(prev_day_but_clicked), NULL);
    gtk_widget_show(prev_day_but);
    
    today_but = gtk_button_new_with_label("Today");
    gtk_box_pack_start(GTK_BOX(day_but_hbox), today_but, TRUE, TRUE, 0);
    gtk_signal_connect(GTK_OBJECT(today_but), "clicked", GTK_SIGNAL_FUNC(today_but_clicked), NULL);
    gtk_widget_show(today_but);
    
    next_day_but = gtk_button_new_with_label("Next");
    gtk_box_pack_start(GTK_BOX(day_but_hbox), next_day_but, TRUE, TRUE, 0);
    gtk_signal_connect(GTK_OBJECT(next_day_but), "clicked", GTK_SIGNAL_FUNC(next_day_but_clicked), NULL);
    gtk_widget_show(next_day_but);


    dailylist = create_clist();
    gtk_box_pack_start(GTK_BOX(right_vbox), dailylist, TRUE, TRUE, 0);
    gtk_widget_show(dailylist);
    setup_clist(dailylist);

    gtk_widget_show(app);

}


int 
main(int argc, char *argv[])
{
    GnomeClient *client;

    argp_program_version = VERSION;


    /* Initialise the i18n stuff */
    bindtextdomain(PACKAGE, GNOMELOCALEDIR);
    textdomain(PACKAGE);

    /* This create a default client and arrages for it to parse some
       command line arguments
     */
    client = gnome_client_new_default();

    /* Arrange to be told when something interesting happens.  */
    gtk_signal_connect (GTK_OBJECT (client), "save_yourself",
              GTK_SIGNAL_FUNC (save_state), (gpointer) argv[0]);
    gtk_signal_connect (GTK_OBJECT (client), "connect",
              GTK_SIGNAL_FUNC (connect_client), NULL);

    gnome_init("gncal", &parser, argc, argv, 0, NULL);

    show_main_window();

    /* Initialse date to the current day */
    old_day = old_month = old_year = 0;
    get_system_date(&curr_day, &curr_month, &curr_year);
    update_today();

    gtk_main();

    return 0;
}

static error_t
parse_an_arg (int key, char *arg, struct argp_state *state)
{
  if (key == DISCARD_KEY)
    {
      discard_session (arg);
      just_exit = 1;
      return 0;
    }

  /* We didn't recognize it.  */
  return ARGP_ERR_UNKNOWN;
}


/* Session Management routines */


static int
save_state (GnomeClient        *client,
        gint                phase,
        GnomeRestartStyle   save_style,
        gint                shutdown,
        GnomeInteractStyle  interact_style,
        gint                fast,
        gpointer            client_data)
{
  gchar *session_id;
  gchar *sess;
  gchar *buf;
  gchar *argv[3];
  gint x, y, w, h;

  session_id= gnome_client_get_id (client);

  /* The only state that gnome-hello has is the window geometry. 
     Get it. */
  gdk_window_get_geometry (app->window, &x, &y, &w, &h, NULL);

  /* Save the state using gnome-config stuff. */
  sess = g_copy_strings ("/gncal/Saved-Session-",
                         session_id,
                         NULL);

  buf = g_copy_strings ( sess, "/x", NULL);
  gnome_config_set_int (buf, x);
  g_free(buf);
  buf = g_copy_strings ( sess, "/y", NULL);
  gnome_config_set_int (buf, y);
  g_free(buf);
  buf = g_copy_strings ( sess, "/w", NULL);
  gnome_config_set_int (buf, w);
  g_free(buf);
  buf = g_copy_strings ( sess, "/h", NULL);
  gnome_config_set_int (buf, h);
  g_free(buf);

  gnome_config_sync();
  g_free(sess);

  /* Here is the real SM code. We set the argv to the parameters needed
     to restart/discard the session that we've just saved and call
     the gnome_session_set_*_command to tell the session manager it. */
  argv[0] = (char*) client_data;
  argv[1] = "--discard-session";
  argv[2] = session_id;
  gnome_client_set_discard_command (client, 3, argv);

  /* Set commands to clone and restart this application.  Note that we
     use the same values for both -- the session management code will
     automatically add whatever magic option is required to set the
     session id on startup.  */
  gnome_client_set_clone_command (client, 1, argv);
  gnome_client_set_restart_command (client, 1, argv);

  g_print("save state\n");
  return TRUE;
}

/* Connected to session manager. If restarted from a former session:
   reads the state of the previous session. Sets os_* (prepare_app
   uses them) */
void
connect_client (GnomeClient *client, gint was_restarted, gpointer client_data)
{
  gchar *session_id;

  /* Note that information is stored according to our *old*
     session id.  The id can change across sessions.  */
  session_id = gnome_client_get_previous_id (client);

  if (was_restarted && session_id != NULL)
    {
      gchar *sess;
      gchar *buf;

      restarted = 1;

      sess = g_copy_strings ("/gncal/Saved-Session-", session_id, NULL);

      buf = g_copy_strings ( sess, "/x", NULL);
      os_x = gnome_config_get_int (buf);
      g_free(buf);
      buf = g_copy_strings ( sess, "/y", NULL);
      os_y = gnome_config_get_int (buf);
      g_free(buf);
      buf = g_copy_strings ( sess, "/w", NULL);
      os_w = gnome_config_get_int (buf);
      g_free(buf);
      buf = g_copy_strings ( sess, "/h", NULL);
      os_h = gnome_config_get_int (buf);
      g_free(buf);
    }

  /* If we had an old session, we clean up after ourselves.  */
  if (session_id != NULL)
    discard_session (session_id);

  return;
}

void
discard_session (gchar *id)
{
  gchar *sess;

  sess = g_copy_strings ("/gncal/Saved-Session-", id, NULL);

  /* we use the gnome_config_get_* to work around a bug in gnome-config 
     (it's going under a redesign/rewrite, so i didn't correct it) */
  gnome_config_get_int ("/gncal/Bug/work-around=0");

  gnome_config_clean_section (sess);
  gnome_config_sync ();

  g_free (sess);
  return;
}