1
1

1999-02-16 Miguel de Icaza <miguel@nuclecu.unam.mx>

* gpopup.c (create_actions): Add support for mountable icons.

	* gdesktop.c (try_to_mount): Add an option to automatically mount
	links on the desktop that point to devices.
	(is_mountable): Returns true if a pathname is mountable.

	* glayout.c: Add the dirsizes command here.

	* gmount.c: New file.  Implements support routines for
	mount/umount.
Этот коммит содержится в:
Miguel de Icaza 1999-02-17 02:18:12 +00:00
родитель c6f07526b7
Коммит e9f974dd11
10 изменённых файлов: 459 добавлений и 11 удалений

Просмотреть файл

@ -1,3 +1,16 @@
1999-02-16 Miguel de Icaza <miguel@nuclecu.unam.mx>
* gpopup.c (create_actions): Add support for mountable icons.
* gdesktop.c (try_to_mount): Add an option to automatically mount
links on the desktop that point to devices.
(is_mountable): Returns true if a pathname is mountable.
* glayout.c: Add the dirsizes command here.
* gmount.c: New file. Implements support routines for
mount/umount.
1999-02-16 Federico Mena Quintero <federico@nuclecu.unam.mx>
* i-symlink.png: Flipped the image around, since we are putting

Просмотреть файл

@ -43,6 +43,7 @@ GNOMESRCS = \
gkey.c \
glayout.c \
gmain.c \
gmount.c \
gmc-chargrid.c \
gmenu.c \
gmetadata.c \
@ -71,6 +72,7 @@ GNOMEHDRS = \
gdnd.h \
gicon.h \
gmain.h \
gmount.h \
gmc-chargrid.h \
gmetadata.h \
gpageprop.h \
@ -138,6 +140,7 @@ OBJS = \
gkey.o \
glayout.o \
gmain.o \
gmount.o \
gmc-chargrid.o \
gmenu.o \
gmetadata.o \

Просмотреть файл

@ -27,6 +27,7 @@
#include "gpopup.h"
#include "../vfs/vfs.h"
#include "main.h"
#include "gmount.h"
/* Name of the user's desktop directory (i.e. ~/desktop) */
#define DESKTOP_DIR_NAME "desktop"
@ -45,7 +46,7 @@ int desktop_auto_placement = FALSE;
int desktop_snap_icons = FALSE;
/* The computed name of the user's desktop directory */
static char *desktop_directory;
char *desktop_directory;
/* Layout information: number of rows/columns for the layout slots, and the array of slots. Each
* slot is an integer that specifies the number of icons that belong to that slot.
@ -825,6 +826,112 @@ selection_stopped (GnomeIconTextItem *iti, gpointer data)
setup_editing_grab (dii);
}
static char *mount_known_locations [] = {
"/sbin/mount", "/bin/mount", "/etc/mount",
"/usr/sbin/mount", "/usr/etc/mount", "/usr/bin/mount",
NULL
};
static char *umount_known_locations [] = {
"/sbin/umount", "/bin/umount", "/etc/umount",
"/usr/sbin/umount", "/usr/etc/umount", "/usr/bin/umount",
NULL
};
/*
* Returns the full path to the mount command
*/
static char *
find_command (char **known_locations)
{
int i;
for (i = 0; known_locations [i]; i++){
if (g_file_exists (known_locations [i]))
return known_locations [i];
}
return NULL;
}
gboolean
is_mountable (char *filename, file_entry *fe, int *is_mounted)
{
char buffer [128];
umode_t mode;
struct stat s;
if (!S_ISLNK (fe->buf.st_mode))
return FALSE;
if (stat (filename, &s) == -1)
return FALSE;
mode = s.st_mode;
if (!S_ISBLK (mode))
return FALSE;
if (readlink (filename, buffer, sizeof (buffer)) == -1)
return FALSE;
if (!is_block_device_mountable (buffer))
return FALSE;
*is_mounted = is_block_device_mounted (buffer);
return TRUE;
}
gboolean
do_mount_umount (char *filename, gboolean is_mount)
{
static char *mount_command;
static char *umount_command;
char *command, *op;
char buffer [128];
if (is_mount){
if (!mount_command)
mount_command = find_command (mount_known_locations);
op = mount_command;
} else {
if (!umount_command)
umount_command = find_command (umount_known_locations);
op = umount_command;
}
if (readlink (filename, buffer, sizeof (buffer)) == -1)
return FALSE;
if (op){
char *command;
FILE *f;
command = g_strconcat (op, " ", buffer, NULL);
open_error_pipe ();
f = popen (command, "r");
if (f == NULL)
close_error_pipe (1, _("While running the mount/umount command"));
else
close_error_pipe (0, 0);
pclose (f);
return TRUE;
}
return FALSE;
}
static gboolean
try_to_mount (char *filename, file_entry *fe)
{
int x;
if (!is_mountable (filename, fe, &x))
return FALSE;
return do_mount_umount (filename, TRUE);
}
/**
* desktop_icon_info_open:
* @dii: The desktop icon to open.
@ -848,10 +955,12 @@ desktop_icon_info_open (DesktopIconInfo *dii)
if (S_ISDIR (fe->buf.st_mode) || link_isdir (fe))
new_panel_at (filename);
else {
if (is_exe (fe->buf.st_mode) && if_link_is_exe (fe))
my_system (EXECUTE_AS_SHELL, shell, filename);
else
gmc_open_filename (filename, NULL);
if (!try_to_mount (filename, fe)){
if (is_exe (fe->buf.st_mode) && if_link_is_exe (fe))
my_system (EXECUTE_AS_SHELL, shell, filename);
else
gmc_open_filename (filename, NULL);
}
}
file_entry_free (fe);
@ -1576,6 +1685,90 @@ setup_trashcan (char *desktop_dir)
g_free (trash_pix);
}
static void
setup_devices (void)
{
GList *list = get_list_of_mountable_devices ();
GList *l;
int floppy = 0;
int generic = 0;
int hd = 0;
char buffer [60];
const char *device_icon = ICONDIR "i-blockdev.png";
if (!list)
return;
/* Create the links */
for (l = list; l; l = l->next){
char *full;
char *name = l->data;
char *short_dev_name = x_basename (name);
char *format = NULL;
int count;
if (strncmp (short_dev_name, "fd", 2) == 0){
char *full;
format = _("floppy %d");
count = floppy++;
} else if (strncmp (short_dev_name, "hd", 2) == 0 || strncmp (short_dev_name, "sd", 2) == 0){
format = _("disk %d");
count = hd++;
} else {
format = _("device %d");
count = generic++;
}
g_snprintf (buffer, sizeof (buffer), format, count);
full = g_concat_dir_and_file (desktop_directory, short_dev_name);
symlink (name, full);
gnome_metadata_set (
full, "icon-filename",
strlen (device_icon) + 1, device_icon);
gnome_metadata_set (
full, "icon-caption",
strlen (buffer)+1, buffer);
gnome_metadata_set (
full, "is-desktop-device",
1, &buffer [0]);
g_free (full);
}
/* release the list */
for (l = list; l; l = l->next)
g_free (l->data);
g_list_free (l);
}
void
desktop_setup_devices ()
{
DIR *dir;
struct dirent *dent;
dir = mc_opendir (desktop_directory);
if (!dir)
return;
while ((dent = mc_readdir (dir)) != NULL){
char *full = g_concat_dir_and_file (desktop_directory, dent->d_name);
int size;
char *buf;
if (gnome_metadata_get (full, "is-desktop-device", &size, &buf) == 0){
mc_unlink (full);
g_free (buf);
}
g_free (full);
}
mc_closedir (dir);
setup_devices ();
reload_desktop_icons (FALSE, 0, 0);
}
/*
* Check that the user's desktop directory exists, and if not, create
* the default desktop setup.
@ -1605,6 +1798,8 @@ create_desktop_dir (void)
gnome_user_home_dir, home_link_name);
}
g_free (home_link_name);
setup_devices ();
}
/* setup_trashcan (desktop_directory); */

Просмотреть файл

@ -24,7 +24,7 @@
extern int desktop_use_shaped_icons; /* Whether to use shaped icons or not (for slow X servers) */
extern int desktop_auto_placement; /* Whether to auto-place icons or not (user placement) */
extern int desktop_snap_icons; /* Whether to snap icons to the grid or not */
extern char *desktop_directory;
extern int tree_panel_visible;
/* Initializes the desktop -- init DnD, load the default desktop icons, etc. */
@ -54,4 +54,8 @@ void desktop_icon_info_delete (DesktopIconInfo *dii);
file_entry *file_entry_from_file (char *filename);
void file_entry_free (file_entry *fe);
gboolean is_mountable (char *filename, file_entry *fe, int *is_mounted);
gboolean do_mount_umount (char *filename, gboolean is_mount);
void desktop_setup_devices ();
#endif

Просмотреть файл

