diff options
author | David Edmundson <david@davidedmundson.co.uk> | 2011-11-22 19:17:07 +0000 |
---|---|---|
committer | David Edmundson <david@davidedmundson.co.uk> | 2011-11-22 19:17:07 +0000 |
commit | 999d9953b1b1e8e05504bc8f8f808e9d55da13b2 (patch) | |
tree | 4fd793ffe1e7db8096effe5743187a83660b409c /liblightdm-qt | |
parent | 94733bc2b6cd0d0a2320e615323607c80bdb0c2c (diff) | |
download | lightdm-git-999d9953b1b1e8e05504bc8f8f808e9d55da13b2.tar.gz |
Port sessions model to use GObject lib
Diffstat (limited to 'liblightdm-qt')
-rw-r--r-- | liblightdm-qt/Makefile.am | 49 | ||||
-rw-r--r-- | liblightdm-qt/QLightDM/Session | 1 | ||||
-rw-r--r-- | liblightdm-qt/QLightDM/SessionsModel | 1 | ||||
-rw-r--r-- | liblightdm-qt/QLightDM/sessionsmodel.h (renamed from liblightdm-qt/QLightDM/session.h) | 12 | ||||
-rw-r--r-- | liblightdm-qt/sessionsmodel.cpp (renamed from liblightdm-qt/session.cpp) | 98 |
5 files changed, 66 insertions, 95 deletions
diff --git a/liblightdm-qt/Makefile.am b/liblightdm-qt/Makefile.am deleted file mode 100644 index a93cb95c..00000000 --- a/liblightdm-qt/Makefile.am +++ /dev/null @@ -1,49 +0,0 @@ -lib_LTLIBRARIES = liblightdm-qt-1.la - -power.cpp: QLightDM/power.h - $(MOC) $< -o power_moc.cpp -greeter.cpp: QLightDM/greeter.h - $(MOC) $< -o greeter_moc.cpp -session.cpp: QLightDM/session.h - $(MOC) $< -o session_moc.cpp -usersmodel.cpp: QLightDM/usersmodel.h - $(MOC) $< -o usermodel_moc.cpp - - - -liblightdm_qt_1_la_LIBADD = $(LIBLIGHTDM_QT_LIBS) -llightdm-gobject-1 -liblightdm_qt_1_la_CXXFLAGS = $(LIBLIGHTDM_QT_CFLAGS) \ - $(LIBLIGHTDM_GOBJECT_CFLAGS) - -DXSESSIONS_DIR=\"$(datadir)/xsessions\" - -liblightdm_qt_1include_HEADERS = \ - QLightDM/Greeter \ - QLightDM/Power \ - QLightDM/Session \ - QLightDM/System \ - QLightDM/UsersModel \ - QLightDM/greeter.h \ - QLightDM/power.h \ - QLightDM/session.h \ - QLightDM/system.h \ - QLightDM/usersmodel.h - -liblightdm_qt_1includedir=$(includedir)/lightdm-qt-1/QLightDM - -liblightdm_qt_1_la_SOURCES = \ - greeter.cpp \ - power.cpp \ - session.cpp \ - system.cpp \ - usersmodel.cpp \ - $(liblightdm_qt_1include_HEADERS) - -pkgconfigdir = $(libdir)/pkgconfig -pkgconfig_DATA = liblightdm-qt-1.pc - -CLEANFILES = \ - *_moc.cpp - -DISTCLEANFILES = \ - Makefile.in \ - $(pkgconfig_DATA) diff --git a/liblightdm-qt/QLightDM/Session b/liblightdm-qt/QLightDM/Session deleted file mode 100644 index 9566e0b8..00000000 --- a/liblightdm-qt/QLightDM/Session +++ /dev/null @@ -1 +0,0 @@ -#include "QLightDM/session.h"
\ No newline at end of file diff --git a/liblightdm-qt/QLightDM/SessionsModel b/liblightdm-qt/QLightDM/SessionsModel new file mode 100644 index 00000000..7fe68741 --- /dev/null +++ b/liblightdm-qt/QLightDM/SessionsModel @@ -0,0 +1 @@ +#include "QLightDM/sessionsmodel.h"
\ No newline at end of file diff --git a/liblightdm-qt/QLightDM/session.h b/liblightdm-qt/QLightDM/sessionsmodel.h index f859e4ce..92df0589 100644 --- a/liblightdm-qt/QLightDM/session.h +++ b/liblightdm-qt/QLightDM/sessionsmodel.h @@ -9,8 +9,8 @@ * license. */ -#ifndef QLIGHTDM_SESSION_H -#define QLIGHTDM_SESSION_H +#ifndef QLIGHTDM_SESSIONS_MODEL_H +#define QLIGHTDM_SESSIONS_MODEL_H #include <QtCore/QAbstractListModel> @@ -22,6 +22,8 @@ namespace QLightDM { Q_OBJECT public: enum SessionModelRoles { + //name is exposed as Qt::DisplayRole + //comment is exposed as Qt::TooltipRole IdRole = Qt::UserRole }; @@ -31,9 +33,11 @@ namespace QLightDM { int rowCount(const QModelIndex &parent) const; QVariant data(const QModelIndex &index, int role=Qt::DisplayRole) const; + protected: + SessionsModelPrivate *d_ptr; + private: - SessionsModelPrivate *d; - void buildList(); //maybe make this a public slot, which apps can call only if they give a care about the session. + Q_DECLARE_PRIVATE(SessionsModel) }; }; diff --git a/liblightdm-qt/session.cpp b/liblightdm-qt/sessionsmodel.cpp index 5b9b1d82..058e6b59 100644 --- a/liblightdm-qt/session.cpp +++ b/liblightdm-qt/sessionsmodel.cpp @@ -9,44 +9,85 @@ * license. */ -#include "QLightDM/session.h" +#include "QLightDM/sessionsmodel.h" -#include <QtCore/QList> -#include <QtCore/QDir> #include <QtCore/QVariant> -#include <QtCore/QSettings> +#include <QtCore/QDebug> + +#include <lightdm-gobject-1/lightdm.h> using namespace QLightDM; -class SessionItem; +class SessionItem +{ +public: + QString id; + QString name; + QString comment; +}; + class SessionsModelPrivate { public: + SessionsModelPrivate(SessionsModel *parent); QList<SessionItem> items; + + void loadSessions(); + +protected: + SessionsModel* q_ptr; + +private: + Q_DECLARE_PUBLIC(SessionsModel) + }; -class SessionItem +SessionsModelPrivate::SessionsModelPrivate(SessionsModel *parent) : + q_ptr(parent) { -public: - QString id; - QString name; - QString comment; -}; + g_type_init(); + loadSessions(); +} + +void SessionsModelPrivate::loadSessions() +{ + qDebug() << "loading sessions"; + + GList *ldmSessions = lightdm_get_sessions(); + for (GList* item = ldmSessions; item; item = item->next) { + LightDMSession *ldmSession = static_cast<LightDMSession*>(item->data); + Q_ASSERT(ldmSession); + + SessionItem session; + session.id = QString::fromLocal8Bit(lightdm_session_get_key(ldmSession)); + session.name = QString::fromLocal8Bit(lightdm_session_get_name(ldmSession)); + session.comment = QString::fromLocal8Bit(lightdm_session_get_comment(ldmSession)); + + qDebug() << "adding session" << session.id; + + items.append(session); + } + + //this happens in the constructor so we don't need beginInsertRows() etc. +} + SessionsModel::SessionsModel(QObject *parent) : QAbstractListModel(parent), - d(new SessionsModelPrivate()) + d_ptr(new SessionsModelPrivate(this)) { - buildList(); } SessionsModel::~SessionsModel() { + delete d_ptr; } int SessionsModel::rowCount(const QModelIndex &parent) const { + Q_D(const SessionsModel); + if (parent == QModelIndex()) { //if top level return d->items.size(); } else { @@ -56,6 +97,8 @@ int SessionsModel::rowCount(const QModelIndex &parent) const QVariant SessionsModel::data(const QModelIndex &index, int role) const { + Q_D(const SessionsModel); + if (! index.isValid()) { return QVariant(); } @@ -74,31 +117,4 @@ QVariant SessionsModel::data(const QModelIndex &index, int role) const return QVariant(); } -void SessionsModel::buildList() -{ - //maybe clear first? - - //FIXME don't hardcode this! - QDir sessionDir("/usr/share/xsessions"); - sessionDir.setNameFilters(QStringList() << "*.desktop"); - - QList<SessionItem> items; - - foreach(QString sessionFileName, sessionDir.entryList()) { - QSettings sessionData(sessionDir.filePath(sessionFileName), QSettings::IniFormat); - sessionData.beginGroup("Desktop Entry"); - sessionFileName.chop(8);// chop(8) removes '.desktop' - - SessionItem item; - item.id = sessionFileName; - item.name = sessionData.value("Name").toString(); - item.comment = sessionData.value("Comment").toString(); - items.append(item); - } - - beginInsertRows(QModelIndex(), 0, items.size()); - d->items.append(items); - endInsertRows(); -} - -#include "session_moc.cpp" +#include "sessionsmodel_moc.cpp" |