aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui/e-select-names-editable.c
blob: 5ec94a0fc6e68634f2f42d7d6e520225ad08cc59 (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
/*
 *  Copyright (C) 2001 Ximian Inc.
 *
 *  Authors: Michael Zucchi <notzed@ximian.com>
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Library 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 Library General Public License for more details.
 *
 *  You should have received a copy of the GNU Library General Public
 *  License along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/** WARNING
 **
 ** DO NOT USE THIS CODE OUTSIDE OF CAMEL
 **
 ** IT IS SUBJECT TO CHANGE OR MAY VANISH AT ANY TIME
 **/

#ifndef _CAMEL_HTML_PARSER_H
#define _CAMEL_HTML_PARSER_H

#include <camel/camel-object.h>

#define CAMEL_HTML_PARSER(obj)         CAMEL_CHECK_CAST (obj, camel_html_parser_get_type (), CamelHTMLParser)
#define CAMEL_HTML_PARSER_CLASS(klass) CAMEL_CHECK_CLASS_CAST (klass, camel_html_parser_get_type (), CamelHTMLParserClass)
#define CAMEL_IS_HTML_PARSER(obj)      CAMEL_CHECK_TYPE (obj, camel_html_parser_get_type ())

typedef struct _CamelHTMLParserClass CamelHTMLParserClass;
typedef struct _CamelHTMLParser CamelHTMLParser;

/* Parser/tokeniser states */
typedef enum _camel_html_parser_t {
    CAMEL_HTML_PARSER_DATA,         /* raw data */
    CAMEL_HTML_PARSER_ENT,          /* entity in data */
    CAMEL_HTML_PARSER_ELEMENT,      /* element (tag + attributes scanned) */
    CAMEL_HTML_PARSER_TAG,          /* tag */
    CAMEL_HTML_PARSER_DTDENT,       /* dtd entity? <! blah blah > */
    CAMEL_HTML_PARSER_COMMENT0,     /* start of comment */
    CAMEL_HTML_PARSER_COMMENT,      /* body of comment */
    CAMEL_HTML_PARSER_ATTR0,        /* start of attribute */
    CAMEL_HTML_PARSER_ATTR,         /* attribute */
    CAMEL_HTML_PARSER_VAL0,         /* start of value */
    CAMEL_HTML_PARSER_VAL,          /* value */
    CAMEL_HTML_PARSER_VAL_ENT,      /* entity in value */
    CAMEL_HTML_PARSER_EOD,          /* end of current data */
    CAMEL_HTML_PARSER_EOF,          /* end of file */
} camel_html_parser_t;

struct _CamelHTMLParser {
    CamelObject parent;

    struct _CamelHTMLParserPrivate *priv;
};

struct _CamelHTMLParserClass {
    CamelObjectClass parent_class;
};

guint       camel_html_parser_get_type  (void);
CamelHTMLParser      *camel_html_parser_new (void);

void camel_html_parser_set_data(CamelHTMLParser *hp, const char /*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) version 3.
 *
 * 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
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with the program; if not, see <http://www.gnu.org/licenses/>  
 *
 *
 * Authors:
 *      Mike Kestner  <mkestner@ximian.com>
 *
 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 *
 */

#include <config.h>
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include <libebook/e-destination.h>
#include <libedataserverui/e-name-selector-entry.h>

#include "e-select-names-editable.h"

struct _ESelectNamesEditablePriv {
    gint dummy;
};

static ENameSelectorEntryClass *parent_class;

static void
esne_cell_editable_init (GtkCellEditableIface *iface)
{
}

static void
esne_finalize (GObject *obj)
{
    ESelectNamesEditable *esne = (ESelectNamesEditable *) obj;

    g_free (esne->priv);

    if (G_OBJECT_CLASS (parent_class)->finalize)
        G_OBJECT_CLASS (parent_class)->finalize (obj);
}

static void
esne_init (ESelectNamesEditable *esne)
{
    esne->priv = g_new0 (ESelectNamesEditablePriv, 1);
}

static void
esne_class_init (GObjectClass *klass)
{
    klass->finalize = esne_finalize;

    parent_class = E_NAME_SELECTOR_ENTRY_CLASS (g_type_class_peek_parent (klass));
}

GType
e_select_names_editable_get_type (void)
{
    static GType esne_type = 0;

    if (!esne_type) {
        static const GTypeInfo esne_info = {
            sizeof (ESelectNamesEditableClass),
            NULL,       /* base_init */
            NULL,       /* base_finalize */
            (GClassInitFunc) esne_class_init,
            NULL,       /* class_finalize */
            NULL,       /* class_data */
            sizeof (ESelectNamesEditable),
            0,              /* n_preallocs */
            (GInstanceInitFunc) esne_init,
        };

        static const GInterfaceInfo cell_editable_info = {
            (GInterfaceInitFunc) esne_cell_editable_init,
            NULL,
            NULL
        };

        esne_type = g_type_register_static (E_TYPE_NAME_SELECTOR_ENTRY, "ESelectNamesEditable", &esne_info, 0);

        g_type_add_interface_static (esne_type, GTK_TYPE_CELL_EDITABLE, &cell_editable_info);
    }

    return esne_type;
}

ESelectNamesEditable *
e_select_names_editable_new (void)
{
    ESelectNamesEditable *esne = g_object_new (E_TYPE_SELECT_NAMES_EDITABLE, NULL);

    return esne;
}

gchar *
e_select_names_editable_get_email (ESelectNamesEditable *esne)
{
    EDestinationStore *destination_store;
    GList *destinations;
    EDestination *destination;
    gchar *result = NULL;

    g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);

    destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
    destinations = e_destination_store_list_destinations (destination_store);
    if (!destinations)
        return NULL;

    destination = destinations->data;
    result = g_strdup (e_destination_get_email (destination));
    g_list_free (destinations);
    return result;
}

GList *
e_select_names_editable_get_emails (ESelectNamesEditable *esne)
{
    EDestinationStore *destination_store;
    GList *destinations;
    EDestination *destination;
    GList *result = NULL;

    g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);

    destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
    destinations = e_destination_store_list_destinations (destination_store);
    if (!destinations)
        return NULL;

    destination = destinations->data;
    if (e_destination_is_evolution_list (destination)) {
        const GList *list_dests, *l;

        list_dests = e_destination_list_get_dests (destination);
        for (l = list_dests; l != NULL; l = g_list_next (l)) {
            result = g_list_append (result, g_strdup (e_destination_get_email (l->data)));
        }
    } else {
        /* check if the contact is contact list, it does not contain all the email ids  */
        /* we dont expand it currently, TODO do we need to expand it by getting it from addressbook*/
        if (e_destination_get_contact (destination) &&
            e_contact_get (e_destination_get_contact (destination), E_CONTACT_IS_LIST)) {
            /* If its a contact_list which is not expanded, it wont have a email id,
               so we can use the name as the email id */

             result = g_list_append (result, g_strdup (e_destination_get_name (destination)));
        } else
             result = g_list_append (result, g_strdup (e_destination_get_email (destination)));
    }

    g_list_free (destinations);

    return result;
}

