diff --git a/autotests/bcbpparsertest.cpp b/autotests/bcbpparsertest.cpp
--- a/autotests/bcbpparsertest.cpp
+++ b/autotests/bcbpparsertest.cpp
@@ -15,7 +15,8 @@
along with this program. If not, see .
*/
-#include "iatabcbpparser.h"
+#include
+#include
#include
#include
#include
@@ -33,6 +34,11 @@
{
Q_OBJECT
private Q_SLOTS:
+ void initTestCase()
+ {
+ KItinerary::init();
+ }
+
void testParserValid_data()
{
QTest::addColumn("message");
diff --git a/autotests/extractortest.cpp b/autotests/extractortest.cpp
--- a/autotests/extractortest.cpp
+++ b/autotests/extractortest.cpp
@@ -19,6 +19,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -57,6 +58,8 @@
{
// use some exotic locale to ensure the date/time parsing doesn't just work by luck
QLocale::setDefault(QLocale(QStringLiteral("fr_FR")));
+
+ KItinerary::init();
}
void testExtract_data()
diff --git a/autotests/jsonlddocumenttest.cpp b/autotests/jsonlddocumenttest.cpp
--- a/autotests/jsonlddocumenttest.cpp
+++ b/autotests/jsonlddocumenttest.cpp
@@ -18,6 +18,7 @@
*/
#include
+#include
#include
#include
#include
@@ -40,6 +41,7 @@
void initTestCase()
{
qputenv("TZ", "GMT");
+ KItinerary::init();
}
void testSerialization()
diff --git a/autotests/pkpassextractortest.cpp b/autotests/pkpassextractortest.cpp
--- a/autotests/pkpassextractortest.cpp
+++ b/autotests/pkpassextractortest.cpp
@@ -19,6 +19,7 @@
#include
#include
#include
+#include
#include
#include
#include
@@ -44,6 +45,8 @@
// use some exotic locale to ensure the date/time parsing doesn't just work by luck
QLocale::setDefault(QLocale(QStringLiteral("fr_FR")));
qputenv("TZ", "EST");
+
+ KItinerary::init();
}
void testExtractText_data()
diff --git a/autotests/postprocessortest.cpp b/autotests/postprocessortest.cpp
--- a/autotests/postprocessortest.cpp
+++ b/autotests/postprocessortest.cpp
@@ -20,6 +20,7 @@
#include "extractorpostprocessor.h"
#include "jsonlddocument.h"
+#include
#include
#include
@@ -37,6 +38,11 @@
{
Q_OBJECT
private Q_SLOTS:
+ void initTestCase()
+ {
+ KItinerary::init();
+ }
+
void testPostProc_data()
{
QTest::addColumn("preFile");
diff --git a/autotests/uic9183parsertest.cpp b/autotests/uic9183parsertest.cpp
--- a/autotests/uic9183parsertest.cpp
+++ b/autotests/uic9183parsertest.cpp
@@ -15,6 +15,7 @@
along with this program. If not, see .
*/
+#include
#include
#include
@@ -31,6 +32,11 @@
{
Q_OBJECT
private Q_SLOTS:
+ void initTestCase()
+ {
+ KItinerary::init();
+ }
+
void testParserValid_data()
{
QTest::addColumn("inFile");
diff --git a/autotests/unstructureddataextractortest.cpp b/autotests/unstructureddataextractortest.cpp
--- a/autotests/unstructureddataextractortest.cpp
+++ b/autotests/unstructureddataextractortest.cpp
@@ -20,6 +20,7 @@
#include
#include
#include
+#include
#include
#include
@@ -62,6 +63,8 @@
{
// use some exotic locale to ensure the date/time parsing doesn't just work by luck
QLocale::setDefault(QLocale(QStringLiteral("fr_FR")));
+
+ KItinerary::init();
}
void testExtractText_data()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -34,6 +34,7 @@
extractorpostprocessor.cpp
extractorrepository.cpp
iatabcbpparser.cpp
+ init.cpp
jsonlddocument.cpp
jsonldimportfilter.cpp
mergeutil.cpp
@@ -46,7 +47,7 @@
ecm_qt_declare_logging_category(kitinerary_lib_srcs HEADER logging.h IDENTIFIER KItinerary::Log CATEGORY_NAME org.kde.kitinerary)
kde_source_files_enable_exceptions(barcodedecoder.cpp)
-add_library(KPimItinerary SHARED ${kitinerary_lib_srcs})
+add_library(KPimItinerary ${kitinerary_lib_srcs})
add_library(KPim::Itinerary ALIAS KPimItinerary)
generate_export_header(KPimItinerary BASE_NAME KItinerary)
set_target_properties(KPimItinerary PROPERTIES
@@ -89,6 +90,7 @@
ExtractorPostprocessor
ExtractorRepository
IataBcbpParser
+ Init
JsonLdDocument
MergeUtil
PdfDocument
diff --git a/src/datatypes/datatypes.cpp b/src/datatypes/datatypes.cpp
--- a/src/datatypes/datatypes.cpp
+++ b/src/datatypes/datatypes.cpp
@@ -15,26 +15,4 @@
along with this program. If not, see .
*/
-#include "organization.h"
-#include "person.h"
-#include "place.h"
-
-#include
-#include
-
-using namespace KItinerary;
-
-struct StartupFunction {
- StartupFunction()
- {
- // add types here that are not covered by moc's auto-registration
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- }
-};
-
-StartupFunction runOnce;
+#include "datatypes.h"
diff --git a/src/datatypes/datatypes.cpp b/src/init.h
copy from src/datatypes/datatypes.cpp
copy to src/init.h
--- a/src/datatypes/datatypes.cpp
+++ b/src/init.h
@@ -15,26 +15,20 @@
along with this program. If not, see .
*/
-#include "organization.h"
-#include "person.h"
-#include "place.h"
-
-#include
-#include
-
-using namespace KItinerary;
-
-struct StartupFunction {
- StartupFunction()
- {
- // add types here that are not covered by moc's auto-registration
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- }
-};
-
-StartupFunction runOnce;
+#ifndef KITINERARY_INIT_H
+#define KITINERARY_INIT_H
+
+#include "kitinerary_export.h"
+
+namespace KItinerary {
+
+/** Initialize static content.
+ * This must be called before using anything from the KItinerary library
+ * when linking statically, for dynamic linking calling this function has
+ * no effect.
+ */
+KITINERARY_EXPORT void init();
+
+}
+
+#endif // KITINERARY_INIT_H
diff --git a/src/datatypes/datatypes.cpp b/src/init.cpp
copy from src/datatypes/datatypes.cpp
copy to src/init.cpp
--- a/src/datatypes/datatypes.cpp
+++ b/src/init.cpp
@@ -15,26 +15,40 @@
along with this program. If not, see .
*/
-#include "organization.h"
-#include "person.h"
-#include "place.h"
+#include "init.h"
-#include
+#include "datatypes/organization.h"
+#include "datatypes/person.h"
+#include "datatypes/place.h"
+
+#include
+#include
#include
using namespace KItinerary;
-struct StartupFunction {
- StartupFunction()
- {
- // add types here that are not covered by moc's auto-registration
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- qRegisterMetaType();
- }
-};
+bool doInit();
+
+static bool runOnce = []() { return doInit(); }();
+
+bool doInit() // must be outside of a namespace for Q_INIT_RESOURCE
+{
+ Q_INIT_RESOURCE(extractors);
-StartupFunction runOnce;
+ qRegisterMetaType();
+ qRegisterMetaType();
+ qRegisterMetaType();
+ qRegisterMetaType();
+ qRegisterMetaType();
+ qRegisterMetaType();
+
+ return true;
+}
+
+void KItinerary::init()
+{
+ if (runOnce) {
+ return;
+ }
+ runOnce = doInit();
+}