1 /*
2 For general Scribus (>=1.3.2) copyright and licensing information please refer
3 to the COPYING file provided with the program.
4 
5 Scribus is copyright The Scribus Team per the COPYING file.
6 */
7 
8 #include <QRegularExpression>
9 #include <QSysInfo>
10 
11 #include "api_application.h"
12 
13 #include "scconfig.h"
14 #ifdef HAVE_SVNVERSION
15 	#include "svnversion.h"
16 #endif
17 
18 #include <cairo.h>
19 
20 namespace ScribusAPI {
21 
getBuildInformation()22 	QString getBuildInformation()
23 	{
24 		QString bu;
25 		bu += "C";
26 		bu += "-";
27 		bu += "-";
28 		bu += "T";
29 		bu += "-";
30 	#ifdef HAVE_FONTCONFIG
31 		bu += "F";
32 	#else
33 		bu += "*";
34 	#endif
35 		bu += "-";
36 		bu += "C";
37 		bu += cairo_version_string();
38 
39 	// Some more information if we are not on a 32bit little endian Unix machine
40 	#if defined(Q_OS_WIN)
41 		bu += "-Windows";
42 	#elif defined(Q_OS_MAC)
43 		bu += "-Mac";
44 	#elif defined(Q_OS_DARWIN)
45 		// dunno if anyone uses this...
46 		bu += "-Darwin";
47 	#endif
48 		if (QSysInfo::WordSize != 32)
49 			bu += QString("-%1bit").arg(QSysInfo::WordSize);
50 	#if Q_BYTE_ORDER == Q_BIG_ENDIAN
51 		if (QSysInfo::ByteOrder==QSysInfo::BigEndian)
52 			bu += "-Big";
53 	#endif
54 		return bu;
55 	}
56 
getVersion()57 	QString getVersion()
58 	{
59 		return QString(VERSION);
60 	}
61 
getVersionMajor()62 	int getVersionMajor()
63 	{
64 		QRegularExpression version_regex("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
65 		QRegularExpressionMatch match = version_regex.match(getVersion());
66 		if (!match.hasMatch())
67 			return -1;
68 		return match.captured(1).toInt();
69 	}
70 
getVersionMinor()71 	int getVersionMinor()
72 	{
73 		QRegularExpression version_regex("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
74 		QRegularExpressionMatch match = version_regex.match(getVersion());
75 		if (!match.hasMatch())
76 			return -1;
77 		return match.captured(2).toInt();
78 	}
79 
getVersionPatch()80 	int getVersionPatch()
81 	{
82 		QRegularExpression version_regex("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
83 		QRegularExpressionMatch match = version_regex.match(getVersion());
84 		if (!match.hasMatch())
85 			return -1;
86 		return match.captured(3).toInt();
87 	}
88 
getVersionSuffix()89 	QString getVersionSuffix()
90 	{
91 		QRegularExpression version_regex("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
92 		QRegularExpressionMatch match = version_regex.match(getVersion());
93 		if (!match.hasMatch())
94 			return QString();
95 		return match.captured(4);
96 	}
97 
getVersionScribus()98 	QString getVersionScribus()
99 	{
100 		return QString("Scribus") + " " + getVersion();
101 	}
102 
getVersionScribusAsByteArray()103 	QByteArray getVersionScribusAsByteArray()
104 	{
105 		return QByteArray("Scribus") + " " + QByteArray(VERSION);
106 	}
107 
getVersionScribusTranslated()108 	QString getVersionScribusTranslated()
109 	{
110 		return QObject::tr("Scribus") + " " + getVersion();
111 	}
112 
getVersionScribusTranslatedAsByteArray()113 	QByteArray getVersionScribusTranslatedAsByteArray()
114 	{
115 		return QObject::tr("Scribus").toUtf8() + " " + QByteArray(VERSION);
116 	}
117 
isSVN()118 	bool isSVN()
119 	{
120 		return getVersion().contains("svn", Qt::CaseInsensitive);
121 	}
122 
haveSVNRevision()123 	bool haveSVNRevision()
124 	{
125 #if defined(HAVE_SVNVERSION) && defined(SVNVERSION)
126 		return true;
127 #endif
128 		return false;
129 	}
130 
getSVNRevision()131 	QString getSVNRevision()
132 	{
133 #if defined(HAVE_SVNVERSION) && defined(SVNVERSION)
134 		if (isSVN())
135 			return QString("%1").arg(SVNVERSION);
136 #endif
137 		return QString();
138 	}
139 
140 }
141