#include <gdk/gdkkeysyms.h>
#include <gtk/gtk.h>
#include <string.h>
+#ifdef HAVE_UNISTD_H
+ #include <unistd.h>
+#endif
+
+#if HAVE_LIBSOUP
+ #include <libsoup/soup.h>
+#endif
struct _MidoriBrowser
{
KatzeArray* trash;
KatzeArray* search_engines;
KatzeArray* history;
+
+ #if HAVE_LIBSOUP
+ SoupSession* session;
+ #endif
};
G_DEFINE_TYPE (MidoriBrowser, midori_browser, GTK_TYPE_WINDOW)
midori_view_set_zoom_level (MIDORI_VIEW (view), 1.0f);
}
+#if HAVE_LIBSOUP
+static void
+midori_browser_got_body_cb (SoupMessage* msg,
+ MidoriBrowser* browser)
+{
+ SoupURI* soup_uri;
+ gchar* uri;
+ gchar* filename;
+ gchar* unique_filename;
+ gchar* text_editor;
+ gint fd;
+ FILE* fp;
+
+ if (msg->response_body->length > 0)
+ {
+ soup_uri = soup_message_get_uri (msg);
+ uri = soup_uri_to_string (soup_uri, FALSE);
+ filename = g_strdup_printf ("%uXXXXXX", g_str_hash (uri));
+ g_free (uri);
+ if (((fd = g_file_open_tmp (filename, &unique_filename, NULL)) != -1))
+ {
+ if ((fp = fdopen (fd, "w")))
+ {
+ fwrite (msg->response_body->data,
+ 1, msg->response_body->length, fp);
+ fclose (fp);
+ g_object_get (browser->settings,
+ "text-editor", &text_editor, NULL);
+ sokoke_spawn_program (text_editor, unique_filename);
+ g_free (unique_filename);
+ g_free (text_editor);
+ }
+ close (fd);
+ }
+ g_free (filename);
+ }
+}
+#endif
+
static void
_action_source_view_activate (GtkAction* action,
MidoriBrowser* browser)
{
+ gchar* text_editor;
+ const gchar* current_uri;
+ #if HAVE_LIBSOUP
+ SoupMessage* msg;
+ #endif
GtkWidget* view;
GtkWidget* source_view;
+ gchar* filename;
gchar* uri;
gint n;
if (!(view = midori_browser_get_current_tab (browser)))
return;
- uri = g_strdup_printf ("view-source:%s",
- midori_view_get_display_uri (MIDORI_VIEW (view)));
- source_view = midori_view_new ();
- midori_view_set_settings (MIDORI_VIEW (source_view), browser->settings);
- midori_view_set_uri (MIDORI_VIEW (source_view), uri);
- g_free (uri);
- gtk_widget_show (source_view);
- n = midori_browser_add_tab (browser, source_view);
- midori_browser_set_current_page (browser, n);
+ g_object_get (browser->settings, "text-editor", &text_editor, NULL);
+ if (text_editor && *text_editor)
+ {
+ current_uri = midori_view_get_display_uri (MIDORI_VIEW (view));
+ #if HAVE_LIBSOUP
+ if (g_str_has_prefix (current_uri, "http://") ||
+ g_str_has_prefix (current_uri, "https://"))
+ {
+ msg = soup_message_new ("GET", current_uri);
+ g_signal_connect (msg, "got-body",
+ G_CALLBACK (midori_browser_got_body_cb), browser);
+ soup_session_queue_message (browser->session, msg, NULL, NULL);
+ g_free (text_editor);
+ return;
+ }
+ #endif
+ if (g_str_has_prefix (current_uri, "file://"))
+ {
+ filename = g_filename_from_uri (current_uri, NULL, NULL);
+ sokoke_spawn_program (text_editor, filename);
+ }
+ }
+ else
+ {
+ uri = g_strdup_printf ("view-source:%s",
+ midori_view_get_display_uri (MIDORI_VIEW (view)));
+ source_view = midori_view_new ();
+ midori_view_set_settings (MIDORI_VIEW (source_view), browser->settings);
+ midori_view_set_uri (MIDORI_VIEW (source_view), uri);
+ g_free (uri);
+ gtk_widget_show (source_view);
+ n = midori_browser_add_tab (browser, source_view);
+ midori_browser_set_current_page (browser, n);
+ }
+ g_free (text_editor);
}
static void
GtkRcStyle* rcstyle;
GtkAction* action;
+ #if HAVE_LIBSOUP
+ browser->session = soup_session_async_new ();
+ #endif
+
browser->settings = midori_web_settings_new ();
browser->proxy_array = katze_array_new (KATZE_TYPE_ARRAY);
browser->bookmarks = NULL;
if (browser->history)
g_object_unref (browser->history);
+ #if HAVE_LIBSOUP
+ g_object_unref (browser->session);
+ #endif
+
G_OBJECT_CLASS (midori_browser_parent_class)->finalize (object);
}
FILLED_ADD (entry, 1, 2, 1, 2);
/* TODO: We need something like "use current website" */
FRAME_NEW (_("Transfers"));
- TABLE_NEW (1, 2);
+ TABLE_NEW (3, 2);
label = katze_property_label (settings, "download-folder");
INDENTED_ADD (label, 0, 1, 0, 1);
button = katze_property_proxy (settings, "download-folder", "folder");
g_signal_connect (entry, "focus-out-event",
G_CALLBACK (proxy_download_manager_icon_cb), button);
FILLED_ADD (hbox, 1, 2, 1, 2);
+ label = katze_property_label (settings, "text-editor");
+ INDENTED_ADD (label, 0, 1, 2, 3);
+ hbox = gtk_hbox_new (FALSE, 4);
+ button = gtk_image_new ();
+ gtk_icon_size_lookup_for_settings (gtk_widget_get_settings (button),
+ GTK_ICON_SIZE_MENU, &icon_width, &icon_height);
+ gtk_widget_set_size_request (button, icon_width, icon_height);
+ gtk_box_pack_start (GTK_BOX (hbox), button, FALSE, FALSE, 4);
+ entry = katze_property_proxy (settings, "text-editor", NULL);
+ gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0);
+ proxy_download_manager_icon_cb (entry, NULL, GTK_IMAGE (button));
+ g_signal_connect (entry, "focus-out-event",
+ G_CALLBACK (proxy_download_manager_icon_cb), button);
+ FILLED_ADD (hbox, 1, 2, 2, 3);
/* Page "Appearance" */
PAGE_NEW (GTK_STOCK_SELECT_FONT, _("Appearance"));
gchar* homepage;
gchar* download_folder;
gchar* download_manager;
+ gchar* text_editor;
gchar* location_entry_search;
MidoriPreferredEncoding preferred_encoding;
PROP_HOMEPAGE,
PROP_DOWNLOAD_FOLDER,
PROP_DOWNLOAD_MANAGER,
+ PROP_TEXT_EDITOR,
PROP_LOCATION_ENTRY_SEARCH,
PROP_PREFERRED_ENCODING,
NULL,
flags));
+ g_object_class_install_property (gobject_class,
+ PROP_TEXT_EDITOR,
+ g_param_spec_string (
+ "text-editor",
+ _("Text Editor"),
+ _("An external text editor"),
+ NULL,
+ flags));
+
g_object_class_install_property (gobject_class,
PROP_LOCATION_ENTRY_SEARCH,
g_param_spec_string (
case PROP_DOWNLOAD_MANAGER:
katze_assign (web_settings->download_manager, g_value_dup_string (value));
break;
+ case PROP_TEXT_EDITOR:
+ katze_assign (web_settings->text_editor, g_value_dup_string (value));
+ break;
case PROP_LOCATION_ENTRY_SEARCH:
katze_assign (web_settings->location_entry_search, g_value_dup_string (value));
break;
case PROP_DOWNLOAD_MANAGER:
g_value_set_string (value, web_settings->download_manager);
break;
+ case PROP_TEXT_EDITOR:
+ g_value_set_string (value, web_settings->text_editor);
+ break;
case PROP_LOCATION_ENTRY_SEARCH:
g_value_set_string (value, web_settings->location_entry_search);
break;