• 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
newresultpage.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/gui/resultpage.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 "newresultpage.h"
36 
37 #include "resultlistwidget.h"
38 #include "resultitemwidget.h"
39 
40 #include <crypto/taskcollection.h>
41 
42 #include <kleo/stl_util.h>
43 
44 #include <boost/mem_fn.hpp>
45 
46 #include <KLocalizedString>
47 
48 #include <QCheckBox>
49 #include <QHash>
50 #include <QHBoxLayout>
51 #include <QIcon>
52 #include <QLabel>
53 #include <QProgressBar>
54 #include <QVBoxLayout>
55 #include <QTimer>
56 
57 #include <cassert>
58 
59 static const int ProgressBarHideDelay = 2000; // 2 secs
60 
61 using namespace Kleo;
62 using namespace Kleo::Crypto;
63 using namespace Kleo::Crypto::Gui;
64 using namespace boost;
65 
66 class NewResultPage::Private {
67  NewResultPage* const q;
68 public:
69  explicit Private( NewResultPage* qq );
70 
71  void progress( const QString & msg, int progress, int total );
72  void result( const shared_ptr<const Task::Result> & result );
73  void started( const shared_ptr<Task> & result );
74  void allDone();
75  void keepOpenWhenDone( bool keep );
76  QLabel * labelForTag( const QString & tag );
77 
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;
84  ResultListWidget* m_resultList;
85  QCheckBox* m_keepOpenCB;
86 };
87 
88 NewResultPage::Private::Private( NewResultPage* qq ) : q( qq ), m_lastErrorItemIndex( 0 )
89 {
90  m_hideProgressTimer.setInterval( ProgressBarHideDelay );
91  m_hideProgressTimer.setSingleShot( true );
92 
93  QBoxLayout* const layout = new QVBoxLayout( q );
94  QWidget* const labels = new QWidget;
95  m_progressLabelLayout = new QVBoxLayout( labels );
96  layout->addWidget( labels );
97  m_progressBar = new QProgressBar;
98  layout->addWidget( m_progressBar );
99  m_resultList = new ResultListWidget;
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 );
107 
108  connect( &m_hideProgressTimer, SIGNAL(timeout()), m_progressBar, SLOT(hide()) );
109 }
110 
111 void NewResultPage::Private::progress( const QString & msg, int progress, int total )
112 {
113  Q_UNUSED( msg );
114  assert( progress >= 0 );
115  assert( total >= 0 );
116  m_progressBar->setRange( 0, total );
117  m_progressBar->setValue( progress );
118 }
119 
120 void NewResultPage::Private::keepOpenWhenDone( bool )
121 {
122 }
123 
124 void NewResultPage::Private::allDone()
125 {
126  assert( !m_collections.empty() );
127  if ( !m_resultList->isComplete() )
128  return;
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() ) { //krazy:exclude=foreach
135  if ( !i.isEmpty() ) {
136  m_progressLabelByTag.value( i )->setText( i18n( "%1: All operations completed.", i ) );
137  } else {
138  m_progressLabelByTag.value( i )->setText( i18n( "All operations completed." ) );
139  }
140  }
141  if ( QAbstractButton * cancel = q->wizard()->button( QWizard::CancelButton ) )
142  cancel->setEnabled( false );
143  emit q->completeChanged();
144  if ( !m_keepOpenCB->isChecked() && !errorOccurred )
145  if ( QWizard * wiz = q->wizard() )
146  if ( QAbstractButton * btn = wiz->button( QWizard::FinishButton ) )
147  QTimer::singleShot( 500, btn, SLOT(animateClick()) );
148  m_hideProgressTimer.start();
149 }
150 
151 void NewResultPage::Private::result( const shared_ptr<const Task::Result> & )
152 {
153 }
154 
155 void NewResultPage::Private::started( const shared_ptr<Task> & task )
156 {
157  assert( task );
158  const QString tag = task->tag();
159  QLabel * const label = labelForTag( tag );
160  assert( label );
161  if ( tag.isEmpty() )
162  label->setText( i18nc( "number, operation description", "Operation %1: %2", m_resultList->numberOfCompletedTasks() + 1, task->label() ) );
163  else
164  label->setText( i18nc( "tag( \"OpenPGP\" or \"CMS\"), operation description", "%1: %2", tag, task->label() ) );
165 }
166 
167 NewResultPage::NewResultPage( QWidget * parent ) : QWizardPage( parent ), d( new Private( this ) )
168 {
169  setTitle( i18n( "<b>Results</b>" ) );
170 }
171 
172 NewResultPage::~NewResultPage()
173 {
174 }
175 
176 bool NewResultPage::keepOpenWhenDone() const
177 {
178  return d->m_keepOpenCB->isChecked();
179 }
180 
181 void NewResultPage::setKeepOpenWhenDone( bool keep )
182 {
183  d->m_keepOpenCB->setChecked( keep );
184 }
185 
186 void NewResultPage::setKeepOpenWhenDoneShown( bool on ) {
187  d->m_keepOpenCB->setVisible( on );
188  if ( !on )
189  d->m_keepOpenCB->setChecked( true );
190 }
191 
192 void NewResultPage::setTaskCollection( const shared_ptr<TaskCollection> & coll )
193 {
194  //clear(); ### PENDING(marc) implement
195  addTaskCollection( coll );
196 }
197 
198 void NewResultPage::addTaskCollection( const shared_ptr<TaskCollection> & coll )
199 {
200  assert( coll );
201  if ( kdtools::contains( d->m_collections, coll ) )
202  return;
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()) );
211  connect( coll.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
212  this, SLOT(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)) );
213  connect( coll.get(), SIGNAL(started(boost::shared_ptr<Kleo::Crypto::Task>)),
214  this, SLOT(started(boost::shared_ptr<Kleo::Crypto::Task>)) );
215 
216  Q_FOREACH ( const shared_ptr<Task> & i, coll->tasks() ) { // create labels for all tags in collection
217  assert( i );
218  QLabel * l = d->labelForTag( i->tag() );
219  assert( l ); (void)l;
220  }
221  emit completeChanged();
222 }
223 
224 QLabel* NewResultPage::Private::labelForTag( const QString & tag ) {
225  if ( QLabel * const label = m_progressLabelByTag.value( tag ) )
226  return label;
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 );
232  return label;
233 }
234 
235 bool NewResultPage::isComplete() const
236 {
237  return d->m_resultList->isComplete();
238 }
239 
240 
241 #include "newresultpage.moc"
Kleo::Crypto::Gui::NewResultPage::isComplete
bool isComplete() const
Definition: newresultpage.cpp:235
resultlistwidget.h
QWizardPage::setTitle
void setTitle(const QString &title)
Definition: qwizard.cpp:3430
Kleo::Crypto::Gui::NewResultPage::setKeepOpenWhenDone
void setKeepOpenWhenDone(bool keep)
Definition: newresultpage.cpp:181
QWizardPage::completeChanged
void completeChanged()
Kleo::Crypto::Gui::NewResultPage::setTaskCollection
void setTaskCollection(const boost::shared_ptr< TaskCollection > &coll)
Definition: newresultpage.cpp:192
Kleo::Crypto::Gui::ResultListWidget
Definition: resultlistwidget.h:53
QWizardPage
The QWizardPage class is the base class for wizard pages.
Definition: qwizard.h:206
Kleo::Crypto::Gui::NewResultPage::addTaskCollection
void addTaskCollection(const boost::shared_ptr< TaskCollection > &coll)
Definition: newresultpage.cpp:198
QWidget
ProgressBarHideDelay
static const int ProgressBarHideDelay
Definition: newresultpage.cpp:59
Kleo::Crypto::Gui::NewResultPage
Definition: newresultpage.h:61
Kleo::Crypto::Gui::NewResultPage::setKeepOpenWhenDoneShown
void setKeepOpenWhenDoneShown(bool on)
Definition: newresultpage.cpp:186
resultitemwidget.h
boost::shared_ptr
Definition: encryptemailcontroller.h:51
d
#define d
Definition: adduseridcommand.cpp:90
Kleo::Crypto::Gui::NewResultPage::~NewResultPage
~NewResultPage()
Definition: newresultpage.cpp:172
QWizard::CancelButton
Definition: qwizard.h:69
q
#define q
Definition: adduseridcommand.cpp:91
QWizard::FinishButton
Definition: qwizard.h:68
newresultpage.h
Kleo::Crypto::Gui::NewResultPage::keepOpenWhenDone
bool keepOpenWhenDone() const
Definition: newresultpage.cpp:176
taskcollection.h
QWizard
The QWizard class provides a framework for wizards.
Definition: qwizard.h:51
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:56:41 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