/* Callback used when a backend loses its last connected client */ static void backend_last_client_gone_cb (EBookBackend *backend, gpointer data) { EDataBookFactory *factory; ESource *source; gchar *uri; factory = E_DATA_BOOK_FACTORY (data); /* Remove the backend from the active server map */ source = e_book_backend_get_source (backend); if (source) uri = e_source_get_uri (source); else uri = NULL; if (uri) { g_mutex_lock (factory->priv->map_mutex); g_hash_table_remove (factory->priv->active_server_map, uri); g_mutex_unlock (factory->priv->map_mutex); } if (g_hash_table_size (factory->priv->active_server_map) == 0) { /* Notify upstream if there are no more backends */ g_signal_emit (G_OBJECT (factory), factory_signals[LAST_BOOK_GONE], 0); } g_free (uri); }
GtkWidget * e_book_file_dummy (EPlugin *epl, EConfigHookItemFactoryData *data) { EABConfigTargetSource *t = (EABConfigTargetSource *) data->target; ESource *source = t->source; gchar *uri_text; const gchar *relative_uri; uri_text = e_source_get_uri (source); if (strncmp (uri_text, "file", 4)) { g_free (uri_text); return NULL; } relative_uri = e_source_peek_relative_uri (source); g_free (uri_text); if (relative_uri && *relative_uri) { return NULL; } e_source_set_relative_uri (source, e_source_peek_uid (source)); return NULL; }
static void process_removal_in_hash (const gchar *uri, gpointer value, ProcessRemovalsData *prd) { GSList *groups, *sources, *p, *q; gboolean found = FALSE; /* search the list of selected calendars */ groups = e_source_list_peek_groups (prd->source_list); for (p = groups; p != NULL; p = p->next) { ESourceGroup *group = E_SOURCE_GROUP (p->data); sources = e_source_group_peek_sources (group); for (q = sources; q != NULL; q = q->next) { ESource *source = E_SOURCE (q->data); gchar *source_uri; const gchar *completion = e_source_get_property (source, "alarm"); source_uri = e_source_get_uri (source); if (strcmp (source_uri, uri) == 0) if (!completion || !g_ascii_strcasecmp (completion, "true")) found = TRUE; g_free (source_uri); if (found) return; } } /* not found, so list it for removal */ prd->removals = g_list_prepend (prd->removals, (gpointer) uri); }
static void unsubscribe_dialog_ab_response (GtkDialog *dialog, int response, gpointer data) { if (response == GTK_RESPONSE_OK) { ExchangeAccount *account = NULL; gchar *path = NULL; gchar *uri = NULL; const char *source_uid = NULL; ESourceGroup *source_group = NULL; ESource *source = NULL; EABPopupTargetSource *target = data; account = exchange_operations_get_exchange_account (); if (!account) return; source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector)); uri = e_source_get_uri (source); path = g_strdup (uri + strlen ("exchange://") + strlen (account->account_filename)); source_uid = e_source_peek_uid (source); exchange_account_remove_shared_folder (account, path); source_group = e_source_peek_group (source); e_source_group_remove_source_by_uid (source_group, source_uid); g_free (path); gtk_widget_destroy (GTK_WIDGET (dialog)); } if (response == GTK_RESPONSE_CANCEL) gtk_widget_destroy (GTK_WIDGET (dialog)); if (response == GTK_RESPONSE_DELETE_EVENT) gtk_widget_destroy (GTK_WIDGET (dialog)); }
GList * evo_environment_list_cal_sources(ECalSourceType type) { GList *paths = NULL; ESourceList *sources = NULL; ESource *source = NULL; if (!e_cal_get_sources(&sources, type, NULL)) { return NULL; } GSList *g = NULL; for (g = e_source_list_peek_groups (sources); g; g = g->next) { ESourceGroup *group = E_SOURCE_GROUP (g->data); GSList *s = NULL; for (s = e_source_group_peek_sources (group); s; s = s->next) { source = E_SOURCE (s->data); evo_location_t *path = g_malloc0(sizeof(evo_location_t)); //FIXME: Word around #442187 //if (!first) { // first = TRUE; // path->uri = g_strdup("default"); //} else { path->uri = g_strdup(e_source_get_uri(source)); //} path->name = g_strdup(e_source_peek_name(source)); paths = g_list_append(paths, path); } } return paths; }
static gboolean is_eex_source_selected (EShellView *shell_view, gchar **puri) { gint mode; ExchangeAccount *account = NULL; ESource *source = NULL; gchar *uri = NULL; EShellSidebar *shell_sidebar; ESourceSelector *selector = NULL; shell_sidebar = e_shell_view_get_shell_sidebar (shell_view); g_return_val_if_fail (shell_sidebar != NULL, FALSE); g_object_get (shell_sidebar, "selector", &selector, NULL); g_return_val_if_fail (selector != NULL, FALSE); source = e_source_selector_ref_primary_selection (selector); if (source != NULL) { uri = e_source_get_uri (source); g_object_unref (source); } g_object_unref (selector); if (!uri || !g_strrstr (uri, "exchange://")) { g_free (uri); return FALSE; } account = exchange_operations_get_exchange_account (); if (!account) { g_free (uri); return FALSE; } exchange_account_is_offline (account, &mode); if (mode == OFFLINE_MODE) { g_free (uri); return FALSE; } if (!exchange_account_get_folder (account, uri)) { g_free (uri); return FALSE; } if (puri) *puri = uri; else g_free (uri); return TRUE; }
static GSList *traverse_sources(GSList *ebooks, GSList *sources, char **default_src) { GError *gerr = NULL; for (; sources != NULL; sources = g_slist_next(sources)) { char *uri; ESource *source = E_SOURCE(sources->data); EBook *ebook = e_book_new(source, &gerr); if (ebook == NULL) { error("Can't create user's address book: %s", gerr->message); g_clear_error(&gerr); continue; } uri = e_source_get_uri(source); if (g_strcmp0(*default_src, uri) == 0) { g_free(uri); continue; } g_free(uri); if (e_book_open(ebook, FALSE, &gerr) == FALSE) { error("Can't open e-book address book: %s", gerr->message); g_object_unref(ebook); g_clear_error(&gerr); continue; } if (*default_src == NULL) *default_src = e_source_get_uri(source); DBG("%s address book opened", e_source_peek_name(source)); ebooks = g_slist_append(ebooks, ebook); } return ebooks; }
ESource * evo_environment_find_source(ESourceList *list, const char *uri) { GSList *g; for (g = e_source_list_peek_groups (list); g; g = g->next) { ESourceGroup *group = E_SOURCE_GROUP (g->data); GSList *s; for (s = e_source_group_peek_sources (group); s; s = s->next) { ESource *source = E_SOURCE (s->data); if (!strcmp(e_source_get_uri(source), uri)) return source; } } return NULL; }
static ESource * get_source (ESourceList *list) { CamelURL *url; gchar *url_string; GSList *p, *l; gchar **temp; gchar *uri; /* FIXME Wow... just... wow. If ever one needed proof that * URL-based accounts were a bad idea, here ya go. */ url = g_malloc0 (sizeof (CamelURL)); camel_settings_save_to_url (settings, url); url_string = camel_url_to_string (url, 0); temp = g_strsplit (url_string, ";", -1); g_free (url_string); camel_url_free (url); uri = temp[0]; l = e_source_list_peek_groups (list); for (p = l; p != NULL; p = p->next) { gchar *so_uri; GSList *r, *s; ESourceGroup *group = E_SOURCE_GROUP (p->data); s = e_source_group_peek_sources (group); for (r = s; r != NULL; r = r->next) { ESource *so = E_SOURCE (r->data); so_uri = e_source_get_uri (so); if (so_uri) { if (!strcmp (so_uri, uri)) { g_free (so_uri), so_uri = NULL; g_strfreev (temp); return E_SOURCE (r->data); } g_free (so_uri), so_uri = NULL; } } } g_strfreev (temp); return NULL; }
static void addressbook_authenticate (EBook *book, gpointer data) { gchar *auth; gchar *user; gchar *passwd; gchar *str_uri; gchar *pass_key; gchar *auth_domain; gchar *component_name; EUri *e_uri; ESource *source = (ESource *)data; auth = (gchar *)e_source_get_property (source, "auth"); auth_domain = (gchar *)e_source_get_property (source, "auth-domain"); component_name = auth_domain ? auth_domain : "Addressbook"; if (auth && !strcmp ("plain/password", auth)) user = (gchar *)e_source_get_property (source, "user"); else user = (gchar *)e_source_get_property (source, "email_addr"); if (!user) user = ""; str_uri = e_source_get_uri (source); e_uri = e_uri_new (str_uri); pass_key = e_uri_to_string (e_uri, FALSE); e_uri_free (e_uri); passwd = e_passwords_get_password (component_name, pass_key); if (passwd) passwd = ""; if (book) if (!e_book_authenticate_user (book, user, passwd, auth, NULL)) LOG (g_warning ("Authentication failed")); g_free (pass_key); g_free (str_uri); return; }
static void dump_source (ESource *source) { gchar *uri = e_source_get_uri (source); const gchar *color_spec; g_print ("\tSource %s\n", e_source_peek_uid (source)); g_print ("\t\tname: %s\n", e_source_peek_name (source)); g_print ("\t\trelative_uri: %s\n", e_source_peek_relative_uri (source)); g_print ("\t\tabsolute_uri: %s\n", uri); color_spec = e_source_peek_color_spec (source); if (color_spec != NULL) g_print ("\t\tcolor: %s\n", color_spec); g_print ("\t\tproperties:\n"); e_source_foreach_property (source, (GHFunc) dump_property, NULL); g_free (uri); }
static void alarm_notify_load_calendars (AlarmNotify *an, ECalSourceType source_type) { ESourceList *source_list; GSList *groups, *sources, *p, *q; if (!e_cal_get_sources (&source_list, source_type, NULL)) { d (printf("%s:%d (load_calendars) - Cannont get sources\n ", __FILE__, __LINE__)); an->priv->source_lists[source_type] = NULL; return; } groups = e_source_list_peek_groups (source_list); for (p = groups; p != NULL; p = p->next) { ESourceGroup *group = E_SOURCE_GROUP (p->data); sources = e_source_group_peek_sources (group); for (q = sources; q != NULL; q = q->next) { ESource *source = E_SOURCE (q->data); gchar *uri; const gchar *completion = e_source_get_property (source, "alarm"); if (completion && (!g_ascii_strcasecmp (completion, "false") || !g_ascii_strcasecmp (completion, "never"))) continue; uri = e_source_get_uri (source); d (printf("%s:%d (load_calendars) - Loading Calendar %s \n", __FILE__, __LINE__, uri)); alarm_notify_add_calendar (an, source_type, source, FALSE); g_free (uri); } } g_signal_connect_object ( source_list, "changed", G_CALLBACK (alarm_notify_list_changed_cb), an, 0); an->priv->source_lists[source_type] = source_list; }
void org_gnome_exchange_check_address_book_subscribed (EPlugin *ep, EABPopupTargetSource *target) { GSList *menus = NULL; int i = 0; ESource *source = NULL; gchar *uri = NULL; gchar *path = NULL; char *sub_folder = NULL; const char *base_uri; ExchangeAccount *account = NULL; ESourceGroup *group; account = exchange_operations_get_exchange_account (); if (!account) return; source = e_source_selector_peek_primary_selection (E_SOURCE_SELECTOR (target->selector)); group = e_source_peek_group (source); base_uri = e_source_group_peek_base_uri (group); if (!base_uri || strcmp (base_uri, "exchange://")) return; uri = e_source_get_uri (source); path = g_strdup (uri + strlen ("exchange://") + strlen (account->account_filename) + strlen ("/;")); g_free (uri); sub_folder = strchr (path, '@'); if (!sub_folder) { g_free (path); return; } for (i = 0; i < sizeof (popup_ab_items) / sizeof (popup_ab_items[0]); i++) menus = g_slist_prepend (menus, &popup_ab_items[i]); e_popup_add_items (target->target.popup, menus, NULL, popup_ab_free, target); g_free (path); }
static void alarm_notify_list_changed_cb (ESourceList *source_list, AlarmNotify *an) { GSList *groups, *sources, *p, *q; ECalSourceType source_type = E_CAL_SOURCE_TYPE_LAST; ProcessRemovalsData prd; GList *l; gint i; g_signal_handlers_block_by_func ( source_list, alarm_notify_list_changed_cb, an); /* Figure out the source type */ for (i = 0; i < E_CAL_SOURCE_TYPE_LAST; i++) { if (source_list == an->priv->source_lists[i]) { source_type = i; break; } } if (source_type == E_CAL_SOURCE_TYPE_LAST) return; /* process the additions */ groups = e_source_list_peek_groups (source_list); for (p = groups; p != NULL; p = p->next) { ESourceGroup *group = E_SOURCE_GROUP (p->data); sources = e_source_group_peek_sources (group); for (q = sources; q != NULL; q = q->next) { ESource *source = E_SOURCE (q->data); gchar *uri; const gchar *completion = e_source_get_property (source, "alarm"); if (completion && (!g_ascii_strcasecmp (completion, "false") || !g_ascii_strcasecmp (completion, "never"))) continue; uri = e_source_get_uri (source); if (!g_hash_table_lookup (an->priv->uri_client_hash[source_type], uri)) { d (printf("%s:%d (list_changed_cb) - Adding Calendar %s\n", __FILE__, __LINE__, uri)); alarm_notify_add_calendar (an, source_type, source, FALSE); } g_free (uri); } } /* process the removals */ prd.an = an; prd.source_list = an->priv->source_lists[source_type]; prd.removals = NULL; g_hash_table_foreach (an->priv->uri_client_hash[source_type], (GHFunc) process_removal_in_hash, &prd); for (l = prd.removals; l; l = l->next) { d (printf("%s:%d (list_changed_cb) - Removing Calendar %s\n", __FILE__, __LINE__, (gchar *)l->data)); alarm_notify_remove_calendar (an, source_type, l->data); } g_list_free (prd.removals); g_signal_handlers_unblock_by_func ( source_list, alarm_notify_list_changed_cb, an); }
static GtkDialog * create_store_view_dialog (ESource * source) { GtkWidget *dialog; GtkWidget *swin; GtkWidget *tree_view; GtkTreeSelection *selection; ScalixStoreModel *model; GtkTreeViewColumn *column; GtkCellRenderer *cell; char *text_uri; dialog = gtk_dialog_new_with_buttons (_("Select a location"), NULL, GTK_DIALOG_MODAL, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_container_set_border_width (GTK_CONTAINER (dialog), 6); /* Scrolled window */ swin = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (swin), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); gtk_widget_show (swin); /* ScalixStoreModel aka TreeModel */ text_uri = e_source_get_uri (source); model = scalix_store_model_new (text_uri); /* Treeview */ tree_view = gtk_tree_view_new_with_model (GTK_TREE_MODEL (model)); g_object_set_data (G_OBJECT (dialog), "treeview", tree_view); gtk_tree_view_set_headers_visible (GTK_TREE_VIEW (tree_view), FALSE); gtk_widget_show (tree_view); gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (swin), tree_view); gtk_widget_add_events (tree_view, GDK_BUTTON_PRESS); column = gtk_tree_view_column_new (); /* the icon */ cell = gtk_cell_renderer_pixbuf_new (); gtk_tree_view_column_pack_start (column, cell, FALSE); gtk_tree_view_column_set_attributes (column, cell, "pixbuf", SCM_COL_ICON, NULL); /* the text */ cell = gtk_cell_renderer_text_new (); gtk_tree_view_column_pack_start (column, cell, FALSE); gtk_tree_view_column_set_attributes (column, cell, "text", SCM_COL_NAME, NULL); gtk_tree_view_append_column (GTK_TREE_VIEW (tree_view), column); /* Selection mode of the treeview */ selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (tree_view)); gtk_tree_selection_set_mode (selection, GTK_SELECTION_BROWSE); g_signal_connect (G_OBJECT (selection), "changed", G_CALLBACK (selection_changed), source); g_signal_connect (G_OBJECT (model), "loaded", G_CALLBACK (model_loaded), tree_view); /* Put everthing together */ gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), swin); gtk_container_set_border_width (GTK_CONTAINER (swin), 6); gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 6); gtk_window_set_default_size (GTK_WINDOW (dialog), 420, 340); return GTK_DIALOG (dialog); }
static GtkWidget * sx_config_source_setup_ui (GtkWidget * parent, ESource * source) { GtkWidget *button; GtkWidget *label; GtkWidget *text; GtkWidget *ret; char *uri_text; const char *uid; const char *ruri; const char *name; gboolean new_source; gulong *sig_id; uri_text = e_source_get_uri (source); if (!g_str_has_prefix (uri_text, "scalix")) { g_free (uri_text); return NULL; } g_free (uri_text); g_assert (GTK_IS_BOX (parent) || GTK_IS_TABLE (parent)); /* Label */ label = gtk_label_new_with_mnemonic (_("_Location:")); gtk_widget_show (label); gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.5); button = gtk_button_new (); g_signal_connect (G_OBJECT (button), "clicked", G_CALLBACK (location_clicked), source); gtk_widget_show (button); uid = e_source_peek_uid (source); ruri = e_source_peek_relative_uri (source); name = e_source_peek_name (source); /* new source */ new_source = (ruri == NULL || ruri[0] == '\0' || g_str_equal (ruri, uid)); if (new_source) { if (name == NULL || name[0] == '\0') name = "nonameyet"; e_source_set_relative_uri (source, name); } if (is_toplevel (ruri)) { text = gtk_label_new (_("Toplevel")); } else { text = gtk_label_new (ruri); } gtk_widget_show (text); #if (GTK_CHECK_VERSION(2, 6, 0)) gtk_label_set_ellipsize (GTK_LABEL (text), PANGO_ELLIPSIZE_START); #endif gtk_container_add (GTK_CONTAINER (button), text); sig_id = (gulong *) g_malloc0 (sizeof (gulong)); *sig_id = g_signal_connect (source, "changed", G_CALLBACK (sn_changed), sig_id); /* We do not support renames (yet?!) */ if (new_source == FALSE) { gtk_widget_set_sensitive (button, FALSE); /* Nasty nasty hack ey ey ey */ find_entries_and_set_sensitive (parent, FALSE); } /* attach it */ if (!GTK_IS_BOX (parent)) { int row; row = GTK_TABLE (parent)->nrows; gtk_table_attach (GTK_TABLE (parent), label, 0, 1, row, row + 1, GTK_FILL, 0, 0, 0); gtk_table_attach (GTK_TABLE (parent), button, 1, 2, row, row + 1, GTK_EXPAND | GTK_FILL, 0, 0, 0); /* HACK for to have a return value != NULL */ ret = button; } else { GtkWidget *hbox; hbox = gtk_hbox_new (FALSE, 6); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, TRUE, 6); gtk_box_pack_start (GTK_BOX (hbox), button, TRUE, TRUE, 6); gtk_box_pack_start (GTK_BOX (parent), hbox, FALSE, FALSE, 6); gtk_widget_show_all (hbox); ret = hbox; } return ret; }
/* The following function taken from gnome clock-applet * (gnome-panel/applets/clock/calendar-sources.c) */ ECal * dates_load_esource (ESource *esource, ECalSourceType source_type, GSList *existing_clients, DatesData *d) { ECal *retval; GError *error; if (existing_clients) { GSList *l; for (l = existing_clients; l; l = l->next) { ECal *client = E_CAL (l->data); if (e_source_equal (esource, e_cal_get_source (client))) { #ifdef DEBUG if (d->debug & DATES_DEBUG_CALENDAR) g_debug ("load_esource: found existing source, returning that"); #endif return g_object_ref (client); } } } retval = e_cal_new (esource, source_type); if (!retval) { g_warning ("Could not load source '%s' from '%s'\n", e_source_peek_name (esource), e_source_get_uri (esource)); return NULL; } error = NULL; if (!e_cal_open (retval, FALSE, &error)) { g_assert (error != NULL); g_warning ("Cannot open calendar from uri '%s': %s\n", e_cal_get_uri (retval), error->message); g_error_free (error); g_object_unref (retval); return NULL; } #ifdef DEBUG if (d->debug & DATES_DEBUG_CALENDAR) g_debug ("Loaded calendar from uri '%s'", e_cal_get_uri (retval)); #endif /* * Set the calendar mode to CAL_MODE_REMOTE. This is necessary to get the * remote (webcal) calendars to work. It doesn't seem to have any effect * on the file backend. */ e_cal_set_mode (retval, CAL_MODE_REMOTE); return retval; }
void gevo_addrbooks_model_populate(GtkTreeModel *model) { ESourceList *addressbooks; GError *err = NULL; GSList *groups, *g; GtkTreeIter iter; GtkListStore *list; g_return_if_fail(model != NULL); g_return_if_fail(GTK_IS_LIST_STORE(model)); list = GTK_LIST_STORE(model); if (!e_book_get_addressbooks(&addressbooks, &err)) { purple_debug_error("evolution", "Unable to fetch list of address books.\n"); gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, ADDRBOOK_COLUMN_NAME, _("None"), ADDRBOOK_COLUMN_URI, NULL, -1); return; } groups = e_source_list_peek_groups(addressbooks); if (groups == NULL) { gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, ADDRBOOK_COLUMN_NAME, _("None"), ADDRBOOK_COLUMN_URI, NULL, -1); return; } for (g = groups; g != NULL; g = g->next) { GSList *sources, *s; sources = e_source_group_peek_sources(g->data); for (s = sources; s != NULL; s = s->next) { ESource *source = E_SOURCE(s->data); g_object_ref(source); gtk_list_store_append(list, &iter); gtk_list_store_set(list, &iter, ADDRBOOK_COLUMN_NAME, e_source_peek_name(source), ADDRBOOK_COLUMN_URI, e_source_get_uri(source), -1); } } g_object_unref(addressbooks); }
/* * Search for a buddy in the Evolution contacts. * * @param buddy The buddy to search for. * @param query An optional query. This function takes ownership of @a query, * so callers must e_book_query_ref() it in advance (to obtain a * second reference) if they want to reuse @a query. */ EContact * gevo_search_buddy_in_contacts(PurpleBuddy *buddy, EBookQuery *query) { ESourceList *addressbooks; GError *err = NULL; EBookQuery *full_query; GSList *groups, *g; EContact *result; EContactField protocol_field = gevo_prpl_get_field(buddy->account, buddy); if (protocol_field == 0) return NULL; if (query != NULL) { EBookQuery *queries[2]; queries[0] = query; queries[1] = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name); if (queries[1] == NULL) { purple_debug_error("evolution", "Error in creating protocol query\n"); e_book_query_unref(query); return NULL; } full_query = e_book_query_and(2, queries, TRUE); } else { full_query = e_book_query_field_test(protocol_field, E_BOOK_QUERY_IS, buddy->name); if (full_query == NULL) { purple_debug_error("evolution", "Error in creating protocol query\n"); return NULL; } } if (!e_book_get_addressbooks(&addressbooks, &err)) { purple_debug_error("evolution", "Unable to fetch list of address books.\n"); e_book_query_unref(full_query); if (err != NULL) g_error_free(err); return NULL; } groups = e_source_list_peek_groups(addressbooks); if (groups == NULL) { g_object_unref(addressbooks); e_book_query_unref(full_query); return NULL; } for (g = groups; g != NULL; g = g->next) { GSList *sources, *s; sources = e_source_group_peek_sources(g->data); for (s = sources; s != NULL; s = s->next) { result = gevo_run_query_in_uri(e_source_get_uri(E_SOURCE(s->data)), full_query); if (result != NULL) { g_object_unref(addressbooks); e_book_query_unref(full_query); return result; } } } g_object_unref(addressbooks); e_book_query_unref(full_query); return NULL; }
/* ************************************************************************* */ static GNOME_Evolution_Addressbook_CallStatus e_book_backend_scalix_load_source (EBookBackend * backend, ESource * source, gboolean only_if_exists) { EBookBackendScalix *bs; EBookBackendScalixPrivate *priv; ScalixContainer *container; const char *prop_ssl; gchar *uri; bs = E_BOOK_BACKEND_SCALIX (backend); priv = E_BOOK_BACKEND_SCALIX_GET_PRIVATE (bs); if (priv->container != NULL) { /* Source already loaded! */ return GNOME_Evolution_Addressbook_Success; } uri = e_source_get_uri (source); if ((prop_ssl = e_source_get_property (source, "use_ssl"))) { CamelURL *url; url = camel_url_new (uri, NULL); camel_url_set_param (url, "use_ssl", prop_ssl); g_free (uri); uri = camel_url_to_string (url, 0); } container = scalix_container_open (uri); g_free (uri); if (container == NULL) { return GNOME_Evolution_Addressbook_OtherError; } e_book_backend_set_is_loaded (E_BOOK_BACKEND (backend), TRUE); e_book_backend_set_is_writable (E_BOOK_BACKEND (backend), TRUE); if (only_if_exists == FALSE) { GLOG_CAT_DEBUG (&slbook, "Only if exists == FALSE"); g_object_set (container, "only_if_exists", FALSE, "type", "Contacts", NULL); } priv->container = container; // go online here? if (priv->mode == GNOME_Evolution_Addressbook_MODE_REMOTE) { go_online (bs); } g_signal_connect (container, "object_added", G_CALLBACK (container_object_added_cb), (gpointer) backend); g_signal_connect (container, "object_removed", G_CALLBACK (container_object_removed_cb), (gpointer) backend); g_signal_connect (container, "object_changed", G_CALLBACK (container_object_changed_cb), (gpointer) backend); return GNOME_Evolution_Addressbook_Success; }
static void e_book_backend_vcf_load_source (EBookBackend *backend, ESource *source, gboolean only_if_exists, GError **perror) { EBookBackendVCF *bvcf = E_BOOK_BACKEND_VCF (backend); gchar *dirname; gboolean writable = FALSE; gchar *uri; gint fd; uri = e_source_get_uri (source); dirname = e_book_backend_vcf_extract_path_from_uri (uri); bvcf->priv->filename = g_build_filename (dirname, "addressbook.vcf", NULL); fd = g_open (bvcf->priv->filename, O_RDWR | O_BINARY, 0); bvcf->priv->contacts = g_hash_table_new_full ( g_str_hash, g_str_equal, (GDestroyNotify) g_free, (GDestroyNotify) NULL); if (fd != -1) { writable = TRUE; } else { fd = g_open (bvcf->priv->filename, O_RDONLY | O_BINARY, 0); if (fd == -1 && !only_if_exists) { gint rv; /* the database didn't exist, so we create the directory then the .vcf file */ rv = g_mkdir_with_parents (dirname, 0700); if (rv == -1 && errno != EEXIST) { g_warning ("failed to make directory %s: %s", dirname, g_strerror (errno)); if (errno == EACCES || errno == EPERM) { g_propagate_error (perror, EDB_ERROR (PERMISSION_DENIED)); } else { g_propagate_error (perror, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Failed to make directory %s: %s", dirname, g_strerror (errno))); } return; } fd = g_open (bvcf->priv->filename, O_CREAT | O_BINARY, 0666); if (fd != -1) { #ifdef CREATE_DEFAULT_VCARD EContact *contact; contact = do_create (bvcf, XIMIAN_VCARD, FALSE); save_file (bvcf); /* XXX check errors here */ g_object_unref (contact); #endif writable = TRUE; } } } if (fd == -1) { g_warning ("Failed to open addressbook at uri `%s'", uri); g_warning ("error == %s", g_strerror(errno)); g_propagate_error (perror, e_data_book_create_error_fmt (E_DATA_BOOK_STATUS_OTHER_ERROR, "Failed to open addressbook at uri '%s': %s", uri, g_strerror (errno))); g_free (uri); return; } load_file (bvcf, fd); e_book_backend_set_is_loaded (backend, TRUE); e_book_backend_set_is_writable (backend, writable); g_free (uri); }
static gboolean impl_CalFactory_get_cal (EGdbusCalFactory *object, GDBusMethodInvocation *invocation, const gchar * const *in_source_type, EDataCalFactory *factory) { EDataCal *calendar; EBackend *backend; EDataCalFactoryPrivate *priv = factory->priv; GDBusConnection *connection; ESource *source; gchar *uri; gchar *path = NULL; const gchar *sender; GList *list; GError *error = NULL; gchar *source_xml = NULL; guint type = 0; sender = g_dbus_method_invocation_get_sender (invocation); connection = g_dbus_method_invocation_get_connection (invocation); if (!e_gdbus_cal_factory_decode_get_cal (in_source_type, &source_xml, &type)) { error = g_error_new ( E_DATA_CAL_ERROR, NoSuchCal, _("Invalid call")); g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); return TRUE; } source = e_source_new_from_standalone_xml (source_xml); g_free (source_xml); if (!source) { error = g_error_new ( E_DATA_CAL_ERROR, NoSuchCal, _("Invalid source")); g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); return TRUE; } uri = e_source_get_uri (source); if (uri == NULL || *uri == '\0') { g_object_unref (source); g_free (uri); error = g_error_new ( E_DATA_CAL_ERROR, NoSuchCal, _("Empty URI")); g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); return TRUE; } backend = e_data_cal_factory_get_backend (factory, source, uri, type); if (backend == NULL) { error = g_error_new ( E_DATA_CAL_ERROR, NoSuchCal, _("Invalid source")); g_dbus_method_invocation_return_gerror (invocation, error); g_error_free (error); return TRUE; } g_mutex_lock (priv->calendars_lock); e_dbus_server_hold (E_DBUS_SERVER (factory)); path = construct_cal_factory_path (); calendar = e_data_cal_new (E_CAL_BACKEND (backend)); g_hash_table_insert (priv->calendars, g_strdup (path), calendar); e_cal_backend_add_client (E_CAL_BACKEND (backend), calendar); e_data_cal_register_gdbus_object (calendar, connection, path, &error); g_object_weak_ref ( G_OBJECT (calendar), (GWeakNotify) calendar_freed_cb, factory); /* Update the hash of open connections. */ g_mutex_lock (priv->connections_lock); list = g_hash_table_lookup (priv->connections, sender); list = g_list_prepend (list, calendar); g_hash_table_insert (priv->connections, g_strdup (sender), list); g_mutex_unlock (priv->connections_lock); g_mutex_unlock (priv->calendars_lock); g_object_unref (source); g_free (uri); e_gdbus_cal_factory_complete_get_cal ( object, invocation, path, error); if (error) g_error_free (error); g_free (path); return TRUE; }
static GNOME_Evolution_Addressbook_Book impl_GNOME_Evolution_Addressbook_BookFactory_getBook (PortableServer_Servant servant, const CORBA_char *source_xml, const GNOME_Evolution_Addressbook_BookListener listener, CORBA_Environment *ev) { EDataBookFactory *factory = E_DATA_BOOK_FACTORY (bonobo_object (servant)); GNOME_Evolution_Addressbook_Book corba_book; EBookBackend *backend; EDataBook *book = NULL; ESource *source; gchar *uri; printf ("impl_GNOME_Evolution_Addressbook_BookFactory_getBook\n"); source = e_source_new_from_standalone_xml (source_xml); if (!source) { CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Addressbook_BookFactory_ProtocolNotSupported, NULL); return CORBA_OBJECT_NIL; } uri = e_source_get_uri (source); if (!uri) { g_object_unref (source); CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Addressbook_BookFactory_ProtocolNotSupported, NULL); return CORBA_OBJECT_NIL; } printf (" + %s\n", uri); /* Look up the backend and create one if needed */ g_mutex_lock (factory->priv->map_mutex); backend = g_hash_table_lookup (factory->priv->active_server_map, uri); if (!backend) { EBookBackendFactory* backend_factory; backend_factory = e_data_book_factory_lookup_backend_factory (factory, uri); if (backend_factory == NULL) { CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Addressbook_BookFactory_ProtocolNotSupported, NULL); g_mutex_unlock (factory->priv->map_mutex); g_free (uri); return CORBA_OBJECT_NIL; } backend = e_data_book_factory_launch_backend (factory, backend_factory, listener, uri); } g_free (uri); if (backend) { g_mutex_unlock (factory->priv->map_mutex); book = e_data_book_new (backend, source, listener); e_book_backend_add_client (backend, book); e_book_backend_set_mode (backend, factory->priv->mode); corba_book = bonobo_object_corba_objref (BONOBO_OBJECT (book)); } else { /* probably need a more descriptive exception here */ CORBA_exception_set (ev, CORBA_USER_EXCEPTION, ex_GNOME_Evolution_Addressbook_BookFactory_ProtocolNotSupported, NULL); g_mutex_unlock (factory->priv->map_mutex); corba_book = CORBA_OBJECT_NIL; } g_object_unref (source); if (book) printf (" => %p\n", book); return corba_book; }