diff options
Diffstat (limited to 'mixgtk')
| -rw-r--r-- | mixgtk/Makefile.am | 1 | ||||
| -rw-r--r-- | mixgtk/mixgtk.c | 11 | ||||
| -rw-r--r-- | mixgtk/mixgtk.glade | 39 | ||||
| -rw-r--r-- | mixgtk/mixgtk.h | 6 | ||||
| -rw-r--r-- | mixgtk/mixgtk_config.c | 149 | ||||
| -rw-r--r-- | mixgtk/mixgtk_config.h | 55 | ||||
| -rw-r--r-- | mixgtk/mixgtk_fontsel.c | 42 | ||||
| -rw-r--r-- | mixgtk/mixgtk_gen_handlers.c | 16 | ||||
| -rw-r--r-- | mixgtk/mixgtk_gen_handlers.h | 7 | ||||
| -rw-r--r-- | mixgtk/mixgtk_widgets.c | 19 | 
10 files changed, 310 insertions, 35 deletions
| diff --git a/mixgtk/Makefile.am b/mixgtk/Makefile.am index 4409625..83b5035 100644 --- a/mixgtk/Makefile.am +++ b/mixgtk/Makefile.am @@ -19,6 +19,7 @@ if MAKE_GUI  pkgdata_DATA = mixgtk.glade  bin_PROGRAMS = gmixvm  gmixvm_SOURCES = gmixvm.c mixgtk.h mixgtk.c \ +                 mixgtk_config.h mixgtk_config.c \                   mixgtk_gen_handlers.h mixgtk_gen_handlers.c \  		 mixgtk_cmd_dispatcher.h mixgtk_cmd_dispatcher.c \                   mixgtk_widgets.h mixgtk_widgets.c \ diff --git a/mixgtk/mixgtk.c b/mixgtk/mixgtk.c index da67c7e..42002f2 100644 --- a/mixgtk/mixgtk.c +++ b/mixgtk/mixgtk.c @@ -1,7 +1,7 @@  /* -*-c-*- -------------- mixgtk.c :   * Main functions of the mix gtk front-end   * ------------------------------------------------------------------ - *  Last change: Time-stamp: "2001-04-28 22:40:32 jao" + *  Last change: Time-stamp: "2001-04-29 12:36:16 jao"   * ------------------------------------------------------------------   * Copyright (C) 2001 Free Software Foundation, Inc.   *   @@ -29,6 +29,7 @@  #include "mixgtk_input.h"  #include "mixgtk_colorsel.h"  #include "mixgtk_fontsel.h" +#include "mixgtk_config.h"  #include "mixgtk.h" @@ -42,6 +43,12 @@ mixgtk_init (int argc, char *argv[])    mix_init_lib (); +  if (!mixgtk_config_load ()) +    { +      g_error ("Unable to read configuration\n"); +      return FALSE; +    } +      if (!mixgtk_widget_factory_init (GLADE_FILE)        && !mixgtk_widget_factory_init (LOCAL_GLADE_FILE))      { @@ -97,5 +104,7 @@ mixgtk_init (int argc, char *argv[])  void  mixgtk_release (void)   { +  if (mixgtk_config_is_autosave ()) mixgtk_config_save (); +      mix_release_lib ();  } diff --git a/mixgtk/mixgtk.glade b/mixgtk/mixgtk.glade index eb3af1e..69d8a17 100644 --- a/mixgtk/mixgtk.glade +++ b/mixgtk/mixgtk.glade @@ -202,7 +202,7 @@  		  <handler>on_mix_font_activate</handler>  		  <last_modification_time>Wed, 25 Apr 2001 01:55:53 GMT</last_modification_time>  		</signal> -		<label>MIX</label> +		<label>_MIX</label>  		<right_justify>False</right_justify>  	      </widget> @@ -214,7 +214,7 @@  		  <handler>on_mixal_font_activate</handler>  		  <last_modification_time>Wed, 25 Apr 2001 01:55:53 GMT</last_modification_time>  		</signal> -		<label>MIXAL</label> +		<label>MI_XAL</label>  		<right_justify>False</right_justify>  	      </widget> @@ -226,7 +226,7 @@  		  <handler>on_prompt_font_activate</handler>  		  <last_modification_time>Wed, 25 Apr 2001 01:55:53 GMT</last_modification_time>  		</signal> -		<label>Command prompt</label> +		<label>Command _prompt</label>  		<right_justify>False</right_justify>  	      </widget> @@ -238,11 +238,42 @@  		  <handler>on_log_font_activate</handler>  		  <last_modification_time>Wed, 25 Apr 2001 01:55:53 GMT</last_modification_time>  		</signal> -		<label>Command log</label> +		<label>Command l_og</label>  		<right_justify>False</right_justify>  	      </widget>  	    </widget>  	  </widget> + +	  <widget> +	    <class>GtkMenuItem</class> +	    <name>separator1</name> +	    <right_justify>False</right_justify> +	  </widget> + +	  <widget> +	    <class>GtkMenuItem</class> +	    <name>save</name> +	    <signal> +	      <name>activate</name> +	      <handler>on_save_activate</handler> +	      <last_modification_time>Sat, 28 Apr 2001 22:51:02 GMT</last_modification_time> +	    </signal> +	    <label>_Save</label> +	    <right_justify>False</right_justify> +	  </widget> + +	  <widget> +	    <class>GtkCheckMenuItem</class> +	    <name>save_on_exit</name> +	    <signal> +	      <name>toggled</name> +	      <handler>on_save_on_exit_toggle</handler> +	      <last_modification_time>Sun, 29 Apr 2001 10:26:16 GMT</last_modification_time> +	    </signal> +	    <label>Save on _exit</label> +	    <active>False</active> +	    <always_show_toggle>True</always_show_toggle> +	  </widget>  	</widget>        </widget> diff --git a/mixgtk/mixgtk.h b/mixgtk/mixgtk.h index d92dda8..c77433f 100644 --- a/mixgtk/mixgtk.h +++ b/mixgtk/mixgtk.h @@ -1,7 +1,7 @@  /* -*-c-*- ---------------- mixgtk.h :   * Gmixvm initialisation and cleanup functions   * ------------------------------------------------------------------ - *  Last change: Time-stamp: <2001-04-28 22:32:58 jao> + *  Last change: Time-stamp: <2001-04-29 12:06:48 jao>   * ------------------------------------------------------------------   * Copyright (C) 2001 Free Software Foundation, Inc.   *   @@ -25,8 +25,12 @@  #ifndef MIXGTK_H  #define MIXGTK_H +#include <gtk/gtk.h>  #include <mixlib/mix.h> +/* the app files directory */ +#define MIXGTK_FILES_DIR  ".gmixvm" +  /* initialise the app */  extern gboolean  mixgtk_init (int argc, char *argv[]); diff --git a/mixgtk/mixgtk_config.c b/mixgtk/mixgtk_config.c new file mode 100644 index 0000000..b886238 --- /dev/null +++ b/mixgtk/mixgtk_config.c @@ -0,0 +1,149 @@ +/* -*-c-*- -------------- mixgtk_config.c : + * Implementation of the functions declared in mixgtk_config.h + * ------------------------------------------------------------------ + *  Last change: Time-stamp: "2001-04-29 14:53:06 jao" + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, 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. + *   + */ + +#include <stdlib.h> +#include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> +#include <errno.h> +#include "mixgtk.h" +#include "mixgtk_config.h" + +#define CONFIG_FILENAME  "config" +#define COMMENT_PREFIX '#' +#define AUTOSAVE_FLAG "Autosave" + +static GHashTable *items_; +static gchar *config_ = NULL; +static gboolean autosave_ = FALSE; + +/* load configuration */ +gboolean +mixgtk_config_load (void) +{ +  const gchar *autosave; +  FILE *f; +  gchar *mixdir = g_strdup_printf ("%s/%s", g_get_home_dir (), MIXGTK_FILES_DIR); +  int k = mkdir (mixdir, S_IRWXU | S_IRWXG | S_IRWXO); +  if (!k) g_message ("Configuration directory %s created\n", mixdir); +  config_ = g_strdup_printf ("%s/%s", mixdir, CONFIG_FILENAME); +  items_ = g_hash_table_new (g_str_hash, g_str_equal); +  f = fopen (config_, "r"); +  if (f != NULL) +    { +      enum {LEN = 256}; +      gchar buffer[LEN]; +      gchar *line = buffer; +      while (!feof (f)) +	{ +	  line = fgets (line, LEN, f); +	  if (line) line = g_strstrip (line); +	  if (line && line[0] != COMMENT_PREFIX) +	    { +	      gchar **vals = g_strsplit (line, "=", 2); +	      g_hash_table_insert (items_, +				   (gpointer)g_strdup (g_strstrip (vals[0])), +				   (gpointer)g_strdup (g_strstrip (vals[1]))); +	      g_strfreev (vals); +	    } +	} +      fclose (f); +    } +       +  autosave = mixgtk_config_get (AUTOSAVE_FLAG); +  autosave_ = autosave && !g_strcasecmp (autosave, "True"); +  g_free (mixdir); +  return TRUE; +} + +/* autosave state */ +gboolean +mixgtk_config_is_autosave (void) +{ +  return autosave_; +} + +void +mixgtk_config_set_autosave (gboolean autosave) +{ +  if (autosave != autosave_) +    { +      mixgtk_config_update (AUTOSAVE_FLAG, autosave? "True" : "False"); +      autosave_ = autosave; +    } +} + +/* update config item */ +void +mixgtk_config_update (const gchar *key, const gchar *value) +{ +  gpointer tmp = NULL; +   +  g_return_if_fail (key != NULL); +  g_return_if_fail (value != NULL); +   +  tmp = g_hash_table_lookup (items_, key); +  if (tmp) +    { +      g_free (tmp); +      tmp = (gpointer)key; +    } +  else +    { +      tmp = (gpointer)g_strdup (key); +    } +   +  g_hash_table_insert (items_, tmp, g_strdup (value)); +} + +/* get config item */ +const gchar * +mixgtk_config_get (const gchar *key) +{ +  return (const gchar*)g_hash_table_lookup (items_, key); +} + + +/* save configuration */ +static void +save_ (gpointer key, gpointer value, gpointer file) +{ +  fprintf ((FILE *)file, "%s=%s\n", (char *)key, (char *)value); +} + +void +mixgtk_config_save (void) +{ +  FILE *f = fopen (config_, "w"); +  if (!f) +    { +      g_warning ("Unable to open config file %s (%s)", +		 config_, g_strerror (errno)); +      return; +    } +  g_hash_table_foreach (items_, save_, (gpointer)f); +  fclose (f); +} + +   + diff --git a/mixgtk/mixgtk_config.h b/mixgtk/mixgtk_config.h new file mode 100644 index 0000000..04cc1d4 --- /dev/null +++ b/mixgtk/mixgtk_config.h @@ -0,0 +1,55 @@ +/* -*-c-*- ---------------- mixgtk_config.h : + * Configuration functions declarations. + * ------------------------------------------------------------------ + *  Last change: Time-stamp: <2001-04-29 12:07:11 jao> + * ------------------------------------------------------------------ + * Copyright (C) 2001 Free Software Foundation, 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. + *   + */ + + +#ifndef MIXGTK_CONFIG_H +#define MIXGTK_CONFIG_H + +#include <mixlib/mix.h> + +/* load configuration */ +extern gboolean +mixgtk_config_load (void); + +/* autosave state */ +extern gboolean +mixgtk_config_is_autosave (void); + +extern void +mixgtk_config_set_autosave (gboolean autosave); + +/* update config item */ +extern void +mixgtk_config_update (const gchar *key, const gchar *value); + +/* get config item */ +extern const gchar * +mixgtk_config_get (const gchar *key); + +/* save configuration */ +extern void +mixgtk_config_save (void); + + +#endif /* MIXGTK_CONFIG_H */ + diff --git a/mixgtk/mixgtk_fontsel.c b/mixgtk/mixgtk_fontsel.c index 139fe9d..3119825 100644 --- a/mixgtk/mixgtk_fontsel.c +++ b/mixgtk/mixgtk_fontsel.c @@ -1,7 +1,7 @@  /* -*-c-*- -------------- mixgtk_fontsel.c :   * Implementation of the functions declared in mixgtk_fontsel.h   * ------------------------------------------------------------------ - *  Last change: Time-stamp: "2001-04-28 00:42:21 jao" + *  Last change: Time-stamp: "2001-04-28 23:44:18 jao"   * ------------------------------------------------------------------   * Copyright (C) 2001 Free Software Foundation, Inc.   *   @@ -41,23 +41,6 @@ static mixgtk_widget_id_t widget_ids_[] = {    MIXGTK_WIDGET_PROMPT,    MIXGTK_WIDGET_LOG,    MIXGTK_WIDGET_MIXAL, -  MIXGTK_WIDGET_rA, -  MIXGTK_WIDGET_rX, -  MIXGTK_WIDGET_rJ, -  MIXGTK_WIDGET_rI1, -  MIXGTK_WIDGET_rI2, -  MIXGTK_WIDGET_rI3, -  MIXGTK_WIDGET_rI4, -  MIXGTK_WIDGET_rI5, -  MIXGTK_WIDGET_rI6, -  MIXGTK_WIDGET_CMP_L, -  MIXGTK_WIDGET_CMP_E, -  MIXGTK_WIDGET_CMP_G, -  MIXGTK_WIDGET_OVER, -  MIXGTK_WIDGET_CELLS, -  MIXGTK_WIDGET_LAPTIME, -  MIXGTK_WIDGET_PROGTIME, -  MIXGTK_WIDGET_UPTIME  };  #define WIDGET_NO_  (sizeof (widget_ids_) / sizeof (widget_ids_[0])) @@ -87,6 +70,13 @@ mixgtk_fontsel_init (void)        infos_[i].style = gtk_style_copy  	(gtk_widget_get_style (infos_[i].widget));        gtk_widget_set_style (infos_[i].widget, infos_[i].style); +      if (widget_ids_[i] == MIXGTK_WIDGET_MIXVM) +	{ +	  int k; +	  for (k = MIXGTK_WIDGET_rA; k <= MIXGTK_WIDGET_UPTIME; ++k) +	    gtk_widget_set_style (mixgtk_widget_factory_get (k), +				  infos_[i].style); +	}        infos_[i].font = NULL;        g_hash_table_insert (winfo_, GINT_TO_POINTER (widget_ids_[i]),  			   (gpointer)(infos_ + i)); @@ -108,17 +98,17 @@ mixgtk_fontsel_set (mixgtk_widget_id_t widget, const gchar *font)  	  w->style->font = f;  	  if (w->font != NULL) g_free (w->font);  	  w->font = g_strdup (font); -	  //      gtk_widget_set_style (w, style); -	  gtk_widget_draw (w->widget, FALSE); +	  gtk_widget_draw (w->widget, NULL); + +	  if (widget == MIXGTK_WIDGET_MIXVM) +	    { +	      int k; +	      for (k = MIXGTK_WIDGET_rA; k <= MIXGTK_WIDGET_UPTIME; ++k) +		gtk_widget_draw (mixgtk_widget_factory_get (k), NULL); +	    }  	}      } -  if (widget == MIXGTK_WIDGET_MIXVM) -    { -      int k; -      for (k = MIXGTK_WIDGET_rA; k <= MIXGTK_WIDGET_UPTIME; ++k) -	mixgtk_fontsel_set (k, font); -    }  }  const gchar * diff --git a/mixgtk/mixgtk_gen_handlers.c b/mixgtk/mixgtk_gen_handlers.c index 9f23310..b687a6d 100644 --- a/mixgtk/mixgtk_gen_handlers.c +++ b/mixgtk/mixgtk_gen_handlers.c @@ -1,7 +1,7 @@  /* -*-c-*- -------------- mixgtk_gen_handlers.c :   * Implementation of the functions declared in mixgtk_gen_handlers.h   * ------------------------------------------------------------------ - *  Last change: Time-stamp: "01/03/16 00:30:40 jose" + *  Last change: Time-stamp: "2001-04-29 12:32:47 jao"   * ------------------------------------------------------------------   * Copyright (C) 2001 Free Software Foundation, Inc.   *   @@ -24,6 +24,7 @@  #include <mixlib/mix_vm_command.h>  #include "mixgtk_gen_handlers.h"  #include "mixgtk_cmd_dispatcher.h" +#include "mixgtk_config.h"  void  on_main_window_destroy (GtkWidget *w, gpointer data) @@ -93,3 +94,16 @@ on_clear_breakpoints_activate (GtkWidget *w, gpointer data)    mixgtk_cmd_dispatcher_dispatch (mix_vm_command_to_string (MIX_CMD_CABP));  } +void +on_save_on_exit_toggle (GtkWidget *w, gpointer data) +{ +  mixgtk_config_set_autosave (GTK_CHECK_MENU_ITEM (w)->active); +} + +void +on_save_activate (GtkWidget *w, gpointer data) +{ +  mixgtk_config_save (); +} + + diff --git a/mixgtk/mixgtk_gen_handlers.h b/mixgtk/mixgtk_gen_handlers.h index 6e0a45d..0442d22 100644 --- a/mixgtk/mixgtk_gen_handlers.h +++ b/mixgtk/mixgtk_gen_handlers.h @@ -1,7 +1,7 @@  /* -*-c-*- ---------------- mixgtk_gen_handlers.h :   * general signal handlers declarations   * ------------------------------------------------------------------ - *  Last change: Time-stamp: <01/03/16 00:29:45 jose> + *  Last change: Time-stamp: <2001-04-29 12:32:32 jao>   * ------------------------------------------------------------------   * Copyright (C) 2001 Free Software Foundation, Inc.   *   @@ -39,6 +39,11 @@ on_file_exit_activate (GtkWidget *w, gpointer data);  extern void  on_clear_breakpoints_activate (GtkWidget *w, gpointer data); +extern void +on_save_on_exit_toggle (GtkWidget *w, gpointer data); + +extern void +on_save_activate (GtkWidget *w, gpointer data); diff --git a/mixgtk/mixgtk_widgets.c b/mixgtk/mixgtk_widgets.c index a26d886..61f973f 100644 --- a/mixgtk/mixgtk_widgets.c +++ b/mixgtk/mixgtk_widgets.c @@ -1,7 +1,7 @@  /* -*-c-*- -------------- mixgtk_widgets.c :   * Implementation of the functions declared in mixgtk_widgets.h   * ------------------------------------------------------------------ - *  Last change: Time-stamp: "2001-04-27 23:32:32 jao" + *  Last change: Time-stamp: "2001-04-29 14:32:17 jao"   * ------------------------------------------------------------------   * Copyright (C) 2001 Free Software Foundation, Inc.   *   @@ -25,6 +25,7 @@  #include <glade/glade.h>  #include <mixlib/mix.h> +#include "mixgtk_config.h"  #include "mixgtk_widgets.h"  /* the glade spec */ @@ -70,14 +71,27 @@ static const gchar *names_[] = {  #define VERSION_LABEL_ "version_label"  #define GPL_TEXT_ "gpl_text" +#define AUTOSAVE_ITEM_ "save_on_exit"  GtkWidget *about_; +static void +init_autosave_ (void) +{ +  GtkCheckMenuItem *item = GTK_CHECK_MENU_ITEM +    (mixgtk_widget_factory_get_by_name (AUTOSAVE_ITEM_)); +  if (item) +    { +      gtk_check_menu_item_set_active (item, mixgtk_config_is_autosave ()); +    } +} +  /* create a new factory from an xml glade file */  gboolean  mixgtk_widget_factory_init (const char *glade_file)  {    GtkWidget *label; +      glade_init ();    xml_ = glade_xml_new (glade_file, NULL);    if (!xml_) return FALSE; @@ -89,6 +103,9 @@ mixgtk_widget_factory_init (const char *glade_file)    g_return_val_if_fail (label != NULL, FALSE);    gtk_label_set_text (GTK_LABEL(label), VERSION);    gtk_widget_show (label); +   +  init_autosave_ (); +      return TRUE;  } | 
