• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • crypto
  • gui
resultitemwidget.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/gui/resultitemwidget.cpp
3 
4  This file is part of Kleopatra, the KDE keymanager
5  Copyright (c) 2008 Klarälvdalens Datakonsult AB
6 
7  Kleopatra is free software; you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation; either version 2 of the License, or
10  (at your option) any later version.
11 
12  Kleopatra 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 #include <config-kleopatra.h>
34 
35 #include "resultitemwidget.h"
36 
37 #include <utils/auditlog.h>
38 
39 #include <ui/messagebox.h>
40 
41 #include <KDebug>
42 #include <KLocalizedString>
43 #include <KPushButton>
44 #include <KStandardGuiItem>
45 #include <KUrl>
46 
47 #include <QHBoxLayout>
48 #include <QLabel>
49 #include <QStringList>
50 #include <QUrl>
51 #include <QVBoxLayout>
52 
53 using namespace Kleo;
54 using namespace Kleo::Crypto;
55 using namespace Kleo::Crypto::Gui;
56 using namespace boost;
57 
58 namespace {
59  //### TODO move outta here, make colors configurable
60  static QColor colorForVisualCode( Task::Result::VisualCode code ) {
61  switch ( code ) {
62  case Task::Result::AllGood:
63  return QColor(0x3E, 0xAC, 0x31); //green
64  case Task::Result::NeutralError:
65  case Task::Result::Warning:
66  return QColor(0xE1, 0xB6, 0x13); //yellow
67  case Task::Result::Danger:
68  return QColor(0xD4, 0x23, 0x23); //red
69  case Task::Result::NeutralSuccess:
70  default:
71  return Qt::blue;
72  }
73  }
74 }
75 
76 class ResultItemWidget::Private {
77  ResultItemWidget* const q;
78 public:
79  explicit Private( const shared_ptr<const Task::Result> result, ResultItemWidget* qq ) : q( qq ), m_result( result ), m_detailsLabel( 0 ), m_showDetailsLabel( 0 ), m_closeButton( 0 ) { assert( m_result ); }
80 
81  void slotLinkActivated( const QString & );
82  void updateShowDetailsLabel();
83 
84  const shared_ptr<const Task::Result> m_result;
85  QLabel * m_detailsLabel;
86  QLabel * m_showDetailsLabel;
87  KPushButton * m_closeButton;
88 };
89 
90 static KUrl auditlog_url_template() {
91  KUrl url;
92  url.setScheme( QLatin1String("kleoresultitem") );
93  url.setHost( QLatin1String("showauditlog") );
94  return url;
95 }
96 
97 void ResultItemWidget::Private::updateShowDetailsLabel()
98 {
99  if ( !m_showDetailsLabel || !m_detailsLabel )
100  return;
101 
102  const bool detailsVisible = m_detailsLabel->isVisible();
103  const QString auditLogLink = m_result->auditLog().formatLink( auditlog_url_template() );
104  m_showDetailsLabel->setText( QString::fromLatin1( "<a href=\"kleoresultitem://toggledetails/\">%1</a><br/>%2" ).arg( detailsVisible ? i18n( "Hide Details" ) : i18n( "Show Details" ), auditLogLink ) );
105  m_showDetailsLabel->setAccessibleDescription( detailsVisible ? i18n( "Hide Details" ) : i18n( "Show Details" ) );
106 }
107 
108 ResultItemWidget::ResultItemWidget( const shared_ptr<const Task::Result> & result, QWidget * parent, Qt::WindowFlags flags ) : QWidget( parent, flags ), d( new Private( result, this ) )
109 {
110  const QColor color = colorForVisualCode( d->m_result->code() );
111  setStyleSheet( QString::fromLatin1( "* { background-color: %1; margin: 0px; } QFrame#resultFrame{ border-color: %2; border-style: solid; border-radius: 3px; border-width: 2px } QLabel { padding: 5px; border-radius: 3px }" ).arg( color.lighter( 150 ).name(), color.name() ) );
112  QVBoxLayout* topLayout = new QVBoxLayout( this );
113  topLayout->setMargin( 0 );
114  topLayout->setSpacing( 0 );
115  QFrame* frame = new QFrame;
116  frame->setObjectName( QLatin1String("resultFrame") );
117  topLayout->addWidget( frame );
118  QVBoxLayout* layout = new QVBoxLayout( frame );
119  layout->setMargin( 0 );
120  layout->setSpacing( 0 );
121  QWidget* hbox = new QWidget;
122  QHBoxLayout* hlay = new QHBoxLayout( hbox );
123  hlay->setMargin( 0 );
124  hlay->setSpacing( 0 );
125  QLabel* overview = new QLabel;
126  overview->setWordWrap( true );
127  overview->setTextFormat( Qt::RichText );
128  overview->setText( d->m_result->overview() );
129  overview->setFocusPolicy ( Qt::StrongFocus );
130  connect( overview, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
131 
132  hlay->addWidget( overview, 1, Qt::AlignTop );
133  layout->addWidget( hbox );
134 
135  const QString details = d->m_result->details();
136 
137  d->m_showDetailsLabel = new QLabel;
138  connect( d->m_showDetailsLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
139  hlay->addWidget( d->m_showDetailsLabel );
140  d->m_showDetailsLabel->setVisible( !details.isEmpty() );
141  d->m_showDetailsLabel->setFocusPolicy ( Qt::StrongFocus );
142  d->m_showDetailsLabel->setTextInteractionFlags( Qt::TextBrowserInteraction );
143 
144  d->m_detailsLabel = new QLabel;
145  d->m_detailsLabel->setWordWrap( true );
146  d->m_detailsLabel->setTextFormat( Qt::RichText );
147  d->m_detailsLabel->setText( details );
148  d->m_detailsLabel->setFocusPolicy ( Qt::StrongFocus );
149  d->m_detailsLabel->setTextInteractionFlags( Qt::TextBrowserInteraction );
150  connect( d->m_detailsLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
151  layout->addWidget( d->m_detailsLabel );
152 
153  d->m_detailsLabel->setVisible( false );
154 
155  d->m_closeButton = new KPushButton;
156  d->m_closeButton->setGuiItem( KStandardGuiItem::close() );
157  d->m_closeButton->setFixedSize( d->m_closeButton->sizeHint() );
158  connect( d->m_closeButton, SIGNAL(clicked()), this, SIGNAL(closeButtonClicked()) );
159  layout->addWidget( d->m_closeButton, 0, Qt::AlignRight );
160  d->m_closeButton->setVisible( false );
161 
162  d->updateShowDetailsLabel();
163 }
164 
165 ResultItemWidget::~ResultItemWidget()
166 {
167 }
168 
169 void ResultItemWidget::showCloseButton( bool show )
170 {
171  d->m_closeButton->setVisible( show );
172 }
173 
174 bool ResultItemWidget::detailsVisible() const
175 {
176  return d->m_detailsLabel && d->m_detailsLabel->isVisible();
177 }
178 
179 bool ResultItemWidget::hasErrorResult() const
180 {
181  return d->m_result->hasError();
182 }
183 
184 void ResultItemWidget::Private::slotLinkActivated( const QString & link )
185 {
186  assert( m_result );
187  if ( link.startsWith( QLatin1String( "key:" ) ) ) {
188  const QStringList split = link.split( QLatin1Char(':') );
189  if ( split.size() == 3 || m_result->nonce() != split.value( 1 ) )
190  emit q->linkActivated( QLatin1String("key://") + split.value( 2 ) );
191  else
192  kWarning() << "key link invalid, or nonce not matching! link=" << link << " nonce" << m_result->nonce();
193  return;
194  }
195 
196  const QUrl url( link );
197  if ( url.host() == QLatin1String("toggledetails") ) {
198  q->showDetails( !q->detailsVisible() );
199  return;
200  }
201 
202  if ( url.host() == QLatin1String("showauditlog") ) {
203  q->showAuditLog();
204  return;
205  }
206  kWarning() << "Unexpected link scheme: " << link;
207 }
208 
209 void ResultItemWidget::showAuditLog() {
210  MessageBox::auditLog( parentWidget(), d->m_result->auditLog().text() );
211 }
212 
213 void ResultItemWidget::showDetails( bool show )
214 {
215  if ( show == d->m_detailsLabel->isVisible() )
216  return;
217  d->m_detailsLabel->setVisible( show );
218  d->updateShowDetailsLabel();
219  emit detailsToggled( show );
220 }
221 
222 #include "moc_resultitemwidget.cpp"
QWidget::layout
QLayout * layout() const
flags
static const char * flags[]
Definition: readerstatus.cpp:114
Kleo::Crypto::Gui::ResultItemWidget::linkActivated
void linkActivated(const QString &link)
QWidget::setStyleSheet
void setStyleSheet(const QString &styleSheet)
QWidget
Kleo::Crypto::Gui::ResultItemWidget::detailsVisible
bool detailsVisible() const
Definition: resultitemwidget.cpp:174
auditlog.h
Kleo::Crypto::Gui::ResultItemWidget::closeButtonClicked
void closeButtonClicked()
QColor::name
QString name() const
Kleo::Crypto::Task::Result::VisualCode
VisualCode
Definition: task.h:129
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
QString::split
QStringList split(const QString &sep, SplitBehavior behavior, Qt::CaseSensitivity cs) const
Kleo::Crypto::Task::Result::Danger
Definition: task.h:132
Kleo::Crypto::Task::Result::NeutralError
Definition: task.h:134
QHBoxLayout
QList::size
int size() const
QList::value
T value(int i) const
resultitemwidget.h
boost::shared_ptr
Definition: encryptemailcontroller.h:51
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
d
#define d
Definition: adduseridcommand.cpp:89
Kleo::Crypto::Gui::ResultItemWidget::detailsToggled
void detailsToggled(bool)
QObject::setObjectName
void setObjectName(const QString &name)
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QLabel::setTextFormat
void setTextFormat(Qt::TextFormat)
Kleo::Crypto::Gui::ResultItemWidget::~ResultItemWidget
~ResultItemWidget()
Definition: resultitemwidget.cpp:165
QVBoxLayout
QLabel::setText
void setText(const QString &)
QString
QColor
QLayout::setMargin
void setMargin(int margin)
QStringList
Kleo::Crypto::Gui::ResultItemWidget::showAuditLog
void showAuditLog()
Definition: resultitemwidget.cpp:209
QUrl
QLatin1Char
QFrame
QColor::lighter
QColor lighter(int factor) const
Kleo::Crypto::Gui::ResultItemWidget::showDetails
void showDetails(bool show=true)
Definition: resultitemwidget.cpp:213
Kleo::Crypto::Gui::ResultItemWidget
Definition: resultitemwidget.h:55
QLatin1String
Kleo::Crypto::Task::Result::Warning
Definition: task.h:131
QWidget::parentWidget
QWidget * parentWidget() const
q
#define q
Definition: adduseridcommand.cpp:90
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
Kleo::Crypto::Gui::ResultItemWidget::ResultItemWidget
ResultItemWidget(const boost::shared_ptr< const Task::Result > &result, QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: resultitemwidget.cpp:108
Kleo::Crypto::Task::Result::AllGood
Definition: task.h:130
Kleo::Crypto::Gui::ResultItemWidget::showCloseButton
void showCloseButton(bool show)
Definition: resultitemwidget.cpp:169
QString::fromLatin1
QString fromLatin1(const char *str, int size)
Qt::WindowFlags
typedef WindowFlags
Kleo::Crypto::Task::Result::NeutralSuccess
Definition: task.h:133
Kleo::Crypto::Gui::ResultItemWidget::hasErrorResult
bool hasErrorResult() const
Definition: resultitemwidget.cpp:179
auditlog_url_template
static KUrl auditlog_url_template()
Definition: resultitemwidget.cpp:90
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
QLabel::setWordWrap
void setWordWrap(bool on)
QBoxLayout::setSpacing
void setSpacing(int spacing)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer
  • pimprint

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal