1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
/*
* Copyright (C) 2009-2012 Geometer Plus <contact@geometerplus.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301, USA.
*/
#include <ZLResource.h>
#include <ZLImage.h>
#include "LibraryNodes.h"
#include "../library/Book.h"
#include "../library/Author.h"
#include "../library/Tag.h"
#include "../libraryActions/LibraryBookActions.h"
#include "../reader/Reader.h"
#include "../formats/FormatPlugin.h"
const ZLTypeId BookNode::TYPE_ID(ReaderNode::TYPE_ID);
const ZLTypeId &BookNode::typeId() const {
return TYPE_ID;
}
const ZLResource &BookNode::resource() const {
return ZLResource::resource("libraryView")["bookNode"];
}
BookNode::BookNode(AuthorNode *parent, shared_ptr<Book> book) : ReaderNode(parent), myBook(book) {
}
BookNode::BookNode(SeriesNode *parent, shared_ptr<Book> book) : ReaderNode(parent), myBook(book) {
}
BookNode::BookNode(TagNode *parent, std::size_t atPosition, shared_ptr<Book> book) : ReaderNode(parent, atPosition), myBook(book) {
}
void BookNode::init() {
registerAction(new BookReadAction(myBook));
registerAction(new BookEditInfoAction(myBook));
registerAction(new BookRemoveAction(myBook));
}
shared_ptr<Book> BookNode::book() const {
return myBook;
}
std::string BookNode::title() const {
return myBook->title();
}
std::string BookNode::summary() const {
ReaderNode *parent = (ReaderNode*)this->parent();
while (!parent->isInstanceOf(AuthorNode::TYPE_ID) &&
!parent->isInstanceOf(TagNode::TYPE_ID)) {
parent = (ReaderNode*)parent->parent();
}
if (parent->isInstanceOf(AuthorNode::TYPE_ID)) {
const TagList &tags = myBook->tags();
if (tags.empty()) {
return std::string();
} else {
std::string tagsText;
for (TagList::const_iterator it = tags.begin(); it != tags.end(); ++it) {
if (!tagsText.empty()) {
tagsText += ", ";
}
tagsText += (*it)->name();
}
return tagsText;
}
} else {
const AuthorList &authors = myBook->authors();
if (authors.empty()) {
return ZLResource::resource("libraryView")["authorNode"]["unknownAuthor"].value();
} else {
std::string authorsText;
for (AuthorList::const_iterator it = authors.begin(); it != authors.end(); ++it) {
if (!authorsText.empty()) {
authorsText += ", ";
}
authorsText += (*it)->name();
}
return authorsText;
}
}
}
bool BookNode::highlighted() const {
return myBook->file() == Reader::Instance().currentBook()->file();
}
shared_ptr<const ZLImage> BookNode::extractCoverImage() const {
shared_ptr<FormatPlugin> plugin = PluginCollection::Instance().plugin(*myBook);
if (!plugin.isNull()) {
shared_ptr<const ZLImage> cover = plugin->coverImage(myBook->file());
if (!cover.isNull()) {
return cover;
}
}
return defaultCoverImage("booktree-book.png");
}
|