Hrvoje Senjan 2014-07-01 22:28:01 +00:00 committed by Git OBS Bridge
parent 93b3932825
commit 839175c33d
5 changed files with 17 additions and 531 deletions

View File

@ -1,522 +0,0 @@
diff --git a/src/kdeclarative/kdeclarative.cpp b/src/kdeclarative/kdeclarative.cpp
index a35dac5..b3906e2 100644
--- a/src/kdeclarative/kdeclarative.cpp
+++ b/src/kdeclarative/kdeclarative.cpp
@@ -39,7 +39,8 @@ namespace KDeclarative {
QStringList KDeclarativePrivate::s_runtimePlatform;
KDeclarativePrivate::KDeclarativePrivate()
- : initialized(false)
+ : initialized(false),
+ contextObj(0)
{
}
@@ -86,8 +87,14 @@ void KDeclarative::setupBindings()
/*Create a context object for the root qml context.
in this way we can register global functions, in this case the i18n() family*/
- RootContext *contextObj = new RootContext(d->declarativeEngine.data());
- d->declarativeEngine.data()->rootContext()->setContextObject(contextObj);
+ if (!d->contextObj) {
+ d->contextObj = new RootContext(d->declarativeEngine.data());
+ }
+ d->declarativeEngine.data()->rootContext()->setContextObject(d->contextObj);
+
+ if (!d->translationDomain.isNull()) {
+ d->contextObj->setProperty("translationDomain", d->translationDomain);
+ }
/* Tell the engine to search for platform-specific imports first
(so it will "win" in import name resolution).
@@ -111,6 +118,19 @@ void KDeclarative::setupBindings()
d->declarativeEngine.data()->addImageProvider(QString(QStringLiteral("icon")), new KIconProvider);
}
+void KDeclarative::setTranslationDomain(const QString &translationDomain)
+{
+ d->translationDomain = translationDomain;
+ if (d->contextObj) {
+ d->contextObj->setProperty("translationDomain", d->translationDomain);
+ }
+}
+
+QString KDeclarative::translationDomain() const
+{
+ return d->translationDomain;
+}
+
void KDeclarative::setupQmlJsDebugger()
{
if (QCoreApplication::arguments().contains(QLatin1String("-qmljsdebugger"))) {
diff --git a/src/kdeclarative/kdeclarative.h b/src/kdeclarative/kdeclarative.h
index b4a274b..1d21964 100644
--- a/src/kdeclarative/kdeclarative.h
+++ b/src/kdeclarative/kdeclarative.h
@@ -54,6 +54,30 @@ public:
QQmlEngine *declarativeEngine() const;
/**
+ * Call this method before calling setupBindings to install a translation domain for all
+ * i18n global functions. If a translation domain is set all i18n calls delegate to the
+ * matching i18nd calls with the provided translation domain.
+ *
+ * The translationDomain affects all i18n calls including those from imports. Because of
+ * that modules intended to be used as imports should prefer the i18nd variants and set
+ * the translation domain explicitly in each call.
+ *
+ * This method is only required if your declarative usage is inside a library. If it's
+ * in an application there is no need to set the translation domain as the application's
+ * domain can be used.
+ *
+ * @param translationDomain The translation domain to be used for i18n calls.
+ * @since 5.0
+ */
+ void setTranslationDomain(const QString &translationDomain);
+
+ /**
+ * @return the translation domain for the i18n calls done in this QML engine
+ * @since 5.0
+ */
+ QString translationDomain() const;
+
+ /**
* This method must be called very early at startup time to ensure the
* QQuickDebugger is enabled. Ideally it should be called in main(),
* after command-line options are defined.
diff --git a/src/kdeclarative/private/kdeclarative_p.h b/src/kdeclarative/private/kdeclarative_p.h
index 6b61d12..7ef9d0a 100644
--- a/src/kdeclarative/private/kdeclarative_p.h
+++ b/src/kdeclarative/private/kdeclarative_p.h
@@ -21,6 +21,7 @@
#define KDECLARATIVE_P_H
#include "kdeclarative.h"
+#include "rootcontext_p.h"
#include <QtCore/QPointer>
@@ -33,7 +34,9 @@ public:
QPointer<QQmlEngine> declarativeEngine;
bool initialized;
+ QString translationDomain;
static QStringList s_runtimePlatform;
+ QPointer<RootContext> contextObj;
};
}
diff --git a/src/kdeclarative/private/rootcontext.cpp b/src/kdeclarative/private/rootcontext.cpp
index 1230666..d88b566 100644
--- a/src/kdeclarative/private/rootcontext.cpp
+++ b/src/kdeclarative/private/rootcontext.cpp
@@ -44,7 +44,12 @@ QString RootContext::i18n(const QString &message, const QString &param1, const Q
return QString();
}
- KLocalizedString trMessage = ki18n(message.toUtf8().constData());
+ KLocalizedString trMessage;
+ if (!m_translationDomain.isNull()) {
+ trMessage = ki18nd(m_translationDomain.toUtf8().constData(), message.toUtf8().constData());
+ } else {
+ trMessage = ki18n(message.toUtf8().constData());
+ }
if (!param1.isNull()) {
trMessage = trMessage.subs(param1);
@@ -87,7 +92,12 @@ QString RootContext::i18nc(const QString &context, const QString &message, const
return QString();
}
- KLocalizedString trMessage = ki18nc(context.toUtf8().constData(), message.toUtf8().constData());
+ KLocalizedString trMessage;
+ if (!m_translationDomain.isNull()) {
+ trMessage = ki18ndc(m_translationDomain.toUtf8().constData(), context.toUtf8().constData(), message.toUtf8().constData());
+ } else {
+ trMessage = ki18nc(context.toUtf8().constData(), message.toUtf8().constData());
+ }
if (!param1.isNull()) {
trMessage = trMessage.subs(param1);
@@ -130,7 +140,12 @@ QString RootContext::i18np(const QString &singular, const QString &plural, const
return QString();
}
- KLocalizedString trMessage = ki18np(singular.toUtf8().constData(), plural.toUtf8().constData());
+ KLocalizedString trMessage;
+ if (!m_translationDomain.isNull()) {
+ trMessage = ki18ndp(m_translationDomain.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
+ } else {
+ trMessage = ki18np(singular.toUtf8().constData(), plural.toUtf8().constData());
+ }
if (!param1.isNull()) {
bool ok;
@@ -179,7 +194,196 @@ QString RootContext::i18ncp(const QString &context, const QString &singular, con
return QString();
}
- KLocalizedString trMessage = ki18ncp(context.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
+ KLocalizedString trMessage;
+ if (!m_translationDomain.isNull()) {
+ trMessage = ki18ndcp(m_translationDomain.toUtf8().constData(), context.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
+ } else {
+ trMessage = ki18ncp(context.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
+ }
+
+ if (!param1.isNull()) {
+ bool ok;
+ int num = param1.toInt(&ok);
+ if (ok) {
+ trMessage = trMessage.subs(num);
+ } else {
+ trMessage = trMessage.subs(param1);
+ }
+ }
+ if (!param2.isNull()) {
+ trMessage = trMessage.subs(param2);
+ }
+ if (!param3.isNull()) {
+ trMessage = trMessage.subs(param3);
+ }
+ if (!param4.isNull()) {
+ trMessage = trMessage.subs(param4);
+ }
+ if (!param5.isNull()) {
+ trMessage = trMessage.subs(param5);
+ }
+ if (!param6.isNull()) {
+ trMessage = trMessage.subs(param6);
+ }
+ if (!param7.isNull()) {
+ trMessage = trMessage.subs(param7);
+ }
+ if (!param8.isNull()) {
+ trMessage = trMessage.subs(param8);
+ }
+ if (!param9.isNull()) {
+ trMessage = trMessage.subs(param9);
+ }
+ if (!param10.isNull()) {
+ trMessage = trMessage.subs(param10);
+ }
+
+ return trMessage.toString();
+}
+
+QString RootContext::i18nd(const QString &domain, const QString &message, const QString &param1, const QString &param2, const QString &param3, const QString &param4, const QString &param5, const QString &param6, const QString &param7, const QString &param8, const QString &param9, const QString &param10) const
+{
+ if (domain.isNull() || message.isNull()) {
+ qWarning() << "i18nd() needs at least two parameters";
+ return QString();
+ }
+
+ KLocalizedString trMessage = ki18nd(domain.toUtf8().constData(), message.toUtf8().constData());
+
+ if (!param1.isNull()) {
+ trMessage = trMessage.subs(param1);
+ }
+ if (!param2.isNull()) {
+ trMessage = trMessage.subs(param2);
+ }
+ if (!param3.isNull()) {
+ trMessage = trMessage.subs(param3);
+ }
+ if (!param4.isNull()) {
+ trMessage = trMessage.subs(param4);
+ }
+ if (!param5.isNull()) {
+ trMessage = trMessage.subs(param5);
+ }
+ if (!param6.isNull()) {
+ trMessage = trMessage.subs(param6);
+ }
+ if (!param7.isNull()) {
+ trMessage = trMessage.subs(param7);
+ }
+ if (!param8.isNull()) {
+ trMessage = trMessage.subs(param8);
+ }
+ if (!param9.isNull()) {
+ trMessage = trMessage.subs(param9);
+ }
+ if (!param10.isNull()) {
+ trMessage = trMessage.subs(param10);
+ }
+
+ return trMessage.toString();
+}
+
+QString RootContext::i18ndc(const QString &domain, const QString &context, const QString &message, const QString &param1, const QString &param2, const QString &param3, const QString &param4, const QString &param5, const QString &param6, const QString &param7, const QString &param8, const QString &param9, const QString &param10) const
+{
+ if (domain.isNull() || context.isNull() || message.isNull()) {
+ qWarning() << "i18ndc() needs at least three arguments";
+ return QString();
+ }
+
+ KLocalizedString trMessage = ki18ndc(domain.toUtf8().constData(), context.toUtf8().constData(), message.toUtf8().constData());
+
+ if (!param1.isNull()) {
+ trMessage = trMessage.subs(param1);
+ }
+ if (!param2.isNull()) {
+ trMessage = trMessage.subs(param2);
+ }
+ if (!param3.isNull()) {
+ trMessage = trMessage.subs(param3);
+ }
+ if (!param4.isNull()) {
+ trMessage = trMessage.subs(param4);
+ }
+ if (!param5.isNull()) {
+ trMessage = trMessage.subs(param5);
+ }
+ if (!param6.isNull()) {
+ trMessage = trMessage.subs(param6);
+ }
+ if (!param7.isNull()) {
+ trMessage = trMessage.subs(param7);
+ }
+ if (!param8.isNull()) {
+ trMessage = trMessage.subs(param8);
+ }
+ if (!param9.isNull()) {
+ trMessage = trMessage.subs(param9);
+ }
+ if (!param10.isNull()) {
+ trMessage = trMessage.subs(param10);
+ }
+
+ return trMessage.toString();
+}
+
+QString RootContext::i18ndp(const QString &domain, const QString &singular, const QString &plural, const QString &param1, const QString &param2, const QString &param3, const QString &param4, const QString &param5, const QString &param6, const QString &param7, const QString &param8, const QString &param9, const QString &param10) const
+{
+ if (domain.isNull() || singular.isNull() || plural.isNull()) {
+ qWarning() << "i18ndp() needs at least three arguments";
+ return QString();
+ }
+
+ KLocalizedString trMessage = ki18ndp(domain.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
+
+ if (!param1.isNull()) {
+ bool ok;
+ int num = param1.toInt(&ok);
+ if (ok) {
+ trMessage = trMessage.subs(num);
+ } else {
+ trMessage = trMessage.subs(param1);
+ }
+ }
+ if (!param2.isNull()) {
+ trMessage = trMessage.subs(param2);
+ }
+ if (!param3.isNull()) {
+ trMessage = trMessage.subs(param3);
+ }
+ if (!param4.isNull()) {
+ trMessage = trMessage.subs(param4);
+ }
+ if (!param5.isNull()) {
+ trMessage = trMessage.subs(param5);
+ }
+ if (!param6.isNull()) {
+ trMessage = trMessage.subs(param6);
+ }
+ if (!param7.isNull()) {
+ trMessage = trMessage.subs(param7);
+ }
+ if (!param8.isNull()) {
+ trMessage = trMessage.subs(param8);
+ }
+ if (!param9.isNull()) {
+ trMessage = trMessage.subs(param9);
+ }
+ if (!param10.isNull()) {
+ trMessage = trMessage.subs(param10);
+ }
+
+ return trMessage.toString();
+}
+
+QString RootContext::i18ndcp(const QString &domain, const QString &context, const QString &singular, const QString &plural, const QString &param1, const QString &param2, const QString &param3, const QString &param4, const QString &param5, const QString &param6, const QString &param7, const QString &param8, const QString &param9, const QString &param10) const
+{
+ if (domain.isNull() || context.isNull() || singular.isNull() || plural.isNull()) {
+ qWarning() << "i18ndcp() needs at least four arguments";
+ return QString();
+ }
+
+ KLocalizedString trMessage = ki18ndcp(domain.toUtf8().constData(), context.toUtf8().constData(), singular.toUtf8().constData(), plural.toUtf8().constData());
if (!param1.isNull()) {
bool ok;
diff --git a/src/kdeclarative/private/rootcontext_p.h b/src/kdeclarative/private/rootcontext_p.h
index 16694b1..94df09f 100644
--- a/src/kdeclarative/private/rootcontext_p.h
+++ b/src/kdeclarative/private/rootcontext_p.h
@@ -27,6 +27,7 @@ namespace KDeclarative {
class RootContext : public QObject
{
Q_OBJECT
+ Q_PROPERTY(QString translationDomain MEMBER m_translationDomain NOTIFY translationDomainChanged)
public:
RootContext(QObject *parent = 0);
@@ -39,6 +40,20 @@ public:
Q_INVOKABLE QString i18np(const QString &singular, const QString &plural, const QString &param1 = QString(), const QString &param2 = QString(), const QString &param3 = QString(), const QString &param4 = QString(), const QString &param5 = QString(), const QString &param6 = QString(), const QString &param7 = QString(), const QString &param8 = QString(), const QString &param9 = QString(), const QString &param10 = QString()) const;
Q_INVOKABLE QString i18ncp(const QString &context, const QString &singular, const QString &plural, const QString &param1 = QString(), const QString &param2 = QString(), const QString &param3 = QString(), const QString &param4 = QString(), const QString &param5 = QString(), const QString &param6 = QString(), const QString &param7 = QString(), const QString &param8 = QString(), const QString &param9 = QString(), const QString &param10 = QString()) const;
+
+ Q_INVOKABLE QString i18nd(const QString &domain, const QString &message, const QString &param1 = QString(), const QString &param2 = QString(), const QString &param3 = QString(), const QString &param4 = QString(), const QString &param5 = QString(), const QString &param6 = QString(), const QString &param7 = QString(), const QString &param8 = QString(), const QString &param9 = QString(), const QString &param10 = QString()) const;
+
+ Q_INVOKABLE QString i18ndc(const QString &domain, const QString &context, const QString &message, const QString &param1 = QString(), const QString &param2 = QString(), const QString &param3 = QString(), const QString &param4 = QString(), const QString &param5 = QString(), const QString &param6 = QString(), const QString &param7 = QString(), const QString &param8 = QString(), const QString &param9 = QString(), const QString &param10 = QString()) const;
+
+ Q_INVOKABLE QString i18ndp(const QString &domain, const QString &singular, const QString &plural, const QString &param1 = QString(), const QString &param2 = QString(), const QString &param3 = QString(), const QString &param4 = QString(), const QString &param5 = QString(), const QString &param6 = QString(), const QString &param7 = QString(), const QString &param8 = QString(), const QString &param9 = QString(), const QString &param10 = QString()) const;
+
+ Q_INVOKABLE QString i18ndcp(const QString &domain, const QString &context, const QString &singular, const QString &plural, const QString &param1 = QString(), const QString &param2 = QString(), const QString &param3 = QString(), const QString &param4 = QString(), const QString &param5 = QString(), const QString &param6 = QString(), const QString &param7 = QString(), const QString &param8 = QString(), const QString &param9 = QString(), const QString &param10 = QString()) const;
+
+Q_SIGNALS:
+ void translationDomainChanged(const QString&);
+
+private:
+ QString m_translationDomain;
};
}
diff --git a/src/kdeclarative/qmlobject.cpp b/src/kdeclarative/qmlobject.cpp
index ca13097..029edaf 100644
--- a/src/kdeclarative/qmlobject.cpp
+++ b/src/kdeclarative/qmlobject.cpp
@@ -88,6 +88,7 @@ public:
QmlObjectIncubator incubator;
QQmlComponent *component;
QTimer *executionEndTimer;
+ KDeclarative kdeclarative;
bool delay : 1;
};
@@ -117,12 +118,6 @@ void QmlObjectPrivate::execute(const QUrl &source)
component = new QQmlComponent(engine, q);
delete incubator.object();
- KDeclarative kdeclarative;
- kdeclarative.setDeclarativeEngine(engine);
-
- //binds things like kconfig and icons
- kdeclarative.setupBindings();
-
component->loadUrl(source);
if (delay) {
@@ -146,6 +141,9 @@ QmlObject::QmlObject(QObject *parent)
d(new QmlObjectPrivate(this))
{
d->engine = new QQmlEngine(this);
+ d->kdeclarative.setDeclarativeEngine(d->engine);
+ //binds things like kconfig and icons
+ d->kdeclarative.setupBindings();
d->engine->setIncubationController(new QmlObjectIncubationController(0));
}
@@ -159,6 +157,9 @@ QmlObject::QmlObject(QQmlEngine *engine, QObject *parent)
d->engine = new QQmlEngine(this);
d->engine->setIncubationController(new QmlObjectIncubationController(0));
}
+ d->kdeclarative.setDeclarativeEngine(d->engine);
+ //binds things like kconfig and icons
+ d->kdeclarative.setupBindings();
}
QmlObject::~QmlObject()
@@ -169,6 +170,16 @@ QmlObject::~QmlObject()
delete d;
}
+void QmlObject::setTranslationDomain(const QString &translationDomain)
+{
+ d->kdeclarative.setTranslationDomain(translationDomain);
+}
+
+QString QmlObject::translationDomain() const
+{
+ return d->kdeclarative.translationDomain();
+}
+
void QmlObject::setSource(const QUrl &source)
{
d->source = source;
diff --git a/src/kdeclarative/qmlobject.h b/src/kdeclarative/qmlobject.h
index 2da6c9c..cd74829 100644
--- a/src/kdeclarative/qmlobject.h
+++ b/src/kdeclarative/qmlobject.h
@@ -55,6 +55,7 @@ class KDECLARATIVE_EXPORT QmlObject : public QObject
Q_OBJECT
Q_PROPERTY(QUrl source READ source WRITE setSource)
+ Q_PROPERTY(QString translationDomain READ translationDomain WRITE setTranslationDomain)
Q_PROPERTY(bool initializationDelayed READ isInitializationDelayed WRITE setInitializationDelayed)
Q_PROPERTY(QObject *rootObject READ rootObject)
@@ -77,6 +78,30 @@ public:
~QmlObject();
/**
+ * Call this method before calling setupBindings to install a translation domain for all
+ * i18n global functions. If a translation domain is set all i18n calls delegate to the
+ * matching i18nd calls with the provided translation domain.
+ *
+ * The translationDomain affects all i18n calls including those from imports. Because of
+ * that modules intended to be used as imports should prefer the i18nd variants and set
+ * the translation domain explicitly in each call.
+ *
+ * This method is only required if your declarative usage is inside a library. If it's
+ * in an application there is no need to set the translation domain as the application's
+ * domain can be used.
+ *
+ * @param translationDomain The translation domain to be used for i18n calls.
+ * @since 5.0
+ */
+ void setTranslationDomain(const QString &translationDomain);
+
+ /**
+ * @return the translation domain for the i18n calls done in this QML engine
+ * @since 5.0
+ */
+ QString translationDomain() const;
+
+ /**
* Sets the path of the QML file to parse and execute
*
* @param path the absolute path of a QML file
diff --git a/src/qmlcontrols/kcoreaddons/kcoreaddonsplugin.cpp b/src/qmlcontrols/kcoreaddons/kcoreaddonsplugin.cpp
index 65dd75f..3c1a96e 100644
--- a/src/qmlcontrols/kcoreaddons/kcoreaddonsplugin.cpp
+++ b/src/qmlcontrols/kcoreaddons/kcoreaddonsplugin.cpp
@@ -1,5 +1,6 @@
/*
* Copyright 2014 Bhushan Shah <bhush94@gmail.com>
+ * Copyright 2014 David Edmundson <davidedmundson@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
@@ -24,10 +25,18 @@
#include "formats.h"
+static QObject *formats_singletontype_provider(QQmlEngine *engine, QJSEngine *scriptEngine)
+{
+ Q_UNUSED(engine)
+ Q_UNUSED(scriptEngine)
+
+ return new Formats();
+}
+
void KCoreAddonsPlugin::registerTypes(const char *uri)
{
Q_ASSERT(uri == QLatin1String("org.kde.kcoreaddons"));
- qmlRegisterType<Formats>(uri, 1, 0, "Formats");
+ qmlRegisterSingletonType<Formats>(uri, 1, 0, "Format", formats_singletontype_provider);
qRegisterMetaType<QLocale::FormatType>();
}
\ No newline at end of file

View File

@ -1,3 +0,0 @@
version https://git-lfs.github.com/spec/v1
oid sha256:e33708cdd149e465dc897720f82a2392798f02ac37c862589e97cf7a65088f36
size 2813732

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:4af225df5c2684baf0272b43d6883b76e6a2d170b5932665dacefb64d19983ba
size 2809464

View File

@ -1,3 +1,14 @@
-------------------------------------------------------------------
Tue Jul 1 21:36:03 UTC 2014 - hrvoje.senjan@gmail.com
- Update to 5.0.0
* Final release of KDE Frameworks 5
* API improvements and cleanups
* Buildsystem fixes
* For more details please see:
http://www.kde.org/announcements/announce-frameworks5-5.0.0.php
- Drop af7c0f8194.patch, merged upstream
-------------------------------------------------------------------
Sun Jun 1 18:02:34 UTC 2014 - hrvoje.senjan@gmail.com

View File

@ -18,10 +18,10 @@
%define lname libKF5Declarative5
Name: kdeclarative
Version: 4.100.0
Version: 5.0.0
Release: 0
BuildRequires: cmake >= 2.8.12
BuildRequires: extra-cmake-modules >= 0.0.14
BuildRequires: extra-cmake-modules >= 1.0.0
BuildRequires: fdupes
BuildRequires: kconfig-devel >= %{_kf5_version}
BuildRequires: kcoreaddons-devel >= %{_kf5_version}
@ -42,10 +42,8 @@ Summary: Integration of QML and KDE workspaces
License: LGPL-2.1+
Group: System/GUI/KDE
Url: http://www.kde.org
Source: http://download.kde.org/unstable/frameworks/%{version}/%{name}-%{version}.tar.xz
Source: http://download.kde.org/stable/frameworks/%{version}/%{name}-%{version}.tar.xz
Source1: baselibs.conf
# PATCH-FIX-UPSTREAM af7c0f8194.patch
Patch0: af7c0f8194.patch
BuildRoot: %{_tmppath}/%{name}-%{version}-build
%description
@ -73,7 +71,6 @@ Development files.
%lang_package -n %lname
%prep
%setup -q
%patch0 -p1
%build
%cmake_kf5 -d build