Programming Question: Locking down X (and Windows..blegh..) with QT

Forum: LXer Meta ForumTotal Replies: 10
Author Content
techiem2

Nov 03, 2009
3:03 PM EDT
So a friend and I decided to write our own webcafe system since there seems to be a great lack of foss ones out there and another friend and I are setting one up in his shop and are having issues with the client for the one we found (i.e. it doesn't seem to do anything). :P

I have the backend stuff mostly working now, and we are trying to figure out the client end. He chose QT because it is easily cross-platform (and that's what he's used to working with), so it should be easy to build for Linux or Windows. The basic idea is that the client will run on the machine, and lock it until the server sends the unlock code, then lock it again when the server sends the lock code. What we are having trouble finding is how to lock/unlock the machine.

The client for the system I have running at the shop right now doesn't have anything useful in the code (the source for the clients is literally only a few pages long). The windows version (which I have played with briefly) doesn't appear to actually lock the machine, it seemed to just set itself to be the topmost window (which task manager happily overrides and lets you kill it).

Can anyone point me in the right direction for locking down Linux and/or Windows in a QT app? Thanks!
penguinist

Nov 03, 2009
3:55 PM EDT
Depends on your definition of "Lock".

I assume that you mean that your client app, while in the locked state, will display a static splash image and will be unresponsive to keyboard and mouse entries.

Causing QT to display a static image on signal from the server is easy. The hard part seems to be forcing the keyboard to be totally unresponsive (including ctl-alt-del and other trapped combinations). Asking QT to trap all keyboard events and throw them away seems to be only a partial solution, but maybe that is good enough?

Maybe someone else has some other ideas?
techiem2

Nov 03, 2009
4:26 PM EDT
That was one of my thoughts too, if we can figure out how to do it. Since capturing keyboard and mouse input would essentially be a lock.
Sander_Marechal

Nov 03, 2009
6:08 PM EDT
Perhaps you can use the screensaver? On Linux, screensaver can lock the system. Perhaps you can have the client talk to xscreensaver to lock/unlock the machine. A quick google shows that the Windows screensaver has an API as well that you could use.
hkwint

Nov 03, 2009
7:27 PM EDT
Strange, in the coffeeshop (yeah, Dutch one!) I used to hang out when I was discovering Linux in 2003, they had a webcafe system running on their Linux computer over there. You could only surf while paying. Unless you knew how to 'ssh' to your own Linux computer using some X-tunnel, but of course we were the only ones who knew, so we were the only ones able to browse the web without paying.

Why just not shut down eth0 (as root) or so instead of locking the computer? That's how most webcafe's handle this issue I guess. After all, people pay you to use the internet, not to play kmahjong, or am I wrong?

Apart from that, if I were you I'd be asking this question on an Opera forum. They have 'kiosk' mode, probably meant for what you're intending.
techiem2

Nov 04, 2009
12:38 AM EDT
It's not just for net, it's for access to the machine at all. Thus why we need a lockdown. Inet, Games, Apps (i.e. kid pays to sit and do his homework for an hour while mom shops....), etc.

Sadly the system has to be cross platform as most of the client machines are Windows (because of games and stuff, apparently he wants to be able to do some tournament stuff too).
hkwint

Nov 04, 2009
6:26 PM EDT
I understand. It's not that easy.

Yeah, that sounds like ground not yet conquered Mark.

I'd say look at QTopia / QT Embedded. AFAIK Smartphones and the like have the ability to 'lock' them (while they are in your pocket), but I'm not sure you can use it for the PC. Something like this:

http://doc.qt.nokia.com/qtopia4.2/qpinmanager.html

but I have to admit I have no clue about QT.
techiem2

Nov 04, 2009
7:14 PM EDT
Me either. :P I'll pass that along.

Yeah, I can't imagine that nobody has done something like this before. lol. I know there are windows programs around (I used to use one way back) that can capture all input. So I know it's doable. I assume there's a way in X as well (after all, the screensavers pretty much do this somehow...).
Sander_Marechal

Nov 04, 2009
7:29 PM EDT
techiem, just look at the source for xscreensaver.
techiem2

Nov 07, 2009
12:52 PM EDT
Well, after much searching and hair pulling, we were unable to find anything for QT that seemed workable. So my friend switched to using Vala with SDL (so it should still be nicely cross platform), and very quickly had a working client put together. A few bugs to work out, but it's looking good.

Another semi-related question that hopefully will be a no-brainer for you MySQL experts: I'm writing the SQL file to create the tables in the database and to create the entries for a default admin and a default options set. The tables were easy enough (create table if not exists....).

How do I go about inserting an entry into a table only if it is empty? I.e. if they already have the table structure and data in place I don't need to insert the default admin and default option set into those tables. Or should I not bother since this is an installation sql file and it is assumed that they are using empty tables? :P

Thanks as always! Our little cafe project is looking very nice now.
Sander_Marechal

Nov 08, 2009
4:27 PM EDT
There are various ways. Making sure you only execute the SQL file when there are no tables yet is one way. Another way is to simply INSERT them with a known ID, then catch the "ID already exists" error and ignore it. A third way is using a stored procedure. Do a SELECT *, see if there are any rows and if not, INSERT the default rows.

Posting in this forum is limited to members of the group: [Editors, MEMBERS, SITEADMINS.]

Becoming a member of LXer is easy and free. Join Us!