Commit e311a7a8 authored by Martin Klapetek's avatar Martin Klapetek
Browse files

Add declarative plugin

For now it contains just the model of holiday regions
which will be used in the Plasma calendar events
configuration.

REVIEW: 125965
parent 88053e89
......@@ -29,7 +29,7 @@ ecm_setup_version(${KHOLIDAYS_LIB_VERSION} VARIABLE_PREFIX KHOLIDAYS
########### Find packages ###########
set(REQUIRED_QT_VERSION 5.4.0)
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core)
find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core Qml)
remove_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII)
......
......@@ -74,3 +74,5 @@ install(FILES
ecm_generate_pri_file(BASE_NAME KHolidays LIB_NAME KF5KHolidays DEPS "widgets" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR ${KDE_INSTALL_INCLUDEDIR_KF5}/KHolidays)
install(FILES ${PRI_FILENAME} DESTINATION ${ECM_MKSPECS_INSTALL_DIR})
add_subdirectory(declarative)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/..)
add_library(kholidaysdeclarativeplugin SHARED kholidaysdeclarativeplugin.cpp
holidayregionsmodel.cpp)
target_link_libraries(kholidaysdeclarativeplugin Qt5::Qml
Qt5::Core
KF5Holidays
)
install(TARGETS kholidaysdeclarativeplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kholidays)
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/kholidays)
/*
This file is part of the kholidays library.
Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "holidayregionsmodel.h"
#include "../holidayregion.h"
class HolidayRegionsDeclarativeModel::Private
{
public:
QStringList regionCodes;
};
HolidayRegionsDeclarativeModel::HolidayRegionsDeclarativeModel(QObject *parent)
: QAbstractListModel(parent),
d(new Private())
{
d->regionCodes = KHolidays::HolidayRegion::regionCodes();
// Make sure we don't add the same regions twice
// This can happen if two copies of the data exists
// in the system and both are read by KHolidays
d->regionCodes.removeDuplicates();
}
HolidayRegionsDeclarativeModel::~HolidayRegionsDeclarativeModel()
{
delete d;
}
int HolidayRegionsDeclarativeModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)
return d->regionCodes.size();
}
QVariant HolidayRegionsDeclarativeModel::data(const QModelIndex &index, int role) const
{
if (!index.isValid()) {
return QVariant();
}
const QString regionCode = d->regionCodes.at(index.row());
switch (role) {
case HolidayRegionsDeclarativeModel::RegionRole:
return regionCode;
case HolidayRegionsDeclarativeModel::NameRole:
return KHolidays::HolidayRegion::name(regionCode);
case HolidayRegionsDeclarativeModel::DescriptionRole:
return KHolidays::HolidayRegion::description(regionCode);
}
return QVariant();
}
QHash<int, QByteArray> HolidayRegionsDeclarativeModel::roleNames() const
{
QHash<int, QByteArray> roles;
roles.insert(HolidayRegionsDeclarativeModel::RegionRole, "region");
roles.insert(HolidayRegionsDeclarativeModel::NameRole, "name");
roles.insert(HolidayRegionsDeclarativeModel::DescriptionRole, "description");
return roles;
}
/*
This file is part of the kholidays library.
Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef HOLIDAYREGIONSDECLARATIVEMODEL_H
#define HOLIDAYREGIONSDECLARATIVEMODEL_H
#include <QObject>
#include <QAbstractListModel>
class HolidayRegionsDeclarativeModel : public QAbstractListModel
{
Q_OBJECT
public:
enum Roles {
RegionRole = Qt::UserRole + 1,
NameRole,
DescriptionRole
};
HolidayRegionsDeclarativeModel(QObject *parent = 0);
virtual ~HolidayRegionsDeclarativeModel();
int rowCount(const QModelIndex &parent = QModelIndex()) const Q_DECL_OVERRIDE;
QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
private:
class Private;
Private * const d;
};
#endif
/*
This file is part of the kholidays library.
Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include "kholidaysdeclarativeplugin.h"
#include "holidayregionsmodel.h"
#include <qqml.h>
void KHolidaysDeclarativePlugin::registerTypes(const char* uri)
{
qmlRegisterType<HolidayRegionsDeclarativeModel>(uri, 1, 0, "HolidayRegionsModel");
}
/*
This file is part of the kholidays library.
Copyright (c) 2015 Martin Klapetek <mklapetek@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 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 Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef KHOLIDAYSDECLARATIVEPLUGIN_H
#define KHOLIDAYSDECLARATIVEPLUGIN_H
#include <QQmlExtensionPlugin>
class KHolidaysDeclarativePlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
public:
virtual void registerTypes(const char* uri);
};
#endif // KHOLIDAYSDECLARATIVEPLUGIN_H
module org.kde.kholidays
plugin kholidaysdeclarativeplugin
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment