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

kleopatra

resultpage.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset:4 -*-
00002     crypto/gui/resultpage.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2008 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include <config-kleopatra.h>
00034 
00035 #include "resultpage.h"
00036 #include "resultlistwidget.h"
00037 #include "resultitemwidget.h"
00038 
00039 #include <crypto/taskcollection.h>
00040 
00041 #include <utils/scrollarea.h>
00042 
00043 #include <KLocalizedString>
00044 
00045 #include <QCheckBox>
00046 #include <QHash>
00047 #include <QHBoxLayout>
00048 #include <QIcon>
00049 #include <QLabel>
00050 #include <QProgressBar>
00051 #include <QVBoxLayout>
00052 
00053 #include <cassert>
00054 
00055 using namespace Kleo;
00056 using namespace Kleo::Crypto;
00057 using namespace Kleo::Crypto::Gui;
00058 using namespace boost;
00059 
00060 class ResultPage::Private {
00061     ResultPage* const q;
00062 public:
00063     explicit Private( ResultPage* qq );
00064 
00065     void progress( const QString & msg, int progress, int total );
00066     void result( const shared_ptr<const Task::Result> & result );
00067     void started( const shared_ptr<Task> & result );
00068     void allDone();
00069     void addResultWidget( ResultItemWidget* widget );
00070     void keepOpenWhenDone( bool keep );
00071     QLabel * labelForTag( const QString & tag );
00072 
00073     shared_ptr<TaskCollection> m_tasks;
00074     QProgressBar* m_progressBar;
00075     QHash<QString, QLabel*> m_progressLabelByTag;
00076     QVBoxLayout* m_progressLabelLayout;
00077     int m_lastErrorItemIndex;
00078     ScrollArea* m_scrollArea;
00079     ResultListWidget* m_resultList;
00080     QCheckBox* m_keepOpenCB;
00081 };
00082 
00083 void ResultPage::Private::addResultWidget( ResultItemWidget* widget )
00084 {
00085     assert( widget );
00086     assert( m_scrollArea->widget() );
00087     assert( qobject_cast<QBoxLayout*>( m_scrollArea->widget()->layout() ) );
00088     QBoxLayout & blay = *static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() );
00089     blay.insertWidget( widget->hasErrorResult() ? m_lastErrorItemIndex++ : ( blay.count() - 1 ), widget );
00090 }
00091 
00092 ResultPage::Private::Private( ResultPage* qq ) : q( qq ), m_lastErrorItemIndex( 0 )
00093 {
00094     QBoxLayout* const layout = new QVBoxLayout( q );
00095     QWidget* const labels = new QWidget;
00096     m_progressLabelLayout = new QVBoxLayout( labels );
00097     layout->addWidget( labels );
00098     m_progressBar = new QProgressBar;
00099     layout->addWidget( m_progressBar );
00100     m_resultList = new ResultListWidget;
00101     connect( m_resultList, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString)) );
00102     layout->addWidget( m_resultList );
00103     m_keepOpenCB = new QCheckBox;
00104     m_keepOpenCB->setText( i18n( "Keep open after operation completed" ) );
00105     m_keepOpenCB->setChecked(true );
00106     connect( m_keepOpenCB, SIGNAL(toggled(bool)), q, SLOT(keepOpenWhenDone(bool)) );
00107     layout->addWidget( m_keepOpenCB );
00108 }
00109 
00110 void ResultPage::Private::progress( const QString & msg, int progress, int total )
00111 {
00112     assert( progress >= 0 );
00113     assert( total >= 0 );
00114     m_progressBar->setRange( 0, total );
00115     m_progressBar->setValue( progress );
00116 }
00117 
00118 void ResultPage::Private::keepOpenWhenDone( bool )
00119 {
00120 }
00121 
00122 void ResultPage::Private::allDone()
00123 {
00124     assert( m_tasks );
00125     q->setAutoAdvance( !m_keepOpenCB->isChecked() && !m_tasks->errorOccurred() );
00126     m_progressBar->setRange( 0, 100 );
00127     m_progressBar->setValue( 100 );
00128     m_tasks.reset();
00129     Q_FOREACH ( const QString & i, m_progressLabelByTag.keys() ) {
00130         if ( !i.isEmpty() )
00131             m_progressLabelByTag.value( i )->setText( i18n("%1: All operations completed.", i ) );
00132         else
00133             m_progressLabelByTag.value( i )->setText( i18n("All operations completed." ) );
00134     }
00135     emit q->completeChanged();
00136 }
00137 
00138 void ResultPage::Private::result( const shared_ptr<const Task::Result> & )
00139 {
00140 }
00141 
00142 void ResultPage::Private::started( const shared_ptr<Task> & task )
00143 {
00144     assert( task );
00145     const QString tag = task->tag();
00146     QLabel * const label = labelForTag( tag );
00147     assert( label );
00148     if ( tag.isEmpty() )
00149         label->setText( i18nc( "number, operation description", "Operation %1: %2", m_tasks->numberOfCompletedTasks() + 1, task->label() ) );
00150     else
00151         label->setText( i18nc( "tag( \"OpenPGP\" or \"CMS\"),  operation description", "%1: %2", tag, task->label() ) );
00152 }
00153 
00154 ResultPage::ResultPage( QWidget* parent, Qt::WindowFlags flags ) : WizardPage( parent, flags ), d( new Private( this ) )
00155 {
00156     setTitle( i18n( "<b>Results</b>" ) );
00157 }
00158 
00159 ResultPage::~ResultPage()
00160 {
00161 }
00162 
00163 bool ResultPage::keepOpenWhenDone() const
00164 {
00165     return d->m_keepOpenCB->isChecked();
00166 }
00167 
00168 void ResultPage::setKeepOpenWhenDone( bool keep )
00169 {
00170     d->m_keepOpenCB->setChecked( keep );
00171 }
00172 
00173 void ResultPage::setTaskCollection( const shared_ptr<TaskCollection> & coll )
00174 {
00175     assert( !d->m_tasks );
00176     if ( d->m_tasks == coll )
00177         return;
00178     d->m_tasks = coll;
00179     assert( d->m_tasks );
00180     d->m_resultList->setTaskCollection( coll );
00181     connect( d->m_tasks.get(), SIGNAL(progress(QString,int,int)),
00182              this, SLOT(progress(QString,int,int)) );
00183     connect( d->m_tasks.get(), SIGNAL(done()),
00184              this, SLOT(allDone()) );
00185     connect( d->m_tasks.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
00186              this, SLOT(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)) );
00187     connect( d->m_tasks.get(), SIGNAL(started(boost::shared_ptr<Kleo::Crypto::Task>)),
00188              this, SLOT(started(boost::shared_ptr<Kleo::Crypto::Task>)) );
00189     
00190     Q_FOREACH ( const shared_ptr<Task> & i, d->m_tasks->tasks() ) // create labels for all tags in collection
00191         assert( i && d->labelForTag( i->tag() ) );
00192     emit completeChanged();
00193 }
00194 
00195 QLabel* ResultPage::Private::labelForTag( const QString & tag ) {
00196     if ( QLabel * const label = m_progressLabelByTag.value( tag ) )
00197         return label;
00198     QLabel* label = new QLabel;
00199     label->setTextFormat( Qt::RichText );
00200     label->setWordWrap( true );
00201     m_progressLabelLayout->addWidget( label );
00202     m_progressLabelByTag.insert( tag, label );
00203     return label;
00204 }
00205 
00206 bool ResultPage::isComplete() const
00207 {
00208     return d->m_tasks ? d->m_tasks->allTasksCompleted() : true;
00209 }
00210 
00211 
00212 #include "resultpage.moc"

kleopatra

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

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal