Skip to content

Commit

Permalink
Fixes for file chooser and setting of book cover image
Browse files Browse the repository at this point in the history
  • Loading branch information
babluboy committed May 18, 2017
1 parent 7cb9fcb commit 0887fd5
Show file tree
Hide file tree
Showing 9 changed files with 98 additions and 73 deletions.
8 changes: 7 additions & 1 deletion data/com.github.babluboy.bookworm.appdata.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,14 @@
<summary>A simple, focused eBook reader</summary>
<description>
<p>Read the books you love without having to worry about the different format complexities like epub, pdf, mobi, cbr, etc.</p>
<p>Manage your library with access to update book metadata and quickly find books with tag based filtering and metadata searching.<p>
<p>Manage your library with access to update book metadata and quickly find books with tag based filtering and metadata searching.</p>
<p>This version supports EPUB, PDF and Comics (CBR and CBZ) formats with support for more formats to follow soon.</p>
<p>Key features for Bookworm v0.7:</p>
<ul>
​ <li>Support for Comics (CBR and CBZ formats)</li>
​ <li>Full screen reading view</li>
<li>Sepia colour profile for reading</li>
​ </ul>
</description>
<screenshots>
<screenshot type="default">
Expand Down
2 changes: 1 addition & 1 deletion data/com.github.babluboy.bookworm.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Name=Bookworm
GenericName=eBook Reader
Comment=A simple ebook reader for Elementary OS
Categories=Office;
MimeType=application/epub+zip;application/pdf;application/x-pdf;
MimeType=application/epub+zip;application/pdf;application/x-pdf;application/cbr;application/x-cbz;
Exec=bookworm %F
Icon=bookworm
Terminal=false
Expand Down
58 changes: 33 additions & 25 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-17 20:54+0100\n"
"POT-Creation-Date: 2017-05-18 18:22+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,15 +17,15 @@ msgstr ""
"Content-Type: text/plain; charset=CHARSET\n"
"Content-Transfer-Encoding: 8bit\n"

#: src/constants.vala:103
#: src/constants.vala:106
msgid "About"
msgstr ""

#: src/constants.vala:69
#: src/constants.vala:72
msgid "Add books to library"
msgstr ""

#: src/constants.vala:134
#: src/constants.vala:70
msgid "All Files"
msgstr ""

Expand All @@ -41,6 +41,10 @@ msgstr ""
msgid "Bookmarks"
msgstr ""

#: src/constants.vala:68
msgid "Books"
msgstr ""

#: src/constants.vala:47
msgid "Bookworm does not support the format of the file found at location : "
msgstr ""
Expand All @@ -57,11 +61,11 @@ msgstr ""
msgid "Click on a link to jump to bookmarked section"
msgstr ""

#: src/constants.vala:74
#: src/constants.vala:77
msgid "Click to bookmark this page"
msgstr ""

#: src/constants.vala:75
#: src/constants.vala:78
msgid "Click to remove this bookmark"
msgstr ""

Expand All @@ -73,35 +77,35 @@ msgstr ""
msgid "Contents"
msgstr ""

#: src/constants.vala:84
#: src/constants.vala:87
msgid "Dark theme"
msgstr ""

#: src/constants.vala:77
#: src/constants.vala:80
msgid "Decrease font size"
msgstr ""

#: src/constants.vala:81
#: src/constants.vala:84
msgid "Decrease line spacing"
msgstr ""

#: src/constants.vala:79
#: src/constants.vala:82
msgid "Decrease line width"
msgstr ""

#: src/constants.vala:59
msgid "Edit Info for"
msgstr ""

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

#: src/constants.vala:65
msgid "Enter full screen view"
msgstr ""

#: src/constants.vala:86 src/constants.vala:87
#: src/constants.vala:89 src/constants.vala:90
msgid "Enter full screen view and Esc key to exit"
msgstr ""

Expand All @@ -113,15 +117,19 @@ msgstr ""
msgid "Found the following matches for '$$$' in &&&:"
msgstr ""

#: src/constants.vala:76
#: src/constants.vala:69
msgid "Images"
msgstr ""

#: src/constants.vala:79
msgid "Increase font size"
msgstr ""

#: src/constants.vala:80
#: src/constants.vala:83
msgid "Increase line spacing"
msgstr ""

#: src/constants.vala:78
#: src/constants.vala:81
msgid "Increase line width"
msgstr ""

Expand All @@ -141,7 +149,7 @@ msgstr ""
msgid "Library"
msgstr ""

#: src/constants.vala:83
#: src/constants.vala:86
msgid "Light theme"
msgstr ""

