Example #1
0
/*
 * Prints An Error Message
 */
void
error ( const gchar *prod,
        const gchar *format,
        ... )
{
  GimpMessageHandlerType t;
  gchar *message, *str;
  va_list ap;

   if ( format == NULL )
    return;

  str = ( gchar * ) g_malloc ( 512 );
  message = (gchar *) g_malloc ( 512 );

  t = gimp_message_get_handler ( );
  gimp_message_set_handler ( GIMP_ERROR_CONSOLE );

  va_start ( ap, format );
  g_vsnprintf ( message, 512, format, ap );
  va_end ( ap );

  if ( prod != NULL )
    g_snprintf ( str, 512, _("error in %s(): %s.\n"), prod, message );
  else
    g_snprintf ( str, 512, _("error: %s.\n"), message );

  gimp_message ( str );
  gimp_message_set_handler ( t );
  g_free ( message );
  g_free ( str );
}
Example #2
0
static void
init (void)
{
  GimpMessageHandlerType old_handler;

  gimp_plugin_domain_register (PLUGIN_NAME, NULL);

  setup_debug_mask ();

  old_handler = gimp_message_get_handler ();
  if (old_handler == GIMP_CONSOLE)
    gimp_message_set_handler (GIMP_MESSAGE_BOX);

  search_path = gimp_gimprc_query (PSPI_PATH_TOKEN);
  
  if (search_path == NULL)
    search_path = g_strdup ("");

  get_saved_plugin_data ();

  pspirc_values_modified = FALSE;
  scan_search_path ();

  /* Forget those PS plug-ins that weren't around any longer. */
  g_hash_table_foreach_remove (plug_in_hash, check_present, NULL);

  /* Rewrite the pspirc file if necessary */
  if (pspirc_values_modified)
    {
      gchar *pspirc_name = gimp_personal_rc_file (PSPIRC);
      gchar *temp_name = g_strconcat (pspirc_name, ".new", NULL);
      gchar *bak_name = g_strconcat (pspirc_name, ".bak", NULL);
      FILE *pspirc = fopen (temp_name, "w");

      if (pspirc == NULL)
	g_message (_("Could not open %s for writing"), temp_name);
      else
	{
	  PSPI_DEBUG (PSPIRC, g_print ("Saving pspirc file\n"));
	  fprintf (pspirc, "<pspi-settings>\n");
	  g_hash_table_foreach (plug_in_hash, save_pspirc_entry, pspirc);
	  fprintf (pspirc, "</pspi-settings>\n");
	  PSPI_DEBUG (PSPIRC, g_print ("\n"));
	  fclose (pspirc);
	  remove (bak_name);
	  if (g_file_test (pspirc_name, G_FILE_TEST_EXISTS) &&
	      rename (pspirc_name, bak_name) != 0)
	    g_message (_("Could not rename %s to %s"),
		       pspirc_name, bak_name);
	  else
	    {
	      if (rename (temp_name, pspirc_name) != 0)
		{
		  g_message (_("Could not rename %s to %s"),
			     temp_name, pspirc_name);
		  if (rename (bak_name, pspirc_name) != 0)
		    g_message (_("Could not rename %s to %s"),
			       bak_name, pspirc_name);
		}
	      else
		remove (bak_name);
	    }
	}
      g_free (pspirc_name);
      g_free (temp_name);
      g_free (bak_name);
    }

  if (old_handler == GIMP_CONSOLE)
    gimp_message_set_handler (GIMP_CONSOLE);
}