Skip to content

Commit

Permalink
Added margin control to reading preference pop up
Browse files Browse the repository at this point in the history
  • Loading branch information
babluboy committed May 10, 2017
1 parent 7b77c73 commit 3d181a5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 10 deletions.
Binary file modified data/icons/24/bookworm-profile-day.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/icons/24/bookworm-profile-night.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 5 additions & 5 deletions po/bookworm.pot
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2017-05-09 22:53+0100\n"
"POT-Creation-Date: 2017-05-10 23:20+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
Expand All @@ -17,11 +17,11 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/constants.vala:76
#: src/constants.vala:77
msgid "About"
msgstr ""

#: src/constants.vala:102
#: src/constants.vala:103
msgid "All Files"
msgstr ""

Expand Down Expand Up @@ -103,7 +103,7 @@ msgstr ""
msgid "Not Available"
msgstr ""

#: src/constants.vala:65 src/constants.vala:77
#: src/constants.vala:65 src/constants.vala:78
msgid "Preferences"
msgstr ""

Expand Down Expand Up @@ -137,7 +137,7 @@ msgstr ""
msgid "Turn on Night Mode"
msgstr ""

#: src/constants.vala:75
#: src/constants.vala:76
msgid "Unknown Book"
msgstr ""

Expand Down
4 changes: 4 additions & 0 deletions schemas/com.github.babluboy.bookworm.gschema.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,9 @@
<default>true</default>
<summary>Local storage for extracted contents of books</summary>
</key>
<key name="reading-width" type="s">
<default>"1"</default>
<summary>Save the page width for reading</summary>
</key>
</schema>
</schemalist>
1 change: 1 addition & 0 deletions src/constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace BookwormApp.Constants {
public const int SPACING_WIDGETS = 12;
public const int SPACING_BUTTONS = 6;
public const double ZOOM_CHANGE_VALUE = 0.1;
public const int MARGIN_CHANGE_VALUE = 2;
public const string RGBA_HEX_WHITE = "#ffffff";
public const string RGBA_HEX_BLACK = "#002B36";

Expand Down
8 changes: 5 additions & 3 deletions src/contentHandler.vala
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ public class BookwormApp.contentHandler {
}else{
onloadJavaScript.append("document.getElementsByTagName('BODY')[0].style.color='black';");
}
//Adjust page margin
string cssMargin = "<style>body{margin-right: "+BookwormApp.Bookworm.settings.reading_width+"%;margin-left: "+BookwormApp.Bookworm.settings.reading_width+"%;}</style>";

//add onload javascript to body tag
if(pageContent.index_of("<BODY") != -1){
pageContent = pageContent.replace("<BODY", "<BODY "+ javaScriptInjectionPrefix + onloadJavaScript.str + javaScriptInjectionSuffix);
pageContent = pageContent.replace("<BODY", cssMargin + "<BODY "+ javaScriptInjectionPrefix + onloadJavaScript.str + javaScriptInjectionSuffix);
}else if (pageContent.index_of("<body") != -1){
pageContent = pageContent.replace("<body", "<body "+ javaScriptInjectionPrefix + onloadJavaScript.str + javaScriptInjectionSuffix);
pageContent = pageContent.replace("<body", cssMargin + "<body "+ javaScriptInjectionPrefix + onloadJavaScript.str + javaScriptInjectionSuffix);
}else{
pageContent = "<BODY "+ javaScriptInjectionPrefix + onloadJavaScript.str + javaScriptInjectionSuffix + ">" + pageContent + "</BODY>";
pageContent = cssMargin + "<BODY "+ javaScriptInjectionPrefix + onloadJavaScript.str + javaScriptInjectionSuffix + ">" + pageContent + "</BODY>";
}
return pageContent;
}
Expand Down
46 changes: 44 additions & 2 deletions src/prefpopover.vala
Original file line number Diff line number Diff line change
Expand Up @@ -40,28 +40,48 @@ public class BookwormApp.PreferencesMenu {

Gtk.Box textSizeBox = new Gtk.Box(Orientation.HORIZONTAL, BookwormApp.Constants.SPACING_BUTTONS);
textSizeBox.pack_start(textSmallerButton, false, false);
textSizeBox.pack_start(textLargerButton, false, false);
textSizeBox.pack_end(textLargerButton, false, false);

Gtk.Image day_profile_image = new Gtk.Image ();
day_profile_image.set_from_file (Constants.DAY_PROFILE_IMAGE_LOCATION);
Gtk.Button dayProfileButton = new Gtk.Button();
dayProfileButton.set_image (day_profile_image);
dayProfileButton.set_halign(Gtk.Align.START);
dayProfileButton.set_relief (ReliefStyle.NONE);

Gtk.Image night_profile_image = new Gtk.Image ();
night_profile_image.set_from_file (Constants.NIGHT_PROFILE_IMAGE_LOCATION);
Gtk.Button nightProfileButton = new Gtk.Button();
nightProfileButton.set_image (night_profile_image);
nightProfileButton.set_halign(Gtk.Align.END);
nightProfileButton.set_relief (ReliefStyle.NONE);

Gtk.Box profileBox = new Gtk.Box(Orientation.HORIZONTAL, BookwormApp.Constants.SPACING_BUTTONS);
profileBox.pack_start(dayProfileButton, false, false);
profileBox.pack_start(nightProfileButton, false, false);
profileBox.pack_end(nightProfileButton, false, false);

Gtk.Image icon_margin_indent_more = new Gtk.Image.from_icon_name ("format-indent-more-symbolic", IconSize.MENU);
Gtk.Button marginIncreaseButton = new Gtk.Button();
marginIncreaseButton.set_image (icon_margin_indent_more);
marginIncreaseButton.set_halign(Gtk.Align.START);
marginIncreaseButton.set_relief (ReliefStyle.NONE);

Gtk.Image icon_margin_indent_less = new Gtk.Image.from_icon_name ("format-indent-less-symbolic", IconSize.MENU);
Gtk.Button marginDecreaseButton = new Gtk.Button();
marginDecreaseButton.set_image (icon_margin_indent_less);
marginDecreaseButton.set_halign(Gtk.Align.END);
marginDecreaseButton.set_relief (ReliefStyle.NONE);

Gtk.Box marginBox = new Gtk.Box(Orientation.HORIZONTAL, BookwormApp.Constants.SPACING_BUTTONS);
marginBox.pack_start(marginIncreaseButton, false, false);
marginBox.pack_end(marginDecreaseButton, false, false);

Gtk.Box prefBox = new Gtk.Box(Orientation.VERTICAL, BookwormApp.Constants.SPACING_BUTTONS);
prefBox.set_border_width(BookwormApp.Constants.SPACING_WIDGETS);
prefBox.pack_start(textSizeBox, false, false);
prefBox.pack_start(new Gtk.HSeparator() , true, true, 0);
prefBox.pack_start(marginBox, false, false);
prefBox.pack_start(new Gtk.HSeparator() , true, true, 0);
prefBox.pack_start(profileBox, false, false);

prefPopover.add(prefBox);
Expand Down Expand Up @@ -95,6 +115,28 @@ public class BookwormApp.PreferencesMenu {
}
});