Expand All @@ -163,7 +171,7 @@ msgstr ""
msgid "Not Available"
msgstr ""

#: src/constants.vala:90 src/constants.vala:104
#: src/constants.vala:93 src/constants.vala:107
msgid "Preferences"
msgstr ""

Expand All @@ -173,7 +181,7 @@ msgid ""
"location : "
msgstr ""

#: src/constants.vala:70
#: src/constants.vala:73
msgid "Remove selected books from library (eBook file will not be deleted)"
msgstr ""

Expand All @@ -193,31 +201,31 @@ msgstr ""
msgid "Search this book..."
msgstr ""

#: src/constants.vala:72
#: src/constants.vala:75
msgid "See Table of Contents, Bookmarks and Search Results"
msgstr ""

#: src/constants.vala:43
msgid "Select an eBook to read"
msgstr ""

#: src/constants.vala:71
#: src/constants.vala:74
msgid "Select one or more books in library"
msgstr ""

#: src/constants.vala:85
#: src/constants.vala:88
msgid "Sepia theme"
msgstr ""

#: src/constants.vala:73
#: src/constants.vala:76
msgid "Set reading preferences"
msgstr ""

#: src/constants.vala:91
#: src/constants.vala:94
msgid "Turn on Night Mode"
msgstr ""

#: src/constants.vala:102
#: src/constants.vala:105
msgid "Unknown Book"
msgstr ""

Expand All @@ -237,7 +245,7 @@ msgstr ""
msgid "Update Title"
msgstr ""

#: src/constants.vala:82
#: src/constants.vala:85
msgid "Update cover image"
msgstr ""

