1
1
ugh, this code sux
Этот коммит содержится в:
Jonathan Blandford 1999-04-13 01:04:11 +00:00
родитель d62476e80e
Коммит ba44c6a5f0
7 изменённых файлов: 157 добавлений и 25 удалений

Просмотреть файл

@ -213,8 +213,11 @@ setup_entry (gchar *key, GtkWidget *g_entry, MimeInfo *mi)
void
initialize_main_win_vals (void)
{
MimeInfo *mi = main_win->mi;
MimeInfo *mi;
gchar *title;
if (main_win == NULL)
return;
mi = main_win->mi;
if (mi == NULL)
return;
/* now we fill in the fields with the mi stuff. */

Просмотреть файл

@ -32,7 +32,8 @@ static GHashTable *mime_types = NULL;
static GHashTable *initial_user_mime_types = NULL;
static GHashTable *user_mime_types = NULL;
static GtkWidget *clist = NULL;
extern GtkWidget *delete_button;
extern GtkWidget *capplet;
/* Initialization functions */
static char *
get_priority (char *def, int *priority)
@ -54,6 +55,11 @@ get_priority (char *def, int *priority)
def++;
return def;
}
static void
free_mime_info (MimeInfo *mi)
{
}
static void
add_to_key (char *mime_type, char *def, GHashTable *table)
@ -221,7 +227,7 @@ mime_load_from_dir (const char *mime_info_dir, gboolean system_dir)
}
closedir (dir);
}
static void
static int
add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl)
{
/* we also finalize the MimeInfo structure here, now that we're done
@ -266,6 +272,7 @@ add_mime_vals_to_clist (gchar *mime_type, gpointer mi, gpointer cl)
row = gtk_clist_insert (GTK_CLIST (cl), 1, text);
gtk_clist_set_row_data (GTK_CLIST (cl), row, mi);
g_string_free (extension, TRUE);
return row;
}
static void
@ -279,11 +286,35 @@ selected_row_callback (GtkWidget *widget, gint row, gint column, GdkEvent *event
if (event && event->type == GDK_2BUTTON_PRESS)
launch_edit_window (mi);
if (g_hash_table_lookup (user_mime_types, mi->mime_type)) {
gtk_widget_set_sensitive (delete_button, TRUE);
} else
gtk_widget_set_sensitive (delete_button, FALSE);
}
/* public functions */
void
edit_clicked ()
delete_clicked (GtkWidget *widget, gpointer data)
{
MimeInfo *mi;
gint row = 0;
if (GTK_CLIST (clist)->selection)
row = GPOINTER_TO_INT ((GTK_CLIST (clist)->selection)->data);
else
return;
mi = (MimeInfo *) gtk_clist_get_row_data (GTK_CLIST (clist), row);
gtk_clist_remove (GTK_CLIST (clist), row);
g_hash_table_remove (user_mime_types, mi->mime_type);
remove_mime_info (mi->mime_type);
free_mime_info (mi);
capplet_widget_state_changed (CAPPLET_WIDGET (capplet),
TRUE);
}
void
edit_clicked (GtkWidget *widget, gpointer data)
{
MimeInfo *mi;
gint row = 0;
@ -328,6 +359,51 @@ get_mime_clist (void)
gtk_container_add (GTK_CONTAINER (retval), clist);
return retval;
}
static void
finalize_mime_type_foreach (gpointer mime_type, gpointer info, gpointer data)
{
MimeInfo *mi = (MimeInfo *)info;
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, ", ");
}
((MimeInfo *) mi)->ext_readable[0] = extension->str;
g_string_free (extension, FALSE);
extension = g_string_new ("");
for (list = ((MimeInfo *) mi)->ext[1];list; list=list->next) {
g_string_append (extension, (gchar *) list->data);
if (list->next)
g_string_append (extension, ", ");
}
((MimeInfo *) mi)->ext_readable[1] = extension->str;
g_string_free (extension, FALSE);
if (((MimeInfo *) mi)->ext[0]) {
extension = g_string_new ((((MimeInfo *) mi)->ext_readable[0]));
if (((MimeInfo *) mi)->ext[1]) {
g_string_append (extension, ", ");
g_string_append (extension, (((MimeInfo *) mi)->ext_readable[1]));
}
} else if (((MimeInfo *) mi)->ext[1])
extension = g_string_new ((((MimeInfo *) mi)->ext_readable[1]));
else
extension = g_string_new ("");
g_string_free (extension, TRUE);
}
static void
finalize_user_mime ()
{
g_hash_table_foreach (user_mime_types, finalize_mime_type_foreach, NULL);
g_hash_table_foreach (initial_user_mime_types, finalize_mime_type_foreach, NULL);
}
void
init_mime_type (void)
{
@ -344,21 +420,21 @@ init_mime_type (void)
mime_info_dir = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/mime-info");
mime_load_from_dir (mime_info_dir, FALSE);
g_free (mime_info_dir);
finalize_user_mime ();
init_mime_info ();
}
void
add_new_mime_type (gchar *mime_type, gchar *ext, gchar *regexp1, gchar *regexp2)
{
gchar *temp;
MimeInfo *mi;
MimeInfo *mi = NULL;
gint row;
/* first we make sure that the information is good */
/* passed check, now we add it. */
if (ext) {
temp = g_strconcat ("ext: ", ext, NULL);
add_to_key (mime_type, temp, user_mime_types);
mi = (MimeInfo *) g_hash_table_lookup (user_mime_types, mime_type);
mi->ext_readable[0] = g_strdup (ext);
g_free (temp);
}
if (regexp1) {
@ -371,13 +447,18 @@ add_new_mime_type (gchar *mime_type, gchar *ext, gchar *regexp1, gchar *regexp2)
add_to_key (mime_type, temp, user_mime_types);
g_free (temp);
}
/* Finally add it to the clist */
if (mi) {
row = add_mime_vals_to_clist (mime_type, mi, clist);
gtk_clist_select_row (GTK_CLIST (clist), row, 0);
gtk_clist_moveto (GTK_CLIST (clist), row, 0, 0.5, 0.0);
}
}
static void
write_mime_foreach (gpointer mime_type, gpointer info, gpointer data)
{
gchar *buf;
MimeInfo *mi = (MimeInfo *) info;
g_print ("in write_mime_foreach:%s:\n", (gchar *) mime_type);
fwrite ((char *) mi->mime_type, 1, strlen ((char *) mi->mime_type), (FILE *) data);
fwrite ("\n", 1, 1, (FILE *) data);
if (mi->ext_readable[0]) {
@ -450,17 +531,49 @@ write_mime (GHashTable *hash)
return;
}
g_hash_table_foreach (hash, write_mime_foreach, file);
g_hash_table_foreach (hash, write_mime_foreach, file);
fclose (file);
}
void write_user_mime (void)
void
write_user_mime (void)
{
write_mime (user_mime_types);
}
void write_initial_mime (void)
void
write_initial_mime (void)
{
write_mime (initial_user_mime_types);
}
void
reread_list ()
{
gtk_clist_freeze (GTK_CLIST (clist));
gtk_clist_clear (GTK_CLIST (clist));
g_hash_table_foreach (mime_types, (GHFunc) add_mime_vals_to_clist, clist);
gtk_clist_thaw (GTK_CLIST (clist));
}
static void
clean_mime_type (gpointer mime_type, gpointer mime_info, gpointer data)
{
/* we should write this )-: */
}
void
discard_mime_info ()
{
gchar *filename;
g_hash_table_foreach (user_mime_types, clean_mime_type, NULL);
g_hash_table_destroy (user_mime_types);
g_hash_table_foreach (initial_user_mime_types, clean_mime_type, NULL);
g_hash_table_destroy (initial_user_mime_types);
user_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
initial_user_mime_types = g_hash_table_new (g_str_hash, g_str_equal);
filename = g_concat_dir_and_file (gnome_util_user_home (), "/.gnome/mime-info/user.keys");
mime_fill_from_file (filename, TRUE);
finalize_user_mime ();
reread_list ();
g_free (filename);
}

