Commit 1fd49af1 authored by Andy Hertzfeld's avatar Andy Hertzfeld

implemented command buttons based on mime-types in the index panel


       implemented command buttons based on mime-types in the index panel
parent 3bce71a5
2000-02-17 Andy Hertzfeld <andy@eazel.com>
implemented command buttons for the index panel.
* libnautilus/nautilus-mime-type.c,h:
this is interim code for associating applications with mime-types; we
will eventually keep this in OAF or GConf or at least in a file
somewhere, but for now it's just scaffolding so we can work on the UI
* libnautilus/Makefile.am:
make nautilus-mime-type.c,h build
* stc/ntl-index-panel.c:
added code to call nautilus-mime-types to get relevant commands based
on the mime-type, and then generate corresponding buttons in the index
panel
2000-02-17 Darin Adler <darin@eazel.com>
Hand tuned icons for multiple resolutions.
......
......@@ -45,6 +45,7 @@ libnautilusinclude_HEADERS= \
nautilus-icons-view-icon-item.h \
nautilus-lib-self-check-functions.h \
nautilus-metadata.h \
nautilus-mime-type.h \
nautilus-self-checks.h \
nautilus-string.h \
ntl-content-view-frame.h \
......@@ -72,6 +73,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
nautilus-icons-controller.c \
nautilus-icons-view-icon-item.c \
nautilus-lib-self-check-functions.c \
nautilus-mime-type.c \
nautilus-self-checks.c \
nautilus-string.c \
ntl-content-view-frame.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Here are the routines that return applications that are relevant to a given MIME-type.
For now, the info is kept in a statically defined string table, but it eventually has to
be editable and augmentable. We'll probably use OAF or GConf for this, but at least this
lets us get going with the UI for now.
Author: Andy Hertzfeld <andy@eazel.com>
*/
#include <string.h>
#include <stdio.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-mime-type.h"
typedef struct {
gchar *base_type;
gchar *sub_type;
gchar *display_name;
gchar *command_string;
} MimeTypeItem;
/* here is the string table associating mime types with commands */
/* FIXME: this should be kept in a file somewhere, possibly using GConf or OAF */
static MimeTypeItem mime_type_table [] = {
{ "text", "*", "Edit with gEdit", "gedit %s" },
{ "text", "html", "View with Netscape", "netscape %s" },
{ "image", "*", "Edit with GIMP", "gimp %s" },
{ "text", "plain", "Edit with gnotepad", "gnp %s" }
};
/* release the storage contained in the passed-in command list */
void nautilus_mime_type_dispose_list (GList *command_list)
{
GList *next_command;
for (next_command = command_list; next_command != NULL; next_command = next_command->next)
{
NautilusCommandInfo *item = (NautilusCommandInfo *) next_command->data;
g_free(item->display_name);
g_free(item->command_string);
g_free(item);
}
g_list_free (command_list);
}
/* return a list of commands corresponding to the passed in mime-type, by iterating
through the table */
GList* nautilus_mime_type_get_commands (const gchar *mime_type)
{
gint index;
gchar *slash_pos, *temp_str;
gchar *target_base_type, *target_sub_type;
NautilusCommandInfo *new_command_item;
GList *command_list = NULL;
/* parse the mime type into a base type and a sub type */
temp_str = strdup(mime_type);
target_base_type = temp_str;
slash_pos = strchr(temp_str, '/');
if (slash_pos)
{
*slash_pos = '\0';
target_sub_type = slash_pos + 1;
}
else
target_sub_type = NULL;
/* iterate through the table, creating a new command info node for each mime type that matches */
for (index = 0; index < NAUTILUS_N_ELEMENTS(mime_type_table); index++)
{
/* see if the types match */
if (strcmp(mime_type_table[index].base_type, target_base_type) == 0)
{
gchar *cur_sub_type = mime_type_table[index].sub_type;
if ((target_sub_type == NULL) || (strcmp(cur_sub_type, target_sub_type) == 0) || (strcmp(cur_sub_type, "*") == 0))
{
/* the types match, so allocate a command entry */
new_command_item = g_new0 (NautilusCommandInfo, 1);
/* add it to the list */
if (command_list != NULL)
command_list = g_list_append(command_list, new_command_item);
else
{
command_list = g_list_alloc();
command_list->data = new_command_item;
}
new_command_item->display_name = strdup(mime_type_table[index].display_name);
new_command_item->command_string = strdup(mime_type_table[index].command_string);
}
}
}
g_free(temp_str);
return command_list;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. 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>
*/
#ifndef NAUTILUS_MIME_TYPE_H
#define NAUTILUS_MIME_TYPE_H
typedef struct _NautilusCommandInfo NautilusCommandInfo;
struct _NautilusCommandInfo {
gchar *display_name;
gchar *command_string;
};
GList* nautilus_mime_type_get_commands (const gchar *mime_type);
void nautilus_mime_type_dispose_list (GList *command_list);
#endif /* NAUTILUS_MIME_TYPE_H */
......@@ -45,6 +45,7 @@ libnautilusinclude_HEADERS= \
nautilus-icons-view-icon-item.h \
nautilus-lib-self-check-functions.h \
nautilus-metadata.h \
nautilus-mime-type.h \
nautilus-self-checks.h \
nautilus-string.h \
ntl-content-view-frame.h \
......@@ -72,6 +73,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
nautilus-icons-controller.c \
nautilus-icons-view-icon-item.c \
nautilus-lib-self-check-functions.c \
nautilus-mime-type.c \
nautilus-self-checks.c \
nautilus-string.c \
ntl-content-view-frame.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Here are the routines that return applications that are relevant to a given MIME-type.
For now, the info is kept in a statically defined string table, but it eventually has to
be editable and augmentable. We'll probably use OAF or GConf for this, but at least this
lets us get going with the UI for now.
Author: Andy Hertzfeld <andy@eazel.com>
*/
#include <string.h>
#include <stdio.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-mime-type.h"
typedef struct {
gchar *base_type;
gchar *sub_type;
gchar *display_name;
gchar *command_string;
} MimeTypeItem;
/* here is the string table associating mime types with commands */
/* FIXME: this should be kept in a file somewhere, possibly using GConf or OAF */
static MimeTypeItem mime_type_table [] = {
{ "text", "*", "Edit with gEdit", "gedit %s" },
{ "text", "html", "View with Netscape", "netscape %s" },
{ "image", "*", "Edit with GIMP", "gimp %s" },
{ "text", "plain", "Edit with gnotepad", "gnp %s" }
};
/* release the storage contained in the passed-in command list */
void nautilus_mime_type_dispose_list (GList *command_list)
{
GList *next_command;
for (next_command = command_list; next_command != NULL; next_command = next_command->next)
{
NautilusCommandInfo *item = (NautilusCommandInfo *) next_command->data;
g_free(item->display_name);
g_free(item->command_string);
g_free(item);
}
g_list_free (command_list);
}
/* return a list of commands corresponding to the passed in mime-type, by iterating
through the table */
GList* nautilus_mime_type_get_commands (const gchar *mime_type)
{
gint index;
gchar *slash_pos, *temp_str;
gchar *target_base_type, *target_sub_type;
NautilusCommandInfo *new_command_item;
GList *command_list = NULL;
/* parse the mime type into a base type and a sub type */
temp_str = strdup(mime_type);
target_base_type = temp_str;
slash_pos = strchr(temp_str, '/');
if (slash_pos)
{
*slash_pos = '\0';
target_sub_type = slash_pos + 1;
}
else
target_sub_type = NULL;
/* iterate through the table, creating a new command info node for each mime type that matches */
for (index = 0; index < NAUTILUS_N_ELEMENTS(mime_type_table); index++)
{
/* see if the types match */
if (strcmp(mime_type_table[index].base_type, target_base_type) == 0)
{
gchar *cur_sub_type = mime_type_table[index].sub_type;
if ((target_sub_type == NULL) || (strcmp(cur_sub_type, target_sub_type) == 0) || (strcmp(cur_sub_type, "*") == 0))
{
/* the types match, so allocate a command entry */
new_command_item = g_new0 (NautilusCommandInfo, 1);
/* add it to the list */
if (command_list != NULL)
command_list = g_list_append(command_list, new_command_item);
else
{
command_list = g_list_alloc();
command_list->data = new_command_item;
}
new_command_item->display_name = strdup(mime_type_table[index].display_name);
new_command_item->command_string = strdup(mime_type_table[index].command_string);
}
}
}
g_free(temp_str);
return command_list;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. 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>
*/
#ifndef NAUTILUS_MIME_TYPE_H
#define NAUTILUS_MIME_TYPE_H
typedef struct _NautilusCommandInfo NautilusCommandInfo;
struct _NautilusCommandInfo {
gchar *display_name;
gchar *command_string;
};
GList* nautilus_mime_type_get_commands (const gchar *mime_type);
void nautilus_mime_type_dispose_list (GList *command_list);
#endif /* NAUTILUS_MIME_TYPE_H */
......@@ -45,6 +45,7 @@ libnautilusinclude_HEADERS= \
nautilus-icons-view-icon-item.h \
nautilus-lib-self-check-functions.h \
nautilus-metadata.h \
nautilus-mime-type.h \
nautilus-self-checks.h \
nautilus-string.h \
ntl-content-view-frame.h \
......@@ -72,6 +73,7 @@ libnautilus_la_SOURCES=$(nautilus_idl_sources) \
nautilus-icons-controller.c \
nautilus-icons-view-icon-item.c \
nautilus-lib-self-check-functions.c \
nautilus-mime-type.c \
nautilus-self-checks.c \
nautilus-string.c \
ntl-content-view-frame.c \
......
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. If not,
write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
Boston, MA 02111-1307, USA.
Here are the routines that return applications that are relevant to a given MIME-type.
For now, the info is kept in a statically defined string table, but it eventually has to
be editable and augmentable. We'll probably use OAF or GConf for this, but at least this
lets us get going with the UI for now.
Author: Andy Hertzfeld <andy@eazel.com>
*/
#include <string.h>
#include <stdio.h>
#include "nautilus-glib-extensions.h"
#include "nautilus-mime-type.h"
typedef struct {
gchar *base_type;
gchar *sub_type;
gchar *display_name;
gchar *command_string;
} MimeTypeItem;
/* here is the string table associating mime types with commands */
/* FIXME: this should be kept in a file somewhere, possibly using GConf or OAF */
static MimeTypeItem mime_type_table [] = {
{ "text", "*", "Edit with gEdit", "gedit %s" },
{ "text", "html", "View with Netscape", "netscape %s" },
{ "image", "*", "Edit with GIMP", "gimp %s" },
{ "text", "plain", "Edit with gnotepad", "gnp %s" }
};
/* release the storage contained in the passed-in command list */
void nautilus_mime_type_dispose_list (GList *command_list)
{
GList *next_command;
for (next_command = command_list; next_command != NULL; next_command = next_command->next)
{
NautilusCommandInfo *item = (NautilusCommandInfo *) next_command->data;
g_free(item->display_name);
g_free(item->command_string);
g_free(item);
}
g_list_free (command_list);
}
/* return a list of commands corresponding to the passed in mime-type, by iterating
through the table */
GList* nautilus_mime_type_get_commands (const gchar *mime_type)
{
gint index;
gchar *slash_pos, *temp_str;
gchar *target_base_type, *target_sub_type;
NautilusCommandInfo *new_command_item;
GList *command_list = NULL;
/* parse the mime type into a base type and a sub type */
temp_str = strdup(mime_type);
target_base_type = temp_str;
slash_pos = strchr(temp_str, '/');
if (slash_pos)
{
*slash_pos = '\0';
target_sub_type = slash_pos + 1;
}
else
target_sub_type = NULL;
/* iterate through the table, creating a new command info node for each mime type that matches */
for (index = 0; index < NAUTILUS_N_ELEMENTS(mime_type_table); index++)
{
/* see if the types match */
if (strcmp(mime_type_table[index].base_type, target_base_type) == 0)
{
gchar *cur_sub_type = mime_type_table[index].sub_type;
if ((target_sub_type == NULL) || (strcmp(cur_sub_type, target_sub_type) == 0) || (strcmp(cur_sub_type, "*") == 0))
{
/* the types match, so allocate a command entry */
new_command_item = g_new0 (NautilusCommandInfo, 1);
/* add it to the list */
if (command_list != NULL)
command_list = g_list_append(command_list, new_command_item);
else
{
command_list = g_list_alloc();
command_list->data = new_command_item;
}
new_command_item->display_name = strdup(mime_type_table[index].display_name);
new_command_item->command_string = strdup(mime_type_table[index].command_string);
}
}
}
g_free(temp_str);
return command_list;
}
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/*
Copyright (C) 2000 Eazel, Inc.
The Gnome Library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public License as
published by the Free Software Foundation; either version 2 of the
License, or (at your option) any later version.
The Gnome Library 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
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with the Gnome Library; see the file COPYING.LIB. 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>
*/
#ifndef NAUTILUS_MIME_TYPE_H
#define NAUTILUS_MIME_TYPE_H
typedef struct _NautilusCommandInfo NautilusCommandInfo;
struct _NautilusCommandInfo {
gchar *display_name;
gchar *command_string;
};
GList* nautilus_mime_type_get_commands (const gchar *mime_type);
void nautilus_mime_type_dispose_list (GList *command_list);
#endif /* NAUTILUS_MIME_TYPE_H */
......@@ -32,6 +32,7 @@
#include "ntl-meta-view.h"
#include "nautilus-index-tabs.h"
#include "nautilus-index-title.h"
#include "libnautilus/nautilus-mime-type.h"
#include <libgnomevfs/gnome-vfs-uri.h>
#include <libnautilus/nautilus-background.h>
......@@ -48,6 +49,8 @@ struct _NautilusIndexPanelDetails {
GtkWidget *notebook;
GtkWidget *index_tabs;
GtkWidget *title_tab;
GtkWidget *button_box;
gboolean has_buttons;
char *uri;
gint selected_index;
NautilusDirectory *directory;
......@@ -66,6 +69,8 @@ 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 char* new_uri);
static void nautilus_index_panel_set_up_buttons (NautilusIndexPanel *index_panel, const char* new_uri);
static void add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list);
#define DEFAULT_BACKGROUND_COLOR "rgb:DDDD/DDDD/FFFF"
#define INDEX_PANEL_WIDTH 136
......@@ -103,6 +108,17 @@ nautilus_index_panel_initialize_class (GtkObjectClass *object_klass)
widget_class->button_press_event = nautilus_index_panel_press_event;
}
/* utility routine to allocate the box the holds the command buttons */
static void
make_button_box(NautilusIndexPanel *index_panel)
{
index_panel->details->button_box = gtk_vbox_new(FALSE, 0);
gtk_container_set_border_width (GTK_CONTAINER (index_panel->details->button_box), 8);
gtk_widget_show (index_panel->details->button_box);
gtk_container_add (GTK_CONTAINER (index_panel->details->index_container), index_panel->details->button_box);
index_panel->details->has_buttons = FALSE;
}
/* initialize the instance's fields, create the necessary subviews, etc. */
static void
......@@ -150,7 +166,10 @@ nautilus_index_panel_initialize (GtkObject *object)
gtk_widget_set_usize (index_panel->details->notebook, INDEX_PANEL_WIDTH, 200);
gtk_notebook_set_show_tabs(GTK_NOTEBOOK(index_panel->details->notebook), FALSE);
/* allocate and install the command button container */
make_button_box(index_panel);
/* prepare ourselves to receive dropped objects */
gtk_drag_dest_set (GTK_WIDGET (index_panel),
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
......@@ -289,6 +308,9 @@ nautilus_index_panel_activate_meta_view(NautilusIndexPanel *index_panel, gint wh
nautilus_index_tabs_set_title(NAUTILUS_INDEX_TABS(index_panel->details->title_tab), title);
g_free(title);
/* hide the buttons, since they look confusing when partially overlapped */
gtk_widget_hide(index_panel->details->button_box);
gtk_notebook_set_page(notebook, which_view);
}
......@@ -301,6 +323,7 @@ nautilus_index_panel_deactivate_meta_view(NautilusIndexPanel *index_panel)
gtk_widget_hide (index_panel->details->title_tab);
}
gtk_widget_show(index_panel->details->button_box);
index_panel->details->selected_index = -1;
nautilus_index_tabs_select_tab(NAUTILUS_INDEX_TABS(index_panel->details->index_tabs), -1);
}
......@@ -342,7 +365,6 @@ nautilus_index_panel_press_event (GtkWidget *widget, GdkEventButton *event)
return TRUE;
}
static void
nautilus_index_panel_background_changed (NautilusIndexPanel *index_panel)
{
......@@ -361,6 +383,94 @@ nautilus_index_panel_background_changed (NautilusIndexPanel *index_panel)
g_free (color_spec);
}
/* FIXME: I'm sure there's a better way to do this */
/* utility to actually execute the button command */
static void
command_button_cb(GtkMenuItem *item, gchar* command_str)
{
gint result;
pid_t button_pid;
if (!(button_pid = fork())) {
result = system(command_str);
exit(0);
}
}
/* utility routine that allocates the command buttons from the command list */
static void
add_command_buttons(NautilusIndexPanel *index_panel, GList *command_list)
{
gchar *command_string, *temp_str;
GList *this_item = command_list;
GtkWidget *temp_button, *temp_label;
while (this_item != NULL)
{
NautilusCommandInfo *info = (NautilusCommandInfo*) this_item->data;
index_panel->details->has_buttons = TRUE;
temp_button = gtk_button_new();
temp_label = gtk_label_new(info->display_name);
gtk_widget_show(temp_label);
gtk_container_add(GTK_CONTAINER(temp_button), temp_label);
gtk_box_pack_start(GTK_BOX(index_panel->details->button_box), temp_button, FALSE, TRUE, 2);
gtk_button_set_relief(GTK_BUTTON(temp_button), GTK_RELIEF_NORMAL);
gtk_widget_set_usize(GTK_WIDGET(temp_button), 80, 20);
/* FIXME: we must quote the uri in case it has blanks */
if (nautilus_has_prefix(index_panel->details->uri, "file://"))
temp_str = index_panel->details->uri + 7;
else
temp_str = index_panel->details->uri;
command_string = g_strdup_printf(info->command_string, temp_str);
gtk_signal_connect(GTK_OBJECT (temp_button), "clicked", GTK_SIGNAL_FUNC (command_button_cb), command_string);
gtk_widget_show(temp_button);
this_item = this_item->next;
}
}
/* here's where we set up the command buttons, based on the mime-type of the associated URL */
/* FIXME: eventually, we need a way to override/augment the type from info in the metadata */
void
nautilus_index_panel_set_up_buttons (NautilusIndexPanel *index_panel, const char* new_uri)
{
NautilusFile *file_object;
GList *command_list;
/* dispose any existing buttons */
if (index_panel->details->has_buttons) {
gtk_widget_destroy(index_panel->details->button_box);
make_button_box(index_panel);
}
/* allocate a file object and fetch the associated mime-type */
file_object = nautilus_file_get(new_uri);
if (file_object) {
const gchar* mime_type = nautilus_file_get_mime_type(file_object);
/* generate a command list from the mime-type */
if (mime_type) {