Beispiel #1
0
/**
 * glade_app_get_project_by_path:
 * @project_path: The path of an open project
 *
 * Finds an open project with @path
 *
 * Returns: A #GladeProject, or NULL if no such open project was found
 */
GladeProject *
glade_app_get_project_by_path (const gchar *project_path)
{
  GladeApp *app;
  GList *l;
  gchar *canonical_path;

  if (project_path == NULL)
    return NULL;

  app = glade_app_get ();

  canonical_path = glade_util_canonical_path (project_path);

  for (l = app->priv->projects; l; l = l->next)
    {
      GladeProject *project = (GladeProject *) l->data;

      if (glade_project_get_path (project) &&
          strcmp (canonical_path, glade_project_get_path (project)) == 0)
        {
          g_free (canonical_path);
          return project;
        }
    }

  g_free (canonical_path);

  return NULL;
}
Beispiel #2
0
GList *
glade_app_get_catalogs (void)
{
  GladeApp *app = glade_app_get ();

  return app->priv->catalogs;
}
Beispiel #3
0
void
glade_app_set_window (GtkWidget *window)
{
  GladeApp *app = glade_app_get ();

  app->priv->window = window;
}
Beispiel #4
0
/*
 * glade_app_set_accel_group:
 *
 * Sets @accel_group to app.
 * The acceleration group will made available for editor dialog windows
 * from the plugin backend.
 */
void
glade_app_set_accel_group (GtkAccelGroup *accel_group)
{
  GladeApp *app;
  g_return_if_fail (GTK_IS_ACCEL_GROUP (accel_group));

  app = glade_app_get ();

  app->priv->accel_group = accel_group;
}
Beispiel #5
0
void
glade_app_search_docs (const gchar *book,
		       const gchar *page, 
		       const gchar *search)
{
  GladeApp *app;

  app = glade_app_get ();

  g_signal_emit (G_OBJECT (app), glade_app_signals[DOC_SEARCH], 0, 
		 book, page, search);
}
Beispiel #6
0
void
glade_app_remove_project (GladeProject *project)
{
  GladeApp *app;
  g_return_if_fail (GLADE_IS_PROJECT (project));

  app = glade_app_get ();

  app->priv->projects = g_list_remove (app->priv->projects, project);

  /* Its safe to just release the project as the project emits a
   * "close" signal and everyone is responsable for cleaning up at
   * that point.
   */
  g_object_unref (project);
}
Beispiel #7
0
void
glade_app_add_project (GladeProject *project)
{
  GladeApp *app;

  g_return_if_fail (GLADE_IS_PROJECT (project));

  app = glade_app_get ();

  /* If the project was previously loaded, don't re-load */
  if (g_list_find (app->priv->projects, project) != NULL)
    return;

  /* Take a reference for GladeApp here... */
  app->priv->projects = g_list_append (app->priv->projects, g_object_ref (project));
}
Beispiel #8
0
GladeCatalog *
glade_app_get_catalog (const gchar *name)
{
  GladeApp *app = glade_app_get ();
  GList *list;
  GladeCatalog *catalog;

  g_return_val_if_fail (name && name[0], NULL);

  for (list = app->priv->catalogs; list; list = list->next)
    {
      catalog = list->data;
      if (!strcmp (glade_catalog_get_name (catalog), name))
        return catalog;
    }
  return NULL;
}
Beispiel #9
0
gboolean
glade_app_is_project_loaded (const gchar *project_path)
{
  GladeApp *app;
  GList *list;
  gboolean loaded = FALSE;

  if (project_path == NULL)
    return FALSE;

  app = glade_app_get ();

  for (list = app->priv->projects; list; list = list->next)
    {
      GladeProject *cur_project = GLADE_PROJECT (list->data);

      if ((loaded = glade_project_get_path (cur_project) &&
           (strcmp (glade_project_get_path (cur_project), project_path) == 0)))
        break;
    }

  return loaded;
}
Beispiel #10
0
int
main (int   argc,
      char *argv[])
{
  GList *adaptors, *l;

  gtk_test_init (&argc, &argv, NULL);

  glade_init ();
  glade_app_get ();

  adaptors = g_list_sort (glade_widget_adaptor_list_adaptors (), adaptor_cmp);
    
  for (l = adaptors; l; l = l->next)
    {
      GladeWidgetAdaptor *adaptor = l->data;
      GType               adaptor_type;

      adaptor_type = glade_widget_adaptor_get_object_type (adaptor);

      if (G_TYPE_IS_INSTANTIATABLE (adaptor_type) && !G_TYPE_IS_ABSTRACT (adaptor_type) &&
	  /* FIXME: FileChooserButton leaks a GTask which will crash in the following test */
	  adaptor_type != GTK_TYPE_FILE_CHOOSER_BUTTON &&
          /* FIXME: GtkRecentChooser tries to remove an unknown source id */
	  !g_type_is_a (adaptor_type, GTK_TYPE_RECENT_CHOOSER))
	{
	  gchar *test_path = g_strdup_printf ("/CreateWidget/%s", glade_widget_adaptor_get_name (adaptor));

	  g_test_add_data_func (test_path, adaptor, test_create_widget);

	  g_free (test_path);
	}
    }
  g_list_free (adaptors);

  return g_test_run ();
}
Beispiel #11
0
int
main (int argc, char **argv)
{
  GladePreviewer *app;
  GOptionContext *context;
  GError *error = NULL;
  GObject *toplevel = NULL;

#ifdef ENABLE_NLS
  setlocale (LC_ALL, "");
  bindtextdomain (GETTEXT_PACKAGE, glade_app_get_locale_dir ());
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);
#endif

  context = g_option_context_new (_("- previews a glade UI definition"));
  g_option_context_add_main_entries (context, option_entries, GETTEXT_PACKAGE);
  g_option_context_add_group (context, gtk_get_option_group (TRUE));
  
  if (!g_option_context_parse (context, &argc, &argv, &error))
    {
      g_printerr (_("%s\nRun '%s --help' to see a full list of available command line "
                   "options.\n"), error->message, argv[0]);
      g_error_free (error);
      g_option_context_free (context);
      return 1;
    }

  g_option_context_free (context);

  if (version)
    {
      g_print ("glade-previewer " VERSION "\n");
      return 0;
    }

  if (!listen && !file_name)
    {
      g_printerr (_("Either --listen or --filename must be specified.\n"));
      return 0;
    }

  gtk_init (&argc, &argv);
  glade_app_get ();

  app = glade_previewer_new (file_name, toplevel_name);
  gtk_widget_show (GTK_WIDGET (app->window));
  
  if (css_file_name)
    glade_preview_window_set_css_file (app->window, css_file_name);

  if (listen)
    {
#ifdef WINDOWS
      GIOChannel *input = g_io_channel_win32_new_fd (fileno (stdin));
#else
      GIOChannel *input = g_io_channel_unix_new (fileno (stdin));
#endif

      app->is_template = template;

      g_io_add_watch (input, G_IO_IN | G_IO_HUP, on_data_incoming, app);

      gtk_main ();
    }
  else if (template)
