diff options
Diffstat (limited to 'embed')
-rw-r--r-- | embed/Makefile.am | 2 | ||||
-rw-r--r-- | embed/downloader-view.c | 1 | ||||
-rw-r--r-- | embed/ephy-embed-persist.c | 673 | ||||
-rw-r--r-- | embed/ephy-embed-persist.h | 101 | ||||
-rw-r--r-- | embed/ephy-embed-popup-control.c | 79 | ||||
-rw-r--r-- | embed/ephy-embed-single.c | 38 | ||||
-rw-r--r-- | embed/ephy-embed-single.h | 21 | ||||
-rw-r--r-- | embed/ephy-embed-utils.c | 214 | ||||
-rw-r--r-- | embed/ephy-embed-utils.h | 39 | ||||
-rw-r--r-- | embed/ephy-favicon-cache.c | 67 | ||||
-rw-r--r-- | embed/mozilla/ContentHandler.cpp | 74 | ||||
-rw-r--r-- | embed/mozilla/ContentHandler.h | 5 | ||||
-rw-r--r-- | embed/mozilla/EphyHeaderSniffer.cpp | 26 | ||||
-rw-r--r-- | embed/mozilla/FilePicker.cpp | 503 | ||||
-rw-r--r-- | embed/mozilla/FilePicker.h | 55 | ||||
-rw-r--r-- | embed/mozilla/Makefile.am | 1 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 7 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-persist.cpp | 9 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 72 |
19 files changed, 738 insertions, 1249 deletions
diff --git a/embed/Makefile.am b/embed/Makefile.am index 36fc9f247..614ed9955 100644 --- a/embed/Makefile.am +++ b/embed/Makefile.am @@ -23,7 +23,6 @@ NOINST_H_FILES = \ ephy-download.h \ ephy-embed-dialog.h \ ephy-embed-popup-control.h \ - ephy-embed-utils.h \ ephy-favicon-cache.h \ find-dialog.h \ print-dialog.h @@ -51,7 +50,6 @@ libephyembed_la_SOURCES = \ ephy-embed-popup-control.c \ ephy-embed-single.c \ ephy-embed-shell.c \ - ephy-embed-utils.c \ ephy-encodings.c \ ephy-favicon-cache.c \ ephy-history.c \ diff --git a/embed/downloader-view.c b/embed/downloader-view.c index 63050ac61..e557422ca 100644 --- a/embed/downloader-view.c +++ b/embed/downloader-view.c @@ -26,7 +26,6 @@ #include "ephy-gui.h" #include "ephy-prefs.h" #include "ephy-ellipsizing-label.h" -#include "ephy-embed-utils.h" #include "ephy-file-helpers.h" #include "ephy-embed-shell.h" #include "ephy-cell-renderer-progress.h" diff --git a/embed/ephy-embed-persist.c b/embed/ephy-embed-persist.c index 54581e52b..231bf3064 100644 --- a/embed/ephy-embed-persist.c +++ b/embed/ephy-embed-persist.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti + * Copyright (C) 2000-2003 Marco Pesenti Gritti + * Copyright (C) 2003 Christian Persch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -18,474 +19,436 @@ * $Id$ */ -#include <config.h> +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif #include "ephy-embed-persist.h" -#include "ephy-debug.h" -#include "mozilla-embed.h" #include "mozilla-embed-persist.h" +#include "ephy-debug.h" enum { - COMPLETED, - LAST_SIGNAL -}; - -enum -{ - PROP_0, - PROP_EMBED, - PROP_SOURCE, - PROP_DEST, - PROP_MAX_SIZE, - PROP_FLAGS, - PROP_HANDLER + PROP_0, + PROP_DEST, + PROP_EMBED, + PROP_FILECHOOSER_TITLE, + PROP_FILECHOOSER_PARENT, + PROP_FLAGS, + PROP_HANDLER, + PROP_MAX_SIZE, + PROP_PERSISTKEY, + PROP_SOURCE, }; #define EPHY_EMBED_PERSIST_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_EMBED_PERSIST, EphyEmbedPersistPrivate)) struct EphyEmbedPersistPrivate { - char *dir; - char *src; - PersistHandlerInfo *handler; + char *dest; + char *source; + char *fc_title; + char *persist_key; EphyEmbed *embed; int max_size; EmbedPersistFlags flags; + GtkWindow *fc_parent; }; -static void -ephy_embed_persist_class_init (EphyEmbedPersistClass *klass); -static void -ephy_embed_persist_init (EphyEmbedPersist *ges); -static void -ephy_embed_persist_finalize (GObject *object); -static void -ephy_embed_persist_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec); -static void -ephy_embed_persist_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec); - -static gresult -impl_set_source (EphyEmbedPersist *persist, - const char *url); -static gresult -impl_set_dest (EphyEmbedPersist *persist, - const char *dir); -static gresult -impl_set_max_size (EphyEmbedPersist *persist, - int kb_size); -static gresult -impl_set_embed (EphyEmbedPersist *persist, - EphyEmbed *embed); -static gresult -impl_set_flags (EphyEmbedPersist *persist, - EmbedPersistFlags flags); -static gresult -impl_set_handler (EphyEmbedPersist *persist, - const char *command, - gboolean need_terminal); +static void ephy_embed_persist_class_init (EphyEmbedPersistClass *klass); +static void ephy_embed_persist_init (EphyEmbedPersist *ges); + +enum +{ + COMPLETED, + LAST_SIGNAL +}; -static GObjectClass *parent_class = NULL; static guint ephy_embed_persist_signals[LAST_SIGNAL] = { 0 }; +static GObjectClass *parent_class = NULL; + GType ephy_embed_persist_get_type (void) { static GType ephy_embed_persist_type = 0; - if (ephy_embed_persist_type == 0) - { - static const GTypeInfo our_info = - { - sizeof (EphyEmbedPersistClass), - NULL, /* base_init */ - NULL, /* base_finalize */ - (GClassInitFunc) ephy_embed_persist_class_init, - NULL, /* class_finalize */ - NULL, /* class_data */ - sizeof (EphyEmbedPersist), - 0, /* n_preallocs */ - (GInstanceInitFunc) ephy_embed_persist_init - }; - - ephy_embed_persist_type = g_type_register_static (G_TYPE_OBJECT, - "EphyEmbedPersist", - &our_info, 0); - } - - return ephy_embed_persist_type; + if (ephy_embed_persist_type == 0) + { + static const GTypeInfo our_info = + { + sizeof (EphyEmbedPersistClass), + NULL, /* base_init */ + NULL, /* base_finalize */ + (GClassInitFunc) ephy_embed_persist_class_init, + NULL, /* class_finalize */ + NULL, /* class_data */ + sizeof (EphyEmbedPersist), + 0, /* n_preallocs */ + (GInstanceInitFunc) ephy_embed_persist_init + }; + + ephy_embed_persist_type = g_type_register_static (G_TYPE_OBJECT, + "EphyEmbedPersist", + &our_info, 0); + } + + return ephy_embed_persist_type; } -static void -ephy_embed_persist_class_init (EphyEmbedPersistClass *klass) +void +ephy_embed_persist_set_dest (EphyEmbedPersist *persist, + const char *value) { - GObjectClass *object_class = G_OBJECT_CLASS (klass); - - parent_class = g_type_class_peek_parent (klass); + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); - object_class->finalize = ephy_embed_persist_finalize; - object_class->set_property = ephy_embed_persist_set_property; - object_class->get_property = ephy_embed_persist_get_property; - - klass->set_source = impl_set_source; - klass->set_dest = impl_set_dest; - klass->set_embed = impl_set_embed; - klass->set_max_size = impl_set_max_size; - klass->set_flags = impl_set_flags; - klass->set_handler = impl_set_handler; - - /* init signals */ - ephy_embed_persist_signals[COMPLETED] = - g_signal_new ("completed", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EphyEmbedPersistClass, completed), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, - 0); - - g_object_class_install_property (object_class, - PROP_EMBED, - g_param_spec_object ("embed", - "Embed", - "The embed containing the document", - G_TYPE_OBJECT, - G_PARAM_READWRITE)); - g_object_class_install_property (object_class, - PROP_SOURCE, - g_param_spec_string ("source", - "Source", - "Url of the document to save", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_DEST, - g_param_spec_string ("dest", - "Destination", - "Destination directory", - NULL, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_MAX_SIZE, - g_param_spec_int ("max_size", - "Maxsize", - "Maximum size of the file", - 0, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_FLAGS, - g_param_spec_int ("flags", - "Flags", - "Flags", - 0, - G_MAXINT, - 0, - G_PARAM_READWRITE)); - - g_object_class_install_property (object_class, - PROP_HANDLER, - g_param_spec_pointer ("handler", - "Handler", - "Handler", - G_PARAM_READWRITE)); - - g_type_class_add_private (object_class, sizeof(EphyEmbedPersistPrivate)); + persist->priv->dest = g_strdup (value); } -static void -ephy_embed_persist_set_property (GObject *object, - guint prop_id, - const GValue *value, - GParamSpec *pspec) +void +ephy_embed_persist_set_embed (EphyEmbedPersist *persist, + EphyEmbed *value) { - EphyEmbedPersist *persist; - PersistHandlerInfo *h; - - persist = EPHY_EMBED_PERSIST (object); + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); - switch (prop_id) - { - case PROP_EMBED: - ephy_embed_persist_set_embed (persist, - g_value_get_object (value)); - break; - case PROP_SOURCE: - ephy_embed_persist_set_source (persist, - g_value_get_string (value)); - break; - case PROP_DEST: - ephy_embed_persist_set_dest (persist, - g_value_get_string (value)); - break; - case PROP_MAX_SIZE: - ephy_embed_persist_set_max_size (persist, - g_value_get_int (value)); - break; - case PROP_FLAGS: - ephy_embed_persist_set_flags - (persist, - (EmbedPersistFlags)g_value_get_int (value)); - break; - case PROP_HANDLER: - h = (PersistHandlerInfo *)g_value_get_pointer (value); - ephy_embed_persist_set_handler - (persist, h->command, h->need_terminal); - break; - } + persist->priv->embed = value; } -static void -ephy_embed_persist_get_property (GObject *object, - guint prop_id, - GValue *value, - GParamSpec *pspec) +void +ephy_embed_persist_set_fc_title (EphyEmbedPersist *persist, + const char *value) { - EphyEmbedPersist *persist; - - persist = EPHY_EMBED_PERSIST (object); + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); - switch (prop_id) - { - case PROP_EMBED: - g_value_set_object (value, persist->priv->embed); - break; - case PROP_SOURCE: - g_value_set_string (value, persist->priv->src); - break; - case PROP_DEST: - g_value_set_string (value, persist->priv->dir); - break; - case PROP_MAX_SIZE: - g_value_set_int (value, persist->priv->max_size); - break; - case PROP_FLAGS: - g_value_set_int (value, (int)persist->priv->flags); - break; - case PROP_HANDLER: - g_value_set_pointer (value, persist->priv->handler); - } + persist->priv->fc_title = g_strdup (value); } -static void -ephy_embed_persist_init (EphyEmbedPersist *persist) +void +ephy_embed_persist_set_fc_parent (EphyEmbedPersist *persist, + GtkWindow *value) { - persist->priv = EPHY_EMBED_PERSIST_GET_PRIVATE (persist); - - persist->priv->src = NULL; - persist->priv->dir = NULL; - persist->priv->handler = NULL; + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); - LOG ("Embed persist init") + persist->priv->fc_parent = value; } -static void -ephy_embed_persist_finalize (GObject *object) +void +ephy_embed_persist_set_flags (EphyEmbedPersist *persist, + EmbedPersistFlags value) { - EphyEmbedPersist *persist = EPHY_EMBED_PERSIST (object); + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); - g_free (persist->priv->dir); - g_free (persist->priv->src); - - if (persist->priv->handler) - { - g_free (persist->priv->handler->command); - g_free (persist->priv->handler); - } + persist->priv->flags = value; +} - LOG ("Embed persist finalize") +void +ephy_embed_persist_set_max_size (EphyEmbedPersist *persist, + int value) +{ + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); - G_OBJECT_CLASS (parent_class)->finalize (object); + persist->priv->max_size = value; } - -EphyEmbedPersist * -ephy_embed_persist_new (EphyEmbed *embed) +void +ephy_embed_persist_set_persist_key (EphyEmbedPersist *persist, + const char *value) { - EphyEmbedPersist *persist; + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); - persist = EPHY_EMBED_PERSIST (g_object_new (MOZILLA_TYPE_EMBED_PERSIST, - "embed", embed, - NULL)); - - return persist; + persist->priv->persist_key = g_strdup (value); } -gresult +void ephy_embed_persist_set_source (EphyEmbedPersist *persist, - const char *url) + const char *value) { - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->set_source (persist, url); + g_return_if_fail (EPHY_IS_EMBED_PERSIST (persist)); + + persist->priv->source = g_strdup (value); } -gresult -ephy_embed_persist_get_source (EphyEmbedPersist *persist, - const char **url) +const char * +ephy_embed_persist_get_dest (EphyEmbedPersist *persist) { - *url = persist->priv->src; + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), NULL); - return G_OK; + return persist->priv->dest; } -gresult -ephy_embed_persist_get_dest (EphyEmbedPersist *persist, - const char **dir) +EphyEmbed * +ephy_embed_persist_get_embed (EphyEmbedPersist *persist) { - *dir = persist->priv->dir; + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), NULL); - return G_OK; + return persist->priv->embed; } -gresult -ephy_embed_persist_set_dest (EphyEmbedPersist *persist, - const char *dir) +const char * +ephy_embed_persist_get_fc_title (EphyEmbedPersist *persist) { - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->set_dest (persist, dir); -} + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), NULL); -gresult -ephy_embed_persist_cancel (EphyEmbedPersist *persist) -{ - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->cancel (persist); + return persist->priv->fc_title; } -gresult -ephy_embed_persist_save (EphyEmbedPersist *persist) +GtkWindow * +ephy_embed_persist_get_fc_parent (EphyEmbedPersist *persist) { - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->save (persist); + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), NULL); + + return persist->priv->fc_parent; } -gresult -ephy_embed_persist_set_max_size (EphyEmbedPersist *persist, - int kb_size) +EmbedPersistFlags +ephy_embed_persist_get_flags (EphyEmbedPersist *persist) { - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->set_max_size (persist, kb_size); + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), 0); + + return persist->priv->flags; } -gresult -ephy_embed_persist_set_embed (EphyEmbedPersist *persist, - EphyEmbed *embed) +int +ephy_embed_persist_get_max_size (EphyEmbedPersist *persist) { - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->set_embed (persist, embed); + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), 0); + + return persist->priv->max_size; } -gresult -ephy_embed_persist_get_embed (EphyEmbedPersist *persist, - EphyEmbed **embed) +const char * +ephy_embed_persist_get_persist_key (EphyEmbedPersist *persist) { - *embed = persist->priv->embed; + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), NULL); - return G_OK; + return persist->priv->persist_key; } -gresult -ephy_embed_persist_set_flags (EphyEmbedPersist *persist, - EmbedPersistFlags flags) +const char * +ephy_embed_persist_get_source (EphyEmbedPersist *persist) { - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->set_flags (persist, flags); + g_return_val_if_fail (EPHY_IS_EMBED_PERSIST (persist), NULL); + + return persist->priv->source; } -gresult -ephy_embed_persist_get_flags (EphyEmbedPersist *persist, - EmbedPersistFlags *flags) +static void +ephy_embed_persist_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) { - *flags = persist->priv->flags= persist->priv->flags; + EphyEmbedPersist *persist = EPHY_EMBED_PERSIST (object); - return G_OK; + switch (prop_id) + { + case PROP_DEST: + ephy_embed_persist_set_dest (persist, g_value_get_string (value)); + break; + case PROP_EMBED: + ephy_embed_persist_set_embed (persist, g_value_get_object (value)); + break; + case PROP_FILECHOOSER_TITLE: + ephy_embed_persist_set_fc_title (persist, g_value_get_string (value)); + break; + case PROP_FILECHOOSER_PARENT: + ephy_embed_persist_set_fc_parent (persist, g_value_get_object (value)); + break; + case PROP_FLAGS: + ephy_embed_persist_set_flags (persist, g_value_get_int (value)); + break; + case PROP_MAX_SIZE: + ephy_embed_persist_set_max_size (persist, g_value_get_int (value)); + break; + case PROP_PERSISTKEY: + ephy_embed_persist_set_persist_key (persist, g_value_get_string (value)); + break; + case PROP_SOURCE: + ephy_embed_persist_set_source (persist, g_value_get_string (value)); + break; + } } -gresult -ephy_embed_persist_set_handler (EphyEmbedPersist *persist, - const char *command, - gboolean need_terminal) +static void +ephy_embed_persist_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) { - EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); - return klass->set_handler (persist, command, need_terminal); + EphyEmbedPersist *persist = EPHY_EMBED_PERSIST (object); + + switch (prop_id) + { + case PROP_DEST: + g_value_set_string (value, ephy_embed_persist_get_dest (persist)); + break; + case PROP_EMBED: + g_value_set_object (value, ephy_embed_persist_get_embed (persist)); + break; + case PROP_FILECHOOSER_TITLE: + g_value_set_string (value, ephy_embed_persist_get_fc_title (persist)); + break; + case PROP_FILECHOOSER_PARENT: + g_value_set_object (value, ephy_embed_persist_get_fc_parent (persist)); + break; + case PROP_FLAGS: + g_value_set_int (value, ephy_embed_persist_get_flags (persist)); + break; + case PROP_MAX_SIZE: + g_value_set_int (value, ephy_embed_persist_get_max_size (persist)); + break; + case PROP_PERSISTKEY: + g_value_set_string (value, ephy_embed_persist_get_persist_key (persist)); + break; + case PROP_SOURCE: + g_value_set_string (value, ephy_embed_persist_get_source (persist)); + break; + } } -static gresult -impl_set_handler (EphyEmbedPersist *persist, - const char *command, - gboolean need_terminal) +static void +ephy_embed_persist_init (EphyEmbedPersist *persist) { - persist->priv->handler = g_new0 (PersistHandlerInfo, 1); - persist->priv->handler->command = g_strdup (command); - persist->priv->handler->need_terminal = need_terminal; + persist->priv = EPHY_EMBED_PERSIST_GET_PRIVATE (persist); - g_object_notify (G_OBJECT(persist), "handler"); + LOG ("EphyEmbedPersist initialising %p", persist) - return G_OK; + persist->priv->dest = NULL; + persist->priv->source = NULL; + persist->priv->fc_title = NULL; + persist->priv->fc_parent = NULL; + persist->priv->flags = 0; + persist->priv->max_size = 0; + persist->priv->persist_key = NULL; } -static gresult -impl_set_flags (EphyEmbedPersist *persist, - EmbedPersistFlags flags) +static void +ephy_embed_persist_finalize (GObject *object) { - persist->priv->flags = flags; + EphyEmbedPersist *persist = EPHY_EMBED_PERSIST (object); + + g_free (persist->priv->dest); + g_free (persist->priv->source); + g_free (persist->priv->fc_title); + g_free (persist->priv->persist_key); - g_object_notify (G_OBJECT(persist), "flags"); + LOG ("EphyEmbedPersist finalised %p", object) - return G_OK; + G_OBJECT_CLASS (parent_class)->finalize (object); } -static gresult -impl_set_source (EphyEmbedPersist *persist, - const char *url) +static void +ephy_embed_persist_class_init (EphyEmbedPersistClass *klass) { - persist->priv->src = g_strdup(url); + GObjectClass *object_class = G_OBJECT_CLASS (klass); - g_object_notify (G_OBJECT(persist), "source"); + parent_class = g_type_class_peek_parent (klass); - return G_OK; -} + object_class->finalize = ephy_embed_persist_finalize; + object_class->set_property = ephy_embed_persist_set_property; + object_class->get_property = ephy_embed_persist_get_property; -static gresult -impl_set_dest (EphyEmbedPersist *persist, - const char *dir) -{ - persist->priv->dir = g_strdup (dir); + /* init signals */ + ephy_embed_persist_signals[COMPLETED] = + g_signal_new ("completed", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyEmbedPersistClass, completed), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, + 0); - g_object_notify (G_OBJECT(persist), "dest"); + g_object_class_install_property (object_class, + PROP_DEST, + g_param_spec_string ("dest", + "Destination", + "Destination file path", + NULL, + G_PARAM_READWRITE)); - return G_OK; -} + g_object_class_install_property (object_class, + PROP_EMBED, + g_param_spec_object ("embed", + "Embed", + "The embed containing the document", + G_TYPE_OBJECT, + G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY)); -static gresult -impl_set_max_size (EphyEmbedPersist *persist, - int kb_size) -{ - persist->priv->max_size = kb_size; + g_object_class_install_property (object_class, + PROP_FILECHOOSER_TITLE, + g_param_spec_string ("filechooser-title", + "Filechooser title", + "Title to use if showing filechooser", + NULL, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_FILECHOOSER_PARENT, + g_param_spec_object ("filechooser-parent", + "Filechooser parent", + "The parent window for the filechooser", + GTK_TYPE_WINDOW, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_FLAGS, + g_param_spec_int ("flags", + "Flags", + "Flags", + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); + + g_object_class_install_property (object_class, + PROP_MAX_SIZE, + g_param_spec_int ("max_size", + "Maxsize", + "Maximum size of the file", + 0, + G_MAXINT, + 0, + G_PARAM_READWRITE)); - g_object_notify (G_OBJECT(persist), "max_size"); + g_object_class_install_property (object_class, + PROP_PERSISTKEY, + g_param_spec_string ("persist-key", + "persist key", + "Path persistence gconf key", + NULL, + G_PARAM_READWRITE)); - return G_OK; + g_object_class_install_property (object_class, + PROP_SOURCE, + g_param_spec_string ("source", + "Source", + "Url of the document to save", + NULL, + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof(EphyEmbedPersistPrivate)); } -static gresult -impl_set_embed (EphyEmbedPersist *persist, - EphyEmbed *embed) +gresult +ephy_embed_persist_cancel (EphyEmbedPersist *persist) { - persist->priv->embed = embed; + EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); + return klass->cancel (persist); +} - g_object_notify (G_OBJECT(persist), "embed"); +gresult +ephy_embed_persist_save (EphyEmbedPersist *persist) +{ + EphyEmbedPersistClass *klass = EPHY_EMBED_PERSIST_GET_CLASS (persist); + return klass->save (persist); +} - return G_OK; +EphyEmbedPersist * +ephy_embed_persist_new (EphyEmbed *embed) +{ + return EPHY_EMBED_PERSIST (g_object_new (MOZILLA_TYPE_EMBED_PERSIST, + "embed", embed, + NULL)); } diff --git a/embed/ephy-embed-persist.h b/embed/ephy-embed-persist.h index 1a48d2455..2f2db4f1b 100644 --- a/embed/ephy-embed-persist.h +++ b/embed/ephy-embed-persist.h @@ -1,5 +1,6 @@ /* - * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti + * Copyright (C) 2000-2003 Marco Pesenti Gritti + * Copyright (C) 2003 Christian Persch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,6 +15,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ */ #ifndef EPHY_EMBED_PERSIST_H @@ -24,6 +27,8 @@ #include <glib-object.h> #include <glib.h> +#include <gtk/gtkwindow.h> + G_BEGIN_DECLS #define EPHY_TYPE_EMBED_PERSIST (ephy_embed_persist_get_type ()) @@ -39,94 +44,78 @@ typedef struct EphyEmbedPersistPrivate EphyEmbedPersistPrivate; typedef enum { - EMBED_PERSIST_BYPASSCACHE = 1 << 0, - EMBED_PERSIST_MAINDOC = 1 << 1, - EMBED_PERSIST_NO_VIEW = 1 << 2, - EMBED_PERSIST_ASK_DESTINATION = 1 << 3 + EMBED_PERSIST_BYPASSCACHE = 1 << 0, + EMBED_PERSIST_MAINDOC = 1 << 1, + EMBED_PERSIST_NO_VIEW = 1 << 2, + EMBED_PERSIST_ASK_DESTINATION = 1 << 3 } EmbedPersistFlags; -typedef struct -{ - char *command; - gboolean need_terminal; -} PersistHandlerInfo; - struct EphyEmbedPersist { - GObject parent; - EphyEmbedPersistPrivate *priv; + GObject parent; + EphyEmbedPersistPrivate *priv; }; struct EphyEmbedPersistClass { - GObjectClass parent_class; + GObjectClass parent_class; - void (* completed) (EphyEmbedPersist *persist); + void (* completed) (EphyEmbedPersist *persist); /* Methods */ - gresult (* set_source) (EphyEmbedPersist *persist, - const char *url); + gresult (* save) (EphyEmbedPersist *persist); - gresult (* set_dest) (EphyEmbedPersist *persist, - const char *dir); + gresult (* cancel) (EphyEmbedPersist *persist); +}; - gresult (* save) (EphyEmbedPersist *persist); +GType ephy_embed_persist_get_type (void); - gresult (* cancel) (EphyEmbedPersist *persist); +EphyEmbedPersist *ephy_embed_persist_new (EphyEmbed *embed); - gresult (* set_max_size) (EphyEmbedPersist *persist, - int max_size); +gresult ephy_embed_persist_save (EphyEmbedPersist *persist); - gresult (* set_embed) (EphyEmbedPersist *persist, - EphyEmbed *embed); +gresult ephy_embed_persist_cancel (EphyEmbedPersist *persist); - gresult (* set_flags) (EphyEmbedPersist *persist, - EmbedPersistFlags flags); +void ephy_embed_persist_set_dest (EphyEmbedPersist *persist, + const char *value); - gresult (* set_handler) (EphyEmbedPersist *persist, - const char *command, - gboolean need_terminal); -}; +void ephy_embed_persist_set_embed (EphyEmbedPersist *persist, + EphyEmbed *value); -GType ephy_embed_persist_get_type (void); +void ephy_embed_persist_set_fc_title (EphyEmbedPersist *persist, + const char *value); -EphyEmbedPersist *ephy_embed_persist_new (EphyEmbed *embed); +void ephy_embed_persist_set_fc_parent (EphyEmbedPersist *persist, + GtkWindow *value); -gresult ephy_embed_persist_set_source (EphyEmbedPersist *persist, - const char *url); +void ephy_embed_persist_set_flags (EphyEmbedPersist *persist, + EmbedPersistFlags value); -gresult ephy_embed_persist_get_source (EphyEmbedPersist *persist, - const char **url); +void ephy_embed_persist_set_max_size (EphyEmbedPersist *persist, + int value); -gresult ephy_embed_persist_set_dest (EphyEmbedPersist *persist, - const char *dir); +void ephy_embed_persist_set_persist_key (EphyEmbedPersist *persist, + const char *value); -gresult ephy_embed_persist_get_dest (EphyEmbedPersist *persist, - const char **dir); +void ephy_embed_persist_set_source (EphyEmbedPersist *persist, + const char *value); -gresult ephy_embed_persist_set_handler (EphyEmbedPersist *persist, - const char *handler, - gboolean need_terminal); +const char *ephy_embed_persist_get_dest (EphyEmbedPersist *persist); -gresult ephy_embed_persist_set_max_size (EphyEmbedPersist *persist, - int kb_size); +EphyEmbed *ephy_embed_persist_get_embed (EphyEmbedPersist *persist); -gresult ephy_embed_persist_set_embed (EphyEmbedPersist *persist, - EphyEmbed *embed); +const char *ephy_embed_persist_get_fc_title (EphyEmbedPersist *persist); -gresult ephy_embed_persist_get_embed (EphyEmbedPersist *persist, - EphyEmbed **embed); +GtkWindow *ephy_embed_persist_get_fc_parent (EphyEmbedPersist *persist); -gresult ephy_embed_persist_set_flags (EphyEmbedPersist *persist, - EmbedPersistFlags flags); +EmbedPersistFlags ephy_embed_persist_get_flags (EphyEmbedPersist *persist); -gresult ephy_embed_persist_get_flags (EphyEmbedPersist *persist, - EmbedPersistFlags *flags); +int ephy_embed_persist_get_max_size (EphyEmbedPersist *persist); -gresult ephy_embed_persist_save (EphyEmbedPersist *persist); +const char *ephy_embed_persist_get_persist_key (EphyEmbedPersist *persist); -gresult ephy_embed_persist_cancel (EphyEmbedPersist *persist); +const char *ephy_embed_persist_get_source (EphyEmbedPersist *persist); G_END_DECLS diff --git a/embed/ephy-embed-popup-control.c b/embed/ephy-embed-popup-control.c index a300e0535..5cda121e1 100644 --- a/embed/ephy-embed-popup-control.c +++ b/embed/ephy-embed-popup-control.c @@ -1,5 +1,6 @@ /* - * Copyright (C) 2000, 2001, 2002 Ricardo Fernández Pascual + * Copyright (C) 2000, 2001, 2002 Ricardo Fernández Pascual + * Copyright (C) 2003 Marco Pesenti Gritti * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -19,8 +20,8 @@ */ #include "ephy-embed-popup-control.h" +#include "ephy-embed-persist.h" #include "ephy-bonobo-extensions.h" -#include "ephy-embed-utils.h" #include "ephy-prefs.h" #include "eel-gconf-extensions.h" #include "ephy-file-helpers.h" @@ -477,6 +478,31 @@ embed_popup_copy_link_location_cmd (BonoboUIComponent *uic, } static void +save_url (EphyEmbedPopupControl *popup, + const char *title, + gboolean ask_dest, + const char *location) +{ + GtkWidget *widget, *window; + EphyEmbedPersist *persist; + + widget = GTK_WIDGET (popup->priv->embed); + window = gtk_widget_get_toplevel (widget); + + persist = ephy_embed_persist_new (popup->priv->embed); + + ephy_embed_persist_set_fc_title (persist, title); + ephy_embed_persist_set_fc_parent (persist,GTK_WINDOW (window)); + ephy_embed_persist_set_flags + (persist, ask_dest ? EMBED_PERSIST_ASK_DESTINATION : 0); + ephy_embed_persist_set_persist_key + (persist, CONF_STATE_DOWNLOADING_DIR); + ephy_embed_persist_set_source (persist, location); + + ephy_embed_persist_save (persist); +} + +static void save_property_url (EphyEmbedPopupControl *popup, const char *title, gboolean ask_dest, @@ -485,24 +511,12 @@ save_property_url (EphyEmbedPopupControl *popup, EphyEmbedEvent *info; const char *location; const GValue *value; - GtkWidget *widget; - GtkWidget *window; - EphyEmbedPersist *persist; info = ephy_embed_popup_control_get_event (popup); ephy_embed_event_get_property (info, property, &value); location = g_value_get_string (value); - widget = GTK_WIDGET (popup->priv->embed); - window = gtk_widget_get_toplevel (widget); - - persist = ephy_embed_persist_new (popup->priv->embed); - - ephy_embed_persist_set_source (persist, location); - - ephy_embed_utils_save (window, title, - CONF_STATE_DOWNLOADING_DIR, - ask_dest, persist); + save_url (popup, title, ask_dest, location); } /* commands */ @@ -553,16 +567,14 @@ background_download_completed (EphyEmbedPersist *persist, const char *bg; char *type; - ephy_embed_persist_get_dest (persist, &bg); + bg = ephy_embed_persist_get_dest (persist); eel_gconf_set_string (CONF_DESKTOP_BG_PICTURE, bg); type = eel_gconf_get_string (CONF_DESKTOP_BG_TYPE); - if (type || strcmp (type, "none") == 0) + if (type == NULL || strcmp (type, "none") == 0) { - eel_gconf_set_string (CONF_DESKTOP_BG_TYPE, - "wallpaper"); + eel_gconf_set_string (CONF_DESKTOP_BG_TYPE, "wallpaper"); } - g_free (type); g_object_unref (persist); @@ -586,11 +598,11 @@ embed_popup_set_image_as_background_cmd (BonoboUIComponent *uic, persist = ephy_embed_persist_new (popup->priv->embed); base = g_path_get_basename (location); - dest = g_build_filename (ephy_dot_dir (), - base, NULL); + dest = g_build_filename (ephy_dot_dir (), base, NULL); - ephy_embed_persist_set_source (persist, location); ephy_embed_persist_set_dest (persist, dest); + ephy_embed_persist_set_flags (persist, EMBED_PERSIST_NO_VIEW); + ephy_embed_persist_set_source (persist, location); ephy_embed_persist_save (persist); @@ -618,27 +630,6 @@ embed_popup_copy_image_location_cmd (BonoboUIComponent *uic, } static void -save_url (EphyEmbedPopupControl *popup, - const char *title, - gboolean ask_dest, - const char *url) -{ - GtkWidget *widget; - GtkWidget *window; - EphyEmbedPersist *persist; - - widget = GTK_WIDGET (popup->priv->embed); - window = gtk_widget_get_toplevel (widget); - - persist = ephy_embed_persist_new (popup->priv->embed); - ephy_embed_persist_set_source (persist, url); - - ephy_embed_utils_save (window, title, - CONF_STATE_DOWNLOADING_DIR, - ask_dest, persist); -} - -static void embed_popup_save_page_as_cmd (BonoboUIComponent *uic, EphyEmbedPopupControl *popup, const char* verbname) diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c index d09377552..7c82b6000 100644 --- a/embed/ephy-embed-single.c +++ b/embed/ephy-embed-single.c @@ -1,5 +1,5 @@ /* - * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti + * Copyright (C) 2000, 2001, 2002, 2003 Marco Pesenti Gritti * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -182,42 +182,6 @@ ephy_embed_single_remove_passwords (EphyEmbedSingle *shell, return klass->remove_passwords (shell, passwords, type); } -/** - * show_file_picker: Shows a file picker. Can be configured to select a - * file or a directory. - * @parentWidget: Parent Widget for file picker. - * @title: Title for file picker. - * @directory: Initial directory to start in. - * @file: Initial filename to show in filepicker. - * @mode: Mode to run filepicker in (modeOpen, modeSave, modeGetFolder) - * @ret_fullpath: On a successful return, will hold the full path to selected - * file or directory. - * @file_formats: an array of FileFormat structures to fill the format chooser - * optionmenu. NULL if not needed. The last item must have - * description == NULL. - * @ret_file_format: where to store the index of the format selected (can be - * NULL) - * returns: TRUE for success, FALSE for failure. - */ - -gresult -ephy_embed_single_show_file_picker (EphyEmbedSingle *shell, - GtkWidget *parentWidget, - const char *title, - const char *directory, - const char *file, - FilePickerMode mode, - char **ret_fullpath, - FileFormat *file_formats, - int *ret_file_format) -{ - EphyEmbedSingleClass *klass = EPHY_EMBED_SINGLE_GET_CLASS (shell); - return klass->show_file_picker (shell, parentWidget, title, - directory, file, mode, - ret_fullpath, - file_formats, ret_file_format); -} - gresult ephy_embed_single_free_cookies (EphyEmbedSingle *shell, GList *cookies) diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h index 9a6e5e873..e45b99cad 100644 --- a/embed/ephy-embed-single.h +++ b/embed/ephy-embed-single.h @@ -14,6 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ */ #ifndef EPHY_EMBED_SINGLE_H @@ -132,15 +134,6 @@ struct EphyEmbedSingleClass gresult (* remove_passwords) (EphyEmbedSingle *shell, GList *passwords, PasswordType type); - gresult (* show_file_picker) (EphyEmbedSingle *shell, - GtkWidget *parentWidget, - const char* title, - const char* directory, - const char* file, - FilePickerMode mode, - char **ret_fullpath, - FileFormat *file_formats, - gint *ret_file_format); }; GType ephy_embed_single_get_type (void); @@ -179,16 +172,6 @@ gresult ephy_embed_single_remove_passwords (EphyEmbedSingle *shell, GList *passwords, PasswordType type); -gresult ephy_embed_single_show_file_picker (EphyEmbedSingle *shell, - GtkWidget *parentWidget, - const char *title, - const char *directory, - const char *file, - FilePickerMode mode, - char **ret_fullpath, - FileFormat *file_formats, - int *ret_file_format); - G_END_DECLS #endif diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c deleted file mode 100644 index 0bcd6bb52..000000000 --- a/embed/ephy-embed-utils.c +++ /dev/null @@ -1,214 +0,0 @@ -/* - * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "eel-gconf-extensions.h" -#include "ephy-embed-utils.h" -#include "ephy-embed-shell.h" -#include "ephy-bonobo-extensions.h" -#include "ephy-gui.h" -#include "ephy-debug.h" -#include "ephy-langs.h" - -#include <gtk/gtkdialog.h> -#include <gtk/gtkmessagedialog.h> -#include <bonobo/bonobo-i18n.h> -#include <bonobo/bonobo-ui-util.h> -#include <libgnomevfs/gnome-vfs-uri.h> -#include <string.h> - -/** - * ephy_embed_utils_save: - * @window: the referrer window. Used to parent the dialogs. - * @title: title of the file picker - * @default_dir_pref: the gconf path to persist the directory selected by the user. - * @ask_dest: ask the user the destination path - * @ask_content: show the user an option to save the content - * of the web page (images, javascript...) - * @persist: the #EphyEmbedPersist referring to the url - * - * Download a save an url asking a location to the user when requested - **/ -void -ephy_embed_utils_save (GtkWidget *window, - const char *title, - const char *default_dir_pref, - gboolean ask_dest, - EphyEmbedPersist *persist) -{ - GnomeVFSURI *uri; - char *retPath = NULL; - char *fileName = NULL; - char *dirName = NULL; - char *target; - const char *source; - gresult ret; - EphyEmbed *embed; - EmbedPersistFlags flags; - EphyEmbedSingle *single; - - single = ephy_embed_shell_get_embed_single - (EPHY_EMBED_SHELL (embed_shell)); - - g_object_ref (G_OBJECT(persist)); - - ephy_embed_persist_get_flags (persist, &flags); - - ephy_embed_persist_get_source (persist, &source); - - if (source) - { - target = g_strdup (source); - } - else - { - ephy_embed_persist_get_embed (persist, &embed); - g_return_if_fail (embed != NULL); - - ephy_embed_get_location (embed, - flags & - EMBED_PERSIST_MAINDOC, - &target); - } - - /* Get a filename from the target url */ - uri = gnome_vfs_uri_new (target); - if (uri) - { - fileName = gnome_vfs_uri_extract_short_name (uri); - gnome_vfs_uri_unref (uri); - } - - dirName = eel_gconf_get_string (default_dir_pref); - if (dirName && dirName[0] == '\0') - { - g_free (dirName); - dirName = NULL; - } - - if (!dirName || strcmp (dirName,"~") == 0) - { - g_free (dirName); - dirName = g_strdup(g_get_home_dir ()); - } - - /* If we aren't asking for downloading dir, check that we aren't - * overwriting anything. If we are, pop up a warning dialog and show - * the filepicker if the user doesn't want to overwrite the file. - */ - ret = G_FAILED; - if (!ask_dest) - { - retPath = g_build_filename (dirName, fileName, NULL); - if (ephy_gui_confirm_overwrite_file (window, retPath)) - { - ret = G_OK; - } - else - { - g_free (retPath); - retPath = NULL; - ask_dest = TRUE; - } - } - - if (ask_dest) - { - char *ret_dir; - - /* show the file picker */ - ret = ephy_embed_single_show_file_picker - (single, window, title, - dirName, fileName, modeSave, &retPath, - NULL, NULL); - - if (g_file_test (retPath, G_FILE_TEST_IS_DIR)) - { - ret_dir = g_strdup (retPath); - } - else - { - ret_dir = g_path_get_dirname (retPath); - } - - /* set default save dir */ - eel_gconf_set_string (default_dir_pref, ret_dir); - g_free (ret_dir); - } - - if (ret == G_OK) - { - ephy_embed_persist_set_flags (persist, flags); - - ephy_embed_persist_set_dest (persist, retPath); - - if (ephy_embed_persist_save (persist) == G_FAILED) - { - GtkWidget *dialog; - - dialog = gtk_message_dialog_new - (GTK_WINDOW (window), - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_CLOSE, - _("The file has not been saved.")); - gtk_dialog_run (GTK_DIALOG (dialog)); - gtk_widget_destroy (dialog); - } - - } - - g_free (retPath); - - g_object_unref (G_OBJECT(persist)); - - g_free (dirName); - g_free (fileName); - g_free (target); -} - -/** - * ephy_embed_utils_handlernotfound_dialog_run: - * @parent: the dialog parent window - * - * Show a dialog to warn the user that no application capable - * to open the specified file are found. Used in the downloader - * and in the mime type dialog. - **/ -void -ephy_embed_utils_nohandler_dialog_run (GtkWidget *parent) -{ - GtkWidget *dialog; - - /* FIXME mime db shortcut */ - - dialog = gtk_message_dialog_new - (GTK_WINDOW(parent), - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("No available applications to open " - "the specified file.")); - gtk_dialog_run (GTK_DIALOG(dialog)); - gtk_widget_destroy (dialog); -} diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h deleted file mode 100644 index 312e51026..000000000 --- a/embed/ephy-embed-utils.h +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2000, 2001, 2002 Marco Pesenti Gritti - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef EPHY_EMBED_UTILS_H -#define EPHY_EMBED_UTILS_H - -#include "ephy-embed-persist.h" - -#include <gtk/gtkwidget.h> -#include <bonobo/bonobo-ui-component.h> - -G_BEGIN_DECLS - -void ephy_embed_utils_save (GtkWidget *window, - const char *title, - const char *default_dir_pref, - gboolean ask_dest, - EphyEmbedPersist *persist); - -void ephy_embed_utils_nohandler_dialog_run (GtkWidget *parent); - -G_END_DECLS - -#endif diff --git a/embed/ephy-favicon-cache.c b/embed/ephy-favicon-cache.c index da598a9e2..f0c3a0022 100644 --- a/embed/ephy-favicon-cache.c +++ b/embed/ephy-favicon-cache.c @@ -1,5 +1,6 @@ /* * Copyright (C) 2002 Jorn Baayen <jorn@nl.linux.org> + * Copyright (C) 2003 Marco Pesenti Gritti * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -84,8 +85,8 @@ ephy_favicon_cache_get_type (void) }; ephy_favicon_cache_type = g_type_register_static (G_TYPE_OBJECT, - "EphyFaviconCache", - &our_info, 0); + "EphyFaviconCache", + &our_info, 0); } return ephy_favicon_cache_type; @@ -117,11 +118,7 @@ ephy_favicon_cache_class_init (EphyFaviconCacheClass *klass) EphyFaviconCache * ephy_favicon_cache_new (void) { - EphyFaviconCache *cache; - - cache = EPHY_FAVICON_CACHE (g_object_new (EPHY_TYPE_FAVICON_CACHE, NULL)); - - return cache; + return EPHY_FAVICON_CACHE (g_object_new (EPHY_TYPE_FAVICON_CACHE, NULL)); } static gboolean @@ -133,8 +130,8 @@ icon_is_obsolete (EphyNode *node, GDate *now) last_visit = ephy_node_get_property_int (node, EPHY_NODE_FAVICON_PROP_LAST_USED); - g_date_clear (&date, 1); - g_date_set_time (&date, last_visit); + g_date_clear (&date, 1); + g_date_set_time (&date, last_visit); return (g_date_days_between (&date, now) >= EPHY_FAVICON_CACHE_OBSOLETE_DAYS); @@ -142,8 +139,8 @@ icon_is_obsolete (EphyNode *node, GDate *now) static void icons_added_cb (EphyNode *node, - EphyNode *child, - EphyFaviconCache *eb) + EphyNode *child, + EphyFaviconCache *eb) { g_static_rw_lock_writer_lock (eb->priv->icons_hash_lock); @@ -176,8 +173,8 @@ remove_obsolete_icons (EphyFaviconCache *eb) GDate current_date; now = time (NULL); - g_date_clear (¤t_date, 1); - g_date_set_time (¤t_date, time (NULL)); + g_date_clear (¤t_date, 1); + g_date_set_time (¤t_date, time (NULL)); children = ephy_node_get_children (eb->priv->icons); ephy_node_thaw (eb->priv->icons); @@ -245,8 +242,8 @@ ephy_favicon_cache_init (EphyFaviconCache *cache) cache->priv->db = db; cache->priv->xml_file = g_build_filename (ephy_dot_dir (), - "ephy-favicon-cache.xml", - NULL); + "ephy-favicon-cache.xml", + NULL); cache->priv->directory = g_build_filename (ephy_dot_dir (), "favicon_cache/", @@ -261,11 +258,11 @@ ephy_favicon_cache_init (EphyFaviconCache *cache) } cache->priv->icons_hash = g_hash_table_new (g_str_hash, - g_str_equal); + g_str_equal); cache->priv->icons_hash_lock = g_new0 (GStaticRWLock, 1); g_static_rw_lock_init (cache->priv->icons_hash_lock); cache->priv->downloads_hash = g_hash_table_new_full (g_str_hash, - g_str_equal, + g_str_equal, g_free, NULL); @@ -273,13 +270,13 @@ ephy_favicon_cache_init (EphyFaviconCache *cache) cache->priv->icons = ephy_node_new_with_id (db, ICONS_NODE_ID); ephy_node_ref (cache->priv->icons); ephy_node_signal_connect_object (cache->priv->icons, - EPHY_NODE_CHILD_ADDED, - (EphyNodeCallback) icons_added_cb, - G_OBJECT (cache)); + EPHY_NODE_CHILD_ADDED, + (EphyNodeCallback) icons_added_cb, + G_OBJECT (cache)); ephy_node_signal_connect_object (cache->priv->icons, - EPHY_NODE_CHILD_REMOVED, - (EphyNodeCallback) icons_removed_cb, - G_OBJECT (cache)); + EPHY_NODE_CHILD_REMOVED, + (EphyNodeCallback) icons_removed_cb, + G_OBJECT (cache)); ephy_node_db_load_from_file (cache->priv->db, cache->priv->xml_file, EPHY_FAVICON_CACHE_XML_ROOT, @@ -356,17 +353,16 @@ static void favicon_download_completed_cb (EphyEmbedPersist *persist, EphyFaviconCache *cache) { - char *url; + const char *url; - url = g_strdup ((char *) g_object_get_data (G_OBJECT (persist), "url")); + url = ephy_embed_persist_get_source (persist); g_return_if_fail (url != NULL); g_hash_table_remove (cache->priv->downloads_hash, url); - g_object_unref (persist); g_signal_emit (G_OBJECT (cache), ephy_favicon_cache_signals[CHANGED], 0, url); - g_free (url); + g_object_unref (persist); } static void @@ -387,17 +383,14 @@ 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_max_size (persist, 100); - ephy_embed_persist_set_flags (persist, EMBED_PERSIST_BYPASSCACHE | - EMBED_PERSIST_NO_VIEW); - ephy_embed_persist_set_source (persist, favicon_url); - ephy_embed_persist_set_dest (persist, dest); + ephy_embed_persist_set_source (persist, favicon_url); g_free (dest); - g_object_set_data_full (G_OBJECT (persist), "url", - g_strdup (favicon_url), g_free); - g_signal_connect (G_OBJECT (persist), "completed", G_CALLBACK (favicon_download_completed_cb), @@ -437,13 +430,13 @@ ephy_favicon_cache_get (EphyFaviconCache *cache, g_value_init (&value, G_TYPE_STRING); g_value_set_string (&value, url); ephy_node_set_property (icon, EPHY_NODE_FAVICON_PROP_URL, - &value); + &value); g_value_unset (&value); g_value_init (&value, G_TYPE_STRING); g_value_set_string (&value, filename); ephy_node_set_property (icon, EPHY_NODE_FAVICON_PROP_FILENAME, - &value); + &value); g_value_unset (&value); ephy_node_add_child (cache->priv->icons, icon); @@ -456,7 +449,7 @@ ephy_favicon_cache_get (EphyFaviconCache *cache, g_value_init (&value, G_TYPE_INT); g_value_set_int (&value, now); ephy_node_set_property (icon, EPHY_NODE_FAVICON_PROP_LAST_USED, - &value); + &value); g_value_unset (&value); if (g_hash_table_lookup (cache->priv->downloads_hash, url) != NULL) diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 519bff738..7da5ae25c 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -14,6 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ */ /* @@ -144,41 +146,17 @@ */ #ifdef HAVE_CONFIG_H -#include <config.h> +#include "config.h" #endif -extern "C" { -#include "libgnomevfs/gnome-vfs-mime-handlers.h" -} - -#include "ephy-embed-shell.h" -#include "ephy-prefs.h" -#include "eel-gconf-extensions.h" -#include "ephy-glade.h" -#include "ephy-string.h" -#include "ephy-gui.h" -#include "ephy-embed-utils.h" -#include "ephy-file-helpers.h" #include "ContentHandler.h" -#include <gtk/gtkentry.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtkprogress.h> -#include <gtk/gtkoptionmenu.h> -#include <libgnome/gnome-exec.h> -#include <libgnome/gnome-i18n.h> -#include <libgnome/gnome-config.h> -#include <libgnome/gnome-util.h> -#include <libgnomevfs/gnome-vfs-mime.h> - #include "FilePicker.h" #include "MozillaPrivate.h" -#include "nsCRT.h" #include "nsCOMPtr.h" #include "nsISupportsArray.h" #include "nsIServiceManager.h" -#include "nsWeakReference.h" #include "nsString.h" #include "nsIURI.h" @@ -190,8 +168,28 @@ extern "C" { #include "nsIDOMWindowInternal.h" #include "nsIMIMEInfo.h" +#include "ephy-embed-shell.h" +#include "ephy-prefs.h" +#include "eel-gconf-extensions.h" +#include "ephy-glade.h" +#include "ephy-string.h" +#include "ephy-gui.h" +#include "ephy-file-helpers.h" + +#include <gtk/gtkentry.h> +#include <gtk/gtktogglebutton.h> +#include <gtk/gtkprogress.h> +#include <gtk/gtkoptionmenu.h> +#include <gtk/gtkdialog.h> +#include <gtk/gtkmessagedialog.h> +#include <libgnome/gnome-exec.h> +#include <libgnome/gnome-i18n.h> +#include <libgnome/gnome-config.h> +#include <libgnome/gnome-util.h> +#include <libgnomevfs/gnome-vfs-mime.h> +#include <bonobo/bonobo-i18n.h> + class GContentHandler; -//class GDownloadProgressListener; struct MimeAskActionDialog; struct HelperAppChooserDialog; @@ -562,7 +560,7 @@ MimeAskActionDialog::MimeAskActionDialog(GContentHandler *aContentHandler, GtkWidget *label; GtkWidget *dialogWidget; const char *description; - char ltext[255]; //philipl: Fixed length buffer == potential security problem... + char *ltext; mGXml = ephy_glade_widget_new ("epiphany.glade", "mime_ask_action_dialog", &dialogWidget, this); @@ -579,9 +577,10 @@ MimeAskActionDialog::MimeAskActionDialog(GContentHandler *aContentHandler, description = gnome_vfs_mime_get_description (aMimeType); if (!description) description = aMimeType; - g_snprintf (ltext, 255, "<b>%s</b>", description); + ltext = g_strdup_printf ("<b>%s</b>", description); label = glade_xml_get_widget (mGXml, "mime_ask_action_description"); gtk_label_set_markup (GTK_LABEL (label), ltext); + g_free (ltext); gtk_window_set_transient_for (GTK_WINDOW (dialogWidget), GTK_WINDOW (aParentWidget)); @@ -646,9 +645,24 @@ mime_ask_dialog_open (MimeAskActionDialog *dialog) delete dialog; } else - { + { + GtkWidget *message_dialog; + mime_ask_dialog_cancel (dialog); - ephy_embed_utils_nohandler_dialog_run (dialog->mParent); + + /* FIXME mime db shortcut */ + + message_dialog = gtk_message_dialog_new + (GTK_WINDOW (dialog->mParent), + GTK_DIALOG_MODAL, + GTK_MESSAGE_ERROR, + GTK_BUTTONS_OK, + _("No available applications to open " + "the specified file.")); + gtk_dialog_run (GTK_DIALOG (message_dialog)); + gtk_widget_destroy (message_dialog); + + /* FIXME where is dialog deleted ? */ } } diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h index d08cf6cbd..3c8a6225f 100644 --- a/embed/mozilla/ContentHandler.h +++ b/embed/mozilla/ContentHandler.h @@ -14,6 +14,8 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ */ #ifndef __ContentHandler_h @@ -31,6 +33,9 @@ #include "nsIURI.h" #include "nsILocalFile.h" +#include "nsCRT.h" +#include "nsWeakReference.h" + #include "nsCOMPtr.h" #include "nsISupports.h" #include "nsError.h" diff --git a/embed/mozilla/EphyHeaderSniffer.cpp b/embed/mozilla/EphyHeaderSniffer.cpp index 483f0fd01..76b71a53f 100644 --- a/embed/mozilla/EphyHeaderSniffer.cpp +++ b/embed/mozilla/EphyHeaderSniffer.cpp @@ -34,7 +34,10 @@ * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * - * ***** END LICENSE BLOCK ***** */ + * ***** END LICENSE BLOCK ***** + * + * $Id$ + */ #ifdef HAVE_CONFIG_H #include "config.h" @@ -46,6 +49,9 @@ #include "EphyHeaderSniffer.h" #include "netCore.h" +#include "ephy-file-chooser.h" +#include "ephy-prefs.h" + #include "nsReadableUtils.h" #include "nsIChannel.h" #include "nsIHttpChannel.h" @@ -164,7 +170,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) EmbedPersistFlags flags; PRBool askDownloadDest; - ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist), &flags); + flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist)); askDownloadDest = flags & EMBED_PERSIST_ASK_DESTINATION; nsAutoString defaultFileName; @@ -176,7 +182,7 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) if (index >= 0) { /* Take the substring following the prefix. */ - index += 9; + index += strlen ("filename="); nsCAutoString filename; mContentDisposition.Right(filename, mContentDisposition.Length() - index); defaultFileName = NS_ConvertUTF8toUCS2(filename); @@ -232,16 +238,24 @@ nsresult EphyHeaderSniffer::PerformSave (nsIURI* inOriginalURI) if (askDownloadDest) { - /* FIXME show the file selector here */ + /* FIXME */ } else { /* FIXME build path from download dir */ } - + + if (defaultFileName.IsEmpty()) + { + defaultFileName.AssignWithConversion(_("Untitled")); + } + + /* FIXME ask user if overwriting ? */ + + /* FIXME: how to inform user of failed save ? */ nsCOMPtr<nsILocalFile> destFile; rv = NS_NewLocalFile(defaultFileName, PR_TRUE, getter_AddRefs(destFile)); - if (NS_FAILED(rv) || !destFile) return G_FAILED; + if (NS_FAILED(rv) || !destFile) return NS_ERROR_FAILURE; return InitiateMozillaDownload (mDocument, mURL, destFile, mContentType.get(), inOriginalURI, mEmbedPersist, diff --git a/embed/mozilla/FilePicker.cpp b/embed/mozilla/FilePicker.cpp index 42c17be06..74b3e7bec 100644 --- a/embed/mozilla/FilePicker.cpp +++ b/embed/mozilla/FilePicker.cpp @@ -1,5 +1,6 @@ /* * Copyright (C) 2001 Philip Langdale + * Copyright (C) 2003 Christian Persch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,45 +15,15 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - */ - -/* Things to be aware of: - * - * This filepicker, like the mozilla one, does not make an attempt - * to verify the validity of the initial directory you pass it. - * It does check that the user doesn't give it a garbage path - * during use, but it is the caller's responsibility to give a - * sensible initial path. * - * At the current moment, we instantiate the filepicker directly - * in our contenthandler where there is path verification code - * and else where through our C wrapper, which also does verification. - * If, at a future date, you need to instantiate filepicker without - * using the C wrapper, please verify the initial path. See - * ContentHandler for a way to do this. + * $Id$ */ #ifdef HAVE_CONFIG_H -#include <config.h> +#include "config.h" #endif -#include "ephy-string.h" -#include "ephy-gui.h" - -#include <glib/gconvert.h> -#include <gtk/gtkmain.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkmenu.h> -#include <gtk/gtkmenuitem.h> -#include <gtk/gtkcheckbutton.h> -#include <gtk/gtktogglebutton.h> -#include <gtk/gtkfilesel.h> -#include <gtk/gtkhbbox.h> -#include <gtk/gtkoptionmenu.h> -#include <gtk/gtkmessagedialog.h> -#include <libgnome/gnome-i18n.h> - -#include "nsIFilePicker.h" +#include "FilePicker.h" #include "nsCRT.h" #include "nsCOMPtr.h" @@ -70,364 +41,308 @@ #include "nsILocalFile.h" #include "nsIPromptService.h" #include "nsReadableUtils.h" +#include "nsIDOMWindow.h" +#include "nsIDOMWindowInternal.h" +#include "nsCOMPtr.h" +#include "nsString.h" +#include "nsILocalFile.h" +#include "MozillaPrivate.h" -#include <libgnome/gnome-util.h> +#include "ephy-string.h" +#include "ephy-prefs.h" +#include "ephy-gui.h" +#include "ephy-debug.h" -#include "FilePicker.h" -#include "MozillaPrivate.h" +#include <glib/gconvert.h> +#include <gtk/gtkfilefilter.h> +#include <gtk/gtkstock.h> +#include <gtk/gtkmessagedialog.h> +#include <bonobo/bonobo-i18n.h> +#include <libgnome/gnome-util.h> -/* Implementation file */ NS_IMPL_ISUPPORTS1(GFilePicker, nsIFilePicker) GFilePicker::GFilePicker() { NS_INIT_ISUPPORTS(); - /* member initializers and constructor code */ - mFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - mDisplayDirectory = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - mDisplayDirectory->InitWithNativePath(nsDependentCString(g_get_home_dir())); + LOG ("GFilePicker constructor") + + mDialog = EPHY_FILE_CHOOSER (g_object_new (EPHY_TYPE_FILE_CHOOSER, + "persist-key", CONF_STATE_UPLOAD_DIR, + NULL)); + + mMode = nsIFilePicker::modeOpen; } GFilePicker::~GFilePicker() { - /* destructor code */ -} + LOG ("GFilePicker destructor") -//////////////////////////////////////////////////////////////////////////////// -// begin nsIFilePicker impl -//////////////////////////////////////////////////////////////////////////////// + if (mDialog) + { + gtk_widget_destroy (GTK_WIDGET (mDialog)); + } +} /* void init (in nsIDOMWindowInternal parent, in wstring title, in short mode); */ -NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *aParent, - const PRUnichar *aTitle, PRInt16 aMode) +NS_IMETHODIMP GFilePicker::Init(nsIDOMWindowInternal *parent, const PRUnichar *title, PRInt16 mode) { - mParent = do_QueryInterface(aParent); - mParentWidget = MozillaFindGtkParent(mParent); - mTitle = NS_ConvertUCS2toUTF8(aTitle); - mMode = aMode; + nsCOMPtr<nsIDOMWindow> dw = do_QueryInterface (parent); + if (!dw) return NS_ERROR_FAILURE; + + GtkWidget *pwin = MozillaFindGtkParent (dw); + + gtk_window_set_transient_for (GTK_WINDOW (mDialog), GTK_WINDOW (pwin)); + + gtk_window_set_title (GTK_WINDOW (mDialog), NS_ConvertUCS2toUTF8 (title).get()); + + mMode = mode; + + switch (mode) + { + case nsIFilePicker::modeOpen: + case nsIFilePicker::modeGetFolder: + case nsIFilePicker::modeOpenMultiple: + gtk_file_chooser_set_action (GTK_FILE_CHOOSER (mDialog), + GTK_FILE_CHOOSER_ACTION_OPEN); + + gtk_dialog_add_buttons (GTK_DIALOG (mDialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, EPHY_RESPONSE_OPEN, + NULL); + break; + case nsIFilePicker::modeSave: + gtk_file_chooser_set_action (GTK_FILE_CHOOSER (mDialog), + GTK_FILE_CHOOSER_ACTION_SAVE); + gtk_dialog_add_buttons (GTK_DIALOG (mDialog), + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, EPHY_RESPONSE_SAVE, + NULL); + break; + } + + gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (mDialog), + mode == nsIFilePicker::modeOpenMultiple); + + gtk_file_chooser_set_folder_mode (GTK_FILE_CHOOSER (mDialog), + mode == nsIFilePicker::modeGetFolder); + return NS_OK; } /* void appendFilters (in long filterMask); */ -NS_IMETHODIMP GFilePicker::AppendFilters(PRInt32 aFilterMask) +NS_IMETHODIMP GFilePicker::AppendFilters(PRInt32 filterMask) { - //This function cannot be implemented due to the crippled - //nature of GtkFileSelection, but NS_ERROR_NOT_IMPLEMENTED - //is interpreted as a terminal error by some callers. + // http://lxr.mozilla.org/seamonkey/source/xpfe/components/filepicker/res/locale/en-US/filepicker.properties + // http://lxr.mozilla.org/seamonkey/source/xpfe/components/filepicker/src/nsFilePicker.js line 131 ff + + // FIXME: use filters with mimetypes instead of extensions + + if (filterMask & nsIFilePicker::filterAll) + { + AppendFilter (NS_ConvertUTF8toUCS2 (_("All files")).get(), + NS_LITERAL_STRING ("*").get()); + } + if (filterMask & nsIFilePicker::filterHTML) + { + AppendFilter (NS_ConvertUTF8toUCS2 (_("HTML files")).get(), + NS_LITERAL_STRING ("*.html; *.htm; *.shtml; *.xhtml").get()); + } + if (filterMask & nsIFilePicker::filterText) + { + AppendFilter (NS_ConvertUTF8toUCS2 (_("Text files")).get(), + NS_LITERAL_STRING ("*.txt; *.text").get()); + } + if (filterMask & nsIFilePicker::filterImages) + { + AppendFilter (NS_ConvertUTF8toUCS2 (_("Image files")).get(), + NS_LITERAL_STRING ("*.png; *.gif; *.jpeg; *.jpg").get()); + } + if (filterMask & nsIFilePicker::filterXML) + { + AppendFilter (NS_ConvertUTF8toUCS2 (_("XML files")).get(), + NS_LITERAL_STRING ("*.xml").get()); + } + if (filterMask & nsIFilePicker::filterXUL) + { + AppendFilter (NS_ConvertUTF8toUCS2 (_("XUL files")).get(), + NS_LITERAL_STRING ("*.xul").get()); + } + return NS_OK; } /* void appendFilter (in wstring title, in wstring filter); */ -NS_IMETHODIMP GFilePicker::AppendFilter(const PRUnichar *aTitle, - const PRUnichar *aFilter) +NS_IMETHODIMP GFilePicker::AppendFilter(const PRUnichar *title, const PRUnichar *filter) { - //GtkFileSelection is crippled, so we can't provide a short-list - //of filters to choose from. We provide minimal functionality - //by using the most recent AppendFilter call as the active filter. - mFilter = NS_ConvertUCS2toUTF8(aFilter); - return NS_OK; -} + GtkFileFilter *filth; + + filth = gtk_file_filter_new (); + + gtk_file_filter_set_name (filth, NS_ConvertUCS2toUTF8(title).get()); + gtk_file_filter_add_pattern (filth, NS_ConvertUCS2toUTF8(filter).get()); + + gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (mDialog), filth); -/* attribute long filterIndex; */ -NS_IMETHODIMP GFilePicker::GetFilterIndex(PRInt32 *aFilterIndex) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -NS_IMETHODIMP GFilePicker::SetFilterIndex(PRInt32 aFilterIndex) -{ return NS_OK; } /* attribute wstring defaultString; */ -NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar * *aDefaultString) +NS_IMETHODIMP GFilePicker::GetDefaultString(PRUnichar **aDefaultString) { - gsize bytesWritten; - gchar *utf8DefaultString = g_filename_to_utf8(mDefaultString.get(), -1, - NULL, - &bytesWritten, NULL); + char *filename, *converted; - *aDefaultString = ToNewUnicode(NS_ConvertUTF8toUCS2(utf8DefaultString)); - g_free(utf8DefaultString); + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog)); + if (filename != NULL) + { + converted = g_filename_to_utf8(filename, -1, NULL, NULL, NULL); + + *aDefaultString = ToNewUnicode (NS_ConvertUTF8toUCS2 (converted)); + + g_free (filename); + g_free (converted); + } return NS_OK; } + NS_IMETHODIMP GFilePicker::SetDefaultString(const PRUnichar *aDefaultString) { if (aDefaultString) { - gsize bytesWritten; - gchar *localeDefaultString = - g_filename_from_utf8(NS_ConvertUCS2toUTF8(aDefaultString).get(), - -1, NULL, - &bytesWritten, NULL); - mDefaultString = localeDefaultString; - g_free(localeDefaultString); + /* set_current_name takes UTF-8, not a filename */ + gtk_file_chooser_set_current_name + (GTK_FILE_CHOOSER (mDialog), + NS_ConvertUCS2toUTF8 (aDefaultString).get()); } - else - mDefaultString = ""; + return NS_OK; } /* attribute wstring defaultExtension; */ -// Again, due to the crippled file selector, we can't really -// do anything here. -NS_IMETHODIMP GFilePicker::GetDefaultExtension(PRUnichar * *aDefaultExtension) -{ - return NS_ERROR_NOT_IMPLEMENTED; -} -NS_IMETHODIMP GFilePicker::SetDefaultExtension(const PRUnichar *aDefaultExtension) -{ - return NS_OK; -} - -/* attribute nsILocalFile displayDirectory; */ -NS_IMETHODIMP GFilePicker::GetDisplayDirectory(nsILocalFile * *aDisplayDirectory) +NS_IMETHODIMP GFilePicker::GetDefaultExtension(PRUnichar **aDefaultExtension) { - NS_IF_ADDREF(*aDisplayDirectory = mDisplayDirectory); - return NS_OK; -} -NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile * aDisplayDirectory) -{ - mDisplayDirectory = aDisplayDirectory; - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } -/* readonly attribute nsILocalFile file; */ -NS_IMETHODIMP GFilePicker::GetFile(nsILocalFile * *aFile) +NS_IMETHODIMP GFilePicker::SetDefaultExtension(const PRUnichar *aDefaultExtension) { - NS_IF_ADDREF(*aFile = mFile); - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } -/* readonly attribute nsIFileURL fileURL; */ -NS_IMETHODIMP GFilePicker::GetFileURL(nsIFileURL * *aFileURL) +/* attribute long filterIndex; */ +NS_IMETHODIMP GFilePicker::GetFilterIndex(PRInt32 *aFilterIndex) { - nsCOMPtr<nsIFileURL> fileURL = - do_CreateInstance(NS_STANDARDURL_CONTRACTID); - fileURL->SetFile(mFile); - NS_IF_ADDREF(*aFileURL = fileURL); - return NS_OK; + return NS_ERROR_NOT_IMPLEMENTED; } -/* readonly attribute nsISimpleEnumerator files; */ -NS_IMETHODIMP GFilePicker::GetFiles(nsISimpleEnumerator * *aFiles) +NS_IMETHODIMP GFilePicker::SetFilterIndex(PRInt32 aFilterIndex) { - return NS_ERROR_NOT_IMPLEMENTED; + return NS_ERROR_NOT_IMPLEMENTED; } -/* short show (); */ -NS_IMETHODIMP GFilePicker::Show(PRInt16 *_retval) +/* attribute nsILocalFile displayDirectory; */ +NS_IMETHODIMP GFilePicker::GetDisplayDirectory(nsILocalFile **aDisplayDirectory) { - mFileSelector = gtk_file_selection_new(mTitle.get()); + char *dir = gtk_file_chooser_get_current_folder (GTK_FILE_CHOOSER (mDialog)); - nsCAutoString cFileName; - if(mMode == nsIFilePicker::modeGetFolder) - cFileName.Assign(""); - else - cFileName = mDefaultString; - - nsCAutoString cDirName; - mDisplayDirectory->GetNativePath(cDirName); - - nsCAutoString cFullPath; - cFullPath.Assign(cDirName + NS_LITERAL_CSTRING("/") + cFileName); - gtk_file_selection_set_filename(GTK_FILE_SELECTION(mFileSelector), - cFullPath.get()); - - if (!mFilter.IsEmpty()) - { - gtk_file_selection_complete(GTK_FILE_SELECTION(mFileSelector), - mFilter.get()); - } - - if (mParentWidget) - gtk_window_set_transient_for(GTK_WINDOW(mFileSelector), - GTK_WINDOW(mParentWidget)); - - if (mMode == nsIFilePicker::modeGetFolder) + if (dir != NULL) { - gtk_widget_set_sensitive(GTK_FILE_SELECTION(mFileSelector) - ->file_list, FALSE); - } - - gtk_window_set_modal(GTK_WINDOW(mFileSelector), TRUE); - - gint retVal = gtk_dialog_run(GTK_DIALOG(mFileSelector)); + nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); + file->InitWithNativePath (nsDependentCString (dir)); + NS_IF_ADDREF (*aDisplayDirectory = file); - HandleFilePickerResult(); - - if (retVal != GTK_RESPONSE_OK) - { - *_retval = returnCancel; - } - else - { - ValidateFilePickerResult(_retval); + g_free (dir); } - gtk_widget_destroy(mFileSelector); - return NS_OK; } -//////////////////////////////////////////////////////////////////////////////// -// begin local public methods impl -//////////////////////////////////////////////////////////////////////////////// - -NS_METHOD GFilePicker::InitWithGtkWidget (GtkWidget *aParentWidget, - const char *aTitle, PRInt16 aMode) +NS_IMETHODIMP GFilePicker::SetDisplayDirectory(nsILocalFile *aDisplayDirectory) { - mParentWidget = aParentWidget; + nsCAutoString dir; + aDisplayDirectory->GetNativePath (dir); - mTitle = nsDependentCString(aTitle); - - mMode = aMode; - - mFile = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (mDialog), + dir.get()); return NS_OK; } -NS_METHOD GFilePicker::SanityCheck (PRBool *retIsSane) +/* readonly attribute nsILocalFile file; */ +NS_IMETHODIMP GFilePicker::GetFile(nsILocalFile **aFile) { - *retIsSane = PR_TRUE; - - nsresult rv; - PRBool dirExists, fileExists = PR_TRUE; + char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog)); - if (mDisplayDirectory) + if (filename != NULL) { - rv = mDisplayDirectory->Exists (&dirExists); - g_return_val_if_fail (NS_SUCCEEDED(rv), rv); - } - else - { - dirExists = PR_FALSE; - } - - if (mMode != nsIFilePicker::modeGetFolder) - { - rv = mFile->Exists (&fileExists); - g_return_val_if_fail (NS_SUCCEEDED(rv), rv); - } - - if (mMode == nsIFilePicker::modeSave && !fileExists) - { - return NS_OK; - } + nsCOMPtr<nsILocalFile> file = do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); + file->InitWithNativePath (nsDependentCString (filename)); + NS_IF_ADDREF (*aFile = file); - if (!dirExists || !fileExists) - { - GtkWidget *errorDialog = gtk_message_dialog_new ( - NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - _("The specified path does not exist.")); - - if (mParentWidget) - gtk_window_set_transient_for(GTK_WINDOW(errorDialog), - GTK_WINDOW(mFileSelector)); - - gtk_window_set_modal (GTK_WINDOW(errorDialog), TRUE); - gtk_dialog_run (GTK_DIALOG(errorDialog)); - gtk_widget_destroy (errorDialog); - *retIsSane = PR_FALSE; - return NS_OK; + g_free (filename); } - PRBool correctType; - char *errorText; - if (mMode == nsIFilePicker::modeGetFolder) - { - rv = mDisplayDirectory->IsDirectory (&correctType); - g_return_val_if_fail (NS_SUCCEEDED(rv), rv); - errorText = g_strdup (_("A file was selected when a " - "folder was expected.")); - } - else - { - rv = mFile->IsFile (&correctType); - g_return_val_if_fail (NS_SUCCEEDED(rv), rv); - errorText = g_strdup (_("A folder was selected when a " - "file was expected.")); - } + return NS_OK; +} + +/* readonly attribute nsIFileURL fileURL; */ +NS_IMETHODIMP GFilePicker::GetFileURL(nsIFileURL **aFileURL) +{ + nsCOMPtr<nsILocalFile> file; + GetFile (getter_AddRefs(file)); - if(!correctType) - { - GtkWidget *errorDialog = gtk_message_dialog_new ( - NULL, - GTK_DIALOG_MODAL, - GTK_MESSAGE_ERROR, - GTK_BUTTONS_OK, - errorText); - - if (mParentWidget) - gtk_window_set_transient_for(GTK_WINDOW(errorDialog), - GTK_WINDOW(mFileSelector)); - - gtk_window_set_modal (GTK_WINDOW(errorDialog), TRUE); - gtk_dialog_run (GTK_DIALOG(errorDialog)); - gtk_widget_destroy (errorDialog); - *retIsSane = PR_FALSE; - } - g_free (errorText); + nsCOMPtr<nsIFileURL> fileURL = do_CreateInstance (NS_STANDARDURL_CONTRACTID); + fileURL->SetFile(file); + NS_IF_ADDREF(*aFileURL = fileURL); return NS_OK; } -//////////////////////////////////////////////////////////////////////////////// -// begin local private methods impl -//////////////////////////////////////////////////////////////////////////////// +/* readonly attribute nsISimpleEnumerator files; */ +NS_IMETHODIMP GFilePicker::GetFiles(nsISimpleEnumerator * *aFiles) +{ + // Not sure if we need to implement it at all, it's used nowhere + // in mozilla, but I guess a javascript might call it? + + return NS_ERROR_NOT_IMPLEMENTED; +} -NS_METHOD GFilePicker::HandleFilePickerResult() +/* short show (); */ +NS_IMETHODIMP GFilePicker::Show(PRInt16 *_retval) { - const char *fileName = gtk_file_selection_get_filename(GTK_FILE_SELECTION(mFileSelector)); + gtk_window_set_modal (GTK_WINDOW (mDialog), TRUE); - if (!fileName || strlen(fileName) == 0) return NS_ERROR_FAILURE; + gtk_widget_show (GTK_WIDGET (mDialog)); - const nsACString &cFileName = nsDependentCString(fileName); - mFile->InitWithNativePath(cFileName); + int response = gtk_dialog_run (GTK_DIALOG (mDialog)); - if (mMode == nsIFilePicker::modeGetFolder) + switch (response) { - mDisplayDirectory->InitWithNativePath(cFileName); - mDefaultString = ""; - } - else - { - nsCOMPtr<nsIFile> directory; - mFile->GetParent(getter_AddRefs(directory)); - mDisplayDirectory = do_QueryInterface(directory); - mFile->GetNativeLeafName(mDefaultString); + case EPHY_RESPONSE_OPEN: + case EPHY_RESPONSE_SAVE: + *_retval = nsIFilePicker::returnOK; + break; + default: + *_retval = nsIFilePicker::returnCancel; + break; } - return NS_OK; -} - -NS_METHOD GFilePicker::ValidateFilePickerResult(PRInt16 *retval) -{ - nsresult rv; - const char *fileName = gtk_file_selection_get_filename(GTK_FILE_SELECTION(mFileSelector)); + char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (mDialog)); - *retval = returnCancel; - - PRBool passesSanityCheck; - rv = SanityCheck(&passesSanityCheck); - if (NS_SUCCEEDED(rv) && !passesSanityCheck) return NS_ERROR_FAILURE; - - if (mMode == nsIFilePicker::modeSave) + if (filename == NULL) + { + *_retval = nsIFilePicker::returnCancel; + } + else if (mMode == nsIFilePicker::modeSave + && ephy_gui_confirm_overwrite_file (GTK_WIDGET (mDialog), filename) == FALSE) { - if (!ephy_gui_confirm_overwrite_file (mFileSelector, - fileName)) - { - return NS_OK; - } + *_retval = nsIFilePicker::returnCancel; } - *retval = returnOK; + g_free (filename); return NS_OK; } diff --git a/embed/mozilla/FilePicker.h b/embed/mozilla/FilePicker.h index 430e8d854..cf6a7f68f 100644 --- a/embed/mozilla/FilePicker.h +++ b/embed/mozilla/FilePicker.h @@ -1,5 +1,6 @@ /* * Copyright (C) 2001 Philip Langdale + * Copyright (C) 2003 Christian Persch * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -14,20 +15,17 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ */ -#ifndef __FilePicker_h -#define __FilePicker_h +#ifndef EPHY_FILEPICKER_H +#define EPHY_FILEPICKER_H + +#include <nsIFilePicker.h> +#include <nsISupports.h> -#include "nsIFilePicker.h" -#include "nsError.h" -#include "nsIDOMWindow.h" -#include "nsIDOMWindowInternal.h" -#include "nsCOMPtr.h" -#include "nsString.h" -#include "nsILocalFile.h" -#include <gtk/gtktogglebutton.h> -#include "ephy-embed-shell.h" +#include "ephy-file-chooser.h" #define G_FILEPICKER_CID \ { /* 3636dc79-0b42-4bad-8a3f-ae15d3671d17 */ \ @@ -37,48 +35,25 @@ {0x8a, 0x3f, 0xae, 0x15, 0xd3, 0x67, 0x1d, 0x17} \ } -#define G_FILEPICKER_CONTRACTID "@mozilla.org/filepicker;1" -#define G_FILEPICKER_CLASSNAME "Epiphany's File Picker Implementation" +#define G_FILEPICKER_CONTRACTID "@mozilla.org/filepicker;1" +#define G_FILEPICKER_CLASSNAME "Epiphany File Picker Implementation" class nsIFactory; extern nsresult NS_NewFilePickerFactory(nsIFactory** aFactory); -/* Header file */ class GFilePicker : public nsIFilePicker { - public: +public: NS_DECL_ISUPPORTS NS_DECL_NSIFILEPICKER - enum { returnOK = nsIFilePicker::returnOK, - returnCancel = nsIFilePicker::returnCancel, - returnReplace = nsIFilePicker::returnReplace }; - + GFilePicker(); virtual ~GFilePicker(); - /* additional members */ - NS_METHOD InitWithGtkWidget(GtkWidget *aParentWidget, - const char *aTitle, PRInt16 aMode); - NS_METHOD SanityCheck(PRBool *retIsSane); - - private: - NS_METHOD HandleFilePickerResult(); - NS_METHOD ValidateFilePickerResult(PRInt16 *retval); - - nsCOMPtr<nsIDOMWindow> mParent; - - nsCString mTitle; - nsCString mFilter; - nsCString mDefaultString; - - nsCOMPtr<nsILocalFile> mFile; - nsCOMPtr<nsILocalFile> mDisplayDirectory; - +private: + EphyFileChooser *mDialog; PRInt16 mMode; - - GtkWidget *mParentWidget; - GtkWidget *mFileSelector; }; #endif diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index 9f80eb1c1..d73ef4794 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -35,6 +35,7 @@ INCLUDES = \ -I$(MOZILLA_INCLUDE_ROOT)/webshell \ -I$(MOZILLA_INCLUDE_ROOT)/widget \ -I$(MOZILLA_INCLUDE_ROOT)/windowwatcher \ + -I$(MOZILLA_INCLUDE_ROOT)/xpcom \ $(GCONF_CFLAGS) \ $(EPIPHANY_DEPENDENCY_CFLAGS) \ -DG_DISABLE_DEPRECATED \ diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index e6ee3d0eb..63901ee35 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -36,7 +36,10 @@ * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * - * ***** END LICENSE BLOCK ***** */ + * ***** END LICENSE BLOCK ***** + * + * $Id$ + */ #include "MozDownload.h" #include "mozilla-download.h" @@ -85,7 +88,7 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp { EmbedPersistFlags flags; - ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist), &flags); + flags = ephy_embed_persist_get_flags (EPHY_EMBED_PERSIST (mEmbedPersist)); addToView = !(flags & EMBED_PERSIST_NO_VIEW); } diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp index 8ba3596e8..53443246f 100644 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ b/embed/mozilla/mozilla-embed-persist.cpp @@ -18,11 +18,15 @@ * $Id$ */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include "mozilla-embed-persist.h" +#include "mozilla-embed.h" #include "EphyWrapper.h" #include "EphyHeaderSniffer.h" #include "MozDownload.h" -#include "mozilla-embed.h" -#include "mozilla-embed-persist.h" #include <stddef.h> #include <nsIWebBrowserPersist.h> @@ -49,7 +53,6 @@ impl_cancel (EphyEmbedPersist *persist); struct MozillaEmbedPersistPrivate { nsCOMPtr<nsIWebBrowserPersist> mPersist; -// GProgressListener *mProgress; }; static GObjectClass *parent_class = NULL; diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index 8f1ce3939..5c1f83040 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -33,7 +33,6 @@ #include "eel-gconf-extensions.h" #include "ephy-embed-prefs.h" #include "MozRegisterComponents.h" -#include "FilePicker.h" #include <time.h> #include <libgnome/gnome-i18n.h> @@ -55,6 +54,8 @@ #include <nsICookie.h> #include <nsCCookieManager.h> #include <nsCPasswordManager.h> +#include <nsString.h> +#include <nsILocalFile.h> // FIXME: For setting the locale. hopefully gtkmozembed will do itself soon #include <nsIChromeRegistry.h> @@ -98,16 +99,6 @@ static gresult impl_remove_passwords (EphyEmbedSingle *shell, GList *passwords, PasswordType type); -static gresult -impl_show_file_picker (EphyEmbedSingle *shell, - GtkWidget *parentWidget, - const char *title, - const char *directory, - const char *file, - FilePickerMode mode, - char **ret_fullpath, - FileFormat *file_formats, - int *ret_file_format); static void mozilla_embed_single_new_window_orphan_cb (GtkMozEmbedSingle *embed, GtkMozEmbed **retval, @@ -172,7 +163,6 @@ mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass) shell_class->remove_cookies = impl_remove_cookies; shell_class->list_passwords = impl_list_passwords; shell_class->remove_passwords = impl_remove_passwords; - shell_class->show_file_picker = impl_show_file_picker; g_type_class_add_private (object_class, sizeof(MozillaEmbedSinglePrivate)); } @@ -779,61 +769,3 @@ impl_remove_passwords (EphyEmbedSingle *shell, return G_OK; } - -static gresult -impl_show_file_picker (EphyEmbedSingle *shell, - GtkWidget *parentWidget, - const char *title, - const char *directory, - const char *file, - FilePickerMode mode, - char **ret_fullpath, - FileFormat *file_formats, - int *ret_file_format) -{ - char *expanded_directory = NULL; - gresult result; - - GFilePicker *filePicker = new GFilePicker (); - - if (directory != NULL) - { - expanded_directory = gnome_vfs_expand_initial_tilde (directory); - } - - /* make sure the directory exists, and use the home directory - * otherwise */ - if (!expanded_directory || - !g_file_test (expanded_directory, G_FILE_TEST_IS_DIR)) - { - g_free (expanded_directory); - expanded_directory = g_strdup (g_get_home_dir()); - } - - nsCOMPtr<nsILocalFile> dir = - do_CreateInstance (NS_LOCAL_FILE_CONTRACTID); - dir->InitWithNativePath (nsDependentCString(expanded_directory)); - g_free (expanded_directory); - - filePicker->InitWithGtkWidget (parentWidget, title, mode); - if (file) - { - filePicker->SetDefaultString (NS_ConvertUTF8toUCS2(file).get()); - } - filePicker->SetDisplayDirectory (dir); - - PRInt16 retval; - filePicker->Show (&retval); - - nsCOMPtr<nsILocalFile> local_file; - filePicker->GetFile (getter_AddRefs(local_file)); - nsCAutoString tempFullPathStr; - local_file->GetNativePath (tempFullPathStr); - *ret_fullpath = g_strdup (tempFullPathStr.get()); - - result = (retval == nsIFilePicker::returnCancel) ? G_FAILED : G_OK; - - delete filePicker; - - return result; -} |