This repository has been archived by the owner on Jan 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 89
start working on themes #479
Open
bilelmoussaoui
wants to merge
17
commits into
master
Choose a base branch
from
themes
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
cd551bc
start working on themes
bilelmoussaoui 94fd767
add themes json file, read local and global themes, install themes on…
bilelmoussaoui 46a2b88
few fixes
bilelmoussaoui c648d28
remove unneeded class
bilelmoussaoui d9e9e18
always load article from file, gresource not used anymore
bilelmoussaoui de0d630
fix flatpak folder, and add a fallback theme, fix building
bilelmoussaoui 38f7a11
more fixes
bilelmoussaoui 8b633eb
few fixes, works perfectly
bilelmoussaoui f33303e
Merge branch 'master' into themes
bilelmoussaoui d8e046d
use struct for themeInfo
bilelmoussaoui 6fdb4d9
update to master
bilelmoussaoui a849460
remove UtilsUI and fix merge confilicts
bilelmoussaoui d976d49
remove old source files from CMakeLists
bilelmoussaoui 8f5aae5
restore the GrabberConfig
bilelmoussaoui 086e6b6
update Utils & catch GLib.Error on ArticleTheme
bilelmoussaoui 4100269
space2tabs
bilelmoussaoui 6bb6fac
fix themes loading, add pre/code tags theming, fix img width & height
bilelmoussaoui File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,14 +14,20 @@ | |
// along with FeedReader. If not, see <http://www.gnu.org/licenses/>. | ||
using Gee; | ||
|
||
public struct ThemeInfo { | ||
string name; | ||
string author; | ||
string path; | ||
} | ||
|
||
public class FeedReader.ArticleTheme { | ||
private static ArrayList<HashMap<string, string>> ? themes = null; | ||
private static HashMap<string, ThemeInfo?> ? themes = null; | ||
|
||
|
||
public static ArrayList<HashMap> getThemes(){ | ||
public static HashMap<string, ThemeInfo?> getThemes(){ | ||
if(themes == null){ | ||
// Local themes | ||
themes = new ArrayList<HashMap<string, string>> (); | ||
themes = new HashMap<string, ThemeInfo?> (); | ||
string local_dir = GLib.Environment.get_user_data_dir() + "/feedreader/themes/"; | ||
grabThemes(local_dir); | ||
// Global themes | ||
|
@@ -31,50 +37,37 @@ public class FeedReader.ArticleTheme { | |
return themes; | ||
} | ||
|
||
private static HashMap<string, string> getThemeInfo (string theme_path) { | ||
var themeInfo = new HashMap<string, string> (); | ||
bool corrupted_theme = true; | ||
string theme_name = ""; | ||
string author = ""; | ||
private static ThemeInfo? getTheme (string theme_path) { | ||
var themeInfo = ThemeInfo (); | ||
bool corrupted_theme = false; | ||
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(); | ||
string path = Path.build_filename(theme_path, "theme.json"); | ||
Json.Parser parser = new Json.Parser(); | ||
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; | ||
} | ||
Value val; | ||
foreach (unowned string node_name in obj.get_members()){ | ||
val = obj.get_member(node_name).get_value(); | ||
switch(node_name) { | ||
case "author": | ||
themeInfo.author = (string) val; | ||
break; | ||
case "name": | ||
themeInfo.name = (string) val; | ||
break; | ||
} | ||
} | ||
}catch(GLib.FileError err){ | ||
themeInfo.path = theme_path; | ||
|
||
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. |
||
} catch(GLib.FileError err){ | ||
Logger.error("A theme must be corrupted :" + theme_path); | ||
corrupted_theme = true; | ||
} | ||
if (!corrupted_theme){ | ||
themeInfo.set("name", theme_name); | ||
themeInfo.set("author", author); | ||
themeInfo.set("path", theme_path); | ||
} else { | ||
themeInfo.set("corrupted", "true"); | ||
} | ||
|
||
if (corrupted_theme) | ||
return null; | ||
|
||
return themeInfo; | ||
} | ||
|
||
|
@@ -85,18 +78,17 @@ public class FeedReader.ArticleTheme { | |
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 (themeInfo.has_key("corrupted") == false){ | ||
themes.add(themeInfo); | ||
} | ||
var themeInfo = getTheme(path); | ||
if(themeInfo != null) | ||
themes.set(name, themeInfo); | ||
} | ||
} | ||
} catch (GLib.FileError err){ | ||
|
||
Logger.debug("Couldn't reach the location of themes : " + location); | ||
} | ||
} | ||
|
||
public static bool isExists(string theme_location){ | ||
public static bool exists(string theme_location){ | ||
// Check wether a theme exists or not | ||
bool exists = true; | ||
try { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Why is the second type argument
ThemeInfo?
? Are there cases where we would want them theme tonull
?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.
Not at all, it's just valac complained about not using themeInfo?