Skip to content

Commit d4f4db3

Browse files
author
politebot
committed
More error handling for faves, update README with XML format
1 parent 5b6fb9f commit d4f4db3

2 files changed

Lines changed: 68 additions & 2 deletions

File tree

README.md

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,47 @@ A simple internet radio player built with the Enlightenment Foundation Libraries
1515
- List stations with their favicons
1616
- Play, pause, and stop radio streams
1717
- Search by station name, country, language, or tag
18+
- Save favorite radio stations locally
19+
- Add custom radio station URLs manually
20+
21+
## Favorites Storage
22+
23+
Favorite radio stations are saved locally in XML format at:
24+
```
25+
~/.config/eradio/favorites.xml
26+
```
27+
28+
### XML Format
29+
30+
The favorites file uses a simple XML structure to store station metadata:
31+
32+
```xml
33+
<?xml version="1.0" encoding="UTF-8"?>
34+
<favorites version="1">
35+
<station uuid="station-uuid-here" name="Station Name"
36+
url="http://example.com/stream.mp3"
37+
favicon="http://example.com/icon.png"/>
38+
<station uuid="another-uuid" name="Another Station"
39+
url="http://example.org/stream"/>
40+
</favorites>
41+
```
42+
43+
### Element Attributes
44+
45+
Each `<station>` element can contain the following attributes:
46+
47+
- **`uuid`** (optional): Unique identifier from the radio-browser.info API
48+
- **`name`** (optional): Human-readable station name
49+
- **`url`** (optional): Stream URL for the radio station
50+
- **`favicon`** (optional): URL to the station's favicon image
51+
52+
**Note:** Either `uuid` or `url` must be present for a station entry to be valid. The `uuid` is used as the primary key when available, with `url` as fallback.
53+
54+
### File Operations
55+
56+
- The file is automatically created when you add your first favorite station
57+
- Favorites are saved atomically using a temporary file and rename operation
58+
- The file can be manually edited - changes will be loaded when the application starts
1859

1960
## Prerequisites
2061

src/favorites.c

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <errno.h>
66
#include <string.h>
77
#include <stdlib.h>
8+
#include <stdio.h>
89

910
#include "favorites.h"
1011

@@ -188,12 +189,36 @@ void favorites_save(AppData *ad)
188189

189190
eina_hash_foreach(ad->favorites, _favorites_save_cb, root);
190191

191-
xmlSaveFormatFileEnc(tmp, doc, "UTF-8", 1);
192+
int xml_save_result = xmlSaveFormatFileEnc(tmp, doc, "UTF-8", 1);
192193
xmlFreeDoc(doc);
193194

194-
rename(tmp, path);
195+
if (xml_save_result == -1) {
196+
// XML save failed - could be disk space, permissions, etc.
197+
if (ad->statusbar) {
198+
elm_object_text_set(ad->statusbar, "Error: Could not save favorites (disk full?)");
199+
}
200+
unlink(tmp); // Clean up the temp file
201+
free(tmp);
202+
goto end;
203+
}
204+
205+
if (rename(tmp, path) == -1) {
206+
// Rename failed - could be filesystem issues
207+
if (ad->statusbar) {
208+
elm_object_text_set(ad->statusbar, "Error: Could not save favorites (filesystem error)");
209+
}
210+
unlink(tmp); // Clean up the temp file
211+
free(tmp);
212+
goto end;
213+
}
214+
195215
free(tmp);
196216

217+
// Success - provide feedback to user
218+
if (ad->statusbar) {
219+
elm_object_text_set(ad->statusbar, "Favorites saved successfully");
220+
}
221+
197222
end:
198223
if (dir) free(dir);
199224
if (path) free(path);

0 commit comments

Comments
 (0)