File indexing completed on 2024-05-12 05:46:31
0001 /* 0002 * Copyright (C) 2012, 2013, 2014, 2015 Ivan Cukic <ivan.cukic(at)kde.org> 0003 * 0004 * This program is free software; you can redistribute it and/or modify 0005 * it under the terms of the GNU General Public License version 2, 0006 * or (at your option) any later version, as published by the Free 0007 * Software Foundation 0008 * 0009 * This program is distributed in the hope that it will be useful, 0010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 * GNU General Public License for more details 0013 * 0014 * You should have received a copy of the GNU General Public 0015 * License along with this program; if not, write to the 0016 * Free Software Foundation, Inc., 0017 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0018 */ 0019 0020 // Self 0021 #include "activityinfo.h" 0022 0023 namespace KActivities { 0024 namespace Imports { 0025 0026 ActivityInfo::ActivityInfo(QObject *parent) 0027 : QObject(parent) 0028 , m_showCurrentActivity(false) 0029 { 0030 connect(&m_service, &KActivities::Controller::currentActivityChanged, 0031 this, &ActivityInfo::setCurrentActivity); 0032 } 0033 0034 ActivityInfo::~ActivityInfo() 0035 { 0036 } 0037 0038 void ActivityInfo::setCurrentActivity(const QString &id) 0039 { 0040 if (!m_showCurrentActivity) return; 0041 0042 setIdInternal(id); 0043 0044 emit nameChanged(m_info->name()); 0045 emit descriptionChanged(m_info->description()); 0046 emit iconChanged(m_info->icon()); 0047 } 0048 0049 void ActivityInfo::setActivityId(const QString &id) 0050 { 0051 m_showCurrentActivity = (id == QLatin1String(":current")); 0052 0053 setIdInternal(m_showCurrentActivity ? 0054 m_service.currentActivity() : id); 0055 } 0056 0057 void ActivityInfo::setIdInternal(const QString &id) 0058 { 0059 using namespace KActivities; 0060 0061 // We are killing the old info object, if any 0062 m_info.reset(new KActivities::Info(id)); 0063 0064 auto ptr = m_info.get(); 0065 0066 connect(ptr, &Info::nameChanged, 0067 this, &ActivityInfo::nameChanged); 0068 connect(ptr, &Info::descriptionChanged, 0069 this, &ActivityInfo::descriptionChanged); 0070 connect(ptr, &Info::iconChanged, 0071 this, &ActivityInfo::iconChanged); 0072 } 0073 0074 #define CREATE_GETTER_AND_SETTER(WHAT, What) \ 0075 QString ActivityInfo::What() const \ 0076 { \ 0077 return m_info ? m_info->What() : QString(); \ 0078 } \ 0079 \ 0080 void ActivityInfo::set##WHAT(const QString &value) \ 0081 { \ 0082 if (!m_info) \ 0083 return; \ 0084 \ 0085 m_service.setActivity##WHAT(m_info->id(), value); \ 0086 } 0087 0088 CREATE_GETTER_AND_SETTER(Name, name) 0089 CREATE_GETTER_AND_SETTER(Description, description) 0090 CREATE_GETTER_AND_SETTER(Icon, icon) 0091 0092 #undef CREATE_GETTER_AND_SETTER 0093 0094 QString ActivityInfo::activityId() const 0095 { 0096 return m_info ? m_info->id() : QString(); 0097 } 0098 0099 bool ActivityInfo::valid() const 0100 { 0101 return true; 0102 } 0103 0104 0105 } // namespace Imports 0106 } // namespace KActivities 0107 0108 // #include "activityinfo.moc" 0109