Commit 01df4690 authored by Jiri (George) Lebl's avatar Jiri (George) Lebl Committed by George Lebl

deal with dropped uris a tad better and actually use gnome-vfs more. Still

Mon Dec 24 01:55:19 2001  George Lebl <jirka@5z.com>

	* panel.c, panel-util.[ch]: deal with dropped uris a tad better and
	  actually use gnome-vfs more.  Still kind of stupid and needs more
	  work, but better then before.  We should now again handle drops
	  from the menus since those were not from a 'file:' uri's.  Also
	  drop the shell quoting routine since we already have that in glib.

	* panel-widget.c: a bit of constization
parent e9d831c8
Mon Dec 24 01:55:19 2001 George Lebl <jirka@5z.com>
* panel.c, panel-util.[ch]: deal with dropped uris a tad better and
actually use gnome-vfs more. Still kind of stupid and needs more
work, but better then before. We should now again handle drops
from the menus since those were not from a 'file:' uri's. Also
drop the shell quoting routine since we already have that in glib.
* panel-widget.c: a bit of constization
Sat Dec 22 23:12:54 2001 George Lebl <jirka@5z.com>
* Makefile.am, foobar-widget.c, gnome-panel-screenshot.c, panel.c,
......
......@@ -21,7 +21,7 @@
#include <libgnome/libgnome.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnomevfs/gnome-vfs-mime.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-directory.h>
......
......@@ -30,7 +30,7 @@
#include <gconf/gconf-client.h>
#include <libbonobo.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnomevfs/gnome-vfs-mime.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-utils.h>
......
......@@ -19,7 +19,7 @@
#include <libgnomeui/libgnomeui.h>
#include <libgnome/libgnome.h>
#include <libgnomevfs/gnome-vfs-mime-utils.h>
#include <libgnomevfs/gnome-vfs-mime.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-utils.h>
......@@ -937,52 +937,6 @@ panel_is_url (const char *url)
return FALSE;
}
static gboolean
no_need_to_quote (const char *str)
{
const char *p;
/* empty string needs quoting */
if (string_empty (str))
return TRUE;
for (p = str; *p != '\0'; p++) {
if ((*p >= 'a' && *p <= 'z') ||
(*p >= 'A' && *p <= 'Z') ||
strchr ("_-./", *p) != NULL)
continue;
return FALSE;
}
return TRUE;
}
/* Quote string so that it could be on a shell like
* quoted line as an argument */
char *
panel_quote_string (const char *str)
{
GString *gs;
const char *p;
if (string_empty (str))
return g_strdup ("''");
if (no_need_to_quote (str))
return g_strdup (str);
gs = g_string_new ("'");
for (p = str; *p != '\0'; p++) {
if (*p == '\'')
g_string_append (gs, "'\\''");
else
g_string_append_c (gs, *p);
}
g_string_append_c (gs, '\'');
return g_string_free (gs, FALSE);
}
void
panel_push_window_busy (GtkWidget *window)
{
......
......@@ -98,10 +98,6 @@ char * panel_gnome_kde_help_path (const char *docpath);
gboolean panel_is_url (const char *url);
/* Quote string so that it could be on a shell like
* quoted line as an argument */
char * panel_quote_string (const char *str);
void panel_push_window_busy (GtkWidget *window);
void panel_pop_window_busy (GtkWidget *window);
......
......@@ -46,7 +46,7 @@ extern gboolean commie_mode;
static void panel_widget_class_init (PanelWidgetClass *klass);
static void panel_widget_instance_init (PanelWidget *panel_widget);
static int panel_try_to_set_pixmap (PanelWidget *panel,
char *pixmap);
const char *pixmap);
static void panel_resize_pixmap (PanelWidget *panel);
static void panel_try_to_set_back_color (PanelWidget *panel,
GdkColor *color);
......@@ -1477,7 +1477,7 @@ panel_widget_is_cursor(PanelWidget *panel, int overlap)
}
void
panel_widget_set_back_pixmap (PanelWidget *panel, char *file)
panel_widget_set_back_pixmap (PanelWidget *panel, const char *file)
{
g_return_if_fail(panel!=NULL);
g_return_if_fail(PANEL_IS_WIDGET(panel));
......@@ -1651,7 +1651,7 @@ panel_resize_pixmap(PanelWidget *panel)
}
static int
panel_try_to_set_pixmap (PanelWidget *panel, char *pixmap)
panel_try_to_set_pixmap (PanelWidget *panel, const char *pixmap)
{
g_return_val_if_fail(panel!=NULL,FALSE);
g_return_val_if_fail(PANEL_IS_WIDGET(panel),FALSE);
......
......@@ -211,7 +211,7 @@ void panel_widget_change_orient (PanelWidget *panel,
GtkOrientation orient);
void panel_widget_set_back_pixmap (PanelWidget *panel,
char *file);
const char *file);
void panel_widget_set_back_color (PanelWidget *panel,
GdkColor *color);
......
......@@ -18,7 +18,10 @@
#include <libgnome/libgnome.h>
#include <libbonobo.h>
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libgnomevfs/gnome-vfs-ops.h>
#include <libgnomevfs/gnome-vfs-mime.h>
#include <libgnomevfs/gnome-vfs-mime-handlers.h>
#include <libgnomevfs/gnome-vfs-file-info.h>
#include "panel.h"
......@@ -889,57 +892,77 @@ drop_menu (PanelWidget *panel, int pos, const char *dir)
load_menu_applet (dir, FALSE /* main_menu */, flags, TRUE, FALSE, NULL, panel, pos, TRUE);
}
static gboolean
uri_exists (const char *uri)
{
gboolean ret;
GnomeVFSURI *vfs_uri = gnome_vfs_uri_new (uri);
ret = gnome_vfs_uri_exists (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
return ret;
}
static void
drop_nautilus_uri (PanelWidget *panel,
int pos,
const char *uri,
const char *icon)
{
char *quoted = g_shell_quote (uri);
char *exec = g_strdup_printf ("nautilus %s",
quoted);
char *base;
g_free (quoted);
base = g_path_get_basename (uri);
load_launcher_applet_from_info (base,
uri,
exec,
icon,
panel,
pos,
TRUE);
g_free (exec);
g_free (base);
}
static void
drop_directory (PanelWidget *panel, int pos, const char *dir)
{
char *tmp;
tmp = g_build_filename (dir, ".directory", NULL);
if (g_file_test (tmp, G_FILE_TEST_EXISTS)) {
/* not filename, but path, these are uris, not local
* files */
tmp = g_build_path ("/", dir, ".directory", NULL);
if (uri_exists (tmp)) {
g_free (tmp);
drop_menu (panel, pos, dir);
return;
}
g_free (tmp);
tmp = g_build_filename (dir, ".order", NULL);
if (g_file_test (tmp, G_FILE_TEST_EXISTS)) {
tmp = g_build_path ("/", dir, ".order", NULL);
if (uri_exists (tmp)) {
g_free (tmp);
drop_menu (panel, pos, dir);
return;
}
g_free (tmp);
tmp = g_find_program_in_path ("nautilus");
if (tmp != NULL) {
if (panel_is_program_in_path ("nautilus")) {
/* nautilus */
char *exec = g_strdup_printf ("nautilus %s",
panel_quote_string (dir));
char *base;
g_free (tmp);
base = g_path_get_basename (dir);
load_launcher_applet_from_info (base,
dir,
exec,
"gnome-folder.png",
panel,
pos,
TRUE);
g_free (exec);
g_free (base);
drop_nautilus_uri (panel, pos, dir, "gnome-folder.png");
} else {
tmp = g_find_program_in_path ("gmc-client");
if (tmp != NULL) {
if (panel_is_program_in_path ("gmc-client")) {
/* gmc */
char *name;
char *quoted = g_shell_quote (dir);
char *exec = g_strdup_printf ("gmc-client "
"--create-window=%s",
panel_quote_string (dir));
g_free (tmp);
quoted);
g_free (quoted);
name = g_path_get_basename (dir);
load_launcher_applet_from_info (name,
......@@ -962,7 +985,6 @@ drop_urilist (PanelWidget *panel, int pos, char *urilist,
gboolean background_drops)
{
GList *li, *files;
struct stat s;
files = gnome_vfs_uri_list_parse (urilist);
......@@ -970,7 +992,10 @@ drop_urilist (PanelWidget *panel, int pos, char *urilist,
GnomeVFSURI *vfs_uri = li->data;
gchar *uri = gnome_vfs_uri_to_string (vfs_uri, GNOME_VFS_URI_HIDE_NONE);
const char *mimetype;
char *basename;
char *dirname;
char *filename;
GnomeVFSFileInfo *info;
if (strncmp (uri, "http:", strlen ("http:")) == 0 ||
strncmp (uri, "https:", strlen ("https:")) == 0 ||
......@@ -979,40 +1004,79 @@ drop_urilist (PanelWidget *panel, int pos, char *urilist,
strncmp (uri, "ghelp:", strlen ("ghelp:")) == 0 ||
strncmp (uri, "man:", strlen ("man:")) == 0 ||
strncmp (uri, "info:", strlen ("info:")) == 0) {
/* FIXME: probably do this only on link,
* in fact, on link always set up a link,
* on copy do all the other stuff. Or something. */
drop_url (panel, pos, uri);
continue;
}
/* FIXME: We should probably use a gnome-vfs function here instead. */
filename = extract_filename (uri);
if(filename == NULL)
continue;
mimetype = gnome_vfs_mime_type_from_name (uri);
basename = gnome_vfs_uri_extract_short_path_name (vfs_uri);
dirname = gnome_vfs_uri_extract_dirname (vfs_uri);
info = gnome_vfs_file_info_new ();
if(stat(filename, &s) != 0) {
g_free(filename);
continue;
if (gnome_vfs_get_file_info_uri (vfs_uri, info,
GNOME_VFS_FILE_INFO_DEFAULT) != GNOME_VFS_OK) {
gnome_vfs_file_info_unref (info);
info = NULL;
}
mimetype = gnome_vfs_mime_type_from_name(filename);
if (background_drops &&
mimetype != NULL &&
strncmp(mimetype, "image", sizeof("image")-1) == 0) {
strncmp(mimetype, "image", sizeof("image")-1) == 0 &&
/* FIXME: We should probably use a gnome-vfs function here instead. */
/* FIXME: probably port the whole panel background stuff to gnome-vfs */
(filename = extract_filename (uri)) != NULL) {
panel_widget_set_back_pixmap (panel, filename);
g_free (filename);
} else if (basename != NULL &&
strcmp (basename, ".directory") == 0 &&
dirname != NULL) {
/* This is definately a menu */
char *menu_uri = g_strconcat (vfs_uri->method_string, ":",
dirname, NULL);
drop_menu (panel, pos, menu_uri);
g_free (menu_uri);
} else if (mimetype != NULL &&
(strcmp(mimetype, "application/x-gnome-app-info") == 0 ||
strcmp(mimetype, "application/x-kde-app-info") == 0)) {
Launcher *launcher;
launcher = load_launcher_applet (filename, panel, pos, TRUE);
launcher = load_launcher_applet (uri, panel, pos, TRUE);
if (launcher != NULL)
launcher_hoard (launcher);
} else if (S_ISDIR(s.st_mode)) {
drop_directory (panel, pos, filename);
} else if (S_IEXEC & s.st_mode) /*executable?*/
} else if (info != NULL &&
info->type == GNOME_VFS_FILE_TYPE_DIRECTORY) {
drop_directory (panel, pos, uri);
} else if (info != NULL &&
info->valid_fields & GNOME_VFS_FILE_INFO_FIELDS_PERMISSIONS &&
info->permissions &
(GNOME_VFS_PERM_USER_EXEC |
GNOME_VFS_PERM_GROUP_EXEC |
GNOME_VFS_PERM_OTHER_EXEC) &&
(filename = extract_filename (uri)) != NULL) {
/* executable and local, so add a launcher with
* it */
ask_about_launcher (filename, panel, pos, TRUE);
g_free (filename);
g_free (filename);
} else {
/* FIXME: add a launcher that will launch the app
* associated with this file */
/* FIXME: For now just add a launcher that launches
* nautilus on this uri */
const char *icon = NULL;
if (mimetype != NULL)
icon = gnome_vfs_mime_get_icon (mimetype);
if (icon == NULL)
icon = "gnome-unknown.png";
drop_nautilus_uri (panel, pos, uri, icon);
}
if (info != NULL)
gnome_vfs_file_info_unref (info);
g_free (basename);
g_free (dirname);
g_free (uri);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment