glade-catalog.c 24.4 KB
Newer Older
Jose Maria Celorio's avatar
Jose Maria Celorio committed
1 2
/*
 * Copyright (C) 2001 Ximian, Inc.
3
 * Copyright (C) 2004 Imendio AB
Jose Maria Celorio's avatar
Jose Maria Celorio committed
4 5 6 7 8 9 10 11 12 13 14 15 16
 *
 * 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
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Jose Maria Celorio's avatar
Jose Maria Celorio committed
18 19 20 21 22
 *
 * Authors:
 *   Chema Celorio <chema@celorio.com>
 */

23
#include <config.h>
Jose Maria Celorio's avatar
Jose Maria Celorio committed
24 25 26

#include "glade.h"
#include "glade-catalog.h"
27
#include "glade-widget-adaptor.h"
28 29
#include "glade-private.h"
#include "glade-tsort.h"
Jose Maria Celorio's avatar
Jose Maria Celorio committed
30

31 32 33 34 35 36
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <glib.h>
#include <glib/gi18n-lib.h>

37
struct _GladeCatalog
Joaquín Cuenca Abela's avatar
Joaquín Cuenca Abela committed
38
{
39 40
  guint16 major_version;        /* The catalog version               */
  guint16 minor_version;
41

42
  GList *targetable_versions;   /* list of suitable version targets */
43

44
  gchar *library;               /* Library name for backend support  */
Jose Maria Celorio's avatar
Jose Maria Celorio committed
45

46
  gchar *name;                  /* Symbolic catalog name             */
47

48 49
  gchar *prefix;                /* Catalog path prefix               */
   
50 51
  gchar *dep_catalog;           /* Symbolic name of the catalog that
                                 * this catalog depends on           */
52

53 54 55 56
  gchar *domain;                /* The domain to be used to translate
                                 * strings from this catalog (otherwise this 
                                 * defaults to the library name)
                                 */
57

58
  gchar *book;                  /* Devhelp search domain */
Vincent Geddes's avatar
Vincent Geddes committed
59

60
  gchar *icon_prefix;           /* the prefix for icons */
61

62 63 64 65 66 67 68 69 70 71
  GList *widget_groups;         /* List of widget groups (palette)   */
  GList *adaptors;              /* List of widget class adaptors (all)  */

  GladeXmlContext *context;     /* Xml context is stored after open
                                 * before classes are loaded         */

  GModule *module;

  gchar *init_function_name;    /* Catalog's init function name */
  GladeCatalogInitFunc init_function;
72 73
};

74 75
struct _GladeWidgetGroup
{
76 77
  gchar *name;                  /* Group name */
  gchar *title;                 /* Group name in the palette */
78

79
  gboolean expanded;            /* Whether group is expanded in the palette */
80

81
  GList *adaptors;              /* List of class adaptors in the palette    */
82 83
};

84
/* List of catalogs successfully loaded. */
85
static GList *loaded_catalogs = NULL;
86

87 88 89
/* Extra paths to load catalogs from */
static GList *catalog_paths = NULL;

90
static gboolean
91
catalog_get_function (GladeCatalog *catalog,
92 93
                      const gchar  *symbol_name,
                      gpointer     *symbol_ptr)
94
{
95 96
  if (catalog->module == NULL)
    catalog->module = glade_util_load_library (catalog->library);
97

98 99 100 101
  if (catalog->module)
    return g_module_symbol (catalog->module, symbol_name, symbol_ptr);

  return FALSE;
102 103
}

104 105 106
static GladeCatalog *
catalog_allocate (void)
{
107 108 109 110 111 112
  GladeCatalog *catalog;

  catalog = g_slice_new0 (GladeCatalog);

  catalog->library = NULL;
  catalog->name = NULL;
113
  catalog->prefix = NULL;
114 115 116 117 118 119 120 121 122 123 124 125
  catalog->dep_catalog = NULL;
  catalog->domain = NULL;
  catalog->book = NULL;
  catalog->icon_prefix = NULL;
  catalog->init_function_name = NULL;
  catalog->module = NULL;

  catalog->context = NULL;
  catalog->adaptors = NULL;
  catalog->widget_groups = NULL;

  return catalog;
126 127
}

128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170
static void
widget_group_destroy (GladeWidgetGroup *group)
{
  g_return_if_fail (GLADE_IS_WIDGET_GROUP (group));

  g_free (group->name);
  g_free (group->title);
  g_list_free (group->adaptors);

  g_slice_free (GladeWidgetGroup, group);
}

static void
catalog_destroy (GladeCatalog *catalog)
{
  g_return_if_fail (GLADE_IS_CATALOG (catalog));

  g_free (catalog->name);
  g_free (catalog->library);
  g_free (catalog->dep_catalog);
  g_free (catalog->domain);
  g_free (catalog->book);
  g_free (catalog->icon_prefix);
  g_free (catalog->init_function_name);

  if (catalog->adaptors)
    {
      g_list_free (catalog->adaptors);
    }

  if (catalog->widget_groups)
    {
      g_list_foreach (catalog->widget_groups, (GFunc) widget_group_destroy,
                      NULL);
      g_list_free (catalog->widget_groups);
    }

  if (catalog->context)
    glade_xml_context_free (catalog->context);

  g_slice_free (GladeCatalog, catalog);
}

171
static GladeCatalog *
172
catalog_open (const gchar *filename)
Jose Maria Celorio's avatar
Jose Maria Celorio committed
173
{
174 175 176 177 178
  GladeTargetableVersion *version;
  GladeCatalog *catalog;
  GladeXmlContext *context;
  GladeXmlDoc *doc;
  GladeXmlNode *root;
179
  gchar *name;
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200

  /* get the context & root node of the catalog file */
  context = glade_xml_context_new_from_path (filename,
                                             NULL, GLADE_TAG_GLADE_CATALOG);
  if (!context)
    {
      g_warning ("Couldn't open catalog [%s].", filename);
      return NULL;
    }

  doc = glade_xml_context_get_doc (context);
  root = glade_xml_doc_get_root (doc);

  if (!glade_xml_node_verify (root, GLADE_TAG_GLADE_CATALOG))
    {
      g_warning ("Catalog root node is not '%s', skipping %s",
                 GLADE_TAG_GLADE_CATALOG, filename);
      glade_xml_context_free (context);
      return NULL;
    }

201 202 203
  if (!(name = glade_xml_get_property_string_required (root, GLADE_TAG_NAME, NULL)))
    return NULL;

204 205
  catalog = catalog_allocate ();
  catalog->context = context;
206
  catalog->name = name;
207
  catalog->prefix = g_path_get_dirname (filename);
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241

  glade_xml_get_property_version (root, GLADE_TAG_VERSION,
                                  &catalog->major_version,
                                  &catalog->minor_version);

  /* Make one default suitable target */
  version = g_new (GladeTargetableVersion, 1);
  version->major = catalog->major_version;
  version->minor = catalog->minor_version;

  catalog->targetable_versions =
      glade_xml_get_property_targetable_versions (root, GLADE_TAG_TARGETABLE);

  catalog->targetable_versions =
      g_list_prepend (catalog->targetable_versions, version);

  catalog->library = glade_xml_get_property_string (root, GLADE_TAG_LIBRARY);
  catalog->dep_catalog =
      glade_xml_get_property_string (root, GLADE_TAG_DEPENDS);
  catalog->domain = glade_xml_get_property_string (root, GLADE_TAG_DOMAIN);
  catalog->book = glade_xml_get_property_string (root, GLADE_TAG_BOOK);
  catalog->icon_prefix =
      glade_xml_get_property_string (root, GLADE_TAG_ICON_PREFIX);
  catalog->init_function_name =
      glade_xml_get_value_string (root, GLADE_TAG_INIT_FUNCTION);

  if (!catalog->domain)
    catalog->domain = g_strdup (catalog->library);

  /* catalog->icon_prefix defaults to catalog->name */
  if (!catalog->icon_prefix)
    catalog->icon_prefix = g_strdup (catalog->name);

  if (catalog->init_function_name)
242 243 244 245 246 247 248
    {
      if (!catalog_get_function (catalog, catalog->init_function_name,
                                 (gpointer) & catalog->init_function))
        g_warning ("Failed to find and execute catalog '%s' init function '%s'",
                   glade_catalog_get_name (catalog),
                   catalog->init_function_name);
    }
249 250

  return catalog;
251
}
Jose Maria Celorio's avatar
Jose Maria Celorio committed
252

