akabeioptions.cpp 3.74 KB
Newer Older
1 2
/*
 * This file is part of the Chakra project
3
 * Definitions for the operations and options objects
4 5 6 7 8 9 10 11 12 13 14

   Copyright (C) 2011 Lisa Vitolo <shainer@chakra-project.org>

   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.
*/

#include "akabeioptions.h"

Lisa's avatar
Lisa committed
15
AkabeiOption::AkabeiOption(APM::OptionName n, QString const& cmdShort, QString const& cmdLong, QString const& desc, QString const& argname)
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
    : m_name(n)
    , m_commandShort(cmdShort)
    , m_commandLong(cmdLong)
    , m_description(desc)
    , m_argname(argname)
{}

APM::OptionName AkabeiOption::name() const
{
    return m_name;
}

QString AkabeiOption::commandShort() const
{
    return m_commandShort;
}

QString AkabeiOption::commandLong() const
{
    return m_commandLong;
}

Lisa's avatar
Lisa committed
38
QString AkabeiOption::description() const
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
{
    return m_description;
}

QString AkabeiOption::argname() const
{
    return m_argname;
}

bool AkabeiOption::hasArgs() const
{
    return !m_argname.isEmpty();
}

QStringList AkabeiOption::arguments() const
{
    return m_args;
}

void AkabeiOption::operator=(const AkabeiOption& other)
59
{
60 61 62 63 64
    this->m_name = other.m_name;
    this->m_commandShort = other.m_commandShort;
    this->m_commandLong = other.m_commandLong;
    this->m_description = other.m_description;
    this->m_argname = other.m_argname;
65
    this->m_args = other.m_args;
66 67 68 69 70 71 72
}

bool AkabeiOption::operator==(const AkabeiOption& other) const
{
    return this->m_name == other.m_name;
}

73
void AkabeiOption::addArguments(QString const& args)
74 75 76 77 78 79 80
{
    m_args.append(args.split(","));
}

int AkabeiOption::length() const
{
    int size = m_commandLong.size();
81

82 83 84
    if (!m_commandShort.isEmpty()) {
        size += DASH + COMMA + m_commandShort.size();
    }
85

86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
    if (hasArgs()) {
        size += m_argname.size() + QUOTES;
    }

    return size;
}

uint qHash(AkabeiOption const& obj)
{
    return qHash(obj.name());
}

AkabeiOperation::AkabeiOperation()
    : m_name(APM::None)
{}

Lisa's avatar
Lisa committed
102
AkabeiOperation::AkabeiOperation(APM::OperationType t, APM::OperationName n, QString const& cmd, QString const& cmdLong, QString const& desc, bool a)
103 104 105 106
    : m_type(t)
    , m_name(n)
    , m_commandShort(cmd)
    , m_commandLong(cmdLong)
107
    , m_description(desc)
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122
    , m_freeArgs(a)
{}

void AkabeiOperation::addConnectionWithOption(APM::OptionName opt)
{
    if (!m_options.contains(opt)) {
        m_options.append(opt);
    }
}

bool AkabeiOperation::isOptionSupported(APM::OptionName opt)
{
    return m_options.contains(opt);
}

123 124 125 126 127
APM::OperationType AkabeiOperation::type() const
{
    return m_type;
}

128 129 130 131 132
APM::OperationName AkabeiOperation::name() const
{
    return m_name;
}

133
QString AkabeiOperation::commandShort() const
134
{
135 136 137 138 139 140
    return m_commandShort;
}

QString AkabeiOperation::commandLong() const
{
    return m_commandLong;
141 142
}

Lisa's avatar
Lisa committed
143 144 145 146 147
void AkabeiOperation::setCommandLong(QString const& cmdLong)
{
    m_commandLong = cmdLong;
}

Lisa's avatar
Lisa committed
148
QString AkabeiOperation::description() const
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
{
    return m_description;
}

bool AkabeiOperation::hasFreeArgs() const
{
    return m_freeArgs;
}

QList<APM::OptionName> AkabeiOperation::options() const
{
    return m_options;
}

void AkabeiOperation::operator=(const AkabeiOperation& other)
{
165
    this->m_type = other.m_type;
166
    this->m_name = other.m_name;
167 168
    this->m_commandShort = other.m_commandShort;
    this->m_commandLong = other.m_commandLong;
169 170 171 172
    this->m_description = other.m_description;
    this->m_freeArgs = other.m_freeArgs;
    this->m_options = other.m_options;
}
173 174 175 176

int AkabeiOperation::length() const
{
    int size = m_commandLong.size();
177

178 179 180 181 182 183
    if (!m_commandShort.isEmpty()) {
        size += DASH + COMMA + m_commandShort.size();
    }

    return size;
}