diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 55b56d9..8e16b05 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,61 +1,63 @@ set(SDDM_CONFIG_FILE "${CMAKE_INSTALL_FULL_SYSCONFDIR}/sddm.conf" CACHE PATH "Path of the sddm config file") set(SDDM_CONFIG_DIR "${CMAKE_INSTALL_FULL_SYSCONFDIR}/sddm.conf.d" CACHE PATH "Path of the sddm config directory") set(SDDM_SYSTEM_CONFIG_DIR "${CMAKE_INSTALL_PREFIX}/lib/sddm/sddm.conf.d" CACHE PATH "Path of the system sddm config directory") +set(XSESSIONS_DIR "${CMAKE_INSTALL_PREFIX}/share/xsessions" CACHE PATH "Path of the xsessions") +set(WAYLAND_SESSIONS_DIR "${CMAKE_INSTALL_PREFIX}/share/wayland-sessions" CACHE PATH "Path of the wayland sessions") configure_file(config.h.in config.h IMMEDIATE @ONLY) # add_subdirectory(configwidgets) include_directories(configwidgets) set(SDDM_KCM_SRCS sddmkcm.cpp themeconfig.cpp themesmodel.cpp thememetadata.cpp themesdelegate.cpp advanceconfig.cpp usersmodel.cpp sessionmodel.cpp cursortheme/thememodel.cpp cursortheme/xcursortheme.cpp cursortheme/cursortheme.cpp cursortheme/sortproxymodel.cpp cursortheme/dummytheme.cpp configwidgets/selectimagebutton.cpp ) set(SDDM_KCM_UI ui/themeconfig.ui ui/advanceconfig.ui) ki18n_wrap_ui(SDDM_KCM_SRCS ${SDDM_KCM_UI}) add_library(kcm_sddm MODULE ${SDDM_KCM_SRCS}) target_compile_definitions(kcm_sddm PRIVATE -DPROJECT_VERSION="${PROJECT_VERSION}") target_link_libraries(kcm_sddm Qt5::Widgets Qt5::X11Extras Qt5::Quick Qt5::QuickWidgets KF5::I18n KF5::ConfigWidgets KF5::Auth KF5::KIOWidgets KF5::NewStuff ${X11_LIBRARIES} XCB::XCB # For mouse cursor themes ) if (X11_Xcursor_FOUND) target_link_libraries(kcm_sddm ${X11_Xcursor_LIB}) endif (X11_Xcursor_FOUND) if (X11_Xfixes_FOUND) target_link_libraries(kcm_sddm ${X11_Xfixes_LIB}) endif (X11_Xfixes_FOUND) install(TARGETS kcm_sddm DESTINATION ${CMAKE_INSTALL_PLUGINDIR}) install(FILES qml/main.qml DESTINATION ${CMAKE_INSTALL_DATADIR}/sddm-kcm) diff --git a/src/config.h.in b/src/config.h.in index 80309ce..6180bd1 100644 --- a/src/config.h.in +++ b/src/config.h.in @@ -1,8 +1,10 @@ #ifndef CONFIG_H #define CONFIG_H #define SDDM_CONFIG_FILE "@SDDM_CONFIG_FILE@" #define SDDM_CONFIG_DIR "@SDDM_CONFIG_DIR@" #define SDDM_SYSTEM_CONFIG_DIR "@SDDM_SYSTEM_CONFIG_DIR@" +#define XSESSIONS_DIR "@XSESSIONS_DIR@" +#define WAYLAND_SESSIONS_DIR "@WAYLAND_SESSIONS_DIR@" #endif //CONFIG_H diff --git a/src/sessionmodel.cpp b/src/sessionmodel.cpp index ff63dbd..2c14304 100644 --- a/src/sessionmodel.cpp +++ b/src/sessionmodel.cpp @@ -1,155 +1,156 @@ /*************************************************************************** * Copyright (c) 2013 Abdurrahman AVCI * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the * Free Software Foundation, Inc., * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. ***************************************************************************/ +#include "config.h" #include "sessionmodel.h" #include #include #include #include #include #include class Session { public: QString file; QString name; QString exec; QString comment; }; typedef std::shared_ptr SessionPtr; class SessionModelPrivate { public: int lastIndex { 0 }; QList sessions; }; SessionModel::SessionModel(QObject *parent) : QAbstractListModel(parent), d(new SessionModelPrivate()) { - loadDir(QStringLiteral("/usr/share/xsessions"), SessionTypeX); - loadDir(QStringLiteral("/usr/share/wayland-sessions"), SessionTypeWayland); + loadDir(QStringLiteral(XSESSIONS_DIR), SessionTypeX); + loadDir(QStringLiteral(WAYLAND_SESSIONS_DIR), SessionTypeWayland); } SessionModel::~SessionModel() { delete d; } void SessionModel::loadDir(const QString &path, SessionType type) { QDir dir(path); dir.setNameFilters(QStringList() << QLatin1String("*.desktop")); dir.setFilter(QDir::Files); // read session foreach(const QString &session, dir.entryList()) { QFile inputFile(dir.absoluteFilePath(session)); if (!inputFile.open(QIODevice::ReadOnly)) continue; SessionPtr si { new Session { session, QString(), QString(), QString() } }; bool isHidden = false; QString current_section; QTextStream in(&inputFile); while (!in.atEnd()) { QString line = in.readLine(); if (line.startsWith(QLatin1String("["))) { // The section name ends before the last ] before the start of a comment int end = line.lastIndexOf(QLatin1Char(']'), line.indexOf(QLatin1Char('#'))); if (end != -1) current_section = line.mid(1, end - 1); } if (current_section != QLatin1String("Desktop Entry")) continue; // We are only interested in the "Desktop Entry" section if (line.startsWith(QLatin1String("Name="))) { si->name = line.mid(5); if (type == SessionTypeWayland) { //we want to exactly match the SDDM prompt which is formatted in this way si->name = i18nc("%1 is the name of a session", "%1 (Wayland)", si->name); } } if (line.startsWith(QLatin1String("Exec="))) si->exec = line.mid(5); if (line.startsWith(QLatin1String("Comment="))) si->comment = line.mid(8); if (line.startsWith(QLatin1String("Hidden="))) isHidden = line.mid(7).toLower() == QLatin1String("true"); } if (!isHidden) { // add to sessions list d->sessions.push_back(si); } // close file inputFile.close(); } } QHash SessionModel::roleNames() const { // set role names QHash roleNames; roleNames[FileRole] = "file"; roleNames[NameRole] = "name"; roleNames[ExecRole] = "exec"; roleNames[CommentRole] = "comment"; return roleNames; } int SessionModel::rowCount(const QModelIndex &parent) const { Q_UNUSED(parent); return d->sessions.length(); } QVariant SessionModel::data(const QModelIndex &index, int role) const { if (index.row() < 0 || index.row() >= d->sessions.count()) return QVariant(); // get session SessionPtr session = d->sessions[index.row()]; // return correct value if (role == FileRole) return session->file; else if (role == NameRole) return session->name; else if (role == ExecRole) return session->exec; else if (role == CommentRole) return session->comment; // return empty value return QVariant(); } int SessionModel::indexOf(const QString &sessionId) const { for (int i = 0; i < d->sessions.length(); i++) { if (d->sessions[i]->file == sessionId) { return i; } } return 0; }