mirror of
https://invent.kde.org/marcoa/shift-shell.git
synced 2026-04-29 15:03:09 +00:00
[dialer] Add KPeople helper plugin
There's no way to access the phone number from PersonsModel directly, so we need to go a bit around
This commit is contained in:
parent
2353652336
commit
5ebcfd904d
8 changed files with 205 additions and 1 deletions
|
|
@ -25,7 +25,7 @@ include(FeatureSummary)
|
|||
|
||||
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED Core Gui Widgets Qml Quick Test)
|
||||
|
||||
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Plasma Service Declarative I18n KIO)
|
||||
find_package(KF5 ${KF5_MIN_VERSION} REQUIRED COMPONENTS Plasma Service Declarative I18n KIO People)
|
||||
find_package(KF5 REQUIRED COMPONENTS PlasmaQuick DBusAddons Notifications)
|
||||
find_package(TelepathyQt5 REQUIRED)
|
||||
find_package(KF5Wayland CONFIG)
|
||||
|
|
|
|||
|
|
@ -5,3 +5,4 @@ install(FILES package/metadata.desktop DESTINATION ${XDG_APPS_INSTALL_DIR} RENAM
|
|||
include_directories(${TELEPATHY_QT5_INCLUDE_DIR})
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(plugin)
|
||||
|
|
|
|||
14
dialer/plugin/CMakeLists.txt
Normal file
14
dialer/plugin/CMakeLists.txt
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
set(kpeoplehelper_SRCS
|
||||
kpeoplehelper.cpp
|
||||
kpeoplehelperplugin.cpp
|
||||
)
|
||||
|
||||
add_library(kpeoplehelperplugin SHARED ${kpeoplehelper_SRCS})
|
||||
target_link_libraries(kpeoplehelperplugin Qt5::Core
|
||||
Qt5::Qml
|
||||
KF5::People
|
||||
KF5::PeopleBackend)
|
||||
|
||||
install(TARGETS kpeoplehelperplugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/kpeoplehelper)
|
||||
|
||||
install(FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/private/kpeoplehelper)
|
||||
60
dialer/plugin/kpeoplehelper.cpp
Normal file
60
dialer/plugin/kpeoplehelper.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
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 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 "kpeoplehelper.h"
|
||||
|
||||
#include <KPeople/PersonsModel>
|
||||
#include <KPeopleBackend/AbstractContact>
|
||||
|
||||
#include <QAbstractItemModel>
|
||||
#include <QDebug>
|
||||
|
||||
KPeopleHelper::KPeopleHelper(QObject *parent)
|
||||
: QIdentityProxyModel(parent)
|
||||
{
|
||||
m_model = new KPeople::PersonsModel(this);
|
||||
setSourceModel(m_model);
|
||||
}
|
||||
|
||||
KPeopleHelper::~KPeopleHelper()
|
||||
{
|
||||
delete m_model;
|
||||
}
|
||||
|
||||
QVariant KPeopleHelper::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
if (!m_model) {
|
||||
return QVariant();
|
||||
}
|
||||
|
||||
if (role == KPeopleHelper::PhoneNumberRole) {
|
||||
return m_model->contactCustomProperty(index, KPeople::AbstractContact::PhoneNumberProperty);
|
||||
}
|
||||
|
||||
return m_model->data(index, role);
|
||||
}
|
||||
|
||||
QHash<int, QByteArray> KPeopleHelper::roleNames() const
|
||||
{
|
||||
QHash<int, QByteArray> roles = QAbstractItemModel::roleNames();
|
||||
roles.insert(PersonUriRole, "personUri");
|
||||
roles.insert(PersonVCardRole, "personVCard");
|
||||
roles.insert(ContactsVCardRole, "contactsVCard");
|
||||
roles.insert(PhoneNumberRole, "phoneNumber");
|
||||
return roles;
|
||||
}
|
||||
60
dialer/plugin/kpeoplehelper.h
Normal file
60
dialer/plugin/kpeoplehelper.h
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
/*
|
||||
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 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 KPEOPLEHELPER_H
|
||||
#define KPEOPLEHELPER_H
|
||||
|
||||
#include <QObject>
|
||||
#include <QIdentityProxyModel>
|
||||
|
||||
namespace KPeople {
|
||||
class PersonsModel;
|
||||
}
|
||||
|
||||
class QAbstractItemModel;
|
||||
|
||||
class KPeopleHelper : public QIdentityProxyModel
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
enum Role {
|
||||
FormattedNameRole = Qt::DisplayRole,//QString best name for this person
|
||||
PhotoRole = Qt::DecorationRole, //QPixmap best photo for this person
|
||||
PersonUriRole = Qt::UserRole, //QString ID of this person
|
||||
PersonVCardRole, //AbstractContact::Ptr
|
||||
ContactsVCardRole, //AbstractContact::List (FIXME or map?)
|
||||
|
||||
GroupsRole, ///groups QStringList
|
||||
PhoneNumberRole, //QString
|
||||
|
||||
UserRole = Qt::UserRole + 0x1000 ///< in case it's needed to extend, use this one to start from
|
||||
};
|
||||
Q_ENUMS(Role)
|
||||
|
||||
KPeopleHelper(QObject *parent = 0);
|
||||
~KPeopleHelper();
|
||||
|
||||
virtual QVariant data(const QModelIndex &index, int role) const Q_DECL_OVERRIDE;
|
||||
virtual QHash<int, QByteArray> roleNames() const Q_DECL_OVERRIDE;
|
||||
|
||||
private:
|
||||
KPeople::PersonsModel *m_model;
|
||||
};
|
||||
|
||||
#endif // KPEOPLEHELPER_H
|
||||
31
dialer/plugin/kpeoplehelperplugin.cpp
Normal file
31
dialer/plugin/kpeoplehelperplugin.cpp
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
/*
|
||||
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 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 "kpeoplehelperplugin.h"
|
||||
#include "kpeoplehelper.h"
|
||||
|
||||
#include <QtQml>
|
||||
|
||||
void KPeopleHelperPlugin::registerTypes(const char *uri)
|
||||
{
|
||||
Q_ASSERT(uri == QLatin1String("org.kde.plasma.private.kpeoplehelper"));
|
||||
|
||||
qmlRegisterType<KPeopleHelper>(uri, 1, 0, "KPeopleHelper");
|
||||
}
|
||||
|
||||
#include "kpeoplehelperplugin.moc"
|
||||
36
dialer/plugin/kpeoplehelperplugin.h
Normal file
36
dialer/plugin/kpeoplehelperplugin.h
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
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 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 KPEOPLEHELPERPLUGIN_H
|
||||
#define KPEOPLEHELPERPLUGIN_H
|
||||
|
||||
#include <QQmlExtensionPlugin>
|
||||
|
||||
class QQmlEngine;
|
||||
class KPeopleHelperPlugin : public QQmlExtensionPlugin
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface")
|
||||
|
||||
public:
|
||||
void registerTypes(const char *uri);
|
||||
|
||||
};
|
||||
|
||||
#endif // KPEOPLEHELPERPLUGIN_H
|
||||
2
dialer/plugin/qmldir
Normal file
2
dialer/plugin/qmldir
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
module org.kde.plasma.private.kpeoplehelper
|
||||
plugin kpeoplehelperplugin
|
||||
Loading…
Reference in a new issue