X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fmaemo%2Fmodest-maemo-utils.c;h=28f73e17c951d6e4447ae6f14ae861fe9ce30a01;hb=ba4f63e1dede973582a3fa6add4cc390925ffea3;hp=7754685cceac394a3f548058e4ab5bf68063f2a1;hpb=ff5c90409a7511dcf1839d988f7b9e4467fa55f9;p=modest diff --git a/src/maemo/modest-maemo-utils.c b/src/maemo/modest-maemo-utils.c index 7754685..28f73e1 100644 --- a/src/maemo/modest-maemo-utils.c +++ b/src/maemo/modest-maemo-utils.c @@ -34,6 +34,9 @@ #include #include #include +#include +#include +#include /* for strlen */ #include #include #include @@ -44,7 +47,10 @@ #include #include "modest-hildon-includes.h" +#include #include "modest-maemo-utils.h" +#include "modest-text-utils.h" +#include "modest-platform.h" /* * For getting and tracking the Bluetooth name @@ -62,33 +68,23 @@ "',member='" BTNAME_SIG_CHANGED "'" -GtkWidget* -modest_maemo_utils_menubar_to_menu (GtkUIManager *ui_manager) -{ - GtkWidget *main_menu; - GtkWidget *menubar; - GList *iter; +static osso_context_t *__osso_context = NULL; /* urgh global */ - g_return_val_if_fail (ui_manager, NULL); +osso_context_t * +modest_maemo_utils_get_osso_context (void) +{ + if (!__osso_context) + g_warning ("%s: __osso_context == NULL", __FUNCTION__); - /* Create new main menu */ - main_menu = gtk_menu_new(); - - /* Get the menubar from the UI manager */ - menubar = gtk_ui_manager_get_widget (ui_manager, "/MenuBar"); - - iter = gtk_container_get_children (GTK_CONTAINER (menubar)); - while (iter) { - GtkWidget *menu; - - menu = GTK_WIDGET (iter->data); - gtk_widget_reparent(menu, main_menu); - - iter = g_list_next (iter); - } - return main_menu; + return __osso_context; } +void +modest_maemo_utils_set_osso_context (osso_context_t *osso_context) +{ + g_return_if_fail (osso_context); + __osso_context = osso_context; +} static void update_device_name_from_msg (DBusMessage *message) @@ -108,7 +104,6 @@ update_device_name_from_msg (DBusMessage *message) return; } dbus_message_iter_get_basic (&iter, &device_name); - g_warning ("update device name: %s", device_name); modest_conf_set_string (modest_runtime_get_conf(), MODEST_CONF_DEVICE_NAME, device_name, NULL); @@ -196,210 +191,72 @@ modest_maemo_utils_get_device_name (void) get_device_name_from_dbus (); } -gboolean -modest_maemo_utils_folder_writable (const gchar *filename) +void +modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser) { - if (g_strncasecmp (filename, "obex", 4) != 0) { - GnomeVFSFileInfo folder_info; - gchar *folder; - folder = g_path_get_dirname (filename); - gnome_vfs_get_file_info (folder, &folder_info, - GNOME_VFS_FILE_INFO_GET_ACCESS_RIGHTS); - g_free (folder); - if (!((folder_info.permissions & GNOME_VFS_PERM_ACCESS_WRITABLE) || - (folder_info.permissions & GNOME_VFS_PERM_USER_WRITE))) { - return FALSE; - } + gchar *images_folder; + GtkFileFilter *file_filter; + GList *image_mimetypes_list; + GList *node; + + g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser)); + + /* Set the default folder to images folder */ + images_folder = g_build_filename (g_get_home_dir (), + MODEST_MAEMO_UTILS_MYDOCS_FOLDER, + MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER, NULL); + gtk_file_chooser_set_current_folder (chooser, images_folder); + g_free (images_folder); + + /* Set the images mime filter */ + file_filter = gtk_file_filter_new (); +#ifdef MODEST_HAVE_HILDON0_WIDGETS + image_mimetypes_list = osso_mime_get_mime_types_for_category (OSSO_MIME_CATEGORY_IMAGES); +#else + image_mimetypes_list = hildon_mime_get_mime_types_for_category (HILDON_MIME_CATEGORY_IMAGES); +#endif + for (node = image_mimetypes_list; node != NULL; node = g_list_next (node)) { + gtk_file_filter_add_mime_type (file_filter, node->data); } - return TRUE; -} - -gboolean -modest_maemo_utils_file_exists (const gchar *filename) -{ - GnomeVFSURI *uri = NULL; - gboolean result = FALSE; + gtk_file_chooser_set_filter (chooser, file_filter); +#ifdef MODEST_HAVE_HILDON0_WIDGETS + osso_mime_types_list_free (image_mimetypes_list); +#else + hildon_mime_types_list_free (image_mimetypes_list); +#endif - uri = gnome_vfs_uri_new (filename); - if (uri) { - result = gnome_vfs_uri_exists (uri); - gnome_vfs_uri_unref (uri); - } - return result; } -TnyFsStream * -modest_maemo_utils_create_temp_stream (const gchar *extension, gchar **path) +void +modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, + gboolean thumbable) { - TnyStream *tmp_fs_stream = NULL; - gint fd; - gchar *filepath = NULL; - gchar *template = NULL; - - if (extension != NULL) - template = g_strdup_printf ("XXXXXX.%s", extension); - - fd = g_file_open_tmp (template, &filepath, NULL); - g_free (template); - if (path != NULL) - *path = filepath; - if (fd == -1) { - g_message ("TODO BANNER: Error saving stream"); - return NULL; - } - tmp_fs_stream = tny_fs_stream_new (fd); - - return TNY_FS_STREAM (tmp_fs_stream); + g_return_if_fail (GTK_IS_SCROLLED_WINDOW(win)); +#ifdef MODEST_HAVE_HILDON1_WIDGETS + hildon_helper_set_thumb_scrollbar (win, thumbable); +#endif /* MODEST_HAVE_HILDON1_WIDGETS */ } -typedef struct -{ - gboolean finished; - GList *result; - GtkWidget* banner; -} ModestGetSupportedAuthInfo; - -#if 0 -static void on_camel_account_get_supported_secure_authentication_status ( - GObject *self, TnyStatus *status, gpointer user_data) +GtkWidget * +modest_maemo_utils_get_manager_menubar_as_menu (GtkUIManager *manager, + const gchar *item_name) { + GtkWidget *new_menu; + GtkWidget *menubar; + GList *children, *iter; - printf ("DEBUG: %s.\n", __FUNCTION__); - ModestGetSupportedAuthInfo* info = (ModestGetSupportedAuthInfo*) user_data; - GDK_THREADS_ENTER(); - hildon_banner_set_fraction(HILDON_BANNER(info->banner), tny_status_get_fraction(status)); - GDK_THREADS_LEAVE(); -} + menubar = gtk_ui_manager_get_widget (manager, item_name); + new_menu = gtk_menu_new (); -static void -on_camel_account_get_supported_secure_authentication ( - TnyCamelAccount *self, gboolean cancelled, - TnyList *auth_types, GError **err, - gpointer user_data) -{ - printf ("DEBUG: %s.\n", __FUNCTION__); - - ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data; - g_return_if_fail (info); - - if (!auth_types) { - printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__); - info->finished = TRUE; /* We are blocking, waiting for this. */ - return; - } - - ModestPairList* pairs = modest_protocol_info_get_auth_protocol_pair_list (); - - /* Get the enum value for the strings: */ - GList *result = NULL; - TnyIterator* iter = tny_list_create_iterator(auth_types); - while (!tny_iterator_is_done(iter)) { - const gchar *auth_name = tny_pair_get_name(TNY_PAIR(tny_iterator_get_current(iter))); - printf("DEBUG: %s: auth_name=%s\n", __FUNCTION__, auth_name); - ModestPair *matching = modest_pair_list_find_by_first_as_string (pairs, - auth_name); - if (matching) - { - result = g_list_append (result, GINT_TO_POINTER((ModestConnectionProtocol)matching->first)); - } - tny_iterator_next(iter); - } - - g_object_unref(auth_types); - - modest_pair_list_free (pairs); - - info->result = result; - printf("DEBUG: finished\n"); - info->finished = TRUE; /* We are blocking, waiting for this. */ -} -#endif + children = gtk_container_get_children (GTK_CONTAINER (menubar)); + for (iter = children; iter != NULL; iter = g_list_next (iter)) { + GtkWidget *menu; -GList* modest_maemo_utils_get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto, - const gchar* hostname, gint port, GtkWindow *parent_window) -{ - return NULL; -/* FIXME: Activate when changes are merged into tinymail */ -#if 0 - g_return_val_if_fail (proto != MODEST_PROTOCOL_TRANSPORT_STORE_UNKNOWN, NULL); - - /* - result = g_list_append (result, GINT_TO_POINTER (MODEST_PROTOCOL_AUTH_CRAMMD5)); - */ - - /* Create a TnyCamelAccount so we can use - * tny_camel_account_get_supported_secure_authentication(): */ - TnyAccount * tny_account = NULL; - switch (proto) { - case MODEST_PROTOCOL_TRANSPORT_SENDMAIL: - case MODEST_PROTOCOL_TRANSPORT_SMTP: - tny_account = TNY_ACCOUNT(tny_camel_transport_account_new ()); break; - case MODEST_PROTOCOL_STORE_POP: - tny_account = TNY_ACCOUNT(tny_camel_pop_store_account_new ()); break; - case MODEST_PROTOCOL_STORE_IMAP: - tny_account = TNY_ACCOUNT(tny_camel_imap_store_account_new ()); break; - case MODEST_PROTOCOL_STORE_MAILDIR: - case MODEST_PROTOCOL_STORE_MBOX: - tny_account = TNY_ACCOUNT(tny_camel_store_account_new()); break; - default: - tny_account = NULL; - } - - if (!tny_account) { - g_printerr ("%s could not create tny account.", __FUNCTION__); - return NULL; - } - - /* Set proto, so that the prepare_func() vfunc will work when we call - * set_session(): */ - /* TODO: Why isn't this done in account_new()? */ - tny_account_set_proto (tny_account, - modest_protocol_info_get_transport_store_protocol_name(proto)); - - /* Set the session for the account, so we can use it: */ - ModestTnyAccountStore *account_store = modest_runtime_get_account_store (); - TnySessionCamel *session = - modest_tny_account_store_get_session (TNY_ACCOUNT_STORE (account_store)); - g_return_val_if_fail (session, NULL); - tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session); - - tny_account_set_hostname (tny_account, hostname); - - if(port > 0) - tny_account_set_port (tny_account, port); - - - /* Ask camel to ask the server, asynchronously: */ - ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo); - info->finished = FALSE; - info->result = NULL; - GtkWidget* progressbar = gtk_progress_bar_new(); - info->banner = hildon_banner_show_progress (GTK_WIDGET(parent_window), - GTK_PROGRESS_BAR(progressbar), - _("Checking for supported authentification types")); - gtk_progress_bar_pulse(GTK_PROGRESS_BAR(progressbar)); - - - printf ("DEBUG: %s: STARTING.\n", __FUNCTION__); - tny_camel_account_get_supported_secure_authentication ( - TNY_CAMEL_ACCOUNT (tny_account), - on_camel_account_get_supported_secure_authentication, - on_camel_account_get_supported_secure_authentication_status, - info); - - /* Block until the callback has been called, - * driving the main context, so that the (idle handler) callback can be - * called, and so that our dialog is clickable: */ - while (!(info->finished)) { - gtk_main_iteration_do(FALSE); + menu = GTK_WIDGET (iter->data); + gtk_widget_reparent (menu, new_menu); } - gtk_widget_destroy(info->banner); - - GList *result = info->result; - g_slice_free (ModestGetSupportedAuthInfo, info); - info = NULL; - - return result; -#endif + g_list_free (children); + + return new_menu; }