253 254 255
static GHashTable *modules = NULL;

static GModule *
256
catalog_load_library (GladeCatalog *catalog)
257
{
258 259 260 261 262 263
  GModule *module;

  if (modules == NULL)
    modules = g_hash_table_new_full (g_str_hash,
                                     g_str_equal,
                                     (GDestroyNotify) g_free,
264
                                     (GDestroyNotify) g_module_close);
265 266 267 268 269 270 271 272 273 274

  if (catalog->library == NULL)
    return NULL;

  if ((module = g_hash_table_lookup (modules, catalog->library)))
    return module;

  if ((module = glade_util_load_library (catalog->library)))
    g_hash_table_insert (modules, g_strdup (catalog->library), module);
  else
275 276 277
    g_warning ("Failed to load external library '%s' for catalog '%s'",
               catalog->library,
               glade_catalog_get_name (catalog));
278 279

  return module;
280
}
281

282
static gboolean
283
catalog_load_classes (GladeCatalog *catalog, GladeXmlNode *widgets_node)
284
{
285 286 287 288 289 290
  GladeXmlNode *node;
  GModule *module = catalog_load_library (catalog);

  node = glade_xml_node_get_children (widgets_node);
  for (; node; node = glade_xml_node_next (node))
    {
291
      const gchar *node_name;
292 293 294 295 296 297 298 299 300 301 302 303
      GladeWidgetAdaptor *adaptor;

      node_name = glade_xml_node_get_name (node);
      if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_CLASS) != 0)
        continue;

      adaptor = glade_widget_adaptor_from_catalog (catalog, node, module);

      catalog->adaptors = g_list_prepend (catalog->adaptors, adaptor);
    }

  return TRUE;
304 305 306
}

static gboolean
307
catalog_load_group (GladeCatalog *catalog, GladeXmlNode *group_node)
308
{
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358
  GladeWidgetGroup *group;
  GladeXmlNode *node;
  char *title, *translated_title;

  group = g_slice_new0 (GladeWidgetGroup);

  group->name = glade_xml_get_property_string (group_node, GLADE_TAG_NAME);

  if (!group->name)
    {
      g_warning ("Required property 'name' not found in group node");
      widget_group_destroy (group);
      return FALSE;
    }

  title = glade_xml_get_property_string (group_node, GLADE_TAG_TITLE);
  if (!title)
    {
      g_warning ("Required property 'title' not found in group node");
      widget_group_destroy (group);
      return FALSE;
    }

  /* by default, group is expanded in palette  */
  group->expanded = TRUE;

  /* Translate it */
  translated_title = dgettext (catalog->domain, title);
  if (translated_title != title)
    {
      group->title = g_strdup (translated_title);
      g_free (title);
    }
  else
    {
      group->title = title;
    }

  group->adaptors = NULL;

  node = glade_xml_node_get_children (group_node);
  for (; node; node = glade_xml_node_next (node))
    {
      const gchar *node_name;
      GladeWidgetAdaptor *adaptor;
      gchar *name;

      node_name = glade_xml_node_get_name (node);

      if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_CLASS_REF) == 0)
359
        {
360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
          if ((name =
               glade_xml_get_property_string (node, GLADE_TAG_NAME)) == NULL)
            {
              g_warning ("Couldn't find required property on %s",
                         GLADE_TAG_GLADE_WIDGET_CLASS);
              continue;
            }

          if ((adaptor = glade_widget_adaptor_get_by_name (name)) == NULL)
            {
              g_warning ("Tried to include undefined widget "
                         "class '%s' in a widget group", name);
              g_free (name);
              continue;
            }
          g_free (name);

          group->adaptors = g_list_prepend (group->adaptors, adaptor);

379
        }
380
      else if (strcmp (node_name, GLADE_TAG_DEFAULT_PALETTE_STATE) == 0)
381
        {
382 383 384
          group->expanded =
              glade_xml_get_property_boolean
              (node, GLADE_TAG_EXPANDED, group->expanded);
385
        }
386
    }
387

388 389 390 391 392
  group->adaptors = g_list_reverse (group->adaptors);

  catalog->widget_groups = g_list_prepend (catalog->widget_groups, group);

  return TRUE;
Jose Maria Celorio's avatar
Jose Maria Celorio committed
393
}
394

395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
static void
catalog_load (GladeCatalog *catalog)
{
  GladeXmlDoc *doc;
  GladeXmlNode *root;
  GladeXmlNode *node;

  g_return_if_fail (catalog->context != NULL);

  doc = glade_xml_context_get_doc (catalog->context);
  root = glade_xml_doc_get_root (doc);
  node = glade_xml_node_get_children (root);

  for (; node; node = glade_xml_node_next (node))
    {
      const gchar *node_name;

      node_name = glade_xml_node_get_name (node);
      if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_CLASSES) == 0)
        {
          catalog_load_classes (catalog, node);
        }
      else if (strcmp (node_name, GLADE_TAG_GLADE_WIDGET_GROUP) == 0)
        {
          catalog_load_group (catalog, node);
        }
      else
        continue;
    }

  catalog->widget_groups = g_list_reverse (catalog->widget_groups);
  catalog->context = (glade_xml_context_free (catalog->context), NULL);

  return;
}

431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447
static GladeCatalog *
catalog_find_by_name (GList *catalogs, const gchar *name)
{
  if (name)
    {
      GList *l;
      for (l = catalogs; l; l = g_list_next (l))
        {
          GladeCatalog *catalog = l->data;
          if (g_strcmp0 (catalog->name, name) == 0)
            return catalog;
        }
    }
  
  return NULL;
}

448
static gint
449
catalog_name_cmp (gconstpointer a, gconstpointer b)
450
{
451
  return (a && b) ? g_strcmp0 (GLADE_CATALOG(a)->name, GLADE_CATALOG(b)->name) : 0;
452 453
}

454
static GList *
455
glade_catalog_tsort (GList *catalogs, gboolean loading)
456
{
457 458 459 460 461
  GList *l, *sorted = NULL;
  GList *deps = NULL;

  /* Sort alphabetically first */
  catalogs = g_list_sort (catalogs, catalog_name_cmp);
462

463 464
  /* Generate dependency graph edges */
  for (l = catalogs; l; l = g_list_next (l))
465
    {
466
      GladeCatalog *catalog = l->data, *dep;
467

468 469
      if (!catalog->dep_catalog)
        continue;
470

471 472 473 474 475 476 477
      if ((dep = catalog_find_by_name ((loading) ? catalogs : loaded_catalogs,
                                       catalog->dep_catalog)))
        deps = _node_edge_prepend (deps, dep, catalog);
      else
        g_critical ("Catalog %s depends on catalog %s, not found",
                    catalog->name, catalog->dep_catalog);
    }
478

479
  sorted = _glade_tsort (&catalogs, &deps);
480

481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
  if (deps)
    {
      GList *l, *cycles = NULL;
      
      g_warning ("Circular dependency detected loading catalogs, they will be ignored");

      for (l = deps; l; l = g_list_next (l))
        {
          _NodeEdge *edge = l->data;

          g_message ("\t%s depends on %s",
                     GLADE_CATALOG (edge->successor)->name,
                     GLADE_CATALOG (edge->successor)->dep_catalog);
          
          if (loading && !g_list_find (cycles, edge->successor))
            cycles = g_list_prepend (cycles, edge->successor);
497 498
        }

499 500 501 502 503
      if (cycles)
        g_list_free_full (cycles, (GDestroyNotify) catalog_destroy);

      _node_edge_list_free (deps);
    }
504 505 506 507 508 509

  return sorted;
}

