-
Notifications
You must be signed in to change notification settings - Fork 88
start working on themes #479
base: master
Are you sure you want to change the base?
Changes from 1 commit
cd551bc
94fd767
46a2b88
c648d28
d9e9e18
de0d630
38f7a11
8b633eb
f33303e
d8e046d
6fdb4d9
a849460
d976d49
8f5aae5
086e6b6
4100269
6bb6fac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "Default", | ||
| "author": "Bilal Elmoussaoui" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,4 @@ | ||
| { | ||
| "name": "Midnight", | ||
| "author": "Bilal Elmoussaoui" | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,87 @@ | ||
| using Gee; | ||
|
|
||
| public class FeedReader.ArticleTheme { | ||
| static Array<HashMap> themes = new Array<HashMap> (); | ||
|
|
||
| public FeedReader.ArticleTheme() { | ||
| // Local themes | ||
| string theme_dir = GLib.Environment.get_home_dir() + "/.feedreader/themes/"; | ||
| FeedReader.ArticleTheme.themes += grabThemes(theme_dir); | ||
| // Global themes | ||
| string global_dir = Constants.INSTALL_PREFIX + "/share/ArticleView/"; | ||
| FeedReader.ArticleTheme.themes += grabThemes(theme_dir); | ||
| } | ||
|
|
||
| private HashMap<string, string> getThemeInfo (string theme_path) { | ||
| """ | ||
| Parse a theme directory, and check if it's a valid theme | ||
| """ | ||
| var themeInfo = new HashMap<string, string> (); | ||
| bool corrupted_theme = true; | ||
| string theme_name = ""; | ||
| string author = ""; | ||
| try { | ||
| Dir theme_dir = Dir.open(theme_path, 0); | ||
| string ? name = null; | ||
| while ((name = theme_dir.read_name()) != null){ | ||
| if (name == "theme.json"){ | ||
| corrupted_theme = false; | ||
| string path = Path.build_filename(theme_path, name); | ||
|
||
| Json.Parser parser = new Json.Parser(); | ||
| try { | ||
| parser.load_from_file(path); | ||
| Json.Object obj = parser.get_root().get_object(); | ||
|
|
||
| Value val; | ||
| foreach (unowned string nname in obj.get_members()){ | ||
| val = obj.get_member(nname).get_value(); | ||
| switch(nname) { | ||
| case "author": | ||
| author = (string) val; | ||
| break; | ||
| case "name": | ||
| theme_name = (string) val; | ||
| break; | ||
| } | ||
| } | ||
| }catch(Error err){ | ||
| corrupted_theme = true; | ||
|
||
| } | ||
| } | ||
| } | ||
| }catch(GLib.FileError err){ | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Logging something here would be nice too. |
||
| } | ||
| if (!corrupted_theme){ | ||
| themeInfo.set("name", theme_name); | ||
| themeInfo.set("author", author); | ||
| themeInfo.set("path", theme_path); | ||
| } else { | ||
| themeInfo.set("corrupted", "true"); | ||
| } | ||
| return themeInfo; | ||
| } | ||
|
|
||
| private Array<HashMap> grabThemes(string location) { | ||
| """ | ||
| Return a list of themes on a specific location (global/local) | ||
| """ | ||
| Array<HashMap> themes = new Array<HashMap> (); | ||
| try{ | ||
| Dir dir = Dir.open(location, 0); | ||
| string ? name = null; | ||
| while ((name = dir.read_name()) != null){ | ||
| string path = Path.build_filename(location, name); | ||
| if(FileUtils.test(path, FileTest.IS_DIR)){ | ||
| var themeInfo = getThemeInfo(path); | ||
| if (!"corrupted" in themeInfo.keys){ | ||
| themes.append_val(themeInfo); | ||
| } | ||
| } | ||
| } | ||
| } catch (GLib.FileError err){ | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One more case where logging would be nice (or just don't catch the exception). |
||
| } | ||
| return themes; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm pretty sure you can't use this path with flatpaks. Also there is already
$HOME/.local/feedreader.You can access that via
GLib.Environment.get_user_data_dir() + "/feedreader/"There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will fix that :)