33 #include <config-kleopatra.h>
42 #include <kleo/stl_util.h>
44 #include <boost/mem_fn.hpp>
46 #include <KLocalizedString>
50 #include <QHBoxLayout>
53 #include <QProgressBar>
54 #include <QVBoxLayout>
62 using namespace Kleo::Crypto;
63 using namespace Kleo::Crypto::Gui;
64 using namespace boost;
66 class NewResultPage::Private {
71 void progress(
const QString & msg,
int progress,
int total );
75 void keepOpenWhenDone(
bool keep );
76 QLabel * labelForTag(
const QString & tag );
78 std::vector< shared_ptr<TaskCollection> > m_collections;
79 QTimer m_hideProgressTimer;
80 QProgressBar* m_progressBar;
81 QHash<QString, QLabel*> m_progressLabelByTag;
82 QVBoxLayout* m_progressLabelLayout;
83 int m_lastErrorItemIndex;
85 QCheckBox* m_keepOpenCB;
88 NewResultPage::Private::Private(
NewResultPage* qq ) :
q( qq ), m_lastErrorItemIndex( 0 )
91 m_hideProgressTimer.setSingleShot(
true );
93 QBoxLayout*
const layout =
new QVBoxLayout(
q );
95 m_progressLabelLayout =
new QVBoxLayout( labels );
96 layout->addWidget( labels );
97 m_progressBar =
new QProgressBar;
98 layout->addWidget( m_progressBar );
100 connect( m_resultList, SIGNAL(linkActivated(QString)),
q, SIGNAL(linkActivated(QString)) );
101 layout->addWidget( m_resultList, 1 );
102 m_keepOpenCB =
new QCheckBox;
103 m_keepOpenCB->setText( i18n(
"Keep open after operation completed" ) );
104 m_keepOpenCB->setChecked(
true );
105 connect( m_keepOpenCB, SIGNAL(toggled(
bool)),
q, SLOT(keepOpenWhenDone(
bool)) );
106 layout->addWidget( m_keepOpenCB );
108 connect( &m_hideProgressTimer, SIGNAL(timeout()), m_progressBar, SLOT(hide()) );
111 void NewResultPage::Private::progress(
const QString & msg,
int progress,
int total )
114 assert( progress >= 0 );
115 assert( total >= 0 );
116 m_progressBar->setRange( 0, total );
117 m_progressBar->setValue( progress );
120 void NewResultPage::Private::keepOpenWhenDone(
bool )
124 void NewResultPage::Private::allDone()
126 assert( !m_collections.empty() );
127 if ( !m_resultList->isComplete() )
129 m_progressBar->setRange( 0, 100 );
130 m_progressBar->setValue( 100 );
131 const bool errorOccurred =
132 kdtools::any( m_collections, mem_fn( &TaskCollection::errorOccurred ) );
133 m_collections.clear();
134 Q_FOREACH (
const QString &i, m_progressLabelByTag.keys() ) {
135 if ( !i.isEmpty() ) {
136 m_progressLabelByTag.value( i )->setText( i18n(
"%1: All operations completed.", i ) );
138 m_progressLabelByTag.value( i )->setText( i18n(
"All operations completed." ) );
142 cancel->setEnabled(
false );
143 emit
q->completeChanged();
144 if ( !m_keepOpenCB->isChecked() && !errorOccurred )
147 QTimer::singleShot( 500, btn, SLOT(animateClick()) );
148 m_hideProgressTimer.start();
158 const QString tag = task->tag();
159 QLabel *
const label = labelForTag( tag );
162 label->setText( i18nc(
"number, operation description",
"Operation %1: %2", m_resultList->numberOfCompletedTasks() + 1, task->label() ) );
164 label->setText( i18nc(
"tag( \"OpenPGP\" or \"CMS\"), operation description",
"%1: %2", tag, task->label() ) );
169 setTitle( i18n(
"<b>Results</b>" ) );
178 return d->m_keepOpenCB->isChecked();
183 d->m_keepOpenCB->setChecked( keep );
187 d->m_keepOpenCB->setVisible( on );
189 d->m_keepOpenCB->setChecked(
true );
201 if ( kdtools::contains( d->m_collections, coll ) )
203 d->m_hideProgressTimer.stop();
204 d->m_progressBar->show();
205 d->m_collections.push_back( coll );
206 d->m_resultList->addTaskCollection( coll );
207 connect( coll.get(), SIGNAL(progress(QString,
int,
int)),
208 this, SLOT(progress(QString,
int,
int)) );
209 connect( coll.get(), SIGNAL(done()),
210 this, SLOT(allDone()) );
218 QLabel * l = d->labelForTag( i->tag() );
219 assert( l ); (void)l;
224 QLabel* NewResultPage::Private::labelForTag(
const QString & tag ) {
225 if ( QLabel *
const label = m_progressLabelByTag.value( tag ) )
227 QLabel* label =
new QLabel;
228 label->setTextFormat( Qt::RichText );
229 label->setWordWrap(
true );
230 m_progressLabelLayout->addWidget( label );
231 m_progressLabelByTag.insert( tag, label );
237 return d->m_resultList->isComplete();
241 #include "newresultpage.moc"
void setTitle(const QString &title)
void setKeepOpenWhenDone(bool keep)
void setTaskCollection(const boost::shared_ptr< TaskCollection > &coll)
The QWizardPage class is the base class for wizard pages.
void addTaskCollection(const boost::shared_ptr< TaskCollection > &coll)
static const int ProgressBarHideDelay
void setKeepOpenWhenDoneShown(bool on)
bool keepOpenWhenDone() const
The QWizard class provides a framework for wizards.