#include <glib.h>
#include <glib/gstdio.h>
#include <errno.h>
+#include <string.h> /* for strlen */
#include <modest-runtime.h>
#include <libgnomevfs/gnome-vfs.h>
#include <tny-fs-stream.h>
#include <tny-camel-pop-store-account.h>
#include "modest-hildon-includes.h"
+#include <modest-defs.h>
#include "modest-maemo-utils.h"
#include "modest-platform.h"
#define BTNAME_MATCH_RULE "type='signal',interface='" BTNAME_SIGNAL_IF \
"',member='" BTNAME_SIG_CHANGED "'"
-GQuark modest_maemo_utils_get_supported_secure_authentication_error_quark (void)
+
+static osso_context_t *__osso_context = NULL; /* urgh global */
+
+osso_context_t *
+modest_maemo_utils_get_osso_context (void)
+{
+ if (!__osso_context)
+ g_warning ("%s: __osso_context == NULL", __FUNCTION__);
+
+ 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;
+}
+
+
+GQuark
+modest_maemo_utils_get_supported_secure_authentication_error_quark (void)
{
return g_quark_from_static_string("modest-maemo-utils-get-supported-secure-authentication-error-quark");
}
{
GtkWidget *main_menu;
GtkWidget *menubar;
- GList *iter;
+ GList *children, *iter;
g_return_val_if_fail (ui_manager, NULL);
/* Get the menubar from the UI manager */
menubar = gtk_ui_manager_get_widget (ui_manager, "/MenuBar");
- iter = gtk_container_get_children (GTK_CONTAINER (menubar));
+ iter = children = gtk_container_get_children (GTK_CONTAINER (menubar));
while (iter) {
GtkWidget *menu;
iter = g_list_next (iter);
}
+ g_list_free (children);
return main_menu;
}
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);
}
TnyFsStream *
-modest_maemo_utils_create_temp_stream (const gchar *orig_name, gchar **path)
+modest_maemo_utils_create_temp_stream (const gchar *orig_name, const gchar *hash_base, gchar **path)
{
gint fd;
gchar *filepath = NULL;
gchar *tmpdir;
+ guint hash_number;
+ /* hmmm... maybe we need a modest_text_utils_validate_file_name? */
+ g_return_val_if_fail (orig_name || strlen(orig_name) == 0, NULL);
+ if (strlen(orig_name) > 200) {
+ g_warning ("%s: filename too long ('%s')",
+ __FUNCTION__, orig_name);
+ return NULL;
+ }
+
+ if (g_strstr_len (orig_name, strlen(orig_name), "/") != NULL) {
+ g_warning ("%s: filename contains '/' character(s) (%s)",
+ __FUNCTION__, orig_name);
+ return NULL;
+ }
+
/* make a random subdir under /tmp or /var/tmp */
- tmpdir = g_strdup_printf ("%s/%d", g_get_tmp_dir (), (guint)random());
- if (g_mkdir (tmpdir, 0755) == -1) {
+ if (hash_base != NULL) {
+ hash_number = g_str_hash (hash_base);
+ } else {
+ hash_number = (guint) random ();
+ }
+ tmpdir = g_strdup_printf ("%s/%u", g_get_tmp_dir (), hash_number);
+ if ((g_access (tmpdir, R_OK) == -1) && (g_mkdir (tmpdir, 0755) == -1)) {
g_warning ("%s: failed to create dir '%s': %s",
__FUNCTION__, tmpdir, g_strerror(errno));
g_free (tmpdir);
return NULL;
}
- /* try to write the file there */
filepath = g_strconcat (tmpdir, "/", orig_name, NULL);
- fd = g_open (filepath, O_CREAT|O_WRONLY|O_TRUNC, 0644);
- if (fd == -1) {
- g_warning ("%s: failed to create '%s': %s",
- __FUNCTION__, filepath, g_strerror(errno));
+ /* don't overwrite if it already exists, even if it is writable */
+ if (modest_maemo_utils_file_exists (filepath)) {
+ if (path!=NULL) {
+ *path = filepath;
+ } else {
+ g_free (filepath);
+ }
g_free (tmpdir);
- g_free (filepath);
return NULL;
+ } else {
+ /* try to write the file there */
+ fd = g_open (filepath, O_CREAT|O_WRONLY|O_TRUNC, 0644);
+ if (fd == -1) {
+ g_warning ("%s: failed to create '%s': %s",
+ __FUNCTION__, filepath, g_strerror(errno));
+ g_free (filepath);
+ g_free (tmpdir);
+ return NULL;
+ }
}
g_free (tmpdir);
static void
on_camel_account_get_supported_secure_authentication (
TnyCamelAccount *self, gboolean cancelled,
- TnyList *auth_types, GError **err,
+ TnyList *auth_types, GError *err,
gpointer user_data)
{
-
ModestGetSupportedAuthInfo *info = (ModestGetSupportedAuthInfo*)user_data;
g_return_if_fail (info);
+
/* Free everything if the actual action was canceled */
if (info->cancel)
}
else
{
- /* TODO: Why is this a pointer to a pointer? We are not supposed to
- * set it, are we? */
- if(err != NULL && *err != NULL)
+ if (err)
{
- if(info->error != NULL) g_error_free(info->error);
- info->error = g_error_copy(*err);
+ if (info->error) {
+ g_error_free (info->error);
+ info->error = NULL;
+ }
+
+ info->error = g_error_copy (err);
}
if (!auth_types) {
- printf ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
+ g_warning ("DEBUG: %s: auth_types is NULL.\n", __FUNCTION__);
}
- else
+ else if (tny_list_get_length(auth_types) == 0) {
+ g_warning ("DEBUG: %s: auth_types is an empty TnyList.\n", __FUNCTION__);
+ } else
{
ModestPairList* pairs = modest_protocol_info_get_auth_protocol_pair_list ();
}
printf("DEBUG: finished\n");
-
+
/* Close the dialog in a main thread */
g_idle_add(on_idle_secure_auth_finished, info);
}
}
-static void on_secure_auth_cancel(GtkWidget* dialog, int response, gpointer user_data)
+static void
+on_secure_auth_cancel(GtkWidget* dialog, int response, gpointer user_data)
{
if(response == GTK_RESPONSE_REJECT || response == GTK_RESPONSE_DELETE_EVENT)
{
}
}
-
-typedef struct
-{
- GMainLoop* loop;
-} UserData;
-
-static UserData *user_data = NULL;
-
-static void
-on_account_online (TnyCamelAccount *account, GError *err)
-{
- printf ("DEBUGa1: %s\n", __FUNCTION__);
-
- if (err) {
- printf("DEBUG: %s: error=\n %s\n", __FUNCTION__, err->message);
- }
-
- /* Allow the function that requested this callback to continue: */
- /* TODO: Tinymail should really give us user_data with this callback. */
- if (user_data && user_data->loop)
- g_main_loop_quit (user_data->loop);
-}
-
GList*
modest_maemo_utils_get_supported_secure_authentication_methods (ModestTransportStoreProtocol proto,
const gchar* hostname, gint port, const gchar* username, GtkWindow *parent_window, GError** error)
tny_camel_account_set_session (TNY_CAMEL_ACCOUNT(tny_account), session);
- /* This blocks on the result: */
- /* TODO: Fix tinymail to take user_data for the callback instead of using one static instance: */
- if (user_data) {
- g_slice_free (UserData, user_data);
- user_data = NULL;
- }
-
- user_data = g_slice_new0 (UserData);
- user_data->loop = g_main_loop_new (NULL, FALSE /* not running */);
-
- /* We get a warning if we don't do use tny_camel_account_set_online():
- * GLIB CRITICAL ** camel-lite - camel_service_query_auth_types: assertion `service != NULL' failed.
- */
- tny_camel_account_set_online (TNY_CAMEL_ACCOUNT (tny_account), TRUE, &on_account_online);
- printf ("DEBUGa2: %s\n", __FUNCTION__);
-
- /* This main loop will run until the idle handler has stopped it: */
- printf ("DEBUG: %s: before g_main_loop_run()\n", __FUNCTION__);
- GDK_THREADS_LEAVE();
- g_main_loop_run (user_data->loop);
- GDK_THREADS_ENTER();
- printf ("DEBUG: %s: after g_main_loop_run()\n", __FUNCTION__);
- g_main_loop_unref (user_data->loop);
- /* g_main_context_unref (context); */
-
- g_slice_free (UserData, user_data);
- user_data = NULL;
-
-
/* Ask camel to ask the server, asynchronously: */
ModestGetSupportedAuthInfo *info = g_slice_new (ModestGetSupportedAuthInfo);
info->result = NULL;
gtk_dialog_run (GTK_DIALOG (info->dialog));
gtk_widget_destroy(info->dialog);
-
+
GList *result = info->result;
if (!info->cancel)
{
- if(info->error != NULL)
+ if (info->error) {
+ gchar * debug_url_string = tny_account_get_url_string (tny_account);
+ g_warning ("DEBUG: %s:\n error: %s\n account url: %s", __FUNCTION__, info->error->message,
+ debug_url_string);
+ g_free (debug_url_string);
+
g_propagate_error(error, info->error);
+ info->error = NULL;
+ }
g_slice_free (ModestGetSupportedAuthInfo, info);
info = NULL;
}
-static void
-on_response (GtkDialog *dialog, gint response, gpointer user_data)
-{
- /* Just destroy the dialog: */
- gtk_widget_destroy (GTK_WIDGET (dialog));
-}
-
-void
-modest_maemo_show_information_note_and_forget (GtkWindow *parent_window, const gchar* message)
-{
- GtkDialog *dialog = GTK_DIALOG (hildon_note_new_information (parent_window, message));
-
- /* Destroy the dialog when it is closed: */
- g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (on_response), NULL);
- gtk_widget_show (GTK_WIDGET (dialog));
-}
-
#if 0
static void
on_hide (GtkDialog *dialog, gpointer user_data)
return FALSE; /* Don't call this again. */
}
-void modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *parent_window, const gchar* message)
+void
+modest_maemo_show_information_note_in_main_context_and_forget (GtkWindow *parent_window,
+ const gchar* message)
{
ModestIdleNoteInfo *info = g_slice_new (ModestIdleNoteInfo);
info->parent_window = parent_window;
}
#endif
-void modest_maemo_show_dialog_and_forget (GtkWindow *parent_window, GtkDialog *dialog)
+void
+modest_maemo_show_dialog_and_forget (GtkWindow *parent_window,
+ GtkDialog *dialog)
{
gtk_window_set_transient_for (GTK_WINDOW (dialog), parent_window);
/* Destroy the dialog when it is closed: */
- g_signal_connect (G_OBJECT (dialog), "response", G_CALLBACK (on_response), NULL);
+ g_signal_connect_swapped (dialog,
+ "response",
+ G_CALLBACK (gtk_widget_destroy),
+ dialog);
+
gtk_widget_show (GTK_WIDGET (dialog));
}
void
-modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win, gboolean thumbable)
+modest_maemo_set_thumbable_scrollbar (GtkScrolledWindow *win,
+ gboolean thumbable)
{
g_return_if_fail (GTK_IS_SCROLLED_WINDOW(win));
#ifdef MODEST_HAVE_HILDON1_WIDGETS
}
}
+
+
+FILE*
+modest_maemo_open_mcc_mapping_file (void)
+{
+ FILE* result;
+
+ const gchar* path;
+ const gchar* path1 = MODEST_OPERATOR_WIZARD_MCC_MAPPING;
+ const gchar* path2 = MODEST_MCC_MAPPING;
+
+ if (access(path1, R_OK) == 0)
+ path = path1;
+ else if (access(path2, R_OK) == 0)
+ path = path2;
+ else {
+ g_warning ("%s: neither '%s' nor '%s' is a readable mapping file",
+ __FUNCTION__, path1, path2);
+ return NULL;
+ }
+
+ result = fopen (path, "r");
+ if (!result) {
+ g_warning ("%s: error opening mapping file '%s': %s",
+ __FUNCTION__, path, strerror(errno));
+ return NULL;
+ }
+ return result;
+}
+