diff options
-rw-r--r-- | mail/e-mail-folder-utils.c | 48 | ||||
-rw-r--r-- | mail/e-mail-folder-utils.h | 3 | ||||
-rw-r--r-- | mail/em-vfolder-rule.c | 64 | ||||
-rw-r--r-- | mail/mail-dialogs.ui | 2 |
4 files changed, 76 insertions, 41 deletions
diff --git a/mail/e-mail-folder-utils.c b/mail/e-mail-folder-utils.c index 7c84957f6a..77a9708e5f 100644 --- a/mail/e-mail-folder-utils.c +++ b/mail/e-mail-folder-utils.c @@ -1630,3 +1630,51 @@ e_mail_folder_uri_from_folder (CamelFolder *folder) return e_mail_folder_uri_build (store, folder_name); } + +/** + * e_mail_folder_uri_to_markup: + * @session: a #CamelSession + * @folder_uri: a folder URI + * @error: return location for a #GError, or %NULL + * + * Converts @folder_uri to a markup string suitable for displaying to users. + * The string consists of the #CamelStore display name (in bold), followed + * by the folder path. If the URI is malformed or no corresponding store + * exists, the function sets @error and returns %NULL. Free the returned + * string with g_free(). + * + * Returns: a newly-allocated markup string, or %NULL + **/ +gchar * +e_mail_folder_uri_to_markup (CamelSession *session, + const gchar *folder_uri, + GError **error) +{ + CamelStore *store = NULL; + const gchar *display_name; + gchar *folder_name = NULL; + gchar *markup; + gboolean success; + + g_return_val_if_fail (CAMEL_IS_SESSION (session), NULL); + g_return_val_if_fail (folder_uri != NULL, NULL); + + success = e_mail_folder_uri_parse ( + session, folder_uri, &store, &folder_name, error); + + if (!success) + return NULL; + + g_return_val_if_fail (CAMEL_IS_STORE (store), NULL); + g_return_val_if_fail (folder_name != NULL, NULL); + + display_name = camel_service_get_display_name (CAMEL_SERVICE (store)); + + markup = g_markup_printf_escaped ( + "<b>%s</b> : %s", display_name, folder_name); + + g_object_unref (store); + g_free (folder_name); + + return markup; +} diff --git a/mail/e-mail-folder-utils.h b/mail/e-mail-folder-utils.h index c82d806d7a..9e8dd0f050 100644 --- a/mail/e-mail-folder-utils.h +++ b/mail/e-mail-folder-utils.h @@ -155,6 +155,9 @@ gboolean e_mail_folder_uri_equal (CamelSession *session, const gchar *folder_uri_a, const gchar *folder_uri_b); gchar * e_mail_folder_uri_from_folder (CamelFolder *folder); +gchar * e_mail_folder_uri_to_markup (CamelSession *session, + const gchar *folder_uri, + GError **error); G_END_DECLS diff --git a/mail/em-vfolder-rule.c b/mail/em-vfolder-rule.c index be18f2c248..04c009bc00 100644 --- a/mail/em-vfolder-rule.c +++ b/mail/em-vfolder-rule.c @@ -32,6 +32,7 @@ #include "em-vfolder-context.h" #include "em-vfolder-rule.h" +#include "mail/e-mail-folder-utils.h" #include "mail/e-mail-store.h" #include "mail/em-utils.h" #include "mail/em-folder-tree.h" @@ -532,63 +533,38 @@ select_source_with_changed (GtkWidget *widget, data->vr->with = with; } -/* attempt to make a 'nice' folder name out of the raw uri */ -static gchar * -format_source (const gchar *uri) -{ - CamelURL *url; - GString *out; - gchar *res; - - /* This should really probably base it on the account name? */ - url = camel_url_new (uri, NULL); - - /* bad uri */ - if (url == NULL) - return g_strdup (uri); - - out = g_string_new (url->protocol); - g_string_append_c (out, ':'); - if (url->user && url->host) { - g_string_append_printf(out, "%s@%s", url->user, url->host); - if (url->port) - g_string_append_printf(out, ":%d", url->port); - } - if (url->fragment) - g_string_append (out, url->fragment); - else if (url->path) - g_string_append (out, url->path); - - res = out->str; - g_string_free (out, FALSE); - - return res; -} - static void vfr_folder_response (EMFolderSelector *selector, gint button, struct _source_data *data) { + EMailBackend *backend; + EMailSession *session; const gchar *uri; + backend = em_folder_selector_get_backend (selector); + session = e_mail_backend_get_session (backend); + uri = em_folder_selector_get_selected_uri (selector); if (button == GTK_RESPONSE_OK && uri != NULL) { - gchar *urinice; GtkTreeSelection *selection; GtkTreeIter iter; + gchar *markup; g_queue_push_tail (&data->vr->sources, g_strdup (uri)); + markup = e_mail_folder_uri_to_markup ( + CAMEL_SESSION (session), uri, NULL); + gtk_list_store_append (data->model, &iter); - urinice = format_source (uri); - gtk_list_store_set (data->model, &iter, 0, urinice, 1, uri, -1); - g_free (urinice); + gtk_list_store_set (data->model, &iter, 0, markup, 1, uri, -1); selection = gtk_tree_view_get_selection (data->list); gtk_tree_selection_select_iter (selection, &iter); data->current = uri; + g_free (markup); + set_sensitive (data); } @@ -687,6 +663,8 @@ get_widget (EFilterRule *fr, ERuleContext *rc) { EMVFolderRule *vr =(EMVFolderRule *) fr; + EMailBackend *backend; + EMailSession *session; GtkWidget *widget, *frame; struct _source_data *data; GtkRadioButton *rb; @@ -721,13 +699,19 @@ get_widget (EFilterRule *fr, object = gtk_builder_get_object (builder, "source_model"); data->model = GTK_LIST_STORE (object); + backend = em_vfolder_context_get_backend (EM_VFOLDER_CONTEXT (rc)); + session = e_mail_backend_get_session (backend); + source = NULL; while ((source = em_vfolder_rule_next_source (vr, source))) { - gchar *nice = format_source (source); + gchar *markup; + + markup = e_mail_folder_uri_to_markup ( + CAMEL_SESSION (session), source, NULL); gtk_list_store_append (data->model, &iter); - gtk_list_store_set (data->model, &iter, 0, nice, 1, source, -1); - g_free (nice); + gtk_list_store_set (data->model, &iter, 0, markup, 1, source, -1); + g_free (markup); } g_signal_connect (data->list, "cursor-changed", G_CALLBACK(select_source), data); diff --git a/mail/mail-dialogs.ui b/mail/mail-dialogs.ui index ff74671741..58a9f8c2aa 100644 --- a/mail/mail-dialogs.ui +++ b/mail/mail-dialogs.ui @@ -125,7 +125,7 @@ <child> <object class="GtkCellRendererText" id="source_renderer"/> <attributes> - <attribute name="text">0</attribute> + <attribute name="markup">0</attribute> </attributes> </child> </object> |