Rev 5257 | Rev 5369 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5244 | cbradney | 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 | #include "scribuscore.moc" |
||
24 | |||
25 | #include "commonstrings.h" |
||
26 | #include "filewatcher.h" |
||
27 | #include "gsutil.h" |
||
28 | #include "pluginmanager.h" |
||
29 | #include "prefsmanager.h" |
||
30 | #include "scpaths.h" |
||
31 | #include "splash.h" |
||
32 | #include "scribusapp.h" |
||
33 | #include "undomanager.h" |
||
34 | |||
35 | extern ScribusQApp* ScQApp; |
||
36 | |||
37 | #ifdef HAVE_CMS |
||
38 | #include "cmserrorhandling.h" |
||
39 | cmsHPROFILE CMSoutputProf; |
||
40 | cmsHPROFILE CMSprinterProf; |
||
41 | cmsHTRANSFORM stdTransG; |
||
42 | cmsHTRANSFORM stdProofG; |
||
43 | cmsHTRANSFORM stdTransImgG; |
||
44 | cmsHTRANSFORM stdProofImgG; |
||
45 | cmsHTRANSFORM stdTransCMYKG; |
||
46 | cmsHTRANSFORM stdProofCMYKG; |
||
47 | cmsHTRANSFORM stdTransRGBG; |
||
48 | cmsHTRANSFORM stdProofGCG; |
||
49 | cmsHTRANSFORM stdProofCMYKGCG; |
||
50 | bool BlackPoint; |
||
51 | bool SoftProofing; |
||
52 | bool Gamut; |
||
53 | bool SCRIBUS_API CMSuse; |
||
5345 | mrdocs | 54 | int IntentColors; |
55 | int IntentImages; |
||
5244 | cbradney | 56 | #endif |
57 | bool CMSavail; |
||
58 | |||
59 | |||
60 | ScribusCore::ScribusCore() : QObject() |
||
61 | { |
||
62 | m_ScribusInitialized=false; |
||
63 | m_SplashScreen=0; |
||
64 | m_UseGUI=false; |
||
5257 | cbradney | 65 | m_PaletteParent=0; |
5244 | cbradney | 66 | } |
67 | |||
68 | |||
69 | |||
70 | ScribusCore::~ScribusCore() |
||
5257 | cbradney | 71 | { |
72 | delete m_PaletteParent; |
||
73 | } |
||
5244 | cbradney | 74 | |
75 | int ScribusCore::init(bool useGUI, bool swapDialogButtonOrder, const QString fileToUse) |
||
76 | { |
||
77 | m_UseGUI=useGUI; |
||
78 | m_File=fileToUse; |
||
79 | m_SwapDialogButtonOrder=swapDialogButtonOrder; |
||
80 | return 0; |
||
81 | } |
||
82 | |||
83 | int ScribusCore::startGUI(bool showSplash, bool showFontInfo, const QString newGuiLanguage, const QString prefsUserFile) |
||
84 | { |
||
5257 | cbradney | 85 | m_PaletteParent=new QWidget(0); |
86 | Q_CHECK_PTR(m_PaletteParent); |
||
87 | scribus = new ScribusMainWindow(); |
||
88 | Q_CHECK_PTR(scribus); |
||
89 | if (!scribus) |
||
90 | return(EXIT_FAILURE); |
||
91 | ScMW=scribus; |
||
92 | int retVal=initScribusCore(showSplash, showFontInfo, newGuiLanguage, prefsUserFile); |
||
93 | if (retVal == 1) |
||
94 | return(EXIT_FAILURE); |
||
95 | retVal = scribus->initScMW(true); |
||
96 | if (retVal == 1) |
||
97 | return(EXIT_FAILURE); |
||
98 | closeSplash(); |
||
99 | m_ScribusInitialized=true; |
||
100 | ScQApp->setMainWidget(scribus); |
||
101 | connect(ScQApp, SIGNAL(lastWindowClosed()), ScQApp, SLOT(quit())); |
||
5244 | cbradney | 102 | |
5257 | cbradney | 103 | scribus->show(); |
104 | scribus->ShowSubs(); |
||
5244 | cbradney | 105 | |
5257 | cbradney | 106 | if (!m_File.isEmpty()) |
107 | scribus->loadDoc(m_File); |
||
108 | else |
||
109 | { |
||
110 | if (PrefsManager::instance()->appPrefs.showStartupDialog) |
||
111 | scribus->startUpDialog(); |
||
5244 | cbradney | 112 | else |
5257 | cbradney | 113 | scribus->setFocus(); |
114 | } |
||
5244 | cbradney | 115 | |
5257 | cbradney | 116 | // A hook for plug-ins and scripts to trigger on. Some plugins and scripts |
117 | // require the app to be fully set up (in particular, the main window to be |
||
118 | // built and shown) before running their setup. |
||
119 | emit appStarted(); |
||
120 | return EXIT_SUCCESS; |
||
5244 | cbradney | 121 | } |
122 | |||
123 | int ScribusCore::initScribusCore(bool showSplash, bool showFontInfo, const QString newGuiLanguage, const QString prefsUserFile) |
||
124 | { |
||
125 | CommonStrings::languageChange(); |
||
126 | int retVal=0; |
||
127 | //FIXME ExternalApp = 0; |
||
128 | m_GuiLanguage = newGuiLanguage; |
||
129 | initSplash(showSplash); |
||
130 | prefsManager = PrefsManager::instance(); |
||
131 | prefsManager->setup(); |
||
132 | prefsManager->initDefaults(); |
||
133 | prefsManager->initDefaultGUIFont(qApp->font()); |
||
134 | prefsManager->initArrowStyles(); |
||
135 | undoManager = UndoManager::instance(); |
||
136 | fileWatcher = new FileWatcher(this); |
||
137 | pluginManager = new PluginManager(); |
||
138 | setSplashStatus( tr("Initializing Plugins") ); |
||
139 | pluginManager->initPlugs(); |
||
140 | bool haveFonts=false; |
||
141 | #ifdef QT_MAC |
||
142 | haveFonts=ScCore->initFonts(true); |
||
143 | #else |
||
144 | haveFonts=ScCore->initFonts(showFontInfo); |
||
145 | #endif |
||
146 | if (!haveFonts) |
||
147 | return 1; |
||
148 | setSplashStatus( tr("Initializing Keyboard Shortcuts") ); |
||
149 | prefsManager->initDefaultActionKeys(); |
||
150 | setSplashStatus( tr("Reading Preferences") ); |
||
151 | if (prefsUserFile.isNull()) |
||
152 | prefsManager->ReadPrefs(); |
||
153 | else |
||
154 | prefsManager->ReadPrefs(prefsUserFile); |
||
155 | |||
156 | m_HaveGS = testGSAvailability(); |
||
157 | m_HavePngAlpha = testGSDeviceAvailability("pngalpha"); |
||
158 | m_HaveTiffSep = testGSDeviceAvailability("tiffsep"); |
||
159 | |||
160 | ScCore->setSplashStatus( tr("Reading ICC Profiles") ); |
||
161 | CMSavail = false; |
||
162 | getCMSProfiles(); |
||
163 | initCMS(); |
||
164 | /* |
||
165 | |||
5257 | cbradney | 166 | buildFontMenu(); |
5244 | cbradney | 167 | |
168 | |||
169 | initPalettes(); |
||
170 | |||
171 | |||
172 | setSplashStatus( tr("Initializing Hyphenator") ); |
||
173 | QString preLang = prefsManager->appPrefs.Language; |
||
174 | initHyphenator(); |
||
175 | if (Sprachen.contains(preLang)) |
||
176 | prefsManager->appPrefs.Language = preLang; |
||
177 | setSplashStatus( tr("Reading Scrapbook") ); |
||
178 | initScrapbook(); |
||
179 | setSplashStatus( tr("Setting up Shortcuts") ); |
||
180 | SetShortCut(); |
||
181 | scrActions["helpTooltips"]->setOn(prefsManager->appPrefs.showToolTips); |
||
182 | ToggleTips(); |
||
183 | |||
184 | connect(fileWatcher, SIGNAL(fileDeleted(QString )), this, SLOT(removeRecent(QString))); |
||
185 | connect(this, SIGNAL(TextIFont(QString)), this, SLOT(AdjustFontMenu(QString))); |
||
186 | connect(this, SIGNAL(TextIFont(QString)), propertiesPalette, SLOT(setFontFace(QString))); |
||
187 | connect(this, SIGNAL(TextISize(int)), this, SLOT(setFSizeMenu(int))); |
||
188 | connect(this, SIGNAL(TextISize(int)), propertiesPalette, SLOT(setSize(int))); |
||
189 | connect(this, SIGNAL(TextUSval(int)), propertiesPalette, SLOT(setExtra(int))); |
||
190 | connect(this, SIGNAL(TextStil(int)), propertiesPalette, SLOT(setStil(int))); |
||
191 | connect(this, SIGNAL(TextScale(int)), propertiesPalette, SLOT(setTScale(int))); |
||
192 | connect(this, SIGNAL(TextScaleV(int)), propertiesPalette, SLOT(setTScaleV(int))); |
||
193 | connect(this, SIGNAL(TextBase(int)), propertiesPalette, SLOT(setTBase(int))); |
||
194 | connect(this, SIGNAL(TextShadow(int, int )), propertiesPalette, SLOT(setShadowOffs(int, int ))); |
||
195 | connect(this, SIGNAL(TextOutline(int)), propertiesPalette, SLOT(setOutlineW(int))); |
||
196 | connect(this, SIGNAL(TextUnderline(int, int)), propertiesPalette, SLOT(setUnderline(int, int))); |
||
197 | connect(this, SIGNAL(TextStrike(int, int)), propertiesPalette, SLOT(setStrike(int, int))); |
||
198 | connect(this, SIGNAL(TextFarben(QString, QString, int, int)), propertiesPalette, SLOT(setActFarben(QString, QString, int, int))); |
||
199 | }*/ |
||
5257 | cbradney | 200 | |
5244 | cbradney | 201 | return retVal; |
202 | } |
||
203 | |||
204 | |||
205 | void ScribusCore::initSplash(bool showSplash) |
||
206 | { |
||
207 | if (showSplash) |
||
208 | { |
||
209 | m_SplashScreen = new SplashScreen(); |
||
210 | if (m_SplashScreen != NULL && m_SplashScreen->isShown()) |
||
211 | setSplashStatus(QObject::tr("Initializing...")); |
||
212 | } |
||
213 | else |
||
214 | m_SplashScreen = NULL; |
||
215 | } |
||
216 | |||
217 | void ScribusCore::setSplashStatus(const QString& newText) |
||
218 | { |
||
219 | if (m_SplashScreen != NULL) |
||
220 | { |
||
221 | m_SplashScreen->setStatus( newText ); |
||
222 | qApp->processEvents(); |
||
223 | } |
||
224 | } |
||
225 | |||
226 | void ScribusCore::showSplash(bool shown) |
||
227 | { |
||
228 | if (m_SplashScreen!=NULL && shown!=m_SplashScreen->isShown()) |
||
229 | m_SplashScreen->setShown(shown); |
||
230 | } |
||
231 | |||
232 | bool ScribusCore::splashShowing() const |
||
233 | { |
||
234 | if (m_SplashScreen != NULL) |
||
235 | return m_SplashScreen->isShown(); |
||
236 | return false; |
||
237 | } |
||
238 | |||
239 | void ScribusCore::closeSplash() |
||
240 | { |
||
241 | if (m_SplashScreen!=NULL) |
||
242 | { |
||
243 | m_SplashScreen->close(); |
||
244 | delete m_SplashScreen; |
||
245 | m_SplashScreen = NULL; |
||
246 | } |
||
247 | } |
||
248 | |||
249 | bool ScribusCore::usingGUI() const |
||
250 | { |
||
251 | return m_UseGUI; |
||
252 | } |
||
253 | |||
254 | bool ScribusCore::isMacGUI() const |
||
255 | { |
||
256 | // Do it statically for now |
||
257 | #if defined(Q_WS_MAC) |
||
258 | return true; |
||
259 | #else |
||
260 | return false; |
||
261 | #endif |
||
262 | } |
||
263 | |||
264 | bool ScribusCore::isWinGUI() const |
||
265 | { |
||
266 | // Do it statically for now |
||
267 | #if defined(_WIN32) |
||
268 | return true; |
||
269 | #else |
||
270 | return false; |
||
271 | #endif |
||
272 | } |
||
273 | |||
274 | bool ScribusCore::reverseDialogButtons() const |
||
275 | { |
||
276 | if (m_SwapDialogButtonOrder) |
||
277 | return true; |
||
278 | //Win32 - dont switch |
||
279 | #if defined(_WIN32) |
||
280 | return false; |
||
281 | //Mac Aqua - switch |
||
282 | #elif defined(Q_WS_MAC) |
||
283 | return true; |
||
284 | #else |
||
285 | //Gnome - switch |
||
286 | QString gnomesession= ::getenv("GNOME_DESKTOP_SESSION_ID"); |
||
287 | if (!gnomesession.isEmpty()) |
||
288 | return true; |
||
289 | |||
290 | //KDE/KDE Aqua - dont switch |
||
291 | //Best guess for now if we are running under KDE |
||
292 | QString kdesession= ::getenv("KDE_FULL_SESSION"); |
||
293 | if (!kdesession.isEmpty()) |
||
294 | return false; |
||
295 | #endif |
||
296 | return false; |
||
297 | } |
||
298 | |||
299 | //Returns false when there are no fonts |
||
300 | bool ScribusCore::initFonts(bool showFontInfo) |
||
301 | { |
||
302 | setSplashStatus( tr("Searching for Fonts") ); |
||
303 | bool haveFonts=prefsManager->GetAllFonts(showFontInfo); |
||
304 | if (!haveFonts) |
||
305 | { |
||
306 | closeSplash(); |
||
307 | QString mess = tr("There are no fonts found on your system."); |
||
308 | mess += "\n" + tr("Exiting now."); |
||
309 | QMessageBox::critical(0, tr("Fatal Error"), mess, 1, 0, 0); |
||
310 | } |
||
311 | else |
||
312 | setSplashStatus( tr("Font System Initialized") ); |
||
313 | return haveFonts; |
||
314 | } |
||
315 | |||
316 | |||
317 | void ScribusCore::getCMSProfiles() |
||
318 | { |
||
319 | QString profDir; |
||
320 | QStringList profDirs; |
||
321 | MonitorProfiles.clear(); |
||
322 | PrinterProfiles.clear(); |
||
323 | InputProfiles.clear(); |
||
324 | InputProfilesCMYK.clear(); |
||
325 | QString pfad = ScPaths::instance().libDir(); |
||
326 | pfad += "profiles/"; |
||
327 | profDirs = ScPaths::getSystemProfilesDirs(); |
||
328 | profDirs.prepend( prefsManager->appPrefs.ProfileDir ); |
||
329 | profDirs.prepend( pfad ); |
||
330 | for(unsigned int i = 0; i < profDirs.count(); i++) |
||
331 | { |
||
332 | profDir = profDirs[i]; |
||
333 | if(!profDir.isEmpty()) |
||
334 | { |
||
335 | if(profDir.right(1) != "/") |
||
336 | profDir += "/"; |
||
337 | getCMSProfilesDir(profDir); |
||
338 | } |
||
339 | } |
||
340 | if ((!PrinterProfiles.isEmpty()) && (!InputProfiles.isEmpty()) && (!MonitorProfiles.isEmpty())) |
||
341 | CMSavail = true; |
||
342 | else |
||
343 | CMSavail = false; |
||
344 | } |
||
345 | |||
346 | void ScribusCore::getCMSProfilesDir(QString pfad) |
||
347 | { |
||
348 | #ifdef HAVE_CMS |
||
349 | QDir d(pfad, "*", QDir::Name, QDir::Files | QDir::Readable | QDir::Dirs | QDir::NoSymLinks); |
||
350 | if ((d.exists()) && (d.count() != 0)) |
||
351 | { |
||
352 | QString nam = ""; |
||
353 | const char *Descriptor; |
||
354 | cmsHPROFILE hIn = NULL; |
||
355 | |||
356 | for (uint dc = 0; dc < d.count(); ++dc) |
||
357 | { |
||
358 | QFileInfo fi(pfad + "/" + d[dc]); |
||
359 | if (fi.isDir() && d[dc][0] != '.') |
||
360 | { |
||
361 | getCMSProfilesDir(fi.filePath()+"/"); |
||
362 | continue; |
||
363 | } |
||
364 | |||
365 | #ifndef QT_MAC |
||
366 | QString ext = fi.extension(false).lower(); |
||
367 | if ((ext != "icm") && (ext != "icc")) |
||
368 | continue; |
||
369 | #endif |
||
370 | |||
371 | QFile f(fi.filePath()); |
||
372 | QByteArray bb(40); |
||
373 | if (!f.open(IO_ReadOnly)) { |
||
374 | qDebug("%s", QString("couldn't open %1 as ICC").arg(fi.filePath()).ascii()); |
||
375 | continue; |
||
376 | } |
||
377 | int len = f.readBlock(bb.data(), 40); |
||
378 | f.close(); |
||
379 | if (len == 40 && bb[36] == 'a' && bb[37] == 'c' && bb[38] == 's' && bb[39] == 'p') |
||
380 | { |
||
381 | const QCString profilePath( QString(pfad + d[dc]).local8Bit() ); |
||
382 | if (setjmp(cmsJumpBuffer)) |
||
383 | { |
||
384 | // Reset to the default handler otherwise may enter a loop |
||
385 | // if an error occur in cmsCloseProfile() |
||
386 | cmsSetErrorHandler(NULL); |
||
387 | if (hIn) |
||
388 | { |
||
389 | cmsCloseProfile(hIn); |
||
390 | hIn = NULL; |
||
391 | } |
||
392 | continue; |
||
393 | } |
||
394 | cmsSetErrorHandler(&cmsErrorHandler); |
||
395 | hIn = cmsOpenProfileFromFile(profilePath.data(), "r"); |
||
396 | if (hIn == NULL) |
||
397 | continue; |
||
398 | Descriptor = cmsTakeProductDesc(hIn); |
||
399 | nam = QString(Descriptor); |
||
400 | switch (static_cast<int>(cmsGetDeviceClass(hIn))) |
||
401 | { |
||
402 | case icSigInputClass: |
||
403 | case icSigColorSpaceClass: |
||
404 | if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigRgbData) |
||
405 | InputProfiles[nam] = pfad + d[dc]; |
||
406 | if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigCmykData) |
||
407 | InputProfilesCMYK[nam] = pfad + d[dc]; |
||
408 | break; |
||
409 | case icSigDisplayClass: |
||
410 | if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigRgbData) |
||
411 | { |
||
412 | MonitorProfiles[nam] = pfad + d[dc]; |
||
413 | InputProfiles[nam] = pfad + d[dc]; |
||
414 | } |
||
415 | if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigCmykData) |
||
416 | InputProfilesCMYK[nam] = pfad + d[dc]; |
||
417 | break; |
||
418 | case icSigOutputClass: |
||
419 | PrinterProfiles[nam] = pfad + d[dc]; |
||
420 | if (static_cast<int>(cmsGetColorSpace(hIn)) == icSigCmykData) |
||
421 | { |
||
422 | PDFXProfiles[nam] = pfad + d[dc]; |
||
423 | InputProfilesCMYK[nam] = pfad + d[dc]; |
||
424 | } |
||
425 | break; |
||
426 | } |
||
427 | cmsCloseProfile(hIn); |
||
428 | hIn = NULL; |
||
429 | } |
||
430 | } |
||
431 | cmsSetErrorHandler(NULL); |
||
432 | } |
||
433 | #endif |
||
434 | } |
||
435 | |||
436 | void ScribusCore::initCMS() |
||
437 | { |
||
438 | if (CMSavail) |
||
439 | { |
||
440 | ProfilesL::Iterator ip; |
||
441 | if ((prefsManager->appPrefs.DCMSset.DefaultImageRGBProfile.isEmpty()) || (!InputProfiles.contains(prefsManager->appPrefs.DCMSset.DefaultImageRGBProfile))) |
||
442 | { |
||
443 | ip = InputProfiles.begin(); |
||
444 | prefsManager->appPrefs.DCMSset.DefaultImageRGBProfile = ip.key(); |
||
445 | } |
||
446 | if ((prefsManager->appPrefs.DCMSset.DefaultImageCMYKProfile.isEmpty()) || (!InputProfilesCMYK.contains(prefsManager->appPrefs.DCMSset.DefaultImageCMYKProfile))) |
||
447 | { |
||
448 | ip = InputProfilesCMYK.begin(); |
||
449 | prefsManager->appPrefs.DCMSset.DefaultImageCMYKProfile = ip.key(); |
||
450 | } |
||
5345 | mrdocs | 451 | if ((prefsManager->appPrefs.DCMSset.DefaultSolidColorRGBProfile.isEmpty()) || (!InputProfiles.contains(prefsManager->appPrefs.DCMSset.DefaultSolidColorRGBProfile))) |
5244 | cbradney | 452 | { |
453 | ip = InputProfiles.begin(); |
||
5345 | mrdocs | 454 | prefsManager->appPrefs.DCMSset.DefaultSolidColorRGBProfile = ip.key(); |
5244 | cbradney | 455 | } |
5345 | mrdocs | 456 | if ((prefsManager->appPrefs.DCMSset.DefaultSolidColorCMYKProfile.isEmpty()) || (!InputProfilesCMYK.contains(prefsManager->appPrefs.DCMSset.DefaultSolidColorCMYKProfile))) |
457 | { |
||
458 | ip = InputProfilesCMYK.begin(); |
||
459 | prefsManager->appPrefs.DCMSset.DefaultSolidColorCMYKProfile = ip.key(); |
||
460 | } |
||
5244 | cbradney | 461 | if ((prefsManager->appPrefs.DCMSset.DefaultMonitorProfile.isEmpty()) || (!MonitorProfiles.contains(prefsManager->appPrefs.DCMSset.DefaultMonitorProfile))) |
462 | { |
||
463 | ip = MonitorProfiles.begin(); |
||
464 | prefsManager->appPrefs.DCMSset.DefaultMonitorProfile = ip.key(); |
||
465 | } |
||
466 | if ((prefsManager->appPrefs.DCMSset.DefaultPrinterProfile.isEmpty()) || (!PrinterProfiles.contains(prefsManager->appPrefs.DCMSset.DefaultPrinterProfile))) |
||
467 | { |
||
468 | ip = PrinterProfiles.begin(); |
||
469 | prefsManager->appPrefs.DCMSset.DefaultPrinterProfile = ip.key(); |
||
470 | } |
||
471 | #ifdef HAVE_CMS |
||
472 | SoftProofing = prefsManager->appPrefs.DCMSset.SoftProofOn; |
||
473 | CMSuse = false; |
||
5345 | mrdocs | 474 | IntentColors = prefsManager->appPrefs.DCMSset.DefaultIntentColors; |
475 | IntentImages = prefsManager->appPrefs.DCMSset.DefaultIntentImages; |
||
5244 | cbradney | 476 | #endif |
477 | } |
||
478 | } |