1 /***************************************************************************
2 * Copyright (C) 2007 by Opsidao,,, *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU Library General Public License as *
7 * published by the Free Software Foundation; either version 2 of the *
8 * License, or (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU Library General Public *
16 * License along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
19 ***************************************************************************/
20 #include "screenlocker.h"
22 #include <QSystemTrayIcon>
31 #define TRAY_ICON_NORMAL ":/images/oxygen-system-lock-screen.svg"
32 #define TRAY_ICON_BAD ":/images/bad.svg"
34 ScreenLocker::ScreenLocker(QWidget
*parent
)
36 trayIcon(new QSystemTrayIcon(this)),
37 contextMenu(new QMenu(this)),
39 requirePasswordAction(0),
41 settings(new QSettings("opsiland","RFIDScreenLocker",this))
43 enableAction
= contextMenu
->addAction("Enabled");
44 enableAction
->setCheckable(true);
45 enableAction
->setChecked(settings
->value("enabled",true).toBool());
46 QObject::connect(enableAction
,SIGNAL(toggled(bool)),this,SLOT(enableToggled(bool)));
48 requirePasswordAction
= contextMenu
->addAction("Password required");
49 requirePasswordAction
->setToolTip("Indicates if the user will have to supply a password to unlock the screen");
50 requirePasswordAction
->setCheckable(true);
51 requirePasswordAction
->setChecked(settings
->value("passwordRequired",true).toBool());
53 closeAction
= contextMenu
->addAction("Close");
54 QObject::connect(closeAction
,SIGNAL(triggered(bool)),this,SLOT(close()));
56 trayIcon
->setContextMenu(contextMenu
);
57 trayIcon
->setIcon(QIcon(TRAY_ICON_NORMAL
));
58 trayIcon
->setVisible(true);
59 QTimer::singleShot(100,this,SLOT(startupNotify()));
61 QObject::connect(&control
,SIGNAL(testNodeLinkDone(int)),this,SLOT(slotTestNodeLinkDone(int)));
62 QObject::connect(&control
,SIGNAL(readPublicModeDone(int, const QString
&, const QString
&)),this,SLOT(slotReadPublicModeDone(int, const QString
&, const QString
&)));
64 control
.setName("/dev/ttyS0");
65 if(enableAction
->isChecked()) {
67 control
.testNodeLink();
72 ScreenLocker::~ScreenLocker()
74 settings
->setValue("enabled",enableAction
->isChecked());
75 settings
->setValue("passwordRequired",requirePasswordAction
->isChecked());
79 void ScreenLocker::startupNotify()
82 if(enableAction
->isChecked())
83 msg
="Remember that the screen will be locked if you take your RFID card away";
85 msg
="The RFID Screen Locker is disabled, use the system tray icon to enable it";
86 trayIcon
->showMessage("RFID Screen Locker Running",msg
,QSystemTrayIcon::Information
);
89 void ScreenLocker::enableToggled(bool enabled
)
91 trayIcon
->showMessage(QString("RFID Screen Locker %1").arg(enabled
? "Enabled":"Disabled"),QString("Use the system tray icon to %1 it").arg(enabled
? "disable":"enable"),QSystemTrayIcon::Information
,6000);
93 trayIcon
->setIcon(QIcon(TRAY_ICON_NORMAL
));
95 control
.testNodeLink();
97 //FIXME The commented code produces a segfault with stack corruption
102 void ScreenLocker::slotTestNodeLinkDone(int result
)
106 case Rdw125Control::Ok
:
107 control
.readPublicModeA();
111 enableAction
->setChecked(false);
112 trayIcon
->setIcon(QIcon(TRAY_ICON_BAD
));
113 trayIcon
->showMessage("Unable to open card reader","It was impossible to open the RFID reader\nThe Screen Locker won't work",QSystemTrayIcon::Warning
);
117 void ScreenLocker::slotReadPublicModeDone(int correct
, const QString
& hexData
, const QString
& decData
)
121 QString
userName(getpwuid(getuid())->pw_name
);
122 if (userName
.endsWith(hexData
)) {
125 args
<< "kdesktop" << "KScreensaverIface";
128 case Rdw125Control::Ok
:
129 if (!requirePasswordAction
->isChecked()) {
131 proc
.start("dcop",args
);
132 proc
.waitForFinished();
137 proc
.start("dcop",args
);
138 proc
.waitForFinished();
141 qDebug() << "That's not the active user: " << hexData
;
142 if(enableAction
->isChecked())
143 control
.readPublicModeA();