Skip to content

Commit

Permalink
Slider for browsing the book and bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
babluboy committed May 9, 2017
1 parent 04b5959 commit 7b77c73
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 62 deletions.
4 changes: 2 additions & 2 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-06 23:05+0100\n"
"POT-Creation-Date: 2017-05-09 22:53+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 Down Expand Up @@ -62,7 +62,7 @@ msgid "Edit Info for"
msgstr ""

#: src/constants.vala:67
msgid "Enable content cache (opens books faster)"
msgid "Enable cache (opens books faster)"
msgstr ""

#: src/constants.vala:57
Expand Down
9 changes: 5 additions & 4 deletions src/book.vala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@
* You should have received a copy of the GNU General Public License along
* with Bookworm. If not, see http://www.gnu.org/licenses/.
*/

using Gtk;
using Gee;
public class BookwormApp.Book{

//These variables are persisted in the database
private int bookId = 0;
private bool isBookParsedCorrectly = false;
private string parsingIssue = "";
Expand All @@ -33,7 +33,10 @@ public class BookwormApp.Book{
private string bookCreationDate = "";
private string bookLastModificationDate = "";
private int bookRating = 1;
private StringBuilder bookmarks = new StringBuilder ("");
private ArrayList<string> bookContentList = new ArrayList<string> ();

//These variables are only available for the current session (not persisted)
private string opfFileLocation = "";
private string baseLocationOfContents = "";
private bool isBookCoverImagePresent = false;
Expand All @@ -43,9 +46,7 @@ public class BookwormApp.Book{
private bool isBookSelected = false;
private bool wasBookOpened = false;
private HashMap<string,Gtk.Widget> bookWidgetsList = new HashMap<string,Gtk.Widget> ();
private ArrayList<string> bookContentList = new ArrayList<string> ();
private ArrayList<HashMap<string,string>> TOCMap = new ArrayList<HashMap<string,string>>();
private StringBuilder bookmarks = new StringBuilder ("");

//getter list for book id
public void setBookId (int aBookId){
Expand Down
108 changes: 66 additions & 42 deletions src/bookinfo.vala
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class BookwormApp.Info:Gtk.Window {

//Check every time a tab is clicked and perform necessary actions
stack.notify["visible-child"].connect ((sender, property) => {
if("content-list"==stack.get_visible_child_name()){
createTableOfContents();
}
if("bookmark-list"==stack.get_visible_child_name()){
populateBookmarks();
}
Expand Down Expand Up @@ -152,52 +155,73 @@ public class BookwormApp.Info:Gtk.Window {
return aBook;
}

public static BookwormApp.Book createTableOfContents(owned BookwormApp.Book aBook){
Box content_box = new Box (Orientation.VERTICAL, BookwormApp.Constants.SPACING_WIDGETS);
//Use Table Of Contents if present
if(aBook.getTOC().size > 0){
ArrayList<HashMap<string,string>> tocList = aBook.getTOC();
foreach(HashMap<string,string> tocListItemMap in tocList){
foreach (var entry in tocListItemMap.entries) {
LinkButton contentLinkButton = new LinkButton.with_label (entry.key, entry.value);
contentLinkButton.halign = Align.START;
content_box.pack_start(contentLinkButton,false,false,0);
contentLinkButton.activate_link.connect (() => {
aBook.setBookPageNumber(aBook.getBookContentList().index_of(contentLinkButton.get_uri ().strip()));
//update book details to libraryView Map
BookwormApp.Bookworm.libraryViewMap.set(aBook.getBookLocation(), aBook);
aBook = BookwormApp.Bookworm.renderPage(aBook, "");
//Set the mode back to Reading mode
BookwormApp.Bookworm.BOOKWORM_CURRENT_STATE = BookwormApp.Constants.BOOKWORM_UI_STATES[1];
BookwormApp.Bookworm.getAppInstance().toggleUIState();
return true;
});
public static BookwormApp.Book createTableOfContents(){
Box content_box;
//get the book being currently read
BookwormApp.Book aBook = BookwormApp.Bookworm.libraryViewMap.get(BookwormApp.Bookworm.locationOfEBookCurrentlyRead);
if(aBook != null){
//Return TOC if it has already been determined for the book - otherwise create TOC for the book
if(aBook.getBookWidget("TABLE_OF_CONTENTS_WIDGET") != null){
content_box = (Gtk.Box) (aBook.getBookWidget("TABLE_OF_CONTENTS_WIDGET"));
debug("found TABLE_OF_CONTENTS_WIDGET");
}else{
content_box = new Box (Orientation.VERTICAL, BookwormApp.Constants.SPACING_WIDGETS);
//Use Table Of Contents if present
if(aBook.getTOC().size > 0){
ArrayList<HashMap<string,string>> tocList = aBook.getTOC();
foreach(HashMap<string,string> tocListItemMap in tocList){
foreach (var entry in tocListItemMap.entries) {
LinkButton contentLinkButton = new LinkButton.with_label (entry.key, entry.value);
contentLinkButton.halign = Align.START;
content_box.pack_start(contentLinkButton,false,false,0);
contentLinkButton.activate_link.connect (() => {
aBook.setBookPageNumber(aBook.getBookContentList().index_of(contentLinkButton.get_uri ().strip()));
//update book details to libraryView Map
BookwormApp.Bookworm.libraryViewMap.set(aBook.getBookLocation(), aBook);
aBook = BookwormApp.Bookworm.renderPage(aBook, "");
//Set the mode back to Reading mode
BookwormApp.Bookworm.BOOKWORM_CURRENT_STATE = BookwormApp.Constants.BOOKWORM_UI_STATES[1];
BookwormApp.Bookworm.getAppInstance().toggleUIState();
return true;
});
}
}
}else{
//If Table Of Contents is not found, set the spine data into the Contents tab
int contentNumber = 1;
foreach(string contentPath in aBook.getBookContentList()){
LinkButton contentLinkButton = new LinkButton.with_label (contentPath, BookwormApp.Constants.TEXT_FOR_INFO_TAB_CONTENT_PREFIX+contentNumber.to_string());
contentLinkButton.halign = Align.START;
content_box.pack_start(contentLinkButton,false,false,0);
contentNumber++;
contentLinkButton.activate_link.connect (() => {
aBook.setBookPageNumber(aBook.getBookContentList().index_of(contentLinkButton.get_uri ()));
//update book details to libraryView Map
BookwormApp.Bookworm.libraryViewMap.set(aBook.getBookLocation(), aBook);
aBook = BookwormApp.Bookworm.renderPage(aBook, "");
//Set the mode back to Reading mode
BookwormApp.Bookworm.BOOKWORM_CURRENT_STATE = BookwormApp.Constants.BOOKWORM_UI_STATES[1];
BookwormApp.Bookworm.getAppInstance().toggleUIState();
return true;
});
}
}
aBook.setBookWidget("TABLE_OF_CONTENTS_WIDGET", content_box);
}
}else{
//If Table Of Contents is not found, set the spine data into the Contents tab
int contentNumber = 1;
foreach(string contentPath in aBook.getBookContentList()){
LinkButton contentLinkButton = new LinkButton.with_label (contentPath, BookwormApp.Constants.TEXT_FOR_INFO_TAB_CONTENT_PREFIX+contentNumber.to_string());
contentLinkButton.halign = Align.START;
content_box.pack_start(contentLinkButton,false,false,0);
contentNumber++;
contentLinkButton.activate_link.connect (() => {
aBook.setBookPageNumber(aBook.getBookContentList().index_of(contentLinkButton.get_uri ()));
//update book details to libraryView Map
BookwormApp.Bookworm.libraryViewMap.set(aBook.getBookLocation(), aBook);
aBook = BookwormApp.Bookworm.renderPage(aBook, "");
//Set the mode back to Reading mode
BookwormApp.Bookworm.BOOKWORM_CURRENT_STATE = BookwormApp.Constants.BOOKWORM_UI_STATES[1];
BookwormApp.Bookworm.getAppInstance().toggleUIState();
return true;
});
//remove the current content widget from any existing parent (ViewPort is a default parent while adding to ScrollWindow)
content_box.unparent ();
if(content_scroll.get_child() != null){
//add a ref to the existing content widget so that it is not destoyed on removal
content_scroll.get_child().@ref();
//remove the existing content widget from the ScrollWindow
content_scroll.remove(content_scroll.get_child());
//add the current content widget to the ScrollWindow
content_scroll.add (content_box);
}else{
//No existing widget in the ScrollWindow, add the current content widget
content_scroll.add (content_box);
}
}
//Remove the existing content list Gtk.Box and add the current one
content_scroll.get_child().destroy();
content_scroll.add (content_box);

return aBook;
}
}
7 changes: 6 additions & 1 deletion src/bookworm.vala
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,9 @@ public class BookwormApp.Bookworm : Granite.Application {
toggleUIState();
//reset the contents of the search entry
BookwormApp.Info.searchresults_scroll.get_child().destroy();
//set the max value and the current value of the page slider
BookwormApp.AppWindow.pageAdjustment.set_upper(aBook.getBookContentList().size);
BookwormApp.AppWindow.pageAdjustment.set_value(aBook.getBookPageNumber());
//render the contents of the current page of book
aBook = renderPage(aBook, "");
}
Expand Down Expand Up @@ -446,7 +449,7 @@ public class BookwormApp.Bookworm : Granite.Application {
//Book Meta Data / Content View Mode
if(BOOKWORM_CURRENT_STATE == BookwormApp.Constants.BOOKWORM_UI_STATES[4]){
//UI for Reading View
BookwormApp.AppHeaderBar.headerSearchBar.set_placeholder_text(BookwormApp.Constants.TEXT_FOR_HEADERBAR_BOOK_SEARCH);
BookwormApp.AppHeaderBar.headerSearchBar.set_placeholder_text(BookwormApp.Constants.TEXT_FOR_HEADERBAR_LIBRARY_SEARCH);
BookwormApp.Info.info_box.show_all();
content_list_button.set_visible(true);
library_view_button.set_visible(true);
Expand Down Expand Up @@ -576,6 +579,8 @@ public class BookwormApp.Bookworm : Granite.Application {
handleBookMark("DISPLAY");
//set the navigation controls
aBook = BookwormApp.Bookworm.controlNavigation(aBook);
//set the current value of the page slider
BookwormApp.AppWindow.pageAdjustment.set_value(currentContentLocation+1);
return aBook;
}

Expand Down
2 changes: 1 addition & 1 deletion src/constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ namespace BookwormApp.Constants {

public const string TEXT_FOR_PREFERENCES_DIALOG_TITLE = _("Preferences");
public const string TEXT_FOR_PREFERENCES_COLOUR_SCHEME = _("Turn on Night Mode");
public const string TEXT_FOR_PREFERENCES_LOCAL_STORAGE = _("Enable content cache (opens books faster)");
public const string TEXT_FOR_PREFERENCES_LOCAL_STORAGE = _("Enable cache (opens books faster)");

public const int SPACING_WIDGETS = 12;
public const int SPACING_BUTTONS = 6;
Expand Down
16 changes: 8 additions & 8 deletions src/headerbar.vala
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,29 @@ public class BookwormApp.AppHeaderBar {
bookwormApp.library_view_button.can_focus = false;
bookwormApp.library_view_button.vexpand = false;

Gtk.Image content_list_button_image = new Gtk.Image ();
content_list_button_image.set_from_file (Constants.CONTENTS_VIEW_IMAGE_LOCATION);
Gtk.Image content_list_button_image = new Gtk.Image.from_icon_name ("view-list-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
bookwormApp.content_list_button = new Gtk.Button ();
bookwormApp.content_list_button.set_image (content_list_button_image);
bookwormApp.content_list_button.set_valign(Gtk.Align.CENTER);

Gtk.Image menu_icon_text_large = new Gtk.Image.from_icon_name ("format-text-larger-symbolic", Gtk.IconSize.LARGE_TOOLBAR);
bookwormApp.prefButton = new Gtk.Button();
bookwormApp.prefButton.set_image (menu_icon_text_large);
bookwormApp.prefButton.set_halign(Gtk.Align.START);
bookwormApp.prefButton.set_valign(Gtk.Align.CENTER);

Gtk.Popover prefPopover = BookwormApp.PreferencesMenu.createPrefPopOver(bookwormApp.prefButton);

Gtk.Image bookmark_inactive_button_image = new Gtk.Image ();
bookmark_inactive_button_image.set_from_file (Constants.BOOKMARK_INACTIVE_IMAGE_LOCATION);
bookmark_inactive_button = new Gtk.Button ();
bookmark_inactive_button.set_image (bookmark_inactive_button_image);
bookmark_inactive_button.set_halign(Gtk.Align.CENTER);
bookmark_inactive_button.set_valign(Gtk.Align.CENTER);

Gtk.Image bookmark_active_button_image = new Gtk.Image ();
bookmark_active_button_image.set_from_file (Constants.BOOKMARK_ACTIVE_IMAGE_LOCATION);
bookmark_active_button = new Gtk.Button ();
bookmark_active_button.set_image (bookmark_active_button_image);
bookmark_active_button.set_halign(Gtk.Align.CENTER);
bookmark_active_button.set_valign(Gtk.Align.CENTER);

headerbar.pack_start(bookwormApp.library_view_button);
headerbar.pack_start(bookwormApp.content_list_button);
Expand Down Expand Up @@ -98,7 +99,7 @@ public class BookwormApp.AppHeaderBar {

//Set actions for HeaderBar search
headerSearchBar.search_changed.connect (() => {
//Call the filter only if the Library View Mode is active and the default text is not present in the search box
//Call the filter only if the Library View Mode is active
if(!(bookwormApp.BOOKWORM_CURRENT_STATE == BookwormApp.Constants.BOOKWORM_UI_STATES[1] || bookwormApp.BOOKWORM_CURRENT_STATE == BookwormApp.Constants.BOOKWORM_UI_STATES[4])){
BookwormApp.AppWindow.library_grid.invalidate_filter ();
}
Expand Down Expand Up @@ -137,8 +138,7 @@ public class BookwormApp.AppHeaderBar {
}
});
bookwormApp.content_list_button.clicked.connect (() => {
BookwormApp.Book aBook = bookwormApp.libraryViewMap.get(bookwormApp.locationOfEBookCurrentlyRead);
BookwormApp.Info.createTableOfContents(aBook);
BookwormApp.Info.createTableOfContents();
//Set the mode to Content View Mode
bookwormApp.BOOKWORM_CURRENT_STATE = BookwormApp.Constants.BOOKWORM_UI_STATES[4];
bookwormApp.toggleUIState();
Expand Down
9 changes: 8 additions & 1 deletion src/utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,13 @@ namespace BookwormApp.Utils {
return outputString;
}

public static string removeMarkUp(string inputString){
string outputString = Soup.URI.decode(inputString);
//replace the escape char for space present in HTML converted from PDF
outputString = outputString.replace("&#160;", " ").replace("#160;", " ").replace("&#160", " ");
return outputString;
}

public static string removeTagsFromText(string input){
debug("Starting execution of removeTagsFromText on text:"+input);
StringBuilder filteredInput = new StringBuilder(input.strip());
Expand Down Expand Up @@ -634,7 +641,7 @@ namespace BookwormApp.Utils {
filteredInput.assign(removeTagsFromText(filteredInput.str.strip()));
}
//remove any html escape characters if present
filteredInput.assign(decodeHTMLChars(filteredInput.str));
filteredInput.assign(removeMarkUp(filteredInput.str));
//remove any line feeds
filteredInput.assign(filteredInput.str.replace("\n",""));
debug("Completed execution of removeTagsFromText with text:"+filteredInput.str);
Expand Down
25 changes: 22 additions & 3 deletions src/window.vala
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class BookwormApp.AppWindow {
public static Gtk.Button forward_button;
public static Gtk.Button back_button;
public static Gtk.ProgressBar bookAdditionBar;
public static Adjustment pageAdjustment;
public static Scale pageSlider;

public static Gtk.Box createBoookwormUI() {
debug("Starting to create main window components...");
Expand Down Expand Up @@ -107,7 +109,7 @@ public class BookwormApp.AppWindow {
aWebView.set_zoom_level(BookwormApp.Settings.get_instance().zoom_level);
webkitSettings.set_enable_javascript(true);
webkitSettings.set_default_font_family(aWebView.get_style_context().get_font(StateFlags.NORMAL).get_family ());

//Set up Button for previous page
Gtk.Image back_button_image = new Gtk.Image.from_icon_name ("go-previous-symbolic", Gtk.IconSize.MENU);
back_button = new Gtk.Button ();
Expand All @@ -120,12 +122,19 @@ public class BookwormApp.AppWindow {
forward_button.set_image (forward_button_image);
forward_button.set_relief (ReliefStyle.NONE);

//Set up a slider for jumping pages
pageAdjustment = new Adjustment (0, 1, 100, 1, 0, 0);
pageSlider = new Gtk.Scale(Gtk.Orientation.HORIZONTAL, pageAdjustment);
pageSlider.set_digits (0);
pageSlider.set_valign (Gtk.Align.START);
pageSlider.set_hexpand(true);

//Set up contents of the footer
ActionBar book_reading_footer_box = new ActionBar();
Gtk.Label pageNumberLabel = new Label("");
book_reading_footer_box.pack_start (back_button);
book_reading_footer_box.pack_start (pageNumberLabel);
book_reading_footer_box.pack_start (pageSlider);
book_reading_footer_box.pack_end (forward_button);
book_reading_footer_box.set_center_widget(pageSlider);

//Create the Gtk Box to hold components for reading a selected book
bookReading_ui_box = new Gtk.Box (Orientation.VERTICAL, 0);
Expand Down Expand Up @@ -165,6 +174,16 @@ public class BookwormApp.AppWindow {
BookwormApp.Bookworm.libraryViewMap.set(currentBookForReverse.getBookLocation(), currentBookForReverse);
BookwormApp.Bookworm.locationOfEBookCurrentlyRead = currentBookForReverse.getBookLocation();
});
//Add action for moving the pages for the page slider
pageSlider.value_changed.connect (() => {
BookwormApp.Book currentBookForSlider = new BookwormApp.Book();
currentBookForSlider = BookwormApp.Bookworm.libraryViewMap.get(BookwormApp.Bookworm.locationOfEBookCurrentlyRead);
currentBookForSlider.setBookPageNumber(pageSlider.get_value ().to_string().to_int()-1);
//update book details to libraryView Map
currentBookForSlider = BookwormApp.Bookworm.renderPage(currentBookForSlider, "");
BookwormApp.Bookworm.libraryViewMap.set(currentBookForSlider.getBookLocation(), currentBookForSlider);
BookwormApp.Bookworm.locationOfEBookCurrentlyRead = currentBookForSlider.getBookLocation();
});
//Add action for adding a book on the library view
add_book_button.clicked.connect (() => {
ArrayList<string> selectedEBooks = BookwormApp.Utils.selectFileChooser(Gtk.FileChooserAction.OPEN, _("Select eBook"), BookwormApp.Bookworm.window, true, BookwormApp.Utils.getFileTypeMapping("EBOOKS"), "EPUB");
Expand Down

0 comments on commit 7b77c73

Please sign in to comment.