diff options
Diffstat (limited to 'embed')
-rw-r--r-- | embed/downloader-view.c | 3 | ||||
-rw-r--r-- | embed/mozilla/ContentHandler.cpp | 6 | ||||
-rw-r--r-- | embed/mozilla/ContentHandler.h | 2 | ||||
-rw-r--r-- | embed/mozilla/MozDownload.cpp | 13 | ||||
-rw-r--r-- | embed/mozilla/mozilla-download.cpp | 102 | ||||
-rw-r--r-- | embed/mozilla/mozilla-download.h | 4 |
6 files changed, 107 insertions, 23 deletions
diff --git a/embed/downloader-view.c b/embed/downloader-view.c index 18b2f940c..38360f089 100644 --- a/embed/downloader-view.c +++ b/embed/downloader-view.c @@ -437,6 +437,8 @@ downloader_view_add_download (DownloaderView *dv, GtkTreeSelection *selection; GtkTreePath *path; + g_object_ref (download); + gtk_list_store_append (GTK_LIST_STORE (dv->priv->model), &iter); gtk_list_store_set (GTK_LIST_STORE (dv->priv->model), @@ -628,6 +630,7 @@ downloader_view_remove_download (DownloaderView *dv, EphyDownload *download) gtk_list_store_remove (GTK_LIST_STORE (dv->priv->model), &iter2); g_hash_table_remove (dv->priv->downloads_hash, download); + g_object_unref (download); /* Actual selection */ diff --git a/embed/mozilla/ContentHandler.cpp b/embed/mozilla/ContentHandler.cpp index 4381a9f47..b39df19bd 100644 --- a/embed/mozilla/ContentHandler.cpp +++ b/embed/mozilla/ContentHandler.cpp @@ -249,7 +249,7 @@ NS_METHOD GContentHandler::Init (void) return NS_OK; } -NS_METHOD GContentHandler::MIMEConfirmAction (PRBool autoDownload) +NS_METHOD GContentHandler::MIMEConfirmAction () { GtkWidget *dialog; GtkWidget *hbox, *vbox, *label, *image; @@ -289,7 +289,7 @@ NS_METHOD GContentHandler::MIMEConfirmAction (PRBool autoDownload) "It's not safe to open it directly. You " "can save it instead.")); } - else if (mAction == CONTENT_ACTION_OPEN && !autoDownload) + else if (mAction == CONTENT_ACTION_OPEN_TMP) { text = g_strdup_printf ("<span weight=\"bold\" size=\"larger\">%s</span>\n\n%s", _("Open the file in another application?"), @@ -370,7 +370,7 @@ NS_METHOD GContentHandler::MIMEDoAction (void) if (!auto_downloads || mAction == CONTENT_ACTION_DOWNLOAD) { - MIMEConfirmAction (auto_downloads); + MIMEConfirmAction (); } nsCOMPtr<nsIMIMEInfo> mimeInfo; diff --git a/embed/mozilla/ContentHandler.h b/embed/mozilla/ContentHandler.h index 3642cc65d..a7f4cb7ca 100644 --- a/embed/mozilla/ContentHandler.h +++ b/embed/mozilla/ContentHandler.h @@ -73,7 +73,7 @@ class GContentHandler : public nsIHelperAppLauncherDialog NS_METHOD Init (); NS_METHOD LaunchHelperApp (); - NS_METHOD MIMEConfirmAction (PRBool autoDownload); + NS_METHOD MIMEConfirmAction (); NS_METHOD MIMEDoAction (); NS_METHOD CheckAppSupportScheme (); diff --git a/embed/mozilla/MozDownload.cpp b/embed/mozilla/MozDownload.cpp index 188169a47..f2877ce9b 100644 --- a/embed/mozilla/MozDownload.cpp +++ b/embed/mozilla/MozDownload.cpp @@ -128,9 +128,9 @@ MozDownload::Init(nsIURI *aSource, nsILocalFile *aTarget, const PRUnichar *aDisp DownloaderView *dview; dview = EPHY_DOWNLOADER_VIEW (ephy_embed_shell_get_downloader_view (embed_shell)); - mEphyDownload = mozilla_download_new (); - MOZILLA_DOWNLOAD (mEphyDownload)->moz_download = this; + mEphyDownload = mozilla_download_new (this); downloader_view_add_download (dview, mEphyDownload); + g_object_unref (mEphyDownload); } else { @@ -558,10 +558,14 @@ GetFilePath (const char *filename) if (g_utf8_collate (download_dir, "Downloads") == 0) { + const char *default_dir; + g_free (download_dir); - return g_build_filename (ephy_file_downloads_dir (), - filename, NULL); + default_dir = ephy_file_downloads_dir (); + ephy_ensure_dir_exists (default_dir); + + return g_build_filename (default_dir, filename, NULL); } converted_dp = g_filename_from_utf8 (download_dir, -1, NULL, NULL, NULL); @@ -570,6 +574,7 @@ GetFilePath (const char *filename) if (converted_dp) { expanded = gnome_vfs_expand_initial_tilde (converted_dp); + ephy_ensure_dir_exists (expanded); path = g_build_filename (expanded, filename, NULL); g_free (expanded); diff --git a/embed/mozilla/mozilla-download.cpp b/embed/mozilla/mozilla-download.cpp index d3c5ac4db..71ed74874 100644 --- a/embed/mozilla/mozilla-download.cpp +++ b/embed/mozilla/mozilla-download.cpp @@ -33,6 +33,19 @@ mozilla_download_init (MozillaDownload *ges); static void mozilla_download_finalize (GObject *object); +enum +{ + PROP_0, + PROP_MOZDOWNLOAD +}; + +struct MozillaDownloadPrivate +{ + MozDownload *moz_download; +}; + +#define MOZILLA_DOWNLOAD_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), MOZILLA_TYPE_DOWNLOAD, MozillaDownloadPrivate)) + static GObjectClass *parent_class = NULL; GType @@ -70,7 +83,7 @@ impl_get_target (EphyDownload *download) nsCOMPtr<nsILocalFile> targetFile; MozDownload *mozDownload; - mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; mozDownload->GetTarget (getter_AddRefs (targetFile)); @@ -87,7 +100,7 @@ impl_get_source (EphyDownload *download) MozDownload *mozDownload; nsCString spec; - mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; mozDownload->GetSource (getter_AddRefs (uri)); uri->GetSpec (spec); @@ -101,7 +114,7 @@ impl_get_current_progress (EphyDownload *download) MozDownload *mozDownload; PRInt32 progress; - mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; mozDownload->GetCurrentProgress (&progress); @@ -114,7 +127,7 @@ impl_get_state (EphyDownload *download) MozDownload *mozDownload; EphyDownloadState state; - mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; mozDownload->GetState (&state); @@ -127,7 +140,7 @@ impl_get_total_progress (EphyDownload *download) MozDownload *mozDownload; PRInt32 progress; - mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; mozDownload->GetTotalProgress (&progress); @@ -140,7 +153,7 @@ impl_get_percent (EphyDownload *download) MozDownload *mozDownload; PRInt32 percent; - mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; mozDownload->GetPercentComplete (&percent); @@ -153,7 +166,7 @@ impl_get_elapsed_time (EphyDownload *download) MozDownload *mozDownload; PRInt64 elapsed; - mozDownload = MOZILLA_DOWNLOAD (download)->moz_download; + mozDownload = MOZILLA_DOWNLOAD (download)->priv->moz_download; mozDownload->GetElapsedTime (&elapsed); @@ -163,28 +176,79 @@ impl_get_elapsed_time (EphyDownload *download) static void impl_cancel (EphyDownload *download) { - MOZILLA_DOWNLOAD (download)->moz_download->Cancel (); + MOZILLA_DOWNLOAD (download)->priv->moz_download->Cancel (); } static void impl_pause (EphyDownload *download) { - MOZILLA_DOWNLOAD (download)->moz_download->Pause (); + MOZILLA_DOWNLOAD (download)->priv->moz_download->Pause (); } static void impl_resume (EphyDownload *download) { - MOZILLA_DOWNLOAD (download)->moz_download->Resume (); + MOZILLA_DOWNLOAD (download)->priv->moz_download->Resume (); +} + +static void +mozilla_download_finalize (GObject *object) +{ + MozillaDownload *download = MOZILLA_DOWNLOAD (object); + + NS_RELEASE (download->priv->moz_download); + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void +mozilla_download_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + MozillaDownload *download = MOZILLA_DOWNLOAD (object); + + switch (prop_id) + { + case PROP_MOZDOWNLOAD: + MozDownload *moz_download; + + moz_download = (MozDownload *)g_value_get_pointer (value); + NS_ADDREF (moz_download); + download->priv->moz_download = moz_download; + break; + } +} + +static void +mozilla_download_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + MozillaDownload *download = MOZILLA_DOWNLOAD (object); + + switch (prop_id) + { + case PROP_MOZDOWNLOAD: + g_value_set_pointer (value, download->priv->moz_download); + break; + } } static void mozilla_download_class_init (MozillaDownloadClass *klass) { + GObjectClass *object_class = G_OBJECT_CLASS (klass); EphyDownloadClass *download_class = EPHY_DOWNLOAD_CLASS (klass); parent_class = (GObjectClass *) g_type_class_peek_parent (klass); + object_class->finalize = mozilla_download_finalize; + object_class->set_property = mozilla_download_set_property; + object_class->get_property = mozilla_download_get_property; + download_class->get_elapsed_time = impl_get_elapsed_time; download_class->get_current_progress = impl_get_current_progress; download_class->get_total_progress = impl_get_total_progress; @@ -195,15 +259,27 @@ mozilla_download_class_init (MozillaDownloadClass *klass) download_class->cancel = impl_cancel; download_class->pause = impl_pause; download_class->resume = impl_resume; + + g_object_class_install_property (object_class, + PROP_MOZDOWNLOAD, + g_param_spec_pointer ("mozilla-download", + "Mozilla Download", + "Mozilla Download", + (GParamFlags) + (G_PARAM_READWRITE | + G_PARAM_CONSTRUCT_ONLY))); } static void -mozilla_download_init (MozillaDownload *view) +mozilla_download_init (MozillaDownload *download) { + download->priv = MOZILLA_DOWNLOAD_GET_PRIVATE (download); } EphyDownload * -mozilla_download_new (void) +mozilla_download_new (MozDownload *download) { - return EPHY_DOWNLOAD (g_object_new (MOZILLA_TYPE_DOWNLOAD, NULL)); + return EPHY_DOWNLOAD (g_object_new (MOZILLA_TYPE_DOWNLOAD, + "mozilla-download", download, + NULL)); } diff --git a/embed/mozilla/mozilla-download.h b/embed/mozilla/mozilla-download.h index fd92d204b..d188f8966 100644 --- a/embed/mozilla/mozilla-download.h +++ b/embed/mozilla/mozilla-download.h @@ -42,7 +42,7 @@ typedef struct MozillaDownloadPrivate MozillaDownloadPrivate; struct MozillaDownload { EphyDownload parent; - MozDownload *moz_download; + MozillaDownloadPrivate *priv; }; struct MozillaDownloadClass @@ -52,7 +52,7 @@ struct MozillaDownloadClass GType mozilla_download_get_type (void); -EphyDownload *mozilla_download_new (void); +EphyDownload *mozilla_download_new (MozDownload *download); G_END_DECLS |