aboutsummaryrefslogtreecommitdiffstats
path: root/ui/evolution-contact-list-editor.xml
blob: 26120557993621a9cb1016bcc34786b77cc7c354 (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
<Root>
        <commands>
        <cmd name="ContactListEditorSave" pixtype="pixbuf" accel="*Control*s"/>
        <cmd name="ContactListEditorSaveAs" pixtype="pixbuf" accel="*Control*v"/>

        <cmd name="ContactListEditorSendAs"/>
        <cmd name="ContactListEditorSendTo"/>

        <cmd name="ContactListEditorDelete"
         _tip="Delete this list"
         pixtype="pixbuf" accel="*Control*d"/>

        <cmd name="ContactListEditorClose"
         pixtype="stock" pixname="Close" accel="*Control*w"/>

        <cmd name="ContactListEditorSaveClose"
         _tip="Save the list and close the dialog box"
         pixtype="pixbuf"/>
    </commands>

    <menu>

        <submenu name="File" _label="_File">

                <menuitem name="ContactListEditorSave" verb="" _label="_Save"/>
                <menuitem name="ContactListEditorSaveClose" verb="" _label="Save and Close" pixtype="pixbuf" accel="*Control*Return"/>

                <menuitem name="ContactListEditorSaveAs" verb="" _label="Save _As..."/>

            <separator/>

                <menuitem name="ContactListEditorDelete" verb="" _label="Delete..." pixtype="pixbuf"/>

            <separator/>

                <menuitem name="ContactListEditorClose" verb=""
            _label="Close"/>

        </submenu>

        <submenu name="Actions" _label="_Actions">
                <menuitem name="ContactListEditorSendAs" verb=""
            _label="Se_nd list to other..."/>

                <menuitem name="ContactListEditorSendTo" verb=""
            _label="Send _message to list..."/>
        </submenu>

    </menu>

    <dockitem name="Toolbar" relief="none" behavior="exclusive"
            hlook="text" vlook="icon">
            <toolitem name="ContactListEditorSaveClose" verb="" _label="Save and Close" priority="1" pixtype="pixbuf"/>

        <separator/>

        <toolitem name="ContactListEditorDelete" verb=""
        _label="Delete" priority="1" />

            <toolitem name="ContactListEditorClose" verb=""
        _label="Close" priority="1" />

    </dockitem>

</Root>
n334'>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
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-select-names-bonobo.c
 *
 * Copyright (C) 2000  Ximian, Inc.
 *
 * 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.
 *
 * Author: Ettore Perazzoli
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include "e-select-names-bonobo.h"
#include "e-simple-card-bonobo.h"

#include <bonobo-activation/bonobo-activation-activate.h>

#include <bonobo/bonobo-property-bag.h>
#include <bonobo/bonobo-control.h>
#include <bonobo/bonobo-exception.h>
#include <bonobo/bonobo-event-source.h>
#include <bonobo/bonobo-ui-util.h>

#include <gal/util/e-util.h>
#include <gal/e-text/e-entry.h>
#include <gal/util/e-text-event-processor.h>

#include "evolution-shell-client.h"

#include "Evolution-Addressbook-SelectNames.h"

#include "e-select-names-manager.h"
#include "e-select-names-model.h"
#include "e-select-names-text-model.h"
#include "e-select-names-completion.h"

#include <string.h>


#define PARENT_TYPE BONOBO_TYPE_OBJECT
static BonoboObjectClass *parent_class = NULL;

struct _ESelectNamesBonoboPrivate {
    ESelectNamesManager *manager;
    BonoboEventSource *event_source;
};

enum _EntryPropertyID {
    ENTRY_PROPERTY_ID_TEXT,
    ENTRY_PROPERTY_ID_ADDRESSES,
    ENTRY_PROPERTY_ID_DESTINATIONS,
    ENTRY_PROPERTY_ID_SIMPLE_CARD_LIST,
    ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS,
    ENTRY_PROPERTY_ID_ENTRY_CHANGED
};
typedef enum _EntryPropertyID EntryPropertyID;


/* PropertyBag implementation for the entry widgets.  */

static void
entry_get_property_fn (BonoboPropertyBag *bag,
               BonoboArg *arg,
               unsigned int arg_id,
               CORBA_Environment *ev,
               void *user_data)
{
    GtkWidget *w;

    w = GTK_WIDGET (user_data);

    switch (arg_id) {
    case ENTRY_PROPERTY_ID_TEXT:
        {
            ETextModel *text_model;
            text_model = E_TEXT_MODEL (g_object_get_data (G_OBJECT (w), "select_names_text_model"));
            g_assert (text_model != NULL);
            
            BONOBO_ARG_SET_STRING (arg, e_text_model_get_text (text_model));
        break;
        }

    case ENTRY_PROPERTY_ID_ADDRESSES:
        {
            ESelectNamesModel *model;
            char *text;

            model = E_SELECT_NAMES_MODEL (g_object_get_data (G_OBJECT (w), "select_names_model"));
            g_assert (model != NULL);

            text = e_select_names_model_get_address_text (model, ", ");
            BONOBO_ARG_SET_STRING (arg, text);
            g_free (text);
        }
        break;

    case ENTRY_PROPERTY_ID_DESTINATIONS:
        {
            ESelectNamesModel *model;
            char *text;

            model = E_SELECT_NAMES_MODEL (g_object_get_data (G_OBJECT (w), "select_names_model"));
            g_assert (model != NULL);

            text = e_select_names_model_export_destinationv (model);
            BONOBO_ARG_SET_STRING (arg, text);
            g_free (text);
        }
        break;

    case ENTRY_PROPERTY_ID_SIMPLE_CARD_LIST:
        {
            ESelectNamesModel *model;
            int count;
            int i;
            GNOME_Evolution_Addressbook_SimpleCardList *card_list;

            model = E_SELECT_NAMES_MODEL (g_object_get_data (G_OBJECT (w), "select_names_model"));
            g_assert (model != NULL);

            count = e_select_names_model_count (model);

            card_list = GNOME_Evolution_Addressbook_SimpleCardList__alloc ();
            card_list->_buffer = CORBA_sequence_GNOME_Evolution_Addressbook_SimpleCard_allocbuf (count);
            card_list->_maximum = count;
            card_list->_length = count;

            for (i = 0; i < count; i++) {
                const EDestination *destination = e_select_names_model_get_destination (model, i);
                const ECard *card = e_destination_get_card (destination);
                ECardSimple *simple = e_card_simple_new ((ECard *) card);
                ESimpleCardBonobo *simple_card = e_simple_card_bonobo_new (simple);
                g_object_unref (simple);

                card_list->_buffer[i] = bonobo_object_corba_objref (BONOBO_OBJECT (simple_card));
            }

            CORBA_free (*(GNOME_Evolution_Addressbook_SimpleCardList **)arg->_value);
            BONOBO_ARG_SET_GENERAL (arg, *card_list, TC_GNOME_Evolution_Addressbook_SimpleCardList, GNOME_Evolution_Addressbook_SimpleCardList, NULL);
        }
        break;

    case ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS:
        {
            ESelectNamesCompletion *comp;
            comp = E_SELECT_NAMES_COMPLETION (g_object_get_data (G_OBJECT (w), "completion_handler"));
            g_assert (comp != NULL);

            BONOBO_ARG_SET_BOOLEAN (arg, e_select_names_completion_get_match_contact_lists (comp));
            break;
        }

    case ENTRY_PROPERTY_ID_ENTRY_CHANGED:
        /* This is a read-only property. */
        g_assert_not_reached ();
        break;

    default:
        break;
    }
}

static void
entry_set_property_fn (BonoboPropertyBag *bag,
               const BonoboArg *arg,
               guint arg_id,
               CORBA_Environment *ev,
               gpointer user_data)
{
    GtkWidget *w;

    w = GTK_WIDGET (user_data);

    switch (arg_id) {

    case ENTRY_PROPERTY_ID_TEXT:
    case ENTRY_PROPERTY_ID_ADDRESSES:
        {
            ESelectNamesModel *model;
            model = E_SELECT_NAMES_MODEL (g_object_get_data (G_OBJECT (w), "select_names_model"));
            g_assert (model != NULL);
            
            e_entry_set_text (E_ENTRY (w), BONOBO_ARG_GET_STRING (arg));
            e_select_names_model_cardify_all (model, NULL, 0);
            break;
        }

    case ENTRY_PROPERTY_ID_DESTINATIONS:
        {
            ESelectNamesModel *model;
            model = E_SELECT_NAMES_MODEL (g_object_get_data (G_OBJECT (w), "select_names_model"));
            g_assert (model != NULL);

            e_select_names_model_import_destinationv (model, BONOBO_ARG_GET_STRING (arg));
            e_select_names_model_cardify_all (model, NULL, 0);
            break;
        }

    case ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS:
        {
            ESelectNamesCompletion *comp;
            comp = E_SELECT_NAMES_COMPLETION (g_object_get_data (G_OBJECT (w), "completion_handler"));
            g_assert (comp != NULL);

            e_select_names_completion_set_match_contact_lists (comp, BONOBO_ARG_GET_BOOLEAN (arg));
            break;
        }
        
    case ENTRY_PROPERTY_ID_ENTRY_CHANGED:
        g_object_set_data (G_OBJECT (w), "entry_property_id_changed", GUINT_TO_POINTER (1));
        break;

    default:
        break;
    }
}

static void
impl_SelectNames_add_section (PortableServer_Servant servant,
                  const CORBA_char *id,
                  const CORBA_char *title,
                  CORBA_Environment *ev)
{
    ESelectNamesBonobo *select_names;
    ESelectNamesBonoboPrivate *priv;

    select_names = E_SELECT_NAMES_BONOBO (bonobo_object (servant));
    priv = select_names->priv;

    e_select_names_manager_add_section (priv->manager, id, title);
}

static void
impl_SelectNames_add_section_with_limit (PortableServer_Servant servant,
                     const CORBA_char *id,
                     const CORBA_char *title,
                     CORBA_short limit,
                     CORBA_Environment *ev)
{
    ESelectNamesBonobo *select_names;
    ESelectNamesBonoboPrivate *priv;

    select_names = E_SELECT_NAMES_BONOBO (bonobo_object (servant));
    priv = select_names->priv;

    e_select_names_manager_add_section_with_limit (priv->manager, id, title, limit);
}

static void
entry_changed (GtkWidget *widget, BonoboControl *control)
{
    gboolean changed = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT (widget), "entry_property_id_changed"));

    if (!changed)
        bonobo_control_set_property (control, NULL, "entry_changed", TC_CORBA_boolean, TRUE, NULL);
}