@ -308,6 +308,8 @@ GnomeUIInfo gnome_panel_file_menu [] = {
GNOMEUIINFO_ITEM_STOCK(N_("_Delete..."), N_("Delete files"), delete_cmd, GNOME_STOCK_PIXMAP_REMOVE),
GNOMEUIINFO_ITEM_NONE(N_("_Move..."), N_("Rename or move files"), ren_cmd),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_ITEM_NONE(N_("Show directory sizes"), N_("Shows the disk space used by each directory"), dirsizes_cmd),
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_MENU_CLOSE_WINDOW_ITEM(gnome_close_panel, NULL),
GNOMEUIINFO_END
};
@ -358,6 +360,8 @@ GnomeUIInfo gnome_panel_commands_menu [] = {
#ifdef WITH_BACKGROUND
GNOMEUIINFO_ITEM_NONE( N_("_Background jobs..."), N_("List of background operations"), jobs_cmd ),
#endif
GNOMEUIINFO_SEPARATOR,
GNOMEUIINFO_ITEM_NONE( N_("Recreate desktop devices"), N_("Recreates the devices shown on the desktop"), desktop_setup_devices ),
GNOMEUIINFO_END
};

166
gnome/gmount.c Обычный файл
Просмотреть файл

@ -0,0 +1,166 @@
#include <config.h>
#ifdef STDC_HEADERS
#include <stdlib.h>
#else
void free (void *ptr);
#endif
#if defined(STDC_HEADERS) || defined(HAVE_STRING_H)
#include <string.h>
#else
#include <strings.h>
#endif
#ifdef HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#if defined (MOUNTED_GETFSSTAT) /* __alpha running OSF_1 */
#include <sys/mount.h>
#include <sys/fs_types.h>
#endif /* MOUNTED_GETFSSTAT */
#ifdef MOUNTED_GETMNTENT1 /* 4.3BSD, SunOS, HP-UX, Dynix, Irix. */
#include <mntent.h>
#if !defined(MOUNTED)
#if defined(MNT_MNTTAB) /* HP-UX. */
#define MOUNTED MNT_MNTTAB
#endif
#if defined(MNTTABNAME) /* Dynix. */
#define MOUNTED MNTTABNAME
#endif
#endif
#endif
#ifdef MOUNTED_GETMNTINFO /* 4.4BSD. */
#include <sys/mount.h>
#endif
#ifdef MOUNTED_GETMNT /* Ultrix. */
#include <sys/mount.h>
#include <sys/fs_types.h>
#endif
#ifdef MOUNTED_FREAD /* SVR2. */
#include <mnttab.h>
#endif
#ifdef MOUNTED_FREAD_FSTYP /* SVR3. */
#include <mnttab.h>
#include <sys/fstyp.h>
#include <sys/statfs.h>
#endif
#ifdef MOUNTED_GETMNTENT2 /* SVR4. */
#include <sys/mnttab.h>
#endif
#ifdef MOUNTED_VMOUNT /* AIX. */
#include <fshelp.h>
#include <sys/vfs.h>
#endif
/* 4.4BSD2 derived systems */
#if defined(__bsdi__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__FreeBSD__)
# ifndef MOUNT_UFS
# define xBSD
# endif
#endif
/* void error (void); FIXME -- needed? */
#ifdef DOLPHIN
/* So special that it's not worth putting this in autoconf. */
#undef MOUNTED_FREAD_FSTYP
#define MOUNTED_GETMNTTBL
#endif
#include <glib.h>
#include "gmount.h"
#ifdef MOUNTED_GETMNTENT1
gboolean
is_block_device_mountable (char *devname)
{
FILE *f;
struct mntent *mnt;
gboolean retval = FALSE;
if (getuid () == 0)
return TRUE;
f = setmntent ("/etc/fstab", "r");
if (f == NULL)
return FALSE;
while ((mnt = getmntent (f))){
if (strstr (mnt->mnt_opts, "user")){
retval = TRUE;
break;
}
}
endmntent (f);
return retval;
}
gboolean
is_block_device_mounted (char *filename)
{
FILE *f;
struct mntent *mnt;
gboolean retval = FALSE;
f = setmntent ("/etc/mtab", "r");
if (f == NULL)
return FALSE;
while ((mnt = getmntent (f))){
if (strcmp (mnt->mnt_fsname, filename) == 0)
retval = TRUE;
}
endmntent (f);
return retval;
}
GList *
get_list_of_mountable_devices (void)
{
FILE *f;
struct mntent *mnt;
GList *list = NULL;
f = setmntent ("/etc/fstab", "r");
if (f == NULL)
return NULL;
while ((mnt = getmntent (f))){
if (strstr (mnt->mnt_opts, "user")){
list = g_list_prepend (list, g_strdup (mnt->mnt_fsname));
break;
}
}
endmntent (f);
return list;
}
#else
gboolean
is_block_device_mountable (char *devname)
{
return FALSE;
}
GList *
get_list_of_mountable_devices ()
{
return NULL;
}
gboolean
is_block_device_mounted (char *devname)
{
return TRUE;
}
#endif

8
gnome/gmount.h Обычный файл
Просмотреть файл

