From efb1686e626efc4ab56efeb7f654ab7e67d3a3eb Mon Sep 17 00:00:00 2001 From: Waqar Ahmed Date: Fri, 24 Feb 2023 11:43:58 +0500 Subject: [PATCH] Make konsole compile on windows --- src/Application.cpp | 5 +- src/ProcessInfo.cpp | 2 + src/Pty.cpp | 118 +++++++++++++++++++++++++++- src/Pty.h | 29 +++++-- src/SSHProcessInfo.cpp | 7 +- src/UnixProcessInfo.cpp | 3 + src/UnixProcessInfo.h | 3 +- src/Vt102Emulation.cpp | 1 - src/history/HistoryFile.cpp | 6 ++ src/profile/Profile.cpp | 9 ++- src/session/Session.cpp | 58 ++++++++++++++ src/session/SessionController.cpp | 2 + src/widgets/KonsolePrintManager.cpp | 3 +- 13 files changed, 230 insertions(+), 16 deletions(-) diff --git a/src/Application.cpp b/src/Application.cpp index 567443317..5f3009b69 100644 --- a/src/Application.cpp +++ b/src/Application.cpp @@ -18,7 +18,9 @@ // KDE #include +#ifndef Q_OS_WIN #include +#endif #include // Konsole @@ -505,13 +507,14 @@ void Application::startBackgroundMode(MainWindow *window) return; } +#ifndef Q_OS_WIN KActionCollection *collection = window->actionCollection(); QAction *action = collection->addAction(QStringLiteral("toggle-background-window")); action->setObjectName(QStringLiteral("Konsole Background Mode")); action->setText(i18nc("@item", "Toggle Background Window")); KGlobalAccel::self()->setGlobalShortcut(action, QKeySequence(Konsole::ACCEL | Qt::Key_F12)); connect(action, &QAction::triggered, this, &Application::toggleBackgroundInstance); - +#endif _backgroundInstance = window; } diff --git a/src/ProcessInfo.cpp b/src/ProcessInfo.cpp index 6473711a2..acb3db9dc 100644 --- a/src/ProcessInfo.cpp +++ b/src/ProcessInfo.cpp @@ -14,6 +14,7 @@ #include "UnixProcessInfo.h" // Unix +#ifndef Q_OS_WIN #include #include #include @@ -21,6 +22,7 @@ #include #include #include +#endif // Qt #include diff --git a/src/Pty.cpp b/src/Pty.cpp index 5d5202c9a..66e4374a5 100644 --- a/src/Pty.cpp +++ b/src/Pty.cpp @@ -9,15 +9,17 @@ #include "konsoledebug.h" +// Qt +#include +#include + +#ifndef Q_OS_WIN + // System #include #include //ioctl() and TIOCSWINSZ #include -// Qt -#include -#include - // KDE #include #include @@ -339,4 +341,112 @@ void Pty::setupChildProcess() sigaction(signal, &action, nullptr); } } +#endif // QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + +#else + +// Windows backend +// FIXME: implementation needed + +using Konsole::Pty; + +Pty::Pty(QObject *aParent) + : Pty(-1, aParent) +{ +} + +Pty::Pty(int masterFd, QObject *aParent) + : QObject(aParent) +{ + Q_UNUSED(masterFd) + + _windowColumns = 0; + _windowLines = 0; + _windowWidth = 0; + _windowHeight = 0; + _eraseChar = 0; + _xonXoff = true; + _utf8 = true; + + setEraseChar(_eraseChar); + setFlowControlEnabled(_xonXoff); + setUtf8Mode(_utf8); + + setWindowSize(_windowColumns, _windowLines, _windowWidth, _windowHeight); +} + +Pty::~Pty() = default; + +void Pty::sendData(const QByteArray & /*data*/) +{ +} + +void Pty::dataReceived() +{ +} + +void Pty::setWindowSize(int, int, int, int) +{ +} + +QSize Pty::windowSize() const +{ + return {_windowColumns, _windowLines}; +} + +QSize Pty::pixelSize() const +{ + return QSize(); +} + +void Pty::setFlowControlEnabled(bool enable) +{ + _xonXoff = enable; +} + +bool Pty::flowControlEnabled() const +{ + return false; +} + +void Pty::setUtf8Mode(bool) +{ +} + +void Pty::setEraseChar(char eChar) +{ + _eraseChar = eChar; +} + +char Pty::eraseChar() const +{ + return _eraseChar; +} + +void Pty::setInitialWorkingDirectory(const QString & /*dir*/) +{ +} + +void Pty::addEnvironmentVariables(const QStringList & /*environmentVariables*/) +{ +} + +int Pty::start(const QString & /*programName*/, const QStringList & /*programArguments*/, const QStringList & /*environmentList*/) +{ + return -1; +} + +void Pty::setWriteable(bool) +{ +} + +void Pty::closePty() +{ +} + +int Pty::foregroundProcessGroup() const +{ + return 0; +} + #endif diff --git a/src/Pty.h b/src/Pty.h index 951e44333..312fb774a 100644 --- a/src/Pty.h +++ b/src/Pty.h @@ -11,12 +11,17 @@ // Qt #include -// KDE -#include - // Konsole #include "konsoleprivate_export.h" +#ifndef Q_OS_WIN +// KDE +#include +#else +// FIXME windows stuff here +#include +#endif + namespace Konsole { /** @@ -32,7 +37,15 @@ namespace Konsole * To start the terminal process, call the start() method * with the program name and appropriate arguments. */ -class KONSOLEPRIVATE_EXPORT Pty : public KPtyProcess +#ifdef Q_OS_WIN +#define _k_override_ +#define ParentClass QObject +#else +#define _k_override_ override +#define ParentClass KPtyProcess +#endif + +class KONSOLEPRIVATE_EXPORT Pty : public ParentClass { Q_OBJECT @@ -151,9 +164,11 @@ Q_SIGNALS: protected: // TODO: remove this; the method is removed from QProcess in Qt6 // instead use setChildProcessModifier() in the constructor +#ifndef Q_OS_WIN #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) - void setupChildProcess() override; -#endif + void setupChildProcess() _k_override_; +#endif // QT_VERSION < QT_VERSION_CHECK(6, 0, 0) +#endif // Q_OS_WIN private Q_SLOTS: // called when data is received from the terminal process @@ -176,4 +191,6 @@ private: }; } +#undef ParentClass + #endif // PTY_H diff --git a/src/SSHProcessInfo.cpp b/src/SSHProcessInfo.cpp index a59bdc2b2..06d625d97 100644 --- a/src/SSHProcessInfo.cpp +++ b/src/SSHProcessInfo.cpp @@ -8,6 +8,7 @@ #include "SSHProcessInfo.h" // Unix +#ifndef Q_OS_WIN #include #include #include @@ -15,6 +16,7 @@ #include #include #include +#endif // Q_OS_WIN // Qt #include @@ -177,6 +179,9 @@ QString SSHProcessInfo::format(const QString &input) const output.replace(QLatin1String("%U"), _user + QLatin1Char('@')); } +#ifdef Q_OS_WIN + // TODO +#else // test whether host is an ip address // in which case 'short host' and 'full host' // markers in the input string are replaced with @@ -196,6 +201,6 @@ QString SSHProcessInfo::format(const QString &input) const } output.replace(QLatin1String("%H"), fullHost); output.replace(QLatin1String("%c"), _command); - +#endif return output; } diff --git a/src/UnixProcessInfo.cpp b/src/UnixProcessInfo.cpp index 8d38fa7b2..bed0feec7 100644 --- a/src/UnixProcessInfo.cpp +++ b/src/UnixProcessInfo.cpp @@ -7,6 +7,7 @@ // Own #include "UnixProcessInfo.h" +#ifndef Q_OS_WIN // Unix #include #include @@ -83,3 +84,5 @@ void UnixProcessInfo::readUserName() } delete[] getpwBuffer; } + +#endif // Q_OS_WIN diff --git a/src/UnixProcessInfo.h b/src/UnixProcessInfo.h index 4e8b344f7..414dc4d90 100644 --- a/src/UnixProcessInfo.h +++ b/src/UnixProcessInfo.h @@ -11,6 +11,7 @@ namespace Konsole { +#ifndef Q_OS_WIN /** * Implementation of ProcessInfo for Unix platforms which uses * the /proc filesystem @@ -48,7 +49,7 @@ private: */ virtual bool readArguments(int pid) = 0; }; - +#endif } #endif diff --git a/src/Vt102Emulation.cpp b/src/Vt102Emulation.cpp index 871a822c4..724de7ae3 100644 --- a/src/Vt102Emulation.cpp +++ b/src/Vt102Emulation.cpp @@ -10,7 +10,6 @@ // Standard #include -#include // Qt #include diff --git a/src/history/HistoryFile.cpp b/src/history/HistoryFile.cpp index 44e8e61f9..8d2819213 100644 --- a/src/history/HistoryFile.cpp +++ b/src/history/HistoryFile.cpp @@ -14,7 +14,9 @@ // System #include +#ifndef Q_OS_WIN #include +#endif // Qt #include @@ -91,7 +93,11 @@ HistoryFile::HistoryFile() // and writing. This guarantees the file won't remain // in filesystem after process termination, even when // there was a crash. +#ifndef Q_OS_WIN unlink(QFile::encodeName(_tmpFile.fileName()).constData()); +#else + // TODO Windows +#endif } } } diff --git a/src/profile/Profile.cpp b/src/profile/Profile.cpp index a96bb5b16..bfc2c4df0 100644 --- a/src/profile/Profile.cpp +++ b/src/profile/Profile.cpp @@ -24,11 +24,13 @@ #include "ProfileGroup.h" #include "config-konsole.h" +#ifndef Q_OS_WIN #ifdef HAVE_GETPWUID #include #include #include -#endif +#endif // HAVE_GETPWUID +#endif // Q_OS_WIN #if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 97, 0) #include @@ -179,6 +181,7 @@ static const char BUILTIN_UNTRANSLATED_NAME_CHAR[] = "Built-in"; static QString defaultShell() { +#ifndef Q_OS_WIN #if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 97, 0) if (!KSandbox::isFlatpak()) { return QString::fromUtf8(qgetenv("SHELL")); @@ -203,6 +206,10 @@ static QString defaultShell() #else return QString::fromUtf8(qgetenv("SHELL")); #endif +#else // Q_OS_WIN + // TODO Windows + return QString(); +#endif // Q_OS_WIN } void Profile::fillTableWithDefaultNames() diff --git a/src/session/Session.cpp b/src/session/Session.cpp index 5783bc429..7ed5cf86c 100644 --- a/src/session/Session.cpp +++ b/src/session/Session.cpp @@ -13,7 +13,10 @@ // Standard #include #include + +#ifndef Q_OS_WIN #include +#endif // Qt #include @@ -28,8 +31,12 @@ #include #include #include + +#ifndef Q_OS_WIN #include +#endif #include + #include // Konsole @@ -52,6 +59,7 @@ #include "terminalDisplay/TerminalFonts.h" #include "terminalDisplay/TerminalScrollBar.h" +#ifndef Q_OS_WIN // Linux #if HAVE_GETPWUID #include @@ -61,6 +69,7 @@ #if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 97, 0) #include #endif +#endif // Q_OS_WIN using namespace Konsole; @@ -144,7 +153,11 @@ void Session::openTeletype(int fd, bool runShell) connect(_emulation, &Konsole::Emulation::useUtf8Request, _shellProcess, &Konsole::Pty::setUtf8Mode); // get notified when the pty process is finished +#ifndef Q_OS_WIN connect(_shellProcess, QOverload::of(&Konsole::Pty::finished), this, &Konsole::Session::done); +#else + // FIXME: Windows! +#endif // emulator size connect(_emulation, &Konsole::Emulation::imageSizeChanged, this, &Konsole::Session::updateWindowSize); @@ -196,7 +209,11 @@ void Session::setDarkBackground(bool darkBackground) bool Session::isRunning() const { +#ifdef Q_OS_WIN + return false; +#else return (_shellProcess != nullptr) && (_shellProcess->state() == QProcess::Running); +#endif } bool Session::hasFocus() const @@ -481,11 +498,16 @@ void Session::run() _shellProcess->setFlowControlEnabled(_flowControlEnabled); _shellProcess->setEraseChar(_emulation->eraseChar()); +#ifndef Q_OS_WIN _shellProcess->setUseUtmp(_addToUtmp); +#endif + +#ifndef Q_OS_WIN #if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 97, 0) if (KSandbox::isFlatpak()) { _shellProcess->pty()->setCTtyEnabled(false); // not possibly inside sandbox } +#endif #endif // this is not strictly accurate use of the COLORFGBG variable. This does not @@ -505,6 +527,7 @@ void Session::run() const QString dbusObject = QStringLiteral("/Sessions/%1").arg(QString::number(_sessionId)); addEnvironmentEntry(QStringLiteral("KONSOLE_DBUS_SESSION=%1").arg(dbusObject)); +#ifndef Q_OS_WIN #if KCOREADDONS_VERSION >= QT_VERSION_CHECK(5, 97, 0) const auto originalEnvironment = _shellProcess->environment(); _shellProcess->setProgram(exec); @@ -517,9 +540,18 @@ void Session::run() int result = _shellProcess->start(exec, arguments, _environment); #endif +#else // Q_OS_WIN + // FIXME + int result = -1; +#endif + if (result < 0) { terminalWarning(i18n("Could not start program '%1' with arguments '%2'.", exec, arguments.join(QLatin1String(" ")))); +#ifndef Q_OS_WIN terminalWarning(_shellProcess->errorString()); +#else + // FIXME windows +#endif return; } @@ -800,6 +832,7 @@ void Session::refresh() void Session::sendSignal(int signal) { +#ifndef Q_OS_WIN const ProcessInfo *process = getProcessInfo(); bool ok = false; int pid; @@ -810,6 +843,9 @@ void Session::sendSignal(int signal) } else { qWarning() << "foreground process id not set, unable to send signal " << signal; } +#else + // FIXME: Can we do this on windows? +#endif } void Session::reportColor(SessionAttributes r, const QColor &c, uint terminator) @@ -839,6 +875,7 @@ void Session::reportBackgroundColor(const QColor &c, uint terminator) bool Session::kill(int signal) { +#ifndef Q_OS_WIN if (processId() <= 0) { return false; } @@ -850,6 +887,9 @@ bool Session::kill(int signal) } else { return false; } +#else + return false; +#endif } void Session::close() @@ -868,6 +908,10 @@ void Session::close() bool Session::closeInNormalWay() { +#ifdef Q_OS_WIN + // FIXME windows impl here + return true; +#else _autoClose = true; _closePerUserRequest = true; @@ -892,6 +936,7 @@ bool Session::closeInNormalWay() qWarning() << "Process " << processId() << " did not die with SIGHUP"; _shellProcess->closePty(); return (_shellProcess->waitForFinished(1000)); +#endif } bool Session::closeInForceWay() @@ -899,12 +944,17 @@ bool Session::closeInForceWay() _autoClose = true; _closePerUserRequest = true; +#ifdef Q_OS_WIN + // FIXME windows impl here + return false; +#else if (kill(SIGKILL)) { return true; } else { qWarning() << "Process " << processId() << " did not die with SIGKILL"; return false; } +#endif } void Session::sendTextToTerminal(const QString &text, const QChar &eol) const @@ -963,8 +1013,12 @@ void Session::sendMouseEvent(int buttons, int column, int line, int eventType) void Session::done(int exitCode, QProcess::ExitStatus exitStatus) { +#ifndef Q_OS_WIN // This slot should be triggered only one time disconnect(_shellProcess, QOverload::of(&Konsole::Pty::finished), this, &Konsole::Session::done); +#else + // FIXME Windows +#endif if (!_autoClose) { _userTitle = i18nc("@info:shell This session is done", "Finished"); @@ -1600,7 +1654,11 @@ void Session::setPreferredSize(const QSize &size) int Session::processId() const { +#ifndef Q_OS_WIN return _shellProcess->processId(); +#else + return 0; +#endif } void Session::setTitle(int role, const QString &title) diff --git a/src/session/SessionController.cpp b/src/session/SessionController.cpp index 84d23b5a5..ab262246c 100644 --- a/src/session/SessionController.cpp +++ b/src/session/SessionController.cpp @@ -915,6 +915,7 @@ void SessionController::setupExtraActions() action->setText(i18n("Reset Font Size")); collection->setDefaultShortcut(action, Qt::CTRL | Qt::ALT | Qt::Key_0); +#ifndef Q_OS_WIN // Send signal auto *sendSignalActions = collection->add(QStringLiteral("send-signal")); sendSignalActions->setText(i18n("Send Signal")); @@ -959,6 +960,7 @@ void SessionController::setupExtraActions() action->setText(i18n("User Signal &2") + QStringLiteral(" (USR2)")); action->setData(SIGUSR2); sendSignalActions->addAction(action); +#endif } void SessionController::switchProfile(const Profile::Ptr &profile) diff --git a/src/widgets/KonsolePrintManager.cpp b/src/widgets/KonsolePrintManager.cpp index ee8a7579e..89426825f 100644 --- a/src/widgets/KonsolePrintManager.cpp +++ b/src/widgets/KonsolePrintManager.cpp @@ -48,7 +48,8 @@ void KonsolePrintManager::printRequest(pPrintContent pContent, QWidget *parent) dialog->setOptionTabs({options}); dialog->setWindowTitle(i18n("Print Shell")); - QObject::connect(dialog, QOverload<>::of(&QPrintDialog::accepted), options, &Konsole::PrintOptions::saveSettings); + // Make MSVC happy by using ultra verbose static_cast :( + QObject::connect(dialog, static_cast(&QPrintDialog::accepted), options, &Konsole::PrintOptions::saveSettings); if (dialog->exec() != QDialog::Accepted) { return; }