]> rtime.felk.cvut.cz Git - sojka/lightdm.git/blobdiff - liblightdm-qt/sessionsmodel.cpp
Load all users only when really needed
[sojka/lightdm.git] / liblightdm-qt / sessionsmodel.cpp
index a43d8d733d569de1adf69d3d81c9aa4b0fa61d9a..8771c799a643b1a7ecae94af1c2c8d5758cece37 100644 (file)
@@ -4,9 +4,8 @@
  *
  * This library is free software; you can redistribute it and/or modify it under
  * the terms of the GNU Lesser General Public License as published by the Free
- * Software Foundation; either version 3 of the License, or (at your option) any
- * later version. See http://www.gnu.org/copyleft/lgpl.html the full text of the
- * license.
+ * Software Foundation; either version 2 or version 3 of the License.
+ * See http://www.gnu.org/copyleft/lgpl.html the full text of the license.
  */
 
 #include "QLightDM/sessionsmodel.h"
@@ -22,6 +21,7 @@ class SessionItem
 {
 public:
     QString key;
+    QString type;
     QString name;
     QString comment;
 };
@@ -32,40 +32,50 @@ class SessionsModelPrivate
 public:
     SessionsModelPrivate(SessionsModel *parent);
     QList<SessionItem> items;
-    
-    void loadSessions();
-    
+
+    void loadSessions(SessionsModel::SessionType sessionType);
+
 protected:
     SessionsModel* q_ptr;
 
 private:
     Q_DECLARE_PUBLIC(SessionsModel)
-    
+
 };
 
 SessionsModelPrivate::SessionsModelPrivate(SessionsModel *parent) :
     q_ptr(parent)
 {
+#if !defined(GLIB_VERSION_2_36)
     g_type_init();
-    loadSessions();
+#endif
 }
 
-void SessionsModelPrivate::loadSessions()
+void SessionsModelPrivate::loadSessions(SessionsModel::SessionType sessionType)
 {
-    qDebug() << "loading sessions";
+    GList *ldmSessions;
+
+    switch (sessionType) {
+    case SessionsModel::RemoteSessions:
+        ldmSessions = lightdm_get_remote_sessions();
+        break;
+    case SessionsModel::LocalSessions:
+        /* Fall through*/
+    default:
+        ldmSessions = lightdm_get_sessions();
+        break;
+    }
 
-   GList *ldmSessions = lightdm_get_sessions();
-   for (GList* item = ldmSessions; item; item = item->next) {
+    for (GList* item = ldmSessions; item; item = item->next) {
        LightDMSession *ldmSession = static_cast<LightDMSession*>(item->data);
        Q_ASSERT(ldmSession);
 
        SessionItem session;
        session.key = QString::fromUtf8(lightdm_session_get_key(ldmSession));
+       session.type = QString::fromUtf8(lightdm_session_get_session_type(ldmSession));
        session.name = QString::fromUtf8(lightdm_session_get_name(ldmSession));
        session.comment = QString::fromUtf8(lightdm_session_get_comment(ldmSession));
 
-       qDebug() << "adding session" << session.key;
-
        items.append(session);
    }
 
@@ -73,13 +83,31 @@ void SessionsModelPrivate::loadSessions()
 }
 
 
+//deprecated constructor for ABI compatability.
 SessionsModel::SessionsModel(QObject *parent) :
     QAbstractListModel(parent),
     d_ptr(new SessionsModelPrivate(this))
 {
+    Q_D(SessionsModel);
+
+    QHash<int, QByteArray> roles = roleNames();
+    roles[KeyRole] = "key";
+    setRoleNames(roles);
+
+    d->loadSessions(SessionsModel::LocalSessions);
+}
+
+SessionsModel::SessionsModel(SessionsModel::SessionType sessionType, QObject *parent) :
+    QAbstractListModel(parent),
+    d_ptr(new SessionsModelPrivate(this))
+{
+    Q_D(SessionsModel);
+
     QHash<int, QByteArray> roles = roleNames();
     roles[KeyRole] = "key";
     setRoleNames(roles);
+
+    d->loadSessions(sessionType);
 }
 
 SessionsModel::~SessionsModel()
@@ -90,7 +118,7 @@ SessionsModel::~SessionsModel()
 int SessionsModel::rowCount(const QModelIndex &parent) const
 {
     Q_D(const SessionsModel);
-    
+
     if (parent == QModelIndex()) { //if top level
         return d->items.size();
     } else {
@@ -111,6 +139,8 @@ QVariant SessionsModel::data(const QModelIndex &index, int role) const
     switch (role) {
     case SessionsModel::KeyRole:
         return d->items[row].key;
+    case SessionsModel::TypeRole:
+        return d->items[row].type;
     case Qt::DisplayRole:
         return d->items[row].name;
     case Qt::ToolTipRole:
@@ -120,4 +150,8 @@ QVariant SessionsModel::data(const QModelIndex &index, int role) const
     return QVariant();
 }
 
-#include "sessionsmodel_moc.cpp"
+#if QT_VERSION >= QT_VERSION_CHECK(5, 0, 0)
+#include "sessionsmodel_moc5.cpp"
+#else
+#include "sessionsmodel_moc4.cpp"
+#endif