Skip to content

Commit 9cda5d8

Browse files
committed
Read session desktop entries with Session and pass it upon login
The greeter knows where the session entry is located (either under the X11 or Wayland sessions path) and so it must pass this information to the daemon. Add a class to represent a session in order to share this information between daemon and greater allowing to know the exact location of the session desktop entry. Since a relative file name can be specified for autologin session, we need to search the desktop entry and create a Session object with the right type. In the long run we might want to deal with absolute desktop entry paths and do not allow relative paths or names without extention. Issue: #419
1 parent 0786621 commit 9cda5d8

File tree

13 files changed

+399
-144
lines changed

13 files changed

+399
-144
lines changed

src/common/Session.cpp

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
/***************************************************************************
2+
* Copyright (c) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
3+
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@gmail.com>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation; either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* This program is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with this program; if not, write to the
17+
* Free Software Foundation, Inc.,
18+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19+
***************************************************************************/
20+
21+
#include <QFile>
22+
#include <QFileInfo>
23+
#include <QTextStream>
24+
25+
#include "Configuration.h"
26+
#include "Session.h"
27+
28+
const QString s_entryExtention = QStringLiteral(".desktop");
29+
30+
namespace SDDM {
31+
Session::Session()
32+
: m_valid(false)
33+
, m_type(UnknownSession)
34+
{
35+
}
36+
37+
Session::Session(Type type, const QString &fileName)
38+
{
39+
setTo(type, fileName);
40+
}
41+
42+
bool Session::isValid() const
43+
{
44+
return m_valid;
45+
}
46+
47+
Session::Type Session::type() const
48+
{
49+
return m_type;
50+
}
51+
52+
QString Session::xdgSessionType() const
53+
{
54+
return m_xdgSessionType;
55+
}
56+
57+
QDir Session::directory() const
58+
{
59+
return m_dir;
60+
}
61+
62+
QString Session::fileName() const
63+
{
64+
return m_fileName;
65+
}
66+
67+
QString Session::displayName() const
68+
{
69+
return m_displayName;
70+
}
71+
72+
QString Session::comment() const
73+
{
74+
return m_comment;
75+
}
76+
77+
QString Session::exec() const
78+
{
79+
return m_exec;
80+
}
81+
82+
QString Session::tryExec() const
83+
{
84+
return m_tryExec;
85+
}
86+
87+
QString Session::desktopSession() const
88+
{
89+
return fileName().replace(s_entryExtention, QStringLiteral(""));
90+
}
91+
92+
QString Session::desktopNames() const
93+
{
94+
return m_desktopNames;
95+
}
96+
97+
void Session::setTo(Type type, const QString &_fileName)
98+
{
99+
QString fileName(_fileName);
100+
if (!fileName.endsWith(s_entryExtention))
101+
fileName += s_entryExtention;
102+
103+
QFileInfo info(fileName);
104+
105+
m_type = UnknownSession;
106+
m_valid = false;
107+
m_desktopNames = QStringLiteral("");
108+
109+
switch (type) {
110+
case X11Session:
111+
m_dir = QDir(mainConfig.XDisplay.SessionDir.get());
112+
m_xdgSessionType = QStringLiteral("x11");
113+
break;
114+
case WaylandSession:
115+
m_dir = QDir(mainConfig.WaylandDisplay.SessionDir.get());
116+
m_xdgSessionType = QStringLiteral("wayland");
117+
break;
118+
default:
119+
m_xdgSessionType = QStringLiteral("");
120+
break;
121+
}
122+
123+
m_fileName = m_dir.absoluteFilePath(fileName);
124+
125+
qDebug() << "Reading from" << m_fileName;
126+
127+
QFile file(m_fileName);
128+
if (!file.open(QIODevice::ReadOnly))
129+
return;
130+
131+
QTextStream in(&file);
132+
while (!in.atEnd()) {
133+
QString line = in.readLine();
134+
135+
if (line.startsWith("Name=")) {
136+
if (type == WaylandSession)
137+
m_displayName = QObject::tr("%1 (Wayland)").arg(line.mid(5));
138+
else
139+
m_displayName = line.mid(5);
140+
}
141+
if (line.startsWith("Comment="))
142+
m_comment = line.mid(8);
143+
if (line.startsWith("Exec="))
144+
m_exec = line.mid(5);
145+
if (line.startsWith("TryExec="))
146+
m_tryExec = line.mid(8);
147+
if (line.startsWith("DesktopNames="))
148+
m_desktopNames = line.mid(13).replace(';', ':');
149+
}
150+
151+
file.close();
152+
153+
m_type = type;
154+
m_valid = true;
155+
}
156+
157+
Session &Session::operator=(const Session &other)
158+
{
159+
setTo(other.type(), other.fileName());
160+
return *this;
161+
}
162+
}

src/common/Session.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/***************************************************************************
2+
* Copyright (c) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
3+
*
4+
* This program is free software; you can redistribute it and/or modify
5+
* it under the terms of the GNU General Public License as published by
6+
* the Free Software Foundation; either version 2 of the License, or
7+
* (at your option) any later version.
8+
*
9+
* This program is distributed in the hope that it will be useful,
10+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
* GNU General Public License for more details.
13+
*
14+
* You should have received a copy of the GNU General Public License
15+
* along with this program; if not, write to the
16+
* Free Software Foundation, Inc.,
17+
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18+
***************************************************************************/
19+
20+
#ifndef SDDM_SESSION_H
21+
#define SDDM_SESSION_H
22+
23+
#include <QDataStream>
24+
#include <QDir>
25+
#include <QSharedPointer>
26+
27+
namespace SDDM {
28+
class SessionModel;
29+
30+
class Session {
31+
public:
32+
enum Type {
33+
UnknownSession = 0,
34+
X11Session,
35+
WaylandSession
36+
};
37+
38+
explicit Session();
39+
Session(Type type, const QString &fileName);
40+
41+
bool isValid() const;
42+
43+
Type type() const;
44+
45+
QString xdgSessionType() const;
46+
47+
QDir directory() const;
48+
QString fileName() const;
49+
50+
QString displayName() const;
51+
QString comment() const;
52+
53+
QString exec() const;
54+
QString tryExec() const;
55+
56+
QString desktopSession() const;
57+
QString desktopNames() const;
58+
59+
void setTo(Type type, const QString &name);
60+
61+
Session &operator=(const Session &other);
62+
63+
private:
64+
bool m_valid;
65+
Type m_type;
66+
QDir m_dir;
67+
QString m_name;
68+
QString m_fileName;
69+
QString m_displayName;
70+
QString m_comment;
71+
QString m_exec;
72+
QString m_tryExec;
73+
QString m_xdgSessionType;
74+
QString m_desktopNames;
75+
76+
friend class SessionModel;
77+
};
78+
79+
inline QDataStream &operator<<(QDataStream &stream, const Session &session) {
80+
const quint32 type = static_cast<quint32>(session.type());
81+
stream << type << session.fileName();
82+
return stream;
83+
}
84+
85+
inline QDataStream &operator>>(QDataStream &stream, Session &session) {
86+
quint32 type;
87+
QString fileName;
88+
stream >> type >> fileName;
89+
session.setTo(static_cast<Session::Type>(type), fileName);
90+
return stream;
91+
}
92+
}
93+
94+
#endif // SDDM_SESSION_H

src/common/SocketWriter.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/***************************************************************************
2+
* Copyright (c) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
23
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@gmail.com>
34
*
45
* This program is free software; you can redistribute it and/or modify
@@ -42,4 +43,10 @@ namespace SDDM {
4243

4344
return *this;
4445
}
46+
47+
SocketWriter &SocketWriter::operator << (const Session &s) {
48+
*output << s;
49+
50+
return *this;
51+
}
4552
}

src/common/SocketWriter.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
/***************************************************************************
2+
* Copyright (c) 2015 Pier Luigi Fiorini <pierluigi.fiorini@gmail.com>
23
* Copyright (c) 2013 Abdurrahman AVCI <abdurrahmanavci@gmail.com>
34
*
45
* This program is free software; you can redistribute it and/or modify
@@ -23,6 +24,8 @@
2324
#include <QDataStream>
2425
#include <QLocalSocket>
2526

27+
#include "Session.h"
28+
2629
namespace SDDM {
2730
class SocketWriter {
2831
Q_DISABLE_COPY(SocketWriter)
@@ -32,6 +35,7 @@ namespace SDDM {
3235

3336
SocketWriter &operator << (const quint32 &u);
3437
SocketWriter &operator << (const QString &s);
38+
SocketWriter &operator << (const Session &s);
3539

3640
private:
3741
QByteArray data;

src/daemon/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ set(DAEMON_SOURCES
88
${CMAKE_SOURCE_DIR}/src/common/Configuration.cpp
99
${CMAKE_SOURCE_DIR}/src/common/SafeDataStream.cpp
1010
${CMAKE_SOURCE_DIR}/src/common/ConfigReader.cpp
11+
${CMAKE_SOURCE_DIR}/src/common/Session.cpp
1112
${CMAKE_SOURCE_DIR}/src/common/SocketWriter.cpp
1213
${CMAKE_SOURCE_DIR}/src/auth/Auth.cpp
1314
${CMAKE_SOURCE_DIR}/src/auth/AuthPrompt.cpp

0 commit comments

Comments
 (0)