2001-08-11 15:47:35 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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 "config.h"
|
|
|
|
|
2002-05-03 20:45:22 +08:00
|
|
|
#include <glib-object.h>
|
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "libgimpconfig/gimpconfig.h"
|
2001-08-11 15:47:35 +08:00
|
|
|
|
2005-01-26 03:11:26 +08:00
|
|
|
#include "core-types.h"
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2003-01-25 01:38:24 +08:00
|
|
|
#include "gimp.h"
|
2002-05-15 19:05:32 +08:00
|
|
|
#include "gimpdocumentlist.h"
|
2001-08-11 15:47:35 +08:00
|
|
|
#include "gimpimagefile.h"
|
|
|
|
|
|
|
|
|
2003-03-06 04:21:50 +08:00
|
|
|
static void gimp_document_list_config_iface_init (gpointer iface,
|
|
|
|
gpointer iface_data);
|
2003-10-11 22:30:18 +08:00
|
|
|
static gboolean gimp_document_list_serialize (GimpConfig *config,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data);
|
2003-10-11 22:30:18 +08:00
|
|
|
static gboolean gimp_document_list_deserialize (GimpConfig *config,
|
2003-03-06 04:21:50 +08:00
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data);
|
2002-05-15 01:31:58 +08:00
|
|
|
|
|
|
|
|
2002-05-15 21:48:47 +08:00
|
|
|
static const gchar *document_symbol = "document";
|
|
|
|
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
GType
|
2002-05-15 19:05:32 +08:00
|
|
|
gimp_document_list_get_type (void)
|
2002-05-15 01:31:58 +08:00
|
|
|
{
|
2002-05-15 19:05:32 +08:00
|
|
|
static GType document_list_type = 0;
|
2002-05-15 01:31:58 +08:00
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
if (! document_list_type)
|
2002-05-15 01:31:58 +08:00
|
|
|
{
|
2002-05-15 19:05:32 +08:00
|
|
|
static const GTypeInfo document_list_info =
|
2002-05-15 01:31:58 +08:00
|
|
|
{
|
2002-05-15 19:05:32 +08:00
|
|
|
sizeof (GimpDocumentListClass),
|
2002-05-15 01:31:58 +08:00
|
|
|
NULL, /* base_init */
|
|
|
|
NULL, /* base_finalize */
|
|
|
|
NULL, /* class_init */
|
|
|
|
NULL, /* class_finalize */
|
|
|
|
NULL, /* class_data */
|
2002-05-15 19:05:32 +08:00
|
|
|
sizeof (GimpDocumentList),
|
2002-05-15 01:31:58 +08:00
|
|
|
0, /* n_preallocs */
|
|
|
|
NULL /* instance_init */
|
|
|
|
};
|
2003-10-11 22:30:18 +08:00
|
|
|
static const GInterfaceInfo document_list_iface_info =
|
|
|
|
{
|
2002-05-15 19:05:32 +08:00
|
|
|
gimp_document_list_config_iface_init,
|
2003-10-11 22:30:18 +08:00
|
|
|
NULL, /* iface_finalize */
|
2002-05-15 01:31:58 +08:00
|
|
|
NULL /* iface_data */
|
|
|
|
};
|
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
document_list_type = g_type_register_static (GIMP_TYPE_LIST,
|
2002-05-15 19:05:32 +08:00
|
|
|
"GimpDocumentList",
|
|
|
|
&document_list_info, 0);
|
2002-05-15 01:31:58 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
g_type_add_interface_static (document_list_type, GIMP_TYPE_CONFIG,
|
2002-05-15 19:05:32 +08:00
|
|
|
&document_list_iface_info);
|
2002-05-15 01:31:58 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
return document_list_type;
|
2002-05-15 01:31:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-05-15 19:05:32 +08:00
|
|
|
gimp_document_list_config_iface_init (gpointer iface,
|
|
|
|
gpointer iface_data)
|
2001-08-11 15:47:35 +08:00
|
|
|
{
|
2002-05-15 01:31:58 +08:00
|
|
|
GimpConfigInterface *config_iface = (GimpConfigInterface *) iface;
|
2001-08-11 15:47:35 +08:00
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
config_iface->serialize = gimp_document_list_serialize;
|
|
|
|
config_iface->deserialize = gimp_document_list_deserialize;
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
static gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_document_list_serialize (GimpConfig *config,
|
2003-03-06 04:21:50 +08:00
|
|
|
GimpConfigWriter *writer,
|
|
|
|
gpointer data)
|
2001-08-11 15:47:35 +08:00
|
|
|
{
|
2003-03-06 04:21:50 +08:00
|
|
|
GList *list;
|
2002-05-15 01:31:58 +08:00
|
|
|
|
2003-10-11 22:30:18 +08:00
|
|
|
for (list = GIMP_LIST (config)->list; list; list = list->next)
|
2001-08-11 15:47:35 +08:00
|
|
|
{
|
2003-03-06 04:21:50 +08:00
|
|
|
gimp_config_writer_open (writer, document_symbol);
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_config_writer_string (writer, GIMP_OBJECT (list->data)->name);
|
2003-03-06 04:21:50 +08:00
|
|
|
gimp_config_writer_close (writer);
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|
2002-05-15 01:31:58 +08:00
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
return TRUE;
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 01:31:58 +08:00
|
|
|
static gboolean
|
2003-10-11 22:30:18 +08:00
|
|
|
gimp_document_list_deserialize (GimpConfig *config,
|
|
|
|
GScanner *scanner,
|
|
|
|
gint nest_level,
|
|
|
|
gpointer data)
|
2001-08-11 15:47:35 +08:00
|
|
|
{
|
2003-10-11 22:30:18 +08:00
|
|
|
GimpDocumentList *document_list = GIMP_DOCUMENT_LIST (config);
|
2003-01-25 01:38:24 +08:00
|
|
|
GTokenType token;
|
|
|
|
gint size;
|
|
|
|
|
2002-05-15 19:59:51 +08:00
|
|
|
size = GPOINTER_TO_INT (data);
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2002-05-15 21:48:47 +08:00
|
|
|
g_scanner_scope_add_symbol (scanner, 0,
|
|
|
|
document_symbol, (gpointer) document_symbol);
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
|
2002-05-27 22:04:21 +08:00
|
|
|
while (g_scanner_peek_next_token (scanner) == token)
|
2002-03-28 07:15:00 +08:00
|
|
|
{
|
|
|
|
token = g_scanner_get_next_token (scanner);
|
|
|
|
|
|
|
|
switch (token)
|
|
|
|
{
|
|
|
|
case G_TOKEN_LEFT_PAREN:
|
|
|
|
token = G_TOKEN_SYMBOL;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_SYMBOL:
|
|
|
|
token = G_TOKEN_RIGHT_PAREN;
|
2002-05-15 21:48:47 +08:00
|
|
|
if (scanner->value.v_symbol == document_symbol)
|
2002-03-28 07:15:00 +08:00
|
|
|
{
|
2004-11-26 22:45:10 +08:00
|
|
|
gchar *uri = NULL;
|
2002-03-28 07:15:00 +08:00
|
|
|
|
|
|
|
if (! gimp_scanner_parse_string (scanner, &uri))
|
|
|
|
{
|
|
|
|
token = G_TOKEN_STRING;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2004-11-26 22:45:10 +08:00
|
|
|
if (uri)
|
|
|
|
{
|
|
|
|
GimpImagefile *imagefile;
|
|
|
|
|
|
|
|
imagefile = gimp_imagefile_new (document_list->gimp, uri);
|
2002-05-15 19:05:32 +08:00
|
|
|
|
2004-11-26 22:45:10 +08:00
|
|
|
g_free (uri);
|
2002-03-28 07:15:00 +08:00
|
|
|
|
2004-11-26 22:45:10 +08:00
|
|
|
gimp_container_add (GIMP_CONTAINER (document_list),
|
|
|
|
GIMP_OBJECT (imagefile));
|
2002-05-27 22:04:21 +08:00
|
|
|
|
2004-11-26 22:45:10 +08:00
|
|
|
g_object_unref (imagefile);
|
|
|
|
}
|
2002-03-28 07:15:00 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case G_TOKEN_RIGHT_PAREN:
|
|
|
|
token = G_TOKEN_LEFT_PAREN;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default: /* do nothing */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2002-05-15 01:31:58 +08:00
|
|
|
|
2002-06-08 04:23:33 +08:00
|
|
|
gimp_list_reverse (GIMP_LIST (document_list));
|
|
|
|
|
2002-06-18 03:36:33 +08:00
|
|
|
return gimp_config_deserialize_return (scanner, token, nest_level);
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|
|
|
|
|
2002-05-15 01:31:58 +08:00
|
|
|
GimpContainer *
|
2003-01-25 01:38:24 +08:00
|
|
|
gimp_document_list_new (Gimp *gimp)
|
2001-08-11 15:47:35 +08:00
|
|
|
{
|
2003-01-25 01:38:24 +08:00
|
|
|
GimpDocumentList *document_list;
|
|
|
|
|
|
|
|
g_return_val_if_fail (GIMP_IS_GIMP (gimp), NULL);
|
2002-05-15 01:31:58 +08:00
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
document_list = g_object_new (GIMP_TYPE_DOCUMENT_LIST,
|
|
|
|
"name", "document_list",
|
|
|
|
"children_type", GIMP_TYPE_IMAGEFILE,
|
|
|
|
"policy", GIMP_CONTAINER_POLICY_STRONG,
|
|
|
|
NULL);
|
2003-01-25 01:38:24 +08:00
|
|
|
|
|
|
|
document_list->gimp = gimp;
|
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
return GIMP_CONTAINER (document_list);
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|
|
|
|
|
2002-04-19 20:05:47 +08:00
|
|
|
GimpImagefile *
|
2002-05-15 19:05:32 +08:00
|
|
|
gimp_document_list_add_uri (GimpDocumentList *document_list,
|
2004-05-14 08:01:11 +08:00
|
|
|
const gchar *uri,
|
|
|
|
const gchar *mime_type)
|
2001-08-11 15:47:35 +08:00
|
|
|
{
|
|
|
|
GimpImagefile *imagefile;
|
2002-05-15 01:31:58 +08:00
|
|
|
GimpContainer *container;
|
2001-08-11 15:47:35 +08:00
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
g_return_val_if_fail (GIMP_IS_DOCUMENT_LIST (document_list), NULL);
|
2002-04-19 20:05:47 +08:00
|
|
|
g_return_val_if_fail (uri != NULL, NULL);
|
2001-08-11 15:47:35 +08:00
|
|
|
|
2002-05-15 19:05:32 +08:00
|
|
|
container = GIMP_CONTAINER (document_list);
|
2002-05-15 01:31:58 +08:00
|
|
|
|
|
|
|
imagefile = (GimpImagefile *) gimp_container_get_child_by_name (container,
|
|
|
|
uri);
|
2001-08-11 15:47:35 +08:00
|
|
|
|
|
|
|
if (imagefile)
|
|
|
|
{
|
2002-05-15 01:31:58 +08:00
|
|
|
gimp_container_reorder (container, GIMP_OBJECT (imagefile), 0);
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2003-01-25 01:38:24 +08:00
|
|
|
imagefile = gimp_imagefile_new (document_list->gimp, uri);
|
2002-05-15 01:31:58 +08:00
|
|
|
gimp_container_add (container, GIMP_OBJECT (imagefile));
|
2003-01-06 06:07:10 +08:00
|
|
|
g_object_unref (imagefile);
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|
2002-04-19 20:05:47 +08:00
|
|
|
|
2004-05-14 08:01:11 +08:00
|
|
|
g_object_set (imagefile->thumbnail,
|
|
|
|
"image-mimetype", mime_type,
|
|
|
|
NULL);
|
|
|
|
|
2002-04-19 20:05:47 +08:00
|
|
|
return imagefile;
|
2001-08-11 15:47:35 +08:00
|
|
|
}
|