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                           pageitem.h  -  description
9                              -------------------
10     copyright            : Scribus Team
11  ***************************************************************************/
12 
13 /***************************************************************************
14  *                                                                         *
15  *   This program is free software; you can redistribute it and/or modify  *
16  *   it under the terms of the GNU General Public License as published by  *
17  *   the Free Software Foundation; either version 2 of the License, or     *
18  *   (at your option) any later version.                                   *
19  *                                                                         *
20  ***************************************************************************/
21 
22 #include "scribuscore.h"
23 
24 #include <cassert>
25 #include <iostream>
26 
27 #include <QByteArray>
28 #include <QDebug>
29 #include <QGlobalStatic>
30 #include <QMessageBox>
31 #include <QScreen>
32 
33 #include "colormgmt/sccolormgmtenginefactory.h"
34 #include "commonstrings.h"
35 #include "filewatcher.h"
36 #include "iconmanager.h"
37 #include "langmgr.h"
38 #include "localemgr.h"
39 #include "pluginmanager.h"
40 #include "prefsmanager.h"
41 #include "scimagecachemanager.h"
42 #include "scpaths.h"
43 #include "scribus.h"
44 #include "scribusapp.h"
45 #include "ui/splash.h"
46 #include "undomanager.h"
47 #include "util_debug.h"
48 #include "util_ghostscript.h"
49 
50 
51 //extern ScribusQApp* ScQApp;
52 
ScribusCore()53 ScribusCore::ScribusCore() : defaultEngine(colorMgmtEngineFactory.createDefaultEngine()),
54 							m_iconManager(IconManager::instance()),
55 							m_prefsManager(PrefsManager::instance())
56 {
57 	ScColorMgmtStrategy strategy;
58 	strategy.setUseBlackPointCompensation(true);
59 	strategy.setUseBlackPreservation(false);
60 	defaultEngine.setStrategy(strategy);
61 }
62 
~ScribusCore()63 ScribusCore::~ScribusCore()
64 {
65 	while (m_ScMWList.count() > 0)
66 	{
67 		ScribusMainWindow *mainWindow = m_ScMWList.takeAt(0);
68 		delete mainWindow;
69 	}
70 	delete pluginManager;
71 }
72 
73 #ifndef NDEBUG
abort_on_error(QtMsgType t,const QMessageLogContext &,const QString & m)74 static void abort_on_error(QtMsgType t, const QMessageLogContext&, const QString & m)
75 {
76 	std::cerr << m.toLocal8Bit().data() << "\n";
77 	if(t==QtFatalMsg) assert(false);
78 //	if(t!=QtDebugMsg) assert(false);
79 }
80 #endif
81 
init(bool useGUI,const QList<QString> & filesToUse)82 int ScribusCore::init(bool useGUI, const QList<QString>& filesToUse)
83 {
84 	m_useGUI=useGUI;
85 	m_Files=filesToUse;
86 #if !defined(NDEBUG) && !defined(_WIN32)
87 	qInstallMessageHandler( & abort_on_error );
88 #endif
89 	return 0;
90 }
91 
startGUI(bool showSplash,bool showFontInfo,bool showProfileInfo,const QString & newGuiLanguage)92 int ScribusCore::startGUI(bool showSplash, bool showFontInfo, bool showProfileInfo, const QString& newGuiLanguage)
93 {
94 	auto* scribus = new ScribusMainWindow();
95 	Q_CHECK_PTR(scribus);
96 	if (!scribus)
97 		return(EXIT_FAILURE);
98 	m_ScMWList.append(scribus);
99 	int retVal=initScribusCore(showSplash, showFontInfo, showProfileInfo, newGuiLanguage);
100 	if (retVal == EXIT_FAILURE)
101 		return(EXIT_FAILURE);
102 
103 	retVal = scribus->initScMW(true);
104 	if (retVal == EXIT_FAILURE)
105 		return(EXIT_FAILURE);
106 
107 	closeSplash();
108 	m_scribusInitialized = true;
109 	connect(ScQApp, SIGNAL(lastWindowClosed()), ScQApp, SLOT(quit()));
110 
111 	scribus->show();
112 	scribus->setupMainWindow();
113 
114 	QStringList recoverFiles = scribus->findRecoverableFile();
115 	int subsRet = scribus->ShowSubs();
116 	if (subsRet == 0)
117 	{
118 		if (!m_Files.isEmpty())
119 		{
120 			for (int i = 0; i < m_Files.size(); ++i)
121 				scribus->loadDoc(m_Files.at(i));
122 		}
123 		else if ((recoverFiles.count() > 0) && usingGUI())
124 		{
125 			if (!scribus->recoverFile(recoverFiles))
126 			{
127 				if (PrefsManager::instance().appPrefs.uiPrefs.showStartupDialog)
128 					scribus->startUpDialog();
129 			}
130 		}
131 		else
132 		{
133 			if (PrefsManager::instance().appPrefs.uiPrefs.showStartupDialog && usingGUI())
134 				scribus->startUpDialog();
135 			else
136 				scribus->setFocus();
137 		}
138 	}
139 	else if (subsRet==QMessageBox::Help)
140 	{
141 		scribus->slotRaiseOnlineHelp();
142 	}
143 	return EXIT_SUCCESS;
144 }
145 
initScribusCore(bool showSplash,bool showFontInfo,bool showProfileInfo,const QString & newGuiLanguage)146 int ScribusCore::initScribusCore(bool showSplash, bool showFontInfo, bool showProfileInfo, const QString& newGuiLanguage)
147 {
148 	CommonStrings::languageChange();
149 	LanguageManager::instance()->languageChange();
150 
151 	if (!m_iconManager.setup())
152 		return EXIT_FAILURE;
153 
154 	// FIXME: Splash needs the prefs loaded by initDefaults() to know if it must force the image to grayscale
155 	initSplash(showSplash);
156 	LocaleManager::instance();
157 	m_prefsManager.setup();
158 	//CB #4428 Get fonts before prefs are set to default
159 	bool haveFonts = false;
160 	haveFonts = ScCore->initFonts(showFontInfo);
161 	if (!haveFonts)
162 		return EXIT_FAILURE;
163 	m_prefsManager.initDefaults();
164 	m_prefsManager.initDefaultGUIFont(qApp->font());
165 	m_prefsManager.initArrowStyles();
166 	m_undoManager = UndoManager::instance();
167 	fileWatcher = new FileWatcher(this);
168 	pluginManager = new PluginManager();
169 
170 	setSplashStatus( tr("Initializing Keyboard Shortcuts") );
171 	m_prefsManager.initDefaultActionKeys();
172 	setSplashStatus( tr("Reading Preferences") );
173 	m_prefsManager.readPrefs();
174 	LocaleManager::instance().setUserPreferredLocale(m_prefsManager.appPrefs.uiPrefs.userPreferredLocale);
175 	m_prefsManager.appPrefs.uiPrefs.showSplashOnStartup=showSplash;
176 	if (!m_iconManager.setActiveFromPrefs(m_prefsManager.appPrefs.uiPrefs.iconSet))
177 	{
178 		//reset prefs name to chosen name based on version, when prefs is empty or not found
179 		m_prefsManager.appPrefs.uiPrefs.iconSet=m_iconManager.activeSetBasename();
180 	}
181 
182 	m_haveGS = testGSAvailability();
183 	m_havePNGAlpha = testGSDeviceAvailability("pngalpha");
184 	m_haveTiffSep = testGSDeviceAvailability("tiffsep");
185 	setSplashStatus( tr("Initializing Plugins") );
186 	pluginManager->initPlugs();
187 
188 	ScCore->setSplashStatus( tr("Reading Color Profiles") );
189 	m_haveCMS = false;
190 	getCMSProfiles(showProfileInfo);
191 	initCMS();
192 
193 	setSplashStatus( tr("Initializing Image Cache") );
194 	ScImageCacheManager & icm = ScImageCacheManager::instance();
195 	icm.setEnabled(m_prefsManager.appPrefs.imageCachePrefs.cacheEnabled);
196 	icm.setMaxCacheSizeMiB(m_prefsManager.appPrefs.imageCachePrefs.maxCacheSizeMiB);
197 	icm.setMaxCacheEntries(m_prefsManager.appPrefs.imageCachePrefs.maxCacheEntries);
198 	icm.setCompressionLevel(m_prefsManager.appPrefs.imageCachePrefs.compressionLevel);
199 	icm.initialize();
200 	return 0;
201 }
202 
getGuiLanguage() const203 const QString &ScribusCore::getGuiLanguage() const
204 {
205 	return ScQApp->currGUILanguage();
206 }
207 
initSplash(bool showSplash)208 void ScribusCore::initSplash(bool showSplash)
209 {
210 	m_SplashScreen = nullptr;
211 	if (!showSplash)
212 		return;
213 
214 	QScreen* primaryScreeen = qApp->primaryScreen();
215 	double pixelRatio = primaryScreeen ? primaryScreeen->devicePixelRatio() : 1.0;
216 	QPixmap pix = IconManager::instance().loadPixmap("scribus_splash.png", true);
217 	if (pixelRatio != 1.0)
218 	{
219 		int w = qRound(pix.width() * pixelRatio);
220 		int h = qRound(pix.height() * pixelRatio);
221 		double integralPart = 0;
222 		bool isIntegerRatio = (modf(pixelRatio, &integralPart) == 0.0);
223 		pix = pix.scaled(w, h, Qt::IgnoreAspectRatio, isIntegerRatio ? Qt::FastTransformation : Qt::SmoothTransformation);
224 		pix.setDevicePixelRatio(pixelRatio);
225 	}
226 
227 	m_SplashScreen = new ScSplashScreen(pix, Qt::WindowStaysOnTopHint);
228 	if (m_SplashScreen != nullptr)
229 	{
230 		m_SplashScreen->show();
231 		if (m_SplashScreen->isVisible())
232 			setSplashStatus(QObject::tr("Initializing..."));
233 	}
234 }
235 
setSplashStatus(const QString & newText)236 void ScribusCore::setSplashStatus(const QString& newText)
237 {
238 	if (m_SplashScreen != nullptr)
239 		m_SplashScreen->setStatus( newText );
240 }
241 
showSplash(bool shown)242 void ScribusCore::showSplash(bool shown)
243 {
244 	if (m_SplashScreen!=nullptr && shown!=m_SplashScreen->isVisible())
245 		m_SplashScreen->setVisible(shown);
246 }
247 
splashShowing() const248 bool ScribusCore::splashShowing() const
249 {
250 	if (m_SplashScreen == nullptr)
251 		return false;
252 	return m_SplashScreen->isVisible();
253 }
254 
closeSplash()255 void ScribusCore::closeSplash()
256 {
257 	if (m_SplashScreen==nullptr)
258 		return;
259 	m_SplashScreen->close();
260 	delete m_SplashScreen;
261 	m_SplashScreen = nullptr;
262 }
263 
usingGUI() const264 bool ScribusCore::usingGUI() const
265 {
266 	return m_useGUI;
267 }
268 
isMacGUI() const269 bool ScribusCore::isMacGUI() const
270 {
271 	// Do it statically for now
272 #if defined(Q_OS_MAC)
273 	return true;
274 #else
275 	return false;
276 #endif
277 }
278 
isWinGUI() const279 bool ScribusCore::isWinGUI() const
280 {
281 	// Do it statically for now
282 #if defined(_WIN32)
283 	return true;
284 #else
285 	return false;
286 #endif
287 }
288 
289 //Returns false when there are no fonts
initFonts(bool showFontInfo)290 bool ScribusCore::initFonts(bool showFontInfo)
291 {
292 	setSplashStatus( tr("Searching for Fonts") );
293 	bool haveFonts=m_prefsManager.GetAllFonts(showFontInfo);
294 	if (!haveFonts)
295 	{
296 		closeSplash();
297 		QString mess = tr("There are no fonts found on your system.");
298 		mess += "\n" + tr("Exiting now.");
299 		ScMessageBox::critical(nullptr, tr("Fatal Error"), mess);
300 	}
301 	else
302 		setSplashStatus( tr("Font System Initialized") );
303 	return haveFonts;
304 }
305 
getCMSProfiles(bool showInfo)306 void ScribusCore::getCMSProfiles(bool showInfo)
307 {
308 	QString profDir;
309 	QStringList profDirs;
310 	MonitorProfiles.clear();
311 	PrinterProfiles.clear();
312 	InputProfiles.clear();
313 	InputProfilesCMYK.clear();
314 	LabProfiles.clear();
315 	profDirs = ScPaths::systemProfilesDirs();
316 	profDirs.prepend( m_prefsManager.appPrefs.pathPrefs.colorProfiles );
317 	profDirs.prepend( ScPaths::instance().shareDir()+"profiles/");
318 	for (int i = 0; i < profDirs.count(); i++)
319 	{
320 		profDir = profDirs[i];
321 		if(!profDir.isEmpty())
322 		{
323 			if(profDir.right(1) != "/")
324 				profDir += "/";
325 			getCMSProfilesDir(profDir, showInfo, true);
326 		}
327 	}
328 	m_haveCMS = (!PrinterProfiles.isEmpty()) && (!InputProfiles.isEmpty()) && (!MonitorProfiles.isEmpty());
329 }
330 
getCMSProfilesDir(const QString & pfad,bool showInfo,bool recursive)331 void ScribusCore::getCMSProfilesDir(const QString& pfad, bool showInfo, bool recursive)
332 {
333 	QString profileName;
334 	QList<ScColorProfileInfo> profileInfos = defaultEngine.getAvailableProfileInfo(pfad, recursive);
335 	for (int i = 0; i < profileInfos.count(); ++i)
336 	{
337 		const ScColorProfileInfo& profInfo = profileInfos.at(i);
338 		profileName = profInfo.description;
339 		if (profileName.isEmpty())
340 		{
341 			if (showInfo)
342 				sDebug(QString("Color profile %1 is broken : no valid description").arg(profInfo.file));
343 			continue;
344 		}
345 		if (!profInfo.debug.isEmpty())
346 		{
347 			if (showInfo)
348 				sDebug(profInfo.debug);
349 			continue;
350 		}
351 		switch (static_cast<int>(profInfo.deviceClass))
352 		{
353 		case Class_Input:
354 			if (profInfo.colorSpace == ColorSpace_Rgb)
355 			{
356 				if (!InputProfiles.contains(profileName))
357 					InputProfiles.insert(profileName, profInfo.file);
358 			}
359 			break;
360 		case Class_ColorSpace:
361 			if (profInfo.colorSpace == ColorSpace_Rgb)
362 			{
363 				if (!InputProfiles.contains(profileName))
364 					InputProfiles.insert(profileName, profInfo.file);
365 			}
366 			if (profInfo.colorSpace == ColorSpace_Cmyk)
367 			{
368 				if (!InputProfilesCMYK.contains(profileName))
369 					InputProfilesCMYK.insert(profileName, profInfo.file);
370 			}
371 			if (profInfo.colorSpace == ColorSpace_Lab)
372 			{
373 				if (!LabProfiles.contains(profileName))
374 					LabProfiles.insert(profileName, profInfo.file);
375 			}
376 			break;
377 		case Class_Display:
378 			if (profInfo.colorSpace == ColorSpace_Rgb)
379 			{
380 				if (!MonitorProfiles.contains(profileName))
381 					MonitorProfiles.insert(profileName, profInfo.file);
382 				if (!InputProfiles.contains(profileName))
383 					InputProfiles.insert(profileName, profInfo.file);
384 			}
385 			if (profInfo.colorSpace == ColorSpace_Cmyk)
386 			{
387 				if (!InputProfilesCMYK.contains(profileName))
388 					InputProfilesCMYK.insert(profileName, profInfo.file);
389 			}
390 			if (profInfo.colorSpace == ColorSpace_Lab)
391 			{
392 				if (!LabProfiles.contains(profileName))
393 					LabProfiles.insert(profileName, profInfo.file);
394 			}
395 			break;
396 		case Class_Output:
397 			// Disable rgb printer profile detection until effective support
398 			// PrinterProfiles.insert(nam, pfad + d[dc], false);
399 			if (profInfo.colorSpace == ColorSpace_Cmyk)
400 			{
401 				if (!PDFXProfiles.contains(profileName))
402 					PDFXProfiles.insert(profileName, profInfo.file);
403 				if (!InputProfilesCMYK.contains(profileName))
404 					InputProfilesCMYK.insert(profileName, profInfo.file);
405 				if (!PrinterProfiles.contains(profileName))
406 					PrinterProfiles.insert(profileName, profInfo.file);
407 			}
408 			break;
409 		}
410 		if (showInfo)
411 			sDebug( QString("Color profile %1 loaded from %2").arg(profileName, profInfo.file) );
412 	}
413 }
414 
InitDefaultColorTransforms()415 void ScribusCore::InitDefaultColorTransforms()
416 {
417 	QString defaultRGBString;
418 	QString defaultRGBString1("sRGB display profile (ICC v2.2)");
419 	QString defaultRGBString2("sRGB IEC61966-2.1");
420 	QString defaultCMYKString1("ISO Coated v2 300% (basICColor)");
421 	QString defaultCMYKString2("Fogra27L CMYK Coated Press");
422 
423 	// Open the default RGB profile
424 	if (InputProfiles.contains(defaultRGBString1))
425 	{
426 		defaultRGBProfile = defaultEngine.openProfileFromFile(InputProfiles[defaultRGBString1]);
427 		defaultRGBString = defaultRGBString1;
428 	}
429 	else if (InputProfiles.contains(defaultRGBString2))
430 	{
431 		defaultRGBProfile = defaultEngine.openProfileFromFile(InputProfiles[defaultRGBString2]);
432 		defaultRGBString = defaultRGBString2;
433 	}
434 	else
435 	{
436 		defaultRGBProfile = defaultEngine.createProfile_sRGB();
437 		defaultRGBString = defaultRGBString2;
438 	}
439 
440 	// Open the default CMYK profile
441 	if (InputProfilesCMYK.contains(defaultCMYKString1))
442 		defaultCMYKProfile = defaultEngine.openProfileFromFile(InputProfilesCMYK[defaultCMYKString1]);
443 	else if (InputProfilesCMYK.contains(defaultCMYKString2))
444 		defaultCMYKProfile = defaultEngine.openProfileFromFile(InputProfilesCMYK[defaultCMYKString2]);
445 
446 	// Keep all chance to have monitor profile set
447 	monitorProfile = defaultRGBProfile;
448 
449 	if (!defaultRGBProfile || !defaultCMYKProfile)
450 	{
451 		ResetDefaultColorTransforms();
452 		return;
453 	}
454 
455 	// Default rgb profile may be a memory profile, if it is the case add it to the lists of
456 	// rgb profiles (input and monitor) so that it can be used later in prefs
457 	if (!InputProfiles.contains(defaultRGBString))
458 		InputProfiles.insert(defaultRGBString, defaultRGBProfile.profilePath());
459 	if (!MonitorProfiles.contains(defaultRGBString))
460 		MonitorProfiles.insert(defaultRGBString, defaultRGBProfile.profilePath());
461 
462 	// Open monitor profile as defined by user preferences
463 	QString displayProfile = m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultMonitorProfile;
464 	if (MonitorProfiles.contains(displayProfile))
465 		monitorProfile = defaultEngine.openProfileFromFile( MonitorProfiles[displayProfile] );
466 	if (monitorProfile.isNull())
467 	{
468 		m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultMonitorProfile = defaultRGBString;
469 		monitorProfile = defaultRGBProfile;
470 	}
471 
472 	// Now create default color transforms (used mainly when color management is "disabled")
473 	int dcmsFlags        = Ctf_BlackPointCompensation;
474 	eRenderIntent intent = Intent_Relative_Colorimetric;
475 //	if (!LabProfiles.isEmpty())
476 //		defaultLabProfile = defaultEngine.openProfileFromFile(LabProfiles.first());
477 //	else
478 		defaultLabProfile = defaultEngine.createProfile_Lab();
479 
480 	defaultRGBToScreenSolidTrans  = defaultEngine.createTransform(defaultRGBProfile, Format_RGB_16,  defaultRGBProfile, Format_RGB_16, intent, dcmsFlags);
481 	defaultRGBToScreenImageTrans  = defaultEngine.createTransform(defaultRGBProfile, Format_RGBA_8,  defaultRGBProfile, Format_RGBA_8, intent, dcmsFlags);
482 	defaultCMYKToScreenImageTrans = defaultEngine.createTransform(defaultCMYKProfile, Format_CMYK_8, defaultRGBProfile, Format_RGBA_8, intent, dcmsFlags);
483 	defaultRGBToCMYKTrans         = defaultEngine.createTransform(defaultRGBProfile, Format_RGB_16, defaultCMYKProfile, Format_CMYK_16, intent, dcmsFlags);
484 	defaultCMYKToRGBTrans         = defaultEngine.createTransform(defaultCMYKProfile, Format_CMYK_16, defaultRGBProfile, Format_RGB_16, intent, dcmsFlags);
485 	defaultLabToRGBTrans          = defaultEngine.createTransform(defaultLabProfile, Format_Lab_Dbl, defaultRGBProfile, Format_RGB_16, Intent_Absolute_Colorimetric, dcmsFlags);
486 	defaultLabToCMYKTrans         = defaultEngine.createTransform(defaultLabProfile, Format_Lab_Dbl, defaultCMYKProfile, Format_CMYK_16, Intent_Absolute_Colorimetric, dcmsFlags);
487 	defaultLabToScreenTrans       = defaultLabToRGBTrans;
488 	if (!defaultRGBToScreenSolidTrans  || !defaultRGBToScreenImageTrans ||
489 		!defaultCMYKToScreenImageTrans || !defaultRGBToCMYKTrans ||
490 		!defaultCMYKToRGBTrans || !defaultLabToRGBTrans|| !defaultLabToCMYKTrans)
491 	{
492 		ResetDefaultColorTransforms();
493 	}
494 }
495 
ResetDefaultColorTransforms()496 void ScribusCore::ResetDefaultColorTransforms()
497 {
498 	defaultRGBProfile  = ScColorProfile();
499 	defaultCMYKProfile = ScColorProfile();
500 	defaultRGBToScreenSolidTrans = ScColorTransform();
501 	defaultRGBToScreenImageTrans = ScColorTransform();
502 	defaultCMYKToScreenImageTrans = ScColorTransform();
503 	defaultRGBToCMYKTrans = ScColorTransform();
504 	defaultCMYKToRGBTrans = ScColorTransform();
505 	defaultLabToRGBTrans = ScColorTransform();
506 	defaultLabToCMYKTrans = ScColorTransform();
507 	defaultLabToScreenTrans = ScColorTransform();
508 }
509 
initCMS()510 void ScribusCore::initCMS()
511 {
512 	if (!m_haveCMS)
513 		return;
514 
515 	ProfilesL::Iterator ip;
516 	QString defaultRGBString1 = "sRGB display profile (ICC v2.2)";
517 	QString defaultRGBString2 = "sRGB IEC61966-2.1";
518 	QString defaultCMYKString1 = "ISO Coated v2 300% (basICColor)";
519 	QString defaultCMYKString2 = "Fogra27L CMYK Coated Press";
520 
521 	QString defaultImageRGBProfile = m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultImageRGBProfile;
522 	if ((defaultImageRGBProfile.isEmpty()) || (!InputProfiles.contains(defaultImageRGBProfile)))
523 	{
524 		ip = InputProfiles.find(defaultRGBString1);
525 		if (ip == InputProfiles.end())
526 			ip = InputProfiles.find(defaultRGBString2);
527 		if (ip == InputProfiles.end())
528 			ip = InputProfiles.begin();
529 		m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultImageRGBProfile = ip.key();
530 	}
531 
532 	QString defaultImageCMYKProfile = m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultImageCMYKProfile;
533 	if ((defaultImageCMYKProfile.isEmpty()) || (!InputProfilesCMYK.contains(defaultImageCMYKProfile)))
534 	{
535 		ip = InputProfilesCMYK.find(defaultCMYKString1);
536 		if (ip == InputProfilesCMYK.end())
537 			ip = InputProfilesCMYK.find(defaultCMYKString2);
538 		if (ip == InputProfilesCMYK.end())
539 			ip = InputProfilesCMYK.begin();
540 		m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultImageCMYKProfile = ip.key();
541 	}
542 
543 	QString defaultSolidColorRGBProfile = m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultSolidColorRGBProfile;
544 	if ((defaultSolidColorRGBProfile.isEmpty()) || (!InputProfiles.contains(defaultSolidColorRGBProfile)))
545 	{
546 		ip = InputProfiles.find(defaultRGBString1);
547 		if (ip == InputProfiles.end())
548 			ip = InputProfiles.find(defaultRGBString2);
549 		if (ip == InputProfiles.end())
550 			ip = InputProfiles.begin();
551 		m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultSolidColorRGBProfile = ip.key();
552 	}
553 
554 	QString defaultSolidColorCMYKProfile = m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultSolidColorCMYKProfile;
555 	if ((defaultSolidColorCMYKProfile.isEmpty()) || (!InputProfilesCMYK.contains(defaultSolidColorCMYKProfile)))
556 	{
557 		ip = InputProfilesCMYK.find(defaultCMYKString1);
558 		if (ip == InputProfilesCMYK.end())
559 			ip = InputProfilesCMYK.find(defaultCMYKString2);
560 		if (ip == InputProfilesCMYK.end())
561 			ip = InputProfilesCMYK.begin();
562 		m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultSolidColorCMYKProfile = ip.key();
563 	}
564 
565 	QString defaultMonitorProfile = m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultMonitorProfile;
566 	if ((defaultMonitorProfile.isEmpty()) || (!MonitorProfiles.contains(defaultMonitorProfile)))
567 	{
568 		ip = MonitorProfiles.find(defaultRGBString1);
569 		if (ip == MonitorProfiles.end())
570 			ip = MonitorProfiles.find(defaultRGBString2);
571 		if (ip == MonitorProfiles.end())
572 			ip = MonitorProfiles.begin();
573 		m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultMonitorProfile = ip.key();
574 	}
575 
576 	QString defaultPrinterProfile = m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultPrinterProfile;
577 	if ((defaultPrinterProfile.isEmpty()) || (!PrinterProfiles.contains(defaultPrinterProfile)))
578 	{
579 		ip = PrinterProfiles.find(defaultCMYKString1);
580 		if (ip == PrinterProfiles.end())
581 			ip = PrinterProfiles.find(defaultCMYKString2);
582 		if (ip == PrinterProfiles.end())
583 			ip = PrinterProfiles.begin();
584 		m_prefsManager.appPrefs.colorPrefs.DCMSset.DefaultPrinterProfile = ip.key();
585 	}
586 
587 	InitDefaultColorTransforms();
588 }
589 
primaryMainWindow()590 ScribusMainWindow * ScribusCore::primaryMainWindow()
591 {
592 	if (m_ScMWList.count() == 0 || m_currScMW > m_ScMWList.count())
593 		return nullptr;
594 	ScribusMainWindow* mw=m_ScMWList.at(m_currScMW);
595 	if (!mw)
596 		return nullptr;
597 	return mw;
598 }
599 
recheckGS()600 void ScribusCore::recheckGS()
601 {
602 	m_haveGS = testGSAvailability();
603 	m_havePNGAlpha = testGSDeviceAvailability("pngalpha");
604 	m_haveTiffSep = testGSDeviceAvailability("tiffsep");
605 }
606 
fileWatcherActive() const607 bool ScribusCore::fileWatcherActive() const
608 {
609 	if (fileWatcher!=nullptr)
610 		return fileWatcher->isActive();
611 	return false;
612 }
613