| File: | cafe-panel/libpanel-util/panel-xdg.c |
| Warning: | line 126, column 5 Value stored to 'current' is never read |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
| 1 | /* |
| 2 | * panel-xdg.c: miscellaneous XDG-related functions. |
| 3 | * |
| 4 | * Copyright (C) 2010 Novell, Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; either version 2 of the |
| 9 | * License, or (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 19 | * 02110-1301, USA. |
| 20 | * |
| 21 | * Authors: |
| 22 | * Vincent Untz <vuntz@gnome.org> |
| 23 | */ |
| 24 | |
| 25 | #include <string.h> |
| 26 | |
| 27 | #include <glib.h> |
| 28 | #include <gio/gio.h> |
| 29 | #include <ctk/ctk.h> |
| 30 | |
| 31 | #include "panel-xdg.h" |
| 32 | |
| 33 | #define DEFAULT_THEME_NAME"hicolor" "hicolor" |
| 34 | |
| 35 | /* |
| 36 | * Originally based on code from panel-util.c. This part of the code was: |
| 37 | * Copyright (C) 2006 Vincent Untz <vuntz@gnome.org> |
| 38 | */ |
| 39 | |
| 40 | char * |
| 41 | panel_xdg_icon_remove_extension (const char *icon) |
| 42 | { |
| 43 | char *icon_no_extension; |
| 44 | char *p; |
| 45 | |
| 46 | icon_no_extension = g_strdup (icon)g_strdup_inline (icon); |
| 47 | p = strrchr (icon_no_extension, '.'); |
| 48 | if (p && |
| 49 | (strcmp (p, ".png") == 0 || |
| 50 | strcmp (p, ".xpm") == 0 || |
| 51 | strcmp (p, ".svg") == 0)) { |
| 52 | *p = 0; |
| 53 | } |
| 54 | |
| 55 | return icon_no_extension; |
| 56 | } |
| 57 | |
| 58 | /* |
| 59 | * End of code coming from panel-util.c |
| 60 | */ |
| 61 | |
| 62 | char * |
| 63 | panel_xdg_icon_name_from_icon_path (const char *path, |
| 64 | CdkScreen *screen) |
| 65 | { |
| 66 | CtkIconTheme *theme; |
| 67 | CtkSettings *settings; |
| 68 | char *theme_name; |
| 69 | char *icon; |
| 70 | char **paths; |
| 71 | int n_paths; |
| 72 | int i; |
| 73 | GFile *file; |
| 74 | |
| 75 | /* we look if the icon comes from the current icon theme */ |
| 76 | if (!screen) |
| 77 | screen = cdk_screen_get_default (); |
| 78 | |
| 79 | settings = ctk_settings_get_for_screen (screen); |
| 80 | g_object_get (settings, |
| 81 | "ctk-icon-theme-name", &theme_name, |
| 82 | NULL((void*)0)); |
| 83 | |
| 84 | theme = ctk_icon_theme_get_for_screen (screen); |
| 85 | ctk_icon_theme_get_search_path (theme, &paths, &n_paths); |
| 86 | |
| 87 | file = g_file_new_for_path (path); |
| 88 | icon = NULL((void*)0); |
| 89 | |
| 90 | for (i = 0; i < n_paths; i++) { |
| 91 | GFile *parent; |
| 92 | char *basename; |
| 93 | |
| 94 | parent = g_file_new_for_path (paths[i]); |
| 95 | |
| 96 | if (!g_file_has_prefix (file, parent)) { |
| 97 | g_object_unref (parent); |
| 98 | continue; |
| 99 | } |
| 100 | |
| 101 | basename = g_file_get_basename (parent); |
| 102 | |
| 103 | if (g_strcmp0 (basename, "pixmaps") == 0) { |
| 104 | char *relative_path; |
| 105 | |
| 106 | relative_path = g_file_get_relative_path (parent, file); |
| 107 | |
| 108 | /* if the icon is in a subdir of pixmaps, then it's not |
| 109 | * a real icon name */ |
| 110 | if (!strchr (relative_path, G_DIR_SEPARATOR'/')) |
| 111 | icon = panel_xdg_icon_remove_extension (relative_path); |
| 112 | |
| 113 | g_free (relative_path); |
| 114 | } else { |
| 115 | /* real icon theme; but is it the current one? */ |
| 116 | GFile *theme_dir; |
| 117 | gboolean current; |
| 118 | |
| 119 | theme_dir = g_file_get_child (parent, theme_name); |
| 120 | |
| 121 | if (g_file_has_prefix (file, theme_dir)) { |
| 122 | /* it's the current one */ |
| 123 | current = TRUE(!(0)); |
| 124 | } else { |
| 125 | /* it's the default one */ |
| 126 | current = FALSE(0); |
Value stored to 'current' is never read | |
| 127 | g_object_unref (theme_dir); |
| 128 | theme_dir = g_file_get_child (parent, DEFAULT_THEME_NAME"hicolor"); |
| 129 | current = g_file_has_prefix (file, theme_dir); |
| 130 | } |
| 131 | |
| 132 | g_object_unref (theme_dir); |
| 133 | |
| 134 | if (current) { |
| 135 | char *buffer; |
| 136 | |
| 137 | buffer = g_file_get_basename (file); |
| 138 | icon = panel_xdg_icon_remove_extension (buffer); |
| 139 | g_free (buffer); |
| 140 | } |
| 141 | } |
| 142 | |
| 143 | g_free (basename); |
| 144 | g_object_unref (parent); |
| 145 | |
| 146 | break; |
| 147 | } |
| 148 | |
| 149 | g_object_unref (file); |
| 150 | g_free (theme_name); |
| 151 | |
| 152 | return icon; |
| 153 | } |