예제 #1
0
static void
terminal_toolbars_model_init (TerminalToolbarsModel *model)
{
  gchar *file;

  exo_toolbars_model_set_actions (EXO_TOOLBARS_MODEL (model),
                                  (gchar **) actions,
                                  G_N_ELEMENTS (actions));

  xfce_resource_push_path (XFCE_RESOURCE_DATA, DATADIR);
  file = xfce_resource_lookup (XFCE_RESOURCE_DATA, "Terminal/Terminal-toolbars.ui");
  xfce_resource_pop_path (XFCE_RESOURCE_DATA);

  if (G_LIKELY (file != NULL))
    {
      exo_toolbars_model_load_from_file (EXO_TOOLBARS_MODEL (model), file, NULL);
      g_free (file);
    }
  else
    {
      g_warning ("Unable to locate Terminal/Terminal-toolbars.ui, "
                 "the toolbars may not work correctly");
    }

  g_signal_connect (G_OBJECT (model), "item-added",
                    G_CALLBACK (terminal_toolbars_model_queue_sync), NULL);
  g_signal_connect (G_OBJECT (model), "item-removed",
                    G_CALLBACK (terminal_toolbars_model_queue_sync), NULL);
  g_signal_connect (G_OBJECT (model), "toolbar-added",
                    G_CALLBACK (terminal_toolbars_model_queue_sync), NULL);
  g_signal_connect (G_OBJECT (model), "toolbar-changed",
                    G_CALLBACK (terminal_toolbars_model_queue_sync), NULL);
  g_signal_connect (G_OBJECT (model), "toolbar-removed",
                    G_CALLBACK (terminal_toolbars_model_queue_sync), NULL);
}
static void
wckbuttons_load_themes (GtkWidget *view, WBPlugin *wb)
{
    GtkTreeModel *model;
    GHashTable   *themes;
    GDir         *dir;
    const gchar  *file;
    gchar       **theme_dirs;
    gchar        *themedir;
    gint          i;

    themes = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);

    model = gtk_tree_view_get_model (GTK_TREE_VIEW (view));

    /* clear any previous row */
    gtk_list_store_clear (GTK_LIST_STORE (model));

    xfce_resource_push_path (XFCE_RESOURCE_THEMES, DATADIR G_DIR_SEPARATOR_S "themes");
    theme_dirs = xfce_resource_dirs (XFCE_RESOURCE_THEMES);
    xfce_resource_pop_path (XFCE_RESOURCE_THEMES);

    for (i = 0; theme_dirs[i] != NULL; ++i)
    {
        dir = g_dir_open (theme_dirs[i], 0, NULL);

        if (G_UNLIKELY (dir == NULL))
            continue;

        while ((file = g_dir_read_name (dir)) != NULL)
        {
            /* check if there is not already a theme with the
            * same name in the database */
            if (g_hash_table_lookup (themes, file) == NULL) {

                if (wb->prefs->sync_wm_theme)
                {
                    if (!test_theme_dir(file, "xfwm4", THEMERC))
                        continue;
                }

                themedir = get_theme_dir (file, NULL);
                if (!themedir)
                    continue;

                GtkTreeIter   iter;
                g_hash_table_insert (themes, g_strdup (file), GINT_TO_POINTER (1));

                /* insert in the list store */
                gtk_list_store_append (GTK_LIST_STORE (model), &iter);
                gtk_list_store_set (GTK_LIST_STORE (model), &iter,
                                  COL_THEME_NAME, file,
                                  COL_THEME_RC, g_path_get_basename (themedir), -1);

                    if (G_UNLIKELY (g_str_equal (wb->prefs->theme, file)))
                    {
                        GtkTreePath *path = gtk_tree_model_get_path (model, &iter);

                        gtk_tree_selection_select_iter (gtk_tree_view_get_selection (GTK_TREE_VIEW (view)),
                                                      &iter);
                        gtk_tree_view_scroll_to_cell (GTK_TREE_VIEW (view), path, NULL, TRUE, 0.5, 0.5);

                        gtk_tree_path_free (path);
                    }
                g_free (themedir);
            }
        }

      g_dir_close (dir);
    }

  g_strfreev (theme_dirs);
  g_hash_table_destroy (themes);
}
예제 #3
0
gint
main (gint argc, gchar **argv)
{
  GError        *error = NULL;
  GtkWidget     *dialog;
  GtkWidget     *button;
  gint           result;
  gint           retval = EXIT_SUCCESS;
  gint           default_response = GTK_RESPONSE_CANCEL;
  XfconfChannel *channel;
  gint           configver;
  gchar         *filename_46;
  gchar         *filename_default;
  gboolean       migrate_vendor_default;

  /* set translation domain */
  xfce_textdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR, "UTF-8");

#ifndef NDEBUG
  /* terminate the program on warnings and critical messages */
  g_log_set_always_fatal (G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_WARNING);
