#define DBUS_API_SUBJECT_TO_CHANGE
#endif /*DBUS_API_SUBJECT_TO_CHANGE*/
-#include <sys/utsname.h>
#include <dbus/dbus.h>
#include <dbus/dbus-glib-lowlevel.h>
#include <glib.h>
#define BTNAME_SERVICE "org.bluez"
#define BTNAME_REQUEST_IF "org.bluez.Adapter"
#define BTNAME_SIGNAL_IF "org.bluez.Adapter"
-#define BTNAME_REQUEST_PATH "/org/bluez/hci0"
#define BTNAME_SIGNAL_PATH "/org/bluez/hci0"
-#define BTNAME_REQ_GET "GetName"
+#define BTNAME_REQ_GET_PROPERTIES "GetProperties"
+#define BTNAME_REQ_DEFAULT_ADAPTER "DefaultAdapter"
#define BTNAME_SIG_CHANGED "NameChanged"
#define BTNAME_MATCH_RULE "type='signal',interface='" BTNAME_SIGNAL_IF \
__osso_context = osso_context;
}
-void
-modest_maemo_utils_get_device_name (void)
+/* static void */
+/* update_device_name_from_msg (DBusMessage *message) */
+/* { */
+/* DBusError error; */
+/* DBusMessageIter iter; */
+
+/* dbus_error_init (&error); */
+
+/* if (dbus_set_error_from_message (&error, message)) { */
+/* g_printerr ("modest: failed to get bluetooth name: %s\n", error.message); */
+/* dbus_error_free (&error); */
+/* } else { */
+/* const gchar *device_name; */
+/* if (!dbus_message_iter_init (message, &iter)) { */
+/* g_printerr ("modest: message did not have argument\n"); */
+/* return; */
+/* } */
+/* dbus_message_iter_get_basic (&iter, &device_name); */
+/* modest_conf_set_string (modest_runtime_get_conf(), */
+/* MODEST_CONF_DEVICE_NAME, device_name, */
+/* NULL); */
+/* } */
+/* } */
+
+
+/* static void */
+/* on_device_name_received (DBusPendingCall *call, void *user_data) */
+/* { */
+/* DBusMessage *message; */
+
+/* g_return_if_fail (dbus_pending_call_get_completed (call)); */
+
+/* message = dbus_pending_call_steal_reply (call); */
+/* if (!message) { */
+/* g_printerr ("modest: no reply on device name query\n"); */
+/* return; */
+/* } */
+
+/* update_device_name_from_msg (message); */
+/* dbus_message_unref (message); */
+/* } */
+
+
+/* static DBusHandlerResult */
+/* handle_dbus_signal (DBusConnection *conn, DBusMessage *msg, gpointer data) */
+/* { */
+/* if (dbus_message_is_signal(msg, BTNAME_SIGNAL_IF, BTNAME_SIG_CHANGED)) */
+/* update_device_name_from_msg (msg); */
+
+/* return DBUS_HANDLER_RESULT_NOT_YET_HANDLED; */
+/* } */
+
+static void
+get_properties_cb (DBusPendingCall *call,
+ void *user_data)
{
- struct utsname name;
+ DBusMessageIter iter;
+ DBusMessageIter dict_iter;
+ DBusMessageIter dict_entry_iter;
+ DBusError err;
+ gchar *bt_name = NULL;
+ DBusMessage *message;
+ int key_type, array_type, msg_type;
+
+ if ( !dbus_pending_call_get_completed ( call ) )
+ g_warning ("%s: Call not completed!", __FUNCTION__);
+
+ message = dbus_pending_call_steal_reply ( call );
+
+ if (message == NULL)
+ g_warning ("%s: Message is NULL", __FUNCTION__);
+
+
+ dbus_error_init(&err);
+ if (dbus_set_error_from_message (&err, message)) {
+ g_warning ("%s: %s", __FUNCTION__, err.message);
+ }
+
+
+ /* Get msg type */
+ dbus_message_iter_init (message, &iter);
+ msg_type = dbus_message_iter_get_arg_type (&iter);
+ dbus_message_iter_recurse (&iter, &dict_iter);
+
+ while ((array_type = dbus_message_iter_get_arg_type (&dict_iter)) == DBUS_TYPE_DICT_ENTRY) {
+
+ dbus_message_iter_recurse (&dict_iter, &dict_entry_iter);
+
+ while ((key_type = dbus_message_iter_get_arg_type (&dict_entry_iter)) == DBUS_TYPE_STRING) {
+ DBusMessageIter dict_entry_content_iter;
+ char *key;
+ char *value;
+ int dict_entry_type;
+ int dict_entry_content_type;
+
+ dbus_message_iter_get_basic (&dict_entry_iter, &key);
+ dbus_message_iter_next (&dict_entry_iter);
+ dict_entry_type = dbus_message_iter_get_arg_type (&dict_entry_iter);
+ dbus_message_iter_recurse (&dict_entry_iter, &dict_entry_content_iter);
+ dict_entry_content_type = dbus_message_iter_get_arg_type (&dict_entry_content_iter);
- if (uname (&name) == 0) {
+ if (dict_entry_content_type == DBUS_TYPE_STRING) {
+ dbus_message_iter_get_basic ( &dict_entry_content_iter, &value );
+
+ if ( strcmp ( key, "Name" ) == 0 ) {
+ g_debug ("-------------Name %s", value);
+ break;
+ }
+ }
+ dbus_message_iter_next (&dict_entry_iter);
+ }
+
+ if (key_type != DBUS_TYPE_INVALID)
+ break;
+
+ dbus_message_iter_next (&dict_iter);
+ }
+
+ /* Save device name */
+ if (bt_name) {
modest_conf_set_string (modest_runtime_get_conf(),
- MODEST_CONF_DEVICE_NAME, name.nodename,
+ MODEST_CONF_DEVICE_NAME, bt_name,
NULL);
}
}
+static void
+get_default_adapter_cb (DBusPendingCall *call,
+ void *user_data)
+{
+ DBusMessage *message;
+ DBusMessageIter iter;
+ gchar* path = NULL;
+
+ message = dbus_pending_call_steal_reply(call);
+
+ // Todo extract msg info from here
+ dbus_message_iter_init ( message, &iter );
+
+ dbus_message_iter_get_basic (&iter, &path);
+ if (path != NULL) {
+ DBusConnection *conn;
+ DBusMessage *adapterMsg = dbus_message_new_method_call(BTNAME_SERVICE, path,
+ BTNAME_REQUEST_IF,
+ BTNAME_REQ_GET_PROPERTIES);
+ DBusPendingCall *call = NULL;
+
+ conn = dbus_bus_get (DBUS_BUS_SYSTEM, NULL);
+
+ if (conn && dbus_connection_send_with_reply(conn, adapterMsg, &call, -1) ) {
+ dbus_pending_call_set_notify(call, get_properties_cb, NULL, NULL);
+ dbus_pending_call_block(call);
+ dbus_pending_call_unref(call);
+ }
+ } else {
+ g_warning ("Failed to get the default bluetooth adapter");
+ }
+}
+
+void
+modest_maemo_utils_get_device_name (void)
+{
+ static DBusConnection *conn = NULL;
+ DBusMessage *request;
+ DBusError error;
+ DBusPendingCall *call = NULL;
+
+ dbus_error_init (&error);
+ if (!conn) {
+ conn = dbus_bus_get (DBUS_BUS_SYSTEM, &error);
+ if (!conn) {
+ g_printerr ("modest: cannot get on the dbus: %s: %s\n",
+ error.name, error.message);
+ dbus_error_free (&error);
+ return;
+ }
+ }
+
+ /* Get the default adapter */
+ request = dbus_message_new_method_call(BTNAME_SERVICE, "/" ,
+ BTNAME_REQUEST_IF,
+ BTNAME_REQ_DEFAULT_ADAPTER);
+
+ if (dbus_connection_send_with_reply(conn, request, &call, -1)) {
+ dbus_pending_call_set_notify(call, get_default_adapter_cb, NULL, NULL);
+ dbus_pending_call_block(call);
+ dbus_pending_call_unref(call);
+ }
+
+/* request = dbus_message_new_method_call (BTNAME_SERVICE, BTNAME_REQUEST_PATH, */
+/* BTNAME_REQUEST_IF, BTNAME_REQ_GET); */
+/* if (!request) { */
+/* /\* should we free the connection? *\/ */
+/* g_printerr ("modest: dbus_message_new_method_call failed\n"); */
+/* return; */
+/* } */
+/* dbus_message_set_auto_start (request, TRUE); */
+/* if (dbus_connection_send_with_reply (conn, request, &call, -1)) { */
+/* dbus_pending_call_set_notify (call, on_device_name_received, */
+/* NULL, NULL); */
+/* dbus_pending_call_unref (call); */
+/* } */
+/* dbus_message_unref (request); */
+
+/* dbus_connection_setup_with_g_main (conn, NULL); */
+/* dbus_bus_add_match (conn, BTNAME_MATCH_RULE, &error); */
+/* if (dbus_error_is_set(&error)) { */
+/* g_printerr ("modest: dbus_bus_add_match failed: %s\n", error.message); */
+/* dbus_error_free (&error); */
+/* } */
+
+/* if (!dbus_connection_add_filter(conn, handle_dbus_signal, NULL, NULL)) */
+/* g_printerr ("modest: dbus_connection_add_filter failed\n"); */
+}
+
void
modest_maemo_utils_setup_images_filechooser (GtkFileChooser *chooser)
{
- gchar *images_folder;
GtkFileFilter *file_filter;
GList *image_mimetypes_list;
GList *node;
+ gchar *conf_folder;
g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
- /* Set the default folder to images folder */
- images_folder = g_build_filename (g_getenv (MODEST_MAEMO_UTILS_MYDOCS_ENV),
- MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER, NULL);
- gtk_file_chooser_set_current_folder (chooser, images_folder);
- g_free (images_folder);
+ conf_folder = modest_conf_get_string (modest_runtime_get_conf (), MODEST_CONF_LATEST_INSERT_IMAGE_PATH, NULL);
+ if (conf_folder && conf_folder[0] != '\0') {
+ gtk_file_chooser_set_current_folder_uri (chooser, conf_folder);
+ } else {
+ gchar *images_folder;
+ /* Set the default folder to images folder */
+ images_folder = g_build_filename (g_getenv (MODEST_MAEMO_UTILS_MYDOCS_ENV),
+ MODEST_MAEMO_UTILS_DEFAULT_IMAGE_FOLDER, NULL);
+ gtk_file_chooser_set_current_folder (chooser, images_folder);
+ g_free (images_folder);
+ }
+ g_free (conf_folder);
/* Set the images mime filter */
file_filter = gtk_file_filter_new ();
#endif /* MODEST_HAVE_HILDON1_WIDGETS */
}
-FILE*
-modest_maemo_open_mcc_mapping_file (gboolean *translated)
-{
- FILE* result = NULL;
- const gchar* path;
- gchar *path1 = g_strdup_printf ("%s.%s", MODEST_OPERATOR_WIZARD_MCC_MAPPING, getenv("LANG"));
- const gchar* path2 = MODEST_MCC_MAPPING;
-
- if (translated)
- *translated = TRUE;
-
- if (access (path1, R_OK) == 0) {
- path = path1;
- } else if (access (MODEST_OPERATOR_WIZARD_MCC_MAPPING, R_OK) == 0) {
- path = MODEST_OPERATOR_WIZARD_MCC_MAPPING;
- if (translated)
- *translated = FALSE;
- } 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);
- goto end;
- }
-
- result = fopen (path, "r");
- if (!result) {
- g_warning ("%s: error opening mapping file '%s': %s",
- __FUNCTION__, path, strerror(errno));
- goto end;
- }
- end:
- g_free (path1);
- return result;
-}
-
GtkWidget *
modest_maemo_utils_get_manager_menubar_as_menu (GtkUIManager *manager,
const gchar *item_name)
title,
use_markup,
control,
- HILDON_SIZE_FINGER_HEIGHT | HILDON_SIZE_AUTO_WIDTH);
+ 0);
}
/**
GtkWidget *dialog;
gint response;
gboolean result = TRUE;
+ gint attachments_added = 0;
model = GTK_TREE_MODEL (gtk_list_store_new (2, G_TYPE_STRING, G_TYPE_OBJECT));
for (iterator = tny_list_create_iterator (att_list);
tny_iterator_next (iterator)) {
GtkTreeIter iter;
TnyMimePart *part;
+ gchar *filename = NULL;
part = (TnyMimePart *) tny_iterator_get_current (iterator);
- /* Embbeded messages are not offered to be
- saved. Purged attachments are ignored as well */
- if (!TNY_IS_MSG (part) && !tny_mime_part_is_purged (part)) {
- gchar *label;
- gchar *filename = NULL;
-
- filename = g_strdup (tny_mime_part_get_filename (part));
- label = g_strconcat (filename, NULL);
+ /* Ignore purged attachments and messages if ignore is
+ set to TRUE */
+ if (!(tny_mime_part_is_purged (part) ||
+ (TNY_IS_MSG (part) && !include_msgs))) {
+
+ if (TNY_IS_MSG (part)) {
+ TnyHeader *header = tny_msg_get_header (TNY_MSG (part));
+ filename = tny_header_dup_subject (header);
+ if ((filename == NULL) || (filename[0] == '\0')) {
+ g_free (filename);
+ filename = g_strdup (_("mail_va_no_subject"));
+ }
+ g_object_unref (header);
+ } else {
+ filename = g_strdup (tny_mime_part_get_filename (part));
+ }
gtk_list_store_append (GTK_LIST_STORE (model), &iter);
- gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, label, 1, part, -1);
- g_free (label);
+ gtk_list_store_set (GTK_LIST_STORE (model), &iter, 0, filename, 1, part, -1);
+ attachments_added ++;
+ g_free (filename);
g_object_unref (part);
}
}
HILDON_TOUCH_SELECTOR_SELECTION_MODE_MULTIPLE);
dialog = hildon_picker_dialog_new (window);
- gtk_window_set_title (GTK_WINDOW (dialog), _("mcen_ti_select_attachment_title"));
+ gtk_window_set_title (GTK_WINDOW (dialog), (attachments_added > 1)?
+ _("mcen_ti_select_attachments_title"):_("mcen_ti_select_attachment_title"));
hildon_picker_dialog_set_selector (HILDON_PICKER_DIALOG (dialog), HILDON_TOUCH_SELECTOR (selector));
hildon_picker_dialog_set_done_label (HILDON_PICKER_DIALOG (dialog), _HL("wdgt_bd_done"));