kleopatra
resultitemwidget.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
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 #include <config-kleopatra.h>
00034
00035 #include "resultitemwidget.h"
00036
00037 #include <ui/messagebox.h>
00038
00039 #include <KDebug>
00040 #include <KLocalizedString>
00041 #include <KPushButton>
00042 #include <KStandardGuiItem>
00043
00044 #include <QHBoxLayout>
00045 #include <QLabel>
00046 #include <QStringList>
00047 #include <QUrl>
00048 #include <QVBoxLayout>
00049
00050 using namespace Kleo;
00051 using namespace Kleo::Crypto;
00052 using namespace Kleo::Crypto::Gui;
00053 using namespace boost;
00054
00055 namespace {
00056
00057 static QColor colorForVisualCode( Task::Result::VisualCode code ) {
00058 switch ( code ) {
00059 case Task::Result::AllGood:
00060 return Qt::green;
00061 case Task::Result::NeutralError:
00062 case Task::Result::Warning:
00063 return Qt::yellow;
00064 case Task::Result::Danger:
00065 return Qt::red;
00066 case Task::Result::NeutralSuccess:
00067 default:
00068 return Qt::blue;
00069 }
00070 }
00071 }
00072
00073 class ResultItemWidget::Private {
00074 ResultItemWidget* const q;
00075 public:
00076 explicit Private( const shared_ptr<const Task::Result> result, ResultItemWidget* qq ) : q( qq ), m_result( result ), m_detailsLabel( 0 ), m_showDetailsLabel( 0 ) { assert( m_result ); }
00077
00078 void slotLinkActivated( const QString & );
00079 void updateShowDetailsLabel();
00080
00081 const shared_ptr<const Task::Result> m_result;
00082 QLabel * m_detailsLabel;
00083 QLabel * m_showDetailsLabel;
00084 KPushButton * m_closeButton;
00085 };
00086
00087 void ResultItemWidget::Private::updateShowDetailsLabel()
00088 {
00089 if ( !m_showDetailsLabel || !m_detailsLabel )
00090 return;
00091
00092 const bool detailsVisible = m_detailsLabel->isVisible();
00093 const QString auditLogLink = !m_result->auditLogAsHtml().isEmpty() ? QString( "<a href=\"kleoresultitem://showauditlog/\">%1</a>" ).arg( i18n( "Show Audit Log" ) ) : i18n( "No Audit Log available" );
00094 m_showDetailsLabel->setText( QString( "<a href=\"kleoresultitem://toggledetails/\">%1</a><br/>%2" ).arg( detailsVisible ? i18n( "Hide Details" ) : i18n( "Show Details" ), auditLogLink ) );
00095 }
00096
00097 ResultItemWidget::ResultItemWidget( const shared_ptr<const Task::Result> & result, QWidget * parent, Qt::WindowFlags flags ) : QWidget( parent, flags ), d( new Private( result, this ) )
00098 {
00099 const QColor color = colorForVisualCode( d->m_result->code() );
00100 setStyleSheet( QString( "* { 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() ) );
00101 QVBoxLayout* topLayout = new QVBoxLayout( this );
00102 topLayout->setMargin( 0 );
00103 topLayout->setSpacing( 0 );
00104 QFrame* frame = new QFrame;
00105 frame->setObjectName( "resultFrame" );
00106 topLayout->addWidget( frame );
00107 QVBoxLayout* layout = new QVBoxLayout( frame );
00108 layout->setMargin( 0 );
00109 layout->setSpacing( 0 );
00110 QWidget* hbox = new QWidget;
00111 QHBoxLayout* hlay = new QHBoxLayout( hbox );
00112 hlay->setMargin( 0 );
00113 hlay->setSpacing( 0 );
00114 QLabel* overview = new QLabel;
00115 overview->setWordWrap( true );
00116 overview->setTextFormat( Qt::RichText );
00117 overview->setText( d->m_result->overview() );
00118 connect( overview, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
00119
00120 hlay->addWidget( overview, 1, Qt::AlignTop );
00121 layout->addWidget( hbox );
00122
00123 const QString details = d->m_result->details();
00124
00125 d->m_showDetailsLabel = new QLabel;
00126 connect( d->m_showDetailsLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
00127 hlay->addWidget( d->m_showDetailsLabel );
00128 d->m_showDetailsLabel->setVisible( !details.isEmpty() );
00129
00130 d->m_detailsLabel = new QLabel;
00131 d->m_detailsLabel->setWordWrap( true );
00132 d->m_detailsLabel->setTextFormat( Qt::RichText );
00133 d->m_detailsLabel->setText( details );
00134 connect( d->m_detailsLabel, SIGNAL(linkActivated(QString)), this, SLOT(slotLinkActivated(QString)) );
00135 layout->addWidget( d->m_detailsLabel );
00136
00137 d->m_detailsLabel->setVisible( false );
00138
00139 d->m_closeButton = new KPushButton;
00140 d->m_closeButton->setGuiItem( KStandardGuiItem::close() );
00141 d->m_closeButton->setFixedSize( d->m_closeButton->sizeHint() );
00142 connect( d->m_closeButton, SIGNAL(clicked()), this, SIGNAL(closeButtonClicked()) );
00143 layout->addWidget( d->m_closeButton, 0, Qt::AlignRight );
00144 d->m_closeButton->setVisible( false );
00145
00146 d->updateShowDetailsLabel();
00147 }
00148
00149 ResultItemWidget::~ResultItemWidget()
00150 {
00151 }
00152
00153 void ResultItemWidget::showCloseButton( bool show )
00154 {
00155 d->m_closeButton->setVisible( show );
00156 }
00157
00158 bool ResultItemWidget::detailsVisible() const
00159 {
00160 return d->m_detailsLabel && d->m_detailsLabel->isVisible();
00161 }
00162
00163 bool ResultItemWidget::hasErrorResult() const
00164 {
00165 return d->m_result->hasError();
00166 }
00167
00168 void ResultItemWidget::Private::slotLinkActivated( const QString & link )
00169 {
00170 assert( m_result );
00171 if ( link.startsWith( "key:" ) ) {
00172 const QStringList split = link.split( ':' );
00173 if ( split.size() == 3 || m_result->nonce() != split.value( 1 ) )
00174 emit q->linkActivated( "key://" + split.value( 2 ) );
00175 else
00176 kWarning() << "key link invalid, or nonce not matching! link=" << link << " nonce" << m_result->nonce();
00177 return;
00178 }
00179
00180 const QUrl url( link );
00181 if ( url.host() == "toggledetails" ) {
00182 q->showDetails( !q->detailsVisible() );
00183 return;
00184 }
00185
00186 if ( url.host() == "showauditlog" ) {
00187 q->showAuditLog();
00188 return;
00189 }
00190 kWarning() << "Unexpected link scheme: " << link;
00191 }
00192
00193 void ResultItemWidget::showAuditLog() {
00194 MessageBox::auditLog( parentWidget(), d->m_result->auditLogAsHtml() );
00195 }
00196
00197 void ResultItemWidget::showDetails( bool show )
00198 {
00199 if ( show == d->m_detailsLabel->isVisible() )
00200 return;
00201 d->m_detailsLabel->setVisible( show );
00202 d->updateShowDetailsLabel();
00203 emit detailsToggled( show );
00204 }
00205
00206 #include "resultitemwidget.moc"