static GList *
catalogs_from_path (GList *catalogs, const gchar *path)
510
{
511 512 513 514 515
  GladeCatalog *catalog;
  GDir *dir;
  GError *error = NULL;
  const gchar *filename;

516 517 518 519
  /* Silent return if the directory didn't exist */
  if (!g_file_test (path, G_FILE_TEST_IS_DIR))
    return catalogs;

520 521 522 523 524 525 526 527 528
  if ((dir = g_dir_open (path, 0, &error)) != NULL)
    {
      while ((filename = g_dir_read_name (dir)))
        {
          gchar *catalog_filename;

          if (!g_str_has_suffix (filename, ".xml"))
            continue;

529 530 531 532 533 534 535 536 537 538 539 540
          /* Special case, ignore gresource files (which are present
           * while running tests)
           */
          if (g_str_has_suffix (filename, ".gresource.xml"))
            continue;

          /* If we're running in the bundle, don't ever try to load
           * anything except the GTK+ catalog
           */
          if (g_getenv (GLADE_ENV_BUNDLED) != NULL &&
              strcmp (filename, "gtk+.xml") != 0)
            continue;
541

542 543 544 545 546 547 548 549
          catalog_filename = g_build_filename (path, filename, NULL);
          catalog = catalog_open (catalog_filename);
          g_free (catalog_filename);

          if (catalog)
            {
              /* Verify that we are not loading the same catalog twice !
               */
550
              if (catalog_find_by_name (catalogs, catalog->name))
551
                catalog_destroy (catalog);
552 553
              else
                catalogs = g_list_prepend (catalogs, catalog);
554 555 556 557
            }
          else
            g_warning ("Unable to open the catalog file %s.\n", filename);
        }
558 559

      g_dir_close (dir);
560 561 562 563 564 565 566
    }
  else
    g_warning ("Failed to open catalog directory '%s': %s", path,
               error->message);


  return catalogs;
567 568
}

569 570 571 572 573 574 575 576 577 578 579 580
/**
 * glade_catalog_add_path:
 * @path:
 * 
 * Adds a new path to the list of path to look catalogs for.
 */
void
glade_catalog_add_path (const gchar *path)
{
  g_return_if_fail (path != NULL);

  if (g_list_find_custom (catalog_paths, path, (GCompareFunc) g_strcmp0) == NULL)
581
    catalog_paths = g_list_append (catalog_paths, g_strdup (path));
582 583 584 585 586 587 588 589 590 591 592 593 594 595 596
}

/**
 * glade_catalog_remove_path:
 * @path:
 * 
 * Remove path from the list of path to look catalogs for.
 * NULL to remove all paths.
 */
void
glade_catalog_remove_path (const gchar *path)
{
  GList *l;
  
  if (path == NULL)
597 598 599 600
    {
      g_list_free_full (catalog_paths, g_free);
      catalog_paths = NULL;
    }
601
  else if ((l = g_list_find_custom (catalog_paths, path, (GCompareFunc) g_strcmp0)))
602 603 604
    {
      catalog_paths = g_list_remove_link (catalog_paths, l); 
    }
605 606
}

607 608 609 610 611 612 613 614 615 616 617
/**
 * glade_catalog_get_extra_paths:
 *
 * Returns a list paths added by glade_catalog_add_path()
 */
const GList *
glade_catalog_get_extra_paths (void)
{
  return catalog_paths;
}

618 619 620 621 622 623 624 625 626 627
/**
 * glade_catalog_load_all:
 * 
 * Loads all available catalogs in the system.
 * First loads catalogs from GLADE_ENV_CATALOG_PATH,
 * then from glade_app_get_catalogs_dir() and finally from paths specified with
 * glade_catalog_add_path()
 *
 * Returns: the list of loaded GladeCatalog *
 */