@ -0,0 +1,8 @@
#ifndef GMOUNT_H
#define GMOUNT_H
gboolean is_block_device_mountable (char *devname);
gboolean is_block_device_mounted (char *devname);
GList *get_list_of_mountable_devices (void);
#endif

Просмотреть файл

@ -31,7 +31,9 @@ enum {
F_SINGLE = 1 << 3, /* Applies only to a single file, not to a multiple selection */
F_NOTDIR = 1 << 4, /* Applies to non-directories */
F_DICON = 1 << 5, /* Applies to desktop icons */
F_PANEL = 1 << 6 /* Applies to files from a panel window */
F_PANEL = 1 << 6, /* Applies to files from a panel window */
F_MOUNTABLE = 1 << 7, /* Only if the device is mountable */
F_UNMOUNTABLE = 1 << 8 /* Only if the device is unmountable */
};
struct action {
@ -118,6 +120,24 @@ dicon_execute (GtkWidget *widget, DesktopIconInfo *dii)
desktop_icon_info_open (dii);
}
static void
dicon_unmount (GtkWidget *widget, DesktopIconInfo *dii)
{
char *full = g_concat_dir_and_file (desktop_directory, dii->filename);
do_mount_umount (full, FALSE);
g_free (full);
}
static void
dicon_mount (GtkWidget *widget, DesktopIconInfo *dii)
{
char *full = g_concat_dir_and_file (desktop_directory, dii->filename);
do_mount_umount (full, TRUE);
g_free (full);
}
static void
panel_action_properties (GtkWidget *widget, WPanel *panel)
{
@ -225,6 +245,8 @@ fill_menu (GtkMenuShell *menu_shell, GnomeUIInfo *uiinfo, int pos)
static struct action file_actions[] = {
{ N_("Properties"), F_SINGLE | F_PANEL, (GtkSignalFunc) panel_action_properties },
{ N_("Properties"), F_SINGLE | F_DICON, (GtkSignalFunc) dicon_properties },
{ N_("Mount device"), F_SINGLE|F_MOUNTABLE|F_DICON, (GtkSignalFunc) dicon_mount },
{ N_("Unmount device"), F_SINGLE|F_UNMOUNTABLE|F_DICON, (GtkSignalFunc) dicon_unmount },
{ "", F_SINGLE, NULL },
{ N_("Open"), F_PANEL | F_ALL, (GtkSignalFunc) panel_action_open },
{ N_("Open"), F_DICON | F_ALL, (GtkSignalFunc) dicon_execute },
@ -333,6 +355,34 @@ create_actions (GtkWidget *menu, WPanel *panel,
if (!S_ISLNK (s->st_mode))
continue;
}
if (action->flags & (F_MOUNTABLE|F_UNMOUNTABLE)){
char *fullname;
file_entry *fe;
int v;
int is_mounted;
fullname = g_concat_dir_and_file (desktop_directory, dii->filename);
fe = file_entry_from_file (fullname);
if (fe){
v = is_mountable (fullname, fe, &is_mounted);
file_entry_free (fe);
g_free (fullname);
if (!v)
continue;
if (is_mounted && (action->flags & F_MOUNTABLE))
continue;
if ((!is_mounted) && (action->flags & F_UNMOUNTABLE))
continue;
} else {
g_free (fullname);
continue;
}
}
}
/* Create the appropriate GnomeUIInfo structure for the menu item */

Просмотреть файл

@ -45,10 +45,15 @@ int query_dialog (char *header, char *text, int flags, int count, ...)
const gchar **buttons;
char *stock;
GSList *allocated = NULL;
char *h;
if (header == MSG_ERROR)
if (header == MSG_ERROR){
h = GNOME_MESSAGE_BOX_ERROR;
header = _("Error");
} else {
h = GNOME_MESSAGE_BOX_ERROR;
}
/* extract the buttons from the args */
buttons = g_malloc (sizeof (char *) * (count+1));
va_start (ap, count);
@ -75,7 +80,8 @@ int query_dialog (char *header, char *text, int flags, int count, ...)
va_end (ap);
buttons[i] = NULL;
dialog = gnome_message_box_newv (text, header, buttons);
dialog = gnome_message_box_newv (text, h, buttons);
gtk_window_set_title (GTK_WINDOW (dialog), header);
gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE);
result = gnome_dialog_run_and_close (GNOME_DIALOG (dialog));

Просмотреть файл

@ -396,7 +396,6 @@ struct mount_entry *read_filesystem_list (int need_fs_type, int all_fs)
me->me_type = strdup (mnt.mnt_fstype);
me->me_dev = -1; /* Magic; means not known yet. */
me->me_next = NULL;
/* Add to the linked list. */
mtail->me_next = me;
mtail = me;