1 /* 2 * Copyright (C) 2004-2010 Geometer Plus <contact@geometerplus.com> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 17 * 02110-1301, USA. 18 */ 19 20 #ifndef __FBREADER_H__ 21 #define __FBREADER_H__ 22 23 #include <string> 24 #include <map> 25 26 #include <ZLOptions.h> 27 #include <ZLTime.h> 28 #include <ZLView.h> 29 #include <ZLApplication.h> 30 #include <ZLKeyBindings.h> 31 32 #include "../library/Library.h" 33 #include "../external/ProgramCollection.h" 34 35 class ZLFile; 36 class ZLMessageHandler; 37 38 class Book; 39 class BookModel; 40 class BookTextView; 41 42 class FBReader : public ZLApplication { 43 44 public: 45 static FBReader &Instance(); 46 47 public: 48 // returns true if description was found or error message was shown 49 static bool createBook(const ZLFile &bookFile, shared_ptr<Book> &book); 50 51 static const std::string PageIndexParameter; 52 53 public: 54 enum ViewMode { 55 UNDEFINED_MODE = 0, 56 BOOK_TEXT_MODE = 1 << 0, 57 FOOTNOTE_MODE = 1 << 1, 58 CONTENTS_MODE = 1 << 2, 59 BOOKMARKS_MODE = 1 << 3, 60 LIBRARY_MODE = 1 << 4, 61 NETWORK_LIBRARY_MODE = 1 << 5, 62 ALL_MODES = 0xFF 63 }; 64 65 public: 66 ZLBooleanOption QuitOnCancelOption; 67 68 ZLIntegerRangeOption KeyScrollingDelayOption; 69 ZLIntegerRangeOption LinesToScrollOption; 70 ZLIntegerRangeOption LinesToKeepOption; 71 ZLBooleanOption EnableTapScrollingOption; 72 ZLBooleanOption TapScrollingOnFingerOnlyOption; 73 74 ZLBooleanOption UseSeparateBindingsOption; 75 76 ZLBooleanOption EnableSingleClickDictionaryOption; 77 78 ZLStringOption LastOpenedPreferencesDialog; 79 80 public: 81 FBReader(const std::string &bookToOpen); 82 ~FBReader(); 83 84 void setMode(ViewMode mode); 85 ViewMode mode() const; 86 87 shared_ptr<Book> currentBook() const; 88 89 void refreshWindow(); 90 91 private: 92 void initWindow(); 93 94 void clearTextCaches(); 95 96 void restorePreviousMode(); 97 98 bool closeView(); 99 std::string helpFileName(const std::string &language) const; 100 101 void openFile(const ZLFile &file); 102 bool canDragFiles(const std::vector<std::string> &filePaths) const; 103 void dragFiles(const std::vector<std::string> &filePaths); 104 105 bool isViewFinal() const; 106 107 void showLibraryView(); 108 109 public: 110 shared_ptr<ZLKeyBindings> keyBindings(); 111 shared_ptr<ZLKeyBindings> keyBindings(ZLView::Angle angle); 112 113 bool isDictionarySupported() const; 114 void openInDictionary(const std::string &word); 115 116 shared_ptr<ProgramCollection> webBrowserCollection() const; 117 void openLinkInBrowser(const std::string &url) const; 118 119 void tryShowFootnoteView(const std::string &id, const std::string &type); 120 BookTextView &bookTextView() const; 121 void showBookTextView(); 122 void openBook(shared_ptr<Book> book); 123 124 void invalidateNetworkView(); 125 void invalidateAccountDependents(); 126 127 private: 128 shared_ptr<ProgramCollection> dictionaryCollection() const; 129 130 void openBookInternal(shared_ptr<Book> book); 131 friend class OpenBookRunnable; 132 void rebuildCollectionInternal(); 133 friend class RebuildCollectionRunnable; 134 friend class OptionsApplyRunnable; 135 136 private: 137 ViewMode myMode; 138 ViewMode myPreviousMode; 139 140 shared_ptr<ZLView> myFootnoteView; 141 shared_ptr<ZLView> myBookTextView; 142 shared_ptr<ZLView> myContentsView; 143 shared_ptr<ZLView> myNetworkLibraryView; 144 shared_ptr<ZLView> myLibraryByAuthorView; 145 shared_ptr<ZLView> myLibraryByTagView; 146 shared_ptr<ZLPopupData> myRecentBooksPopupData; 147 shared_ptr<ZLPopupData> myPreferencesPopupData; 148 149 ZLTime myLastScrollingTime; 150 151 shared_ptr<BookModel> myModel; 152 153 shared_ptr<ZLKeyBindings> myBindings0; 154 shared_ptr<ZLKeyBindings> myBindings90; 155 shared_ptr<ZLKeyBindings> myBindings180; 156 shared_ptr<ZLKeyBindings> myBindings270; 157 158 std::string myBookToOpen; 159 bool myBookAlreadyOpen; 160 161 ProgramCollectionMap myProgramCollectionMap; 162 163 shared_ptr<ZLMessageHandler> myOpenFileHandler; 164 165 enum { 166 RETURN_TO_TEXT_MODE, 167 UNFULLSCREEN 168 } myActionOnCancel; 169 170 friend class OpenFileHandler; 171 172 friend class OptionsDialog; 173 friend class SystemOptionsDialog; 174 friend class FBView; 175 176 //friend class ShowCollectionAction; 177 friend class ShowHelpAction; 178 //friend class ShowOptionsDialogAction; 179 friend class ShowContentsAction; 180 friend class AddBookAction; 181 friend class ShowBookInfoAction; 182 //friend class ScrollToHomeAction; 183 //friend class ScrollToStartOfTextAction; 184 //friend class ScrollToEndOfTextAction; 185 friend class UndoAction; 186 //friend class RedoAction; 187 friend class SearchAction; 188 friend class SearchPatternAction; 189 friend class FindNextAction; 190 friend class FindPreviousAction; 191 friend class ScrollingAction; 192 friend class ScrollingAction2; 193 friend class ChangeFontSizeAction; 194 friend class CancelAction; 195 //friend class ToggleIndicatorAction; 196 friend class QuitAction; 197 friend class OpenPreviousBookAction; 198 friend class GotoNextTOCSectionAction; 199 friend class GotoPreviousTOCSectionAction; 200 //friend class GotoPageNumber; 201 friend class SelectionAction; 202 friend class SearchOnNetworkAction; 203 friend class AdvancedSearchOnNetworkAction; 204 friend class FBFullscreenAction; 205 friend class BooksOrderAction; 206 friend class LogOutAction; 207 }; 208 209 #endif /* __FBREADER_H__ */ 210