kgpg
convert.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "convert.h"
00022
00023 #include <KGlobal>
00024 #include <KLocale>
00025
00026 #include "kgpgsettings.h"
00027
00028 namespace KgpgCore
00029 {
00030
00031 QString Convert::toString(const KgpgKeyAlgo &algorithm)
00032 {
00033 switch (algorithm)
00034 {
00035 case ALGO_RSA: return QString("RSA");
00036 case ALGO_DSA: return QString("DSA");
00037 case ALGO_ELGAMAL: return QString("ElGamal");
00038 case ALGO_DSA_ELGAMAL: return QString("DSA - ElGamal");
00039 case ALGO_UNKNOWN:
00040 default: return i18nc("Unknown algorithm", "Unknown");
00041 }
00042 }
00043
00044 QString Convert::toString(const KgpgKeyOwnerTrust &ownertrust)
00045 {
00046 switch (ownertrust)
00047 {
00048 case OWTRUST_UNDEFINED: return i18n("Do not Know");
00049 case OWTRUST_NONE: return i18n("Do NOT Trust");
00050 case OWTRUST_MARGINAL: return i18n("Marginally");
00051 case OWTRUST_FULL: return i18n("Fully");
00052 case OWTRUST_ULTIMATE: return i18n("Ultimately");
00053 case OWTRUST_UNKNOWN:
00054 default: return i18nc("Unknown trust in key owner", "Unknown");
00055 }
00056 }
00057
00058 QString Convert::toString(const KgpgKeyTrust &trust)
00059 {
00060 switch (trust)
00061 {
00062 case TRUST_INVALID: return i18nc("Invalid key", "Invalid");
00063 case TRUST_DISABLED: return i18nc("Disabled key", "Disabled");
00064 case TRUST_REVOKED: return i18n("Revoked");
00065 case TRUST_EXPIRED: return i18nc("Expired key", "Expired");
00066 case TRUST_UNDEFINED: return i18nc("Undefined key trust", "Undefined");
00067 case TRUST_NONE: return i18nc("No trust in key", "None");
00068 case TRUST_MARGINAL: return i18nc("Marginal trust in key", "Marginal");
00069 case TRUST_FULL: return i18nc("Full trust in key", "Full");
00070 case TRUST_ULTIMATE: return i18nc("Ultimate trust in key", "Ultimate");
00071 case TRUST_UNKNOWN:
00072 default: return i18nc("Unknown trust in key", "Unknown");
00073 }
00074 }
00075
00076 QColor Convert::toColor(const KgpgKeyTrust &trust)
00077 {
00078 switch (trust)
00079 {
00080 case TRUST_INVALID:
00081 case TRUST_DISABLED: return KGpgSettings::colorBad();
00082 case TRUST_EXPIRED: return KGpgSettings::colorExpired();
00083 case TRUST_MARGINAL: return KGpgSettings::colorMarginal();
00084 case TRUST_REVOKED: return KGpgSettings::colorRev();
00085 case TRUST_UNDEFINED:
00086 case TRUST_NONE: return KGpgSettings::colorUnknown();
00087 case TRUST_FULL: return KGpgSettings::colorGood();
00088 case TRUST_ULTIMATE: return KGpgSettings::colorUltimate();
00089 case TRUST_UNKNOWN:
00090 default: return KGpgSettings::colorUnknown();
00091 }
00092 }
00093
00094 QString Convert::toString(const QDate &date)
00095 {
00096 return KGlobal::locale()->formatDate(date, KLocale::ShortDate);
00097 }
00098
00099 KgpgKeyAlgo Convert::toAlgo(const uint &v)
00100 {
00101 switch (v)
00102 {
00103 case 1: return ALGO_RSA;
00104 case 16:
00105 case 20: return ALGO_ELGAMAL;
00106 case 17: return ALGO_DSA;
00107 default: return ALGO_UNKNOWN;
00108 }
00109 }
00110
00111 KgpgKeyAlgo Convert::toAlgo(const QString &s)
00112 {
00113 bool b;
00114 unsigned int u = s.toUInt(&b);
00115 return b ? toAlgo(u) : ALGO_UNKNOWN;
00116 }
00117
00118 KgpgKeyTrust Convert::toTrust(const QChar &c)
00119 {
00120 switch (c.toAscii())
00121 {
00122 case 'o': return TRUST_UNKNOWN;
00123 case 'i': return TRUST_INVALID;
00124 case 'd': return TRUST_DISABLED;
00125 case 'r': return TRUST_REVOKED;
00126 case 'e': return TRUST_EXPIRED;
00127 case 'q': return TRUST_UNDEFINED;
00128 case 'n': return TRUST_NONE;
00129 case 'm': return TRUST_MARGINAL;
00130 case 'f': return TRUST_FULL;
00131 case 'u': return TRUST_ULTIMATE;
00132 default: return TRUST_UNKNOWN;
00133 }
00134 }
00135
00136 KgpgKeyTrust Convert::toTrust(const QString &s)
00137 {
00138 return s.isEmpty() ? TRUST_UNKNOWN : toTrust(s[0]);
00139 }
00140
00141 KgpgKeyOwnerTrust Convert::toOwnerTrust(const QChar &c)
00142 {
00143 switch (c.toAscii())
00144 {
00145 case 'n': return OWTRUST_NONE;
00146 case 'm': return OWTRUST_MARGINAL;
00147 case 'u': return OWTRUST_ULTIMATE;
00148 case 'f': return OWTRUST_FULL;
00149 default: return OWTRUST_UNDEFINED;
00150 }
00151 }
00152
00153 KgpgKeyOwnerTrust Convert::toOwnerTrust(const QString &s)
00154 {
00155 return s.isEmpty() ? OWTRUST_UNDEFINED : toOwnerTrust(s[0]);
00156 }
00157
00158 }