Sync to laptop; I ifdef-ed the old code just so that it will compile - Federico

This commit is contained in:
Miguel de Icaza 1998-10-30 00:47:54 +00:00
parent 612019d206
commit 903eb5a880
7 changed files with 337 additions and 9 deletions

View File

@ -1,3 +1,10 @@
1998-10-29 Federico Mena Quintero <federico@nuclecu.unam.mx>
* 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 <federico@nuclecu.unam.mx>
* gdesktop-icon.c (create_window_shape): Use shaped icons only

View File

@ -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 \

View File

@ -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 */

View File

@ -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 <federico@nuclecu.unam.mx>
* Miguel de Icaza <miguel@nuclecu.unam.mx>
*/
#if 0
#include <config.h>
#include <gnome.h>
#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 <config.h>
#include <gnome.h>
#include "gdesktop-icon.h"
@ -1485,3 +1650,5 @@ stop_desktop (void)
}
image_cache_destroy ();
}
#endif

View File

@ -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 <federico@nuclecu.unam.mx>
* Miguel de Icaza <miguel@nuclecu.unam.mx>
*/
#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

84
gnome/gmetadata.c Normal file
View File

@ -0,0 +1,84 @@
/* Convenience functions for metadata handling in the MIdnight Commander
*
* Copyright (C) 1998 The Free Software Foundation
*
* Author: Federico Mena <federico@nuclecu.unam.mx>
*/
#include <config.h>
#include <sys/stat.h>
#include <libgnome/libgnome.h>
#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;
}

21
gnome/gmetadata.h Normal file
View File

@ -0,0 +1,21 @@
/* Convenience functions for metadata handling in the MIdnight Commander
*
* Copyright (C) 1998 The Free Software Foundation
*
* Author: Federico Mena <federico@nuclecu.unam.mx>
*/
#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