home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kleo / cryptoconfig.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-05-14  |  11.2 KB  |  388 lines

  1. /*
  2.     cryptoconfig.h
  3.  
  4.     This file is part of libkleopatra, the KDE keymanagement library
  5.     Copyright (c) 2004 KlarΣlvdalens Datakonsult AB
  6.  
  7.     Libkleopatra is free software; you can redistribute it and/or
  8.     modify it under the terms of the GNU General Public License as
  9.     published by the Free Software Foundation; either version 2 of the
  10.     License, or (at your option) any later version.
  11.  
  12.     Libkleopatra is distributed in the hope that it will be useful,
  13.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  14.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  15.     General Public License for more details.
  16.  
  17.     You should have received a copy of the GNU General Public License
  18.     along with this program; if not, write to the Free Software
  19.     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  20.  
  21.     In addition, as a special exception, the copyright holders give
  22.     permission to link the code of this program with any edition of
  23.     the Qt library by Trolltech AS, Norway (or with modified versions
  24.     of Qt that use the same license as Qt), and distribute linked
  25.     combinations including the two.  You must obey the GNU General
  26.     Public License in all respects for all of the code used other than
  27.     Qt.  If you modify this file, you may extend this exception to
  28.     your version of the file, but you are not obligated to do so.  If
  29.     you do not wish to do so, delete this exception statement from
  30.     your version.
  31. */
  32.  
  33. #ifndef CRYPTOCONFIG_H
  34. #define CRYPTOCONFIG_H
  35.  
  36. #ifdef __cplusplus
  37. /* we read this file from a C compiler, and are only interested in the
  38.  * enums... */
  39.  
  40. #include <kurl.h>
  41.  
  42. /* Start reading this file from the bottom up :) */
  43.  
  44. namespace Kleo {
  45.  
  46.   /**
  47.    * Description of a single option
  48.    */
  49.   class CryptoConfigEntry {
  50.  
  51.   public:
  52. #endif /* __cplusplus */
  53.     /**
  54.        @li basic    This option should always be offered to the user.
  55.        @li advanced    This option may be offered to advanced users.
  56.        @li expert    This option should only be offered to expert users.
  57.        */
  58.     enum Level { Level_Basic = 0,
  59.                  Level_Advanced = 1,
  60.                  Level_Expert = 2 };
  61.  
  62.     /**
  63.        Type of the argument
  64.        @li ArgType_None    The option is set or not set, but no argument.
  65.        @li ArgType_String    An unformatted string.
  66.        @li ArgType_Int        A signed integer number.
  67.        @li ArgType_UInt    An unsigned integer number.
  68.        @li ArgType_Path    A string that describes the pathname of a file.
  69.        The file does not necessarily need to exist.
  70.        Separated from string so that e.g. a KURLRequester can be used.
  71.        @li ArgType_DirPath    A string that describes the pathname of a directory.
  72.        The directory does not necessarily need to exist.
  73.        Separated from path so that e.g. a KURLRequester can be used which only
  74.        allows directories to be selected.
  75.        @li ArgType_URL        A URL
  76.        @li ArgType_LDAPURL    A LDAP URL
  77.        Separated from URL so that a more specific widget can be shown, hiding the url syntax
  78.     */
  79.     enum ArgType { ArgType_None = 0,
  80.                    ArgType_String = 1,
  81.                    ArgType_Int = 2,
  82.                    ArgType_UInt = 3,
  83.                    ArgType_Path = 4,
  84.                    ArgType_URL = 5,
  85.                    ArgType_LDAPURL = 6,
  86.                    ArgType_DirPath = 7 };
  87.  
  88. #ifdef __cplusplus
  89.     virtual ~CryptoConfigEntry() {}
  90.  
  91.     /**
  92.      * Return the internal name of this entry
  93.      */
  94.     virtual QString name() const = 0;
  95.  
  96.     /**
  97.      * @return user-visible description of this entry
  98.      */
  99.     virtual QString description() const = 0;
  100.  
  101.     /**
  102.      * @return true if the argument is optional
  103.      */
  104.     virtual bool isOptional() const = 0;
  105.  
  106.     /**
  107.      * @return true if the entry is readonly
  108.      */
  109.     virtual bool isReadOnly() const = 0;
  110.  
  111.     /**
  112.      * @return true if the argument can be given multiple times
  113.      */
  114.     virtual bool isList() const = 0;
  115.  
  116.     /**
  117.      * @return true if the argument can be changed at runtime
  118.      */
  119.     virtual bool isRuntime() const = 0;
  120.  
  121.     /**
  122.      * User level
  123.      */
  124.     virtual Level level() const = 0;
  125.  
  126.     /**
  127.      * Argument type
  128.      */
  129.     virtual ArgType argType() const = 0;
  130.  
  131.     /**
  132.      * Return true if the option is set, i.e. different from default
  133.      */
  134.     virtual bool isSet() const = 0;
  135.  
  136.     /**
  137.      * Return value as a bool (only allowed for ArgType_None)
  138.      */
  139.     virtual bool boolValue() const = 0;
  140.  
  141.     /**
  142.      * Return value as a string (available for all argtypes)
  143.      * The returned string can be empty (explicitely set to empty) or null (not set).
  144.      */
  145.     virtual QString stringValue() const = 0;
  146.  
  147.     /**
  148.      * Return value as a signed int
  149.      */
  150.     virtual int intValue() const = 0;
  151.  
  152.     /**
  153.      * Return value as an unsigned int
  154.      */
  155.     virtual unsigned int uintValue() const = 0;
  156.  
  157.     /**
  158.      * Return value as a URL (only meaningful for Path and URL argtypes)
  159.      */
  160.     virtual KURL urlValue() const = 0;
  161.  
  162.     /**
  163.      * Return number of times the option is set (only valid for ArgType_None, if isList())
  164.      */
  165.     virtual unsigned int numberOfTimesSet() const = 0;
  166.  
  167.     /**
  168.      * Return value as a list of strings (mostly meaningful for String, Path and URL argtypes, if isList())
  169.      */
  170.     virtual QStringList stringValueList() const = 0;
  171.  
  172.     /**
  173.      * Return value as a list of signed ints
  174.      */
  175.     virtual QValueList<int> intValueList() const = 0;
  176.  
  177.     /**
  178.      * Return value as a list of unsigned ints
  179.      */
  180.     virtual QValueList<unsigned int> uintValueList() const = 0;
  181.  
  182.     /**
  183.      * Return value as a list of URLs (only meaningful for Path and URL argtypes, if isList())
  184.      */
  185.     virtual KURL::List urlValueList() const = 0;
  186.  
  187.     /**
  188.      * Reset an option to its default value
  189.      */
  190.     virtual void resetToDefault() = 0;
  191.  
  192.     /**
  193.      * Define whether the option is set or not (only allowed for ArgType_None)
  194.      * #### TODO: and for options with optional args
  195.      */
  196.     virtual void setBoolValue( bool ) = 0;
  197.  
  198.     /**
  199.      * Set string value (allowed for all argtypes)
  200.      */
  201.     virtual void setStringValue( const QString& ) = 0;
  202.  
  203.     /**
  204.      * Set a new signed int value
  205.      */
  206.     virtual void setIntValue( int ) = 0;
  207.  
  208.     /**
  209.      * Set a new unsigned int value
  210.      */
  211.     virtual void setUIntValue( unsigned int ) = 0;
  212.  
  213.     /**
  214.      * Set value as a URL (only meaningful for Path (if local) and URL argtypes)
  215.      */
  216.     virtual void setURLValue( const KURL& ) = 0;
  217.  
  218.     /**
  219.      * Set the number of times the option is set (only valid for ArgType_None, if isList())
  220.      */
  221.     virtual void setNumberOfTimesSet( unsigned int ) = 0;
  222.  
  223.     /**
  224.      * Set a new string-list value (only allowed for String, Path and URL argtypes, if isList())
  225.      */
  226.     virtual void setStringValueList( const QStringList& ) = 0;
  227.  
  228.     /**
  229.      * Set a new list of signed int values
  230.      */
  231.     virtual void setIntValueList( const QValueList<int>& ) = 0;
  232.  
  233.     /**
  234.      * Set a new list of unsigned int values
  235.      */
  236.     virtual void setUIntValueList( const QValueList<unsigned int>& ) = 0;
  237.  
  238.     /**
  239.      * Set value as a URL list (only meaningful for Path (if all URLs are local) and URL argtypes, if isList())
  240.      */
  241.     virtual void setURLValueList( const KURL::List& ) = 0;
  242.  
  243.     /**
  244.      * @return true if the value was changed
  245.      */
  246.     virtual bool isDirty() const = 0;
  247.   };
  248.  
  249.   /**
  250.    * Group containing a set of config options
  251.    */
  252.   class CryptoConfigGroup {
  253.  
  254.   public:
  255.     virtual ~CryptoConfigGroup() {}
  256.  
  257.     /**
  258.      * Return the internal name of this group
  259.      */
  260.     virtual QString name() const = 0;
  261.  
  262.     /**
  263.      * Return the name of the icon for this group
  264.      */
  265.     virtual QString iconName() const = 0;
  266.  
  267.     /**
  268.      * @return user-visible description of this group
  269.      */
  270.     virtual QString description() const = 0;
  271.  
  272.     /**
  273.      * User level
  274.      */
  275.     virtual CryptoConfigEntry::Level level() const = 0;
  276.  
  277.     /**
  278.      * Returns the list of entries that are known by this group.
  279.      *
  280.      * @return list of group entry names.
  281.      **/
  282.     virtual QStringList entryList() const = 0;
  283.  
  284.     /**
  285.      * @return the configuration object for a given entry in this group
  286.      * The object is owned by CryptoConfigGroup, don't delete it.
  287.      * Groups cannot be nested, so all entries returned here are pure entries, no groups.
  288.      */
  289.     virtual CryptoConfigEntry* entry( const QString& name ) const = 0;
  290.   };
  291.  
  292.   /**
  293.    * Crypto config for one component (e.g. gpg-agent, dirmngr etc.)
  294.    */
  295.   class CryptoConfigComponent {
  296.  
  297.   public:
  298.     virtual ~CryptoConfigComponent() {}
  299.  
  300.     /**
  301.      * Return the internal name of this component
  302.      */
  303.     virtual QString name() const = 0;
  304.  
  305.     /**
  306.      * Return the name of the icon for this component
  307.      */
  308.     virtual QString iconName() const = 0;
  309.  
  310.     /**
  311.      * Return user-visible description of this component
  312.      */
  313.     virtual QString description() const = 0;
  314.  
  315.     /**
  316.      * Returns the list of groups that are known about.
  317.      *
  318.      * @return list of group names. One of them can be "<nogroup>", which is the group where all
  319.      * "toplevel" options (belonging to no group) are.
  320.      */
  321.     virtual QStringList groupList() const = 0;
  322.  
  323.     /**
  324.      * @return the configuration object for a given group
  325.      * The object is owned by CryptoConfigComponent, don't delete it.
  326.      */
  327.     virtual CryptoConfigGroup* group( const QString& name ) const = 0;
  328.  
  329.   };
  330.  
  331.   /**
  332.    * Main interface to crypto configuration.
  333.    */
  334.   class CryptoConfig {
  335.  
  336.   public:
  337.     virtual ~CryptoConfig() {}
  338.  
  339.     /**
  340.      * Returns the list of known components (e.g. "gpg-agent", "dirmngr" etc.).
  341.      * Use @ref component() to retrieve more information about each one.
  342.      * @return list of component names.
  343.      **/
  344.     virtual QStringList componentList() const = 0;
  345.  
  346.     /**
  347.      * @return the configuration object for a given component
  348.      * The object is owned by CryptoConfig, don't delete it.
  349.      */
  350.     virtual CryptoConfigComponent* component( const QString& name ) const = 0;
  351.  
  352.     /**
  353.      * Convenience method to get hold of a single configuration entry when
  354.      * its component, group and name are known. This can be used to read
  355.      * the value and/or to set a value to it.
  356.      *
  357.      * @return the configuration object for a single configuration entry, 0 if not found.
  358.      * The object is owned by CryptoConfig, don't delete it.
  359.      */
  360.     CryptoConfigEntry* entry( const QString& componentName, const QString& groupName, const QString& entryName ) const {
  361.       const Kleo::CryptoConfigComponent* comp = component( componentName );
  362.       const Kleo::CryptoConfigGroup* group = comp ? comp->group( groupName ) : 0;
  363.       return group ? group->entry( entryName ) : 0;
  364.     }
  365.  
  366.     /**
  367.      * Write back changes
  368.      *
  369.      * @param runtime If this option is set, the changes will take effect at run-time, as
  370.      * far as this is possible.  Otherwise, they will take effect at the next
  371.      * start of the respective backend programs.
  372.      */
  373.     virtual void sync( bool runtime ) = 0;
  374.  
  375.     /**
  376.      * Tells the CryptoConfig to discard any cached information, including
  377.      * all components, groups and entries.
  378.      * Call this to free some memory when you won't be using the object
  379.      * for some time.
  380.      * DON'T call this if you're holding pointers to components, groups or entries.
  381.      */
  382.     virtual void clear() = 0;
  383.   };
  384.  
  385. }
  386. #endif /* __cplusplus */
  387. #endif /* CRYPTOCONFIG_H */
  388.