static void
manager_changed_cb (ESelectNamesManager *manager, const gchar *section_id, gint changed_working_copy, gpointer closure)
{
    ESelectNamesBonobo *select_names = E_SELECT_NAMES_BONOBO (closure);
    BonoboArg *arg;

    arg = bonobo_arg_new (BONOBO_ARG_STRING);
    BONOBO_ARG_SET_STRING (arg, section_id);

    bonobo_event_source_notify_listeners_full (select_names->priv->event_source,
                           "GNOME/Evolution",
                           "changed",
                           changed_working_copy ? "working_copy" : "model",
                           arg, NULL);

    bonobo_arg_release (arg);
}

static void
manager_ok_cb (ESelectNamesManager *manager, gpointer closure)
{
    ESelectNamesBonobo *select_names = E_SELECT_NAMES_BONOBO (closure);
    BonoboArg *arg;

    arg = bonobo_arg_new (BONOBO_ARG_NULL);

    bonobo_event_source_notify_listeners_full (select_names->priv->event_source,
                           "GNOME/Evolution",
                           "ok",
                           "dialog",
                           arg,
                           NULL);

    bonobo_arg_release (arg);
}

static void
copy_cb (BonoboUIComponent *ui, gpointer user_data, const char *command)
{
    EEntry *entry = E_ENTRY (user_data);

    e_text_copy_clipboard (entry->item);
}