Просмотреть файл

@ -19,10 +19,12 @@ typedef struct {
GtkWidget *get_mime_clist (void);
void init_mime_type (void);
void delete_clicked (GtkWidget *widget, gpointer data);
void add_clicked (GtkWidget *widget, gpointer data);
void edit_clicked ();
void edit_clicked (GtkWidget *widget, gpointer data);
void add_new_mime_type (gchar *mime_type, gchar *ext, gchar *regexp1, gchar *regexp2);
void write_user_mime (void);
void write_initial_mime (void);
void reread_list (void);
void discard_mime_info (void);
#endif

Просмотреть файл

@ -307,10 +307,8 @@ set_mime_key_value (gchar *mime_type, gchar *key, gchar *value)
GString *str = g_string_new (mime_type);
context = context_new (str, FALSE);
g_string_free (str, TRUE);
g_hash_table_insert (specific_types, mime_type, context);
}
context_add_key (context, key, value);
}
void
init_mime_info (void)
@ -326,7 +324,6 @@ init_mime_info (void)
filename = g_concat_dir_and_file (gnome_util_user_home (), "/.gnome/mime-info/user.keys");
load_mime_type_info_from (filename);
g_free (filename);
}
const char *
@ -458,23 +455,34 @@ write_user_keys (void)
{
write_keys (generic_types, specific_types);
}
static void
print_mime_foreach (gpointer mime_info, gpointer mi, gpointer data)
{
g_print ("mime_info:%s:\n", (char *)mime_info);
g_print ("\t:%s:\n", ((MimeInfo *)mi)->mime_type);
}
void
discard_mime_info (void)
discard_key_info (void)
{
gchar *filename;
current_lang = getenv ("LANG");
g_hash_table_foreach (generic_types, clean_mime_foreach, NULL);
/* g_hash_table_foreach (specific_types, print_mime_foreach, NULL);*/
g_hash_table_foreach (specific_types, clean_mime_foreach, NULL);
g_hash_table_destroy (generic_types);
g_hash_table_destroy (specific_types);
specific_types = g_hash_table_new (g_str_hash, g_str_equal);
generic_types = g_hash_table_new (g_str_hash, g_str_equal);
initial_specific_types = g_hash_table_new (g_str_hash, g_str_equal);
initial_generic_types = g_hash_table_new (g_str_hash, g_str_equal);
filename = g_concat_dir_and_file (gnome_util_user_home (), "/.gnome/mime-info/user.keys");
load_mime_type_info_from (filename);
reread_list ();
g_free (filename);
}
void
remove_mime_info (gchar *mime_type)
{
g_hash_table_remove (generic_types, mime_type);
g_hash_table_remove (specific_types, mime_type);
}

