1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program. Following this notice may exist
4 a copyright and/or license notice that predates the release of Scribus 1.3.2
5 for which a new license (GPL+exception) is in place.
6 */
7 
8 #include "ui/prefs_preflightverifier.h"
9 #include "prefsstructs.h"
10 #include "util.h"
11 
Prefs_PreflightVerifier(QWidget * parent,ScribusDoc * doc)12 Prefs_PreflightVerifier::Prefs_PreflightVerifier(QWidget* parent, ScribusDoc* doc)
13 	: Prefs_Pane(parent)
14 {
15 	setupUi(this);
16 	languageChange();
17 
18 	m_caption = tr("Preflight Verifier");
19 	m_icon = "16/preflight-verifier.png";
20 
21 	connect(currentProfileComboBox, SIGNAL(activated(const QString&)), this, SLOT(setProfile(const QString&)));
22 	connect(currentProfileComboBox, SIGNAL(editTextChanged(const QString&)), this, SLOT(setProfile(const QString&)));
23 
24 	connect(ignoreAllErrorsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
25 	connect(autoCheckBeforePrintExportCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
26 	connect(checkMissingGlyphsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
27 	connect(checkItemsNotOnAPageCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
28 	connect(checkTextOverflowCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
29 	connect(checkTransparenciesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
30 	connect(checkMissingImagesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
31 	connect(checkPartFilledImageFramesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
32 	connect(checkImageResolutionCheckBox, SIGNAL(toggled(bool)), this, SLOT(putProfile()));
33 	connect(checkPDFAnnotFieldsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
34 	connect(checkPlacedPDFCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
35 	connect(checkGIFsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
36 	connect(minimumResolutionSpinBox, SIGNAL(valueChanged(int)), this, SLOT(putProfile()));
37 	connect(maximumResolutionSpinBox, SIGNAL(valueChanged(int)), this, SLOT(putProfile()));
38 	connect(checkNonPrintableLayersCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
39 	connect(checkVisiblePrintableLayersCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
40 	connect(removeProfilePushButton, SIGNAL(clicked()), this, SLOT(delProf()));
41 	connect(addProfilePushButton, SIGNAL(clicked()), this, SLOT(addProf()));
42 	connect(checkAppliedMasterPageLocationCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
43 	connect(checkEmptyTextFramesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
44 }
45 
46 Prefs_PreflightVerifier::~Prefs_PreflightVerifier() = default;
47 
languageChange()48 void Prefs_PreflightVerifier::languageChange()
49 {
50 }
51 
restoreDefaults(struct ApplicationPrefs * prefsData)52 void Prefs_PreflightVerifier::restoreDefaults(struct ApplicationPrefs *prefsData)
53 {
54 	showPagesWithoutErrorsCheckBox->setChecked(prefsData->verifierPrefs.showPagesWithoutErrors);
55 	showNonPrintingLayerErrorsCheckBox->setChecked(prefsData->verifierPrefs.showNonPrintingLayerErrors);
56 	checkerProfiles = prefsData->verifierPrefs.checkerPrefsList;
57 	currentProfileComboBox->clear();
58 	CheckerPrefsList::Iterator it;
59 	currentProfileComboBox->clear();
60 	for (it = checkerProfiles.begin(); it != checkerProfiles.end(); ++it)
61 		currentProfileComboBox->addItem(it.key());
62 	QString prefProfile(prefsData->verifierPrefs.curCheckProfile);
63 	setCurrentComboItem(currentProfileComboBox, prefProfile);
64 
65 	CheckerPrefs& checkerProfile = checkerProfiles[prefProfile];
66 	ignoreAllErrorsCheckBox->setChecked(checkerProfile.ignoreErrors);
67 	autoCheckBeforePrintExportCheckBox->setChecked(checkerProfile.autoCheck);
68 	checkMissingGlyphsCheckBox->setChecked(checkerProfile.checkGlyphs);
69 	checkItemsNotOnAPageCheckBox->setChecked(checkerProfile.checkOrphans);
70 	checkTextOverflowCheckBox->setChecked(checkerProfile.checkOverflow);
71 	checkTransparenciesCheckBox->setChecked(checkerProfile.checkTransparency);
72 	checkMissingImagesCheckBox->setChecked(checkerProfile.checkPictures);
73 	checkPartFilledImageFramesCheckBox->setChecked(checkerProfile.checkPartFilledImageFrames);
74 	checkImageResolutionCheckBox->setChecked(checkerProfile.checkResolution);
75 	checkPDFAnnotFieldsCheckBox->setChecked(checkerProfile.checkAnnotations);
76 	checkPlacedPDFCheckBox->setChecked(checkerProfile.checkRasterPDF);
77 	checkGIFsCheckBox->setChecked(checkerProfile.checkForGIF);
78 	checkNonPrintableLayersCheckBox->setChecked(checkerProfile.ignoreOffLayers);
79 	checkVisiblePrintableLayersCheckBox->setChecked(checkerProfile.checkOffConflictLayers);
80 	checkAppliedMasterPageLocationCheckBox->setChecked(checkerProfile.checkAppliedMasterDifferentSide);
81 	checkEmptyTextFramesCheckBox->setChecked(checkerProfile.checkEmptyTextFrames);
82 	minimumResolutionSpinBox->setValue( qRound(checkerProfile.minResolution) );
83 	maximumResolutionSpinBox->setValue( qRound(checkerProfile.maxResolution) );
84 
85 	currentProfile = prefProfile;
86 	if (checkerProfiles.count() == 1)
87 		removeProfilePushButton->setEnabled(false);
88 	addProfilePushButton->setEnabled(false);
89 	tempNewProfileName="";
90 }
91 
saveGuiToPrefs(struct ApplicationPrefs * prefsData) const92 void Prefs_PreflightVerifier::saveGuiToPrefs(struct ApplicationPrefs *prefsData) const
93 {
94 	prefsData->verifierPrefs.showPagesWithoutErrors=showPagesWithoutErrorsCheckBox->isChecked();
95 	prefsData->verifierPrefs.showNonPrintingLayerErrors=showNonPrintingLayerErrorsCheckBox->isChecked();
96 	prefsData->verifierPrefs.checkerPrefsList = checkerProfiles;
97 	prefsData->verifierPrefs.curCheckProfile = currentProfileComboBox->currentText();
98 }
99 
putProfile()100 void Prefs_PreflightVerifier::putProfile()
101 {
102 	if (!checkerProfiles.contains(currentProfile))
103 		return;
104 
105 	CheckerPrefs& checkerProfile = checkerProfiles[currentProfile];
106 	checkerProfile.ignoreErrors = ignoreAllErrorsCheckBox->isChecked();
107 	checkerProfile.autoCheck = autoCheckBeforePrintExportCheckBox->isChecked();
108 	checkerProfile.checkGlyphs = checkMissingGlyphsCheckBox->isChecked();
109 	checkerProfile.checkOrphans = checkItemsNotOnAPageCheckBox->isChecked();
110 	checkerProfile.checkOverflow = checkTextOverflowCheckBox->isChecked();
111 	checkerProfile.checkPictures = checkMissingImagesCheckBox->isChecked();
112 	checkerProfile.checkPartFilledImageFrames = checkPartFilledImageFramesCheckBox->isChecked();
113 	checkerProfile.checkResolution = checkImageResolutionCheckBox->isChecked();
114 	checkerProfile.checkTransparency = checkTransparenciesCheckBox->isChecked();
115 	checkerProfile.minResolution = minimumResolutionSpinBox->value();
116 	checkerProfile.maxResolution = maximumResolutionSpinBox->value();
117 	checkerProfile.checkAnnotations = checkPDFAnnotFieldsCheckBox->isChecked();
118 	checkerProfile.checkRasterPDF = checkPlacedPDFCheckBox->isChecked();
119 	checkerProfile.checkForGIF = checkGIFsCheckBox->isChecked();
120 	checkerProfile.ignoreOffLayers = checkNonPrintableLayersCheckBox->isChecked();
121 	checkerProfile.checkOffConflictLayers = checkVisiblePrintableLayersCheckBox->isChecked();
122 	checkerProfile.checkAppliedMasterDifferentSide = checkAppliedMasterPageLocationCheckBox->isChecked();
123 	checkerProfile.checkEmptyTextFrames = checkEmptyTextFramesCheckBox->isChecked();
124 }
125 
setProfile(const QString & name)126 void Prefs_PreflightVerifier::setProfile(const QString& name)
127 {
128 	if (checkerProfiles.contains(name))
129 	{
130 		putProfile();
131 		updateProfile(name);
132 		tempNewProfileName="";
133 		addProfilePushButton->setEnabled(false);
134 	}
135 	else
136 	{
137 		tempNewProfileName=name;
138 		addProfilePushButton->setEnabled(true);
139 	}
140 }
141 
updateProfile(const QString & name)142 void Prefs_PreflightVerifier::updateProfile(const QString& name)
143 {
144 	disconnect(ignoreAllErrorsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
145 	disconnect(autoCheckBeforePrintExportCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
146 	disconnect(checkMissingGlyphsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
147 	disconnect(checkItemsNotOnAPageCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
148 	disconnect(checkMissingImagesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
149 	disconnect(checkPartFilledImageFramesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
150 	disconnect(checkImageResolutionCheckBox, SIGNAL(toggled(bool)), this, SLOT(putProfile()));
151 	disconnect(checkTransparenciesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
152 	disconnect(minimumResolutionSpinBox, SIGNAL(valueChanged(int)), this, SLOT(putProfile()));
153 	disconnect(maximumResolutionSpinBox, SIGNAL(valueChanged(int)), this, SLOT(putProfile()));
154 	disconnect(checkPlacedPDFCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
155 	disconnect(checkGIFsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
156 	disconnect(checkPDFAnnotFieldsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
157 	disconnect(checkNonPrintableLayersCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
158 	disconnect(checkVisiblePrintableLayersCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
159 	disconnect(checkAppliedMasterPageLocationCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
160 	disconnect(checkEmptyTextFramesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
161 
162 	CheckerPrefs& checkerProfile = checkerProfiles[name];
163 	ignoreAllErrorsCheckBox->setChecked(checkerProfile.ignoreErrors);
164 	autoCheckBeforePrintExportCheckBox->setChecked(checkerProfile.autoCheck);
165 	checkMissingGlyphsCheckBox->setChecked(checkerProfile.checkGlyphs);
166 	checkItemsNotOnAPageCheckBox->setChecked(checkerProfile.checkOrphans);
167 	checkTextOverflowCheckBox->setChecked(checkerProfile.checkOverflow);
168 	checkTransparenciesCheckBox->setChecked(checkerProfile.checkTransparency);
169 	checkMissingImagesCheckBox->setChecked(checkerProfile.checkPictures);
170 	checkPartFilledImageFramesCheckBox->setChecked(checkerProfile.checkPartFilledImageFrames);
171 	checkImageResolutionCheckBox->setChecked(checkerProfile.checkResolution);
172 	minimumResolutionSpinBox->setValue( qRound(checkerProfile.minResolution) );
173 	maximumResolutionSpinBox->setValue( qRound(checkerProfile.maxResolution) );
174 	checkPDFAnnotFieldsCheckBox->setChecked(checkerProfile.checkAnnotations);
175 	checkPlacedPDFCheckBox->setChecked(checkerProfile.checkRasterPDF);
176 	checkGIFsCheckBox->setChecked(checkerProfile.checkForGIF);
177 	checkNonPrintableLayersCheckBox->setChecked(checkerProfile.ignoreOffLayers);
178 	checkVisiblePrintableLayersCheckBox->setChecked(checkerProfile.checkOffConflictLayers);
179 	checkAppliedMasterPageLocationCheckBox->setChecked(checkerProfile.checkAppliedMasterDifferentSide);
180 	checkEmptyTextFramesCheckBox->setChecked(checkerProfile.checkEmptyTextFrames);
181 	currentProfile = name;
182 
183 	connect(ignoreAllErrorsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
184 	connect(autoCheckBeforePrintExportCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
185 	connect(checkMissingGlyphsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
186 	connect(checkItemsNotOnAPageCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
187 	connect(checkMissingImagesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
188 	connect(checkPartFilledImageFramesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
189 	connect(checkImageResolutionCheckBox, SIGNAL(toggled(bool)), this, SLOT(putProfile()));
190 	connect(checkTransparenciesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
191 	connect(minimumResolutionSpinBox, SIGNAL(valueChanged(int)), this, SLOT(putProfile()));
192 	connect(maximumResolutionSpinBox, SIGNAL(valueChanged(int)), this, SLOT(putProfile()));
193 	connect(checkPlacedPDFCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
194 	connect(checkGIFsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
195 	connect(checkPDFAnnotFieldsCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
196 	connect(checkNonPrintableLayersCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
197 	connect(checkVisiblePrintableLayersCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
198 	connect(checkAppliedMasterPageLocationCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
199 	connect(checkEmptyTextFramesCheckBox, SIGNAL(clicked()), this, SLOT(putProfile()));
200 }
201 
addProf()202 void Prefs_PreflightVerifier::addProf()
203 {
204 	struct CheckerPrefs checkerSettings;
205 	checkerSettings.ignoreErrors = ignoreAllErrorsCheckBox->isChecked();
206 	checkerSettings.autoCheck = autoCheckBeforePrintExportCheckBox->isChecked();
207 	checkerSettings.checkGlyphs = checkMissingGlyphsCheckBox->isChecked();
208 	checkerSettings.checkOrphans = checkItemsNotOnAPageCheckBox->isChecked();
209 	checkerSettings.checkOverflow = checkTextOverflowCheckBox->isChecked();
210 	checkerSettings.checkPictures = checkMissingImagesCheckBox->isChecked();
211 	checkerSettings.checkPartFilledImageFrames = checkPartFilledImageFramesCheckBox->isChecked();
212 	checkerSettings.checkResolution = checkImageResolutionCheckBox->isChecked();
213 	checkerSettings.checkTransparency =  checkTransparenciesCheckBox->isChecked();
214 	checkerSettings.minResolution = minimumResolutionSpinBox->value();
215 	checkerSettings.maxResolution = maximumResolutionSpinBox->value();
216 	checkerSettings.checkAnnotations = checkPDFAnnotFieldsCheckBox->isChecked();
217 	checkerSettings.checkRasterPDF = checkPlacedPDFCheckBox->isChecked();
218 	checkerSettings.checkForGIF = checkGIFsCheckBox->isChecked();
219 	checkerSettings.ignoreOffLayers = checkNonPrintableLayersCheckBox->isChecked();
220 	checkerSettings.checkOffConflictLayers = checkVisiblePrintableLayersCheckBox->isChecked();
221 	checkerSettings.checkAppliedMasterDifferentSide = checkAppliedMasterPageLocationCheckBox->isChecked();
222 	checkerSettings.checkEmptyTextFrames = checkEmptyTextFramesCheckBox->isChecked();
223 	checkerProfiles.insert(tempNewProfileName, checkerSettings);
224 	currentProfile = tempNewProfileName;
225 	if (checkerProfiles.count() > 1)
226 		removeProfilePushButton->setEnabled(true);
227 	addProfilePushButton->setEnabled(false);
228 	currentProfileComboBox->clear();
229 
230 	disconnect(currentProfileComboBox, SIGNAL(activated(const QString&)), this, SLOT(setProfile(const QString&)));
231 	disconnect(currentProfileComboBox, SIGNAL(editTextChanged(const QString&)), this, SLOT(setProfile(const QString&)));
232 	CheckerPrefsList::Iterator it;
233 	int j,i=0;
234 	for (it = checkerProfiles.begin(), j=0; it != checkerProfiles.end(); ++it, ++j)
235 	{
236 		currentProfileComboBox->addItem(it.key());
237 		if (it.key()==currentProfile)
238 			i=j;
239 	}
240 	currentProfileComboBox->setCurrentIndex(i);
241 	connect(currentProfileComboBox, SIGNAL(activated(const QString&)), this, SLOT(setProfile(const QString&)));
242 	connect(currentProfileComboBox, SIGNAL(editTextChanged(const QString&)), this, SLOT(setProfile(const QString&)));
243 	tempNewProfileName="";
244 }
245 
delProf()246 void Prefs_PreflightVerifier::delProf()
247 {
248 	disconnect(currentProfileComboBox, SIGNAL(activated(const QString&)), this, SLOT(setProfile(const QString&)));
249 	disconnect(currentProfileComboBox, SIGNAL(editTextChanged(const QString&)), this, SLOT(setProfile(const QString&)));
250 	checkerProfiles.remove(currentProfile);
251 	updateProfile(checkerProfiles.begin().key());
252 	currentProfileComboBox->clear();
253 	CheckerPrefsList::Iterator it;
254 	CheckerPrefsList::Iterator itend=checkerProfiles.end();
255 	for (it = checkerProfiles.begin(); it != itend; ++it)
256 		currentProfileComboBox->addItem(it.key());
257 	setCurrentComboItem(currentProfileComboBox, currentProfile);
258 	connect(currentProfileComboBox, SIGNAL(activated(const QString&)), this, SLOT(setProfile(const QString&)));
259 	connect(currentProfileComboBox, SIGNAL(editTextChanged(const QString&)), this, SLOT(setProfile(const QString&)));
260 	if (checkerProfiles.count() == 1)
261 		removeProfilePushButton->setEnabled(false);
262 }
263