File indexing completed on 2022-11-29 13:02:26

0001 /*
0002     SPDX-FileCopyrightText: 2012, 2013, 2014, 2015 Ivan Cukic <ivan.cukic(at)kde.org>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 // Self
0008 #include "activityinfo.h"
0009 
0010 namespace KActivities
0011 {
0012 namespace Imports
0013 {
0014 ActivityInfo::ActivityInfo(QObject *parent)
0015     : QObject(parent)
0016     , m_showCurrentActivity(false)
0017 {
0018     connect(&m_service, &KActivities::Controller::currentActivityChanged, this, &ActivityInfo::setCurrentActivity);
0019 }
0020 
0021 ActivityInfo::~ActivityInfo()
0022 {
0023 }
0024 
0025 void ActivityInfo::setCurrentActivity(const QString &id)
0026 {
0027     if (!m_showCurrentActivity) {
0028         return;
0029     }
0030 
0031     setIdInternal(id);
0032 
0033     Q_EMIT nameChanged(m_info->name());
0034     Q_EMIT descriptionChanged(m_info->description());
0035     Q_EMIT iconChanged(m_info->icon());
0036 }
0037 
0038 void ActivityInfo::setActivityId(const QString &id)
0039 {
0040     m_showCurrentActivity = (id == QLatin1String(":current"));
0041 
0042     setIdInternal(m_showCurrentActivity ? m_service.currentActivity() : id);
0043 }
0044 
0045 void ActivityInfo::setIdInternal(const QString &id)
0046 {
0047     using namespace KActivities;
0048 
0049     // We are killing the old info object, if any
0050     m_info.reset(new KActivities::Info(id));
0051 
0052     auto ptr = m_info.get();
0053 
0054     connect(ptr, &Info::nameChanged, this, &ActivityInfo::nameChanged);
0055     connect(ptr, &Info::descriptionChanged, this, &ActivityInfo::descriptionChanged);
0056     connect(ptr, &Info::iconChanged, this, &ActivityInfo::iconChanged);
0057 }
0058 // clang-format off
0059 #define CREATE_GETTER_AND_SETTER(WHAT, What)                                   \
0060     QString ActivityInfo::What() const                                         \
0061     {                                                                          \
0062         return m_info ? m_info->What() : QString();                            \
0063     }                                                                          \
0064                                                                                \
0065     void ActivityInfo::set##WHAT(const QString &value)                         \
0066     {                                                                          \
0067         if (!m_info)                                                           \
0068             return;                                                            \
0069                                                                                \
0070         m_service.setActivity##WHAT(m_info->id(), value);                      \
0071     }
0072 // clang-format on
0073 
0074 CREATE_GETTER_AND_SETTER(Name, name)
0075 CREATE_GETTER_AND_SETTER(Description, description)
0076 CREATE_GETTER_AND_SETTER(Icon, icon)
0077 
0078 #undef CREATE_GETTER_AND_SETTER
0079 
0080 QString ActivityInfo::activityId() const
0081 {
0082     return m_info ? m_info->id() : QString();
0083 }
0084 
0085 bool ActivityInfo::valid() const
0086 {
0087     return true;
0088 }
0089 
0090 } // namespace Imports
0091 } // namespace KActivities
0092 
0093 // #include "activityinfo.moc"