-
Notifications
You must be signed in to change notification settings - Fork 29
/
runtimeconfiguration.cpp
358 lines (317 loc) · 11.5 KB
/
runtimeconfiguration.cpp
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
/*
dspdfviewer - Dual Screen PDF Viewer for LaTeX-Beamer
Copyright (C) 2012 Danny Edel <mail@danny-edel.de>
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 "runtimeconfiguration.h"
#include <boost/program_options.hpp>
#include <iostream>
#include <fstream>
#include <QCoreApplication>
#ifndef DSPDFVIEWER_VERSION
#warning DSPDFVIEWER_VERSION was not set by the build system!
#define DSPDFVIEWER_VERSION "UNKNOWN"
#endif
#ifndef I3WORKAROUND_SHELLCODE
/* This will get executed once both windows are created, provided
* the user passed --i3-workaround=true via command line or configuration file.
*
* You can override the shellcode by providing -DI3WORKAROUND_SHELLCODE="your shellcode"
* at the cmake step.
*/
#define I3WORKAROUND_SHELLCODE "i3-msg '[class=\"dspdfviewer\" window_role=\"Audience_Window\"] move to output right, fullscreen' && " \
" i3-msg '[class=\"dspdfviewer\" window_role=\"Secondary_Window\"]' fullscreen"
#endif
using namespace std;
using namespace boost::program_options;
RuntimeConfiguration::RuntimeConfiguration(int argc, const char* const * argv):
m_useFullPage(false),
m_showPresenterArea(true),
m_duplicate(false),
m_showWallClock(true),
m_showThumbnails(true),
m_thumbnailPagePart(PagePart::FullPage),
m_showPresentationClock(true),
m_showSlideClock(true),
m_filePath(),
m_hyperlinkSupport(true),
m_cacheToMemory(true),
m_cacheSizeMegaBytes(0),
m_useSecondScreen(true),
m_i3workaround(false),
m_prerenderPreviousPages(3),
m_prerenderNextPages(10),
m_bottomPaneHeightPercent(20)
{
options_description generic( tr("Generic options").toLocal8Bit().constData() );
/** FIXME: Using .toLocal8Bit() [.constData()] is Very Very Very Ugly,
* but works because program_options copies the string...
*/
generic.add_options()
("help,h", tr("Print help message").toLocal8Bit() )
("version,v", tr("Print version statement").toLocal8Bit() )
;
options_description global( tr("Options affecting program behaviour")
.toLocal8Bit().constData() );
global.add_options()
("full-page,f", //value<bool>(&m_useFullPage)->default_value(false)->implicit_value(true),
tr("Display the full slide on both screens (useful for PDFs created by presentation software other than latex-beamer)").toLocal8Bit() )
("prerender-previous-pages",
value<unsigned>(&m_prerenderPreviousPages)->default_value(3),
tr("Pre-render the preceding arg slides\n"
"NOTE: If you set this to zero, you might not get a thumbnail for the previous slide unless it was loaded already."
).toLocal8Bit()
)
("prerender-next-pages",
value<unsigned>(&m_prerenderNextPages)->default_value(10),
tr(
"Pre-render the next arg slides\n"
"NOTE: If you set this to zero, you might not get a thumbnail for the next slide unless it was loaded already."
).toLocal8Bit()
)
("hyperlink-support,l",
value<bool>(&m_hyperlinkSupport)->default_value(true),
tr(
"Support PDF Hyperlinks\n"
"Follow hyperlinks when clicked (mouse pointer will change to a pointing hand) - set this to false if "
"you cannot reliably control your mouse pointer position and want to always go ahead one slide on click.").toLocal8Bit()
)
("cache-to-memory",
value<bool>(&m_cacheToMemory)->default_value(true),
tr(
"Cache the PDF file into memory\n"
"Useful if you are editing the PDF file with latex while using the presenter software.").toLocal8Bit()
)
("cache-size",
value<unsigned>(&m_cacheSizeMegaBytes)->default_value(1024),
tr(
"Size of the cache for pre-rendered pages, in megabytes."
).toLocal8Bit()
)
("i3-workaround",
value<bool>(&m_i3workaround)->default_value(false),
tr(
"Use i3 specific workaround: Execute shellcode once both windows have been created.")
#ifndef NDEBUG
.append( QString::fromUtf8(
"\nDebug info: Shellcode is \n"
I3WORKAROUND_SHELLCODE
) )
#endif
.toLocal8Bit()
)
;
options_description secondscreen( tr("Options affecting the second screen").toLocal8Bit().constData() );
secondscreen.add_options()
("use-second-screen,u",
value<bool>(&m_useSecondScreen)->default_value(true),
tr(
"Use the second screen. If you only have one monitor and just want to use this application as a fast, pre-caching PDF viewer"
" you might want to say 0 here.\n"
"NOTE: Whatever you say on -a, -t, -w, -s or -p doesn't matter if you set this to false.\n"
"NOTE: You might want to say -f if you set this to false."
).toLocal8Bit()
)
("presenter-area,a",
value<bool>(&m_showPresenterArea)->default_value(true),
tr(
"Shows or hides the complete \"presenter area\" on the second screen, giving you a full-screen note page.\n"
"NOTE: Whatever you say on -t, -w, -s or -p doesnt matter if you set this to false."
).toLocal8Bit()
)
("duplicate,d",
value<bool>(&m_duplicate)->default_value(false),
tr("Duplicates the audience's screen next to the notes on the second screen.").toLocal8Bit()
)
("thumbnails,t",
value<bool>(&m_showThumbnails)->default_value(true),
tr(
"Show thumbnails of previous, current and next slide").toLocal8Bit()
)
("thumbnail-page-part,T",
value<PagePart>(&m_thumbnailPagePart)->default_value(PagePart::FullPage),
tr("Thumbnails show this page part. Valid values are \"left\", \"right\" or \"both\"").toLocal8Bit()
)
("wall-clock,w",
value<bool>(&m_showWallClock)->default_value(true),
tr(
"Show the wall clock").toLocal8Bit()
)
("presentation-clock,p",
value<bool>(&m_showPresentationClock)->default_value(true),
tr(
"Show the presentation clock").toLocal8Bit()
)
("slide-clock,s",
value<bool>(&m_showSlideClock)->default_value(true),
tr("Show the slide clock").toLocal8Bit()
)
("bottom-pane-height,b",
value<unsigned>(&m_bottomPaneHeightPercent)->default_value(20),
tr("Percentage of second screen to use for the bottom pane").toLocal8Bit()
)
;
options_description hidden(tr("Hidden options").toLocal8Bit().constData());
hidden.add_options()
("pdf-file", value< string >(&m_filePath), tr("PDF File to display").toLocal8Bit())
;
positional_options_description p;
p.add("pdf-file", 1);
options_description help;
help.add(generic).add(global).add(secondscreen);
options_description commandLineOptions;
commandLineOptions.add(help).add(hidden);
options_description configFileOptions;
configFileOptions.add(global).add(secondscreen);
variables_map vm;
store( command_line_parser(argc,argv).options(commandLineOptions).positional(p).run(), vm);
QString configurationFileLocation = QString::fromUtf8( qgetenv("HOME").append("/.config/dspdfviewer.ini") );
{
// See if the configuration file exists and is readable
std::ifstream cfile( qPrintable(configurationFileLocation) );
if ( cfile.good() ) {
store( parse_config_file( cfile, configFileOptions), vm);
}
} // close input file
notify(vm);
if ( vm.count("version") || vm.count("help") ) {
cout << "dspdfviewer version " << DSPDFVIEWER_VERSION << endl;
cout << tr( "Written by Danny Edel\n"
"\n"
"Copyright (C) 2012 Danny Edel.\n"
"This is free software; see the source for copying conditions. There is NO\n"
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.").toLocal8Bit().constData() << endl;
if ( vm.count("help")) {
cout << endl;
cout << tr("Usage: %1 [options] pdf-file").arg( QString::fromUtf8(argv[0]) ).toLocal8Bit().constData() << endl;
cout << help << endl;
/*: Please try to keep line length below 70 chars and use \t (tab) for padding */
cout << tr("Interactive Controls:\n"
"\tPress F1 or ? during program execution to get a quick\n"
"\toverview about available controls.\n"
"\tPlease read the manpage (man dspdfviewer) for the full list.").toLocal8Bit().constData() << endl;
}
exit(0);
}
if ( m_bottomPaneHeightPercent < 1 || m_bottomPaneHeightPercent > 99 ) {
throw std::runtime_error( tr("Invalid height in specified. Please use a value from 1 to 99 (inclusive)").toLocal8Bit().constData() );
}
m_useFullPage = ( 0 < vm.count("full-page") );
/** Implied options */
if ( ! m_useSecondScreen ) {
/* If we dont use a second screen, there's no point in using the presenter area */
m_showPresenterArea = false;
}
if ( ! m_showPresenterArea ) {
/* If the presenter area is hidden, disable all clocks and the thumbnails */
m_showPresentationClock = false;
m_showWallClock = false;
m_showSlideClock = false;
/* This option will effectively disable rendering of thumbnails */
m_showThumbnails = false;
}
}
string RuntimeConfiguration::filePath() const
{
if ( m_filePath.empty() ) {
throw noFileNameException();
}
return m_filePath;
}
QString RuntimeConfiguration::filePathQString() const
{
return QString::fromLocal8Bit( filePath().c_str() );
}
bool RuntimeConfiguration::useFullPage() const
{
return m_useFullPage;
}
bool RuntimeConfiguration::showPresentationClock() const
{
return m_showPresentationClock;
}
bool RuntimeConfiguration::showPresenterArea() const
{
return m_showPresenterArea;
}
bool RuntimeConfiguration::duplicate() const
{
return m_duplicate;
}
bool RuntimeConfiguration::showSlideClock() const
{
return m_showSlideClock;
}
bool RuntimeConfiguration::showThumbnails() const
{
return m_showThumbnails;
}
bool RuntimeConfiguration::showWallClock() const
{
return m_showWallClock;
}
unsigned int RuntimeConfiguration::prerenderNextPages() const
{
return m_prerenderNextPages;
}
unsigned int RuntimeConfiguration::prerenderPreviousPages() const
{
return m_prerenderPreviousPages;
}
bool RuntimeConfiguration::useSecondScreen() const
{
return m_useSecondScreen;
}
PDFCacheOption RuntimeConfiguration::cacheSetting() const
{
return m_cacheToMemory?
PDFCacheOption::keepPDFinMemory :
PDFCacheOption::rereadFromDisk;
}
unsigned int RuntimeConfiguration::bottomPaneHeight() const
{
return m_bottomPaneHeightPercent;
}
bool RuntimeConfiguration::hyperlinkSupport() const
{
return m_hyperlinkSupport;
}
void RuntimeConfiguration::filePath(const std::string& newPath )
{
m_filePath = newPath;
}
bool RuntimeConfiguration::filePathDefined() const
{
return ! m_filePath.empty();
}
noFileNameException::noFileNameException():
logic_error( QCoreApplication::translate("DSPDFViewer", "You did not specify a PDF-File to display.").toLocal8Bit().constData() ) {
}
bool RuntimeConfiguration::i3workaround() const
{
return m_i3workaround;
}
std::string RuntimeConfiguration::i3workaround_shellcode() const
{
return std::string( I3WORKAROUND_SHELLCODE );
}
PagePart RuntimeConfiguration::thumbnailPagePart() const
{
return m_thumbnailPagePart;
}
unsigned RuntimeConfiguration::cacheSizeBytes() const {
return cacheSizeMegaBytes()*1024*1024;
}
unsigned RuntimeConfiguration::cacheSizeMegaBytes() const{
return m_cacheSizeMegaBytes;
}