diff --git a/src/frontend/qt/fcitx-input-context.cpp b/src/frontend/qt/fcitx-input-context.cpp index 5ba941b..6e5a9d9 100644 --- a/src/frontend/qt/fcitx-input-context.cpp +++ b/src/frontend/qt/fcitx-input-context.cpp @@ -113,11 +113,37 @@ typedef QInputMethodEvent::Attribute QAttribute; static bool key_filtered = false; +QByteArray QFcitxInputContext::localMachineId() +{ +#if QT_VERSION >= QT_VERSION_CHECK(4, 8, 0) + return QDBusConnection::localMachineId(); +#else + QFile file1("/var/lib/dbus/machine-id"); + QFile file2("/etc/machine-id"); + QFile* fileToRead = NULL; + if (file1.open(QIODevice::ReadOnly)) { + fileToRead = &file1; + } + else if (file2.open(QIODevice::ReadOnly)) { + fileToRead = &file2; + } + if (fileToRead) { + QByteArray result = fileToRead->readLine(1024); + fileToRead->close(); + result = result.trimmed(); + if (!result.isEmpty()) + return result; + } + return "machine-id"; +#endif +} + QString QFcitxInputContext::socketFile() { char* addressFile = NULL; - asprintf(&addressFile, "%s-%d", QDBusConnection::localMachineId().data(), fcitx_utils_get_display_number()); + + asprintf(&addressFile, "%s-%d", localMachineId().data(), fcitx_utils_get_display_number()); char* file = NULL; diff --git a/src/frontend/qt/fcitx-input-context.h b/src/frontend/qt/fcitx-input-context.h index 6c7ecf4..ed7d2db 100644 --- a/src/frontend/qt/fcitx-input-context.h +++ b/src/frontend/qt/fcitx-input-context.h @@ -102,6 +102,7 @@ private Q_SLOTS: void updateCursor(); #endif private: + static QByteArray localMachineId(); static QString socketFile(); static QString address(); void cleanUp();