Commit c85bb8ca authored by Andy Hertzfeld's avatar Andy Hertzfeld

made a new class, nautilus-index-title, to display the icon, title and


       made a new class, nautilus-index-title, to display the icon, title
       and other information for the index panel
parent a47e0099
2000-02-13 Andy Hertzfeld <andy@eazel.com>
made nautilus-index-title widget to hold the title information for the index panel
* src/ntl-index-panel.c:
allocated index-title to display info, removed old code that did it
* src/Makefile.am:
added nautilus-index-title.c and nautilus-index-title.h
* src/nautilus-index-title.c,h:
moved code from index-panel here to show icon and title
used nautilus_file and icon_factory to get the icon the real way
added more info besides the name (size, type and date)
2000-02-12 Andy Hertzfeld <andy@eazel.com>
* src/nautilus-index-tabs.c:
......@@ -5,7 +18,7 @@
tabs as fit in a row instead of a maximum of two. Tightened
up the layout and improved the drawing, too.
* src/ntl-index-panel.c:
right clicking on the tabs adds extra ones for testing purposes
right clicking on the tabs adds extra ones for testing purposes
2000-02-11 Andy Hertzfeld <andy@eazel.com>
......
......@@ -32,6 +32,8 @@ nautilus_SOURCES= \
nautilus-bookmarks-window.h \
nautilus-index-tabs.c \
nautilus-index-tabs.h \
nautilus-index-title.c \
nautilus-index-title.h \
nautilus-self-check-functions.c \
nautilus-self-check-functions.h \
nautilus-zoom-control.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* Nautilus
* Copyright (C) 2000 Eazel, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Andy Hertzfeld <andy@eazel.com>
*
* This is the index title widget, which is the title part of the index panel
*
*/
#include <config.h>
#include "ntl-meta-view.h"
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-directory.h>
#include <libnautilus/nautilus-glib-extensions.h>
#include <libnautilus/nautilus-icon-factory.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-metadata.h>
#include <libnautilus/nautilus-string.h>
#include <gnome.h>
#include <math.h>
#include "nautilus-index-title.h"
static void nautilus_index_title_class_initialize (NautilusIndexTitleClass *klass);
static void nautilus_index_title_finalize (GtkObject *object);
static void nautilus_index_title_initialize (NautilusIndexTitle *pixmap);
static gboolean nautilus_index_title_button_press_event(GtkWidget *widget, GdkEventButton *event);
GdkFont *select_font(const gchar *text_to_format, gint width, const gchar* font_template);
void set_up_font(GtkWidget *widget, GdkFont *font);
void nautilus_index_title_set_uri (NautilusIndexTitle *index_title, const gchar* new_uri);
void nautilus_index_title_set_up_icon (NautilusIndexTitle *index_title, NautilusFile *file_object);
void nautilus_index_title_set_up_label (NautilusIndexTitle *index_title, const gchar *uri);
void nautilus_index_title_set_up_info (NautilusIndexTitle *index_title, NautilusFile *file_object);
static GtkHBoxClass *parent_class;
struct _NautilusIndexTitleDetails
{
GtkWidget *icon;
GtkWidget *title;
GtkWidget *more_info;
};
/* button assignments */
GtkType
nautilus_index_title_get_type (void)
{
static GtkType index_title_type = 0;
if (!index_title_type)
{
static const GtkTypeInfo index_title_info =
{
"NautilusIndexTitle",
sizeof (NautilusIndexTitle),
sizeof (NautilusIndexTitleClass),
(GtkClassInitFunc) nautilus_index_title_class_initialize,
(GtkObjectInitFunc) nautilus_index_title_initialize,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
index_title_type = gtk_type_unique (gtk_vbox_get_type(), &index_title_info);
}
return index_title_type;
}
static void
nautilus_index_title_class_initialize (NautilusIndexTitleClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
object_class = (GtkObjectClass*) class;
widget_class = (GtkWidgetClass*) class;
parent_class = gtk_type_class (gtk_vbox_get_type ());
object_class->finalize = nautilus_index_title_finalize;
widget_class->button_press_event = nautilus_index_title_button_press_event;
}
static void
nautilus_index_title_initialize (NautilusIndexTitle *index_title)
{
index_title ->details = g_new0 (NautilusIndexTitleDetails, 1);
index_title->details->icon = NULL;
index_title->details->title = NULL;
index_title->details->more_info = NULL;
}
/* finalize by throwing away private storage */
static void
nautilus_index_title_finalize (GtkObject *object)
{
NautilusIndexTitle *index_title = NAUTILUS_INDEX_TITLE(object);
g_free(index_title->details);
(* GTK_OBJECT_CLASS (parent_class)->finalize) (object);
}
/* return a new index title object */
GtkWidget*
nautilus_index_title_new ()
{
NautilusIndexTitle *index_title = gtk_type_new (nautilus_index_title_get_type ());
return GTK_WIDGET (index_title);
}
/* set up the icon image */
void
nautilus_index_title_set_up_icon (NautilusIndexTitle *index_title, NautilusFile *file_object)
{
GdkPixmap *pixmap_for_dragged_file;
GdkBitmap *mask_for_dragged_file;
NautilusScalableIcon *icon = nautilus_icon_factory_get_icon_for_file(file_object);
GdkPixbuf *pixbuf = nautilus_icon_factory_get_pixbuf_for_icon(icon, NAUTILUS_ICON_SIZE_STANDARD);
/* set up the pixmap and mask of the new gtk_pixmap */
gdk_pixbuf_render_pixmap_and_mask (pixbuf, &pixmap_for_dragged_file,
&mask_for_dragged_file, 128);
/* if there's no pixmap so far, so allocate one */
if (index_title->details->icon)
gtk_pixmap_set(GTK_PIXMAP(index_title->details->icon), pixmap_for_dragged_file, mask_for_dragged_file);
else
{
index_title->details->icon = GTK_WIDGET (gtk_pixmap_new(pixmap_for_dragged_file, mask_for_dragged_file));
gtk_widget_show (index_title->details->icon);
gtk_box_pack_start (GTK_BOX (index_title), index_title->details->icon, 0, 0, 0);
}
/* we're done with the pixmap and icon */
gdk_pixbuf_unref(pixbuf);
nautilus_scalable_icon_unref (icon);
}
/* utility routine (FIXME: should be located elsewhere) to find the largest font that fits */
GdkFont *
select_font(const gchar *text_to_format, gint width, const gchar* font_template)
{
GdkFont *candidate_font = NULL;
gchar *font_name;
gint this_width;
gint font_sizes[5] = { 28, 24, 18, 14, 12 };
gint font_index;
for (font_index = 0; font_index < NAUTILUS_N_ELEMENTS (font_sizes); font_index++) {
if (candidate_font != NULL)
gdk_font_unref (candidate_font);
font_name = g_strdup_printf (font_template, font_sizes[font_index]);
candidate_font = gdk_font_load (font_name);
g_free (font_name);
this_width = gdk_string_width (candidate_font, text_to_format);
if (this_width < width)
return candidate_font;
}
return candidate_font;
}
/* utility to apply font */
void
set_up_font(GtkWidget *widget, GdkFont *font)
{
GtkStyle *temp_style;
gtk_widget_realize (widget);
temp_style = gtk_style_new ();
temp_style->font = font;
gtk_widget_set_style (widget, gtk_style_attach (temp_style, widget->window));
}
/* set up the label */
void
nautilus_index_title_set_up_label (NautilusIndexTitle *index_title, const gchar *uri)
{
GnomeVFSURI *vfs_uri;
gchar *file_name;
GdkFont *label_font;
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL)
return;
file_name = gnome_vfs_uri_extract_short_name (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
if (file_name == NULL)
return;
if (index_title->details->title)
gtk_label_set_text(GTK_LABEL(index_title->details->title), file_name);
else
{
index_title->details->title = GTK_WIDGET(gtk_label_new(file_name));
gtk_label_set_line_wrap(GTK_LABEL(index_title->details->title), TRUE);
gtk_widget_show (index_title->details->title);
gtk_box_pack_start (GTK_BOX (index_title), index_title->details->title, 0, 0, 0);
}
/* FIXME: don't use hardwired font like this */
label_font = select_font(file_name, GTK_WIDGET (index_title)->allocation.width - 4,
"-bitstream-courier-medium-r-normal-*-%d-*-*-*-*-*-*-*");
set_up_font(index_title->details->title, label_font);
g_free (file_name);
}
/* set up more info about the file */
void
nautilus_index_title_set_up_info (NautilusIndexTitle *index_title, NautilusFile *file_object)
{
GdkFont *label_font;
gchar *temp_string = NULL;
gchar *info_string = nautilus_file_get_string_attribute(file_object, "type");
if (info_string == NULL)
return;
temp_string = nautilus_file_get_string_attribute(file_object, "size");
if (temp_string != NULL)
{
gchar *new_info_string = g_strconcat(info_string, ", ", temp_string, NULL);
g_free(info_string);
g_free(temp_string);
info_string = new_info_string;
}
temp_string = nautilus_file_get_string_attribute(file_object, "date_modified");
if (temp_string != NULL)
{
gchar *new_info_string = g_strconcat(info_string, "\n", temp_string, NULL);
g_free(info_string);
g_free(temp_string);
info_string = new_info_string;
}
if (index_title->details->more_info)
gtk_label_set_text(GTK_LABEL(index_title->details->more_info), info_string);
else
{
index_title->details->more_info = GTK_WIDGET(gtk_label_new(info_string));
gtk_widget_show (index_title->details->more_info);
gtk_box_pack_start (GTK_BOX (index_title), index_title->details->more_info, 0, 0, 0);
}
/* FIXME: shouldn't use hardwired font */
label_font = gdk_font_load("-*-helvetica-medium-r-normal-*-12-*-*-*-*-*-*-*");
set_up_font(index_title->details->more_info, label_font);
g_free(info_string);
}
/* here's the place where we set everything up passed on the passed in uri */
void
nautilus_index_title_set_uri(NautilusIndexTitle *index_title, const gchar* new_uri)
{
NautilusFile *file_object = nautilus_file_get(new_uri);
/* For now, just use a fixed folder image */
nautilus_index_title_set_up_icon (index_title, file_object);
/* add the name, in a variable-sized label */
nautilus_index_title_set_up_label (index_title, new_uri);
/* add various info */
nautilus_index_title_set_up_info(index_title, file_object);
nautilus_file_unref(file_object);
}
/* handle a button press */
static gboolean
nautilus_index_title_button_press_event (GtkWidget *widget, GdkEventButton *event)
{
/*
NautilusIndexTitle *index_title = NAUTILUS_INDEX_TITLE (widget);
*/
printf("button press\n");
return TRUE;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* Nautilus
* Copyright (C) 2000 Eazel, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Andy Hertzfeld <andy@eazel.com>
*
* This is the header file for the index title panel, which is part of the index panel
*
*/
#ifndef __NAUTILUS_INDEX_TITLE_H__
#define __NAUTILUS_INDEX_TITLE_H__
#include <gdk/gdk.h>
#include <gtk/gtkvbox.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define NAUTILUS_TYPE_INDEX_TITLE (nautilus_index_title_get_type ())
#define NAUTILUS_INDEX_TITLE(obj) (GTK_CHECK_CAST ((obj), NAUTILUS_TYPE_INDEX_TITLE, NautilusIndexTitle))
#define NAUTILUS_INDEX_TITLE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), NAUTILUS_TYPE_INDEX_TITLE, NautilusIndexTitleClass))
#define NAUTILUS_IS_INDEX_TITLE(obj) (GTK_CHECK_TYPE ((obj), NAUTILUS_TYPE_INDEX_TITLE))
#define NAUTILUS_IS_INDEX_TITLE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), NAUTILUS_TYPE_INDEX_TITLE))
typedef struct _NautilusIndexTitle NautilusIndexTitle;
typedef struct _NautilusIndexTitleClass NautilusIndexTitleClass;
typedef struct _NautilusIndexTitleDetails NautilusIndexTitleDetails;
struct _NautilusIndexTitle
{
GtkVBox box;
NautilusIndexTitleDetails *details;
};
struct _NautilusIndexTitleClass
{
GtkVBoxClass parent_class;
};
GtkType nautilus_index_title_get_type (void);
GtkWidget* nautilus_index_title_new (void);
void nautilus_index_title_set_uri(NautilusIndexTitle *index_title, const gchar* new_uri);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __NAUTILUS_INDEX_TITLE_H__ */
......@@ -29,6 +29,8 @@
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-directory.h>
......@@ -41,7 +43,7 @@
struct _NautilusIndexPanelDetails {
GtkWidget *index_container;
GtkWidget *per_uri_container;
GtkWidget *index_title;
GtkWidget *notebook;
GtkWidget *index_tabs;
GtkWidget *title_tab;
......@@ -63,10 +65,6 @@ static void nautilus_index_panel_drag_data_received (GtkWidget *widget, GdkDragC
guint info, guint time);
static void nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar* new_uri);
static void nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar *uri);
static void nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path);
static GdkFont *select_font(const gchar *text_to_format, gint width, const gchar* font_template);
#define DEFAULT_BACKGROUND_COLOR "rgb:DDDD/DDDD/FFFF"
#define INDEX_PANEL_WIDTH 136
......@@ -102,17 +100,6 @@ nautilus_index_panel_initialize_class (GtkObjectClass *object_klass)
widget_class->button_press_event = nautilus_index_panel_press_event;
}
/* common routine to make the per-uri container */
static void make_per_uri_container(NautilusIndexPanel *index_panel)
{
index_panel->details->per_uri_container = gtk_vbox_new (FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (index_panel->details->per_uri_container), 0);
gtk_widget_show (index_panel->details->per_uri_container);
gtk_box_pack_start (GTK_BOX (index_panel->details->index_container),
index_panel->details->per_uri_container, FALSE, FALSE, 0);
}
/* initialize the instance's fields, create the necessary subviews, etc. */
static void
......@@ -135,9 +122,12 @@ nautilus_index_panel_initialize (GtkObject *object)
gtk_widget_show (index_panel->details->index_container);
gtk_container_add (GTK_CONTAINER (index_panel), index_panel->details->index_container);
/* allocate and install the vbox to hold the per-uri information */
make_per_uri_container (index_panel);
/* allocate and install the index title widget */
index_panel->details->index_title = nautilus_index_title_new();
gtk_widget_show(index_panel->details->index_title);
gtk_box_pack_start (GTK_BOX (index_panel->details->index_container),
index_panel->details->index_title, FALSE, FALSE, 0);
/* first, allocate the index tabs */
index_panel->details->index_tabs = GTK_WIDGET(nautilus_index_tabs_new());
index_panel->details->selected_index = -1;
......@@ -320,7 +310,7 @@ nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
NautilusIndexTabs *title_tab = NAUTILUS_INDEX_TABS(index_panel->details->title_tab);
gint rounded_y = floor(event->y + .5);
/* test code: create some more tabs if the right button is down */
/* FIXME: test code, will remove soon: create some more tabs if the right button is down */
if (event->button == 3)
{
......@@ -362,85 +352,6 @@ nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
return TRUE;
}
/* set up the logo image */
void
nautilus_index_panel_set_up_logo (NautilusIndexPanel *index_panel, const gchar *logo_path)
{
gchar *file_name;
GtkWidget *pix_widget;
file_name = gnome_pixmap_file (logo_path);
pix_widget = GTK_WIDGET (gnome_pixmap_new_from_file (file_name));
gtk_widget_show (pix_widget);
gtk_box_pack_start (GTK_BOX (index_panel->details->per_uri_container), pix_widget, 0, 0, 0);
g_free (file_name);
}
/* utility routine (FIXME: should be located elsewhere) to find the largest font that fits */
GdkFont *
select_font(const gchar *text_to_format, gint width, const gchar* font_template)
{
GdkFont *candidate_font = NULL;
gchar *font_name;
gint this_width;
gint font_sizes[8] = { 28, 24, 18, 14, 12, 10, 8 };
gint font_index;
for (font_index = 0; font_index < NAUTILUS_N_ELEMENTS (font_sizes); font_index++) {
if (candidate_font != NULL)
gdk_font_unref (candidate_font);
font_name = g_strdup_printf (font_template, font_sizes[font_index]);
candidate_font = gdk_font_load (font_name);
g_free (font_name);
this_width = gdk_string_width (candidate_font, text_to_format);
if (this_width < width)
return candidate_font;
}
return candidate_font;
}
/* set up the label */
void
nautilus_index_panel_set_up_label (NautilusIndexPanel *index_panel, const gchar *uri)
{
GnomeVFSURI *vfs_uri;
GtkWidget *label_widget;
char *file_name;
GdkFont *label_font;
vfs_uri = gnome_vfs_uri_new (uri);
if (vfs_uri == NULL)
return;
file_name = gnome_vfs_uri_extract_short_name (vfs_uri);
gnome_vfs_uri_unref (vfs_uri);
if (file_name == NULL)
return;
label_widget = gtk_label_new (file_name);
gtk_box_pack_start (GTK_BOX (index_panel->details->per_uri_container), label_widget, 0, 0, 0);
label_font = select_font(file_name, GTK_WIDGET (index_panel)->allocation.width - 4,
"-bitstream-courier-medium-r-normal-*-%d-*-*-*-*-*-*-*");
if (label_font != NULL) {
GtkStyle *temp_style;
gtk_widget_realize (label_widget);
temp_style = gtk_style_new ();
temp_style->font = label_font;
gtk_widget_set_style (label_widget, gtk_style_attach (temp_style, label_widget->window));
}
gtk_widget_show(label_widget);
g_free (file_name);
}
static void
nautilus_index_panel_background_changed (NautilusIndexPanel *index_panel)
......@@ -489,14 +400,9 @@ nautilus_index_panel_set_up_info (NautilusIndexPanel *index_panel, const gchar*
nautilus_background_set_color (background, background_color);
g_free (background_color);
/* next, install the logo image. */
/* For now, just use a fixed folder image */
nautilus_index_panel_set_up_logo (index_panel, "nautilus/i-directory.png");
/* add the name, discarding all but the last part of the path */
/* soon, we'll use the biggest font that fit, for now don't worry about it */
nautilus_index_panel_set_up_label (index_panel, new_uri);
/* tell the title widget about it */
nautilus_index_title_set_uri(NAUTILUS_INDEX_TITLE(index_panel->details->index_title), new_uri);
/* format and install the type-dependent descriptive info */
/* add the description text, if any. Try to fetch it from the notes file if none is present */
......@@ -516,11 +422,7 @@ nautilus_index_panel_set_uri (NautilusIndexPanel *index_panel, const gchar* new_
g_free (index_panel->details->uri);
index_panel->details->uri = g_strdup (new_uri);
/* get rid of the old widgets in the per_uri container */
gtk_widget_destroy (index_panel->details->per_uri_container);
make_per_uri_container (index_panel);
/* populate the per-uri box with the info */
nautilus_index_panel_set_up_info (index_panel, new_uri);
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* Nautilus
* Copyright (C) 2000 Eazel, Inc.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: Andy Hertzfeld <andy@eazel.com>
*
* This is the index title widget, which is the title part of the index panel
*
*/
#include <config.h>
#include "ntl-meta-view.h"
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
#include <libnautilus/nautilus-directory.h>
#include <libnautilus/nautilus-glib-extensions.h>
#include <libnautilus/nautilus-icon-factory.h>
#include <libnautilus/nautilus-gtk-macros.h>
#include <libnautilus/nautilus-metadata.h>
#include <libnautilus/nautilus-string.h>
#include <gnome.h>
#include <math.h>