Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 22 additions & 17 deletions src/greeter/sessionmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@

#include "sessionmodel.h"

#include <Configuration.h>
#include <Config.h>

Check warning on line 23 in src/greeter/sessionmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <Config.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QFileInfo>

Check warning on line 25 in src/greeter/sessionmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileInfo> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QFileSystemWatcher>

Check warning on line 26 in src/greeter/sessionmodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QFileSystemWatcher> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QProcessEnvironment>
#include <QVector>

Expand All @@ -47,31 +47,36 @@
: QAbstractListModel(parent)
, d(new SessionModelPrivate())
{
QStringList x11SessionDir = mainConfig.get<QStringList>("X11", "SessionDir");
QStringList waylandSessionDir = mainConfig.get<QStringList>("Wayland", "SessionDir");

// Check for flag to show Wayland sessions
bool dri_active = QFileInfo::exists(QStringLiteral("/dev/dri"));

// initial population
beginResetModel();
if (dri_active)
populate(Session::WaylandSession, mainConfig.Wayland.SessionDir.get());
populate(Session::X11Session, mainConfig.X11.SessionDir.get());
populate(Session::WaylandSession, waylandSessionDir);
populate(Session::X11Session, x11SessionDir);
endResetModel();

// refresh everytime a file is changed, added or removed
QFileSystemWatcher *watcher = new QFileSystemWatcher(this);
connect(watcher, &QFileSystemWatcher::directoryChanged, [this]() {
// Recheck for flag to show Wayland sessions
bool dri_active = QFileInfo::exists(QStringLiteral("/dev/dri"));
beginResetModel();
d->sessions.clear();
d->displayNames.clear();
if (dri_active)
populate(Session::WaylandSession, mainConfig.Wayland.SessionDir.get());
populate(Session::X11Session, mainConfig.X11.SessionDir.get());
endResetModel();
});
watcher->addPaths(mainConfig.Wayland.SessionDir.get());
watcher->addPaths(mainConfig.X11.SessionDir.get());
connect(watcher,
&QFileSystemWatcher::directoryChanged,
[this, x11SessionDir, waylandSessionDir]() {
// Recheck for flag to show Wayland sessions
bool dri_active = QFileInfo::exists(QStringLiteral("/dev/dri"));
beginResetModel();
d->sessions.clear();
d->displayNames.clear();
if (dri_active)
populate(Session::WaylandSession, waylandSessionDir);
populate(Session::X11Session, x11SessionDir);
endResetModel();
});
watcher->addPaths(waylandSessionDir);
watcher->addPaths(x11SessionDir);
}

SessionModel::~SessionModel()
Expand Down Expand Up @@ -184,7 +189,7 @@
}
// find out index of the last session
for (int i = 0; i < d->sessions.size(); ++i) {
if (d->sessions.at(i)->fileName() == stateConfig.Last.Session.get()) {
if (d->sessions.at(i)->fileName() == stateConfig.get<QString>("Last", "Session")) {
d->lastIndex = i;
break;
}
Expand Down
6 changes: 3 additions & 3 deletions src/greeter/usermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@

#include "usermodel.h"

#include "common/treelandlogging.h"

Check warning on line 22 in src/greeter/usermodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: "common/treelandlogging.h" not found.

#include <Configuration.h>
#include <Config.h>

Check warning on line 24 in src/greeter/usermodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <Config.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <DDBusInterface>

Check warning on line 26 in src/greeter/usermodel.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DDBusInterface> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <QFile>
#include <QGuiApplication>
Expand Down Expand Up @@ -109,7 +109,7 @@
});

// find out index of the last user
auto lastUserName = stateConfig.Last.User.get();
auto lastUserName = lastUser();

for (const auto &user : d->users) {
if (user->userName() == lastUserName) {
Expand Down Expand Up @@ -153,7 +153,7 @@

QString UserModel::lastUser()
{
return stateConfig.Last.User.get();
return stateConfig.get<QString>("Last", "User");
}

int UserModel::rowCount(const QModelIndex &parent) const
Expand Down
Loading