From 476dd3a483d5002b07859036b1b7dbb6f883e4f9 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Sat, 11 Jan 2003 12:56:54 +0000 Subject: Implement a cancel api. Fix refcount to really destroy the WebPersist 2003-01-11 Marco Pesenti Gritti * embed/ephy-embed-persist.c: (ephy_embed_persist_cancel): * embed/ephy-embed-persist.h: * embed/mozilla/ProgressListener.cpp: * embed/mozilla/mozilla-embed-persist.cpp: * embed/mozilla/mozilla-embed-persist.h: Implement a cancel api. Fix refcount to really destroy the WebPersist object when done. --- embed/mozilla/mozilla-embed-persist.cpp | 37 ++++++++++++++++++++++++++++----- embed/mozilla/mozilla-embed-persist.h | 4 +++- 2 files changed, 35 insertions(+), 6 deletions(-) (limited to 'embed/mozilla') diff --git a/embed/mozilla/mozilla-embed-persist.cpp b/embed/mozilla/mozilla-embed-persist.cpp index 3453f18cd..a2db4ac4a 100644 --- a/embed/mozilla/mozilla-embed-persist.cpp +++ b/embed/mozilla/mozilla-embed-persist.cpp @@ -36,10 +36,13 @@ mozilla_embed_persist_finalize (GObject *object); static gresult impl_save (EphyEmbedPersist *persist); +static gresult +impl_cancel (EphyEmbedPersist *persist); struct MozillaEmbedPersistPrivate { - gpointer dummy; + nsCOMPtr mPersist; + GProgressListener *mProgress; }; static GObjectClass *parent_class = NULL; @@ -85,12 +88,14 @@ mozilla_embed_persist_class_init (MozillaEmbedPersistClass *klass) object_class->finalize = mozilla_embed_persist_finalize; persist_class->save = impl_save; + persist_class->cancel = impl_cancel; } static void mozilla_embed_persist_init (MozillaEmbedPersist *persist) { persist->priv = g_new0 (MozillaEmbedPersistPrivate, 1); + persist->priv->mPersist = do_CreateInstance (NS_WEBBROWSERPERSIST_CONTRACTID); } static void @@ -103,6 +108,9 @@ mozilla_embed_persist_finalize (GObject *object) persist = MOZILLA_EMBED_PERSIST (object); + persist->priv->mPersist->SetProgressListener (nsnull); + persist->priv->mPersist = nsnull; + g_return_if_fail (persist->priv != NULL); g_free (persist->priv); @@ -110,6 +118,24 @@ mozilla_embed_persist_finalize (GObject *object) G_OBJECT_CLASS (parent_class)->finalize (object); } +void +mozilla_embed_persist_completed (MozillaEmbedPersist *persist) +{ + g_signal_emit_by_name (persist, "completed"); +} + +static gresult +impl_cancel (EphyEmbedPersist *persist) +{ + nsCOMPtr bpersist = + MOZILLA_EMBED_PERSIST (persist)->priv->mPersist; + if (!bpersist) return G_FAILED; + + bpersist->CancelSave (); + + return G_OK; +} + static gresult impl_save (EphyEmbedPersist *persist) { @@ -132,6 +158,10 @@ impl_save (EphyEmbedPersist *persist) g_return_val_if_fail (filename != NULL, G_FAILED); + nsCOMPtr bpersist = + MOZILLA_EMBED_PERSIST (persist)->priv->mPersist; + if (!bpersist) return G_FAILED; + nsCOMPtr linkURI; linkURI = nsnull; if (uri) @@ -141,10 +171,6 @@ impl_save (EphyEmbedPersist *persist) if (NS_FAILED(rv) || !linkURI) return G_FAILED; } - nsCOMPtr bpersist = - do_CreateInstance(NS_WEBBROWSERPERSIST_CONTRACTID, &rv); - if (NS_FAILED(rv) || !persist) return G_FAILED; - nsCOMPtr file; NS_NewLocalFile(NS_ConvertUTF8toUCS2(filename), PR_TRUE, getter_AddRefs(file)); if (NS_FAILED(rv) || !file) return G_FAILED; @@ -194,6 +220,7 @@ impl_save (EphyEmbedPersist *persist) } GProgressListener *aProgress = new GProgressListener (); + MOZILLA_EMBED_PERSIST (persist)->priv->mProgress = aProgress; if (uri == NULL) { diff --git a/embed/mozilla/mozilla-embed-persist.h b/embed/mozilla/mozilla-embed-persist.h index bcd073ca3..d65170eda 100644 --- a/embed/mozilla/mozilla-embed-persist.h +++ b/embed/mozilla/mozilla-embed-persist.h @@ -38,7 +38,7 @@ typedef struct MozillaEmbedPersistClass MozillaEmbedPersistClass; typedef struct MozillaEmbedPersist MozillaEmbedPersist; typedef struct MozillaEmbedPersistPrivate MozillaEmbedPersistPrivate; -struct MozillaEmbedPersist +struct MozillaEmbedPersist { EphyEmbedPersist parent; MozillaEmbedPersistPrivate *priv; @@ -51,6 +51,8 @@ struct MozillaEmbedPersistClass GType mozilla_embed_persist_get_type (void); +void mozilla_embed_persist_completed (MozillaEmbedPersist *persist); + G_END_DECLS #endif -- cgit v1.2.3