File indexing completed on 2024-11-10 04:56:49
0001 /* 0002 SPDX-FileCopyrightText: 2018 Eike Hein <hein@kde.org> 0003 SPDX-FileCopyrightText: 2018 Vlad Zahorodnii <vlad.zahorodnii@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "virtualdesktops.h" 0009 #include "animationsmodel.h" 0010 #include "desktopsmodel.h" 0011 #include "virtualdesktopsdata.h" 0012 #include "virtualdesktopssettings.h" 0013 0014 #include <KAboutApplicationDialog> 0015 #include <KAboutData> 0016 #include <KConfigGroup> 0017 #include <KLocalizedString> 0018 #include <KPluginFactory> 0019 #include <QDBusConnection> 0020 #include <QDBusMessage> 0021 0022 K_PLUGIN_FACTORY_WITH_JSON(VirtualDesktopsFactory, 0023 "kcm_kwin_virtualdesktops.json", 0024 registerPlugin<KWin::VirtualDesktops>(); 0025 registerPlugin<KWin::VirtualDesktopsData>();) 0026 0027 namespace KWin 0028 { 0029 0030 VirtualDesktops::VirtualDesktops(QObject *parent, const KPluginMetaData &metaData) 0031 : KQuickManagedConfigModule(parent, metaData) 0032 , m_data(new VirtualDesktopsData(this)) 0033 { 0034 qmlRegisterAnonymousType<VirtualDesktopsSettings>("org.kde.kwin.kcm.desktop", 0); 0035 0036 setButtons(Apply | Default | Help); 0037 0038 QObject::connect(m_data->desktopsModel(), &KWin::DesktopsModel::userModifiedChanged, 0039 this, &VirtualDesktops::settingsChanged); 0040 connect(m_data->animationsModel(), &AnimationsModel::animationEnabledChanged, 0041 this, &VirtualDesktops::settingsChanged); 0042 connect(m_data->animationsModel(), &AnimationsModel::animationIndexChanged, 0043 this, &VirtualDesktops::settingsChanged); 0044 } 0045 0046 VirtualDesktops::~VirtualDesktops() 0047 { 0048 } 0049 0050 QAbstractItemModel *VirtualDesktops::desktopsModel() const 0051 { 0052 return m_data->desktopsModel(); 0053 } 0054 0055 QAbstractItemModel *VirtualDesktops::animationsModel() const 0056 { 0057 return m_data->animationsModel(); 0058 } 0059 0060 VirtualDesktopsSettings *VirtualDesktops::virtualDesktopsSettings() const 0061 { 0062 return m_data->settings(); 0063 } 0064 0065 void VirtualDesktops::load() 0066 { 0067 KQuickManagedConfigModule::load(); 0068 0069 m_data->desktopsModel()->load(); 0070 m_data->animationsModel()->load(); 0071 } 0072 0073 void VirtualDesktops::save() 0074 { 0075 KQuickManagedConfigModule::save(); 0076 0077 m_data->desktopsModel()->syncWithServer(); 0078 m_data->animationsModel()->save(); 0079 0080 QDBusMessage message = QDBusMessage::createSignal(QStringLiteral("/KWin"), 0081 QStringLiteral("org.kde.KWin"), QStringLiteral("reloadConfig")); 0082 QDBusConnection::sessionBus().send(message); 0083 } 0084 0085 void VirtualDesktops::defaults() 0086 { 0087 KQuickManagedConfigModule::defaults(); 0088 0089 m_data->desktopsModel()->defaults(); 0090 m_data->animationsModel()->defaults(); 0091 } 0092 0093 bool VirtualDesktops::isDefaults() const 0094 { 0095 return m_data->isDefaults(); 0096 } 0097 0098 void VirtualDesktops::configureAnimation() 0099 { 0100 const QModelIndex index = m_data->animationsModel()->index(m_data->animationsModel()->animationIndex(), 0); 0101 if (!index.isValid()) { 0102 return; 0103 } 0104 0105 m_data->animationsModel()->requestConfigure(index, nullptr); 0106 } 0107 0108 void VirtualDesktops::showAboutAnimation() 0109 { 0110 const QModelIndex index = m_data->animationsModel()->index(m_data->animationsModel()->animationIndex(), 0); 0111 if (!index.isValid()) { 0112 return; 0113 } 0114 0115 const QString name = index.data(AnimationsModel::NameRole).toString(); 0116 const QString comment = index.data(AnimationsModel::DescriptionRole).toString(); 0117 const QString author = index.data(AnimationsModel::AuthorNameRole).toString(); 0118 const QString email = index.data(AnimationsModel::AuthorEmailRole).toString(); 0119 const QString website = index.data(AnimationsModel::WebsiteRole).toString(); 0120 const QString version = index.data(AnimationsModel::VersionRole).toString(); 0121 const QString license = index.data(AnimationsModel::LicenseRole).toString(); 0122 const QString icon = index.data(AnimationsModel::IconNameRole).toString(); 0123 0124 const KAboutLicense::LicenseKey licenseType = KAboutLicense::byKeyword(license).key(); 0125 0126 KAboutData aboutData( 0127 name, // Plugin name 0128 name, // Display name 0129 version, // Version 0130 comment, // Short description 0131 licenseType, // License 0132 QString(), // Copyright statement 0133 QString(), // Other text 0134 website.toLatin1() // Home page 0135 ); 0136 aboutData.setProgramLogo(icon); 0137 0138 const QStringList authors = author.split(','); 0139 const QStringList emails = email.split(','); 0140 0141 if (authors.count() == emails.count()) { 0142 int i = 0; 0143 for (const QString &author : authors) { 0144 if (!author.isEmpty()) { 0145 aboutData.addAuthor(i18n(author.toUtf8()), QString(), emails[i]); 0146 } 0147 i++; 0148 } 0149 } 0150 0151 QPointer<KAboutApplicationDialog> aboutPlugin = new KAboutApplicationDialog(aboutData); 0152 aboutPlugin->exec(); 0153 0154 delete aboutPlugin; 0155 } 0156 0157 bool VirtualDesktops::isSaveNeeded() const 0158 { 0159 return m_data->animationsModel()->needsSave() || m_data->desktopsModel()->needsSave(); 0160 } 0161 0162 } 0163 0164 #include "moc_virtualdesktops.cpp" 0165 #include "virtualdesktops.moc"