Expand Down
Binary file modified screenshots/BookwormLibraryView.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion src/constants.vala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ namespace BookwormApp.Constants {
public const string TEXT_FOR_PAGE_CONTEXTMENU_FULL_SCREEN_ENTRY = _("Enter full screen view");
public const string TEXT_FOR_PAGE_CONTEXTMENU_FULL_SCREEN_EXIT = _("Exit full screen view");
public const string TEXT_FOR_PAGE_CONTEXTMENU_WORD_MEANING = _("Check Word Meaning");
public const string TEXT_FOR_FILE_CHOOSER_FILTER_BOOKS = _("Books");
public const string TEXT_FOR_FILE_CHOOSER_FILTER_IMAGES = _("Images");
public const string TEXT_FOR_FILE_CHOOSER_FILTER_ALL_FILES = _("All Files");

public const string TOOLTIP_TEXT_FOR_ADD_BOOK = _("Add books to library");
public const string TOOLTIP_TEXT_FOR_REMOVE_BOOK = _("Remove selected books from library (eBook file will not be deleted)");
Expand Down Expand Up @@ -131,7 +134,9 @@ namespace BookwormApp.Constants {
public static const int MAX_BOOK_COVER_PER_ROW = 6;
public static const int MAX_NUMBER_OF_LINES_PER_PAGE = 30;
public static const int MAX_NUMBER_OF_CHARS_PER_LINE = 80;
public static const string FILE_CHOOSER_FILTER_ALL_FILES = _("All Files");
public static const string FILE_CHOOSER_FILTER_EBOOKS[] = {"*.epub", "*.pdf", "*.cbr", "*.cbz"};
public static const string FILE_CHOOSER_FILTER_IMAGES[] = {"*.jpg", "*.jpeg", "*.gif", "*.png", "*.svg"};


public static const string BOOKWORM_READING_MODE[] = {"DAY MODE",
"SEPIA MODE",
Expand Down
4 changes: 2 additions & 2 deletions src/dialog.vala
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public class BookwormApp.AppDialog : Gtk.Dialog {
updateCoverImageBox.pack_start(updateCoverImageButton,false, true, 0);
//Add action for setting cover image
updateCoverImageButton.clicked.connect (() => {
ArrayList<string> selectedFiles = BookwormApp.Utils.selectFileChooser(Gtk.FileChooserAction.OPEN, _("Select Image"), BookwormApp.Bookworm.window, false, BookwormApp.Utils.getFileTypeMapping("IMAGES"), "JPG");
ArrayList<string> selectedFiles = BookwormApp.Utils.selectFileChooser(Gtk.FileChooserAction.OPEN, _("Select Image"), BookwormApp.Bookworm.window, false, "IMAGES");
if(selectedFiles != null && selectedFiles.size > 0){
string selectedCoverImagePath = selectedFiles.get(0);
//copy cover image to bookworm cover image cache
Expand Down Expand Up @@ -87,7 +87,7 @@ public class BookwormApp.AppDialog : Gtk.Dialog {
updateTitleBox.pack_end(updateTitleEntry,false, true, 0);
//Add action for setting Book Title
updateTitleEntry.focus_out_event.connect (() => {
if(updateTitleEntry.get_text() != null && updateTitleEntry.get_text().length > 0){
if(!aBook.getIsBookCoverImagePresent() && updateTitleEntry.get_text() != null && updateTitleEntry.get_text().length > 0){
aBook.setBookTitle(updateTitleEntry.get_text());
aBook.setWasBookOpened(true);
//refresh the library view
Expand Down
18 changes: 15 additions & 3 deletions src/library.vala
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class BookwormApp.Library{
Gtk.Image bookSelectionImage;
Gtk.Image bookSelectedImage;
string bookCoverLocation;

Gdk.Pixbuf aBookCover;
Gdk.Pixbuf bookPlaceholderCoverPix = new Gdk.Pixbuf.from_file_at_scale(BookwormApp.Constants.PLACEHOLDER_COVER_IMAGE_LOCATION, 150, 200, false);
Gtk.Image bookPlaceholderCoverImage = new Gtk.Image.from_pixbuf(bookPlaceholderCoverPix);

Expand All @@ -37,8 +37,20 @@ public class BookwormApp.Library{
bookCoverLocation = BookwormApp.Constants.DEFAULT_COVER_IMAGE_LOCATION.replace("N", GLib.Random.int_range(1, 6).to_string());
aBook.setBookCoverLocation(bookCoverLocation);
}
Gdk.Pixbuf aBookCover = new Gdk.Pixbuf.from_file_at_scale(aBook.getBookCoverLocation(), 150, 200, false);
aCoverImage = new Gtk.Image.from_pixbuf(aBookCover);
try{
aBookCover = new Gdk.Pixbuf.from_file_at_scale(aBook.getBookCoverLocation(), 150, 200, false);
aCoverImage = new Gtk.Image.from_pixbuf(aBookCover);
}catch(GLib.Error e){
//Sometimes the path to the image selected by the parser is not a image
//This catch block assigns a default cover selected at random to cover this issue
bookCoverLocation = BookwormApp.Constants.DEFAULT_COVER_IMAGE_LOCATION.replace("N", GLib.Random.int_range(1, 6).to_string());
aBook.setBookCoverLocation(bookCoverLocation);
aBookCover = new Gdk.Pixbuf.from_file_at_scale(aBook.getBookCoverLocation(), 150, 200, false);
aCoverImage = new Gtk.Image.from_pixbuf(aBookCover);
//set cover image present flag to false - this will add title text to the default cover
aBook.setIsBookCoverImagePresent(false);
}

aCoverImage.set_halign(Align.START);
aCoverImage.set_valign(Align.START);

Expand Down
70 changes: 32 additions & 38 deletions src/utils.vala
Original file line number Diff line number Diff line change
Expand Up @@ -513,33 +513,10 @@ namespace BookwormApp.Utils {
debug("Completed creating Table Of Contents....");
return tocHTML.str;
}
//Utility function to provide a filter list of file types. This is used for file chooser dialog filter
public static Gee.HashMap<string, string> getFileTypeMapping(string fileType){
Gee.HashMap<string, string> filterMap = new Gee.HashMap<string, string>();
switch(fileType){
case "EBOOKS":
filterMap.set("*.epub", "EPUB");
filterMap.set("*.pdf", "PDF");
filterMap.set("*", BookwormApp.Constants.FILE_CHOOSER_FILTER_ALL_FILES);
break;
case "IMAGES":
filterMap.set("*.jpg", "JPG");
filterMap.set("*.jpeg", "JPEG");
filterMap.set("*.gif", "GIF");
filterMap.set("*.png", "PNG");
filterMap.set("*", BookwormApp.Constants.FILE_CHOOSER_FILTER_ALL_FILES);
break;
default:
filterMap.set("*", BookwormApp.Constants.FILE_CHOOSER_FILTER_ALL_FILES);
break;
}
return filterMap;
}


// Create a GtkFileChooserDialog to perform the action desired
//The filterMap should be in the format: key=*.epub, value=ePUB, key=*.jpg, value=Images
public Gtk.FileChooserDialog new_file_chooser_dialog (Gtk.FileChooserAction action, string title, Gtk.Window? parent, bool select_multiple, Gee.HashMap<string, string> filterMap, string defaultFilterName) {
bool isFilterSet = false;
public Gtk.FileChooserDialog new_file_chooser_dialog (Gtk.FileChooserAction action, string title, Gtk.Window? parent, bool select_multiple, string filterType) {
Gtk.FileChooserDialog aFileChooserDialog = new Gtk.FileChooserDialog (title, parent, action);
aFileChooserDialog.set_select_multiple (select_multiple);
aFileChooserDialog.add_button (_("Cancel"), Gtk.ResponseType.CANCEL);
Expand All @@ -550,10 +527,9 @@ namespace BookwormApp.Utils {
aFileChooserDialog.set_current_name("");
}
aFileChooserDialog.set_default_response (Gtk.ResponseType.ACCEPT);
debug("Setting File chooser to open on folder:"+BookwormApp.Utils.last_file_chooser_path);
if(BookwormApp.Utils.last_file_chooser_path != null && BookwormApp.Utils.last_file_chooser_path.length != 0){
bool aFileChooserDialogOpeningstatus = aFileChooserDialog.set_current_folder_file (GLib.File.new_for_path(BookwormApp.Utils.last_file_chooser_path));
debug("Opening FileChooserDialog with path:"+BookwormApp.Utils.last_file_chooser_path+" returned status:"+aFileChooserDialogOpeningstatus.to_string());
debug("Opening FileChooserDialog with last used path:"+BookwormApp.Utils.last_file_chooser_path+" returned status:"+aFileChooserDialogOpeningstatus.to_string());
}else{
aFileChooserDialog.set_current_folder (GLib.Environment.get_home_dir ());
}
Expand All @@ -563,25 +539,43 @@ namespace BookwormApp.Utils {
return false;
});

foreach (var entry in filterMap.entries) {
Gtk.FileFilter files_filter = new Gtk.FileFilter ();
files_filter.set_filter_name (entry.value);
files_filter.add_pattern (entry.key);
aFileChooserDialog.add_filter (files_filter);
if((!isFilterSet) && defaultFilterName == entry.value){
aFileChooserDialog.set_filter (files_filter);
isFilterSet = true;
}
//Set File filters based on the required Filter Type
switch(filterType){
case "EBOOKS":
Gtk.FileFilter ebook_files_filter = new Gtk.FileFilter ();
//Add filter for supported eBook formats
ebook_files_filter.set_filter_name (BookwormApp.Constants.TEXT_FOR_FILE_CHOOSER_FILTER_BOOKS);
foreach (string pattern in BookwormApp.Constants.FILE_CHOOSER_FILTER_EBOOKS) {
ebook_files_filter.add_pattern (pattern);
}
aFileChooserDialog.add_filter (ebook_files_filter);
break;
case "IMAGES":
Gtk.FileFilter image_files_filter = new Gtk.FileFilter ();
//Add filter for supported eBook formats
image_files_filter.set_filter_name (BookwormApp.Constants.TEXT_FOR_FILE_CHOOSER_FILTER_IMAGES);
foreach (string pattern in BookwormApp.Constants.FILE_CHOOSER_FILTER_IMAGES) {
image_files_filter.add_pattern (pattern);
}
aFileChooserDialog.add_filter (image_files_filter);
break;
default:
break;
}
//Set the All Files filter
Gtk.FileFilter all_files_filter = new Gtk.FileFilter ();
all_files_filter.set_filter_name (BookwormApp.Constants.TEXT_FOR_FILE_CHOOSER_FILTER_ALL_FILES);
all_files_filter.add_pattern ("*");
aFileChooserDialog.add_filter (all_files_filter);
return aFileChooserDialog;
}

public static ArrayList<string> selectFileChooser(Gtk.FileChooserAction action, string title, Gtk.Window? parent, bool select_multiple, Gee.HashMap<string, string> filterMap, string defaultFilterName){
public static ArrayList<string> selectFileChooser(Gtk.FileChooserAction action, string title, Gtk.Window? parent, bool select_multiple, string filterType){
ArrayList<string> eBookLocationList = new ArrayList<string>();
//create a hashmap to hold details for the book
Gee.HashMap<string,string> bookDetailsMap = new Gee.HashMap<string,string>();
//choose eBook using a File chooser dialog
Gtk.FileChooserDialog aFileChooserDialog = BookwormApp.Utils.new_file_chooser_dialog (action, title, parent, select_multiple, filterMap, defaultFilterName);
Gtk.FileChooserDialog aFileChooserDialog = BookwormApp.Utils.new_file_chooser_dialog (action, title, parent, select_multiple, filterType);
aFileChooserDialog.show_all ();
if (aFileChooserDialog.run () == Gtk.ResponseType.ACCEPT) {
SList<string> uris = aFileChooserDialog.get_uris ();
Expand Down
Loading

0 comments on commit 0887fd5

Please sign in to comment.