theme.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /* $Id$
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License as published by
  5. * the Free Software Foundation; either version 3 of the License, or
  6. * (at your option) any later version.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License along
  14. * with this program; if not, write to the Free Software Foundation, Inc.,
  15. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  16. *
  17. * Copyright (C) 2013 Cedric Leporcq <cedl38@gmail.com>
  18. *
  19. * Parts of this code is derived from xfwm4 sources (setting.c)
  20. *
  21. */
  22. #include <libxfce4util/libxfce4util.h>
  23. #include "theme.h"
  24. #define UNITY_TEST_FILE_PNG "close_focused_normal.png"
  25. #define UNITY_TEST_FILE_SVG "close_focused_normal.svg"
  26. gchar *test_theme_dir (const gchar *theme, const char *themedir, const gchar *file) {
  27. gchar *test_file, *abs_path, *path;
  28. path = g_build_filename (theme, themedir, file, NULL);
  29. xfce_resource_push_path (XFCE_RESOURCE_THEMES,
  30. DATADIR G_DIR_SEPARATOR_S "themes");
  31. test_file = xfce_resource_lookup (XFCE_RESOURCE_THEMES, path);
  32. xfce_resource_pop_path (XFCE_RESOURCE_THEMES);
  33. g_free (path);
  34. if (test_file)
  35. {
  36. abs_path = g_path_get_dirname (test_file);
  37. g_free (test_file);
  38. return abs_path;
  39. }
  40. return NULL;
  41. }
  42. gchar *
  43. get_unity_theme_dir (const gchar *theme, const gchar *default_theme)
  44. {
  45. const gchar *file;
  46. gchar *abs_path;
  47. gint i;
  48. if (g_path_is_absolute (theme))
  49. {
  50. if (g_file_test (theme, G_FILE_TEST_IS_DIR))
  51. {
  52. return g_strdup (theme);
  53. }
  54. }
  55. abs_path = test_theme_dir (theme, "unity", UNITY_TEST_FILE_PNG);
  56. if (!abs_path)
  57. abs_path = test_theme_dir (theme, "unity", UNITY_TEST_FILE_SVG);
  58. if (abs_path)
  59. return abs_path;
  60. /* Pfew, really can't find that theme nowhere! */
  61. if (default_theme)
  62. return g_build_filename (DATADIR, "themes", default_theme, "unity", NULL);
  63. return NULL;
  64. }