From 903eb5a8805e3efa8b24e962a7bd8607cca4816a Mon Sep 17 00:00:00 2001 From: Miguel de Icaza Date: Fri, 30 Oct 1998 00:47:54 +0000 Subject: [PATCH] Sync to laptop; I ifdef-ed the old code just so that it will compile - Federico --- gnome/ChangeLog | 7 ++ gnome/Makefile.in | 3 + gnome/gdesktop-icon.c | 14 +++- gnome/gdesktop.c | 177 ++++++++++++++++++++++++++++++++++++++++-- gnome/gdesktop.h | 40 +++++++++- gnome/gmetadata.c | 84 ++++++++++++++++++++ gnome/gmetadata.h | 21 +++++ 7 files changed, 337 insertions(+), 9 deletions(-) create mode 100644 gnome/gmetadata.c create mode 100644 gnome/gmetadata.h diff --git a/gnome/ChangeLog b/gnome/ChangeLog index 637345aa0..3826d7e9c 100644 --- a/gnome/ChangeLog +++ b/gnome/ChangeLog @@ -1,3 +1,10 @@ +1998-10-29 Federico Mena Quintero + + * gmetadata.[ch]: New files with functions to handle all metadata + issues -- fetching icons, icon positions, etc. + + * Makefile.in: Added gmetadata.[ch] to the list of sources. + 1998-10-28 Federico Mena Quintero * gdesktop-icon.c (create_window_shape): Use shaped icons only diff --git a/gnome/Makefile.in b/gnome/Makefile.in index b805744e5..b2b630453 100644 --- a/gnome/Makefile.in +++ b/gnome/Makefile.in @@ -18,6 +18,7 @@ GNOMESRCS = \ gdesktop-icon.c \ gkey.c \ gmain.c \ + gmetadata.c \ gscreen.c \ gwidget.c \ gmenu.c \ @@ -40,6 +41,7 @@ GNOMESRCS = \ GNOMEHDRS = \ gdesktop-icon.h \ gmain.h \ + gmetadata.h \ gscreen.h \ gwidget.h \ gdesktop.h \ @@ -82,6 +84,7 @@ OBJS = $(LOBJS) $(OOBJS) \ gdesktop-icon.o \ gkey.o \ gmain.o \ + gmetadata.o \ gscreen.o \ gwidget.o \ gmenu.o \ diff --git a/gnome/gdesktop-icon.c b/gnome/gdesktop-icon.c index fe4b2fbe3..05ed59e28 100644 --- a/gnome/gdesktop-icon.c +++ b/gnome/gdesktop-icon.c @@ -92,8 +92,11 @@ create_window_shape (DesktopIcon *dicon, int icon_width, int icon_height, int te im = GNOME_CANVAS_IMAGE (dicon->icon)->im; gdk_imlib_render (im, icon_width, icon_height); im_mask = gdk_imlib_move_mask (im); - +#if 0 if (im_mask && desktop_use_shaped_icons) { +#else + if (im_mask && want_transparent_icons) { +#endif gdk_draw_pixmap (mask, mgc, im_mask, @@ -243,7 +246,11 @@ set_text (DesktopIcon *dicon, char *text) gnome_icon_text_item_configure (GNOME_ICON_TEXT_ITEM (dicon->text), 0, icon_height + SPACING, +#if 0 DESKTOP_SNAP_X, +#else + SNAP_X, +#endif DESKTOP_ICON_FONT, text, TRUE); @@ -349,8 +356,11 @@ desktop_icon_reshape (DesktopIcon *dicon) text_height = y2 - y1 + 1; /* Calculate new size of widget */ - +#if 0 dicon->width = MAX (icon_width, DESKTOP_SNAP_X); +#else + dicon->width = MAX (icon_width, SNAP_X); +#endif dicon->height = icon_height + SPACING + text_height; /* Set new position of children */ diff --git a/gnome/gdesktop.c b/gnome/gdesktop.c index ec50f31a8..391ffb677 100644 --- a/gnome/gdesktop.c +++ b/gnome/gdesktop.c @@ -1,10 +1,175 @@ -/* - * Controls the desktop contents - * (C) 1998 the Free Software Foundation +/* Desktop management for the Midnight Commander * - * Authors: Miguel de Icaza (miguel@gnu.org) - * Federico Mena (federico@nuclecu.unam.mx) + * Copyright (C) 1998 The Free Software Foundation + * + * Authors: Federico Mena + * Miguel de Icaza */ +#if 0 +#include +#include +#include "gdesktop.h" +#include "../vfs/vfs.h" + + +/* Name of the user's desktop directory (i.e. ~/Desktop) */ +#define DESKTOP_DIR_NAME "desktop" + + +/* This structure defines the information carried by a desktop icon */ +struct desktop_icon_info { + GtkWidget *dicon; /* The desktop icon widget */ + int x, y; /* Position in the desktop */ + char *filename; /* The file this icon refers to */ + int selected : 1; /* Is the icon selected? */ +}; + + +/* Should use a shaped window for icons? If not, use a solid square. */ +int desktop_use_shaped_icons = TRUE; + +/* The computed name of the user's desktop directory */ +static char *desktop_directory; + +/* Layout information: number of rows/columns for the layout slots, and the array of slots */ +static int layout_cols; +static int layout_rows; +static int *layout_slots; + +/* The list of desktop icons */ +static GList *desktop_icons; + + +/* Creates a new desktop icon. The filename is the pruned filename inside the desktop directory. + * If auto_pos is true, then the function will look for a place to position the icon automatically, + * else it will use the specified coordinates. + */ +static void +desktop_icon_info_new (char *filename, int auto_pos, int xpos, int ypos) +{ + +} + +/* Creates the layout information array */ +static void +create_layout_info (void) +{ + layout_cols = gdk_screen_width () / DESKTOP_SNAP_X; + layout_rows = gdk_screen_height () / DESKTOP_SNAP_Y; + layout_slots = g_new0 (int, layout_cols * layout_rows); +} + +/* Check that the user's desktop directory exists, and if not, create it with a symlink to the + * user's home directory so that an icon will be displayed. + */ +static void +create_desktop_dir (void) +{ + char *home_link_name; + + desktop_directory = g_concat_dir_and_file (gnome_user_home_dir, DESKTOP_DIR_NAME); + + if (!g_file_exists (desktop_directory)) { + /* Create the directory */ + + mkdir (desktop_directory, 0777); + + /* Create the link to the user's home directory so that he will have an icon */ + + home_link_name = g_concat_dir_and_file (desktop_directory, _("Home directory")); + + if (mc_symlink (gnome_user_home_dir, home_link_name) != 0) { + message (FALSE, + _("Warning"), + _("Could not symlink %s to %s; will not have initial desktop icons."), + gnome_user_home_dir, home_link_name); + g_free (home_link_name); + return; + } + + g_free (home_link_name); + } +} + +/* Reads the ~/Desktop directory and creates the initial desktop icons */ +static void +load_initial_desktop_icons (void) +{ + struct dirent *dirent; + DIR *dir; + int have_pos, x, y; + + dir = mc_opendir (desktop_directory); + if (!dir) { + message (FALSE, + _("Warning"), + _("Could not open %s; will not have initial desktop icons"), + desktop_directory); + return; + } + + while ((dirent = mc_readdir (dir)) != NULL) { + if (((dirent->d_name[0] == '.') && (dirent->d_name[1] == 0)) + || ((dirent->d_name[0] == '.') && (dirent->d_name[1] == '.') && (dirent->d_name[2] == 0))) + continue; + + desktop_icon_info_new (dirent->d_name, TRUE, 0, 0); + } + + mc_closedir (dir); +} + +/** + * desktop_init + * + * Initializes the desktop by setting up the default icons (if necessary), setting up drag and drop, + * and other miscellaneous tasks. + */ +void +desktop_init (void) +{ + create_layout_info (); + create_desktop_dir (); + load_initial_desktop_icons (); +} + +/** desktop_destroy + * + * Shuts the desktop down by destroying the desktop icons. + */ +void +desktop_destroy (void) +{ + GList *list; + + /* Destroy the desktop icons */ + + for (list = desktop_icons; list; list = list->next) + desktop_icon_info_free (dii->data); + + g_list_free (desktop_icons); + desktop_icons = NULL; + + /* Cleanup */ + + g_free (layout_slots); + layout_slots = NULL; + layout_cols = 0; + layout_rows = 0; + + g_free (desktop_directory); + desktop_directory = NULL; +} + + + + + + + + +#else + #include #include #include "gdesktop-icon.h" @@ -1485,3 +1650,5 @@ stop_desktop (void) } image_cache_destroy (); } + +#endif diff --git a/gnome/gdesktop.h b/gnome/gdesktop.h index 8afe25943..0aa64c82c 100644 --- a/gnome/gdesktop.h +++ b/gnome/gdesktop.h @@ -1,5 +1,39 @@ -#ifndef _GDESKTOP_H -#define _GDESKTOP_H +/* Desktop management for the Midnight Commander + * + * Copyright (C) 1998 The Free Software Foundation + * + * Authors: Federico Mena + * Miguel de Icaza + */ + +#ifndef GDESKTOP_H +#define GDESKTOP_H + +#if 0 + + +/* Snap granularity for desktop icons -- maybe these should be calculated in terms of the font size? */ +#define DESKTOP_SNAP_X 80 +#define DESKTOP_SNAP_Y 80 + + +/* Configuration options for the desktop */ + +extern int desktop_use_shaped_icons; /* Specifies whether to use shaped icons or not (for slow X servers) */ + + +/* Initializes the desktop -- init DnD, load the default desktop icons, etc. */ +void desktop_init (void); + +/* Shuts the desktop down by destroying the desktop icons. */ +void desktop_destroy (void); + + + + + + +#else #define MC_LIB_DESKTOP "mc.desktop" @@ -72,3 +106,5 @@ void file_popup (GdkEventButton *event, void *WPanel_pointer, void *desktop_icon extern int icons_snap_to_grid; #endif + +#endif diff --git a/gnome/gmetadata.c b/gnome/gmetadata.c new file mode 100644 index 000000000..be851371e --- /dev/null +++ b/gnome/gmetadata.c @@ -0,0 +1,84 @@ +/* Convenience functions for metadata handling in the MIdnight Commander + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena + */ + +#include +#include +#include +#include "gmetadata.h" + + +#define ICON_FILENAME "icon-filename" +#define ICON_POSITION "icon-position" + + +/** + * meta_get_icon_for_file + * @filename: The name of the file to get the icon for. + * + * Computes the name of the file that holds the icon for the specified file. The + * resulting string is guaranteed to be non-NULL. You have to free this string + * on your own. + * + * Returns the icon's file name. + */ +char * +meta_get_icon_for_file (char *filename) +{ + int size; + char *buf; + struct stat s; + int retval; + + g_return_if_fail (filename != NULL); + + if (gnome_metadata_get (filename, ICON_FILENAME, &size, &buf) != 0) { + /* Return a default icon */ + + retval = mc_stat (filename, &s); + + if (!retval && S_ISDIR (s.st_mode)) + return gnome_unconditional_pixmap_file ("gnome-folder.png"); + else + return gnome_unconditional_pixmap_file ("gnome-unknown.png"); + } + + return buf; +} + +/** + * meta_get_desktop_icon_pos + * @filename: The file under ~/desktop for which to get the icon position + * @x: The x position will be stored here. Must be non-NULL. + * @y: The y position will be stored here. Must be non-NULL. + * + * Checks if the specified file in the user's desktop directory has an icon position + * associated to it. If so, returns TRUE and fills in the x and y values. Otherwise + * it returns FALSE and x and y are not modified. + */ +int +meta_get_desktop_icon_pos (char *filename, int *x, int *y) +{ + int size; + char *buf; + int tx, ty; + + g_return_val_if_fail (filename != NULL, FALSE); + g_return_val_if_fail (x != NULL, FALSE); + g_return_val_if_fail (y != NULL, FALSE); + + if (gnome_metadata_get (filename, ICON_POSITION, &size, &buf) != 0) + return FALSE; + + if (!buf || (sscanf (buf, "%d%d", &tx, &ty) != 2)) { + g_warning ("Invalid metadata for \"%s\"'s icon position, using auto-placement", filename); + return FALSE; + } + + *x = tx; + *y = ty; + return TRUE; +} diff --git a/gnome/gmetadata.h b/gnome/gmetadata.h new file mode 100644 index 000000000..135539a21 --- /dev/null +++ b/gnome/gmetadata.h @@ -0,0 +1,21 @@ +/* Convenience functions for metadata handling in the MIdnight Commander + * + * Copyright (C) 1998 The Free Software Foundation + * + * Author: Federico Mena + */ + +#ifndef GMETADATA_H +#define GMETADATA_H + + +/* Returns the icon filename for the specified file. You must free the name. */ +char *meta_get_icon_for_file (char *filename); + +/* Returns the coordinates of the desktop icon corresponding to the specified file. If no position + * has been set, returns FALSE. Else it returns TRUE and sets the *x and *y values. + */ +int meta_get_desktop_icon_pos (char *filename, int *x, int *y); + + +#endif