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
3233namespace SDDM {
3334 class Session {
3435 public:
36+ SessionModel::SessionType type;
37+ QString directory;
3538 QString file;
3639 QString name;
3740 QString exec;
@@ -47,22 +50,78 @@ namespace SDDM {
4750 };
4851
4952 SessionModel::SessionModel (QObject *parent) : QAbstractListModel(parent), d(new SessionModelPrivate()) {
53+ populate (SessionModel::X11Session, mainConfig.XDisplay .SessionDir .get ());
54+ populate (SessionModel::WaylandSession, mainConfig.WaylandDisplay .SessionDir .get ());
55+ }
56+
57+ SessionModel::~SessionModel () {
58+ delete d;
59+ }
60+
61+ QHash<int , QByteArray> SessionModel::roleNames () const {
62+ // set role names
63+ QHash<int , QByteArray> roleNames;
64+ roleNames[DirectoryRole] = " directory" ;
65+ roleNames[FileRole] = " file" ;
66+ roleNames[NameRole] = " name" ;
67+ roleNames[ExecRole] = " exec" ;
68+ roleNames[CommentRole] = " comment" ;
69+
70+ return roleNames;
71+ }
72+
73+ const int SessionModel::lastIndex () const {
74+ return d->lastIndex ;
75+ }
76+
77+ int SessionModel::rowCount (const QModelIndex &parent) const {
78+ return d->sessions .length ();
79+ }
80+
81+ QVariant SessionModel::data (const QModelIndex &index, int role) const {
82+ if (index.row () < 0 || index.row () >= d->sessions .count ())
83+ return QVariant ();
84+
85+ // get session
86+ SessionPtr session = d->sessions [index.row ()];
87+
88+ // return correct value
89+ if (role == DirectoryRole)
90+ return session->directory ;
91+ if (role == FileRole)
92+ return session->file ;
93+ else if (role == NameRole)
94+ return session->name ;
95+ else if (role == ExecRole)
96+ return session->exec ;
97+ else if (role == CommentRole)
98+ return session->comment ;
99+
100+ // return empty value
101+ return QVariant ();
102+ }
103+
104+ void SessionModel::populate (SessionModel::SessionType type, const QString &path) {
50105 // read session files
51- QDir dir (mainConfig. XDisplay . SessionDir . get () );
106+ QDir dir (path );
52107 dir.setNameFilters (QStringList () << " *.desktop" );
53108 dir.setFilter (QDir::Files);
54109 // read session
55110 foreach (const QString &session, dir.entryList ()) {
56111 QFile inputFile (dir.absoluteFilePath (session));
57112 if (!inputFile.open (QIODevice::ReadOnly))
58113 continue ;
59- SessionPtr si { new Session { session, " " , " " , " " } };
114+ SessionPtr si { new Session { type, path, session, " " , " " , " " } };
60115 QTextStream in (&inputFile);
61116 bool execAllowed = true ;
62117 while (!in.atEnd ()) {
63118 QString line = in.readLine ();
64- if (line.startsWith (" Name=" ))
65- si->name = line.mid (5 );
119+ if (line.startsWith (" Name=" )) {
120+ if (type == WaylandSession)
121+ si->name = tr (" %1 (Wayland)" ).arg (line.mid (5 ));
122+ else
123+ si->name = line.mid (5 );
124+ }
66125 if (line.startsWith (" Exec=" ))
67126 si->exec = line.mid (5 );
68127 if (line.startsWith (" Comment=" ))
@@ -96,7 +155,8 @@ namespace SDDM {
96155 inputFile.close ();
97156 }
98157 // add failsafe session
99- d->sessions << SessionPtr { new Session {" failsafe" , " Failsafe" , " failsafe" , " Failsafe Session" } };
158+ if (type == X11Session)
159+ d->sessions << SessionPtr { new Session {type, path, " failsafe" , " Failsafe" , " failsafe" , " Failsafe Session" } };
100160 // find out index of the last session
101161 for (int i = 0 ; i < d->sessions .size (); ++i) {
102162 if (d->sessions .at (i)->file == stateConfig.Last .Session .get ()) {
@@ -105,48 +165,4 @@ namespace SDDM {
105165 }
106166 }
107167 }
108-
109- SessionModel::~SessionModel () {
110- delete d;
111- }
112-
113- QHash<int , QByteArray> SessionModel::roleNames () const {
114- // set role names
115- QHash<int , QByteArray> roleNames;
116- roleNames[FileRole] = " file" ;
117- roleNames[NameRole] = " name" ;
118- roleNames[ExecRole] = " exec" ;
119- roleNames[CommentRole] = " comment" ;
120-
121- return roleNames;
122- }
123-
124- const int SessionModel::lastIndex () const {
125- return d->lastIndex ;
126- }
127-
128- int SessionModel::rowCount (const QModelIndex &parent) const {
129- return d->sessions .length ();
130- }
131-
132- QVariant SessionModel::data (const QModelIndex &index, int role) const {
133- if (index.row () < 0 || index.row () >= d->sessions .count ())
134- return QVariant ();
135-
136- // get session
137- SessionPtr session = d->sessions [index.row ()];
138-
139- // return correct value
140- if (role == FileRole)
141- return session->file ;
142- else if (role == NameRole)
143- return session->name ;
144- else if (role == ExecRole)
145- return session->exec ;
146- else if (role == CommentRole)
147- return session->comment ;
148-
149- // return empty value
150- return QVariant ();
151- }
152168}
0 commit comments