static void
cut_cb (BonoboUIComponent *ui, gpointer user_data, const char *command)
{
    EEntry *entry = E_ENTRY (user_data);

    e_text_cut_clipboard (entry->item);
}

static void
paste_cb (BonoboUIComponent *ui, gpointer user_data, const char *command)
{
    EEntry *entry = E_ENTRY (user_data);

    e_text_paste_clipboard (entry->item);
}

static void
select_all_cb (BonoboUIComponent *ui, gpointer user_data, const char *command)
{
    EEntry *entry = E_ENTRY (user_data);

    e_text_select_all (entry->item);
}

static BonoboUIVerb verbs [] = {
    BONOBO_UI_VERB ("EditCut", cut_cb),
    BONOBO_UI_VERB ("EditCopy", copy_cb),
    BONOBO_UI_VERB ("EditPaste", paste_cb),
    BONOBO_UI_VERB ("EditSelectAll", select_all_cb),
    BONOBO_UI_VERB_END
};

typedef struct {
    BonoboControl *control;
    Bonobo_UIContainer remote_ui_container;
    char *ui_xml_path;
    char *app_name;
    BonoboUIVerb *verbs;
    gpointer user_data;
} ControlUIClosure;

static void
free_closure (ControlUIClosure *closure,
          GtkObject *where_object_was)
{
    bonobo_object_release_unref (closure->remote_ui_container, NULL);
    g_free (closure->ui_xml_path);
    g_free (closure->app_name);
    g_free (closure);
}

