Beispiel #1
0
static void
charset_handler(control *ctrl, void *unused(data), int event)
{
  char *charset = new_cfg.charset;
  switch (event) {
    when EVENT_REFRESH:
      dlg_update_start(ctrl);
      dlg_listbox_clear(ctrl);
      const char *cs;
      for (int i = 0; (cs = charset_menu[i]); i++)
        dlg_listbox_add(ctrl, cs);
      dlg_update_done(ctrl);
      update_charset();
    when EVENT_UNFOCUS:
      dlg_editbox_set(ctrl, charset);
      update_locale();
    when EVENT_VALCHANGE or EVENT_SELCHANGE:
      dlg_editbox_get(ctrl, charset, sizeof cfg.charset);
      if (event == EVENT_SELCHANGE) {
        if (*charset == '(')
          *charset = 0;
        else 
          *strchr(charset, ' ') = 0;
        update_locale();
      }
  }
}
Beispiel #2
0
int
main (int argc, char *argv[])
{
  XdgDirEntry *old_entries, *new_entries, *entry;
  XdgDirEntry *desktop_entry;
  GtkBookmark *bookmark;
  GList *bookmarks, *l;
  char *old_locale;
  char *locale, *dot;
  int i;
  gboolean modified_bookmarks;
  char *uri;
  
  setlocale (LC_ALL, "");
  
  bindtextdomain (GETTEXT_PACKAGE, GLIBLOCALEDIR);
  bindtextdomain ("xdg-user-dirs", GLIBLOCALEDIR);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  old_entries = parse_xdg_dirs (NULL);
  old_locale = parse_xdg_dirs_locale ();
  locale = g_strdup (setlocale (LC_MESSAGES, NULL));
  dot = strchr (locale, '.');
  if (dot)
    *dot = 0;

  if (old_locale && *old_locale != 0 &&
      strcmp (old_locale, locale) != 0 &&
      has_xdg_translation ())
    {
       gtk_init (&argc, &argv);
       update_locale (old_entries);
    }
  
  new_entries = parse_xdg_dirs (NULL);

  bookmarks = parse_gtk_bookmarks ();

  modified_bookmarks = FALSE;
  if (bookmarks == NULL)
    {
      char *make_bm_for[] = {
	"DOCUMENTS",
	"MUSIC",
	"PICTURES",
	"VIDEOS",
	"DOWNLOAD",
	NULL};
      /* No previous bookmarks. Generate standard ones */

      desktop_entry = find_dir_entry (new_entries, "DESKTOP");
      for (i = 0; make_bm_for[i] != NULL; i++)
	{
	  entry = find_dir_entry (new_entries, make_bm_for[i]);
	  
	  if (entry && strcmp (entry->path, g_get_home_dir ()) != 0 &&
	      (desktop_entry == NULL || strcmp (entry->path, desktop_entry->path) != 0))
	    {
	      uri = g_filename_to_uri (entry->path, NULL, NULL);
	      if (uri)
		{
		  modified_bookmarks = TRUE;
		  bookmark = g_new0 (GtkBookmark, 1);
		  bookmark->uri = uri;
		  bookmarks = g_list_append (bookmarks, bookmark);
		}
	    }
	}
    }
  else
    {
      /* Map old bookmarks that were moved */

      for (l = bookmarks; l != NULL; l = l->next)
	{
	  char *path;
	  
	  bookmark = l->data;

	  path = g_filename_from_uri (bookmark->uri, NULL, NULL);
	  if (path)
	    {
	      entry = find_dir_entry_by_path (old_entries, path);
	      if (entry)
		{
		  entry = find_dir_entry (new_entries, entry->type);
		  if (entry)
		    {
		      uri = g_filename_to_uri (entry->path, NULL, NULL);
		      if (uri)
			{
			  modified_bookmarks = TRUE;
			  g_free (bookmark->uri);
			  bookmark->uri = uri;
			}
		    }
		}
	      g_free (path);
	    }
	}
    }

  if (modified_bookmarks)
    save_gtk_bookmarks (bookmarks);
  
  g_free (new_entries);
  g_free (old_entries);
  
  return 0;
}