Bastiaan,
I looked into a solution for the similar problem last fall. I not sure if I
will continue with this project so I HAVE NOT thoroughly tested it. This is
what I came up with.
James,
From the numa.sourceforge.net package
http://ext3carve.cvs.sourceforge.net/ext3carve/gfs_watch/client/numa_gui.c?view=markup
[CODE]
/*
1690 * Determines the type of file and attempts to launch it
1691 * using the default application or the shell
1692 */
1693 static gboolean numa_gui_util_launch_restored (PNOTIFY pnotify, gchar
*pch_file)
1694 {
1695 gboolean b_rc = TRUE;
1696 gchar *pch_uri = NULL, *pch = NULL;
1697 const char *pch_mime = NULL;
1698 const char *pemsg = NULL;
1699 GnomeVFSURI *vfs_uri = NULL;
1700 GnomeVFSMimeApplication *pApp = NULL;
1701 GList *glFile = NULL;
1702 GnomeVFSResult result;
1703 GError *gerror = NULL;
1704
1705 g_return_val_if_fail (pnotify != NULL, FALSE);
1706 g_return_val_if_fail (pch_file != NULL, FALSE);
1707
1708 numa_gui_util_log_msg (numa_gui_util_launch_restored, enter,
pch_file);
1709
1710
1711 /*
1712* turn regular filename into a uri */
1713 pch_uri = gnome_vfs_make_uri_from_input (pch_file);
1714 glFile = g_list_append (glFile, g_strdup ((gchar *)pch_uri));
1715
1716 /*
1717* create a formal uri from output of above */
1718 vfs_uri = gnome_vfs_uri_new (pch_uri);
1719
1720 /*
1721* get the mime type for this uri */
1722 pch_mime = gnome_vfs_get_mime_type_from_uri (vfs_uri);
1723
1724 /*
1725* get the application to launch */
1726 pApp = gnome_vfs_mime_get_default_application_for_uri (pch_uri,
pch_mime);
1727 if (pApp == NULL)
1728 {
1729 if ( g_file_test (pch_file, G_FILE_TEST_IS_EXECUTABLE) )
1730 {
1731 b_rc = g_spawn_command_line_async ( pch_file, gerror );
1732 if ( gerror != NULL )
1733 {
1734 g_snprintf(pnotify-cLastStatusMsg,
sizeof(pnotify-cLastStatusMsg),
1735Launching { %s } EMsg=%s, pch_file,
gerror-message);
1736 g_error_free (gerror);
1737 } else {
1738 g_snprintf(pnotify-cLastStatusMsg,
sizeof(pnotify-cLastStatusMsg),
1739Launched { %s }., pch_file);
1740 }
1741 } else {
1742 g_snprintf(pnotify-cLastStatusMsg,
sizeof(pnotify-cLastStatusMsg),
1743Unable to Launch { %s }., pch_file);
1744 b_rc = FALSE;
1745 }
1746 }
1747 else
1748 {
1749 /*
1750 * launch the application */
1751 result = gnome_vfs_mime_application_launch (pApp, glFile);
1752
1753 switch (result)
1754 {
1755 case GNOME_VFS_OK:
1756 pch = the application was launched.;
1757 pemsg = gnome_vfs_result_to_string (result);
1758 b_rc = TRUE;
1759 break;
1760 case GNOME_VFS_ERROR_NOT_SUPPORTED:
1761 pch = the uri protocol is not supported by the application.;
1762 pemsg = gnome_vfs_result_to_string (result);
1763 b_rc = FALSE;
1764 break;
1765 case GNOME_VFS_ERROR_PARSE:
1766 pch = the application command can not be parsed.;
1767 pemsg = gnome_vfs_result_to_string (result);
1768 b_rc = FALSE;
1769 break;
1770 case GNOME_VFS_ERROR_LAUNCH:
1771 pch = the application command can not be launched.;
1772 pemsg = gnome_vfs_result_to_string (result);
1773 b_rc = FALSE;
1774 break;
1775 case GNOME_VFS_ERROR_INTERNAL:
1776 pch = internal error.;
1777 pemsg = gnome_vfs_result_to_string (result);
1778 b_rc = FALSE;
1779 break;
1780 default:
1781 pch = unknown launch error.;
1782 pemsg = gnome_vfs_result_to_string (result);
1783 b_rc = FALSE;
1784 }
1785
1786 g_snprintf (pnotify-cLastStatusMsg, sizeof(pnotify-cLastStatusMsg),
1787 Launch restored file using %s, %s, %s, pApp-name, pch,
pemsg);
1788 }
1789
1790 /*
1791* release mem used */
1792 gnome_vfs_mime_application_free (pApp);
1793 gnome_vfs_uri_unref (vfs_uri);
1794 g_free(pch_uri);
1795 g_list_free(glFile);
1796
1797 numa_gui_util_log_msg (numa_gui_util_launch_restored, exit, (b_rc)
? Launched : Failed);
1798
1799 return b_rc;
1800 }
[/CODE]
- Original Message
From: Bastiaan Veelo [EMAIL PROTECTED]
To: gtk-app-devel-list@gnome.org
Sent: Saturday, March 8, 2008 5:11:02 PM
Subject: How do I spawn an unknown viewer for a known file?
Hi,
What
is
the
platform
independent
way
to
spawn
a
viewer
for,
say,
a
PDF
document?
Thanks,
Bastiaan.
___
gtk-app-devel-list
mailing
list
gtk-app-devel-list@gnome.org
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
___
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org