aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTing-Wei Lan <lantw44@gmail.com>2013-07-26 00:10:04 +0800
committerLAN-TW <lantw44@gmail.com>2013-09-16 22:04:47 +0800
commit50212cb607e4f3d59824dd7e13bf79fa126527f4 (patch)
treeb3130c12683291ed7170d9dd6e05530309885197
parenta714aaca1a27be4d2982654eb8503249ba6f2c55 (diff)
downloadgsoc2013-epiphany-50212cb607e4f3d59824dd7e13bf79fa126527f4.tar
gsoc2013-epiphany-50212cb607e4f3d59824dd7e13bf79fa126527f4.tar.gz
gsoc2013-epiphany-50212cb607e4f3d59824dd7e13bf79fa126527f4.tar.bz2
gsoc2013-epiphany-50212cb607e4f3d59824dd7e13bf79fa126527f4.tar.lz
gsoc2013-epiphany-50212cb607e4f3d59824dd7e13bf79fa126527f4.tar.xz
gsoc2013-epiphany-50212cb607e4f3d59824dd7e13bf79fa126527f4.tar.zst
gsoc2013-epiphany-50212cb607e4f3d59824dd7e13bf79fa126527f4.zip
Integrate autoarchive functions into Epiphany download panel
This commit complete the extraction part of the archive integration project in Epiphany.
-rw-r--r--embed/ephy-download.c87
-rw-r--r--embed/ephy-download.h5
-rw-r--r--lib/widgets/ephy-download-widget.c119
-rw-r--r--src/Makefile.am1
4 files changed, 185 insertions, 27 deletions
diff --git a/embed/ephy-download.c b/embed/ephy-download.c
index 60cbbb873..c95bfe979 100644
--- a/embed/ephy-download.c
+++ b/embed/ephy-download.c
@@ -36,8 +36,6 @@
#include <errno.h>
#include <glib/gi18n.h>
#include <string.h>
-#include <archive.h>
-#include <archive_entry.h>
G_DEFINE_TYPE (EphyDownload, ephy_download, G_TYPE_OBJECT)
@@ -50,6 +48,7 @@ G_DEFINE_TYPE (EphyDownload, ephy_download, G_TYPE_OBJECT)
struct _EphyDownloadPrivate
{
WebKitDownload *download;
+ AutoarExtract *arextract;
char *destination;
char *source;
@@ -367,6 +366,9 @@ ephy_download_set_destination_uri (EphyDownload *download,
g_return_if_fail (scheme != NULL);
g_free (scheme);
+ if (priv->destination != NULL)
+ g_free (priv->destination);
+
priv->destination = g_strdup (destination);
g_object_notify (G_OBJECT (download), "destination");
@@ -460,6 +462,22 @@ ephy_download_get_webkit_download (EphyDownload *download)
}
/**
+ * ephy_download_get_autoar_extract:
+ * @download: an #EphyDownload
+ *
+ * Gets the #AutoarExtract being wrapped by @download.
+ *
+ * Returns: (transfer none): a #AutoarExtract.
+ **/
+AutoarExtract *
+ephy_download_get_autoar_extract (EphyDownload *download)
+{
+ g_return_val_if_fail (EPHY_IS_DOWNLOAD (download), NULL);
+
+ return download->priv->arextract;
+}
+
+/**
* ephy_download_get_window:
* @download: an #EphyDownload
*
@@ -601,7 +619,7 @@ ephy_download_do_download_action (EphyDownload *download,
priv = download->priv;
- destination_uri = webkit_download_get_destination (priv->download);
+ destination_uri = priv->destination;
destination = g_file_new_for_uri (destination_uri);
switch ((action ? action : priv->action)) {
@@ -636,19 +654,39 @@ ephy_download_do_download_action (EphyDownload *download,
return ret;
}
-/**
- * ephy_download_do_extract_archive:
- * @download: an #EphyDownload
- *
- * Extract downloaded archives for @download.
- *
- * Returns: %TRUE if the extraction succeeded.
- *
- **/
-gboolean
+void
ephy_download_do_extract_archive (EphyDownload *download)
{
- return TRUE;
+ AutoarPref *arpref;
+ AutoarExtract *arextract;
+ GSettings *settings;
+
+ settings = g_settings_new (AUTOAR_PREF_DEFAULT_GSCHEMA_ID);
+ arpref = autoar_pref_new_with_gsettings (settings);
+
+ if (!autoar_pref_check_file_name (arpref, download->priv->destination)) {
+ LOG ("ephy_download_do_extract_archive: not an archive");
+ g_object_unref (settings);
+ g_object_unref (arpref);
+ return;
+ }
+
+ arextract = autoar_extract_new (download->priv->destination,
+ ephy_file_get_downloads_dir (),
+ arpref);
+
+ if (download->priv->arextract != NULL)
+ g_object_unref (download->priv->arextract);
+
+ download->priv->arextract = arextract;
+ g_signal_emit_by_name (download, "archive");
+
+ autoar_extract_start_async (arextract);
+
+ g_object_unref (settings);
+ g_object_unref (arpref);
+
+ return;
}
static void
@@ -667,6 +705,11 @@ ephy_download_dispose (GObject *object)
priv->download = NULL;
}
+ if (priv->arextract) {
+ g_object_unref (priv->arextract);
+ priv->arextract = NULL;
+ }
+
if (priv->window) {
g_object_unref (priv->window);
priv->window = NULL;
@@ -835,6 +878,20 @@ ephy_download_class_init (EphyDownloadClass *klass)
G_TYPE_NONE,
0);
/**
+ * EphyDownload::archive:
+ *
+ * The ::archive signal is emitted when @download is going to extract the
+ * downloaded archive files.
+ **/
+ g_signal_new ("archive",
+ G_OBJECT_CLASS_TYPE (object_class),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (EphyDownloadClass, archive),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0);
+ /**
* EphyDownload::error:
*
* The ::error signal wraps the @download ::error signal.
@@ -857,6 +914,8 @@ ephy_download_init (EphyDownload *download)
LOG ("EphyDownload initialising %p", download);
download->priv->download = NULL;
+ download->priv->arextract = NULL;
+
download->priv->destination = NULL;
download->priv->action = EPHY_DOWNLOAD_ACTION_NONE;
diff --git a/embed/ephy-download.h b/embed/ephy-download.h
index e0b48c50e..7d140693b 100644
--- a/embed/ephy-download.h
+++ b/embed/ephy-download.h
@@ -29,6 +29,7 @@
#ifndef _EPHY_DOWNLOAD_H
#define _EPHY_DOWNLOAD_H
+#include <autoarchive/autoarchive.h>
#include <glib-object.h>
#include <webkit2/webkit2.h>
@@ -57,6 +58,7 @@ struct _EphyDownloadClass
GObjectClass parent_class;
void (* completed) (EphyDownload *download);
+ void (* archive) (EphyDownload *download);
void (* error) (EphyDownload *download,
gint error_code,
gint error_detail,
@@ -90,6 +92,7 @@ void ephy_download_set_destination_uri (EphyDownload *download,
const char *destination);
WebKitDownload *ephy_download_get_webkit_download (EphyDownload *download);
+AutoarExtract *ephy_download_get_autoar_extract (EphyDownload *download);
const char *ephy_download_get_destination_uri (EphyDownload *download);
const char *ephy_download_get_source_uri (EphyDownload *download);
@@ -104,7 +107,7 @@ void ephy_download_set_action (EphyDownload *download,
EphyDownloadActionType action);
gboolean ephy_download_do_download_action (EphyDownload *download,
EphyDownloadActionType action);
-gboolean ephy_download_do_extract_archive (EphyDownload *download);
+void ephy_download_do_extract_archive (EphyDownload *download);
GtkWidget *ephy_download_get_widget (EphyDownload *download);
void ephy_download_set_widget (EphyDownload *download,
diff --git a/lib/widgets/ephy-download-widget.c b/lib/widgets/ephy-download-widget.c
index 8de9fe3c6..d956c9e9a 100644
--- a/lib/widgets/ephy-download-widget.c
+++ b/lib/widgets/ephy-download-widget.c
@@ -45,14 +45,17 @@ G_DEFINE_TYPE (EphyDownloadWidget, ephy_download_widget, GTK_TYPE_BOX)
struct _EphyDownloadWidgetPrivate
{
EphyDownload *download;
+ AutoarExtract *arextract;
GtkWidget *text;
GtkWidget *remaining;
GtkWidget *button;
GtkWidget *menu;
+ GtkWidget *menu_open;
GtkWidget *icon;
gboolean finished;
+ gboolean arextract_ok;
};
enum
@@ -288,14 +291,6 @@ widget_destination_changed_cb (WebKitDownload *download,
g_free (dest);
}
-static void
-widget_finished_cb (WebKitDownload *download,
- EphyDownloadWidget *widget)
-{
- widget->priv->finished = TRUE;
- update_download_label_and_tooltip (widget, _("Finished"));
- totem_glow_button_set_glow (TOTEM_GLOW_BUTTON (widget->priv->button), TRUE);
-}
#else
static void
widget_status_cb (WebKitDownload *download,
@@ -357,6 +352,91 @@ widget_error_cb (WebKitDownload *download,
#endif
static void
+widget_finished_cb (EphyDownload *ephy_download,
+ EphyDownloadWidget *widget)
+{
+ widget->priv->finished = TRUE;
+ update_download_label_and_tooltip (widget, _("Finished"));
+ totem_glow_button_set_glow (TOTEM_GLOW_BUTTON (widget->priv->button), TRUE);
+}
+
+static void
+widget_archive_decide_cb (AutoarExtract *arextract,
+ GFile *destination,
+ EphyDownloadWidget *widget)
+{
+ char *dest = g_file_get_basename (destination);
+ char *uri = g_file_get_uri (destination);
+ LOG ("widget_archive_decide_cb: text: %s => %s",
+ gtk_label_get_text (GTK_LABEL (widget->priv->text)), dest);
+ LOG ("widget_archive_decide_cb: download: %s => %s",
+ ephy_download_get_destination_uri (widget->priv->download), uri);
+ gtk_label_set_text (GTK_LABEL (widget->priv->text), dest);
+ ephy_download_set_destination_uri (widget->priv->download, uri);
+ update_download_icon (widget);
+ g_free (dest);
+ g_free (uri);
+}
+
+static void
+widget_archive_progress_cb (AutoarExtract *arextract,
+ gdouble fraction_size,
+ gdouble fraction_files,
+ EphyDownloadWidget *widget)
+{
+ int progress;
+ char *label;
+ progress = fraction_size * 100;
+ label = g_strdup_printf (_("Extracting: %d%%"), progress);
+ LOG ("widget_archive_progress_cb: %s", label);
+ update_download_label_and_tooltip (widget, label);
+ g_free (label);
+}
+
+static void
+widget_archive_error_cb (AutoarExtract *arextract,
+ GError *error,
+ EphyDownloadWidget *widget)
+{
+ const char *uri = webkit_download_get_destination (ephy_download_get_webkit_download (widget->priv->download));
+ char *dest = g_path_get_basename (uri);
+ LOG ("widget_archive_error_cb: error: %s", error->message);
+ LOG ("widget_archive_error_cb: text: %s => %s",
+ gtk_label_get_text (GTK_LABEL (widget->priv->text)), dest);
+ LOG ("widget_archive_error_cb: download: %s => %s",
+ ephy_download_get_destination_uri (widget->priv->download), uri);
+ gtk_label_set_text (GTK_LABEL (widget->priv->text), dest);
+ ephy_download_set_destination_uri (widget->priv->download, uri);
+ update_download_label_and_tooltip (widget, _("Finished (extraction failed)"));
+ update_download_icon (widget);
+ g_free (dest);
+ g_error_free (error);
+}
+
+static void
+widget_archive_completed_cb (AutoarExtract *arextract,
+ EphyDownloadWidget *widget)
+{
+ widget->priv->arextract_ok = TRUE;
+ update_download_label_and_tooltip (widget, _("Finished"));
+}
+
+static void
+widget_archive_cb (EphyDownload *ephy_download,
+ EphyDownloadWidget *widget)
+{
+ AutoarExtract *arextract = ephy_download_get_autoar_extract (ephy_download);
+ if (widget->priv->arextract != NULL)
+ g_object_unref (widget->priv->arextract);
+ widget->priv->arextract = g_object_ref (arextract);
+ g_signal_connect (arextract, "decide-dest", G_CALLBACK (widget_archive_decide_cb), widget);
+ g_signal_connect (arextract, "progress", G_CALLBACK (widget_archive_progress_cb), widget);
+ g_signal_connect (arextract, "completed", G_CALLBACK (widget_archive_completed_cb), widget);
+ g_signal_connect (arextract, "error", G_CALLBACK (widget_archive_error_cb), widget);
+ update_download_label_and_tooltip (widget, _("Extracting…"));
+}
+
+static void
open_activate_cb (GtkMenuItem *item, EphyDownloadWidget *widget)
{
if (ephy_download_do_download_action (widget->priv->download,
@@ -422,7 +502,7 @@ download_menu_clicked_cb (GtkWidget *button,
item = gtk_menu_item_new_with_label (_("Open"));
gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
- gtk_widget_set_sensitive (item, widget->priv->finished);
+ gtk_widget_set_sensitive (item, widget->priv->finished && !widget->priv->arextract_ok);
g_signal_connect (item, "activate",
G_CALLBACK (open_activate_cb), widget);
@@ -494,7 +574,6 @@ ephy_download_widget_dispose (GObject *object)
#ifdef HAVE_WEBKIT2
g_signal_handlers_disconnect_by_func (download, widget_progress_cb, widget);
g_signal_handlers_disconnect_by_func (download, widget_destination_changed_cb, widget);
- g_signal_handlers_disconnect_by_func (download, widget_finished_cb, widget);
g_signal_handlers_disconnect_by_func (download, widget_failed_cb, widget);
#else
g_signal_handlers_disconnect_by_func (download, widget_progress_cb, widget);
@@ -502,10 +581,22 @@ ephy_download_widget_dispose (GObject *object)
g_signal_handlers_disconnect_by_func (download, widget_error_cb, widget);
#endif
+ g_signal_handlers_disconnect_by_func (download, widget_finished_cb, widget);
+
g_object_unref (widget->priv->download);
widget->priv->download = NULL;
}
+ if (widget->priv->arextract != NULL) {
+ AutoarExtract *arextract = widget->priv->arextract;
+ g_signal_handlers_disconnect_by_func (arextract, widget_archive_decide_cb, widget);
+ g_signal_handlers_disconnect_by_func (arextract, widget_archive_error_cb, widget);
+ g_signal_handlers_disconnect_by_func (arextract, widget_archive_progress_cb, widget);
+ g_signal_handlers_disconnect_by_func (arextract, widget_archive_completed_cb, widget);
+ g_object_unref (widget->priv->arextract);
+ widget->priv->arextract = NULL;
+ }
+
G_OBJECT_CLASS (ephy_download_widget_parent_class)->dispose (object);
}
@@ -543,6 +634,7 @@ ephy_download_widget_init (EphyDownloadWidget *self)
GtkStyleContext *context;
self->priv = DOWNLOAD_WIDGET_PRIVATE (self);
+ self->priv->arextract_ok = FALSE;
gtk_orientable_set_orientation (GTK_ORIENTABLE (self),
GTK_ORIENTATION_HORIZONTAL);
@@ -647,8 +739,6 @@ ephy_download_widget_new (EphyDownload *ephy_download)
G_CALLBACK (widget_progress_cb), widget);
g_signal_connect (download, "notify::destination",
G_CALLBACK (widget_destination_changed_cb), widget);
- g_signal_connect (download, "finished",
- G_CALLBACK (widget_finished_cb), widget);
g_signal_connect (download, "failed",
G_CALLBACK (widget_failed_cb), widget);
#else
@@ -660,6 +750,11 @@ ephy_download_widget_new (EphyDownload *ephy_download)
G_CALLBACK (widget_error_cb), widget);
#endif
+ g_signal_connect (ephy_download, "archive",
+ G_CALLBACK (widget_archive_cb), widget);
+ g_signal_connect (ephy_download, "completed",
+ G_CALLBACK (widget_finished_cb), widget);
+
gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_HALF);
gtk_button_set_relief (GTK_BUTTON (menu), GTK_RELIEF_NORMAL);
diff --git a/src/Makefile.am b/src/Makefile.am
index 0046e6789..e9c5a18e5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -163,6 +163,7 @@ epiphany_LDADD = \
$(top_builddir)/lib/history/libephyhistory.la \
$(top_builddir)/lib/libephymisc.la \
$(top_builddir)/lib/egg/libegg.la \
+ $(top_builddir)/autoarchive/libautoarchive.la \
$(DEPENDENCIES_LIBS) \
$(CODE_COVERAGE_LDFLAGS) \
$(LIBINTL)