• Skip to content
  • Skip to link menu
KDE 4.2 API Reference
  • KDE API Reference
  • kdeutils
  • Sitemap
  • Contact Us
 

kgpg

convert.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (C) 2006 by Jimmy Gilles                                    *
00003  *   jimmygilles@gmail.com                                                 *
00004  *                                                                         *
00005  *   This program is free software; you can redistribute it and/or modify  *
00006  *   it under the terms of the GNU General Public License as published by  *
00007  *   the Free Software Foundation; either version 2 of the License, or     *
00008  *   (at your option) any later version.                                   *
00009  *                                                                         *
00010  *   This program is distributed in the hope that it will be useful,       *
00011  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00012  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00013  *   GNU General Public License for more details.                          *
00014  *                                                                         *
00015  *   You should have received a copy of the GNU General Public License     *
00016  *   along with this program; if not, write to the                         *
00017  *   Free Software Foundation, Inc.,                                       *
00018  *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA          *
00019  ***************************************************************************/
00020 
00021 #include "convert.h"
00022 
00023 #include <KGlobal>
00024 #include <KLocale>
00025 
00026 #include "kgpgsettings.h"
00027 #include "images.h"
00028 
00029 namespace KgpgCore
00030 {
00031 
00032 QString Convert::toString(const KgpgKeyAlgo &algorithm)
00033 {
00034     switch (algorithm)
00035     {
00036         case ALGO_RSA:          return QString("RSA");
00037         case ALGO_DSA:          return QString("DSA");
00038         case ALGO_ELGAMAL:      return QString("ElGamal");
00039         case ALGO_DSA_ELGAMAL:  return QString("DSA - ElGamal");
00040         case ALGO_UNKNOWN:
00041         default:                return i18nc("Unknown algorithm", "Unknown");
00042     }
00043 }
00044 
00045 QString Convert::toString(const KgpgKeyOwnerTrust &ownertrust)
00046 {
00047     switch (ownertrust)
00048     {
00049         case OWTRUST_UNDEFINED: return i18n("Do not Know");
00050         case OWTRUST_NONE:      return i18n("Do NOT Trust");
00051         case OWTRUST_MARGINAL:  return i18n("Marginally");
00052         case OWTRUST_FULL:      return i18n("Fully");
00053         case OWTRUST_ULTIMATE:  return i18n("Ultimately");
00054         case OWTRUST_UNKNOWN:
00055         default:                return i18nc("Unknown trust in key owner", "Unknown");
00056     }
00057 }
00058 
00059 QString Convert::toString(const KgpgKeyTrust &trust)
00060 {
00061     switch (trust)
00062     {
00063         case TRUST_INVALID:     return i18nc("Invalid key", "Invalid");
00064         case TRUST_DISABLED:    return i18nc("Disabled key", "Disabled");
00065         case TRUST_REVOKED:     return i18n("Revoked");
00066         case TRUST_EXPIRED:     return i18nc("Expired key", "Expired");
00067         case TRUST_UNDEFINED:   return i18nc("Undefined key trust", "Undefined");
00068         case TRUST_NONE:        return i18nc("No trust in key", "None");
00069         case TRUST_MARGINAL:    return i18nc("Marginal trust in key", "Marginal");
00070         case TRUST_FULL:        return i18nc("Full trust in key", "Full");
00071         case TRUST_ULTIMATE:    return i18nc("Ultimate trust in key", "Ultimate");
00072         case TRUST_UNKNOWN:
00073         default:                return i18nc("Unknown trust in key", "Unknown");
00074     }
00075 }
00076 
00077 QColor Convert::toColor(const KgpgKeyTrust &trust)
00078 {
00079     switch (trust)
00080     {
00081         case TRUST_INVALID:
00082         case TRUST_DISABLED:    return KGpgSettings::colorBad();
00083         case TRUST_EXPIRED:     return KGpgSettings::colorExpired();
00084         case TRUST_MARGINAL:    return KGpgSettings::colorMarginal();
00085         case TRUST_REVOKED:     return KGpgSettings::colorRev();
00086         case TRUST_UNDEFINED:
00087         case TRUST_NONE:        return KGpgSettings::colorUnknown();
00088         case TRUST_FULL:        return KGpgSettings::colorGood();
00089         case TRUST_ULTIMATE:    return KGpgSettings::colorUltimate();
00090         case TRUST_UNKNOWN:
00091         default:                return KGpgSettings::colorUnknown();
00092     }
00093 }
00094 
00095 QString Convert::toString(const QDate &date)
00096 {
00097     return KGlobal::locale()->formatDate(date, KLocale::ShortDate);
00098 }
00099 
00100 KgpgKeyAlgo Convert::toAlgo(const uint &v)
00101 {
00102     switch (v)
00103     {
00104         case 1:      return ALGO_RSA;
00105         case 16:
00106         case 20:     return ALGO_ELGAMAL;
00107         case 17:     return ALGO_DSA;
00108         default:     return ALGO_UNKNOWN;
00109     }
00110 }
00111 
00112 KgpgKeyAlgo Convert::toAlgo(const QString &s)
00113 {
00114     bool b;
00115     unsigned int u = s.toUInt(&b);
00116     return b ? toAlgo(u) : ALGO_UNKNOWN;
00117 }
00118 
00119 KgpgKeyTrust Convert::toTrust(const QChar &c)
00120 {
00121     switch (c.toAscii())
00122     {
00123         case 'o':    return TRUST_UNKNOWN;
00124         case 'i':    return TRUST_INVALID;
00125         case 'd':    return TRUST_DISABLED;
00126         case 'r':    return TRUST_REVOKED;
00127         case 'e':    return TRUST_EXPIRED;
00128         case 'q':    return TRUST_UNDEFINED;
00129         case 'n':    return TRUST_NONE;
00130         case 'm':    return TRUST_MARGINAL;
00131         case 'f':    return TRUST_FULL;
00132         case 'u':    return TRUST_ULTIMATE;
00133         default:     return TRUST_UNKNOWN;
00134     }
00135 }
00136 
00137 KgpgKeyTrust Convert::toTrust(const QString &s)
00138 {
00139     return s.isEmpty() ? TRUST_UNKNOWN : toTrust(s[0]);
00140 }
00141 
00142 KgpgKeyOwnerTrust Convert::toOwnerTrust(const QChar &c)
00143 {
00144     switch (c.toAscii())
00145     {
00146         case 'n':     return OWTRUST_NONE;
00147         case 'm':     return OWTRUST_MARGINAL;
00148         case 'u':     return OWTRUST_ULTIMATE;
00149         case 'f':     return OWTRUST_FULL;
00150         default:      return OWTRUST_UNDEFINED;
00151     }
00152 }
00153 
00154 KgpgKeyOwnerTrust Convert::toOwnerTrust(const QString &s)
00155 {
00156     return s.isEmpty() ? OWTRUST_UNDEFINED : toOwnerTrust(s[0]);
00157 }
00158 
00159 QPixmap Convert::toPixmap(const KgpgItemType &t)
00160 {
00161     switch (t)
00162     {
00163         case ITYPE_GROUP:   return Images::group();
00164         case ITYPE_GSECRET:
00165         case ITYPE_SECRET:  return Images::orphan();
00166         case ITYPE_GPUBLIC:
00167         case ITYPE_SUB:
00168         case ITYPE_PUBLIC:  return Images::single();
00169         case ITYPE_GPAIR:
00170         case ITYPE_PAIR:    return Images::pair();
00171         case ITYPE_UID:     return Images::userId();
00172         case ITYPE_UAT:     return Images::photo();
00173         case ITYPE_REVSIGN: return Images::revoke();
00174         case ITYPE_SIGN:    return Images::signature();
00175     default:        Q_ASSERT(1);
00176                 return NULL;
00177     }
00178 }
00179 
00180 } // namespace KgpgCore

kgpg

Skip menu "kgpg"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdeutils

Skip menu "kdeutils"
  • ark
  • kcalc
  • kcharselect
  • kdessh
  • kdf
  • kfloppy
  • kgpg
  • ktimer
  • kwallet
  • okteta
  • printer-applet
  • superkaramba
  • sweeper
Generated for kdeutils by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal