aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ephy-shell.c35
-rw-r--r--src/ephy-shell.h5
-rw-r--r--src/window-commands.c130
3 files changed, 150 insertions, 20 deletions
diff --git a/src/ephy-shell.c b/src/ephy-shell.c
index d6dc7b61a..9eac44c94 100644
--- a/src/ephy-shell.c
+++ b/src/ephy-shell.c
@@ -76,6 +76,7 @@ struct EphyShellPrivate
GtkWidget *bme;
GtkWidget *history_window;
GList *plugins;
+ GList *del_on_exit;
};
static void
@@ -279,6 +280,15 @@ ephy_shell_init (EphyShell *gs)
}
static void
+delete_files (GList *l)
+{
+ for (; l != NULL; l = l->next)
+ {
+ unlink (l->data);
+ }
+}
+
+static void
ephy_shell_finalize (GObject *object)
{
EphyShell *gs = EPHY_SHELL (object);
@@ -288,6 +298,10 @@ ephy_shell_finalize (GObject *object)
g_list_foreach (gs->priv->plugins, (GFunc)g_type_module_unuse, NULL);
g_list_free (gs->priv->plugins);
+ delete_files (gs->priv->del_on_exit);
+ g_list_foreach (gs->priv->del_on_exit, (GFunc)g_free, NULL);
+ g_list_free (gs->priv->del_on_exit);
+
LOG ("Unref toolbars model")
if (gs->priv->toolbars_model)
{
@@ -460,8 +474,7 @@ ephy_shell_new_tab (EphyShell *shell,
}
grouped = ((flags & EPHY_NEW_TAB_OPEN_PAGE ||
- flags & EPHY_NEW_TAB_APPEND_GROUPED ||
- flags & EPHY_NEW_TAB_CLONE_PAGE)) &&
+ flags & EPHY_NEW_TAB_APPEND_GROUPED)) &&
!(flags & EPHY_NEW_TAB_APPEND_LAST);
if ((flags & EPHY_NEW_TAB_APPEND_AFTER) && previous_embed != NULL)
@@ -495,16 +508,6 @@ ephy_shell_new_tab (EphyShell *shell,
g_assert (url != NULL);
ephy_embed_load_url (embed, url);
}
- else if (flags & EPHY_NEW_TAB_CLONE_PAGE)
- {
- EmbedDisplayType display_type;
-
- display_type = (flags & EPHY_NEW_TAB_SOURCE_MODE) ?
- DISPLAY_AS_SOURCE : DISPLAY_NORMAL;
-
- ephy_embed_load_url (embed, "about:blank");
- ephy_embed_copy_page (embed, previous_embed, display_type);
- }
if (flags & EPHY_NEW_TAB_FULLSCREEN_MODE)
{
@@ -698,3 +701,11 @@ ephy_shell_show_history_window (EphyShell *gs,
gtk_window_present (GTK_WINDOW (gs->priv->history_window));
}
+
+void
+ephy_shell_delete_on_exit (EphyShell *gs, const char *path)
+{
+ gs->priv->del_on_exit = g_list_append (gs->priv->del_on_exit,
+ g_strdup (path));
+}
+
diff --git a/src/ephy-shell.h b/src/ephy-shell.h
index 5c6d54899..381277f53 100644
--- a/src/ephy-shell.h
+++ b/src/ephy-shell.h
@@ -53,11 +53,9 @@ typedef enum
EPHY_NEW_TAB_HOME_PAGE = 1 << 0,
EPHY_NEW_TAB_NEW_PAGE = 1 << 1,
EPHY_NEW_TAB_OPEN_PAGE = 1 << 2,
- EPHY_NEW_TAB_CLONE_PAGE = 1 << 3,
/* Page mode */
EPHY_NEW_TAB_FULLSCREEN_MODE = 1 << 4,
- EPHY_NEW_TAB_SOURCE_MODE = 1 << 5,
/* Tabs */
EPHY_NEW_TAB_APPEND_GROUPED = 1 << 6,
@@ -104,6 +102,9 @@ void ephy_shell_show_bookmarks_editor (EphyShell *gs,
void ephy_shell_show_history_window (EphyShell *gs,
GtkWidget *parent);
+void ephy_shell_delete_on_exit (EphyShell *gs,
+ const char *path);
+
G_END_DECLS
#endif
diff --git a/src/window-commands.c b/src/window-commands.c
index 5ae736448..4d9e54e33 100644
--- a/src/window-commands.c
+++ b/src/window-commands.c
@@ -53,6 +53,7 @@
#include <libgnomeui/gnome-stock-icons.h>
#include <libgnomeui/gnome-icon-theme.h>
#include <libgnome/gnome-program.h>
+#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <gtk/gtkeditable.h>
#include <gtk/gtktoggleaction.h>
@@ -600,18 +601,135 @@ window_cmd_view_zoom_normal (GtkAction *action,
ephy_window_set_zoom (window, 1.0);
}
+static GnomeVFSMimeApplication *
+get_editor_application (void)
+{
+ GnomeVFSMimeApplication *app;
+
+ app = gnome_vfs_mime_get_default_application ("text/plain");
+ if (app == NULL)
+ {
+ g_warning ("Cannot find a text editor.");
+ }
+ return app;
+}
+
+static void
+editor_open_uri (const char *address)
+{
+ GList *uris = NULL;
+ char *canonical;
+ GnomeVFSMimeApplication *app;
+
+ canonical = gnome_vfs_make_uri_canonical (address);
+
+ uris = g_list_append (uris, canonical);
+
+ app = get_editor_application ();
+ if (app)
+ {
+ gnome_vfs_mime_application_launch (app, uris);
+ gnome_vfs_mime_application_free (app);
+ }
+
+ g_free (canonical);
+ g_list_free (uris);
+}
+
+static void
+save_source_completed_cb (EphyEmbedPersist *persist)
+{
+ const char *dest;
+
+ dest = ephy_embed_persist_get_dest (persist);
+ g_return_if_fail (dest != NULL);
+
+ ephy_shell_delete_on_exit (ephy_shell, dest);
+
+ editor_open_uri (dest);
+}
+
+static gboolean
+editor_can_open_uri (char *address)
+{
+ GnomeVFSMimeApplication *app;
+ GnomeVFSURI *uri;
+ const char *scheme;
+ gboolean result = FALSE;
+
+ app = get_editor_application ();
+
+ uri = gnome_vfs_uri_new (address);
+ scheme = uri ? gnome_vfs_uri_get_scheme (uri) : NULL;
+
+ /* Open directly only read/write protocols, otherwise
+ you just get extra network overhead without any advantage */
+ if (scheme && strcmp (scheme, "file") != 0)
+ {
+ scheme = NULL;
+ }
+
+ if (scheme && app && app->supported_uri_schemes)
+ {
+ if (g_list_find_custom (app->supported_uri_schemes,
+ scheme, (GCompareFunc) strcmp))
+ {
+ result = TRUE;
+ }
+ }
+
+ if (uri)
+ {
+ gnome_vfs_uri_unref (uri);
+ }
+
+ return result;
+}
+
+static void
+save_temp_source (EphyEmbed *embed)
+{
+ char *tmp, *base;
+ EphyEmbedPersist *persist;
+
+ base = g_build_filename (g_get_tmp_dir (), "viewsourceXXXXXX", NULL);
+ tmp = ephy_file_tmp_filename (base, "html");
+ g_free (base);
+
+ persist = ephy_embed_persist_new (embed);
+ ephy_embed_persist_set_flags (persist, EMBED_PERSIST_COPY_PAGE |
+ EMBED_PERSIST_NO_VIEW);
+ ephy_embed_persist_set_dest (persist, tmp);
+
+ g_signal_connect (persist, "completed",
+ G_CALLBACK (save_source_completed_cb), NULL);
+
+ ephy_embed_persist_save (persist);
+ g_object_unref (persist);
+
+ g_free (tmp);
+}
+
void
window_cmd_view_page_source (GtkAction *action,
EphyWindow *window)
{
- EphyTab *tab;
+ EphyEmbed *embed;
+ char *address;
- tab = ephy_window_get_active_tab (window);
- g_return_if_fail (tab != NULL);
+ embed = ephy_window_get_active_embed (window);
+ g_return_if_fail (embed != NULL);
- ephy_shell_new_tab (ephy_shell, window, tab, NULL,
- EPHY_NEW_TAB_CLONE_PAGE |
- EPHY_NEW_TAB_SOURCE_MODE);
+ ephy_embed_get_location (embed, TRUE, &address);
+
+ if (editor_can_open_uri (address))
+ {
+ editor_open_uri (address);
+ }
+ else
+ {
+ save_temp_source (embed);
+ }
}
void