Просмотреть файл

@ -8,9 +8,10 @@
#include <regex.h>
/* Typedefs */
void init_mime_info (void);
void discard_mime_info (void);
void discard_key_info (void);
void set_mime_key_value (gchar *mime_type, gchar *key, gchar *value);
const char * local_mime_get_value (const char *mime_type, char *key);
void write_user_keys (void);
void write_initial_keys (void);
void remove_mime_info (gchar *mime_type);
#endif

Просмотреть файл

@ -19,8 +19,8 @@ static void revert_callback ();
static void ok_callback ();
static void cancel_callback ();
static void help_callback ();
GtkWidget *capplet;
GtkWidget *delete_button;
GtkWidget *capplet = NULL;
GtkWidget *delete_button = NULL;
static GtkWidget *
left_aligned_button (gchar *label)
@ -45,6 +45,7 @@ revert_callback ()
{
write_initial_keys ();
write_initial_mime ();
discard_key_info ();
discard_mime_info ();
initialize_main_win_vals ();
}
@ -52,11 +53,13 @@ static void
ok_callback ()
{
write_user_keys ();
write_user_mime ();
}
static void
cancel_callback ()
{
write_initial_keys ();
write_initial_mime ();
}
static void
help_callback ()
@ -71,6 +74,10 @@ init_mime_capplet ()
GtkWidget *button;
capplet = capplet_widget_new ();
delete_button = left_aligned_button (_("Delete"));
gtk_signal_connect (GTK_OBJECT (delete_button), "clicked",
delete_clicked, NULL);
hbox = gtk_hbox_new (FALSE, GNOME_PAD);
gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL);
gtk_container_add (GTK_CONTAINER (capplet), hbox);
@ -85,7 +92,6 @@ init_mime_capplet ()
gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
gtk_signal_connect (GTK_OBJECT (button), "clicked",
edit_clicked, NULL);
delete_button = left_aligned_button (_("Delete"));
gtk_box_pack_start (GTK_BOX (vbox), delete_button, FALSE, FALSE, 0);
gtk_widget_show_all (capplet);
gtk_signal_connect(GTK_OBJECT(capplet), "try",

Просмотреть файл

@ -95,7 +95,6 @@ launch_new_mime_window (void)
gtk_entry_get_text (GTK_ENTRY (ext_entry)),
gtk_entry_get_text (GTK_ENTRY (regex1_entry)),
gtk_entry_get_text (GTK_ENTRY (regex2_entry)));
case 1:
gtk_widget_destroy (add_dialog);
default:;