Skip to content
This repository was archived by the owner on Jan 11, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ vala_precompile(UI ${UI_NAME}
src/FavIconCache.vala
src/FeedReader.vala
src/LoginInterface.vala
src/ArticleTheme.vala
src/dbUI.vala
src/UtilsUI.vala
src/Widgets/AddPopover.vala
Expand Down Expand Up @@ -310,3 +311,4 @@ install (FILES ${CMAKE_CURRENT_SOURCE_DIR}/data/org.gnome.FeedReader.Daemon.serv
install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/application-icons/hicolor DESTINATION ${CMAKE_INSTALL_PREFIX}/share/icons)
install (CODE "execute_process (COMMAND gtk-update-icon-cache -t ${CMAKE_INSTALL_PREFIX}/share/icons/hicolor)")
install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/GrabberConfig DESTINATION ${PKGDATADIR})
install (DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data/ArticleView DESTINATION ${PKGDATADIR})
4 changes: 4 additions & 0 deletions data/ArticleView/default/theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Default",
"author": "Bilal Elmoussaoui"
}
4 changes: 4 additions & 0 deletions data/ArticleView/midnight/theme.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"name": "Midnight",
"author": "Bilal Elmoussaoui"
}
5 changes: 0 additions & 5 deletions data/org.gnome.FeedReader.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@
<file compressed="true">gtk-css/gtk.css</file>
<file compressed="true">gtk-css/elementary.css</file>

<file compressed="true">ArticleView/default/style.css</file>
<file compressed="true">ArticleView/default/article.html</file>
<file compressed="true">ArticleView/midnight/style.css</file>
<file compressed="true">ArticleView/midnight/article.html</file>

<file preprocess="xml-stripblanks">icons/16x16/actions/feed-add-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/feed-arrow-up-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/16x16/actions/feed-refresh-symbolic.svg</file>
Expand Down
87 changes: 87 additions & 0 deletions src/ArticleTheme.vala
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/";
Copy link
Owner

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/"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will fix that :)

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);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like we're reading through the directory but only doing something with one file. Could we replace this while loop with:

// etc.
string author = "";
try {
  string path = Path.build_filename(theme_path, "theme.json");
  Json.Parser parser = new Json.Parser();
  // etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code here is still not complete, i would like to check if there's an article.html & style.css file too. Otherwise the theme will be correct. But yeah it's better to use this 👍

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be good to log the error here for debugging purposes.

}
}
}
}catch(GLib.FileError err){

Copy link
Collaborator

Choose a reason for hiding this comment

The 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){

Copy link
Collaborator

Choose a reason for hiding this comment

The 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;
}
}
2 changes: 2 additions & 0 deletions src/Utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -669,4 +669,6 @@ public class FeedReader.Utils : GLib.Object {
if(!setting.set_string(key, val))
Logger.error("Utils.gsettingWriteString: writing %s %s failed".printf(setting.schema_id, key));
}


}
12 changes: 7 additions & 5 deletions src/Widgets/Setting.vala
Original file line number Diff line number Diff line change
Expand Up @@ -55,20 +55,22 @@ public class FeedReader.SettingFont : FeedReader.Setting {

public class FeedReader.ArticleThemeSetting : FeedReader.Setting {

public ArticleThemeSetting (string name, GLib.Settings settings, string key, string [] values, string ? tooltip = null){
public ArticleThemeSetting (string name, GLib.Settings settings, string key, Array<HashMap> themes, string ? tooltip = null){
base (name, tooltip);
var liststore = new Gtk.ListStore(1, typeof(string));
int active = 0;
bool was_found = false;
string current_theme = settings.get_string(key);
foreach (string val in values){
foreach (HashMap theme in themes){
Gtk.TreeIter iter;
if (current_theme == val.down()){
string theme_name = theme.get("name");
string path = theme.get("path");
if (current_theme == path){
was_found = true;
}
liststore.append(out iter);
liststore.set(iter, 0, val);
liststore.set(iter, 1, val.down());
liststore.set(iter, 0, theme_name);
liststore.set(iter, 1, path);
if(!was_found){
active += 1;
}
Expand Down
3 changes: 1 addition & 2 deletions src/Widgets/SettingsDialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,7 @@ public class FeedReader.SettingsDialog : Gtk.Dialog {

var articleview_settings = headline(_("Article View:"));

var article_theme = new ArticleThemeSetting(_("Theme"), Settings.general(), "article-theme",
{_("Default"), _("Midnight")});
var article_theme = new ArticleThemeSetting(_("Theme"), Settings.general(), "article-theme", FeedReader.ArticleTheme.themes);
article_theme.changed.connect(() => {
ColumnView.get_default().reloadArticleView();
});
Expand Down