~ubuntu-branches/ubuntu/utopic/kde-workspace/utopic-proposed

« back to all changes in this revision

Viewing changes to kdm/kfrontend/utils.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Michał Zając
  • Date: 2011-07-09 08:31:15 UTC
  • Revision ID: james.westby@ubuntu.com-20110709083115-ohyxn6z93mily9fc
Tags: upstream-4.6.90
Import upstream version 4.6.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 
 
3
Copyright (C) 2005-2006 Oswald Buddenhagen <ossi@kde.org>
 
4
 
 
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.
 
9
 
 
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.
 
14
 
 
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.
 
18
 
 
19
*/
 
20
 
 
21
#include "utils.h"
 
22
#include "kdm_greet.h"
 
23
 
 
24
#include <klocale.h>
 
25
 
 
26
#include <stdlib.h>
 
27
 
 
28
QString qString(char *str)
 
29
{
 
30
    if (!str)
 
31
        return QString();
 
32
    QString qs = QString::fromUtf8(str);
 
33
    free(str);
 
34
    return qs;
 
35
}
 
36
 
 
37
QStringList qStringList(char **strList)
 
38
{
 
39
    QStringList qsl;
 
40
    for (int i = 0; strList[i]; i++) {
 
41
        qsl.append(QString::fromUtf8(strList[i]));
 
42
        free(strList[i]);
 
43
    }
 
44
    free(strList);
 
45
    return qsl;
 
46
}
 
47
 
 
48
QList<DpySpec>
 
49
fetchSessions(int flags)
 
50
{
 
51
    QList<DpySpec> sessions;
 
52
    DpySpec tsess;
 
53
 
 
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)
 
71
                {
 
72
                    sessions[i].count++;
 
73
                    goto next;
 
74
                }
 
75
        tsess.count = 1;
 
76
        sessions.append(tsess);
 
77
    }
 
78
    gSet(0);
 
79
    return sessions;
 
80
}
 
81
 
 
82
void
 
83
decodeSession(const DpySpec &sess, QString &user, QString &loc)
 
84
{
 
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;
 
110
    }
 
111
}