Beispiel #12
0
GtkAccelGroup *
glade_app_get_accel_group (void)
{
  return glade_app_get ()->priv->accel_group;
}
Beispiel #13
0
/**
 * glade_app_get_catalogs:
 *
 * Return value: (element-type GladeCatalog): catalogs
 */
GList *
glade_app_get_projects (void)
{
  GladeApp *app = glade_app_get ();
  return app->priv->projects;
}
Beispiel #14
0
GladeClipboard *
glade_app_get_clipboard (void)
{
  GladeApp *app = glade_app_get ();
  return app->priv->clipboard;
}
Beispiel #15
0
GtkWidget *
glade_app_get_window (void)
{
  GladeApp *app = glade_app_get ();
  return app->priv->window;
}
Beispiel #16
0
/**
 * glade_app_config_save
 *
 * Saves the GKeyFile to "g_get_user_config_dir()/GLADE_CONFIG_FILENAME"
 *
 * Return 0 on success.
 */
gint
glade_app_config_save ()
{
  GIOChannel *channel;
  GIOStatus status;
  gchar *data = NULL, *filename;
  const gchar *config_dir = g_get_user_config_dir ();
  GError *error = NULL;
  gsize size, written, bytes_written = 0;
  static gboolean error_shown = FALSE;
  GladeApp *app;

  /* If we had any errors; wait untill next session to retry.
   */
  if (error_shown)
    return -1;

  app = glade_app_get ();

  /* Just in case... try to create the config directory */
  if (g_file_test (config_dir, G_FILE_TEST_IS_DIR) == FALSE)
    {
      if (g_file_test (config_dir, G_FILE_TEST_EXISTS))
        {
          /* Config dir exists but is not a directory */
          glade_util_ui_message
              (glade_app_get_window (),
               GLADE_UI_ERROR, NULL,
               _("Trying to save private data to %s directory "
                 "but it is a regular file.\n"
                 "No private data will be saved in this session"), config_dir);
          error_shown = TRUE;
          return -1;
        }
      else if (g_mkdir (config_dir, S_IRWXU) != 0)
        {
          /* Doesnt exist; failed to create */
          glade_util_ui_message
              (glade_app_get_window (),
               GLADE_UI_ERROR, NULL,
               _("Failed to create directory %s to save private data.\n"
                 "No private data will be saved in this session"), config_dir);
          error_shown = TRUE;
          return -1;
        }
    }

  filename = g_build_filename (config_dir, GLADE_CONFIG_FILENAME, NULL);

  if ((channel = g_io_channel_new_file (filename, "w", &error)) != NULL)
    {
      if ((data =
           g_key_file_to_data (app->priv->config, &size, &error)) != NULL)
        {

          /* Implement loop here */
          while ((status = g_io_channel_write_chars (channel, data + bytes_written,     /* Offset of write */
                                                     size - bytes_written,      /* Size left to write */
                                                     &written,
                                                     &error)) !=
                 G_IO_STATUS_ERROR && (bytes_written + written) < size)
            bytes_written += written;

          if (status == G_IO_STATUS_ERROR)
            {
              glade_util_ui_message
                  (glade_app_get_window (),
                   GLADE_UI_ERROR, NULL,
                   _("Error writing private data to %s (%s).\n"
                     "No private data will be saved in this session"),
                   filename, error->message);
              error_shown = TRUE;
            }
          g_free (data);
        }
      else
        {
          glade_util_ui_message
              (glade_app_get_window (),
               GLADE_UI_ERROR, NULL,
               _("Error serializing configuration data to save (%s).\n"
                 "No private data will be saved in this session"),
               error->message);
          error_shown = TRUE;
        }
      g_io_channel_shutdown (channel, TRUE, NULL);
      g_io_channel_unref (channel);
    }
  else
    {
      glade_util_ui_message
          (glade_app_get_window (),
           GLADE_UI_ERROR, NULL,
           _("Error opening %s to write private data (%s).\n"
             "No private data will be saved in this session"),
           filename, error->message);
      error_shown = TRUE;
    }
  g_free (filename);

  if (error)
    {
      g_error_free (error);
      return -1;
    }
  return 0;
}