2007-11-07 [colin] 3.0.2cvs124
[claws.git] / src / mimeview.c
index 5eef45c03ecd80ed2c7b8397204ce52e5f8c56ad..35aa0ccc29d6fad0996a8707ac341ffa9686cf05 100644 (file)
@@ -41,6 +41,8 @@
 #include <gtk/gtkcontainer.h>
 #include <gtk/gtkbutton.h>
 #include <stdio.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 
 #ifndef HAVE_APACHE_FNMATCH
 /* kludge: apache's fnmatch clashes with <regex.h>, don't include
 #include "gtk/logwindow.h"
 #include "timing.h"
 
+#ifdef MAEMO
+//#include <hildon-widgets/hildon-program.h>
+//#include <gtk/gtkmain.h>
+#include <libosso.h>
+#include <osso-mime.h>
+#endif
+
 typedef enum
 {
        COL_MIMETYPE = 0,
@@ -164,7 +173,9 @@ static void mimeview_launch_cb(MimeView *mimeview)
 static GtkItemFactoryEntry mimeview_popup_entries[] =
 {
        {N_("/_Open (l)"),                NULL, mimeview_launch_cb,       0, NULL},
+#ifndef MAEMO
        {N_("/Open _with (o)..."),        NULL, mimeview_open_with,       0, NULL},
+#endif
        {N_("/_Display as text (t)"),     NULL, mimeview_display_as_text, 0, NULL},
        {N_("/_Save as (y)..."),          NULL, mimeview_save_as,         0, NULL},
        {N_("/Save _all..."),             NULL, mimeview_save_all,        0, NULL},
@@ -779,7 +790,7 @@ void mimeview_clear(MimeView *mimeview)
 }
 
 static void check_signature_cb(GtkWidget *widget, gpointer user_data);
-void mimeview_check_signature(MimeView *mimeview);
+static void mimeview_check_signature(MimeView *mimeview);
 static void display_full_info_cb(GtkWidget *widget, gpointer user_data);
 
 static void update_signature_noticeview(MimeView *mimeview, MimeInfo *mimeinfo, 
@@ -1050,7 +1061,7 @@ static void check_signature_cb(GtkWidget *widget, gpointer user_data)
 #endif
        noticeview_set_text(mimeview->siginfoview, _("Checking signature..."));
        GTK_EVENTS_FLUSH();
-#if (defined USE_PTHREAD && defined __GLIBC__ && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3)))
+#if (defined USE_PTHREAD && ((defined __GLIBC__ && (__GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 3))) || !defined __GLIBC__))
        /* let's do it non-blocking */
        mimeview_check_sig_in_thread(mimeview);
        if (!mimeview->check_data) /* let's check syncronously */
@@ -1064,7 +1075,7 @@ static void check_signature_cb(GtkWidget *widget, gpointer user_data)
        }
 }
 
-void mimeview_check_signature(MimeView *mimeview)
+static void mimeview_check_signature(MimeView *mimeview)
 {
        check_signature_cb(NULL, mimeview);     
 }
@@ -1765,6 +1776,9 @@ static void mimeview_open_with(MimeView *mimeview)
        mimeview_open_part_with(mimeview, partinfo, FALSE);
 }
 
+#ifdef MAEMO
+osso_context_t *get_osso_context(void);
+#endif
 static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboolean automatic)
 {
        gchar *filename;
@@ -1772,6 +1786,11 @@ static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboo
        gchar *mime_command = NULL;
        gchar *content_type = NULL;
        gint err;
+#ifdef MAEMO
+       DBusConnection *dbusconn;
+       gchar *uri;
+       int r = 0;
+#endif
        g_return_if_fail(partinfo != NULL);
 
        filename = procmime_get_tmp_file_name(partinfo);
@@ -1783,7 +1802,7 @@ static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboo
                g_free(filename);
                return;
        }
-
+       
        if (!prefs_common.mime_open_cmd_history)
                prefs_common.mime_open_cmd_history =
                        add_history(NULL, prefs_common.mime_open_cmd);
@@ -1798,6 +1817,19 @@ static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboo
                        partinfo->subtype);
        }
        
+#ifdef MAEMO
+       if (content_type != NULL) {
+               uri = g_strconcat ("file://", filename, NULL);
+               dbusconn = osso_get_dbus_connection (get_osso_context());
+               r = osso_mime_open_file_with_mime_type (dbusconn, uri, content_type);
+               g_free(uri);
+       }
+       if (r != 1) {
+               alertpanel_error(_("No registered viewer for this file type."));
+       }
+       goto out;
+#endif
+       
        if ((partinfo->type == MIMETYPE_TEXT && !strcmp(partinfo->subtype, "html"))
        && prefs_common.uri_cmd && prefs_common.uri_cmd[0]) {
                mime_command = g_strdup(prefs_common.uri_cmd);
@@ -1829,16 +1861,14 @@ static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboo
                                 _("Enter the command line to open file:\n"
                                   "('%s' will be replaced with file name)"),
                                 mime_command ? mime_command : prefs_common.mime_open_cmd,
-                                prefs_common.mime_open_cmd_history,
-                                TRUE, &remember);
+                                prefs_common.mime_open_cmd_history, &remember);
                else
                        cmd = input_dialog_combo
                                (_("Open with"),
                                 _("Enter the command line to open file:\n"
                                   "('%s' will be replaced with file name)"),
                                 mime_command ? mime_command : prefs_common.mime_open_cmd,
-                                prefs_common.mime_open_cmd_history,
-                                TRUE);
+                                prefs_common.mime_open_cmd_history);
                if (cmd && remember) {
                        mailcap_update_default(content_type, cmd);
                }
@@ -1853,6 +1883,9 @@ static void mimeview_open_part_with(MimeView *mimeview, MimeInfo *partinfo, gboo
                prefs_common.mime_open_cmd_history =
                        add_history(prefs_common.mime_open_cmd_history, cmd);
        }
+#ifdef MAEMO
+out:
+#endif
        g_free(content_type);
        g_free(filename);
 }
@@ -1866,14 +1899,21 @@ static void mimeview_view_file(const gchar *filename, MimeInfo *partinfo,
                mimeview_open_part_with(mimeview, partinfo, TRUE);
        else {
                if ((p = strchr(cmd, '%')) && *(p + 1) == 's' &&
-                   !strchr(p + 2, '%'))
+                   !strchr(p + 2, '%')) {
                        g_snprintf(buf, sizeof(buf), cmd, filename);
-               else {
+                       if (!prefs_common.save_parts_readwrite)
+                               g_chmod(filename, S_IRUSR);
+                       else
+                               g_chmod(filename, S_IRUSR|S_IWUSR);
+               } else {
                        g_warning("MIME viewer command line is invalid: '%s'", cmd);
                        mimeview_open_part_with(mimeview, partinfo, FALSE);
                }
-               if (execute_command_line(buf, TRUE) != 0)
+               if (execute_command_line(buf, TRUE) != 0) {
+                       if (!prefs_common.save_parts_readwrite)
+                               g_chmod(filename, S_IRUSR|S_IWUSR);
                        mimeview_open_part_with(mimeview, partinfo, FALSE);
+               }
        }
 }
 
@@ -2222,6 +2262,7 @@ static void icon_list_clear (MimeView *mimeview)
        mimeview->icon_count = 0;
        adj  = gtk_layout_get_vadjustment(GTK_LAYOUT(mimeview->icon_scroll));
        gtk_adjustment_set_value(adj, adj->lower);
+       gtk_adjustment_changed(adj);
 }
 
 /*!
@@ -2283,16 +2324,16 @@ static void icon_list_toggle_by_mime_info (MimeView     *mimeview,
                        continue;
                if(g_object_get_data(G_OBJECT(child->data),
                                      "partinfo") == (gpointer)mimeinfo) {
-                       gint *border_x = NULL;
+                       gboolean *highlight = NULL;
                        GtkWidget *icon = gtk_bin_get_child(GTK_BIN(child->data));
-                       border_x = g_object_get_data(G_OBJECT(icon), "border_x");
-                       *border_x = 0;
+                       highlight = g_object_get_data(G_OBJECT(icon), "highlight");
+                       *highlight = TRUE;
                        gtk_widget_queue_draw(icon);
                } else {
-                       gint *border_x = NULL;
+                       gint *highlight = NULL;
                        GtkWidget *icon = gtk_bin_get_child(GTK_BIN(child->data));
-                       border_x = g_object_get_data(G_OBJECT(icon), "border_x");
-                       *border_x = 6;
+                       highlight = g_object_get_data(G_OBJECT(icon), "highlight");
+                       *highlight = FALSE;
                        gtk_widget_queue_draw(icon);
                }                        
        }