static void
merge_menu_items (BonoboControl *control, BonoboUIComponent *uic, ControlUIClosure *closure)
{
    if (closure->remote_ui_container) {
        bonobo_ui_component_set_container (uic, closure->remote_ui_container, NULL);

        bonobo_ui_component_add_verb_list_with_data (uic, closure->verbs, closure->user_data);

        bonobo_ui_component_freeze (uic, NULL);

        bonobo_ui_util_set_ui (uic, PREFIX,
                       closure->ui_xml_path,
                       closure->app_name, NULL);

        bonobo_ui_component_thaw (uic, NULL);
    }
}

static void
unmerge_menu_items (BonoboControl *control, BonoboUIComponent *uic, ControlUIClosure *closure)
{
    bonobo_ui_component_unset_container (uic, NULL);
}

static void
control_set_frame_cb (BonoboControl *control,
              ControlUIClosure *closure)
{
    Bonobo_ControlFrame frame = bonobo_control_get_control_frame (control,
                                      NULL);
    if (!frame)
        return;
    closure->remote_ui_container = bonobo_control_get_remote_ui_container (control, NULL);
}

static void
control_activate_cb (BonoboControl *control,
             gboolean activate, 
             ControlUIClosure *closure)
{
    BonoboUIComponent *uic;

    uic = bonobo_control_get_ui_component (control);

    if (activate) {
        merge_menu_items (control, uic, closure);
    } else {
        unmerge_menu_items (control, uic, closure);
    }
}

static gboolean
widget_focus_cb (GtkWidget *w, GdkEventFocus *focus, ControlUIClosure *closure)
{
    control_activate_cb (closure->control, GTK_WIDGET_HAS_FOCUS (w), closure);
    return FALSE;
}

static void
e_bonobo_control_automerge_ui (GtkWidget *w,
                   BonoboControl *control,
                   const char *ui_xml_path,
                   const char *app_name,
                   BonoboUIVerb *verbs,
                   gpointer data)
{
    ControlUIClosure *closure;

    g_return_if_fail (GTK_IS_WIDGET (w));
    g_return_if_fail (BONOBO_IS_CONTROL (control));
    g_return_if_fail (ui_xml_path != NULL);
    g_return_if_fail (app_name != NULL);
    g_return_if_fail (verbs != NULL);
    
    closure = g_new (ControlUIClosure, 1);

    closure->control = control;
    closure->ui_xml_path = g_strdup (ui_xml_path);
    closure->app_name = g_strdup (app_name);
    closure->verbs = verbs;
    closure->user_data = data;

    g_signal_connect (w, "focus_in_event",
              G_CALLBACK (widget_focus_cb), closure);
    g_signal_connect (w, "focus_out_event",
              G_CALLBACK (widget_focus_cb), closure);
    g_signal_connect (control, "set_frame",
              G_CALLBACK (control_set_frame_cb), closure);

    g_object_weak_ref (G_OBJECT (control), (GWeakNotify)free_closure, closure);
}

static Bonobo_Control
impl_SelectNames_get_entry_for_section (PortableServer_Servant servant,
                    const CORBA_char *section_id,
                    CORBA_Environment *ev)
{
    ESelectNamesBonobo *select_names;
    ESelectNamesBonoboPrivate *priv;
    GtkWidget *entry_widget;
    BonoboControl *control;
    BonoboPropertyBag *property_bag;

    select_names = E_SELECT_NAMES_BONOBO (bonobo_object (servant));
    priv = select_names->priv;

    entry_widget = e_select_names_manager_create_entry (priv->manager, section_id);
    gtk_widget_show (entry_widget);
    
    if (entry_widget == NULL) {
        CORBA_exception_set (ev,
                     CORBA_USER_EXCEPTION,
                     ex_GNOME_Evolution_Addressbook_SelectNames_SectionNotFound,
                     NULL);
        return CORBA_OBJECT_NIL;
    }

    control = bonobo_control_new (entry_widget);

    property_bag = bonobo_property_bag_new (entry_get_property_fn, entry_set_property_fn, entry_widget);
    bonobo_property_bag_add (property_bag, "text", ENTRY_PROPERTY_ID_TEXT,
                 BONOBO_ARG_STRING, NULL, NULL,
                 BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE);
    bonobo_property_bag_add (property_bag, "addresses", ENTRY_PROPERTY_ID_ADDRESSES,
                 BONOBO_ARG_STRING, NULL, NULL,
                 BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE);
    bonobo_property_bag_add (property_bag, "destinations", ENTRY_PROPERTY_ID_DESTINATIONS,
                 BONOBO_ARG_STRING, NULL, NULL,
                 BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE);
    bonobo_property_bag_add (property_bag, "simple_card_list", ENTRY_PROPERTY_ID_SIMPLE_CARD_LIST,
                 TC_GNOME_Evolution_Addressbook_SimpleCardList, NULL, NULL,
                 BONOBO_PROPERTY_READABLE);
    bonobo_property_bag_add (property_bag, "allow_contact_lists", ENTRY_PROPERTY_ID_ALLOW_CONTACT_LISTS,
                 BONOBO_ARG_BOOLEAN, NULL, NULL,
                 BONOBO_PROPERTY_READABLE | BONOBO_PROPERTY_WRITEABLE);
    bonobo_property_bag_add (property_bag, "entry_changed", ENTRY_PROPERTY_ID_ENTRY_CHANGED,
                 BONOBO_ARG_BOOLEAN, NULL, NULL,
                 BONOBO_PROPERTY_WRITEABLE);

    bonobo_control_set_properties (control, bonobo_object_corba_objref (BONOBO_OBJECT (property_bag)), NULL);
    bonobo_object_unref (BONOBO_OBJECT (property_bag));

    g_signal_connect (entry_widget, "changed", G_CALLBACK (entry_changed), control);

    e_bonobo_control_automerge_ui (GTK_WIDGET (E_ENTRY (entry_widget)->canvas),
                       control,
                       EVOLUTION_UIDIR "/evolution-composer-entries.xml",
                       "evolution-addressbook",
                       verbs, entry_widget);

    return CORBA_Object_duplicate (bonobo_object_corba_objref (BONOBO_OBJECT (control)), ev);
}

static void