diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | capplets/Makefile.am | 1 | ||||
-rw-r--r-- | capplets/mime-type/Makefile.am | 23 | ||||
-rw-r--r-- | capplets/mime-type/edit-window.c | 23 | ||||
-rw-r--r-- | capplets/mime-type/edit-window.h | 12 | ||||
-rw-r--r-- | capplets/mime-type/mime-data.c | 283 | ||||
-rw-r--r-- | capplets/mime-type/mime-data.h | 22 | ||||
-rw-r--r-- | capplets/mime-type/mime-type-capplet.c | 101 | ||||
-rw-r--r-- | configure.in | 1 | ||||
-rw-r--r-- | po/no.po | 28 |
10 files changed, 487 insertions, 12 deletions
@@ -1,3 +1,8 @@ +1999-03-10 Jonathan Blandford <jrb@redhat.com> + + * capplets/Makefile.am (always_built_SUBDIRS): mime-type capplet. + New capplet added. + 1999-03-10 Chris Lahey <clahey@umich.edu> * capplets/gnome-edit-properties/gnome-edit-properties.c: Updated diff --git a/capplets/Makefile.am b/capplets/Makefile.am index 171363d91..9dfad87b7 100644 --- a/capplets/Makefile.am +++ b/capplets/Makefile.am @@ -3,6 +3,7 @@ always_built_SUBDIRS = desktop-links mouse-properties \ theme-switcher sound-properties bell-properties \ ui-properties url-properties gnome-edit-properties \ session-properties wm-properties keyboard-properties +# mime-type SUBDIRS = $(always_built_SUBDIRS) diff --git a/capplets/mime-type/Makefile.am b/capplets/mime-type/Makefile.am new file mode 100644 index 000000000..8594251b3 --- /dev/null +++ b/capplets/mime-type/Makefile.am @@ -0,0 +1,23 @@ +INCLUDES = -I. -I$(srcdir) \ + -I$(top_srcdir)/intl -I$(top_builddir)/intl \ + -I$(srcdir)/../../control-center \ + -DGNOMELOCALEDIR=\""$(datadir)/locale"\" \ + -I$(includedir) $(GNOME_INCLUDEDIR) + +bin_PROGRAMS = mime-type-capplet + +mime_type_capplet_SOURCES = mime-type-capplet.c mime-data.c edit-window.c + +mime_type_capplet_LDADD = ../../control-center/libcapplet.la \ + $(GNOME_LIBDIR) $(ORB_LIBS) \ + $(GNOMEUI_LIBS) $(INTLLIBS) -lgnorba + +EXTRA_DIST = \ + mime-type.desktop + + +sysdir = $(datadir)/control-center +sys_DATA = mime-type.desktop + +install-data-local: + $(INSTALL_DATA) $(srcdir)/mime-type.desktop $(datadir)/gnome/apps/Settings/mime-type.desktop diff --git a/capplets/mime-type/edit-window.c b/capplets/mime-type/edit-window.c new file mode 100644 index 000000000..1a26bba6b --- /dev/null +++ b/capplets/mime-type/edit-window.c @@ -0,0 +1,23 @@ +#include "edit-window.h" +typedef struct { + GtkWidget *window; +} edit_window; +static edit_window *main_win = NULL; + +static void +initialize_main_win () +{ + main_win = g_new (edit_window, 1); + main_win->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + +} + + +void +launch_edit_window (MimeInfo *mi) +{ + if (main_win == NULL) + initialize_main_win (); + gtk_widget_show_all (main_win->window); +} + diff --git a/capplets/mime-type/edit-window.h b/capplets/mime-type/edit-window.h new file mode 100644 index 000000000..4c6d918b6 --- /dev/null +++ b/capplets/mime-type/edit-window.h @@ -0,0 +1,12 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/* Copyright (C) 1998 Redhat Software Inc. + * Authors: Jonathan Blandford <jrb@redhat.com> + */ +#ifndef _EDIT_WINDOW_H_ +#define _EDIT_WINDOW_H_ + +#include "mime-data.h" + +void launch_edit_window (MimeInfo *mi); + +#endif diff --git a/capplets/mime-type/mime-data.c b/capplets/mime-type/mime-data.c new file mode 100644 index 000000000..bbac7fdb7 --- /dev/null +++ b/capplets/mime-type/mime-data.c @@ -0,0 +1,283 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/* Copyright (C) 1998 Redhat Software Inc. + * Authors: Jonathan Blandford <jrb@redhat.com> + */ +#include <config.h> +#include "capplet-widget.h" +#include "gnome.h" +#include <string.h> +#include <sys/types.h> +#include <dirent.h> +#include <regex.h> +#include <ctype.h> +#include "mime-data.h" +/* Prototypes */ +static void mime_fill_from_file (const char *filename); +static void mime_load_from_dir (const char *mime_info_dir); +static void add_to_key (char *mime_type, char *def); +static char *get_priority (char *def, int *priority); + + +/* Global variables */ +static char *current_lang; + /* Our original purpose for having + * the hash table seems to have dissappeared. + * Oh well... must-fix-later */ +static GHashTable *mime_types = NULL; + +/* Initialization functions */ +static char * +get_priority (char *def, int *priority) +{ + *priority = 0; + + if (*def == ','){ + def++; + if (*def == '1'){ + *priority = 0; + def++; + } else if (*def == '2'){ + *priority = 1; + def++; + } + } + + while (*def && *def == ':') + def++; + + return def; +} +static void +add_to_key (char *mime_type, char *def) +{ + int priority = 1; + char *s, *p, *ext; + int used; + MimeInfo *info; + + info = g_hash_table_lookup (mime_types, (const void *) mime_type); + if (info == NULL) { + info = g_malloc (sizeof (MimeInfo)); + info->mime_type = g_strdup (mime_type); + info->regex[0] = NULL; + info->regex[1] = NULL; + info->ext[0] = NULL; + info->ext[1] = NULL; + info->keys = gnome_mime_get_keys (mime_type); + g_hash_table_insert (mime_types, mime_type, info); + } + if (strncmp (def, "ext", 3) == 0){ + char *tokp; + + def += 3; + def = get_priority (def, &priority); + s = p = g_strdup (def); + + used = 0; + + while ((ext = strtok_r (s, " \t\n\r,", &tokp)) != NULL){ + info->ext[priority] = g_list_prepend (info->ext[priority], ext); + g_print ("inserting:%s:\n", ext); + used = 1; + s = NULL; + } + if (!used) + g_free (p); + } + + if (strncmp (def, "regex", 5) == 0){ + regex_t *regex; + + regex = g_new (regex_t, 1); + def += 5; + def = get_priority (def, &priority); + + while (*def && isspace (*def)) + def++; + + if (!*def) + return; + if (regcomp (regex, def, REG_EXTENDED | REG_NOSUB)) + g_free (regex); + else + info->regex[priority] = regex; + } +} +static void +mime_fill_from_file (const char *filename) +{ + FILE *f; + char buf [1024]; + char *current_key; + gboolean used; + + g_assert (filename != NULL); + + f = fopen (filename, "r"); + if (!f) + return; + + current_key = NULL; + used = FALSE; + while (fgets (buf, sizeof (buf), f)){ + char *p; + + if (buf [0] == '#') + continue; + + /* Trim trailing spaces */ + for (p = buf + strlen (buf) - 1; p >= buf; p--){ + if (isspace (*p) || *p == '\n') + *p = 0; + else + break; + } + + if (!buf [0]) + continue; + + if (buf [0] == '\t' || buf [0] == ' '){ + if (current_key){ + char *p = buf; + + while (*p && isspace (*p)) + p++; + + if (*p == 0) + continue; + + add_to_key (current_key, p); + used = TRUE; + } + } else { + if (!used && current_key) + g_free (current_key); + current_key = g_strdup (buf); + if (current_key [strlen (current_key)-1] == ':') + current_key [strlen (current_key)-1] = 0; + + used = FALSE; + } + } + fclose (f); +} + +static void +mime_load_from_dir (const char *mime_info_dir) +{ + DIR *dir; + struct dirent *dent; + const int extlen = sizeof (".mime") - 1; + + dir = opendir (mime_info_dir); + if (!dir) + return; + + while ((dent = readdir (dir)) != NULL){ + char *filename; + + int len = strlen (dent->d_name); + + if (len <= extlen) + continue; + + if (strcmp (dent->d_name + len - extlen, ".mime")) + continue; + + filename = g_concat_dir_and_file (mime_info_dir, dent->d_name); + mime_fill_from_file (filename); + g_free (filename); + } + closedir (dir); +} +static void +add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer clist) +{ + static gchar *text[2]; + GList *list; + GString *extension; + gint row; + + extension = g_string_new (""); + + for (list = ((MimeInfo *) mi)->ext[0];list; list=list->next) { + g_string_append (extension, (gchar *) list->data); + if (list->next != NULL) + g_string_append (extension, ", "); + else if (((MimeInfo *) mi)->ext[1] != NULL) + g_string_append (extension, ", "); + } + for (list = ((MimeInfo *) mi)->ext[1];list; list=list->next) { + g_string_append (extension, (gchar *) list->data); + if (list->next) + g_string_append (extension, ", "); + } + text[0] = ((MimeInfo *) mi)->mime_type; + text[1] = extension->str; + row = gtk_clist_insert (GTK_CLIST (clist), 1, text); + gtk_clist_set_row_data (GTK_CLIST (clist), row, mi); + g_string_free (extension, TRUE); +} +static void +selected_row_callback (GtkWidget *widget, gint row, gint column, GdkEvent *event, gpointer data) +{ + MimeInfo *mi; + if (column < 0) + return; + + mi = (MimeInfo *) gtk_clist_get_row_data (GTK_CLIST (widget),row); + + if (event && event->type == GDK_2BUTTON_PRESS) + launch_edit_window (mi); +} + +/* public functions */ +void +edit_clicked () +{ + MimeInfo *mi; + + /*mi = (MimeInfo *) gtk_clist_get_row_data (GTK_CLIST (widget), row);*/ +} + +GtkWidget * +get_mime_clist () +{ + GtkWidget *clist; + GtkWidget *retval; + gchar *titles[2]; + + titles[0] = "Mime Type"; + titles[1] = "Extension"; + retval = gtk_scrolled_window_new (NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (retval), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + clist = gtk_clist_new_with_titles (2, titles); + gtk_signal_connect (GTK_OBJECT (clist), + "select_row", + GTK_SIGNAL_FUNC (selected_row_callback), + NULL); + gtk_clist_set_auto_sort (GTK_CLIST (clist), TRUE); + g_hash_table_foreach (mime_types, (GHFunc) add_mime_vals_to_clist, clist); + gtk_clist_columns_autosize (GTK_CLIST (clist)); + + gtk_container_add (GTK_CONTAINER (retval), clist); + return retval; +} +void +init_mime_type () +{ + char *mime_info_dir; + + mime_types = g_hash_table_new (g_str_hash, g_str_equal); + + mime_info_dir = gnome_unconditional_datadir_file ("mime-info"); + mime_load_from_dir (mime_info_dir); + g_free (mime_info_dir); + + mime_info_dir = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/mime-info"); + mime_load_from_dir (mime_info_dir); + g_free (mime_info_dir); + +} diff --git a/capplets/mime-type/mime-data.h b/capplets/mime-type/mime-data.h new file mode 100644 index 000000000..2f61eacbb --- /dev/null +++ b/capplets/mime-type/mime-data.h @@ -0,0 +1,22 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/* Copyright (C) 1998 Redhat Software Inc. + * Authors: Jonathan Blandford <jrb@redhat.com> + */ +#ifndef _MIME_DATA_H_ +#define _MIME_DATA_H_ +#include "gnome.h" +#include <regex.h> +/* Typedefs */ +typedef struct { + char *mime_type; + regex_t *regex[2]; + GList *ext[2]; + char *file_name; + GList *keys; +} MimeInfo; + +GtkWidget *get_mime_clist (); +void init_mime_type (); + + +#endif diff --git a/capplets/mime-type/mime-type-capplet.c b/capplets/mime-type/mime-type-capplet.c new file mode 100644 index 000000000..4ad1dd875 --- /dev/null +++ b/capplets/mime-type/mime-type-capplet.c @@ -0,0 +1,101 @@ +/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ +/* Copyright (C) 1998 Redhat Software Inc. + * Authors: Jonathan Blandford <jrb@redhat.com> + */ +#include <config.h> +#include "capplet-widget.h" +#include "gnome.h" +#include <string.h> +#include <sys/types.h> +#include <dirent.h> +#include <regex.h> +#include <ctype.h> +#include "mime-data.h" + +/* Prototypes */ +static void try_callback (); +static void revert_callback (); +static void ok_callback (); +static void cancel_callback (); +static void help_callback (); + +static void +try_callback () +{ + +} +static void +revert_callback () +{ + +} +static void +ok_callback () +{ + +} +static void +cancel_callback () +{ + +} +static void +help_callback () +{ + +} +static void +init_mime_capplet () +{ + GtkWidget *capplet; + GtkWidget *vbox; + GtkWidget *hbox; + GtkWidget *button; + + capplet = capplet_widget_new (); + vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); + gtk_container_add (GTK_CONTAINER (capplet), vbox); + gtk_box_pack_start (GTK_BOX (vbox), get_mime_clist (), TRUE, TRUE, 0); + hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); + gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); + button = gtk_button_new_with_label (_("Remove")); + gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_label (_("Add")); + gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0); + button = gtk_button_new_with_label (_("Edit")); + gtk_box_pack_end (GTK_BOX (hbox), button, FALSE, FALSE, 0); + gtk_widget_show_all (capplet); + gtk_signal_connect(GTK_OBJECT(capplet), "try", + GTK_SIGNAL_FUNC(try_callback), NULL); + gtk_signal_connect(GTK_OBJECT(capplet), "revert", + GTK_SIGNAL_FUNC(revert_callback), NULL); + gtk_signal_connect(GTK_OBJECT(capplet), "ok", + GTK_SIGNAL_FUNC(ok_callback), NULL); + gtk_signal_connect(GTK_OBJECT(capplet), "cancel", + GTK_SIGNAL_FUNC(cancel_callback), NULL); + gtk_signal_connect(GTK_OBJECT(capplet), "help", + GTK_SIGNAL_FUNC(help_callback), NULL); +} + +int +main (int argc, char **argv) +{ + int init_results; + + bindtextdomain (PACKAGE, GNOMELOCALEDIR); + textdomain (PACKAGE); + + init_results = gnome_capplet_init("mouse-properties", VERSION, + argc, argv, NULL, 0, NULL); + + if (init_results < 0) { + exit (0); + } + + if (init_results == 0) { + init_mime_type (); + init_mime_capplet (); + capplet_gtk_main (); + } + return 0; +} diff --git a/configure.in b/configure.in index 1a8a5ba84..b17259a2f 100644 --- a/configure.in +++ b/configure.in @@ -92,6 +92,7 @@ macros/Makefile control-center/Makefile capplets/Makefile capplets/mouse-properties/Makefile +capplets/mime-type/Makefile capplets/keyboard-properties/Makefile capplets/desktop-links/Makefile capplets/background-properties/Makefile @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: control-centre 1.0.0\n" -"POT-Creation-Date: 1999-03-10 02:02+0100\n" +"POT-Creation-Date: 1999-03-09 18:54-0500\n" "PO-Revision-Date: 1999-02-25 01:35+0100\n" "Last-Translator: Kjartan Maraas <kmaraas@fib.hl.no>\n" "Language-Team: Norwegian <no@li.org>\n" @@ -371,8 +371,7 @@ msgstr "Lydhendelser" #: capplets/sound-properties/sound-properties.c:335 msgid "" "This copy of the GNOME control center was not compiled with sound support" -msgstr "" -"GNOME kontrollsenter ble kompilert uten støtte for lyd" +msgstr "GNOME kontrollsenter ble kompilert uten støtte for lyd" #: capplets/sound-properties/sound-properties.c:695 msgid "The sound file for this event does not exist." @@ -595,31 +594,31 @@ msgstr "Sett" msgid "Remove" msgstr "Fjern" -#: control-center/callbacks.c:69 +#: control-center/callbacks.c:79 msgid "GNOME Control Center" msgstr "GNOME Kontrollsenter" -#: control-center/callbacks.c:72 +#: control-center/callbacks.c:82 msgid "Desktop Properties manager." msgstr "Egenskaper for skrivebord." -#: control-center/capplet-manager.c:163 +#: control-center/capplet-manager.c:170 msgid "Try" msgstr "Prøv" -#: control-center/capplet-manager.c:168 +#: control-center/capplet-manager.c:175 msgid "Revert" msgstr "Forkast" -#: control-center/capplet-manager.c:173 +#: control-center/capplet-manager.c:180 msgid "OK" msgstr "OK" -#: control-center/capplet-manager.c:178 +#: control-center/capplet-manager.c:185 msgid "Cancel" msgstr "Avbryt" -#: control-center/capplet-manager.c:181 +#: control-center/capplet-manager.c:188 control-center/main.c:30 msgid "Help" msgstr "Hjelp" @@ -672,12 +671,17 @@ msgstr "capplet-kommando som skal kjøres." msgid "CAPPLET" msgstr "CAPPLET" +#: control-center/main.c:30 +#, fuzzy +msgid "Help with the GNOME control-center." +msgstr "Kontrollsenterets IOR" + #. we create the widgets -#: control-center/main.c:75 +#: control-center/main.c:58 msgid "Discard all changes" msgstr "Forkast alle endringer" #. create the app -#: control-center/main.c:145 +#: control-center/main.c:162 msgid "Control Center" msgstr "Kontrollsenter" |