plugin code
[lbook_fbreader.git] / fbreader / src / collection / BookCollection.h
blob98250fd2a27ce1c69180e53ff72eb6e251c84f5d
1 /*
2 * Copyright (C) 2004-2008 Geometer Plus <contact@geometerplus.com>
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.
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.
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.
20 #ifndef __BOOKCOLLECTION_H__
21 #define __BOOKCOLLECTION_H__
23 #include <string>
24 #include <vector>
25 #include <set>
26 #include <map>
28 #include <ZLOptions.h>
30 #include "../description/BookDescription.h"
32 typedef std::vector<BookDescriptionPtr> Books;
34 class DescriptionComparator {
36 public:
37 DescriptionComparator();
38 ~DescriptionComparator();
39 bool operator() (const BookDescriptionPtr d1, const BookDescriptionPtr d2);
42 class BookCollection {
44 public:
45 ZLStringOption PathOption;
46 ZLBooleanOption ScanSubdirsOption;
48 public:
49 BookCollection();
50 ~BookCollection();
52 const std::vector<AuthorPtr> &authors() const;
53 const Books &books(AuthorPtr author) const;
54 bool isBookExternal(BookDescriptionPtr description) const;
56 void rebuild(bool strong);
57 bool synchronize() const;
59 private:
61 void collectDirNames(std::set<std::string> &names) const;
62 void collectBookFileNames(std::set<std::string> &bookFileNames) const;
64 void addDescription(BookDescriptionPtr description) const;
66 private:
67 mutable std::vector<AuthorPtr> myAuthors;
68 mutable std::map<AuthorPtr,Books> myCollection;
69 mutable std::set<BookDescriptionPtr> myExternalBooks;
71 mutable std::string myPath;
72 mutable bool myScanSubdirs;
73 mutable bool myDoStrongRebuild;
74 mutable bool myDoWeakRebuild;
77 class LastOpenedBooks {
79 public:
80 ZLIntegerRangeOption MaxListSizeOption;
82 public:
83 LastOpenedBooks();
84 ~LastOpenedBooks();
85 void addBook(const std::string &fileName);
86 const Books &books() const;
88 private:
89 Books myBooks;
92 inline DescriptionComparator::DescriptionComparator() {}
93 inline DescriptionComparator::~DescriptionComparator() {}
95 inline const std::vector<AuthorPtr > &BookCollection::authors() const {
96 synchronize();
97 return myAuthors;
100 inline const Books &BookCollection::books(AuthorPtr author) const {
101 synchronize();
102 return (*myCollection.find(author)).second;
105 inline bool BookCollection::isBookExternal(BookDescriptionPtr description) const {
106 synchronize();
107 return myExternalBooks.find(description) != myExternalBooks.end();
110 inline const Books &LastOpenedBooks::books() const { return myBooks; }
112 #endif /* __BOOKCOLLECTION_H__ */