2023-02-23 12:47:39 +01:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include "commandline.h"
|
|
|
|
|
#include "environment.h"
|
|
|
|
|
#include "filepath.h"
|
2023-03-07 17:55:38 +01:00
|
|
|
#include "id.h"
|
2023-02-23 12:47:39 +01:00
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
|
|
namespace Utils {
|
|
|
|
|
class ProcessInterface;
|
|
|
|
|
|
|
|
|
|
template<typename R, typename... Params>
|
|
|
|
|
class Hook
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using Callback = std::function<R(Params...)>;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
Hook() = delete;
|
|
|
|
|
Hook(const Hook &other) = delete;
|
|
|
|
|
Hook(Hook &&other) = delete;
|
|
|
|
|
Hook &operator=(const Hook &other) = delete;
|
|
|
|
|
Hook &operator=(Hook &&other) = delete;
|
|
|
|
|
|
|
|
|
|
explicit Hook(Callback defaultCallback) { set(defaultCallback); }
|
|
|
|
|
|
|
|
|
|
void set(Callback cb) { m_callback = cb; }
|
|
|
|
|
R operator()(Params &&...params) { return m_callback(std::forward<Params>(params)...); }
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Callback m_callback;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
namespace Terminal {
|
|
|
|
|
struct HooksPrivate;
|
|
|
|
|
|
|
|
|
|
enum class ExitBehavior { Close, Restart, Keep };
|
|
|
|
|
|
|
|
|
|
struct OpenTerminalParameters
|
|
|
|
|
{
|
|
|
|
|
std::optional<CommandLine> shellCommand;
|
|
|
|
|
std::optional<FilePath> workingDirectory;
|
|
|
|
|
std::optional<Environment> environment;
|
|
|
|
|
ExitBehavior m_exitBehavior{ExitBehavior::Close};
|
2023-03-07 17:55:38 +01:00
|
|
|
std::optional<Id> identifier{std::nullopt};
|
2023-02-23 12:47:39 +01:00
|
|
|
};
|
|
|
|
|
|
2023-02-25 10:47:21 +01:00
|
|
|
struct NameAndCommandLine
|
|
|
|
|
{
|
|
|
|
|
QString name;
|
|
|
|
|
CommandLine commandLine;
|
|
|
|
|
};
|
|
|
|
|
|
2023-03-01 09:57:43 +01:00
|
|
|
QTCREATOR_UTILS_EXPORT FilePath defaultShellForDevice(const FilePath &deviceRoot);
|
|
|
|
|
|
2023-02-23 12:47:39 +01:00
|
|
|
class QTCREATOR_UTILS_EXPORT Hooks
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
using OpenTerminalHook = Hook<void, const OpenTerminalParameters &>;
|
|
|
|
|
using CreateTerminalProcessInterfaceHook = Hook<ProcessInterface *>;
|
2023-02-25 10:47:21 +01:00
|
|
|
using GetTerminalCommandsForDevicesHook = Hook<QList<NameAndCommandLine>>;
|
2023-02-23 12:47:39 +01:00
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
static Hooks &instance();
|
2023-02-25 10:47:21 +01:00
|
|
|
~Hooks();
|
2023-02-23 12:47:39 +01:00
|
|
|
|
|
|
|
|
OpenTerminalHook &openTerminalHook();
|
|
|
|
|
CreateTerminalProcessInterfaceHook &createTerminalProcessInterfaceHook();
|
2023-02-25 10:47:21 +01:00
|
|
|
GetTerminalCommandsForDevicesHook &getTerminalCommandsForDevicesHook();
|
2023-02-23 12:47:39 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
Hooks();
|
|
|
|
|
std::unique_ptr<HooksPrivate> d;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Terminal
|
|
|
|
|
} // namespace Utils
|