Blame lang/qt/src/cryptoconfig.h

Packit d7e8d0
/*
Packit d7e8d0
    cryptoconfig.h
Packit d7e8d0
Packit d7e8d0
    This file is part of qgpgme, the Qt API binding for gpgme
Packit d7e8d0
    Copyright (c) 2004 Klarälvdalens Datakonsult AB
Packit d7e8d0
    Copyright (c) 2016 by Bundesamt für Sicherheit in der Informationstechnik
Packit d7e8d0
    Software engineering by Intevation GmbH
Packit d7e8d0
Packit d7e8d0
    QGpgME is free software; you can redistribute it and/or
Packit d7e8d0
    modify it under the terms of the GNU General Public License as
Packit d7e8d0
    published by the Free Software Foundation; either version 2 of the
Packit d7e8d0
    License, or (at your option) any later version.
Packit d7e8d0
Packit d7e8d0
    QGpgME is distributed in the hope that it will be useful,
Packit d7e8d0
    but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit d7e8d0
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit d7e8d0
    General Public License for more details.
Packit d7e8d0
Packit d7e8d0
    You should have received a copy of the GNU General Public License
Packit d7e8d0
    along with this program; if not, write to the Free Software
Packit d7e8d0
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
Packit d7e8d0
Packit d7e8d0
    In addition, as a special exception, the copyright holders give
Packit d7e8d0
    permission to link the code of this program with any edition of
Packit d7e8d0
    the Qt library by Trolltech AS, Norway (or with modified versions
Packit d7e8d0
    of Qt that use the same license as Qt), and distribute linked
Packit d7e8d0
    combinations including the two.  You must obey the GNU General
Packit d7e8d0
    Public License in all respects for all of the code used other than
Packit d7e8d0
    Qt.  If you modify this file, you may extend this exception to
Packit d7e8d0
    your version of the file, but you are not obligated to do so.  If
Packit d7e8d0
    you do not wish to do so, delete this exception statement from
Packit d7e8d0
    your version.
Packit d7e8d0
*/
Packit d7e8d0
Packit d7e8d0
#ifndef CRYPTOCONFIG_H
Packit d7e8d0
#define CRYPTOCONFIG_H
Packit d7e8d0
Packit d7e8d0
#include "qgpgme_export.h"
Packit d7e8d0
#ifdef __cplusplus
Packit d7e8d0
/* we read this file from a C compiler, and are only interested in the
Packit d7e8d0
 * enums... */