#endif

  gtk_init (&argc, &argv);

  if (!xfconf_init (&error))
    {
      g_critical ("Failed to initialize Xfconf: %s", error->message);
      g_error_free (error);
      return EXIT_FAILURE;
    }

  channel = xfconf_channel_get (XFCE_PANEL_CHANNEL_NAME);
  if (!xfconf_channel_has_property (channel, "/panels"))
    {
      /* lookup the old 4.6 config file */
      filename_46 = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, XFCE_46_CONFIG);

      /* lookup the default configuration */
      xfce_resource_push_path (XFCE_RESOURCE_CONFIG, XDGCONFIGDIR);
      filename_default = xfce_resource_lookup (XFCE_RESOURCE_CONFIG, DEFAULT_CONFIG_FILENAME);
      xfce_resource_pop_path (XFCE_RESOURCE_CONFIG);

      if (filename_46 == NULL && filename_default == NULL)
        {
          g_warning ("No default or old configuration found");
          return EXIT_FAILURE;
        }

      /* if the default configuration does not match with the file found
       * by the resource lookup, migrate it without asking */
      migrate_vendor_default = (g_strcmp0 (DEFAULT_CONFIG_PATH, filename_default) != 0);

      /* check if we auto-migrate the default configuration */
      if (g_getenv ("XFCE_PANEL_MIGRATE_DEFAULT") != NULL
          || migrate_vendor_default)
        {
          if (filename_46 != NULL)
            g_message ("Tried to auto-migrate, but old configuration found");
          else if (filename_default == NULL)
            g_message ("Tried to auto-migrate, but no default configuration found");
          else
            goto migrate_default;
        }

      /* create question dialog */
      dialog = gtk_message_dialog_new (NULL, 0, GTK_MESSAGE_QUESTION, GTK_BUTTONS_NONE,
                                       _("Welcome to the first start of the panel"));
      gtk_window_set_title (GTK_WINDOW (dialog), _("Panel"));
      gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_PREFERENCES);
      gtk_window_stick (GTK_WINDOW (dialog));
      gtk_window_set_keep_above (GTK_WINDOW (dialog), TRUE);

      if (filename_46 != NULL)
        {
          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog), "%s\n%s",
              _("Because the panel moved to a new system for storing the "
                "settings, it has to load a fresh initial configuration."),
              _("Choose below which setup you want for the first startup."));

          button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Migrate old config"), GTK_RESPONSE_OK);
          gtk_widget_set_tooltip_text (button, _("Migrate the old 4.6 configuration to Xfconf"));
          default_response = GTK_RESPONSE_OK;
        }
      else
        {
          gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
              _("Choose below which setup you want for the first startup."));
        }

      if (filename_default != NULL)
        {
          button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("Use default config"), GTK_RESPONSE_YES);
          gtk_widget_set_tooltip_text (button, _("Load the default configuration"));

          if (default_response == GTK_RESPONSE_CANCEL)
            default_response = GTK_RESPONSE_YES;
        }

      button = gtk_dialog_add_button (GTK_DIALOG (dialog), _("One empty panel"), GTK_RESPONSE_CANCEL);
      gtk_widget_set_tooltip_text (button, _("Start with one empty panel"));

      gtk_dialog_set_default_response (GTK_DIALOG (dialog), default_response);
      result = gtk_dialog_run (GTK_DIALOG (dialog));
      gtk_widget_destroy (dialog);

      if (result == GTK_RESPONSE_OK && filename_46 != NULL)
        {
          /* restore 4.6 config */
          if (!migrate_46 (filename_46, channel, &error))
            {
              xfce_dialog_show_error (NULL, error, _("Failed to migrate the old panel configuration"));
              g_error_free (error);
              retval = EXIT_FAILURE;
            }
        }
      else if (result == GTK_RESPONSE_YES && filename_default != NULL)
        {
          migrate_default:

          /* apply default config */
          if (!migrate_default (filename_default, &error))
            {
              xfce_dialog_show_error (NULL, error, _("Failed to load the default configuration"));
              g_error_free (error);
              retval = EXIT_FAILURE;
            }
        }

      g_free (filename_46);
      g_free (filename_default);
    }

  configver = xfconf_channel_get_int (channel, "/configver", -1);
  if (configver < XFCE4_PANEL_CONFIG_VERSION)
    {
      g_message (_("Panel config needs migration..."));

      if (!migrate_config (channel, configver, &error))
        {
          xfce_dialog_show_error (NULL, error, _("Failed to migrate the existing configuration"));
          g_error_free (error);
          retval = EXIT_FAILURE;
        }
      else
        {
          g_message (_("Panel configuration has been updated."));
        }

      /* migration complete, set new version */
      xfconf_channel_set_int (channel, "/configver", XFCE4_PANEL_CONFIG_VERSION);
    }

  xfconf_shutdown ();

  return retval;
}