not quite so much needs to be delayed to the init() function
[personal-kdebase.git] / workspace / kdm / kfrontend / utils.cpp
blobd9802859f18e6b88fb2fa2c8b8c23af28ffc09a6
1 /*
3 Copyright (C) 2005-2006 Oswald Buddenhagen <ossi@kde.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (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 General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "utils.h"
22 #include "kdm_greet.h"
24 #include <klocale.h>
26 #include <stdlib.h>
28 QString qString( char *str )
30 if (!str)
31 return QString();
32 QString qs = QString::fromUtf8( str );
33 free( str );
34 return qs;
37 QStringList qStringList( char **strList )
39 QStringList qsl;
40 for (int i = 0; strList[i]; i++) {
41 qsl.append( QString::fromUtf8( strList[i] ) );
42 free( strList[i] );
44 free( strList );
45 return qsl;
48 QList<DpySpec>
49 fetchSessions( int flags )
51 QList<DpySpec> sessions;
52 DpySpec tsess;
54 gSet( 1 );
55 gSendInt( G_List );
56 gSendInt( flags );
57 next:
58 while (!(tsess.display = qString( gRecvStr() )).isEmpty()) {
59 tsess.from = qString( gRecvStr() );
60 #ifdef HAVE_VTS
61 tsess.vt = gRecvInt();
62 #endif
63 tsess.user = qString( gRecvStr() );
64 tsess.session = qString( gRecvStr() );
65 tsess.flags = gRecvInt();
66 if ((tsess.flags & isTTY) && !tsess.from.isEmpty())
67 for (int i = 0; i < sessions.size(); i++)
68 if (!sessions[i].user.isEmpty() &&
69 sessions[i].user == tsess.user &&
70 sessions[i].from == tsess.from)
72 sessions[i].count++;
73 goto next;
75 tsess.count = 1;
76 sessions.append( tsess );
78 gSet( 0 );
79 return sessions;
82 void
83 decodeSession( const DpySpec &sess, QString &user, QString &loc )
85 if (sess.flags & isTTY) {
86 user =
87 i18ncp( "user: ...", "%2: TTY login", "%2: %1 TTY logins",
88 sess.count, sess.user );
89 loc =
90 #ifdef HAVE_VTS
91 sess.vt ?
92 QString("vt%1").arg( sess.vt ) :
93 #endif
94 !sess.from.isEmpty() ?
95 sess.from : sess.display;
96 } else {
97 user =
98 sess.session.isEmpty() ?
99 i18nc("... session", "Unused") :
100 !sess.user.isEmpty() ?
101 i18nc( "user: session type", "%1: %2",
102 sess.user, sess.session ) :
103 i18nc( "... host", "X login on %1", sess.session );
104 loc =
105 #ifdef HAVE_VTS
106 sess.vt ?
107 QString("%1, vt%2").arg( sess.display ).arg( sess.vt ) :
108 #endif
109 sess.display;