~ubuntu-branches/ubuntu/maverick/evolution-data-server/maverick-proposed

« back to all changes in this revision

Viewing changes to addressbook/libedata-book/e-book-backend.c

  • Committer: Bazaar Package Importer
  • Author(s): Didier Roche
  • Date: 2010-05-17 17:02:06 UTC
  • mfrom: (1.1.79 upstream) (1.6.12 experimental)
  • Revision ID: james.westby@ubuntu.com-20100517170206-4ufr52vwrhh26yh0
Tags: 2.30.1-1ubuntu1
* Merge from debian experimental. Remaining change:
  (LP: #42199, #229669, #173703, #360344, #508494)
  + debian/control:
    - add Vcs-Bzr tag
    - don't use libgnome
    - Use Breaks instead of Conflicts against evolution 2.25 and earlier.
  + debian/evolution-data-server.install,
    debian/patches/45_libcamel_providers_version.patch:
    - use the upstream versioning, not a Debian-specific one 
  + debian/libedata-book1.2-dev.install, debian/libebackend-1.2-dev.install,
    debian/libcamel1.2-dev.install, debian/libedataserverui1.2-dev.install:
    - install html documentation
  + debian/rules:
    - don't build documentation it's shipped with the tarball

Show diffs side-by-side

added added

removed removed

Lines of Context:
9
9
#include <config.h>
10
10
 
11
11
#include "e-data-book-view.h"
 
12
#include "e-data-book.h"
12
13
#include "e-book-backend.h"
13
14
 
 
15
G_DEFINE_TYPE (EBookBackend, e_book_backend, G_TYPE_OBJECT)
 
16
 
14
17
struct _EBookBackendPrivate {
15
18
        GMutex *open_mutex;
16
19
 
40
43
 *
41
44
 * Does nothing.
42
45
 *
43
 
 * Return value: %TRUE.
 
46
 * Returns: %TRUE.
44
47
 **/
45
48
gboolean
46
49
e_book_backend_construct (EBookBackend *backend)
56
59
 *
57
60
 * Loads @source into @backend.
58
61
 *
59
 
 * Return value: A #GNOME_Evolution_Addressbook_CallStatus indicating the outcome.
 
62
 * Returns: A #GNOME_Evolution_Addressbook_CallStatus indicating the outcome.
60
63
 **/
61
64
GNOME_Evolution_Addressbook_CallStatus
62
65
e_book_backend_load_source (EBookBackend           *backend,
87
90
 *
88
91
 * Queries the source that an addressbook backend is serving.
89
92
 *
90
 
 * Return value: ESource for the backend.
 
93
 * Returns: ESource for the backend.
91
94
 **/
92
95
ESource *
93
96
e_book_backend_get_source (EBookBackend *backend)
119
122
        g_mutex_lock (backend->priv->open_mutex);
120
123
 
121
124
        if (backend->priv->loaded) {
 
125
                e_data_book_report_writable (book, backend->priv->writable);
 
126
                e_data_book_report_connection_status (book, backend->priv->online);
 
127
 
122
128
                e_data_book_respond_open (
123
129
                        book, opid, GNOME_Evolution_Addressbook_Success);
124
 
 
125
 
                e_data_book_report_writable (book, backend->priv->writable);
126
 
                e_data_book_report_connection_status (book, backend->priv->online);
127
130
        } else {
128
131
                GNOME_Evolution_Addressbook_CallStatus status =
129
132
                        e_book_backend_load_source (backend, e_data_book_get_source (book), only_if_exists);
130
133
 
131
 
                e_data_book_respond_open (book, opid, status);
132
 
 
133
134
                if (status == GNOME_Evolution_Addressbook_Success || status == GNOME_Evolution_Addressbook_InvalidServerVersion)
134
135
                        e_data_book_report_writable (book, backend->priv->writable);
135
136
                        e_data_book_report_connection_status (book, backend->priv->online);
 
137
 
 
138
                e_data_book_respond_open (book, opid, status);
136
139
        }
137
140
 
138
141
        g_mutex_unlock (backend->priv->open_mutex);
454
457
 *
455
458
 * Cancel @book's running operation on @backend.
456
459
 *
457
 
 * Return value: A GNOME_Evolution_Addressbook_CallStatus indicating the outcome.
 
460
 * Returns: A GNOME_Evolution_Addressbook_CallStatus indicating the outcome.
458
461
 **/
459
462
GNOME_Evolution_Addressbook_CallStatus
460
463
e_book_backend_cancel_operation (EBookBackend *backend,
469
472
}
470
473
 
471
474
static void
472
 
book_destroy_cb (gpointer data, GObject *where_book_was)
473
 
{
474
 
        EBookBackend *backend = E_BOOK_BACKEND (data);
475
 
 
476
 
        e_book_backend_remove_client (backend, (EDataBook *)where_book_was);
477
 
}
478
 
 
479
 
static gboolean
480
 
idle_remove_client (gpointer data)
481
 
{
482
 
        EDataBook *book = (EDataBook *) data;
483
 
 
484
 
        e_book_backend_remove_client (e_data_book_get_backend (book), book);
485
 
        g_object_unref ((GObject *) book);
486
 
 
487
 
        return FALSE;
488
 
}
489
 
static void
490
 
listener_died_cb (gpointer cnx, gpointer user_data)
491
 
{
492
 
        g_object_ref ((GObject *)user_data);
493
 
        g_idle_add (idle_remove_client, user_data);
494
 
}
495
 
 
496
 
static void
497
475
last_client_gone (EBookBackend *backend)
498
476
{
499
477
        g_signal_emit (backend, e_book_backend_signals[LAST_CLIENT_GONE], 0);
505
483
 *
506
484
 * Gets the list of #EDataBookView views running on this backend.
507
485
 *
508
 
 * Return value: An #EList of #EDataBookView objects.
 
486
 * Returns: An #EList of #EDataBookView objects.
509
487
 **/
510
488
EList*
511
489
e_book_backend_get_book_views (EBookBackend *backend)
562
540
 *
563
541
 * Adds a client to an addressbook backend.
564
542
 *
565
 
 * Return value: TRUE on success, FALSE on failure to add the client.
 
543
 * Returns: TRUE on success, FALSE on failure to add the client.
566
544
 */
567
545
gboolean
568
546
e_book_backend_add_client (EBookBackend      *backend,
571
549
        g_return_val_if_fail (E_IS_BOOK_BACKEND (backend), FALSE);
572
550
        g_return_val_if_fail (E_IS_DATA_BOOK (book), FALSE);
573
551
 
574
 
        bonobo_object_set_immortal (BONOBO_OBJECT (book), TRUE);
575
 
 
576
 
        g_object_weak_ref (G_OBJECT (book), book_destroy_cb, backend);
577
 
 
578
 
        ORBit_small_listen_for_broken (e_data_book_get_listener (book), G_CALLBACK (listener_died_cb), book);
579
 
 
580
552
        g_mutex_lock (backend->priv->clients_mutex);
581
553
        backend->priv->clients = g_list_prepend (backend->priv->clients, book);
582
554
        g_mutex_unlock (backend->priv->clients_mutex);
624
596
 *
625
597
 * Checks if @backend has clients running in other system processes.
626
598
 *
627
 
 * Return value: %TRUE if there are clients in other processes, %FALSE otherwise.
 
599
 * Returns: %TRUE if there are clients in other processes, %FALSE otherwise.
628
600
 **/
629
601
gboolean
630
602
e_book_backend_has_out_of_proc_clients (EBookBackend *backend)
631
603
{
632
 
        GList *l;
633
 
 
634
 
        g_mutex_lock (backend->priv->clients_mutex);
635
 
 
636
 
        if (!backend->priv->clients) {
637
 
                g_mutex_unlock (backend->priv->clients_mutex);
638
 
 
639
 
                return FALSE;
640
 
        }
641
 
 
642
 
        for (l = backend->priv->clients; l; l = l->next) {
643
 
                if (ORBit_small_get_connection_status (e_data_book_get_listener (l->data)) != ORBIT_CONNECTION_IN_PROC) {
644
 
                        g_mutex_unlock (backend->priv->clients_mutex);
645
 
 
646
 
                        return TRUE;
647
 
                }
648
 
        }
649
 
 
650
 
        g_mutex_unlock (backend->priv->clients_mutex);
651
 
 
652
 
        /* If we get here, all remaining clients are in proc */
653
 
 
654
 
        return FALSE;
 
604
        return TRUE;
655
605
}
656
606
 
657
607
/**
660
610
 *
661
611
 * Gets the capabilities offered by this @backend.
662
612
 *
663
 
 * Return value: A string listing the capabilities.
 
613
 * Returns: A string listing the capabilities.
664
614
 **/
665
615
gchar *
666
616
e_book_backend_get_static_capabilities (EBookBackend *backend)
679
629
 * Checks if @backend's storage has been opened and the backend
680
630
 * itself is ready for accessing.
681
631
 *
682
 
 * Return value: %TRUE if loaded, %FALSE otherwise.
 
632
 * Returns: %TRUE if loaded, %FALSE otherwise.
683
633
 **/
684
634
gboolean
685
635
e_book_backend_is_loaded (EBookBackend *backend)
711
661
 *
712
662
 * Checks if we can write to @backend.
713
663
 *
714
 
 * Return value: %TRUE if writeable, %FALSE if not.
 
664
 * Returns: %TRUE if writeable, %FALSE if not.
715
665
 **/
716
666
gboolean
717
667
e_book_backend_is_writable (EBookBackend *backend)
743
693
 *
744
694
 * Checks if @backend has been removed from its physical storage.
745
695
 *
746
 
 * Return value: %TRUE if @backend has been removed, %FALSE otherwise.
 
696
 * Returns: %TRUE if @backend has been removed, %FALSE otherwise.
747
697
 **/
748
698
gboolean
749
699
e_book_backend_is_removed (EBookBackend *backend)
796
746
 * Write all pending data to disk.  This is only required under special
797
747
 * circumstances (for example before a live backup) and should not be used in
798
748
 * normal use.
 
749
 *
 
750
 * Since: 1.12
799
751
 */
800
752
void
801
753
e_book_backend_sync (EBookBackend *backend)
813
765
 * Creates a new change item indicating @vcard was added.
814
766
 * Meant to be used by backend implementations.
815
767
 *
816
 
 * Return value: A new #GNOME_Evolution_Addressbook_BookChangeItem.
 
768
 * Returns: A new #GNOME_Evolution_Addressbook_BookChangeItem.
817
769
 **/
818
 
GNOME_Evolution_Addressbook_BookChangeItem*
 
770
EDataBookChange *
819
771
e_book_backend_change_add_new     (const gchar *vcard)
820
772
{
821
 
        GNOME_Evolution_Addressbook_BookChangeItem* new_change = GNOME_Evolution_Addressbook_BookChangeItem__alloc();
 
773
  EDataBookChange *new_change = g_new (EDataBookChange, 1);
822
774
 
823
 
        new_change->changeType= GNOME_Evolution_Addressbook_ContactAdded;
824
 
        new_change->vcard = CORBA_string_dup (vcard);
 
775
        new_change->change_type = E_DATA_BOOK_BACKEND_CHANGE_ADDED;
 
776
        new_change->vcard = g_strdup (vcard);
825
777
 
826
778
        return new_change;
827
779
}
833
785
 * Creates a new change item indicating @vcard was modified.
834
786
 * Meant to be used by backend implementations.
835
787
 *
836
 
 * Return value: A new #GNOME_Evolution_Addressbook_BookChangeItem.
 
788
 * Returns: A new #GNOME_Evolution_Addressbook_BookChangeItem.
837
789
 **/
838
 
GNOME_Evolution_Addressbook_BookChangeItem*
 
790
EDataBookChange *
839
791
e_book_backend_change_modify_new  (const gchar *vcard)
840
792
{
841
 
        GNOME_Evolution_Addressbook_BookChangeItem* new_change = GNOME_Evolution_Addressbook_BookChangeItem__alloc();
 
793
  EDataBookChange *new_change = g_new (EDataBookChange, 1);
842
794
 
843
 
        new_change->changeType= GNOME_Evolution_Addressbook_ContactModified;
844
 
        new_change->vcard = CORBA_string_dup (vcard);
 
795
        new_change->change_type = E_DATA_BOOK_BACKEND_CHANGE_MODIFIED;
 
796
        new_change->vcard = g_strdup (vcard);
845
797
 
846
798
        return new_change;
847
799
}
853
805
 * Creates a new change item indicating @vcard was deleted.
854
806
 * Meant to be used by backend implementations.
855
807
 *
856
 
 * Return value: A new #GNOME_Evolution_Addressbook_BookChangeItem.
 
808
 * Returns: A new #GNOME_Evolution_Addressbook_BookChangeItem.
857
809
 **/
858
 
GNOME_Evolution_Addressbook_BookChangeItem*
 
810
EDataBookChange *
859
811
e_book_backend_change_delete_new  (const gchar *vcard)
860
812
{
861
 
        GNOME_Evolution_Addressbook_BookChangeItem* new_change = GNOME_Evolution_Addressbook_BookChangeItem__alloc();
 
813
  EDataBookChange *new_change = g_new (EDataBookChange, 1);
862
814
 
863
 
        new_change->changeType= GNOME_Evolution_Addressbook_ContactDeleted;
864
 
        new_change->vcard = CORBA_string_dup (vcard);
 
815
        new_change->change_type = E_DATA_BOOK_BACKEND_CHANGE_DELETED;
 
816
        new_change->vcard = g_strdup (vcard);
865
817
 
866
818
        return new_change;
867
819
}
1099
1051
                              g_cclosure_marshal_VOID__VOID,
1100
1052
                              G_TYPE_NONE, 0);
1101
1053
}
1102
 
 
1103
 
/**
1104
 
 * e_book_backend_get_type:
1105
 
 */
1106
 
GType
1107
 
e_book_backend_get_type (void)
1108
 
{
1109
 
        static GType type = 0;
1110
 
 
1111
 
        if (! type) {
1112
 
                GTypeInfo info = {
1113
 
                        sizeof (EBookBackendClass),
1114
 
                        NULL, /* base_class_init */
1115
 
                        NULL, /* base_class_finalize */
1116
 
                        (GClassInitFunc)  e_book_backend_class_init,
1117
 
                        NULL, /* class_finalize */
1118
 
                        NULL, /* class_data */
1119
 
                        sizeof (EBookBackend),
1120
 
                        0,    /* n_preallocs */
1121
 
                        (GInstanceInitFunc) e_book_backend_init
1122
 
                };
1123
 
 
1124
 
                type = g_type_register_static (G_TYPE_OBJECT, "EBookBackend", &info, 0);
1125
 
        }
1126
 
 
1127
 
        return type;
1128
 
}