aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarco Pesenti Gritti <marco@gnome.org>2003-10-28 19:33:19 +0800
committerMarco Pesenti Gritti <marco@src.gnome.org>2003-10-28 19:33:19 +0800
commit025c7959e438aad9770f9aa801b6ead6e19e79dd (patch)
tree7a3595c5b012722d6e6dcea81b97773c15c9450c
parent4ff6bbed9a23f05f1ee9158d2607c2e811c5de6f (diff)
downloadgsoc2013-epiphany-025c7959e438aad9770f9aa801b6ead6e19e79dd.tar
gsoc2013-epiphany-025c7959e438aad9770f9aa801b6ead6e19e79dd.tar.gz
gsoc2013-epiphany-025c7959e438aad9770f9aa801b6ead6e19e79dd.tar.bz2
gsoc2013-epiphany-025c7959e438aad9770f9aa801b6ead6e19e79dd.tar.lz
gsoc2013-epiphany-025c7959e438aad9770f9aa801b6ead6e19e79dd.tar.xz
gsoc2013-epiphany-025c7959e438aad9770f9aa801b6ead6e19e79dd.tar.zst
gsoc2013-epiphany-025c7959e438aad9770f9aa801b6ead6e19e79dd.zip
Open source in the default editor and remove the unused copy api. Add a
2003-10-28 Marco Pesenti Gritti <marco@gnome.org> * embed/ephy-embed-persist.h: * embed/ephy-embed.c: * embed/ephy-embed.h: * embed/ephy-favicon-cache.c: (ephy_favicon_cache_download): * embed/mozilla/EphyBrowser.cpp: * embed/mozilla/EphyBrowser.h: * embed/mozilla/EphyHeaderSniffer.cpp: * embed/mozilla/EphyHeaderSniffer.h: * embed/mozilla/MozDownload.cpp: * embed/mozilla/MozDownload.h: * embed/mozilla/mozilla-embed-persist.cpp: * embed/mozilla/mozilla-embed.cpp: * src/ephy-shell.c: (delete_files), (ephy_shell_finalize), (ephy_shell_new_tab), (ephy_shell_delete_on_exit): * src/ephy-shell.h: * src/window-commands.c: (get_editor_application), (editor_open_uri), (save_source_completed_cb), (editor_can_open_uri), (save_temp_source), (window_cmd_view_page_source): Open source in the default editor and remove the unused copy api. Add a missing include while at it.
-rw-r--r--ChangeLog26
-rw-r--r--embed/ephy-embed-persist.h2
-rw-r--r--embed/ephy-embed.c9
-rw-r--r--embed/ephy-embed.h13
-rw-r--r--embed/ephy-favicon-cache.c3
-rw-r--r--embed/mozilla/EphyBrowser.cpp17
-rw-r--r--embed/mozilla/EphyBrowser.h2
-rw-r--r--embed/mozilla/EphyHeaderSniffer.cpp5
-rw-r--r--embed/mozilla/EphyHeaderSniffer.h3
-rw-r--r--embed/mozilla/MozDownload.cpp18
-rw-r--r--embed/mozilla/MozDownload.h2
-rw-r--r--embed/mozilla/mozilla-embed-persist.cpp18
-rw-r--r--embed/mozilla/mozilla-embed.cpp25
-rw-r--r--src/ephy-shell.c35
-rw-r--r--src/ephy-shell.h5
-rw-r--r--src/window-commands.c130
16 files changed, 204 insertions, 109 deletions
diff --git a/ChangeLog b/ChangeLog
index 8397a0e5d..4f2a3acf0 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,29 @@
+2003-10-28 Marco Pesenti Gritti <marco@gnome.org>
+
+ * embed/ephy-embed-persist.h:
+ * embed/ephy-embed.c:
+ * embed/ephy-embed.h:
+ * embed/ephy-favicon-cache.c: (ephy_favicon_cache_download):
+ * embed/mozilla/EphyBrowser.cpp:
+ * embed/mozilla/EphyBrowser.h:
+ * embed/mozilla/EphyHeaderSniffer.cpp:
+ * embed/mozilla/EphyHeaderSniffer.h:
+ * embed/mozilla/MozDownload.cpp:
+ * embed/mozilla/MozDownload.h:
+ * embed/mozilla/mozilla-embed-persist.cpp:
+ * embed/mozilla/mozilla-embed.cpp:
+ * src/ephy-shell.c: (delete_files), (ephy_shell_finalize),
+ (ephy_shell_new_tab), (ephy_shell_delete_on_exit):
+ * src/ephy-shell.h:
+ * src/window-commands.c: (get_editor_application),
+ (editor_open_uri), (save_source_completed_cb),
+ (editor_can_open_uri), (save_temp_source),
+ (window_cmd_view_page_source):
+
+ Open source in the default editor and
+ remove the unused copy api.
+ Add a missing include while at it.
+
2003-10-27 Marco Pesenti Gritti <marco@gnome.org>
* embed/mozilla/EphyBrowser.cpp:
diff --git a/embed/ephy-embed-persist.h b/embed/ephy-embed-persist.h
index 2f2db4f1b..ca53ff7a2 100644
--- a/embed/ephy-embed-persist.h
+++ b/embed/ephy-embed-persist.h
@@ -44,7 +44,7 @@ typedef struct EphyEmbedPersistPrivate EphyEmbedPersistPrivate;
typedef enum
{
- EMBED_PERSIST_BYPASSCACHE = 1 << 0,
+ EMBED_PERSIST_COPY_PAGE = 1 << 0,
EMBED_PERSIST_MAINDOC = 1 << 1,
EMBED_PERSIST_NO_VIEW = 1 << 2,
EMBED_PERSIST_ASK_DESTINATION = 1 << 3
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 41cbb551f..3158a1d00 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -415,15 +415,6 @@ ephy_embed_reload (EphyEmbed *embed,
}
gresult
-ephy_embed_copy_page (EphyEmbed *dest,
- EphyEmbed *source,
- EmbedDisplayType display_type)
-{
- EphyEmbedClass *klass = EPHY_EMBED_GET_CLASS (dest);
- return klass->copy_page (dest, source, display_type);
-}
-
-gresult
ephy_embed_zoom_set (EphyEmbed *embed,
float zoom,
gboolean reflow)
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index b0c9c77ed..b25f02dea 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -86,12 +86,6 @@ typedef enum
EMBED_RELOAD_BYPASSPROXY = 1 << 3
} EmbedReloadFlags;
-typedef enum
-{
- DISPLAY_AS_SOURCE = 1U,
- DISPLAY_NORMAL = 2U
-} EmbedDisplayType;
-
typedef struct
{
gboolean print_to_file;
@@ -223,9 +217,6 @@ struct EphyEmbedClass
char **location);
gresult (* reload) (EphyEmbed *embed,
EmbedReloadFlags flags);
- gresult (* copy_page) (EphyEmbed *dest,
- EphyEmbed *source,
- EmbedDisplayType display_type);
gresult (* zoom_set) (EphyEmbed *embed,
float zoom,
gboolean reflow);
@@ -321,10 +312,6 @@ gresult ephy_embed_get_location (EphyEmbed *embed,
gresult ephy_embed_reload (EphyEmbed *embed,
EmbedReloadFlags flags);
-gresult ephy_embed_copy_page (EphyEmbed *dest,
- EphyEmbed *source,
- EmbedDisplayType display_type);
-
/* Zoom */
gresult ephy_embed_zoom_set (EphyEmbed *embed,
float zoom,
diff --git a/embed/ephy-favicon-cache.c b/embed/ephy-favicon-cache.c
index f0c3a0022..0ba259132 100644
--- a/embed/ephy-favicon-cache.c
+++ b/embed/ephy-favicon-cache.c
@@ -384,8 +384,7 @@ ephy_favicon_cache_download (EphyFaviconCache *cache,
persist = ephy_embed_persist_new (NULL);
ephy_embed_persist_set_dest (persist, dest);
- ephy_embed_persist_set_flags
- (persist, EMBED_PERSIST_BYPASSCACHE | EMBED_PERSIST_NO_VIEW);
+ ephy_embed_persist_set_flags (persist, EMBED_PERSIST_NO_VIEW);
ephy_embed_persist_set_max_size (persist, 100);
ephy_embed_persist_set_source (persist, favicon_url);
diff --git a/embed/mozilla/EphyBrowser.cpp b/embed/mozilla/EphyBrowser.cpp
index 102607e4e..9dbafbbd7 100644
--- a/embed/mozilla/EphyBrowser.cpp
+++ b/embed/mozilla/EphyBrowser.cpp
@@ -490,23 +490,6 @@ nsresult EphyBrowser::Find (PRBool backwards,
return finder->FindNext(didFind);
}
-nsresult EphyBrowser::LoadDocument(nsISupports *aPageDescriptor,
- PRUint32 aDisplayType)
-{
- nsresult rv;
-
- g_return_val_if_fail (mWebBrowser, NS_ERROR_FAILURE);
-
- nsCOMPtr<nsIDocShell> ds;
- ds = do_GetInterface (mWebBrowser);
- if (!ds) return NS_ERROR_FAILURE;
-
- nsCOMPtr<nsIWebPageDescriptor> wpd = do_QueryInterface(ds, &rv);
- if (!wpd || !NS_SUCCEEDED(rv)) return NS_ERROR_FAILURE;
-
- return wpd->LoadPage(aPageDescriptor, aDisplayType);
-}
-
nsresult EphyBrowser::GetPageDescriptor(nsISupports **aPageDescriptor)
{
nsresult rv;
diff --git a/embed/mozilla/EphyBrowser.h b/embed/mozilla/EphyBrowser.h
index 9d02d87b0..4d4a11da6 100644
--- a/embed/mozilla/EphyBrowser.h
+++ b/embed/mozilla/EphyBrowser.h
@@ -32,6 +32,7 @@
#include "nsCOMPtr.h"
#include "nsIDOMEventReceiver.h"
#include "nsIDOMDocument.h"
+#include "nsIDOMWindow.h"
#include "nsPIDOMWindow.h"
#include <gtkmozembed.h>
@@ -65,7 +66,6 @@ public:
nsresult Find (PRBool bacwards,
PRBool *didFind);
- nsresult LoadDocument(nsISupports *aPageDescriptor, PRUint32 aDisplayType);
nsresult GetPageDescriptor(nsISupports **aPageDescriptor);
nsresult GetSHInfo (PRInt32 *count, PRInt32 *index);
diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp
index 957f9cf19..fb185a0c7 100644
--- a/embed/mozilla/EphyHeaderSniffer.cpp
+++ b/embed/mozilla/EphyHeaderSniffer.cpp
@@ -69,8 +69,7 @@
#include <bonobo/bonobo-i18n.h>
EphyHeaderSniffer::EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist,
- nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData,
- PRBool aBypassCache)
+ nsIFile* aFile, nsIURI* aURL, nsIDOMDocument* aDocument, nsIInputStream* aPostData)
: mPersist(aPersist)
, mEmbedPersist(aEmbedPersist)
, mTmpFile(aFile)
@@ -319,7 +318,7 @@ nsresult EphyHeaderSniffer::InitiateDownload (nsILocalFile *aDestFile)
LOG ("Initiating download")
return InitiateMozillaDownload (mDocument, mURL, aDestFile,
mContentType.get(), mOriginalURI, mEmbedPersist,
- mBypassCache, mPostData);
+ mPostData, nsnull);
}
NS_IMETHODIMP EphyHeaderSniffer::Prompt (const PRUnichar *dialogTitle, const PRUnichar *text,
diff --git a/embed/mozilla/EphyHeaderSniffer.h b/embed/mozilla/EphyHeaderSniffer.h
index c3790cec3..8d5d6f0d3 100644
--- a/embed/mozilla/EphyHeaderSniffer.h
+++ b/embed/mozilla/EphyHeaderSniffer.h
@@ -54,7 +54,7 @@ class EphyHeaderSniffer : public nsIWebProgressListener,
public:
EphyHeaderSniffer (nsIWebBrowserPersist* aPersist, MozillaEmbedPersist *aEmbedPersist,
nsIFile* aFile, nsIURI* aURL,
- nsIDOMDocument* aDocument, nsIInputStream* aPostData, PRBool aBypassCache);
+ nsIDOMDocument* aDocument, nsIInputStream* aPostData);
virtual ~EphyHeaderSniffer ();
NS_DECL_ISUPPORTS
@@ -74,7 +74,6 @@ private:
nsCOMPtr<nsIURI> mOriginalURI;
nsCOMPtr<nsIDOMDocument> mDocument;
nsCOMPtr<nsIInputStream> mPostData;
- PRBool mBypassCache;
nsCString mContentType;
nsCString mContentDisposition;
nsCOMPtr<nsIPromptService> mPrompt;
diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp
index 63901ee35..875d11e3b 100644
--- a/embed/mozilla/MozDownload.cpp
+++ b/embed/mozilla/MozDownload.cpp
@@ -385,10 +385,13 @@ MozDownload::Resume()
nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI,
nsILocalFile* inDestFile, const char *contentType,
nsIURI* inOriginalURI, MozillaEmbedPersist *embedPersist,
- PRBool bypassCache, nsIInputStream *postData)
+ nsIInputStream *postData, nsISupports *aCacheKey)
{
nsresult rv = NS_OK;
+ EmbedPersistFlags ephy_flags;
+ ephy_flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (embedPersist));
+
PRBool isHTML = (domDocument && contentType &&
(strcmp (contentType, "text/html") == 0 ||
strcmp (contentType, "text/xml") == 0 ||
@@ -410,20 +413,15 @@ nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceURI
PRInt32 flags = nsIWebBrowserPersist::PERSIST_FLAGS_NO_CONVERSION |
nsIWebBrowserPersist::PERSIST_FLAGS_REPLACE_EXISTING_FILES;
- if (bypassCache)
- {
- flags |= nsIWebBrowserPersist::PERSIST_FLAGS_BYPASS_CACHE;
- }
- else
+ if (ephy_flags & EMBED_PERSIST_COPY_PAGE)
{
flags |= nsIWebBrowserPersist::PERSIST_FLAGS_FROM_CACHE;
}
-
webPersist->SetPersistFlags(flags);
-
- if (!isHTML)
+
+ if (!isHTML || ephy_flags & EMBED_PERSIST_COPY_PAGE)
{
- rv = webPersist->SaveURI (sourceURI, nsnull, nsnull,
+ rv = webPersist->SaveURI (sourceURI, aCacheKey, nsnull,
postData, nsnull, inDestFile);
}
else
diff --git a/embed/mozilla/MozDownload.h b/embed/mozilla/MozDownload.h
index 49f0e6cc9..89d20b8c3 100644
--- a/embed/mozilla/MozDownload.h
+++ b/embed/mozilla/MozDownload.h
@@ -79,7 +79,7 @@
nsresult InitiateMozillaDownload (nsIDOMDocument *domDocument, nsIURI *sourceUri,
nsILocalFile* inDestFile, const char *contentType,
nsIURI* inOriginalURI, MozillaEmbedPersist *embedPersist,
- PRBool bypassCache, nsIInputStream *postData);
+ nsIInputStream *postData, nsISupports *aCacheKey);
class MozDownload : public nsIDownload,
public nsIWebProgressListener
diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp
index f08d8648e..052aacb76 100644
--- a/embed/mozilla/mozilla-embed-persist.cpp
+++ b/embed/mozilla/mozilla-embed-persist.cpp
@@ -169,7 +169,9 @@ impl_save (EphyEmbedPersist *persist)
"embed", &embed,
"max_size", &max_size,
NULL);
-
+
+ g_return_val_if_fail (!(flags & EMBED_PERSIST_COPY_PAGE)
+ || embed != NULL, G_FAILED);
g_return_val_if_fail (filename != NULL, G_FAILED);
EphyBrowser *browser = NULL;
@@ -244,6 +246,14 @@ impl_save (EphyEmbedPersist *persist)
if (NS_FAILED(rv) || !DOMDocument) return G_FAILED;
}
+
+ /* Get the current page descriptor */
+ nsCOMPtr<nsISupports> pageDescriptor;
+ if (flags & EMBED_PERSIST_COPY_PAGE)
+ {
+ rv = browser->GetPageDescriptor(getter_AddRefs(pageDescriptor));
+ }
+
if (filename == NULL)
{
/* Create an header sniffer and do the save */
@@ -253,8 +263,7 @@ impl_save (EphyEmbedPersist *persist)
EphyHeaderSniffer* sniffer = new EphyHeaderSniffer
(webPersist, MOZILLA_EMBED_PERSIST (persist),
- tmpFile, inURI, DOMDocument, postData,
- flags & EMBED_PERSIST_BYPASSCACHE);
+ tmpFile, inURI, DOMDocument, postData);
if (!sniffer) return G_FAILED;
webPersist->SetProgressListener(sniffer);
@@ -271,8 +280,7 @@ impl_save (EphyEmbedPersist *persist)
rv = InitiateMozillaDownload (DOMDocument, inURI, destFile,
nsnull, inURI, MOZILLA_EMBED_PERSIST (persist),
- flags & EMBED_PERSIST_BYPASSCACHE,
- postData);
+ postData, pageDescriptor);
if (NS_FAILED (rv)) return G_FAILED;
}
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index e240304d2..dbc04ad39 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -99,10 +99,6 @@ static gresult
impl_reload (EphyEmbed *embed,
EmbedReloadFlags flags);
static gresult
-impl_copy_page (EphyEmbed *dest,
- EphyEmbed *source,
- EmbedDisplayType display_type);
-static gresult
impl_zoom_set (EphyEmbed *embed,
float zoom,
gboolean reflow);
@@ -377,7 +373,6 @@ ephy_embed_init (EphyEmbedClass *embed_class)
embed_class->get_title = impl_get_title;
embed_class->get_location = impl_get_location;
embed_class->reload = impl_reload;
- embed_class->copy_page = impl_copy_page;
embed_class->zoom_set = impl_zoom_set;
embed_class->zoom_get = impl_zoom_get;
embed_class->shistory_count = impl_shistory_count;
@@ -802,26 +797,6 @@ impl_reload (EphyEmbed *embed,
}
static gresult
-impl_copy_page (EphyEmbed *dest,
- EphyEmbed *source,
- EmbedDisplayType display_type)
-{
- MozillaEmbedPrivate *mpriv_dest = MOZILLA_EMBED(dest)->priv;
- MozillaEmbedPrivate *mpriv_source = MOZILLA_EMBED(source)->priv;
-
- nsresult rv;
-
- nsCOMPtr<nsISupports> pageDescriptor;
- rv = mpriv_source->browser->GetPageDescriptor(getter_AddRefs(pageDescriptor));
- if (!pageDescriptor || NS_FAILED(rv)) return G_FAILED;
-
- rv = mpriv_dest->browser->LoadDocument(pageDescriptor, static_cast<PRUint32>(display_type));
- if (NS_FAILED(rv)) return G_FAILED;
-
- return G_OK;
-}
-
-static gresult
impl_zoom_set (EphyEmbed *embed,
float zoom,
gboolean reflow)
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