marginIncreaseButton.clicked.connect (() => {
if(BookwormApp.Bookworm.settings.reading_width.to_int() < 40){
BookwormApp.Bookworm.settings.reading_width = (BookwormApp.Bookworm.settings.reading_width.to_int() + BookwormApp.Constants.MARGIN_CHANGE_VALUE).to_string();
if(BookwormApp.Bookworm.BOOKWORM_CURRENT_STATE == BookwormApp.Constants.BOOKWORM_UI_STATES[1]){
BookwormApp.Book currentBookForMarginIncrease = BookwormApp.Bookworm.libraryViewMap.get(BookwormApp.Bookworm.locationOfEBookCurrentlyRead);
currentBookForMarginIncrease = BookwormApp.Bookworm.renderPage(BookwormApp.Bookworm.libraryViewMap.get(BookwormApp.Bookworm.locationOfEBookCurrentlyRead), "");
BookwormApp.Bookworm.libraryViewMap.set(BookwormApp.Bookworm.locationOfEBookCurrentlyRead, currentBookForMarginIncrease);
}
}
});

marginDecreaseButton.clicked.connect (() => {
if(BookwormApp.Bookworm.settings.reading_width.to_int() > 1){
BookwormApp.Bookworm.settings.reading_width = (BookwormApp.Bookworm.settings.reading_width.to_int() - BookwormApp.Constants.MARGIN_CHANGE_VALUE).to_string();
if(BookwormApp.Bookworm.BOOKWORM_CURRENT_STATE == BookwormApp.Constants.BOOKWORM_UI_STATES[1]){
BookwormApp.Book currentBookForMarginDecrease = BookwormApp.Bookworm.libraryViewMap.get(BookwormApp.Bookworm.locationOfEBookCurrentlyRead);
currentBookForMarginDecrease = BookwormApp.Bookworm.renderPage(BookwormApp.Bookworm.libraryViewMap.get(BookwormApp.Bookworm.locationOfEBookCurrentlyRead), "");
BookwormApp.Bookworm.libraryViewMap.set(BookwormApp.Bookworm.locationOfEBookCurrentlyRead, currentBookForMarginDecrease);
}
}
});

return prefPopover;
}
}
1 change: 1 addition & 0 deletions src/settings.vala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public class BookwormApp.Settings : Granite.Services.Settings {
public double zoom_level { get; set; }
public string reading_profile { get; set; }
public bool is_local_storage_enabled { get; set; }
public string reading_width { get; set; }

public static Settings get_instance () {
if (instance == null) {
Expand Down

0 comments on commit 3d181a5

Please sign in to comment.