File indexing completed on 2024-05-12 05:36:58
0001 /* 0002 * SPDX-FileCopyrightText: 2021 Felipe Kinoshita <kinofhek@gmail.com> 0003 * SPDX-FileCopyrightText: 2022 Nate Graham <nate@kde.org> 0004 * 0005 * SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL 0006 */ 0007 0008 #include <QDir> 0009 #include <QFileInfo> 0010 #include <QNetworkInterface> 0011 #include <QStandardPaths> 0012 #include <QString> 0013 0014 #include "config-plasma-welcome.h" 0015 #include "controller.h" 0016 #include "plasma-welcome-version.h" 0017 0018 #include <KDesktopFile> 0019 #include <KIO/ApplicationLauncherJob> 0020 #include <KIO/CommandLauncherJob> 0021 #include <KLocalizedString> 0022 #include <KNotificationJobUiDelegate> 0023 #include <KOSRelease> 0024 #include <KPluginMetaData> 0025 #include <KService> 0026 0027 Controller::Controller() 0028 { 0029 m_mode = Mode::Welcome; 0030 0031 // Version 0032 m_version = QVersionNumber::fromString(QString::fromLatin1(PLASMA_WELCOME_VERSION_STRING)); 0033 m_patchVersion = m_version.microVersion(); 0034 0035 // Release URL 0036 if constexpr (PLASMA_WELCOME_VERSION_PATCH >= 90) { 0037 // Beta version 0038 m_releaseUrl = QStringLiteral("https://kde.org/announcements/plasma/%1/%1.%2.90/?source=plasma-welcome") 0039 .arg(QString::number(m_version.majorVersion()), QString::number(m_version.minorVersion())); 0040 } else if constexpr (PLASMA_WELCOME_VERSION_PATCH >= 80) { 0041 // Development version 0042 m_releaseUrl = QStringLiteral("https://invent.kde.org/groups/plasma/-/activity"); 0043 } else { 0044 // Release version 0045 m_releaseUrl = QStringLiteral("https://kde.org/announcements/plasma/%1/%1.%2.0/?source=plasma-welcome") 0046 .arg(QString::number(m_version.majorVersion()), QString::number(m_version.minorVersion())); 0047 } 0048 0049 // Shown version string, matching desktop preview banner 0050 if constexpr (PLASMA_WELCOME_VERSION_MAJOR == 5 && PLASMA_WELCOME_VERSION_MINOR >= 80) { 0051 // Overrides for Plasma 6.0 pre-release 0052 if constexpr (PLASMA_WELCOME_VERSION_PATCH == 80) { 0053 // Development 0054 m_shownVersion = i18n("6.0 Dev"); 0055 } else if constexpr (PLASMA_WELCOME_VERSION_MINOR == 80) { 0056 // Alpha, 5.80.0 0057 m_shownVersion = i18n("6.0 Alpha"); 0058 } else if constexpr (PLASMA_WELCOME_VERSION_MINOR == 90) { 0059 // Beta 1, 5.90.0 0060 m_shownVersion = i18n("6.0 Beta 1"); 0061 } else if constexpr (PLASMA_WELCOME_VERSION_MINOR == 91) { 0062 // Beta 2, 5.91.0 0063 m_shownVersion = i18n("6.0 Beta 2"); 0064 } else if constexpr (PLASMA_WELCOME_VERSION_MINOR == 92) { 0065 // RC1, 5.92.0 0066 m_shownVersion = i18nc("@label RC meaning Release Candidate", "6.0 RC1"); 0067 } else if constexpr (PLASMA_WELCOME_VERSION_MINOR == 93) { 0068 // RC2, 5.93.0 0069 m_shownVersion = i18nc("@label RC meaning Release Candidate", "6.0 RC2"); 0070 } 0071 } else if constexpr (PLASMA_WELCOME_VERSION_PATCH >= 80) { 0072 // Beta or development version 0073 // finalMajor, finalMinor is the final version in the line 0074 // and should be updated after the final Plasma 6 release 0075 constexpr int finalMajor = 5; 0076 constexpr int finalMinor = 27; 0077 0078 // Incremented minor, which is zeroed and major incremented when 0079 // we reach the final version in the major release line 0080 int major = (PLASMA_WELCOME_VERSION_MAJOR == finalMajor && PLASMA_WELCOME_VERSION_MINOR == finalMinor) ? PLASMA_WELCOME_VERSION_MAJOR + 1 0081 : PLASMA_WELCOME_VERSION_MAJOR; 0082 int minor = (PLASMA_WELCOME_VERSION_MAJOR == finalMajor && PLASMA_WELCOME_VERSION_MINOR == finalMinor) ? 0 : PLASMA_WELCOME_VERSION_MINOR + 1; 0083 const QString version = QStringLiteral("%1.%2").arg(QString::number(major), QString::number(minor)); 0084 0085 if constexpr (PLASMA_WELCOME_VERSION_PATCH == 80) { 0086 // Development version 0087 m_shownVersion = i18nc("@label %1 is the Plasma version", "%1 Dev", version); 0088 } else if constexpr (PLASMA_WELCOME_VERSION_PATCH >= 90) { 0089 // Beta version 0090 if constexpr (PLASMA_WELCOME_VERSION_PATCH == 90) { 0091 m_shownVersion = i18nc("@label %1 is the Plasma version", "%1 Beta", version); 0092 } else { 0093 constexpr int betaNumber = PLASMA_WELCOME_VERSION_PATCH - 89; 0094 m_shownVersion = i18nc("@label %1 is the Plasma version, %2 is the beta release number", "%1 Beta %2", version, betaNumber); 0095 } 0096 } 0097 } else { 0098 // Release version 0099 m_shownVersion = QStringLiteral("%1.%2").arg(QString::number(m_version.majorVersion()), QString::number(m_version.minorVersion())); 0100 } 0101 0102 // Welcome page customisation 0103 m_customIntroText = QString(); 0104 m_customIntroIcon = QString(); 0105 m_customIntroIconCaption = QString(); 0106 0107 const QFileInfo introTextFile = QFileInfo(QStringLiteral(DISTRO_CUSTOM_INTRO_FILE)); 0108 if (introTextFile.exists()) { 0109 const KDesktopFile desktopFile(introTextFile.absoluteFilePath()); 0110 m_customIntroText = desktopFile.readName(); 0111 m_customIntroIcon = desktopFile.readIcon(); 0112 m_customIntroIconLink = desktopFile.readUrl(); 0113 m_customIntroIconCaption = desktopFile.readComment(); 0114 } 0115 } 0116 0117 void Controller::launchApp(const QString &program) 0118 { 0119 auto *job = new KIO::ApplicationLauncherJob(KService::serviceByDesktopName(program)); 0120 job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled)); 0121 job->start(); 0122 } 0123 0124 void Controller::runCommand(const QString &command) 0125 { 0126 runCommand(command, QString()); 0127 } 0128 0129 void Controller::runCommand(const QString &command, const QString &desktopFilename) 0130 { 0131 auto *job = new KIO::CommandLauncherJob(command); 0132 if (!desktopFilename.isEmpty()) { 0133 job->setDesktopName(desktopFilename); 0134 } 0135 job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoErrorHandlingEnabled)); 0136 job->start(); 0137 } 0138 0139 bool Controller::networkAlreadyConnected() 0140 { 0141 for (QNetworkInterface interface : QNetworkInterface::allInterfaces()) { 0142 if (interface.addressEntries().count() >= 1) { 0143 const QFlags flags = interface.flags(); 0144 if (flags.testFlag(QNetworkInterface::IsUp) && !flags.testFlag(QNetworkInterface::IsLoopBack)) { 0145 return true; 0146 } 0147 } 0148 } 0149 return false; 0150 } 0151 0152 bool Controller::userFeedbackAvailable() 0153 { 0154 KPluginMetaData data(QStringLiteral("plasma/kcms/systemsettings/kcm_feedback")); 0155 return data.isValid(); 0156 } 0157 0158 QStringList Controller::distroPages() 0159 { 0160 const QString dirname = QStringLiteral(DISTRO_CUSTOM_PAGE_FOLDER); 0161 const QDir distroPagePath = QDir(dirname); 0162 0163 if (!distroPagePath.exists() || distroPagePath.isEmpty()) { 0164 return {}; 0165 } 0166 0167 QStringList pages = distroPagePath.entryList(QDir::NoDotAndDotDot | QDir::Files | QDir::Readable, QDir::Name); 0168 for (int i = 0; i < pages.length(); i++) { 0169 pages[i] = QStringLiteral("file://") + dirname + pages[i]; 0170 } 0171 0172 return pages; 0173 } 0174 0175 QString Controller::installPrefix() 0176 { 0177 return QString::fromLatin1(PLASMA_WELCOME_INSTALL_DIR); 0178 } 0179 0180 QString Controller::distroName() 0181 { 0182 return KOSRelease().name(); 0183 } 0184 0185 QString Controller::distroIcon() 0186 { 0187 return KOSRelease().logo(); 0188 } 0189 0190 QString Controller::distroUrl() 0191 { 0192 return KOSRelease().homeUrl(); 0193 } 0194 0195 void Controller::setMode(Mode mode) 0196 { 0197 if (m_mode == mode) { 0198 return; 0199 } 0200 0201 m_mode = mode; 0202 Q_EMIT modeChanged(); 0203 } 0204 0205 #include "moc_controller.cpp"