Skip to content

Commit

Permalink
Use combobox for leave button
Browse files Browse the repository at this point in the history
  • Loading branch information
surlykke committed Sep 21, 2015
1 parent 82de137 commit 8b209e5
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 33 deletions.
37 changes: 20 additions & 17 deletions loginform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <QMenu>
#include <QProcess>
#include <QLightDM/UsersModel>
#include <QMetaMethod>

#include "loginform.h"
#include "ui_loginform.h"
Expand Down Expand Up @@ -71,25 +72,18 @@ void LoginForm::initialize()
ui->hostnameLabel->setText(m_Greeter.hostname());

ui->sessionCombo->setModel(&sessionsModel);
ui->leaveButton->setMenu(new QMenu(this));

if (power.canShutdown()) {
addLeaveEntry("system-shutdown", tr("Shutdown"), SLOT(shutdown()));
}
if (power.canRestart()) {
addLeaveEntry("system-reboot", tr("Restart"), SLOT(restart()));
}
if (power.canHibernate()) {
addLeaveEntry("system-suspend-hibernate", tr("Hibernate"), SLOT(hibernate()));
}
if (power.canSuspend()) {
addLeaveEntry("system-suspend", tr("Suspend"), SLOT(suspend()));
}
addLeaveEntry(power.canShutdown(), "system-shutdown", tr("Shutdown"), "shutdown");
addLeaveEntry(power.canRestart(), "system-reboot", tr("Restart"), "restart");
addLeaveEntry(power.canHibernate(), "system-suspend-hibernate", tr("Hibernate"), "hibernate");
addLeaveEntry(power.canSuspend(), "system-suspend", tr("Suspend"), "suspend");
ui->leaveComboBox->setDisabled(ui->leaveComboBox->count() <= 1);

ui->sessionCombo->setCurrentIndex(0);
setCurrentSession(m_Greeter.defaultSessionHint());

connect(ui->userInput, SIGNAL(editingFinished()), this, SLOT(userChanged()));
connect(ui->leaveComboBox, SIGNAL(activated(int)), this, SLOT(leaveDropDownActivated(int)));
connect(&m_Greeter, SIGNAL(showPrompt(QString, QLightDM::Greeter::PromptType)), this, SLOT(onPrompt(QString, QLightDM::Greeter::PromptType)));
connect(&m_Greeter, SIGNAL(authenticationComplete()), this, SLOT(authenticationComplete()));

Expand Down Expand Up @@ -130,6 +124,15 @@ void LoginForm::userChanged()
}
}

void LoginForm::leaveDropDownActivated(int index)
{
QString actionName = ui->leaveComboBox->itemData(index).toString();
if (actionName == "shutdown") power.shutdown();
else if (actionName == "restart") power.restart();
else if (actionName == "hibernate") power.hibernate();
else if (actionName == "suspend") power.suspend();
}

void LoginForm::respond()
{
m_Greeter.respond(ui->passwordInput->text().trimmed());
Expand All @@ -144,11 +147,11 @@ void LoginForm::onPrompt(QString prompt, QLightDM::Greeter::PromptType promptTyp
}


void LoginForm::addLeaveEntry(QString iconName, QString text, const char* slot)
void LoginForm::addLeaveEntry(bool canDo, QString iconName, QString text, QString actionName)
{
QMenu* menu = ui->leaveButton->menu();
QAction *action = menu->addAction(QIcon::fromTheme(iconName), text);
connect(action, SIGNAL(triggered(bool)), &power, slot);
if (canDo) {
ui->leaveComboBox->addItem(QIcon::fromTheme(iconName), text, actionName);
}
}

QString LoginForm::currentSession()
Expand Down
8 changes: 5 additions & 3 deletions loginform.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <QDialog>
#include <QKeyEvent>
#include <QGraphicsOpacityEffect>
#include <QMenu>
#include <QMap>

#include <QLightDM/Power>
#include <QLightDM/Greeter>
Expand All @@ -38,6 +38,7 @@ friend class DecoratedUsersModel;

public slots:
void userChanged();
void leaveDropDownActivated(int index);
void respond();
void onPrompt(QString prompt, QLightDM::Greeter::PromptType promptType);
void authenticationComplete();
Expand All @@ -47,8 +48,7 @@ public slots:

private:
void initialize();
void addLeaveEntry(QString iconName, QString text, const char *slot);

void addLeaveEntry(bool canDo, QString iconName, QString text, QString actionName);
QString currentSession();
void setCurrentSession(QString session);

Expand All @@ -57,6 +57,8 @@ public slots:
QLightDM::Greeter m_Greeter;
QLightDM::PowerInterface power;
QLightDM::SessionsModel sessionsModel;

QMap<int, void (QLightDM::PowerInterface::*)()> powerSlots;
};

#endif // LOGINFORM_H
26 changes: 14 additions & 12 deletions loginform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>330</width>
<height>340</height>
<width>347</width>
<height>346</height>
</rect>
</property>
<property name="font">
Expand Down Expand Up @@ -231,26 +231,28 @@ QComboBox::down-arrow {
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="leaveButton">
<widget class="QComboBox" name="leaveComboBox">
<property name="minimumSize">
<size>
<width>60</width>
<width>80</width>
<height>60</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>60</width>
<width>80</width>
<height>60</height>
</size>
</property>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="qt-lightdm-greeter.qrc">
<normaloff>:/resources/leaveIcon.svg</normaloff>:/resources/leaveIcon.svg</iconset>
</property>
<item>
<property name="text">
<string/>
</property>
<property name="icon">
<iconset resource="qt-lightdm-greeter.qrc">
<normaloff>:/resources/leaveIcon.svg</normaloff>:/resources/leaveIcon.svg</iconset>
</property>
</item>
</widget>
</item>
</layout>
Expand Down
1 change: 0 additions & 1 deletion qt-lightdm-greeter.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
<qresource prefix="/">
<file>resources/dropdown.svg</file>
<file>resources/leaveIcon.svg</file>
<file>resources/qt-lightdm-greeter.qss</file>
<file>resources/rqt-2.png</file>
</qresource>
</RCC>

0 comments on commit 8b209e5

Please sign in to comment.