Refine code of creating ibus address string.
This commit is contained in:
Родитель
1843f0adcf
Коммит
eef1e0fc61
|
@ -204,22 +204,37 @@ _ibus_im_client_ibus_open (IBusIMClient *client)
|
|||
}
|
||||
#endif
|
||||
if (ibus_addr == NULL) {
|
||||
gchar *display, *host, *id, *username;
|
||||
gchar *display;
|
||||
gchar *hostname = "";
|
||||
gchar *displaynumber = "0";
|
||||
gchar *screennumber = "0";
|
||||
gchar *username = NULL;
|
||||
gchar *p;
|
||||
|
||||
display = g_strdup (g_getenv ("DISPLAY"));
|
||||
if (display != NULL) {
|
||||
id = host = display;
|
||||
for (; *id != ':' && *id != '\0'; id++);
|
||||
if (*id == '\0')
|
||||
id = "";
|
||||
else {
|
||||
*id = '\0';
|
||||
id ++;
|
||||
}
|
||||
if (display == NULL) {
|
||||
g_warning ("DISPLAY is empty! We use default DISPLAY (:0.0)");
|
||||
}
|
||||
else {
|
||||
host = id = "";
|
||||
p = display;
|
||||
hostname = display;
|
||||
for (; *p != ':' && *p != '\0'; p++);
|
||||
|
||||
if (*p == ':') {
|
||||
*p = '\0';
|
||||
p++;
|
||||
displaynumber = p;
|
||||
}
|
||||
|
||||
for (; *p != '.' && *p != '\0'; p++);
|
||||
|
||||
if (*p == '.') {
|
||||
*p = '\0';
|
||||
p++;
|
||||
screennumber = p;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
username = getlogin();
|
||||
if (username == NULL)
|
||||
username = getenv("LOGNAME");
|
||||
|
@ -230,7 +245,10 @@ _ibus_im_client_ibus_open (IBusIMClient *client)
|
|||
if (username == NULL)
|
||||
username = getenv("USERNAME");
|
||||
|
||||
ibus_addr = g_strdup_printf ("unix:path=/tmp/ibus-%s/ibus-%s-%s", username, host, id);
|
||||
ibus_addr = g_strdup_printf (
|
||||
"unix:path=/tmp/ibus-%s/ibus-%s-%s.%s",
|
||||
username, hostname, displaynumber, screennumber);
|
||||
|
||||
g_free (display);
|
||||
}
|
||||
|
||||
|
|
|
@ -44,6 +44,20 @@
|
|||
IBusClient::IBusClient ()
|
||||
: ibus (NULL), focused_context (NULL)
|
||||
{
|
||||
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");
|
||||
|
||||
session = getenv ("DISPLAY");
|
||||
session.replace (":", "-");
|
||||
|
||||
ibus_addr = QString("unix:path=/tmp/ibus-%1/ibus-%2").arg (username, session);
|
||||
connectToBus ();
|
||||
|
||||
QObject::connect (
|
||||
|
@ -51,8 +65,10 @@ IBusClient::IBusClient ()
|
|||
SIGNAL(directoryChanged(const QString &)),
|
||||
this,
|
||||
SLOT(slotDirectoryChanged(const QString &)));
|
||||
|
||||
QString ibus_dir;
|
||||
ibus_dir = QString ("/tmp/ibus-%1/").arg (getenv ("USER"));
|
||||
|
||||
ibus_dir = QString ("/tmp/ibus-%1/").arg (username);
|
||||
watcher.addPath (ibus_dir);
|
||||
}
|
||||
|
||||
|
@ -342,31 +358,14 @@ IBusClient::widgetDestroyed (IBusInputContext * /* ctx */, QWidget * /* widget *
|
|||
bool
|
||||
IBusClient::connectToBus ()
|
||||
{
|
||||
QString address;
|
||||
QString session;
|
||||
QString username;
|
||||
QDBusConnection *connection = NULL;
|
||||
|
||||
if (ibus != NULL)
|
||||
return false;
|
||||
|
||||
session = getenv ("DISPLAY");
|
||||
session.replace (":", "-");
|
||||
|
||||
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,
|
||||
ibus_addr,
|
||||
QString ("ibus")));
|
||||
|
||||
if (!connection->isConnected ()) {
|
||||
|
@ -464,10 +463,7 @@ IBusClient::slotDirectoryChanged (const QString & /*path*/)
|
|||
disconnectFromBus ();
|
||||
|
||||
if (ibus == NULL ) {
|
||||
QString session = getenv ("DISPLAY");
|
||||
session.replace (":", "-");
|
||||
QString path = QString("/tmp/ibus-%1/ibus-%2").arg (getenv ("USER"), session);
|
||||
if (QFile::exists (path)) {
|
||||
if (QFile::exists (ibus_addr)) {
|
||||
usleep (500);
|
||||
connectToBus ();
|
||||
}
|
||||
|
|
|
@ -79,6 +79,9 @@ private:
|
|||
QList <IBusInputContext *> context_list;
|
||||
QHash <QString, IBusInputContext *>context_dict;
|
||||
IBusInputContext *focused_context;
|
||||
QString username;
|
||||
QString session;
|
||||
QString ibus_addr;
|
||||
};
|
||||
|
||||
#endif // __IBUS_CLIENT_H_
|
||||
|
|
Загрузка…
Ссылка в новой задаче