Add function executor shell
This commit is contained in:
68
KeyBorad/KeyBorad/LOGIC/Lgc_FunctionExecutor.cpp
Normal file
68
KeyBorad/KeyBorad/LOGIC/Lgc_FunctionExecutor.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
#include "LOGIC/Lgc_FunctionExecutor.h"
|
||||
|
||||
#include <QtCore/QUrl>
|
||||
#include <QtGui/QDesktopServices>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
||||
QString Lgc_Func_GetFunctionName(const Lgc_FunctionDefinition& Function)
|
||||
{
|
||||
return Function.Name.trimmed().isEmpty()
|
||||
? QStringLiteral("Unnamed Function")
|
||||
: Function.Name.trimmed();
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool Lgc_FunctionExecutor_Run(
|
||||
const Lgc_FunctionDefinition& Function,
|
||||
QString* p_TextStatus)
|
||||
{
|
||||
if (p_TextStatus != nullptr)
|
||||
{
|
||||
p_TextStatus->clear();
|
||||
}
|
||||
|
||||
switch (Function.Type)
|
||||
{
|
||||
case Lgc_FunctionType::None:
|
||||
if (p_TextStatus != nullptr)
|
||||
{
|
||||
*p_TextStatus = QStringLiteral("%1 has no executable action.")
|
||||
.arg(Lgc_Func_GetFunctionName(Function));
|
||||
}
|
||||
return false;
|
||||
|
||||
case Lgc_FunctionType::Shortcut:
|
||||
if (p_TextStatus != nullptr)
|
||||
{
|
||||
*p_TextStatus = QStringLiteral("Shortcut execution will be connected after transport is ready.");
|
||||
}
|
||||
return false;
|
||||
|
||||
case Lgc_FunctionType::ShortcutSequence:
|
||||
if (p_TextStatus != nullptr)
|
||||
{
|
||||
*p_TextStatus = QStringLiteral("Shortcut sequence execution will be connected after transport is ready.");
|
||||
}
|
||||
return false;
|
||||
|
||||
case Lgc_FunctionType::Website:
|
||||
{
|
||||
const QUrl Url = QUrl::fromUserInput(Function.WebsiteUrl.trimmed());
|
||||
const bool IsOpened = Url.isValid() && !Url.isEmpty() && QDesktopServices::openUrl(Url);
|
||||
|
||||
if (p_TextStatus != nullptr)
|
||||
{
|
||||
*p_TextStatus = IsOpened
|
||||
? QStringLiteral("Opened website: %1").arg(Url.toString())
|
||||
: QStringLiteral("Failed to open website for %1.").arg(Lgc_Func_GetFunctionName(Function));
|
||||
}
|
||||
|
||||
return IsOpened;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
27
KeyBorad/KeyBorad/LOGIC/Lgc_FunctionExecutor.h
Normal file
27
KeyBorad/KeyBorad/LOGIC/Lgc_FunctionExecutor.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
#include <QtCore/QString>
|
||||
#include <QtCore/QStringList>
|
||||
#include <QtCore/QtGlobal>
|
||||
|
||||
enum class Lgc_FunctionType : quint8
|
||||
{
|
||||
None = 0,
|
||||
Shortcut,
|
||||
ShortcutSequence,
|
||||
Website,
|
||||
};
|
||||
|
||||
struct Lgc_FunctionDefinition
|
||||
{
|
||||
int Id = 0;
|
||||
QString Name;
|
||||
QString Description;
|
||||
Lgc_FunctionType Type = Lgc_FunctionType::None;
|
||||
QStringList ShortcutTokens;
|
||||
QString WebsiteUrl;
|
||||
};
|
||||
|
||||
bool Lgc_FunctionExecutor_Run(
|
||||
const Lgc_FunctionDefinition& Function,
|
||||
QString* p_TextStatus);
|
||||
Reference in New Issue
Block a user