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

kleopatra

  • sources
  • kde-4.12
  • 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 }
106 
107 ResultItemWidget::ResultItemWidget( const shared_ptr<const Task::Result> & result, QWidget * parent, Qt::WindowFlags flags ) : QWidget( parent, flags ), d( new Private( result, this ) )
108 {
109  const QColor color = colorForVisualCode( d->m_result->code() );
110  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() ) );
111  QVBoxLayout* topLayout = new QVBoxLayout( this );
112  topLayout->setMargin( 0 );
113  topLayout->setSpacing( 0 );
114  QFrame* frame = new QFrame;
115  frame->setObjectName( QLatin1String("resultFrame") );
116  topLayout->addWidget( frame );
117  QVBoxLayout* layout = new QVBoxLayout( frame );
118  layout->setMargin( 0 );
119  layout->setSpacing( 0 );
120  QWidget* hbox = new QWidget;
121  QHBoxLayout* hlay = new QHBoxLayout( hbox );
122  hlay->setMargin( 0 );
123  hlay->setSpacing( 0 );
124  QLabel* overview = new QLabel;
125  overview->setWordWrap( true );
126  overview->setTextFormat( Qt::RichText );
127  overview->setText( d->m_result->overview() );
128  connect( overview, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
129 
130  hlay->addWidget( overview, 1, Qt::AlignTop );
131  layout->addWidget( hbox );
132 
133  const QString details = d->m_result->details();
134 
135  d->m_showDetailsLabel = new QLabel;
136  connect( d->m_showDetailsLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
137  hlay->addWidget( d->m_showDetailsLabel );
138  d->m_showDetailsLabel->setVisible( !details.isEmpty() );
139 
140  d->m_detailsLabel = new QLabel;
141  d->m_detailsLabel->setWordWrap( true );
142  d->m_detailsLabel->setTextFormat( Qt::RichText );
143  d->m_detailsLabel->setText( details );
144  connect( d->m_detailsLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
145  layout->addWidget( d->m_detailsLabel );
146 
147  d->m_detailsLabel->setVisible( false );
148 
149  d->m_closeButton = new KPushButton;
150  d->m_closeButton->setGuiItem( KStandardGuiItem::close() );
151  d->m_closeButton->setFixedSize( d->m_closeButton->sizeHint() );
152  connect( d->m_closeButton, SIGNAL(clicked()), this, SIGNAL(closeButtonClicked()) );
153  layout->addWidget( d->m_closeButton, 0, Qt::AlignRight );
154  d->m_closeButton->setVisible( false );
155 
156  d->updateShowDetailsLabel();
157 }
158 
159 ResultItemWidget::~ResultItemWidget()
160 {
161 }
162 
163 void ResultItemWidget::showCloseButton( bool show )
164 {
165  d->m_closeButton->setVisible( show );
166 }
167 
168 bool ResultItemWidget::detailsVisible() const
169 {
170  return d->m_detailsLabel && d->m_detailsLabel->isVisible();
171 }
172 
173 bool ResultItemWidget::hasErrorResult() const
174 {
175  return d->m_result->hasError();
176 }
177 
178 void ResultItemWidget::Private::slotLinkActivated( const QString & link )
179 {
180  assert( m_result );
181  if ( link.startsWith( QLatin1String( "key:" ) ) ) {
182  const QStringList split = link.split( QLatin1Char(':') );
183  if ( split.size() == 3 || m_result->nonce() != split.value( 1 ) )
184  emit q->linkActivated( QLatin1String("key://") + split.value( 2 ) );
185  else
186  kWarning() << "key link invalid, or nonce not matching! link=" << link << " nonce" << m_result->nonce();
187  return;
188  }
189 
190  const QUrl url( link );
191  if ( url.host() == QLatin1String("toggledetails") ) {
192  q->showDetails( !q->detailsVisible() );
193  return;
194  }
195 
196  if ( url.host() == QLatin1String("showauditlog") ) {
197  q->showAuditLog();
198  return;
199  }
200  kWarning() << "Unexpected link scheme: " << link;
201 }
202 
203 void ResultItemWidget::showAuditLog() {
204  MessageBox::auditLog( parentWidget(), d->m_result->auditLog().text() );
205 }
206 
207 void ResultItemWidget::showDetails( bool show )
208 {
209  if ( show == d->m_detailsLabel->isVisible() )
210  return;
211  d->m_detailsLabel->setVisible( show );
212  d->updateShowDetailsLabel();
213  emit detailsToggled( show );
214 }
215 
216 #include "resultitemwidget.moc"
flags
static const char * flags[]
Definition: readerstatus.cpp:115
Kleo::Crypto::Gui::ResultItemWidget::linkActivated
void linkActivated(const QString &link)
Kleo::Crypto::Gui::ResultItemWidget::detailsVisible
bool detailsVisible() const
Definition: resultitemwidget.cpp:168
auditlog.h
Kleo::Crypto::Gui::ResultItemWidget::closeButtonClicked
void closeButtonClicked()
Kleo::Crypto::Task::Result::VisualCode
VisualCode
Definition: task.h:127
Kleo::Crypto::Task::Result::Danger
Definition: task.h:130
Kleo::Crypto::Task::Result::NeutralError
Definition: task.h:132
QWidget
resultitemwidget.h
boost::shared_ptr
Definition: encryptemailcontroller.h:51
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Crypto::Gui::ResultItemWidget::detailsToggled
void detailsToggled(bool)
Kleo::Crypto::Gui::ResultItemWidget::~ResultItemWidget
~ResultItemWidget()
Definition: resultitemwidget.cpp:159
Kleo::Crypto::Gui::ResultItemWidget::showAuditLog
void showAuditLog()
Definition: resultitemwidget.cpp:203
Kleo::Crypto::Gui::ResultItemWidget::showDetails
void showDetails(bool show=true)
Definition: resultitemwidget.cpp:207
Kleo::Crypto::Gui::ResultItemWidget
Definition: resultitemwidget.h:53
Kleo::Crypto::Task::Result::Warning
Definition: task.h:129
q
#define q
Definition: adduseridcommand.cpp:91
Kleo::Crypto::Gui::ResultItemWidget::ResultItemWidget
ResultItemWidget(const boost::shared_ptr< const Task::Result > &result, QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: resultitemwidget.cpp:107
Kleo::Crypto::Task::Result::AllGood
Definition: task.h:128
Kleo::Crypto::Gui::ResultItemWidget::showCloseButton
void showCloseButton(bool show)
Definition: resultitemwidget.cpp:163
Kleo::Crypto::Task::Result::NeutralSuccess
Definition: task.h:131
Kleo::Crypto::Gui::ResultItemWidget::hasErrorResult
bool hasErrorResult() const
Definition: resultitemwidget.cpp:173
auditlog_url_template
static KUrl auditlog_url_template()
Definition: resultitemwidget.cpp:90
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:42 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

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