Skip to content

Commit

Permalink
Fixed book's opening at libraries. Added Help book to library.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruslan Nigmatullin committed Sep 28, 2011
1 parent 30e3dd2 commit 15c07b1
Show file tree
Hide file tree
Showing 19 changed files with 376 additions and 159 deletions.
10 changes: 5 additions & 5 deletions TODO.meego
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ DONE "About fbreader" text should be changed to the version without icons
(I was sure that's already done -- in symbian version at least)
** Is this done for all languages?
DONE all the QML list dialogs: add left/right margins (~1 mm)

*'About FBReader' book should be listed in the library in both 'by author'
DONE 'About FBReader' book should be listed in the library in both 'by author'
and 'by tag' subtrees. (In 'Unknown author' and 'Books with no tags' branches.)
** It looks like already been listed at both subtrees
DONE I've put a file *.fb2.zip into ~/MyDocs/Books directory, however the book
Expand All @@ -20,9 +19,7 @@ DONE I tried to increase font (just edited corresponding field in Preferences di
** Looks like there is an issue in integer (integer range?) field editor. I found
the same bahaviour when tried to edit progress indicator height.
DONE The default font size value should be 22.
* By default progress indcator option is set to 'vertical scrollbar' value. However
scrollbar is not shown. Should be.
* Default option value should be changed to 'horizontal indicator'.
DONE Default option value should be changed to 'horizontal indicator'.
DONE Is it possible to draw 'bootom toolbar' without resizing of text area? That's not
convinient that text area receives a resize event every time this toolbar is
shown/hidden.
Expand All @@ -31,3 +28,6 @@ DONE In preferences dialog combo boxes are too wide. There is no space between l
DONE 'Apply' button semantics in preferences dialog is not clear. Does it apply
preferences in current window only, or all the settings over the dialog? Is this
preferences dialog look/behaviour consistent with guidelines/other meego applications?

* By default progress indcator option is set to 'vertical scrollbar' value. However
scrollbar is not shown. Should be.
19 changes: 19 additions & 0 deletions fbreader/src/fbreader/FBReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ void FBReader::openBook(shared_ptr<Book> book) {
OpenBookRunnable runnable(book);
ZLDialogManager::Instance().wait(ZLResourceKey("loadingBook"), runnable);
resetWindowCaption();
refreshWindow();
}

void FBReader::openBookInternal(shared_ptr<Book> book) {
Expand Down Expand Up @@ -378,6 +379,13 @@ void FBReader::tryShowFootnoteView(const std::string &id, const std::string &typ
}
}

void FBReader::bookDownloadingProgress(DownloadBookRunnable *downloader, int downloaded, int size) {
// TODO: Implement me
(void) downloader;
(void) downloaded;
(void) size;
}

void FBReader::bookDownloaded(DownloadBookRunnable *downloader) {
if (downloader->hasErrors()) {
downloader->showErrorMessage();
Expand Down Expand Up @@ -484,6 +492,17 @@ std::string FBReader::helpFileName(const std::string &language) const {
return ZLibrary::ApplicationDirectory() + ZLibrary::FileNameDelimiter + "help" + ZLibrary::FileNameDelimiter + "MiniHelp." + language + ".fb2";
}

shared_ptr<Book> FBReader::helpFile(const std::string &language) const {
return BooksDBUtil::getBook(helpFileName(language));
}

shared_ptr<Book> FBReader::helpFile() const {
shared_ptr<Book> book = helpFile(ZLibrary::Language());
if (book.isNull())
book = helpFile("en");
return book;
}

void FBReader::openFile(const ZLFile &file) {
shared_ptr<Book> book;
createBook(file, book);
Expand Down
3 changes: 3 additions & 0 deletions fbreader/src/fbreader/FBReader.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ class FBReader : public ZLApplication, public DownloadBookListener {
ViewMode mode() const;

shared_ptr<Book> currentBook() const;
shared_ptr<Book> helpFile() const;

void refreshWindow();

Expand All @@ -99,6 +100,7 @@ class FBReader : public ZLApplication, public DownloadBookListener {

bool closeView();
std::string helpFileName(const std::string &language) const;
shared_ptr<Book> helpFile(const std::string &language) const;

void openFile(const ZLFile &file);
bool canDragFiles(const std::vector<std::string> &filePaths) const;
Expand All @@ -119,6 +121,7 @@ class FBReader : public ZLApplication, public DownloadBookListener {
void openLinkInBrowser(const std::string &url) const;

void tryShowFootnoteView(const std::string &id, const std::string &type);
void bookDownloadingProgress(DownloadBookRunnable *downloader, int downloaded, int size);
void bookDownloaded(DownloadBookRunnable *runnable);
BookTextView &bookTextView() const;
void showBookTextView();
Expand Down
5 changes: 1 addition & 4 deletions fbreader/src/fbreader/FBReaderActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ void SetModeAction::run() {

void ShowHelpAction::run() {
FBReader &fbreader = FBReader::Instance();
shared_ptr<Book> book = BooksDBUtil::getBook(fbreader.helpFileName(ZLibrary::Language()));
if (book.isNull()) {
book = BooksDBUtil::getBook(fbreader.helpFileName("en"));
}
shared_ptr<Book> book = fbreader.helpFile();
if (!book.isNull()) {
fbreader.openBook(book);
fbreader.setMode(FBReader::BOOK_TEXT_MODE);
Expand Down
8 changes: 8 additions & 0 deletions fbreader/src/library/Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "Book.h"
#include "Author.h"
#include "Tag.h"
#include "../fbreader/FBReader.h"

#include "../formats/FormatPlugin.h"

Expand Down Expand Up @@ -135,6 +136,13 @@ void Library::rebuildBookSet() const {
}
}
}

// help file
shared_ptr<Book> help = FBReader::Instance().helpFile();
if (!help.isNull()) {
insertIntoBookSet(help);
myExternalBooks.insert(help);
}
}

size_t Library::revision() const {
Expand Down
35 changes: 30 additions & 5 deletions fbreader/src/networkActions/NetworkActions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
#include "../library/Book.h"
#include "../fbreader/FBReader.h"

NetworkBookReadAction::NetworkBookReadAction(const NetworkBookItem &book, bool demo) : myBook(book), myDemo(demo) {
NetworkBookReadAction::NetworkBookReadAction(ZLTreeNode *node, const NetworkBookItem &book, bool demo) : myNode(node), myBook(book), myDemo(demo) {
}

ZLResourceKey NetworkBookReadAction::key() const {
Expand Down Expand Up @@ -72,11 +72,13 @@ void NetworkBookReadAction::run() {
fbreader.openBook(bookPtr);
fbreader.setMode(FBReader::BOOK_TEXT_MODE);
fbreader.refreshWindow();
myNode->close();
}
}
finished(std::string());
}

NetworkBookDownloadAction::NetworkBookDownloadAction(const NetworkBookItem &book, bool demo, const std::string &tag) : myBook(book), myDemo(demo), myTag(tag) {
NetworkBookDownloadAction::NetworkBookDownloadAction(ZLTreeNode *node, const NetworkBookItem &book, bool demo, const std::string &tag) : myNode(node), myBook(book), myDemo(demo), myTag(tag) {
}

ZLResourceKey NetworkBookDownloadAction::key() const {
Expand All @@ -101,24 +103,33 @@ bool NetworkBookDownloadAction::makesSense() const {

void NetworkBookDownloadAction::run() {
if (!NetworkOperationRunnable::tryConnect()) {
finished(std::string());
return;
}

shared_ptr<BookReference> reference = myBook.reference(
myDemo ? BookReference::DOWNLOAD_DEMO : BookReference::DOWNLOAD_FULL
);
if (reference.isNull()) {
finished(std::string());
return;
}

DownloadBookRunnable *downloader = new DownloadBookRunnable(reference, myBook.Link.authenticationManager());
downloader->setListener(this);
downloader->run();
}

void NetworkBookDownloadAction::bookDownloadingProgress(DownloadBookRunnable *downloader, int downloaded, int size) {
(void)downloader;
setPercent(downloaded, size);
}

void NetworkBookDownloadAction::bookDownloaded(DownloadBookRunnable *downloader) {
if (downloader->hasErrors()) {
downloader->showErrorMessage();
finished(downloader->errorMessage());
setListener(0);
return;
}

Expand All @@ -132,6 +143,8 @@ void NetworkBookDownloadAction::bookDownloaded(DownloadBookRunnable *downloader)
const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title);
ZLDialogManager::Instance().errorBox(boxKey, message);
fbreader.refreshWindow();
finished(message);
setListener(0);
return;
}

Expand All @@ -156,6 +169,9 @@ void NetworkBookDownloadAction::bookDownloaded(DownloadBookRunnable *downloader)
fbreader.openBook(downloaderBook);
fbreader.setMode(FBReader::BOOK_TEXT_MODE);
fbreader.refreshWindow();
finished(std::string());
setListener(0);
myNode->close();
}

NetworkBookBuyDirectlyAction::NetworkBookBuyDirectlyAction(const NetworkBookItem &book) : myBook(book) {
Expand All @@ -173,7 +189,7 @@ bool NetworkBookBuyDirectlyAction::makesSense() const {
}

std::string NetworkBookBuyDirectlyAction::text(const ZLResource &resource) const {
const std::string text = ZLRunnableWithKey::text(resource);
const std::string text = ZLTreeAction::text(resource);
shared_ptr<BookReference> reference = myBook.reference(BookReference::BUY);
if (!reference.isNull()) {
return ZLStringUtil::printf(text, ((BuyBookReference&)*reference).Price);
Expand All @@ -184,26 +200,31 @@ std::string NetworkBookBuyDirectlyAction::text(const ZLResource &resource) const
void NetworkBookBuyDirectlyAction::run() {
FBReader &fbreader = FBReader::Instance();
if (myBook.Link.authenticationManager().isNull()) {
finished(std::string());
return;
}
if (!NetworkOperationRunnable::tryConnect()) {
finished(std::string());
return;
}
NetworkAuthenticationManager &mgr = *myBook.Link.authenticationManager();
if (mgr.isAuthorised().Status != B3_TRUE) {
if (!AuthenticationDialog::run(mgr)) {
finished(std::string());
return;
}
fbreader.invalidateAccountDependents();
fbreader.refreshWindow();
if (!mgr.needPurchase(myBook)) {
finished(std::string());
return;
}
}
ZLResourceKey boxKey("purchaseConfirmBox");
const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title);
const int code = ZLDialogManager::Instance().questionBox(boxKey, message, ZLResourceKey("buy"), ZLResourceKey("buyAndDownload"), ZLDialogManager::CANCEL_BUTTON);
if (code == 2) {
finished(std::string());
return;
}
bool downloadBook = code == 1;
Expand All @@ -216,12 +237,13 @@ void NetworkBookBuyDirectlyAction::run() {
}
}
if (downloadBook) {
NetworkBookDownloadAction(myBook, false).run();
NetworkBookDownloadAction(0, myBook, false).run();
}
if (mgr.isAuthorised().Status == B3_FALSE) {
fbreader.invalidateAccountDependents();
}
fbreader.refreshWindow();
finished(std::string());
}

NetworkBookBuyInBrowserAction::NetworkBookBuyInBrowserAction(const NetworkBookItem &book) : myBook(book) {
Expand All @@ -240,7 +262,7 @@ bool NetworkBookBuyInBrowserAction::makesSense() const {
}

std::string NetworkBookBuyInBrowserAction::text(const ZLResource &resource) const {
const std::string text = ZLRunnableWithKey::text(resource);
const std::string text = ZLTreeAction::text(resource);
shared_ptr<BookReference> reference = myBook.reference(BookReference::BUY_IN_BROWSER);
if (!reference.isNull()) {
return ZLStringUtil::printf(text, ((BuyBookReference&)*reference).Price);
Expand All @@ -253,6 +275,7 @@ void NetworkBookBuyInBrowserAction::run() {
if (!reference.isNull()) {
FBReader::Instance().openLinkInBrowser(reference->URL);
}
finished(std::string());
}

NetworkBookDeleteAction::NetworkBookDeleteAction(const NetworkBookItem &book) : myBook(book) {
Expand All @@ -270,9 +293,11 @@ void NetworkBookDeleteAction::run() {
ZLResourceKey boxKey("deleteLocalCopyBox");
const std::string message = ZLStringUtil::printf(ZLDialogManager::dialogMessage(boxKey), myBook.Title);
if (ZLDialogManager::Instance().questionBox(boxKey, message, ZLDialogManager::YES_BUTTON, ZLDialogManager::NO_BUTTON) != 0) {
finished(std::string());
return;
}

myBook.removeLocalFiles();
FBReader::Instance().refreshWindow();
finished(std::string());
}
18 changes: 11 additions & 7 deletions fbreader/src/networkActions/NetworkActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,38 +22,42 @@

#include <ZLRunnable.h>
#include "NetworkOperationRunnable.h"
#include <ZLTreeNode.h>

class NetworkBookItem;

class NetworkBookDownloadAction : public ZLRunnableWithKey, public DownloadBookListener {
class NetworkBookDownloadAction : public ZLTreeAction, public DownloadBookListener {

public:
NetworkBookDownloadAction(const NetworkBookItem &book, bool demo, const std::string &tag = std::string());
NetworkBookDownloadAction(ZLTreeNode *node, const NetworkBookItem &book, bool demo, const std::string &tag = std::string());
ZLResourceKey key() const;
bool makesSense() const;
void run();
void bookDownloadingProgress(DownloadBookRunnable *downloader, int downloaded, int size);
void bookDownloaded(DownloadBookRunnable *runnable);

private:
ZLTreeNode *myNode;
const NetworkBookItem &myBook;
const bool myDemo;
const std::string myTag;
};

class NetworkBookReadAction : public ZLRunnableWithKey {
class NetworkBookReadAction : public ZLTreeAction {

public:
NetworkBookReadAction(const NetworkBookItem &book, bool demo);
NetworkBookReadAction(ZLTreeNode *node, const NetworkBookItem &book, bool demo);
ZLResourceKey key() const;
bool makesSense() const;
void run();

private:
ZLTreeNode *myNode;
const NetworkBookItem &myBook;
const bool myDemo;
};

class NetworkBookBuyDirectlyAction : public ZLRunnableWithKey {
class NetworkBookBuyDirectlyAction : public ZLTreeAction {

public:
NetworkBookBuyDirectlyAction(const NetworkBookItem &book);
Expand All @@ -66,7 +70,7 @@ class NetworkBookBuyDirectlyAction : public ZLRunnableWithKey {
const NetworkBookItem &myBook;
};

class NetworkBookBuyInBrowserAction : public ZLRunnableWithKey {
class NetworkBookBuyInBrowserAction : public ZLTreeAction {

public:
NetworkBookBuyInBrowserAction(const NetworkBookItem &book);
Expand All @@ -79,7 +83,7 @@ class NetworkBookBuyInBrowserAction : public ZLRunnableWithKey {
const NetworkBookItem &myBook;
};

class NetworkBookDeleteAction : public ZLRunnableWithKey {
class NetworkBookDeleteAction : public ZLTreeAction {

public:
NetworkBookDeleteAction(const NetworkBookItem &book);
Expand Down
1 change: 1 addition & 0 deletions fbreader/src/networkActions/NetworkOperationRunnable.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ class DownloadBookListener {
public:
virtual ~DownloadBookListener();

virtual void bookDownloadingProgress(DownloadBookRunnable *downloader, int downloaded, int size) = 0;
virtual void bookDownloaded(DownloadBookRunnable *runnable) = 0;
};

Expand Down
8 changes: 4 additions & 4 deletions fbreader/src/networkTree/NetworkBookNode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ void NetworkBookNode::init() {
const NetworkBookItem &book = this->book();
if (!book.reference(BookReference::DOWNLOAD_FULL).isNull() ||
!book.reference(BookReference::DOWNLOAD_FULL_CONDITIONAL).isNull()) {
registerAction(new NetworkBookReadAction(book, false));
registerAction(new NetworkBookDownloadAction(book, false));
registerAction(new NetworkBookReadAction(this, book, false));
registerAction(new NetworkBookDownloadAction(this, book, false));
registerAction(new NetworkBookDeleteAction(book));
}
if (!book.reference(BookReference::DOWNLOAD_DEMO).isNull()) {
registerAction(new NetworkBookReadAction(book, true));
registerAction(new NetworkBookDownloadAction(book, true, resource()["demo"].value()));
registerAction(new NetworkBookReadAction(this, book, true));
registerAction(new NetworkBookDownloadAction(this, book, true, resource()["demo"].value()));
}
if (!book.reference(BookReference::BUY).isNull()) {
registerAction(new NetworkBookBuyDirectlyAction(book));
Expand Down
Loading

0 comments on commit 15c07b1

Please sign in to comment.