aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/conduits/todo/todo-conduit-config.h
blob: 3296cd47e3954f9bbe26b0873cb74533961487dd (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* Evolution calendar - ToDo Conduit Configuration
 *
 * Copyright (C) 1998 Free Software Foundation
 * Copyright (C) 2000 Ximian, Inc.
 *
 * Authors: Eskil Heyn Olsen <deity@eskil.dk> 
 *          JP Rosevear <jpr@ximian.com>
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
 */

#ifndef __TODO_CONDUIT_CONFIG_H__
#define __TODO_CONDUIT_CONFIG_H__

#include <gnome.h>
#include <libgpilotdCM/gnome-pilot-conduit-management.h>
#include <libgpilotdCM/gnome-pilot-conduit-config.h>

/* Configuration info */
typedef struct _EToDoConduitCfg EToDoConduitCfg;
struct _EToDoConduitCfg {
    guint32 pilot_id;
    GnomePilotConduitSyncType  sync_type;   /* only used by capplet */

    gboolean open_secret;
    gchar *last_uri;
};

#ifdef TODO_CONFIG_LOAD
/* Load the configuration data */
static void 
todoconduit_load_configuration (EToDoConduitCfg **c, guint32 pilot_id) 
{
    GnomePilotConduitManagement *management;
    GnomePilotConduitConfig *config;
    gchar prefix[256];
    g_snprintf (prefix, 255, "/gnome-pilot.d/e-todo-conduit/Pilot_%u/",
            pilot_id);
    
    *c = g_new0 (EToDoConduitCfg,1);
    g_assert (*c != NULL);

    (*c)->pilot_id = pilot_id;

    management = gnome_pilot_conduit_management_new ("e_todo_conduit", GNOME_PILOT_CONDUIT_MGMT_ID);
    config = gnome_pilot_conduit_config_new (management, pilot_id);
    if (!gnome_pilot_conduit_config_is_enabled (config, &(*c)->sync_type))
        (*c)->sync_type = GnomePilotConduitSyncTypeNotSet;
    gtk_object_unref (GTK_OBJECT (config));
    gtk_object_unref (GTK_OBJECT (management));
    
    /* Custom settings */
    gnome_config_push_prefix (prefix);

    (*c)->open_secret = gnome_config_get_bool ("open_secret=FALSE");
    (*c)->last_uri = gnome_config_get_string ("last_uri");

    gnome_config_pop_prefix ();
}
#endif

#ifdef TODO_CONFIG_SAVE
/* Saves the configuration data. */
static void
todoconduit_save_configuration (EToDoConduitCfg *c) 
{
    gchar prefix[256];

    g_snprintf (prefix, 255, "/gnome-pilot.d/e-todo-conduit/Pilot_%u/",
            c->pilot_id);

    gnome_config_push_prefix (prefix);
    gnome_config_set_bool ("open_secret", c->open_secret);
    gnome_config_set_string ("last_uri", c->last_uri);
    gnome_config_pop_prefix ();

    gnome_config_sync ();
    gnome_config_drop_all ();
}
#endif

#ifdef TODO_CONFIG_DUPE
/* Creates a duplicate of the configuration data */
static EToDoConduitCfg*
todoconduit_dupe_configuration (EToDoConduitCfg *c) 
{
    EToDoConduitCfg *retval;

    g_return_val_if_fail (c != NULL, NULL);

    retval = g_new0 (EToDoConduitCfg, 1);
    retval->sync_type = c->sync_type;
    retval->pilot_id = c->pilot_id;

    retval->open_secret = c->open_secret;
    retval->last_uri = g_strdup (c->last_uri);

    return retval;
}
#endif

#ifdef TODO_CONFIG_DESTROY
/* Destroy a configuration */
static void 
todoconduit_destroy_configuration (EToDoConduitCfg **c) 
{
    g_return_if_fail (c != NULL);
    g_return_if_fail (*c != NULL);

    g_free ((*c)->last_uri);
    g_free (*c);
    *c = NULL;
}
#endif

#endif /* __TODO_CONDUIT_CONFIG_H__ */