Skip to content
This repository has been archived by the owner on Apr 1, 2018. It is now read-only.

Commit

Permalink
Merge pull request #1 from aavci1/master
Browse files Browse the repository at this point in the history
Set auto user on startup.
  • Loading branch information
rshah committed Feb 16, 2013
2 parents f9a7df1 + beee8e9 commit 143eeab
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 28 deletions.
23 changes: 13 additions & 10 deletions advanceconfig.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
Copyright 2013 by Reza Fatahilah Shah <rshah0385@kireihana.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -28,12 +28,12 @@ AdvanceConfig::AdvanceConfig(QWidget *parent) :
QWidget(parent)
{
mConfig = KSharedConfig::openConfig(SDDM_CONFIG_FILE, KConfig::SimpleConfig);

configUi = new Ui::AdvanceConfig();
configUi->setupUi(this);

load();

connect(configUi->userList, SIGNAL(activated(int)), SIGNAL(changed()));
connect(configUi->haltCommand, SIGNAL(textChanged(QString)), SIGNAL(changed()));
connect(configUi->rebootCommand, SIGNAL(textChanged(QString)), SIGNAL(changed()));
Expand All @@ -49,18 +49,21 @@ void AdvanceConfig::load()
UsersModel *model = new UsersModel(this);
configUi->userList->setModel(model);
model->populate(mConfig->group("General").readEntry("MinimumUid", 1000));


QString currentUser = mConfig->group("General").readEntry("AutoUser", "");
configUi->userList->setCurrentIndex(model->indexOf(currentUser));

configUi->haltCommand->setUrl(mConfig->group("General").readEntry("HaltCommand"));
configUi->rebootCommand->setUrl(mConfig->group("General").readEntry("RebootCommand"));
}

QVariantMap AdvanceConfig::save()
{
QVariantMap args;

args["sddm.conf/General/AutoUser"] = (configUi->userList->currentIndex() == 0) ? "" : configUi->userList->currentText();
args["sddm.conf/General/HaltCommand"] = configUi->haltCommand->url().path();
args["sddm.conf/General/RebootCommand"] = configUi->rebootCommand->url().path();

return args;
}
}
37 changes: 24 additions & 13 deletions usersmodel.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
Copyright 2013 by Reza Fatahilah Shah <rshah0385@kireihana.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand All @@ -32,39 +32,39 @@ UsersModel::~UsersModel()
int UsersModel::rowCount(const QModelIndex &parent) const
{
Q_UNUSED(parent)

return mUserList.size();
}

QVariant UsersModel::data(const QModelIndex &index, int role) const
{
const KUser user = mUserList[index.row()];

switch(role) {
case Qt::DisplayRole:
return (index.row() == 0 ) ? "<No Autologin>" : user.loginName();
}

return QVariant();
}

void UsersModel::add(const KUser &user)
void UsersModel::add(const KUser &user)
{
beginInsertRows(QModelIndex(), mUserList.count(), mUserList.count());

mUserList.append( KUser(user) );

endInsertRows();
}

void UsersModel::populate(const int minimumUid) {
KUser firstUser("No Autologin");

QList< KUser > userList = KUser::allUsers();

KUser user;
add(firstUser);

foreach( user, userList ) {
if (user.uid() >= minimumUid) {
add(user);
Expand All @@ -74,5 +74,16 @@ void UsersModel::populate(const int minimumUid) {
kDebug() << " isSuperUser:" << user.isSuperUser() << ",isValid:" << user.isValid();
kDebug() << " faceIconPath:" << user.faceIconPath();*/
}

}

int UsersModel::indexOf(const QString &user) {
if (user.isEmpty())
return 0;
// find user index
for (int i = 0; i < mUserList.size(); ++i)
if (mUserList.at(i).loginName() == user)
return i;
// user not found
return 0;
}

11 changes: 6 additions & 5 deletions usersmodel.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/*
Copyright 2013 by Reza Fatahilah Shah <rshah0385@kireihana.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
Expand Down Expand Up @@ -38,11 +38,12 @@ class UsersModel : public QAbstractListModel
int rowCount(const QModelIndex &parent) const;
QVariant data(const QModelIndex &index, int role) const;
void populate(const int minimumUid);
int indexOf(const QString &user);

private:
void add(const KUser &user);

QList<KUser> mUserList;

};
#endif //USERSMODEL_H
#endif //USERSMODEL_H

0 comments on commit 143eeab

Please sign in to comment.