https://bugs.kde.org/show_bug.cgi?id=396679

--- Comment #4 from Kusi <k...@forum.titlis.org> ---
I investigated a bit the problem of launching a terminal cross platform

The following code snippet allows to handle the case of KDE, but it should be
easy to extend it for various desktop environments. I just guessed the values
for GNOME, I didn't test for GNOME

    QByteArray env = qgetenv("XDG_CURRENT_DESKTOP");
    QString desktopEnvironment = QString::fromLocal8Bit(env.data());
    QMap<QString, QString> terminals;
    terminals["KDE"] = "konsole";
    terminals["GNOME"] = "gnome-shell";
    terminals["WINDOWS"] = "cmd.exe";

    if (terminals.contains(desktopEnvironment))
    {
        QProcess *process = new QProcess(this);
        QString terminal = terminals[desktopEnvironment];
        QString folder = "/share/pictures";
        process->setWorkingDirectory(folder);
        process->start(terminal);
    }

While getting the current platform (linux/win/osx) seems straight forward with
either QSysInfo or https://wiki.qt.io/Get_OS_name, it is tricky to get the
desktop environment, but it is still feasible w/o too much hassle:

https://stackoverflow.com/questions/47022134/how-can-i-find-out-at-runtime-which-desktop-environment-that-a-qt-application

Remember, if the terminal is not available, the option is just disabled. It
doesn't have to exist for every exotic desktop environment

what do you think?

-- 
You are receiving this mail because:
You are watching all bug changes.

Reply via email to