libxputty 0.1
Loading...
Searching...
No Matches
Typedefs | Functions
xdgmimeicon.h File Reference

Go to the source code of this file.

Typedefs

typedef struct XdgIconList XdgIconList
 

Functions

void _xdg_mime_icon_read_from_file (XdgIconList *list, const char *file_name)
 
XdgIconList_xdg_mime_icon_list_new (void)
 
void _xdg_mime_icon_list_free (XdgIconList *list)
 
const char * _xdg_mime_icon_list_lookup (XdgIconList *list, const char *mime)
 
void _xdg_mime_icon_list_dump (XdgIconList *list)
 

Typedef Documentation

◆ XdgIconList

typedef struct XdgIconList XdgIconList

Definition at line 32 of file xdgmimeicon.h.

Function Documentation

◆ _xdg_mime_icon_list_dump()

void _xdg_mime_icon_list_dump ( XdgIconList list)

Definition at line 168 of file xdgmimeicon.c.

169{
170 int i;
171
172 if (list->icons)
173 {
174 for (i = 0; i < list->n_icons; i++)
175 {
176 printf ("%s %s\n",
177 list->icons[i].mime_type,
178 list->icons[i].icon_name);
179 }
180 }
181}
struct XdgIcon * icons
Definition xdgmimeicon.c:57
char * icon_name
Definition xdgmimeicon.c:52
char * mime_type
Definition xdgmimeicon.c:51

References XdgIcon::icon_name, XdgIconList::icons, XdgIcon::mime_type, and XdgIconList::n_icons.

◆ _xdg_mime_icon_list_free()

void _xdg_mime_icon_list_free ( XdgIconList list)

Definition at line 75 of file xdgmimeicon.c.

76{
77 int i;
78
79 if (list->icons)
80 {
81 for (i = 0; i < list->n_icons; i++)
82 {
83 free (list->icons[i].mime_type);
84 free (list->icons[i].icon_name);
85 }
86 free (list->icons);
87 }
88 free (list);
89}

References XdgIcon::icon_name, XdgIconList::icons, XdgIcon::mime_type, and XdgIconList::n_icons.

Referenced by xdg_mime_shutdown().

◆ _xdg_mime_icon_list_lookup()

const char * _xdg_mime_icon_list_lookup ( XdgIconList list,
const char *  mime 
)

Definition at line 98 of file xdgmimeicon.c.

100{
101 XdgIcon *entry;
102 XdgIcon key;
103
104 if (list->n_icons > 0)
105 {
106 key.mime_type = (char *)mime_type;
107 key.icon_name = NULL;
108
109 entry = bsearch (&key, list->icons, list->n_icons,
110 sizeof (XdgIcon), icon_entry_cmp);
111 if (entry)
112 return entry->icon_name;
113 }
114
115 return NULL;
116}

References XdgIcon::icon_name, XdgIconList::icons, XdgIcon::mime_type, and XdgIconList::n_icons.

Referenced by xdg_mime_get_generic_icon(), and xdg_mime_get_icon().

◆ _xdg_mime_icon_list_new()

XdgIconList * _xdg_mime_icon_list_new ( void  )

Definition at line 62 of file xdgmimeicon.c.

63{
64 XdgIconList *list;
65
66 list = malloc (sizeof (XdgIconList));
67
68 list->icons = NULL;
69 list->n_icons = 0;
70
71 return list;
72}

References XdgIconList::icons, and XdgIconList::n_icons.

◆ _xdg_mime_icon_read_from_file()

void _xdg_mime_icon_read_from_file ( XdgIconList list,
const char *  file_name 
)

Definition at line 119 of file xdgmimeicon.c.

121{
122 FILE *file;
123 char line[255];
124 int alloc;
125
126 file = fopen (file_name, "r");
127
128 if (file == NULL)
129 return;
130
131 /* FIXME: Not UTF-8 safe. Doesn't work if lines are greater than 255 chars.
132 * Blah */
133 alloc = list->n_icons + 16;
134 list->icons = realloc (list->icons, alloc * sizeof (XdgIcon));
135 while (fgets (line, 255, file) != NULL)
136 {
137 char *sep;
138 if (line[0] == '#')
139 continue;
140
141 sep = strchr (line, ':');
142 if (sep == NULL)
143 continue;
144 *(sep++) = '\000';
145 sep[strlen (sep) -1] = '\000';
146 if (list->n_icons == alloc)
147 {
148 alloc <<= 1;
149 list->icons = realloc (list->icons,
150 alloc * sizeof (XdgIcon));
151 }
152 list->icons[list->n_icons].mime_type = strdup (line);
153 list->icons[list->n_icons].icon_name = strdup (sep);
154 list->n_icons++;
155 }
156 list->icons = realloc (list->icons,
157 list->n_icons * sizeof (XdgIcon));
158
159 fclose (file);
160
161 if (list->n_icons > 1)
162 qsort (list->icons, list->n_icons,
163 sizeof (XdgIcon), icon_entry_cmp);
164}

References XdgIcon::icon_name, XdgIconList::icons, XdgIcon::mime_type, and XdgIconList::n_icons.