Commit df069d8a authored by Nicolás Alvarez's avatar Nicolás Alvarez

Initial import from the monolithic kdepim.

This is the beginning of revision history for this module. If you
want to look at revision history older than this, please refer to the
techbase wiki for how to use Git history grafting. At the time of
writing, this wiki is located here:

http://community.kde.org/Frameworks/GitOldHistory

If you have already performed the grafting and you don't see any
history beyond this commit, try running "git log" with the "--follow"
argument.

Branched from the monolithic repo, kdepim master branch, at commit
d0009536f24e8c7f4cc32a70936f5c25194e9a6f
parents
cmake_minimum_required(VERSION 2.8.12)
project(GrantleeTheme)
if(${CMAKE_SOURCE_DIR} STREQUAL ${GrantleeTheme_SOURCE_DIR})
# ECM setup
find_package(ECM 5.16.0 CONFIG REQUIRED)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH})
set(LIBRARY_NAMELINK)
include(GenerateExportHeader)
include(ECMSetupVersion)
include(ECMGenerateHeaders)
include(ECMGeneratePriFile)
include(ECMPackageConfigHelpers)
include(ECMSetupVersion)
include(FeatureSummary)
include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDEFrameworkCompilerSettings)
include(ECMQtDeclareLoggingCategory)
include(ECMAddTests)
set(KF5_VERSION "5.16.0")
set(KDEPIM_LIB_VERSION "5.1.42")
set(QT_REQUIRED_VERSION "5.4.0")
set(GRANTLEE_VERSION "5.0.0")
find_package(Qt5 ${QT_REQUIRED_VERSION} CONFIG REQUIRED Widgets Test Network)
find_package(KF5I18n ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5IconThemes ${KF5_VERSION} CONFIG REQUIRED)
find_package(KF5NewStuff ${KF5_VERSION} CONFIG REQUIRED)
find_package(Grantlee5 ${GRANTLEE_VERSION} CONFIG REQUIRED)
ecm_setup_version(${KDEPIM_LIB_VERSION} VARIABLE_PREFIX GRANTLEETHEME
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/grantleetheme_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5GrantleeThemeConfigVersion.cmake"
SOVERSION 5
)
########### Targets ###########
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)
########### CMake Config Files ###########
set(CMAKECONFIG_INSTALL_DIR "${KDE_INSTALL_CMAKEPACKAGEDIR}/KF5GrantleeTheme")
ecm_configure_package_config_file(
"${CMAKE_CURRENT_SOURCE_DIR}/KF5GrantleeThemeConfig.cmake.in"
"${CMAKE_CURRENT_BINARY_DIR}/KF5GrantleeThemeConfig.cmake"
INSTALL_DESTINATION ${CMAKECONFIG_INSTALL_DIR}
)
install(FILES
"${CMAKE_CURRENT_BINARY_DIR}/KF5GrantleeThemeConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/KF5GrantleeThemeConfigVersion.cmake"
DESTINATION "${CMAKECONFIG_INSTALL_DIR}"
COMPONENT Devel
)
install(EXPORT KF5GrantleeThemeTargets DESTINATION "${CMAKECONFIG_INSTALL_DIR}" FILE KF5GrantleeThemeTargets.cmake NAMESPACE KF5::)
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/grantleetheme_version.h
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5} COMPONENT Devel
)
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
else()
ecm_setup_version(${KDEPIM_LIB_VERSION} VARIABLE_PREFIX GRANTLEETHEME
VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/grantleetheme_version.h"
PACKAGE_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/KF5GrantleeThemeConfigVersion.cmake"
SOVERSION 5
)
endif()
add_subdirectory(src)
if (BUILD_TESTING)
add_subdirectory(autotest)
endif()
install( FILES grantleetheme.categories DESTINATION ${KDE_INSTALL_CONFDIR} )
@PACKAGE_INIT@
include("${CMAKE_CURRENT_LIST_DIR}/KF5GrantleeThemeTargets.cmake")
add_definitions( -DGRANTLEETHEME_DATA_DIR="${CMAKE_CURRENT_SOURCE_DIR}/data" )
ecm_add_test(grantleethemetest.cpp
NAME_PREFIX "grantleetheme-"
LINK_LIBRARIES Qt5::Test KF5::GrantleeTheme
)
[Desktop Entry]
Name=Example
Description=Example theme for header.
FileName=header.html
DisplayExtraVariables=foo,bla
[Desktop Entry]
Name=Example
Description=Example theme for header.
FileName=header.html
{% extends "main.html" %}
{% block box %}
<div class="center">
<h2>{{ title }}</h2>
<p>{{ subtext }}</p>
</div>
{% endblock box %}
\ No newline at end of file
<?xml version="1.0" encoding="UTF8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF8" />
<style type="text/css">
/*<![CDATA[*/
@import "main.css";
/*]]>*/
</style>
<title>KMail</title>
</head>
<body>
<div id="header">
<img src="file:kmail.png" align="top" height="128" width="128" alt="kmail" title="" />
<div id="title"><h1>KMail</h1>...just rocks!
</div>
</div>
<div id="box">
<div id="boxInner">
<div class="center">
<h2>Something's going on</h2>
<p>Please wait, it will be over soon.</p>
</div>
</div>
</div>
</body>
</html>
<!-- vim:set sw=2 et nocindent smartindent: -->
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<style type="text/css">
/*<![CDATA[*/
@import "main.css";
/*]]>*/
{% block style %}
{% endblock style %}
</style>
<title>{{ name }}</title>
</head>
<body>
<div id="header">
{% icon icon sizeenormous %}
<div id="title">
<h1>{{ name }}</h1>
{{ subtitle }}
</div>
</div>
<div id="box">
<div id="boxInner">
{% block box %}
{% endblock box %}
</div>
</div>
</body>
</html>
<!-- vim:set sw=2 et nocindent smartindent: -->
/*
Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "grantleethemetest.h"
#include "grantleetheme.h"
#include <qtest.h>
#include <QDir>
#include <QProcess>
#include <QStandardPaths>
GrantleeThemeTest::GrantleeThemeTest(QObject *parent)
: QObject(parent)
{
QStandardPaths::setTestModeEnabled(true);
}
GrantleeThemeTest::~GrantleeThemeTest()
{
}
void GrantleeThemeTest::shouldHaveDefaultValue()
{
GrantleeTheme::Theme theme;
QVERIFY(theme.description().isEmpty());
QVERIFY(theme.themeFilename().isEmpty());
QVERIFY(theme.name().isEmpty());
QVERIFY(theme.displayExtraVariables().isEmpty());
QVERIFY(theme.dirName().isEmpty());
QVERIFY(theme.absolutePath().isEmpty());
QVERIFY(theme.author().isEmpty());
QVERIFY(theme.authorEmail().isEmpty());
QVERIFY(!theme.isValid());
}
void GrantleeThemeTest::shouldInvalidWhenPathIsNotValid()
{
const QString themePath(QStringLiteral("/foo"));
const QString dirName(QStringLiteral("name"));
const QString defaultDesktopFileName(QStringLiteral("bla"));
GrantleeTheme::Theme theme(themePath, dirName, defaultDesktopFileName);
QVERIFY(theme.description().isEmpty());
QVERIFY(theme.themeFilename().isEmpty());
QVERIFY(theme.name().isEmpty());
QVERIFY(theme.displayExtraVariables().isEmpty());
QVERIFY(!theme.dirName().isEmpty());
QVERIFY(!theme.absolutePath().isEmpty());
QVERIFY(theme.author().isEmpty());
QVERIFY(theme.authorEmail().isEmpty());
QVERIFY(!theme.isValid());
}
void GrantleeThemeTest::shouldLoadTheme_data()
{
QTest::addColumn<QString>("dirname");
QTest::addColumn<QString>("filename");
QTest::addColumn<bool>("isvalid");
QTest::addColumn<QStringList>("displayExtraVariables");
QTest::newRow("valid theme") << QStringLiteral("valid") << QStringLiteral("filename.testdesktop") << true << QStringList();
QTest::newRow("not existing theme") << QStringLiteral("notvalid") << QStringLiteral("filename.testdesktop") << false << QStringList();
QStringList extraVariables;
extraVariables << QStringLiteral("foo") << QStringLiteral("bla");
QTest::newRow("valid with extra variable") << QStringLiteral("valid-with-extravariables") << QStringLiteral("filename.testdesktop") << true << extraVariables;
}
void GrantleeThemeTest::shouldLoadTheme()
{
QFETCH(QString, dirname);
QFETCH(QString, filename);
QFETCH(bool, isvalid);
QFETCH(QStringList, displayExtraVariables);
GrantleeTheme::Theme theme(QStringLiteral(GRANTLEETHEME_DATA_DIR) + QDir::separator() + dirname, dirname, filename);
QCOMPARE(theme.isValid(), isvalid);
QCOMPARE(theme.displayExtraVariables(), displayExtraVariables);
QCOMPARE(theme.dirName(), dirname);
}
bool GrantleeThemeTest::validateHtml(const QString &themePath, const QString &name, const QString &html)
{
const QString outFileName = themePath + QStringLiteral("/%1.out").arg(name);
const QString htmlFileName = themePath + QStringLiteral("/%1.out.html").arg(name);
QFile outFile(outFileName);
if (!outFile.open(QIODevice::WriteOnly)) {
return false;
}
outFile.write(html.toUtf8());
outFile.close();
// validate xml and pretty-print for comparisson
// TODO add proper cmake check for xmllint and diff
const QStringList args = {
QStringLiteral("--format"),
QStringLiteral("--encode"),
QStringLiteral("UTF8"),
QStringLiteral("--output"),
htmlFileName,
outFileName
};
const int result = QProcess::execute(QStringLiteral("xmllint"), args);
return result == 0;
}
bool GrantleeThemeTest::compareHtml(const QString &themePath, const QString &name)
{
const QString htmlFileName = themePath + QStringLiteral("/%1.out.html").arg(name);
const QString referenceFileName = themePath + QStringLiteral("/%1_expected.html").arg(name);
// get rid of system dependent or random paths
{
QFile f(htmlFileName);
if (!f.open(QIODevice::ReadOnly)) {
return false;
}
QString content = QString::fromUtf8(f.readAll());
f.close();
content.replace(QRegExp(QLatin1String("\"file:[^\"]*[/(?:%2F)]([^\"/(?:%2F)]*)\"")), QStringLiteral("\"file:\\1\""));
if (!f.open(QIODevice::WriteOnly | QIODevice::Truncate)) {
return false;
}
f.write(content.toUtf8());
f.close();
}
// compare to reference file
const QStringList args = {
QStringLiteral("-u"),
referenceFileName,
htmlFileName
};
QProcess proc;
proc.setProcessChannelMode(QProcess::ForwardedChannels);
proc.start(QStringLiteral("diff"), args);
if (!proc.waitForFinished()) {
return false;
}
return proc.exitCode() == 0;
}
void GrantleeThemeTest::testRenderTemplate_data()
{
QTest::addColumn<QString>("dirname");
QTest::addColumn<bool>("isValid");
QTest::addColumn<QString>("filename");
QTest::addColumn<QString>("templateBasename");
QTest::newRow("valid theme") << QStringLiteral("valid") << true << QStringLiteral("filename.testdesktop") << QStringLiteral("header");
QTest::newRow("invalid theme") << QStringLiteral("invalid") << false << QStringLiteral("filename.testdesktop") << QString();
}
void GrantleeThemeTest::testRenderTemplate()
{
QFETCH(QString, dirname);
QFETCH(bool, isValid);
QFETCH(QString, filename);
QFETCH(QString, templateBasename);
const QString themePath = QStringLiteral(GRANTLEETHEME_DATA_DIR) + QDir::separator() + dirname;
QVariantHash data;
data[QStringLiteral("icon")] = QStringLiteral("kmail");
data[QStringLiteral("name")] = QStringLiteral("KMail");
data[QStringLiteral("subtitle")] = QStringLiteral("...just rocks!");
data[QStringLiteral("title")] = QStringLiteral("Something's going on");
data[QStringLiteral("subtext")] = QStringLiteral("Please wait, it will be over soon.");
GrantleeTheme::Theme theme(themePath, dirname, filename);
QCOMPARE(theme.isValid(), isValid);
if (isValid) {
const QString result = theme.render(templateBasename + QStringLiteral(".html"), data);
QVERIFY(validateHtml(themePath, templateBasename, result));
QVERIFY(compareHtml(themePath, templateBasename));
QFile::remove(themePath + QDir::separator() + templateBasename + QStringLiteral(".out"));
QFile::remove(themePath + QDir::separator() + templateBasename + QStringLiteral(".out.html"));
}
}
QTEST_MAIN(GrantleeThemeTest)
/*
Copyright (c) 2014-2015 Montel Laurent <montel@kde.org>
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#ifndef GRANTLEETHEMETEST_H
#define GRANTLEETHEMETEST_H
#include <QObject>
class GrantleeThemeTest : public QObject
{
Q_OBJECT
public:
explicit GrantleeThemeTest(QObject *parent = Q_NULLPTR);
~GrantleeThemeTest();
private Q_SLOTS:
void shouldHaveDefaultValue();
void shouldInvalidWhenPathIsNotValid();
void shouldLoadTheme_data();
void shouldLoadTheme();
void testRenderTemplate_data();
void testRenderTemplate();
private:
bool validateHtml(const QString &path, const QString &name, const QString &html);
bool compareHtml(const QString &path, const QString &name);
};
#endif // GRANTLEETHEMETEST_H
log_grantleetheme kdepim (grantleetheme)
add_definitions( -DQT_NO_CAST_FROM_ASCII )
add_definitions( -DQT_NO_CAST_TO_ASCII )
add_definitions(-DTRANSLATION_DOMAIN=\"libgrantleetheme\")
add_subdirectory(plugin)
set(libgrantleetheme_SRCS
grantleetheme.cpp
grantleethememanager.cpp
grantleeki18nlocalizer.cpp
)
configure_file(config-grantleetheme.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/config-grantleetheme.h)
ecm_qt_declare_logging_category(libgrantleetheme_SRCS HEADER grantleetheme_debug.h IDENTIFIER GRANTLEETHEME_LOG CATEGORY_NAME log_grantleetheme)
add_library(KF5GrantleeTheme ${libgrantleetheme_SRCS})
generate_export_header(KF5GrantleeTheme BASE_NAME grantleetheme)
add_library(KF5::GrantleeTheme ALIAS KF5GrantleeTheme)
target_include_directories(KF5GrantleeTheme INTERFACE "$<INSTALL_INTERFACE:${KDE_INSTALL_INCLUDEDIR_KF5}/GrantleeTheme/;${KDE_INSTALL_INCLUDEDIR_KF5}/grantleetheme>")
target_include_directories(KF5GrantleeTheme PUBLIC "$<BUILD_INTERFACE:${GrantleeTheme_SOURCE_DIR}/src;${GrantleeTheme_BINARY_DIR}/src;>")
target_link_libraries(KF5GrantleeTheme
PRIVATE
KF5::NewStuff
KF5::I18n
Grantlee5::Templates
)
set_target_properties(KF5GrantleeTheme PROPERTIES
VERSION ${GRANTLEETHEME_VERSION_STRING}
SOVERSION ${GRANTLEETHEME_SOVERSION}
EXPORT_NAME GrantleeTheme
)
install(TARGETS
KF5GrantleeTheme
EXPORT KF5GrantleeThemeTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS} ${LIBRARY_NAMELINK}
)
ecm_generate_headers(GrantleeTheme_CamelCase_HEADERS
HEADER_NAMES
GrantleeThemeManager
GrantleeTheme
REQUIRED_HEADERS GrantleeTheme_HEADERS
PREFIX GrantleeTheme
)
ecm_generate_pri_file(BASE_NAME GrantleeTheme
LIB_NAME KF5GrantleeTheme
DEPS "" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/GrantleeTheme
)
if(${CMAKE_SOURCE_DIR} STREQUAL ${GrantleeTheme_SOURCE_DIR})
install(FILES
${GrantleeTheme_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/GrantleeTheme
COMPONENT Devel
)
install(FILES
${GrantleeTheme_HEADERS}
${CMAKE_CURRENT_BINARY_DIR}/grantleetheme_export.h
${GrantleeTheme_CamelCase_HEADERS}
DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/grantleetheme
COMPONENT Devel
)
install(FILES
${PRI_FILENAME}
DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
endif()
#! /bin/sh
$XGETTEXT `find . -name '*.cpp' -o -name '*.h'` -o $podir/libgrantleetheme.pot
rm -f rc.cpp
/*
* Copyright (C) 2015 Volker Krause <vkrause@kde.org>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef CONFIG_GRANTLEETHEME_H
#define CONFIG_GRANTLEETHEME_H
#define GRANTLEE_PLUGIN_INSTALL_DIR "${CMAKE_INSTALL_PREFIX}/${LIB_INSTALL_DIR}"
#endif
\ No newline at end of file
/*
* Copyright (C) 2015 Daniel Vrátil <dvratil@redhat.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include "grantleeki18nlocalizer_p.h"
#include "grantleetheme_debug.h"
#include <QLocale>
#include <QDate>
#include <grantlee/safestring.h>
#include <KLocalizedString>
GrantleeKi18nLocalizer::GrantleeKi18nLocalizer()
: Grantlee::QtLocalizer()
{
}
GrantleeKi18nLocalizer::~GrantleeKi18nLocalizer()
{
}
QString GrantleeKi18nLocalizer::processArguments(const KLocalizedString &kstr,
const QVariantList &arguments) const
{
KLocalizedString str = kstr;
for (auto iter = arguments.cbegin(), end = arguments.cend(); iter != end; ++iter) {
switch (iter->type()) {
case QVariant::String:
str = str.subs(iter->toString());
break;
case QVariant::Int:
str = str.subs(iter->toInt());
break;
case QVariant::UInt:
str = str.subs(iter->toUInt());
break;
case QVariant::LongLong:
str = str.subs(iter->toLongLong());
break;
case QVariant::ULongLong:
str = str.subs(iter->toULongLong());
break;
case QVariant::Char:
str = str.subs(iter->toChar());
break;
case QVariant::Double:
str = str.subs(iter->toDouble());
break;
case QVariant::UserType:
if (iter->canConvert<Grantlee::SafeString>()) {
str = str.subs(iter->value<Grantlee::SafeString>().get());
break;
}
// fall-through
default:
qCWarning(GRANTLEETHEME_LOG) << "Unknown type" << iter->typeName() << "(" << iter->type() << ")";
break;
}
}
// Return localized in the currenctly active locale