1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
/*
* BuiltinDirectoryPlugin.h - declaration of BuiltinDirectoryPlugin class
*
* Copyright (c) 2017-2021 Tobias Junghans <tobydox@veyon.io>
*
* This file is part of Veyon - https://veyon.io
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public
* License along with this program (see COPYING); if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*
*/
#pragma once
#include "CommandLinePluginInterface.h"
#include "CommandLineIO.h"
#include "ConfigurationPagePluginInterface.h"
#include "BuiltinDirectoryConfiguration.h"
#include "NetworkObject.h"
#include "NetworkObjectDirectoryPluginInterface.h"
class QFile;
class BuiltinDirectoryPlugin : public QObject,
PluginInterface,
NetworkObjectDirectoryPluginInterface,
ConfigurationPagePluginInterface,
CommandLinePluginInterface,
CommandLineIO
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "io.veyon.Veyon.Plugins.BuiltinDirectory")
Q_INTERFACES(PluginInterface
NetworkObjectDirectoryPluginInterface
ConfigurationPagePluginInterface
CommandLinePluginInterface)
public:
explicit BuiltinDirectoryPlugin( QObject* paren = nullptr );
~BuiltinDirectoryPlugin() override = default;
Plugin::Uid uid() const override
{
return QStringLiteral("14bacaaa-ebe5-449c-b881-5b382f952571");
}
QVersionNumber version() const override
{
return QVersionNumber( 1, 1 );
}
QString name() const override
{
return QStringLiteral( "BuiltinDirectory" );
}
QString description() const override
{
return tr( "Network object directory which stores objects in local configuration" );
}
QString vendor() const override
{
return QStringLiteral( "Veyon Community" );
}
QString copyright() const override
{
return QStringLiteral( "Tobias Junghans" );
}
Plugin::Flags flags() const override
{
return Plugin::ProvidesDefaultImplementation;
}
void upgrade( const QVersionNumber& oldVersion ) override;
QString directoryName() const override
{
return tr( "Builtin (computers and locations in local configuration)" );
}
NetworkObjectDirectory* createNetworkObjectDirectory( QObject* parent ) override;
ConfigurationPage* createConfigurationPage() override;
QString commandLineModuleName() const override
{
return QStringLiteral( "networkobjects" );
}
QString commandLineModuleHelp() const override
{
return tr( "Commands for managing the builtin network object directory" );
}
QStringList commands() const override;
QString commandHelp( const QString& command ) const override;
public Q_SLOTS:
CommandLinePluginInterface::RunResult handle_help( const QStringList& arguments );
CommandLinePluginInterface::RunResult handle_add( const QStringList& arguments );
CommandLinePluginInterface::RunResult handle_clear( const QStringList& arguments );
CommandLinePluginInterface::RunResult handle_dump( const QStringList& arguments );
CommandLinePluginInterface::RunResult handle_list( const QStringList& arguments );
CommandLinePluginInterface::RunResult handle_remove( const QStringList& arguments );
CommandLinePluginInterface::RunResult handle_import( const QStringList& arguments );
CommandLinePluginInterface::RunResult handle_export( const QStringList& arguments );
private:
void listObjects( const QJsonArray& objects, const NetworkObject& parent );
static QStringList dumpNetworkObject( const NetworkObject& object );
static QString listNetworkObject( const NetworkObject& object );
static QString networkObjectTypeName( const NetworkObject& object );
static NetworkObject::Type parseNetworkObjectType( const QString& typeName );
CommandLinePluginInterface::RunResult saveConfiguration();
bool importFile( QFile& inputFile, const QString& regExWithVariables, const QString& location );
bool exportFile( QFile& outputFile, const QString& formatString, const QString& location );
NetworkObject findNetworkObject( const QString& uidOrName ) const;
static NetworkObject toNetworkObject( const QString& line, const QString& regExWithVariables, QString& location );
static QString toFormattedString( const NetworkObject& networkObject, const QString& formatString, const QString& location );
static QStringList importExportPlaceholders();
static QString typeNameLocation()
{
return tr( "Location" );
}
static QString typeNameComputer()
{
return tr( "Computer" );
}
static QString typeNameRoot()
{
return tr( "Root" );
}
static QString importCommand()
{
return QStringLiteral("import");
}
static QString exportCommand()
{
return QStringLiteral("export");
}
static QString addCommand()
{
return QStringLiteral("add");
}
static QString removeCommand()
{
return QStringLiteral("remove");
}
static QString locationArgument()
{
return QStringLiteral("location");
}
static QString formatArgument()
{
return QStringLiteral("format");
}
static QString regexArgument()
{
return QStringLiteral("regex");
}
static QString typeLocation()
{
return QStringLiteral("location");
}
static QString typeComputer()
{
return QStringLiteral("computer");
}
static QString exampleRoom()
{
return tr( "\"Room 01\"" );
}
static QString exampleComputer()
{
return tr( "\"Computer 01\"" );
}
BuiltinDirectoryConfiguration m_configuration;
QMap<QString, QString> m_commands;
};
|