aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/default-source/default-source.c
blob: a7392f25f918a90a2c7b7200986dce2d0708d6d7 (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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/*
 * Copyright (C) 2004 D
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * 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.
 *
 */

#include <gtk/gtk.h>

#include <e-util/e-config.h>
#include <calendar/gui/e-cal-config.h>
#include <libedataserver/e-source.h>
#include <addressbook/gui/widgets/eab-config.h>
#include <libebook/e-book.h>
#include <libecal/e-cal.h>
#include <libedataserver/e-source.h>
#include <libgnome/gnome-i18n.h>
#include <string.h>
GtkWidget* org_gnome_default_book (EPlugin *epl, EConfigHookItemFactoryData *data);
void commit_default_calendar (EPlugin *epl, EConfigTarget *target);
void commit_default_book (EPlugin *epl, EConfigTarget *target);
void 
commit_default_calendar (EPlugin *epl, EConfigTarget *target)
{
    ECalConfigTargetSource *cal_target;
    ESource *source;

    cal_target = (ECalConfigTargetSource *) target;
    source = cal_target->source;
    if (e_source_get_property (source, "default")) 
        if (!e_cal_set_default_source (source, E_CAL_SOURCE_TYPE_EVENT, NULL))
            e_cal_set_default_source (source, E_CAL_SOURCE_TYPE_TODO, NULL);
}

void
commit_default_book (EPlugin *epl, EConfigTarget *target)
{
    EABConfigTargetSource *book_target;
    ESource *source;

    book_target = (EABConfigTargetSource *) target;
    source = book_target->source;
    if (e_source_get_property (source, "default"))
        e_book_set_default_source (source, NULL);
  
    
}

static void
default_source_changed (GtkWidget *check_box,  ESource *source)
{
    
    if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (check_box))) 
        e_source_set_property (source, "default", "true");
    else 
        e_source_set_property (source, "default", NULL);
}


GtkWidget *
org_gnome_default_book (EPlugin *epl, EConfigHookItemFactoryData *data)
{
    GtkWidget *widget;
    ESource *source;
    EABConfigTargetSource *book_target;
 
    if (data->old)
        return data->old;
    widget = gtk_check_button_new_with_mnemonic (_("Mark as _default folder"));
    book_target = (EABConfigTargetSource *) data->target;
    source = book_target->source;
    
    if (e_source_get_property (source, "default"))
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
    else 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
    gtk_container_add (GTK_CONTAINER (data->parent), widget);

    g_signal_connect (GTK_TOGGLE_BUTTON (widget), "toggled", G_CALLBACK (default_source_changed), source);
    gtk_widget_show (widget);
    return widget;
}

GtkWidget *org_gnome_default_cal (EPlugin *epl, EConfigHookItemFactoryData *data);

GtkWidget *
org_gnome_default_cal (EPlugin *epl, EConfigHookItemFactoryData *data)
{
    GtkWidget *widget;
    ESource *source;
    ECalConfigTargetSource *cal_target;
    int i;

    if (data->old)
        return data->old;
    widget = gtk_check_button_new_with_mnemonic (_("Mark as _default folder"));
    cal_target = (ECalConfigTargetSource *) data->target;
    source = cal_target->source;
    
    if (e_source_get_property (source, "default"))
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), TRUE);
    else 
        gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), FALSE);
    
    i = ((GtkTable *)data->parent)->nrows;
    gtk_table_attach((GtkTable *)data->parent, widget, 1, 2, i, i+1, GTK_EXPAND | GTK_FILL, 0, 0, 0);

    g_signal_connect (GTK_TOGGLE_BUTTON (widget), "toggled", G_CALLBACK (default_source_changed), source);
    gtk_widget_show (widget);
    return widget;
}