Packit d7e8d0
Packit d7e8d0
#include <QUrl>
Packit d7e8d0
Packit d7e8d0
#include <vector>
Packit d7e8d0
Packit d7e8d0
/* Start reading this file from the bottom up :) */
Packit d7e8d0
Packit d7e8d0
namespace QGpgME
Packit d7e8d0
{
Packit d7e8d0
Packit d7e8d0
/**
Packit d7e8d0
 * Description of a single option
Packit d7e8d0
 */
Packit d7e8d0
class QGPGME_EXPORT CryptoConfigEntry
Packit d7e8d0
{
Packit d7e8d0
Packit d7e8d0
public:
Packit d7e8d0
#endif /* __cplusplus */
Packit d7e8d0
    /**
Packit d7e8d0
       @li basic        This option should always be offered to the user.
Packit d7e8d0
       @li advanced        This option may be offered to advanced users.
Packit d7e8d0
       @li expert        This option should only be offered to expert users.
Packit d7e8d0
       */
Packit d7e8d0
    enum Level { Level_Basic = 0,
Packit d7e8d0
                 Level_Advanced = 1,
Packit d7e8d0
                 Level_Expert = 2
Packit d7e8d0
               };
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
       Type of the argument
Packit d7e8d0
       @li ArgType_None        The option is set or not set, but no argument.
Packit d7e8d0
       @li ArgType_String        An unformatted string.
Packit d7e8d0
       @li ArgType_Int                A signed integer number.
Packit d7e8d0
       @li ArgType_UInt        An unsigned integer number.
Packit d7e8d0
       @li ArgType_Path        A string that describes the pathname of a file.
Packit d7e8d0
       The file does not necessarily need to exist.
Packit d7e8d0
       Separated from string so that e.g. a FileDialog can be used.
Packit d7e8d0
       @li ArgType_DirPath        A string that describes the pathname of a directory.
Packit d7e8d0
       The directory does not necessarily need to exist.
Packit d7e8d0
       Separated from path so that e.g. a FileDialog can be used which only
Packit d7e8d0
       allows directories to be selected.
Packit d7e8d0
       @li ArgType_LDAPURL        A LDAP URL
Packit d7e8d0
       Separated from URL so that a more specific widget can be shown, hiding the url syntax
Packit d7e8d0
    */
Packit d7e8d0
    enum ArgType { ArgType_None = 0,
Packit d7e8d0
                   ArgType_String = 1,
Packit d7e8d0
                   ArgType_Int = 2,
Packit d7e8d0
                   ArgType_UInt = 3,
Packit d7e8d0
                   ArgType_Path = 4,
Packit d7e8d0
                   /* Nr. 5 was URL historically. */
Packit d7e8d0
                   ArgType_LDAPURL = 6,
Packit d7e8d0
                   ArgType_DirPath = 7,
Packit d7e8d0
Packit d7e8d0
                   NumArgType
Packit d7e8d0
                 };
Packit d7e8d0
Packit d7e8d0
#ifdef __cplusplus
Packit d7e8d0
    virtual ~CryptoConfigEntry() {}
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return the internal name of this entry
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString name() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return user-visible description of this entry
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString description() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return "component/group/name"
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString path() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return true if the argument is optional
Packit d7e8d0
     */
Packit d7e8d0
    virtual bool isOptional() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return true if the entry is readonly
Packit d7e8d0
     */
Packit d7e8d0
    virtual bool isReadOnly() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return true if the argument can be given multiple times
Packit d7e8d0
     */
Packit d7e8d0
    virtual bool isList() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return true if the argument can be changed at runtime
Packit d7e8d0
     */
Packit d7e8d0
    virtual bool isRuntime() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * User level
Packit d7e8d0
     */
Packit d7e8d0
    virtual Level level() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Argument type
Packit d7e8d0
     */
Packit d7e8d0
    virtual ArgType argType() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return true if the option is set, i.e. different from default
Packit d7e8d0
     */
Packit d7e8d0
    virtual bool isSet() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as a bool (only allowed for ArgType_None)
Packit d7e8d0
     */
Packit d7e8d0
    virtual bool boolValue() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as a string (available for all argtypes)
Packit d7e8d0
     * The returned string can be empty (explicitly set to empty) or null (not set).
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString stringValue() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as a signed int
Packit d7e8d0
     */
Packit d7e8d0
    virtual int intValue() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as an unsigned int
Packit d7e8d0
     */
Packit d7e8d0
    virtual unsigned int uintValue() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as a URL (only meaningful for Path and URL argtypes)
Packit d7e8d0
     */
Packit d7e8d0
    virtual QUrl urlValue() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return number of times the option is set (only valid for ArgType_None, if isList())
Packit d7e8d0
     */
Packit d7e8d0
    virtual unsigned int numberOfTimesSet() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as a list of signed ints
Packit d7e8d0
     */
Packit d7e8d0
    virtual std::vector<int> intValueList() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as a list of unsigned ints
Packit d7e8d0
     */
Packit d7e8d0
    virtual std::vector<unsigned int> uintValueList() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return value as a list of URLs (only meaningful for Path and URL argtypes, if isList())
Packit d7e8d0
     */
Packit d7e8d0
    virtual QList<QUrl> urlValueList() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Reset an option to its default value
Packit d7e8d0
     */
Packit d7e8d0
    virtual void resetToDefault() = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Define whether the option is set or not (only allowed for ArgType_None)
Packit d7e8d0
     * #### TODO: and for options with optional args
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setBoolValue(bool) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set string value (allowed for all argtypes)
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setStringValue(const QString &) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set a new signed int value
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setIntValue(int) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set a new unsigned int value
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setUIntValue(unsigned int) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set value as a URL (only meaningful for Path (if local) and URL argtypes)
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setURLValue(const QUrl &) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set the number of times the option is set (only valid for ArgType_None, if isList())
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setNumberOfTimesSet(unsigned int) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set a new list of signed int values
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setIntValueList(const std::vector<int> &) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set a new list of unsigned int values
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setUIntValueList(const std::vector<unsigned int> &) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Set value as a URL list (only meaningful for Path (if all URLs are local) and URL argtypes, if isList())
Packit d7e8d0
     */
Packit d7e8d0
    virtual void setURLValueList(const QList<QUrl> &) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return true if the value was changed
Packit d7e8d0
     */
Packit d7e8d0
    virtual bool isDirty() const = 0;
Packit d7e8d0
Packit d7e8d0
    // Design change from here on we are closely bound to one implementation
Packit d7e8d0
    // of cryptoconfig. To avoid ABI breaks with every new function we
Packit d7e8d0
    // add real functions from now on.
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return a stringValueList.
Packit d7e8d0
     */
Packit d7e8d0
    QStringList stringValueList() const;
Packit d7e8d0
};
Packit d7e8d0
Packit d7e8d0
/**
Packit d7e8d0
 * Group containing a set of config options
Packit d7e8d0
 */
Packit d7e8d0
class QGPGME_EXPORT CryptoConfigGroup
Packit d7e8d0
{
Packit d7e8d0
Packit d7e8d0
public:
Packit d7e8d0
    virtual ~CryptoConfigGroup() {}
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return the internal name of this group
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString name() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return the name of the icon for this group
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString iconName() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return user-visible description of this group
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString description() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return "component/group"
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString path() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * User level
Packit d7e8d0
     */
Packit d7e8d0
    virtual CryptoConfigEntry::Level level() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Returns the list of entries that are known by this group.
Packit d7e8d0
     *
Packit d7e8d0
     * @return list of group entry names.
Packit d7e8d0
     **/
Packit d7e8d0
    virtual QStringList entryList() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return the configuration object for a given entry in this group
Packit d7e8d0
     * The object is owned by CryptoConfigGroup, don't delete it.
Packit d7e8d0
     * Groups cannot be nested, so all entries returned here are pure entries, no groups.
Packit d7e8d0
     */
Packit d7e8d0
    virtual CryptoConfigEntry *entry(const QString &name) const = 0;
Packit d7e8d0
};
Packit d7e8d0
Packit d7e8d0
/**
Packit d7e8d0
 * Crypto config for one component (e.g. gpg-agent, dirmngr etc.)
Packit d7e8d0
 */
Packit d7e8d0
class QGPGME_EXPORT CryptoConfigComponent
Packit d7e8d0
{
Packit d7e8d0
Packit d7e8d0
public:
Packit d7e8d0
    virtual ~CryptoConfigComponent() {}
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return the internal name of this component
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString name() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return the name of the icon for this component
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString iconName() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Return user-visible description of this component
Packit d7e8d0
     */
Packit d7e8d0
    virtual QString description() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Returns the list of groups that are known about.
Packit d7e8d0
     *
Packit d7e8d0
     * @return list of group names. One of them can be "<nogroup>", which is the group where all
Packit d7e8d0
     * "toplevel" options (belonging to no group) are.
Packit d7e8d0
     */
Packit d7e8d0
    virtual QStringList groupList() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return the configuration object for a given group
Packit d7e8d0
     * The object is owned by CryptoConfigComponent, don't delete it.
Packit d7e8d0
     */
Packit d7e8d0
    virtual CryptoConfigGroup *group(const QString &name) const = 0;
Packit d7e8d0
Packit d7e8d0
};
Packit d7e8d0
Packit d7e8d0
/**
Packit d7e8d0
 * Main interface to crypto configuration.
Packit d7e8d0
 */
Packit d7e8d0
class QGPGME_EXPORT CryptoConfig
Packit d7e8d0
{
Packit d7e8d0
Packit d7e8d0
public:
Packit d7e8d0
    virtual ~CryptoConfig() {}
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Returns the list of known components (e.g. "gpg-agent", "dirmngr" etc.).
Packit d7e8d0
     * Use @ref component() to retrieve more information about each one.
Packit d7e8d0
     * @return list of component names.
Packit d7e8d0
     **/
Packit d7e8d0
    virtual QStringList componentList() const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * @return the configuration object for a given component
Packit d7e8d0
     * The object is owned by CryptoConfig, don't delete it.
Packit d7e8d0
     */
Packit d7e8d0
    virtual CryptoConfigComponent *component(const QString &name) const = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Convenience method to get hold of a single configuration entry when
Packit d7e8d0
     * its component, group and name are known. This can be used to read
Packit d7e8d0
     * the value and/or to set a value to it.
Packit d7e8d0
     *
Packit d7e8d0
     * @return the configuration object for a single configuration entry, 0 if not found.
Packit d7e8d0
     * The object is owned by CryptoConfig, don't delete it.
Packit d7e8d0
     */
Packit d7e8d0
    CryptoConfigEntry *entry(const QString &componentName, const QString &groupName, const QString &entryName) const
Packit d7e8d0
    {
Packit d7e8d0
        const QGpgME::CryptoConfigComponent *comp = component(componentName);
Packit d7e8d0
        const QGpgME::CryptoConfigGroup *group = comp ? comp->group(groupName) : 0;
Packit d7e8d0
        return group ? group->entry(entryName) : 0;
Packit d7e8d0
    }
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Write back changes
Packit d7e8d0
     *
Packit d7e8d0
     * @param runtime this parameter is ignored. Changes will always
Packit d7e8d0
     * be made with --runtime set.
Packit d7e8d0
     */
Packit d7e8d0
    virtual void sync(bool runtime) = 0;
Packit d7e8d0
Packit d7e8d0
    /**
Packit d7e8d0
     * Tells the CryptoConfig to discard any cached information, including
Packit d7e8d0
     * all components, groups and entries.
Packit d7e8d0
     * Call this to free some memory when you won't be using the object
Packit d7e8d0
     * for some time.
Packit d7e8d0
     * DON'T call this if you're holding pointers to components, groups or entries.
Packit d7e8d0
     */
Packit d7e8d0
    virtual void clear() = 0;
Packit d7e8d0
};
Packit d7e8d0
Packit d7e8d0
}
Packit d7e8d0
#endif /* __cplusplus */
Packit d7e8d0
#endif /* CRYPTOCONFIG_H */