[file-roller: 2/6] allow to specify the required packages for each command
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [file-roller: 2/6] allow to specify the required packages for each command
- Date: Fri, 23 Oct 2009 17:28:16 +0000 (UTC)
commit e7fe13ab35956fe1c68c4e3fa35b9e3e2f155568
Author: Paolo Bacchilega <paobac src gnome org>
Date: Fri Oct 23 13:51:44 2009 +0200
allow to specify the required packages for each command
added a get_packages method to FrCommand
src/dlg-package-installer.c | 39 ++++++++++++++++++++-----
src/file-utils.c | 8 +++++
src/file-utils.h | 2 +
src/fr-command-7z.c | 9 +++--
src/fr-command-ace.c | 5 ++-
src/fr-command-alz.c | 5 ++-
src/fr-command-ar.c | 5 ++-
src/fr-command-arj.c | 5 ++-
src/fr-command-cfile.c | 21 +++++++------
src/fr-command-cpio.c | 5 ++-
src/fr-command-iso.c | 5 ++-
src/fr-command-jar.c | 5 ++-
src/fr-command-lha.c | 5 ++-
src/fr-command-rar.c | 18 +++++++++--
src/fr-command-rpm.c | 5 ++-
src/fr-command-tar.c | 23 ++++++++-------
src/fr-command-unstuff.c | 5 ++-
src/fr-command-zip.c | 7 ++--
src/fr-command-zoo.c | 5 ++-
src/fr-command.c | 27 +++++++++++++++--
src/fr-command.h | 10 +++++-
src/main.c | 67 +++++++++++++++++++++++++++++++++++++------
src/main.h | 16 ++++++----
src/typedefs.h | 9 +++++-
24 files changed, 227 insertions(+), 84 deletions(-)
---
diff --git a/src/dlg-package-installer.c b/src/dlg-package-installer.c
index a1c0db4..41a6e1f 100644
--- a/src/dlg-package-installer.c
+++ b/src/dlg-package-installer.c
@@ -30,9 +30,10 @@
typedef struct {
- FrWindow *window;
- FrArchive *archive;
- FrAction action;
+ FrWindow *window;
+ FrArchive *archive;
+ FrAction action;
+ const char *packages;
} InstallerData;
@@ -56,7 +57,10 @@ package_installer_terminated (InstallerData *idata,
error);
}
else {
- /* FIXME: continue batch operation */
+ if (fr_window_is_batch_mode (idata->window))
+ fr_window_resume_batch (idata->window);
+ else
+ fr_window_restart_current_batch_action (idata->window);
}
installer_data_free (idata);
@@ -120,7 +124,7 @@ install_packages (InstallerData *idata)
else
xid = 0;
- names = g_strsplit ("rar,unrar", ",", -1);
+ names = g_strsplit (idata->packages, ",", -1);
call = dbus_g_proxy_begin_call (proxy,
"InstallPackageNames",
(DBusGProxyCallNotify) packagekit_install_package_call_notify_cb,
@@ -128,7 +132,7 @@ install_packages (InstallerData *idata)
NULL,
G_TYPE_UINT, xid,
G_TYPE_STRV, names,
- G_TYPE_STRING, "",
+ G_TYPE_STRING, "" /*"hide-confirm-search"*/,
G_TYPE_INVALID);
success = (call != NULL);
@@ -154,7 +158,7 @@ confirm_search_dialog_response_cb (GtkDialog *dialog,
install_packages (idata);
}
else {
- /* FIXME: cancel the batch operation */
+ fr_window_stop_batch (idata->window);
installer_data_free (idata);
}
}
@@ -203,15 +207,34 @@ dlg_package_installer (FrWindow *window,
FrArchive *archive,
FrAction action)
{
- gboolean success = FALSE;
InstallerData *idata;
+ GType command_type;
+ FrCommand *command;
DBusGConnection *connection;
+ gboolean success = FALSE;
idata = g_new0 (InstallerData, 1);
idata->window = g_object_ref (window);
idata->archive = g_object_ref (archive);
idata->action = action;
+ command_type = get_preferred_command_for_mime_type (idata->archive->content_type, FR_COMMAND_CAN_READ_WRITE);
+ if (command_type == 0)
+ command_type = get_preferred_command_for_mime_type (idata->archive->content_type, FR_COMMAND_CAN_READ);
+ if (command_type == 0) {
+ package_installer_terminated (idata, _("Archive type not supported."));
+ return;
+ }
+
+ command = g_object_new (command_type, 0);
+ idata->packages = fr_command_get_packages (command, idata->archive->content_type);
+ g_object_unref (command);
+
+ if (idata->packages == NULL) {
+ package_installer_terminated (idata, _("Archive type not supported."));
+ return;
+ }
+
#ifdef ENABLE_PACKAGEKIT
connection = dbus_g_bus_get (DBUS_BUS_SESSION, NULL);
if (connection != NULL) {
diff --git a/src/file-utils.c b/src/file-utils.c
index c1866b3..018d6a4 100644
--- a/src/file-utils.c
+++ b/src/file-utils.c
@@ -1178,6 +1178,14 @@ is_program_in_path (const char *filename)
}
+gboolean
+is_program_available (const char *filename,
+ gboolean check)
+{
+ return ! check || is_program_in_path (filename);
+}
+
+
const char *
get_home_uri (void)
{
diff --git a/src/file-utils.h b/src/file-utils.h
index fde0067..18511fe 100644
--- a/src/file-utils.h
+++ b/src/file-utils.h
@@ -99,6 +99,8 @@ char* file_list__get_prev_field (const char *line,
gboolean check_permissions (const char *path,
int mode);
gboolean is_program_in_path (const char *filename);
+gboolean is_program_available (const char *filename,
+ gboolean check);
/* URI utils */
diff --git a/src/fr-command-7z.c b/src/fr-command-7z.c
index ecc6f8c..ebc4fe5 100644
--- a/src/fr-command-7z.c
+++ b/src/fr-command-7z.c
@@ -531,12 +531,13 @@ fr_command_7z_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_7z_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (! is_program_in_path ("7za") && ! is_program_in_path ("7zr") && ! is_program_in_path ("7z"))
+ if (! is_program_available ("7za", check_command) && ! is_program_available ("7zr", check_command) && ! is_program_available ("7z", check_command))
return capabilities;
if (is_mime_type (mime_type, "application/x-7z-compressed")) {
@@ -545,7 +546,7 @@ fr_command_7z_get_capabilities (FrCommand *comm,
else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER | FR_COMMAND_CAN_CREATE_VOLUMES;
}
- else if (is_program_in_path ("7z")) {
+ else if (is_program_available ("7z", check_command)) {
if (is_mime_type (mime_type, "application/x-rar")
|| is_mime_type (mime_type, "application/x-cbr"))
{
@@ -562,7 +563,7 @@ fr_command_7z_get_capabilities (FrCommand *comm,
capabilities |= FR_COMMAND_CAN_WRITE | FR_COMMAND_CAN_ENCRYPT;
}
}
- else if (is_program_in_path ("7za")) {
+ else if (is_program_available ("7za", check_command)) {
if (is_mime_type (mime_type, "application/vnd.ms-cab-compressed")
|| is_mime_type (mime_type, "application/zip"))
{
diff --git a/src/fr-command-ace.c b/src/fr-command-ace.c
index a849580..173b4c1 100644
--- a/src/fr-command-ace.c
+++ b/src/fr-command-ace.c
@@ -247,12 +247,13 @@ fr_command_ace_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_ace_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("unace"))
+ if (is_program_available ("unace", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-alz.c b/src/fr-command-alz.c
index 529e110..34fa368 100644
--- a/src/fr-command-alz.c
+++ b/src/fr-command-alz.c
@@ -310,12 +310,13 @@ fr_command_alz_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_alz_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("unalz"))
+ if (is_program_available ("unalz", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-ar.c b/src/fr-command-ar.c
index 091a67b..8b7762e 100644
--- a/src/fr-command-ar.c
+++ b/src/fr-command-ar.c
@@ -291,12 +291,13 @@ fr_command_ar_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_ar_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("ar")) {
+ if (is_program_available ("ar", check_command)) {
if (is_mime_type (mime_type, "application/x-deb"))
capabilities |= FR_COMMAND_CAN_READ;
else if (is_mime_type (mime_type, "application/x-ar"))
diff --git a/src/fr-command-arj.c b/src/fr-command-arj.c
index 6699c09..2d69d88 100644
--- a/src/fr-command-arj.c
+++ b/src/fr-command-arj.c
@@ -328,12 +328,13 @@ fr_command_arj_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_arj_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES | FR_COMMAND_CAN_ENCRYPT;
- if (is_program_in_path ("arj"))
+ if (is_program_available ("arj", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command-cfile.c b/src/fr-command-cfile.c
index 6b2d05c..5e0ba78 100644
--- a/src/fr-command-cfile.c
+++ b/src/fr-command-cfile.c
@@ -475,43 +475,44 @@ fr_command_cfile_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_cfile_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_DO_NOTHING;
if (is_mime_type (mime_type, "application/x-gzip")) {
- if (is_program_in_path ("gzip"))
+ if (is_program_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-bzip")) {
- if (is_program_in_path ("bzip2"))
+ if (is_program_available ("bzip2", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-compress")) {
- if (is_program_in_path ("compress"))
+ if (is_program_available ("compress", check_command))
capabilities |= FR_COMMAND_CAN_WRITE;
- if (is_program_in_path ("uncompress") || is_program_in_path ("gzip"))
+ if (is_program_available ("uncompress", check_command) || is_program_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ;
}
else if (is_mime_type (mime_type, "application/x-lzip")) {
- if (is_program_in_path ("lzip"))
+ if (is_program_available ("lzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-lzma")) {
- if (is_program_in_path ("lzma"))
+ if (is_program_available ("lzma", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-xz")) {
- if (is_program_in_path ("xz"))
+ if (is_program_available ("xz", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-lzop")) {
- if (is_program_in_path ("lzop"))
+ if (is_program_available ("lzop", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-rzip")) {
- if (is_program_in_path ("rzip"))
+ if (is_program_available ("rzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
diff --git a/src/fr-command-cpio.c b/src/fr-command-cpio.c
index e6810a8..189a513 100644
--- a/src/fr-command-cpio.c
+++ b/src/fr-command-cpio.c
@@ -228,12 +228,13 @@ fr_command_cpio_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_cpio_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("cpio"))
+ if (is_program_available ("cpio", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-iso.c b/src/fr-command-iso.c
index 998c006..d0fd769 100644
--- a/src/fr-command-iso.c
+++ b/src/fr-command-iso.c
@@ -213,12 +213,13 @@ fr_command_iso_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_iso_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("isoinfo"))
+ if (is_program_available ("isoinfo", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-jar.c b/src/fr-command-jar.c
index 5125bf6..3efe3d4 100644
--- a/src/fr-command-jar.c
+++ b/src/fr-command-jar.c
@@ -159,12 +159,13 @@ fr_command_jar_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_jar_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("zip"))
+ if (is_program_available ("zip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command-lha.c b/src/fr-command-lha.c
index dfb7886..efdb216 100644
--- a/src/fr-command-lha.c
+++ b/src/fr-command-lha.c
@@ -313,12 +313,13 @@ fr_command_lha_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_lha_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("lha"))
+ if (is_program_available ("lha", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command-rar.c b/src/fr-command-rar.c
index bf4d6fd..2021e5b 100644
--- a/src/fr-command-rar.c
+++ b/src/fr-command-rar.c
@@ -696,14 +696,15 @@ fr_command_rar_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_rar_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES | FR_COMMAND_CAN_ENCRYPT | FR_COMMAND_CAN_ENCRYPT_HEADER;
- if (is_program_in_path ("rar"))
+ if (is_program_available ("rar", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE | FR_COMMAND_CAN_CREATE_VOLUMES;
- else if (is_program_in_path ("unrar"))
+ else if (is_program_available ("unrar", check_command))
capabilities |= FR_COMMAND_CAN_READ;
/* multi-volumes are read-only */
@@ -714,6 +715,16 @@ fr_command_rar_get_capabilities (FrCommand *comm,
}
+static const char *
+fr_command_rar_get_packages (FrCommand *comm,
+ const char *mime_type)
+{
+ if (is_mime_type (mime_type, "application/x-rar") || is_mime_type (mime_type, "application/x-cbr"))
+ return "rar,unrar";
+ else
+ return NULL;
+}
+
static void
fr_command_rar_class_init (FrCommandRarClass *class)
{
@@ -733,6 +744,7 @@ fr_command_rar_class_init (FrCommandRarClass *class)
afc->handle_error = fr_command_rar_handle_error;
afc->get_mime_types = fr_command_rar_get_mime_types;
afc->get_capabilities = fr_command_rar_get_capabilities;
+ afc->get_packages = fr_command_rar_get_packages;
}
diff --git a/src/fr-command-rpm.c b/src/fr-command-rpm.c
index 152d618..c0016c0 100644
--- a/src/fr-command-rpm.c
+++ b/src/fr-command-rpm.c
@@ -227,12 +227,13 @@ fr_command_rpm_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_rpm_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("cpio"))
+ if (is_program_available ("cpio", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-tar.c b/src/fr-command-tar.c
index fc72455..5cea8a0 100644
--- a/src/fr-command-tar.c
+++ b/src/fr-command-tar.c
@@ -963,47 +963,48 @@ fr_command_tar_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_tar_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
/* In solaris gtar is present under /usr/sfw/bin */
- if (! is_program_in_path ("tar") && ! is_program_in_path ("/usr/sfw/bin/gtar"))
+ if (! is_program_available ("tar", check_command) && ! is_program_available ("/usr/sfw/bin/gtar", check_command))
return capabilities;
if (is_mime_type (mime_type, "application/x-tar")) {
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-compressed-tar")) {
- if (is_program_in_path ("gzip"))
+ if (is_program_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-bzip-compressed-tar")) {
- if (is_program_in_path ("bzip2"))
+ if (is_program_available ("bzip2", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-tarz")) {
- if (is_program_in_path ("compress") && is_program_in_path ("uncompress"))
+ if (is_program_available ("compress", check_command) && is_program_available ("uncompress", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
- else if (is_program_in_path ("gzip"))
+ else if (is_program_available ("gzip", check_command))
capabilities |= FR_COMMAND_CAN_READ;
}
else if (is_mime_type (mime_type, "application/x-lzip-compressed-tar")) {
- if (is_program_in_path ("lzip"))
+ if (is_program_available ("lzip", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-lzma-compressed-tar")) {
- if (is_program_in_path ("lzma"))
+ if (is_program_available ("lzma", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-xz-compressed-tar")) {
- if (is_program_in_path ("xz"))
+ if (is_program_available ("xz", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-lzop-compressed-tar")) {
- if (is_program_in_path ("lzop"))
+ if (is_program_available ("lzop", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
else if (is_mime_type (mime_type, "application/x-7z-compressed-tar")) {
@@ -1011,7 +1012,7 @@ fr_command_tar_get_capabilities (FrCommand *comm,
int i;
for (i = 0; i < G_N_ELEMENTS (try_command); i++) {
- if (is_program_in_path (try_command[i])) {
+ if (is_program_available (try_command[i], check_command)) {
capabilities |= FR_COMMAND_CAN_WRITE;
break;
}
diff --git a/src/fr-command-unstuff.c b/src/fr-command-unstuff.c
index 99114ba..5419a12 100644
--- a/src/fr-command-unstuff.c
+++ b/src/fr-command-unstuff.c
@@ -288,12 +288,13 @@ fr_command_unstuff_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_unstuff_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("unstuff"))
+ if (is_program_available ("unstuff", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-zip.c b/src/fr-command-zip.c
index 39382c0..3b11a79 100644
--- a/src/fr-command-zip.c
+++ b/src/fr-command-zip.c
@@ -388,18 +388,19 @@ fr_command_zip_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_zip_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES | FR_COMMAND_CAN_ENCRYPT;
- if (is_program_in_path ("zip")) {
+ if (is_program_available ("zip", check_command)) {
if (strcmp (mime_type, "application/x-ms-dos-executable") == 0)
capabilities |= FR_COMMAND_CAN_READ;
else
capabilities |= FR_COMMAND_CAN_READ_WRITE;
}
- else if (is_program_in_path ("unzip"))
+ else if (is_program_available ("unzip", check_command))
capabilities |= FR_COMMAND_CAN_READ;
return capabilities;
diff --git a/src/fr-command-zoo.c b/src/fr-command-zoo.c
index b3fd459..3fc7ce8 100644
--- a/src/fr-command-zoo.c
+++ b/src/fr-command-zoo.c
@@ -332,12 +332,13 @@ fr_command_zoo_get_mime_types (FrCommand *comm)
FrCommandCap
fr_command_zoo_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
FrCommandCap capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
- if (is_program_in_path ("zoo"))
+ if (is_program_available ("zoo", check_command))
capabilities |= FR_COMMAND_CAN_READ_WRITE;
return capabilities;
diff --git a/src/fr-command.c b/src/fr-command.c
index 864edab..873c02d 100644
--- a/src/fr-command.c
+++ b/src/fr-command.c
@@ -180,7 +180,8 @@ base_fr_command_get_mime_types (FrCommand *comm)
FrCommandCap
base_fr_command_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
return FR_COMMAND_CAN_DO_NOTHING;
}
@@ -195,6 +196,14 @@ base_fr_command_set_mime_type (FrCommand *comm,
}
+static const char *
+base_fr_command_get_packages (FrCommand *comm,
+ const char *mime_type)
+{
+ return NULL;
+}
+
+
static void
fr_command_start (FrProcess *process,
gpointer data)
@@ -370,6 +379,7 @@ fr_command_class_init (FrCommandClass *class)
class->get_mime_types = base_fr_command_get_mime_types;
class->get_capabilities = base_fr_command_get_capabilities;
class->set_mime_type = base_fr_command_set_mime_type;
+ class->get_packages = base_fr_command_get_packages;
class->start = NULL;
class->done = NULL;
class->progress = NULL;
@@ -712,15 +722,16 @@ fr_command_get_mime_types (FrCommand *comm)
void
fr_command_update_capabilities (FrCommand *comm)
{
- comm->capabilities = fr_command_get_capabilities (comm, comm->mime_type);
+ comm->capabilities = fr_command_get_capabilities (comm, comm->mime_type, TRUE);
}
FrCommandCap
fr_command_get_capabilities (FrCommand *comm,
- const char *mime_type)
+ const char *mime_type,
+ gboolean check_command)
{
- return FR_COMMAND_GET_CLASS (G_OBJECT (comm))->get_capabilities (comm, mime_type);
+ return FR_COMMAND_GET_CLASS (G_OBJECT (comm))->get_capabilities (comm, mime_type, check_command);
}
@@ -732,6 +743,14 @@ fr_command_is_capable_of (FrCommand *comm,
}
+const char *
+fr_command_get_packages (FrCommand *comm,
+ const char *mime_type)
+{
+ return FR_COMMAND_GET_CLASS (G_OBJECT (comm))->get_packages (comm, mime_type);
+}
+
+
/* fraction == -1 means : I don't known how much time the current operation
* will take, the dialog will display this info pulsing
* the progress bar.
diff --git a/src/fr-command.h b/src/fr-command.h
index 0144301..dad77fb 100644
--- a/src/fr-command.h
+++ b/src/fr-command.h
@@ -144,9 +144,12 @@ struct _FrCommandClass
FrProcError *error);
const char ** (*get_mime_types) (FrCommand *comm);
FrCommandCap (*get_capabilities) (FrCommand *comm,
- const char *mime_type);
+ const char *mime_type,
+ gboolean check_command);
void (*set_mime_type) (FrCommand *comm,
const char *mime_type);
+ const char * (*get_packages) (FrCommand *comm,
+ const char *mime_type);
/*<signals>*/
@@ -193,11 +196,14 @@ gboolean fr_command_is_capable_of (FrCommand *comm,
const char ** fr_command_get_mime_types (FrCommand *comm);
void fr_command_update_capabilities (FrCommand *comm);
FrCommandCap fr_command_get_capabilities (FrCommand *comm,
- const char *mime_type);
+ const char *mime_type,
+ gboolean check_command);
void fr_command_set_mime_type (FrCommand *comm,
const char *mime_type);
gboolean fr_command_is_capable_of (FrCommand *comm,
FrCommandCaps capabilities);
+const char * fr_command_get_packages (FrCommand *comm,
+ const char *mime_type);
/* protected functions */
diff --git a/src/main.c b/src/main.c
index 16cd83b..63c4288 100644
--- a/src/main.c
+++ b/src/main.c
@@ -475,20 +475,29 @@ fr_registered_command_new (GType command_type)
reg_com->ref = 1;
reg_com->type = command_type;
reg_com->caps = g_ptr_array_new ();
+ reg_com->packages = g_ptr_array_new ();
command = (FrCommand*) g_object_new (reg_com->type, NULL);
mime_types = fr_command_get_mime_types (command);
for (i = 0; mime_types[i] != NULL; i++) {
- const char *mime_type;
- FrMimeTypeCap *cap;
+ const char *mime_type;
+ FrMimeTypeCap *cap;
+ FrMimeTypePackages *packages;
mime_type = get_static_string (mime_types[i]);
cap = g_new0 (FrMimeTypeCap, 1);
cap->mime_type = mime_type;
- cap->capabilities = fr_command_get_capabilities (command, mime_type);
+ cap->current_capabilities = fr_command_get_capabilities (command, mime_type, TRUE);
+ cap->potential_capabilities = fr_command_get_capabilities (command, mime_type, FALSE);
g_ptr_array_add (reg_com->caps, cap);
+
+ packages = g_new0 (FrMimeTypePackages, 1);
+ packages->mime_type = mime_type;
+ packages->packages = fr_command_get_packages (command, mime_type);
+ g_ptr_array_add (reg_com->packages, packages);
}
+
g_object_unref (command);
return reg_com;
@@ -525,7 +534,25 @@ fr_registered_command_get_capabilities (FrRegisteredCommand *reg_com,
cap = g_ptr_array_index (reg_com->caps, i);
if (strcmp (mime_type, cap->mime_type) == 0)
- return cap->capabilities;
+ return cap->current_capabilities;
+ }
+
+ return FR_COMMAND_CAN_DO_NOTHING;
+}
+
+
+FrCommandCaps
+fr_registered_command_get_potential_capabilities (FrRegisteredCommand *reg_com,
+ const char *mime_type)
+{
+ int i;
+
+ for (i = 0; i < reg_com->caps->len; i++) {
+ FrMimeTypeCap *cap;
+
+ cap = g_ptr_array_index (reg_com->caps, i);
+ if (strcmp (mime_type, cap->mime_type) == 0)
+ return cap->potential_capabilities;
}
return FR_COMMAND_CAN_DO_NOTHING;
@@ -614,6 +641,28 @@ get_command_type_from_mime_type (const char *mime_type,
}
+GType
+get_preferred_command_for_mime_type (const char *mime_type,
+ FrCommandCaps requested_capabilities)
+{
+ int i;
+
+ for (i = 0; i < Registered_Commands->len; i++) {
+ FrRegisteredCommand *command;
+ FrCommandCaps capabilities;
+
+ command = g_ptr_array_index (Registered_Commands, i);
+ capabilities = fr_registered_command_get_potential_capabilities (command, mime_type);
+
+ /* the command must support all the requested capabilities */
+ if (((capabilities ^ requested_capabilities) & requested_capabilities) == 0)
+ return command->type;
+ }
+
+ return 0;
+}
+
+
const char *
get_mime_type_from_extension (const char *ext)
{
@@ -747,13 +796,13 @@ compute_supported_archive_types (void)
g_warning ("mime type not recognized: %s", cap->mime_type);
continue;
}
- mime_type_desc[idx].capabilities |= cap->capabilities;
- if (cap->capabilities & FR_COMMAND_CAN_READ)
+ mime_type_desc[idx].capabilities |= cap->current_capabilities;
+ if (cap->current_capabilities & FR_COMMAND_CAN_READ)
add_if_non_present (open_type, &o_i, idx);
- if (cap->capabilities & FR_COMMAND_CAN_WRITE) {
- if (cap->capabilities & FR_COMMAND_CAN_ARCHIVE_MANY_FILES) {
+ if (cap->current_capabilities & FR_COMMAND_CAN_WRITE) {
+ if (cap->current_capabilities & FR_COMMAND_CAN_ARCHIVE_MANY_FILES) {
add_if_non_present (save_type, &s_i, idx);
- if (cap->capabilities & FR_COMMAND_CAN_WRITE)
+ if (cap->current_capabilities & FR_COMMAND_CAN_WRITE)
add_if_non_present (create_type, &c_i, idx);
}
add_if_non_present (single_file_save_type, &sf_i, idx);
diff --git a/src/main.h b/src/main.h
index 69512bc..8d500f0 100644
--- a/src/main.h
+++ b/src/main.h
@@ -70,12 +70,14 @@ extern int save_type[]; /* File types that can be saved. */
extern int open_type[]; /* File types that can be opened. */
extern int create_type[]; /* File types that can be created. */
-GType get_command_type_from_mime_type (const char *mime_type,
- FrCommandCaps requested_capabilities);
-const char * get_mime_type_from_extension (const char *ext);
-const char * get_archive_filename_extension (const char *uri);
-int get_mime_type_index (const char *mime_type);
-void sort_mime_types_by_extension (int *a);
-void sort_mime_types_by_description (int *a);
+GType get_command_type_from_mime_type (const char *mime_type,
+ FrCommandCaps requested_capabilities);
+GType get_preferred_command_for_mime_type (const char *mime_type,
+ FrCommandCaps requested_capabilities);
+const char * get_mime_type_from_extension (const char *ext);
+const char * get_archive_filename_extension (const char *uri);
+int get_mime_type_index (const char *mime_type);
+void sort_mime_types_by_extension (int *a);
+void sort_mime_types_by_description (int *a);
#endif /* MAIN_H */
diff --git a/src/typedefs.h b/src/typedefs.h
index 06fda21..2fe31d7 100644
--- a/src/typedefs.h
+++ b/src/typedefs.h
@@ -91,13 +91,20 @@ typedef guint8 FrCommandCaps;
typedef struct {
const char *mime_type;
- FrCommandCaps capabilities;
+ FrCommandCaps current_capabilities;
+ FrCommandCaps potential_capabilities;
} FrMimeTypeCap;
typedef struct {
+ const char *mime_type;
+ const char *packages;
+} FrMimeTypePackages;
+
+typedef struct {
int ref;
GType type;
GPtrArray *caps; /* array of FrMimeTypeCap */
+ GPtrArray *packages; /* array of FrMimeTypePackages */
} FrRegisteredCommand;
typedef struct {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]