628 629 630
const GList *
glade_catalog_load_all (void)
{
631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655
  GList *catalogs = NULL, *l, *adaptors;
  GladeCatalog *catalog;
  const gchar *search_path;
  gchar **split;
  GString *icon_warning = NULL;
  gint i;


  /* Make sure we don't init the catalogs twice */
  if (loaded_catalogs)
    return loaded_catalogs;

  /* First load catalogs from user specified directories ... */
  if ((search_path = g_getenv (GLADE_ENV_CATALOG_PATH)) != NULL)
    {
      if ((split = g_strsplit (search_path, ":", 0)) != NULL)
        {
          for (i = 0; split[i] != NULL; i++)
            catalogs = catalogs_from_path (catalogs, split[i]);

          g_strfreev (split);
        }
    }

  /* ... Then load catalogs from standard install directory */
656 657
  if (g_getenv (GLADE_ENV_TESTING) == NULL)
    catalogs = catalogs_from_path (catalogs, glade_app_get_catalogs_dir ());
658

659 660 661 662
  /* And then load catalogs from extra paths */
  for (l = catalog_paths; l; l = g_list_next (l))
    catalogs = catalogs_from_path (catalogs, l->data);
  
663 664 665 666
  /* Catalogs need dependancies, most catalogs depend on
   * the gtk+ catalog, but some custom toolkits may depend
   * on the gnome catalog for instance.
   */
667
  catalogs = glade_catalog_tsort (catalogs, TRUE);
668 669

  /* After sorting, execute init function and then load */
670
  for (l = catalogs; l; l = g_list_next (l))
671 672 673 674 675 676
    {
      catalog = l->data;
      if (catalog->init_function)
        catalog->init_function (catalog->name);
    }

677
  for (l = catalogs; l; l = g_list_next (l))
678 679 680 681 682 683 684 685
    {
      catalog = l->data;
      catalog_load (catalog);
    }

  /* Print a summery of widget adaptors missing icons.
   */
  adaptors = glade_widget_adaptor_list_adaptors ();
686
  for (l = adaptors; l; l = g_list_next (l))
687 688 689
    {
      GladeWidgetAdaptor *adaptor = l->data;

690 691
      /* Dont print missing icons in unit tests */
      if (glade_widget_adaptor_get_missing_icon (adaptor) &&
692
          g_getenv (GLADE_ENV_TESTING) == NULL)
693 694 695 696 697 698
        {
          if (!icon_warning)
            icon_warning = g_string_new ("Glade needs artwork; "
                                         "a default icon will be used for "
                                         "the following classes:");

699 700 701 702
          g_string_append_printf (icon_warning,
                                  "\n\t%s\tneeds an icon named '%s'",
                                  glade_widget_adaptor_get_name (adaptor), 
                                  glade_widget_adaptor_get_missing_icon (adaptor));
703 704
        }
    }
705

706 707 708 709 710 711 712 713 714 715 716
  g_list_free (adaptors);

  if (icon_warning)
    {
      g_message ("%s", icon_warning->str);
      g_string_free (icon_warning, TRUE);
    }

  loaded_catalogs = catalogs;

  return loaded_catalogs;
717
}
718

719 720 721 722 723 724
/**
 * glade_catalog_get_name:
 * @catalog: a catalog object
 * 
 * Returns: The symbolic catalog name.
 */
725
G_CONST_RETURN gchar *
726
glade_catalog_get_name (GladeCatalog *catalog)
727
{
728
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);
729

730
  return catalog->name;
731 732
}

733 734 735 736 737 738 739 740 741 742 743 744 745 746
/**
 * glade_catalog_get_prefix:
 * @catalog: a catalog object
 * 
 * Returns: The catalog path prefix.
 */
G_CONST_RETURN gchar *
glade_catalog_get_prefix (GladeCatalog *catalog)
{
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);

  return catalog->prefix;
}

747 748 749 750 751 752
/**
 * glade_catalog_get_book:
 * @catalog: a catalog object
 * 
 * Returns: The Devhelp search domain.
 */
753
G_CONST_RETURN gchar *
754
glade_catalog_get_book (GladeCatalog *catalog)
755
{
756
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);
757

758
  return catalog->book;
759 760
}

761 762 763 764 765 766
/**
 * glade_catalog_get_domain:
 * @catalog: a catalog object
 * 
 * Returns: The domain to be used to translate strings from this catalog
 */
767
G_CONST_RETURN gchar *
768
glade_catalog_get_domain (GladeCatalog *catalog)
769
{
770
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);
771

772
  return catalog->domain;
773 774
}

775 776 777 778 779 780
/**
 * glade_catalog_get_icon_prefix:
 * @catalog: a catalog object
 * 
 * Returns: The prefix for icons.
 */
781
G_CONST_RETURN gchar *
782
glade_catalog_get_icon_prefix (GladeCatalog *catalog)
783
{
784
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);
785

786
  return catalog->icon_prefix;
787 788
}

789 790 791 792 793 794
/**
 * glade_catalog_get_major_version:
 * @catalog: a catalog object
 * 
 * Returns: The catalog version
 */
795
guint16
796
glade_catalog_get_major_version (GladeCatalog *catalog)
797
{
798
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), 0);
799

800
  return catalog->major_version;
801 802
}

803 804 805 806 807 808
/**
 * glade_catalog_get_minor_version:
 * @catalog: a catalog object
 * 
 * Returns: The catalog minor version
 */
