2006-12-10 05:33:38 +08:00
|
|
|
/* GIMP - The GNU Image Manipulation Program
|
1998-06-23 01:30:40 +08:00
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
2001-12-18 20:39:45 +08:00
|
|
|
* Session-managment stuff
|
|
|
|
* Copyright (C) 1998 Sven Neumann <sven@gimp.org>
|
|
|
|
*
|
1998-06-23 01:30:40 +08:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1999-03-07 20:56:03 +08:00
|
|
|
#include "config.h"
|
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
#include <errno.h>
|
2002-09-07 06:25:19 +08:00
|
|
|
#include <string.h>
|
2005-02-07 09:24:22 +08:00
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
#ifdef HAVE_UNISTD_H
|
|
|
|
#include <unistd.h>
|
|
|
|
#endif
|
1998-06-23 01:30:40 +08:00
|
|
|
|
2005-02-07 09:24:22 +08:00
|
|
|
#include <glib/gstdio.h>
|
1998-07-19 20:02:29 +08:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
|
2001-05-22 04:30:16 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-04-18 00:00:27 +08:00
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include "libgimpbase/gimpwin32-io.h"
|
|
|
|
#endif
|
|
|
|
|
2001-08-17 22:27:31 +08:00
|
|
|
#include "gui-types.h"
|
2000-12-17 05:37:03 +08:00
|
|
|
|
2005-01-25 06:41:24 +08:00
|
|
|
#include "config/gimpconfig-file.h"
|
2002-11-19 04:50:31 +08:00
|
|
|
#include "config/gimpguiconfig.h"
|
|
|
|
|
2001-10-24 00:23:32 +08:00
|
|
|
#include "core/gimp.h"
|
|
|
|
|
2001-04-17 02:49:29 +08:00
|
|
|
#include "widgets/gimpdialogfactory.h"
|
2003-10-10 23:59:12 +08:00
|
|
|
#include "widgets/gimpsessioninfo.h"
|
2001-04-17 02:49:29 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
#include "dialogs/dialogs.h"
|
|
|
|
|
2001-04-18 05:43:29 +08:00
|
|
|
#include "session.h"
|
|
|
|
|
2003-03-26 00:38:19 +08:00
|
|
|
#include "gimp-intl.h"
|
2002-06-03 03:48:01 +08:00
|
|
|
|
|
|
|
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
SESSION_INFO = 1,
|
2003-10-10 23:59:12 +08:00
|
|
|
LAST_TIP_SHOWN
|
|
|
|
};
|
2002-06-03 03:48:01 +08:00
|
|
|
|
2003-03-11 03:01:07 +08:00
|
|
|
|
2003-11-13 22:14:20 +08:00
|
|
|
static gchar * session_filename (Gimp *gimp);
|
|
|
|
|
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
/* private variables */
|
|
|
|
|
|
|
|
static gboolean sessionrc_deleted = FALSE;
|
|
|
|
|
|
|
|
|
2003-10-10 23:59:12 +08:00
|
|
|
/* public functions */
|
2002-06-03 03:48:01 +08:00
|
|
|
|
2001-04-18 00:00:27 +08:00
|
|
|
void
|
2001-10-24 00:23:32 +08:00
|
|
|
session_init (Gimp *gimp)
|
1998-06-23 01:30:40 +08:00
|
|
|
{
|
2002-06-03 03:48:01 +08:00
|
|
|
gchar *filename;
|
|
|
|
GScanner *scanner;
|
|
|
|
GTokenType token;
|
|
|
|
GError *error = NULL;
|
1998-07-12 06:23:23 +08:00
|
|
|
|
2001-10-24 00:23:32 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2003-11-13 22:14:20 +08:00
|
|
|
filename = session_filename (gimp);
|
|
|
|
|
2003-06-24 06:02:56 +08:00
|
|
|
scanner = gimp_scanner_new_file (filename, &error);
|
2000-03-25 06:10:28 +08:00
|
|
|
|
2003-11-05 05:58:39 +08:00
|
|
|
if (! scanner && error->code == GIMP_CONFIG_ERROR_OPEN_ENOENT)
|
|
|
|
{
|
|
|
|
g_clear_error (&error);
|
|
|
|
g_free (filename);
|
|
|
|
|
|
|
|
filename = g_build_filename (gimp_sysconf_directory (),
|
|
|
|
"sessionrc", NULL);
|
|
|
|
scanner = gimp_scanner_new_file (filename, NULL);
|
|
|
|
}
|
|
|
|
|
2002-06-03 03:48:01 +08:00
|
|
|
if (! scanner)
|
2000-03-25 06:10:28 +08:00
|
|
|
{
|
2003-11-05 05:58:39 +08:00
|
|
|
g_clear_error (&error);
|
2003-10-22 02:14:58 +08:00
|
|
|
g_free (filename);
|
2002-06-03 03:48:01 +08:00
|
|
|
return;
|
2000-03-25 06:10:28 +08:00
|
|
|
}
|
|
|
|
|
2005-11-07 06:01:25 +08:00
|
|
|
if (gimp->be_verbose)
|
|
|
|
g_print ("Parsing '%s'\n", gimp_filename_to_utf8 (filename));
|
|
|
|
|
2002-06-03 03:48:01 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, 0, "session-info",
|
|
|
|
GINT_TO_POINTER (SESSION_INFO));
|
|
|
|
g_scanner_scope_add_symbol (scanner, 0, "last-tip-shown",
|
|
|
|
GINT_TO_POINTER (LAST_TIP_SHOWN));
|
|
|
|
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
if (scanner->value.v_symbol == GINT_TO_POINTER (SESSION_INFO))
|
|
|
|
{
|
2008-05-17 00:06:42 +08:00
|
|
|
GimpDialogFactory *factory;
|
|
|
|
GimpSessionInfo *info;
|
|
|
|
gchar *factory_name;
|
|
|
|
gchar *entry_name;
|
|
|
|
gboolean skip = FALSE;
|
2002-06-03 03:48:01 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, &factory_name))
|
|
|
|
break;
|
|
|
|
|
|
|
|
factory = gimp_dialog_factory_from_name (factory_name);
|
|
|
|
g_free (factory_name);
|
|
|
|
|
|
|
|
if (! factory)
|
2002-08-22 22:48:28 +08:00
|
|
|
break;
|
2008-05-17 00:06:42 +08:00
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, &entry_name))
|
|
|
|
break;
|
|
|
|
|
|
|
|
info = gimp_session_info_new ();
|
|
|
|
|
|
|
|
if (strcmp (entry_name, "dock"))
|
|
|
|
{
|
|
|
|
info->toplevel_entry = gimp_dialog_factory_find_entry (factory,
|
|
|
|
entry_name);
|
|
|
|
skip = (info->toplevel_entry == NULL);
|
|
|
|
}
|
|
|
|
|
2008-07-22 14:51:59 +08:00
|
|
|
g_free (entry_name);
|
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
if (GIMP_CONFIG_GET_INTERFACE (info)->deserialize (GIMP_CONFIG (info),
|
|
|
|
scanner,
|
|
|
|
1,
|
|
|
|
NULL))
|
|
|
|
{
|
|
|
|
if (! skip)
|
|
|
|
{
|
|
|
|
factory->session_infos =
|
|
|
|
g_list_append (factory->session_infos, info);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_unref (info);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
g_object_unref (info);
|
|
|
|
break;
|
|
|
|
}
|
2002-06-03 03:48:01 +08:00
|
|
|
}
|
|
|
|
else if (scanner->value.v_symbol == GINT_TO_POINTER (LAST_TIP_SHOWN))
|
|
|
|
{
|
2006-04-12 20:49:29 +08:00
|
|
|
GimpGuiConfig *config = GIMP_GUI_CONFIG (gimp->config);
|
2002-11-19 04:50:31 +08:00
|
|
|
|
2002-06-03 03:48:01 +08:00
|
|
|
token = G_TOKEN_INT;
|
|
|
|
|
2002-11-19 04:50:31 +08:00
|
|
|
if (! gimp_scanner_parse_int (scanner, &config->last_tip))
|
2002-06-03 03:48:01 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (token != G_TOKEN_LEFT_PAREN)
|
|
|
|
{
|
|
|
|
g_scanner_get_next_token (scanner);
|
|
|
|
g_scanner_unexp_token (scanner, token, NULL, NULL, NULL,
|
|
|
|
_("fatal parse error"), TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (error)
|
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
|
2002-06-03 03:48:01 +08:00
|
|
|
g_clear_error (&error);
|
2003-10-22 02:14:58 +08:00
|
|
|
|
|
|
|
gimp_config_file_backup_on_error (filename, "sessionrc", NULL);
|
2002-06-03 03:48:01 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
gimp_scanner_destroy (scanner);
|
2003-10-22 02:14:58 +08:00
|
|
|
g_free (filename);
|
2008-05-17 00:06:42 +08:00
|
|
|
|
|
|
|
dialogs_load_recent_docks (gimp);
|
2001-04-18 00:00:27 +08:00
|
|
|
}
|
2000-03-25 06:10:28 +08:00
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
void
|
|
|
|
session_exit (Gimp *gimp)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
}
|
|
|
|
|
2001-04-18 00:00:27 +08:00
|
|
|
void
|
2001-10-24 00:23:32 +08:00
|
|
|
session_restore (Gimp *gimp)
|
2001-04-18 00:00:27 +08:00
|
|
|
{
|
2001-10-24 00:23:32 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2001-10-22 20:13:44 +08:00
|
|
|
gimp_dialog_factories_session_restore ();
|
1998-06-23 01:30:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2004-07-22 00:11:31 +08:00
|
|
|
session_save (Gimp *gimp,
|
|
|
|
gboolean always_save)
|
1998-06-23 01:30:40 +08:00
|
|
|
{
|
2003-03-11 03:01:07 +08:00
|
|
|
GimpConfigWriter *writer;
|
|
|
|
gchar *filename;
|
2006-10-10 02:49:15 +08:00
|
|
|
GError *error = NULL;
|
1998-06-23 01:30:40 +08:00
|
|
|
|
2001-10-24 00:23:32 +08:00
|
|
|
g_return_if_fail (GIMP_IS_GIMP (gimp));
|
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
if (sessionrc_deleted && ! always_save)
|
|
|
|
return;
|
|
|
|
|
2003-11-13 22:14:20 +08:00
|
|
|
filename = session_filename (gimp);
|
1998-06-23 01:30:40 +08:00
|
|
|
|
2005-11-07 06:01:25 +08:00
|
|
|
if (gimp->be_verbose)
|
|
|
|
g_print ("Writing '%s'\n", gimp_filename_to_utf8 (filename));
|
|
|
|
|
2003-06-24 06:02:56 +08:00
|
|
|
writer =
|
|
|
|
gimp_config_writer_new_file (filename,
|
2006-04-12 20:49:29 +08:00
|
|
|
TRUE,
|
|
|
|
"GIMP sessionrc\n\n"
|
|
|
|
"This file takes session-specific info "
|
|
|
|
"(that is info, you want to keep between "
|
|
|
|
"two GIMP sessions). You are not supposed "
|
|
|
|
"to edit it manually, but of course you "
|
|
|
|
"can do. The sessionrc will be entirely "
|
2006-02-24 22:57:13 +08:00
|
|
|
"rewritten every time you quit GIMP. "
|
2003-09-12 23:14:02 +08:00
|
|
|
"If this file isn't found, defaults are "
|
|
|
|
"used.",
|
2006-04-12 20:49:29 +08:00
|
|
|
NULL);
|
2003-06-24 21:58:34 +08:00
|
|
|
g_free (filename);
|
2003-03-11 03:01:07 +08:00
|
|
|
|
|
|
|
if (!writer)
|
1999-03-07 20:56:03 +08:00
|
|
|
return;
|
1998-06-24 06:50:16 +08:00
|
|
|
|
2003-03-11 03:01:07 +08:00
|
|
|
gimp_dialog_factories_session_save (writer);
|
|
|
|
gimp_config_writer_linefeed (writer);
|
2001-04-17 02:49:29 +08:00
|
|
|
|
1999-03-07 20:56:03 +08:00
|
|
|
/* save last tip shown */
|
2003-03-11 03:01:07 +08:00
|
|
|
gimp_config_writer_open (writer, "last-tip-shown");
|
|
|
|
gimp_config_writer_printf (writer, "%d",
|
|
|
|
GIMP_GUI_CONFIG (gimp->config)->last_tip + 1);
|
|
|
|
gimp_config_writer_close (writer);
|
2000-02-12 23:01:33 +08:00
|
|
|
|
2006-10-10 02:49:15 +08:00
|
|
|
if (! gimp_config_writer_finish (writer, "end of sessionrc", &error))
|
|
|
|
{
|
2008-11-04 20:33:09 +08:00
|
|
|
gimp_message_literal (gimp, NULL, GIMP_MESSAGE_ERROR, error->message);
|
2006-10-10 02:49:15 +08:00
|
|
|
g_clear_error (&error);
|
|
|
|
}
|
2004-07-22 00:11:31 +08:00
|
|
|
|
2008-05-17 00:06:42 +08:00
|
|
|
dialogs_save_recent_docks (gimp);
|
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
sessionrc_deleted = FALSE;
|
1998-06-23 01:30:40 +08:00
|
|
|
}
|
2002-06-03 03:48:01 +08:00
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
gboolean
|
|
|
|
session_clear (Gimp *gimp,
|
|
|
|
GError **error)
|
2003-04-08 18:02:42 +08:00
|
|
|
{
|
2004-07-22 00:11:31 +08:00
|
|
|
gchar *filename;
|
|
|
|
gboolean success = TRUE;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), FALSE);
|
|
|
|
g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
|
|
|
|
|
|
|
|
filename = session_filename (gimp);
|
|
|
|
|
2005-02-07 09:24:22 +08:00
|
|
|
if (g_unlink (filename) != 0 && errno != ENOENT)
|
2004-07-22 00:11:31 +08:00
|
|
|
{
|
|
|
|
g_set_error (error, 0, 0, _("Deleting \"%s\" failed: %s"),
|
|
|
|
gimp_filename_to_utf8 (filename), g_strerror (errno));
|
|
|
|
success = FALSE;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
sessionrc_deleted = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
g_free (filename);
|
2003-04-08 18:02:42 +08:00
|
|
|
|
2004-07-22 00:11:31 +08:00
|
|
|
return success;
|
2003-04-08 18:02:42 +08:00
|
|
|
}
|
2003-11-13 22:14:20 +08:00
|
|
|
|
|
|
|
|
|
|
|
static gchar *
|
|
|
|
session_filename (Gimp *gimp)
|
|
|
|
{
|
|
|
|
gchar *filename = gimp_personal_rc_file ("sessionrc");
|
|
|
|
|
|
|
|
if (gimp->session_name)
|
|
|
|
{
|
|
|
|
gchar *tmp = g_strconcat (filename, ".", gimp->session_name, NULL);
|
|
|
|
|
|
|
|
g_free (filename);
|
|
|
|
filename = tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return filename;
|
|
|
|
}
|