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
|
/*
* Copyright (C) 2004-2012 Geometer Plus <[email protected]>
*
* 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.
*/
#ifndef __FORMATPLUGIN_H__
#define __FORMATPLUGIN_H__
#include <string>
#include <vector>
#include <shared_ptr.h>
#include <ZLOptions.h>
class Book;
class BookModel;
class ZLOptionsDialog;
class ZLOptionsDialogTab;
class ZLFile;
class ZLInputStream;
class ZLImage;
class FormatInfoPage {
protected:
FormatInfoPage();
public:
virtual ~FormatInfoPage();
};
class FormatPlugin {
protected:
FormatPlugin();
public:
virtual ~FormatPlugin();
virtual bool providesMetaInfo() const = 0;
virtual bool acceptsFile(const ZLFile &file) const = 0;
virtual FormatInfoPage *createInfoPage(ZLOptionsDialog &dialog, const ZLFile &file);
virtual const std::string &tryOpen(const ZLFile &file) const;
virtual bool readMetaInfo(Book &book) const = 0;
virtual bool readLanguageAndEncoding(Book &book) const = 0;
virtual bool readModel(BookModel &model) const = 0;
virtual shared_ptr<const ZLImage> coverImage(const ZLFile &file) const;
protected:
static bool detectEncodingAndLanguage(Book &book, ZLInputStream &stream, bool force = false);
static bool detectLanguage(Book &book, ZLInputStream &stream, const std::string &encoding, bool force = false);
};
class PluginCollection {
public:
ZLBooleanOption LanguageAutoDetectOption;
ZLStringOption DefaultLanguageOption;
ZLStringOption DefaultEncodingOption;
public:
static PluginCollection &Instance();
static void deleteInstance();
private:
PluginCollection();
public:
shared_ptr<FormatPlugin> plugin(const ZLFile &file, bool strong);
shared_ptr<FormatPlugin> plugin(const Book &book);
private:
static PluginCollection *ourInstance;
std::vector<shared_ptr<FormatPlugin> > myPlugins;
};
inline FormatInfoPage::FormatInfoPage() {}
inline FormatInfoPage::~FormatInfoPage() {}
inline FormatPlugin::FormatPlugin() {}
inline FormatPlugin::~FormatPlugin() {}
inline FormatInfoPage *FormatPlugin::createInfoPage(ZLOptionsDialog&, const ZLFile&) { return 0; }
#endif /* __FORMATPLUGIN_H__ */
|