809
guint16
810
glade_catalog_get_minor_version (GladeCatalog *catalog)
811
{
812
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), 0);
813

814
  return catalog->minor_version;
815 816
}

817 818 819 820 821 822
/**
 * glade_catalog_get_targets:
 * @catalog: a catalog object
 * 
 * Returns: the list of suitable version targets.
 */
823
GList *
824
glade_catalog_get_targets (GladeCatalog *catalog)
825
{
826
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);
827

828
  return catalog->targetable_versions;
829 830
}

831 832 833 834 835 836
/**
 * glade_catalog_get_widget_groups:
 * @catalog: a catalog object
 * 
 * Returns: the list of widget groups (palette)
 */
837
GList *
838
glade_catalog_get_widget_groups (GladeCatalog *catalog)
839
{
840
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);
841

842
  return catalog->widget_groups;
843 844
}

845 846 847 848 849 850
/**
 * glade_catalog_get_adaptors:
 * @catalog: a catalog object
 * 
 * Returns: the list of widget class adaptors
 */
851
GList *
852
glade_catalog_get_adaptors (GladeCatalog *catalog)
853
{
854
  g_return_val_if_fail (GLADE_IS_CATALOG (catalog), NULL);
855

856
  return catalog->adaptors;
857
}
858

859 860 861 862 863 864
/**
 * glade_catalog_is_loaded:
 * @name: a catalog object
 * 
 * Returns: Whether @name is loaded or not
 */
865
gboolean
866
glade_catalog_is_loaded (const gchar *name)
867
{
868 869
  g_return_val_if_fail (name != NULL, FALSE);
  g_assert (loaded_catalogs != NULL);
870
  return catalog_find_by_name (loaded_catalogs, name) != NULL;
871
}
872

873 874 875 876 877
/**
 * glade_catalog_destroy_all:
 * 
 * Destroy and free all resources related with every loaded catalog.
 */
878 879
void
glade_catalog_destroy_all (void)
880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896
{
  /* close catalogs */
  if (loaded_catalogs)
    {
      GList *l;
      for (l = loaded_catalogs; l; l = l->next)
        catalog_destroy (GLADE_CATALOG (l->data));
      g_list_free (loaded_catalogs);
      loaded_catalogs = NULL;
    }

  /* close plugin modules */
  if (modules)
    {
      g_hash_table_destroy (modules);
      modules = NULL;
    }
897
}
898

899 900 901 902 903 904
/**
 * glade_widget_group_get_name:
 * @group: a widget group
 * 
 * Returns: the widget group name
 */
905
const gchar *
906
glade_widget_group_get_name (GladeWidgetGroup *group)
907
{
908
  g_return_val_if_fail (group != NULL, NULL);
909

910
  return group->name;
911 912
}

913 914 915 916 917 918
/**
 * glade_widget_group_get_title:
 * @group: a widget group
 * 
 * Returns: the widget group name used in the palette
 */
919
const gchar *
920
glade_widget_group_get_title (GladeWidgetGroup *group)
921
{
922
  g_return_val_if_fail (group != NULL, NULL);
923

924
  return group->title;
925 926
}

927 928 929 930 931 932
/**
 * glade_widget_group_get_expanded:
 * @group: a widget group
 * 
 * Returns: Whether group is expanded in the palette
 */
933
gboolean
934
glade_widget_group_get_expanded (GladeWidgetGroup *group)
935
{
936
  g_return_val_if_fail (group != NULL, FALSE);
937

938
  return group->expanded;
939 940
}

941 942 943 944 945 946
/**
 * glade_widget_group_get_adaptors:
 * @group: a widget group
 * 
 * Returns: a list of class adaptors in the palette
 */
947
const GList *
948
glade_widget_group_get_adaptors (GladeWidgetGroup *group)
949
{
950
  g_return_val_if_fail (group != NULL, NULL);
951

952
  return group->adaptors;
953
}
954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970

/* Private API */

GladeCatalog *
_glade_catalog_get_catalog (const gchar *name)
{
  g_return_val_if_fail (name != NULL, NULL);
  g_assert (loaded_catalogs != NULL);

  return catalog_find_by_name (loaded_catalogs, name);
}

GList *
_glade_catalog_tsort (GList *catalogs)
{
  return glade_catalog_tsort (catalogs, FALSE);
}