diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,7 +18,7 @@ include(ECMQtDeclareLoggingCategory) include(ECMAddTests) -set(PIM_VERSION "5.2.42") +set(PIM_VERSION "5.2.43") set(KF5_VERSION "5.19.0") set(LIBKLEO_LIB_VERSION ${PIM_VERSION}) set(QT_REQUIRED_VERSION "5.4.0") diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -77,6 +77,7 @@ kleo/defaultkeyfilter.cpp kleo/kconfigbasedkeyfilter.cpp kleo/keyfiltermanager.cpp + kleo/formatting.cpp ) set(libkleo_ui_common_SRCS @@ -193,6 +194,7 @@ AbstractImportJob DefaultKeyFilter KeyForMailboxJob + Formatting REQUIRED_HEADERS libkleo_HEADERS PREFIX Libkleo RELATIVE kleo diff --git a/src/kleo/formatting.h b/src/kleo/formatting.h new file mode 100644 --- /dev/null +++ b/src/kleo/formatting.h @@ -0,0 +1,62 @@ +/* formatting.h + + This file is part of libkleopatra, the KDE keymanagement library + Copyright (c) 2016 Intevation GmbH + + Libkleopatra 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. + + Libkleopatra is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#ifndef __KLEO_FORMATTING_H__ +#define __KLEO_FORMATTING_H__ + +#include +#include "kleo_export.h" + +#include + +class QIcon; +class QString; + +namespace Kleo +{ +namespace Formatting // There is also Kleo::Formatting declared in Kleopatra. +{ + // TODO: Move more formatting code from Kleopatra into libkleo for + // reuse. + + /** Gets an icon that can be used to indicate the validity of this UID. */ + KLEO_EXPORT QIcon iconForUid(const GpgME::UserID &uid); + + /** A sentence about the validity of the UserID using Recipient. + * + * The string to be returned uses the word "recipient" to avoid + * the technical term "User ID" so it is intended to be used + * in a context where the word recipient makes sense. + */ + KLEO_EXPORT QString validityForRecipient(const GpgME::UserID &uid); +} // namespace Formatting +} +#endif // KLEO_FORMATTING_H diff --git a/src/kleo/formatting.cpp b/src/kleo/formatting.cpp new file mode 100644 --- /dev/null +++ b/src/kleo/formatting.cpp @@ -0,0 +1,72 @@ +/* formatting.cpp + + This file is part of libkleopatra, the KDE keymanagement library + Copyright (c) 2016 Intevation GmbH + + Libkleopatra 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. + + Libkleopatra is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + + In addition, as a special exception, the copyright holders give + permission to link the code of this program with any edition of + the Qt library by Trolltech AS, Norway (or with modified versions + of Qt that use the same license as Qt), and distribute linked + combinations including the two. You must obey the GNU General + Public License in all respects for all of the code used other than + Qt. If you modify this file, you may extend this exception to + your version of the file, but you are not obligated to do so. If + you do not wish to do so, delete this exception statement from + your version. +*/ + +#include "formatting.h" + +#include +#include + +using namespace Kleo; +using namespace GpgME; + +QIcon Formatting::iconForUid(const UserID &uid) +{ + switch (uid.validity()) { + case UserID::Ultimate: + case UserID::Full: + case UserID::Marginal: + return QIcon::fromTheme(QStringLiteral("emblem-success")); + case UserID::Never: + return QIcon::fromTheme(QStringLiteral("emblem-error")); + case UserID::Undefined: + case UserID::Unknown: + default: + return QIcon::fromTheme(QStringLiteral("emblem-information")); + } +} + +QString Formatting::validityForRecipient(const UserID &uid) +{ + switch (uid.validity()) { + case UserID::Ultimate: + return i18n("The encryption key for this recipient is marked as your own."); + case UserID::Full: + return i18n("It is trusted that the encryption key belongs to this recipient."); + case UserID::Marginal: + return i18n("It is marginally trusted that the key encryption key belongs to this recipient."); + case UserID::Never: + return i18n("The encryption key is marked as not belonging to this recipient."); + case UserID::Undefined: + case UserID::Unknown: + default: + return i18n("There is no indication that the encryption key belongs to this recipient."); + } +}