From 66d293363d06253f7d34040219e316dc3c5816d5 Mon Sep 17 00:00:00 2001 From: Huang Peng Date: Mon, 4 Aug 2008 21:04:48 +0800 Subject: [PATCH] get username from getlogin(), $LOGNAME, $USER, $LNAME, $USERNAME. --- gtk2/ibusimclient.c | 15 +++++++++++++-- qt4/ibus-client.cpp | 14 +++++++++++++- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/gtk2/ibusimclient.c b/gtk2/ibusimclient.c index 25b0686c..939ce129 100644 --- a/gtk2/ibusimclient.c +++ b/gtk2/ibusimclient.c @@ -204,7 +204,7 @@ _ibus_im_client_ibus_open (IBusIMClient *client) } #endif if (ibus_addr == NULL) { - gchar *display, *host, *id; + gchar *display, *host, *id, *username; display = g_strdup (g_getenv ("DISPLAY")); if (display != NULL) { id = host = display; @@ -219,7 +219,18 @@ _ibus_im_client_ibus_open (IBusIMClient *client) else { host = id = ""; } - ibus_addr = g_strdup_printf ("unix:path=/tmp/ibus-%s/ibus-%s-%s", getlogin (), host, id); + + username = getlogin(); + if (username == NULL) + username = getenv("LOGNAME"); + if (username == NULL) + username = getenv("USER"); + if (username == NULL) + username = getenv("LNAME"); + if (username == NULL) + username = getenv("USERNAME"); + + ibus_addr = g_strdup_printf ("unix:path=/tmp/ibus-%s/ibus-%s-%s", username, host, id); g_free (display); } diff --git a/qt4/ibus-client.cpp b/qt4/ibus-client.cpp index 43ca50a5..8b0aff22 100644 --- a/qt4/ibus-client.cpp +++ b/qt4/ibus-client.cpp @@ -332,6 +332,7 @@ IBusClient::connectToBus () { QString address; QString session; + QString username; QDBusConnection *connection = NULL; if (ibus != NULL) @@ -339,7 +340,18 @@ IBusClient::connectToBus () session = getenv ("DISPLAY"); session.replace (":", "-"); - address = QString("unix:path=/tmp/ibus-%1/ibus-%2").arg (getlogin(), session); + + username = getlogin (); + if (username.isNull ()) + username = getenv ("LOGNAME"); + if (username.isNull ()) + username = getenv ("USER"); + if (username.isNull ()) + username = getenv ("LNAME"); + if (username.isNull ()) + username = getenv ("USERNAME"); + + address = QString("unix:path=/tmp/ibus-%1/ibus-%2").arg (username, session); connection = new QDBusConnection ( QDBusConnection::connectToBus ( address,