gchar *
e_select_names_editable_get_name (ESelectNamesEditable *esne)
{
    EDestinationStore *destination_store;
    GList *destinations;
    EDestination *destination;
    gchar *result = NULL;

    g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);

    destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
    destinations = e_destination_store_list_destinations (destination_store);
    if (!destinations)
        return NULL;

    destination = destinations->data;
    result = g_strdup (e_destination_get_name (destination));
    g_list_free (destinations);
    return result;
}

GList *
e_select_names_editable_get_names (ESelectNamesEditable *esne)
{
    EDestinationStore *destination_store;
    GList *destinations;
    EDestination *destination;
    GList *result = NULL;

    g_return_val_if_fail (E_SELECT_NAMES_EDITABLE (esne), NULL);

    destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
    destinations = e_destination_store_list_destinations (destination_store);
    if (!destinations)
        return NULL;

    destination = destinations->data;
    if (e_destination_is_evolution_list (destination)) {
        const GList *list_dests, *l;

        list_dests = e_destination_list_get_dests (destination);
        for (l = list_dests; l != NULL; l = g_list_next (l)) {
            result = g_list_append (result, g_strdup (e_destination_get_name (l->data)));
        }
    } else {
        result = g_list_append (result, g_strdup (e_destination_get_name (destination)));
    }

    g_list_free (destinations);

    return result;
}

void
e_select_names_editable_set_address (ESelectNamesEditable *esne, const gchar *name, const gchar *email)
{
    EDestinationStore *destination_store;
    GList *destinations;
    EDestination *destination;

    g_return_if_fail (E_IS_SELECT_NAMES_EDITABLE (esne));

    destination_store = e_name_selector_entry_peek_destination_store (E_NAME_SELECTOR_ENTRY (esne));
    destinations = e_destination_store_list_destinations (destination_store);

    if (!destinations)
        destination = e_destination_new ();
    else
        destination = g_object_ref (destinations->data);

    e_destination_set_name (destination, name);
    e_destination_set_email (destination, email);

    if (!destinations)
        e_destination_store_append_destination (destination_store, destination);
    g_object_unref (destination);
}