1 //========================================================================
2 //
3 // ViewerPreferences.cc
4 //
5 // This file is licensed under the GPLv2 or later
6 //
7 // Copyright 2011 Pino Toscano <pino@kde.org>
8 // Copyright 2017, 2020 Albert Astals Cid <aacid@kde.org>
9 // Copyright 2019 Marek Kasik <mkasik@redhat.com>
10 //
11 //========================================================================
12
13 #include <config.h>
14
15 #include "ViewerPreferences.h"
16
17 #include "Object.h"
18 #include "Dict.h"
19
ViewerPreferences(Dict * prefDict)20 ViewerPreferences::ViewerPreferences(Dict *prefDict)
21 {
22 init();
23
24 hideToolbar = prefDict->lookup("HideToolbar").getBoolWithDefaultValue(false);
25
26 hideMenubar = prefDict->lookup("HideMenubar").getBoolWithDefaultValue(false);
27
28 hideWindowUI = prefDict->lookup("HideWindowUI").getBoolWithDefaultValue(false);
29
30 fitWindow = prefDict->lookup("FitWindow").getBoolWithDefaultValue(false);
31
32 centerWindow = prefDict->lookup("CenterWindow").getBoolWithDefaultValue(false);
33
34 displayDocTitle = prefDict->lookup("DisplayDocTitle").getBoolWithDefaultValue(false);
35
36 Object obj = prefDict->lookup("NonFullScreenPageMode");
37 if (obj.isName()) {
38 const char *mode = obj.getName();
39 if (!strcmp(mode, "UseNone")) {
40 nonFullScreenPageMode = nfpmUseNone;
41 } else if (!strcmp(mode, "UseOutlines")) {
42 nonFullScreenPageMode = nfpmUseOutlines;
43 } else if (!strcmp(mode, "UseThumbs")) {
44 nonFullScreenPageMode = nfpmUseThumbs;
45 } else if (!strcmp(mode, "UseOC")) {
46 nonFullScreenPageMode = nfpmUseOC;
47 }
48 }
49
50 obj = prefDict->lookup("Direction");
51 if (obj.isName()) {
52 const char *dir = obj.getName();
53 if (!strcmp(dir, "L2R")) {
54 direction = directionL2R;
55 } else if (!strcmp(dir, "R2L")) {
56 direction = directionR2L;
57 }
58 }
59
60 obj = prefDict->lookup("PrintScaling");
61 if (obj.isName()) {
62 const char *ps = obj.getName();
63 if (!strcmp(ps, "None")) {
64 printScaling = printScalingNone;
65 } else if (!strcmp(ps, "AppDefault")) {
66 printScaling = printScalingAppDefault;
67 }
68 }
69
70 obj = prefDict->lookup("Duplex");
71 if (obj.isName()) {
72 const char *d = obj.getName();
73 if (!strcmp(d, "Simplex")) {
74 duplex = duplexSimplex;
75 } else if (!strcmp(d, "DuplexFlipShortEdge")) {
76 duplex = duplexDuplexFlipShortEdge;
77 } else if (!strcmp(d, "DuplexFlipLongEdge")) {
78 duplex = duplexDuplexFlipLongEdge;
79 }
80 }
81
82 pickTrayByPDFSize = prefDict->lookup("PickTrayByPDFSize").getBoolWithDefaultValue(false);
83
84 obj = prefDict->lookup("NumCopies");
85 if (obj.isInt()) {
86 numCopies = obj.getInt();
87 if (numCopies < 2)
88 numCopies = 1;
89 }
90
91 obj = prefDict->lookup("PrintPageRange");
92 if (obj.isArray()) {
93 Array *range = obj.getArray();
94 int length = range->getLength();
95 int pageNumber1, pageNumber2;
96
97 if (length % 2 == 1)
98 length--;
99
100 for (int i = 0; i < length; i += 2) {
101 Object obj2 = range->get(i);
102 Object obj3 = range->get(i + 1);
103
104 if (obj2.isInt() && (pageNumber1 = obj2.getInt()) >= 1 && obj3.isInt() && (pageNumber2 = obj3.getInt()) >= 1 && pageNumber1 < pageNumber2) {
105 printPageRange.emplace_back(pageNumber1, pageNumber2);
106 } else {
107 printPageRange.clear();
108 break;
109 }
110 }
111 }
112 }
113
~ViewerPreferences()114 ViewerPreferences::~ViewerPreferences() { }
115
init()116 void ViewerPreferences::init()
117 {
118 nonFullScreenPageMode = nfpmUseNone;
119 direction = directionL2R;
120 printScaling = printScalingAppDefault;
121 duplex = duplexNone;
122 numCopies = 1;
123 }
124