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

kleopatra

  • sources
  • kde-4.14
  • kdepim
  • kleopatra
  • crypto
  • gui
resultpage.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 "resultpage.h"
36 #include "resultlistwidget.h"
37 #include "resultitemwidget.h"
38 
39 #include <crypto/taskcollection.h>
40 
41 #include <utils/scrollarea.h>
42 
43 #include <KLocalizedString>
44 
45 #include <QCheckBox>
46 #include <QHash>
47 #include <QLabel>
48 #include <QProgressBar>
49 #include <QVBoxLayout>
50 
51 #include <cassert>
52 
53 using namespace Kleo;
54 using namespace Kleo::Crypto;
55 using namespace Kleo::Crypto::Gui;
56 using namespace boost;
57 
58 class ResultPage::Private {
59  ResultPage* const q;
60 public:
61  explicit Private( ResultPage* qq );
62 
63  void progress( const QString & msg, int progress, int total );
64  void result( const shared_ptr<const Task::Result> & result );
65  void started( const shared_ptr<Task> & result );
66  void allDone();
67  void keepOpenWhenDone( bool keep );
68  QLabel * labelForTag( const QString & tag );
69 
70  shared_ptr<TaskCollection> m_tasks;
71  QProgressBar* m_progressBar;
72  QHash<QString, QLabel*> m_progressLabelByTag;
73  QVBoxLayout* m_progressLabelLayout;
74  int m_lastErrorItemIndex;
75  ResultListWidget* m_resultList;
76  QCheckBox* m_keepOpenCB;
77 };
78 
79 ResultPage::Private::Private( ResultPage* qq ) : q( qq ), m_lastErrorItemIndex( 0 )
80 {
81  QBoxLayout* const layout = new QVBoxLayout( q );
82  QWidget* const labels = new QWidget;
83  m_progressLabelLayout = new QVBoxLayout( labels );
84  layout->addWidget( labels );
85  m_progressBar = new QProgressBar;
86  layout->addWidget( m_progressBar );
87  m_resultList = new ResultListWidget;
88  connect( m_resultList, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString)) );
89  layout->addWidget( m_resultList );
90  m_keepOpenCB = new QCheckBox;
91  m_keepOpenCB->setText( i18n( "Keep open after operation completed" ) );
92  m_keepOpenCB->setChecked(true );
93  connect( m_keepOpenCB, SIGNAL(toggled(bool)), q, SLOT(keepOpenWhenDone(bool)) );
94  layout->addWidget( m_keepOpenCB );
95 }
96 
97 void ResultPage::Private::progress( const QString &msg, int progress, int total )
98 {
99  Q_UNUSED( msg );
100  assert( progress >= 0 );
101  assert( total >= 0 );
102  m_progressBar->setRange( 0, total );
103  m_progressBar->setValue( progress );
104 }
105 
106 void ResultPage::Private::keepOpenWhenDone( bool )
107 {
108 }
109 
110 void ResultPage::Private::allDone()
111 {
112  assert( m_tasks );
113  q->setAutoAdvance( !m_keepOpenCB->isChecked() && !m_tasks->errorOccurred() );
114  m_progressBar->setRange( 0, 100 );
115  m_progressBar->setValue( 100 );
116  m_tasks.reset();
117  Q_FOREACH ( const QString &i, m_progressLabelByTag.keys() ) { //krazy:exclude=foreach
118  if ( !i.isEmpty() ) {
119  m_progressLabelByTag.value( i )->setText( i18n( "%1: All operations completed.", i ) );
120  } else {
121  m_progressLabelByTag.value( i )->setText( i18n( "All operations completed." ) );
122  }
123  }
124  emit q->completeChanged();
125 }
126 
127 void ResultPage::Private::result( const shared_ptr<const Task::Result> & )
128 {
129 }
130 
131 void ResultPage::Private::started( const shared_ptr<Task> & task )
132 {
133  assert( task );
134  const QString tag = task->tag();
135  QLabel * const label = labelForTag( tag );
136  assert( label );
137  if ( tag.isEmpty() )
138  label->setText( i18nc( "number, operation description", "Operation %1: %2", m_tasks->numberOfCompletedTasks() + 1, task->label() ) );
139  else
140  label->setText( i18nc( "tag( \"OpenPGP\" or \"CMS\"), operation description", "%1: %2", tag, task->label() ) );
141 }
142 
143 ResultPage::ResultPage( QWidget* parent, Qt::WindowFlags flags ) : WizardPage( parent, flags ), d( new Private( this ) )
144 {
145  setTitle( i18n( "<b>Results</b>" ) );
146 }
147 
148 ResultPage::~ResultPage()
149 {
150 }
151 
152 bool ResultPage::keepOpenWhenDone() const
153 {
154  return d->m_keepOpenCB->isChecked();
155 }
156 
157 void ResultPage::setKeepOpenWhenDone( bool keep )
158 {
159  d->m_keepOpenCB->setChecked( keep );
160 }
161 
162 void ResultPage::setTaskCollection( const shared_ptr<TaskCollection> & coll )
163 {
164  assert( !d->m_tasks );
165  if ( d->m_tasks == coll )
166  return;
167  d->m_tasks = coll;
168  assert( d->m_tasks );
169  d->m_resultList->setTaskCollection( coll );
170  connect( d->m_tasks.get(), SIGNAL(progress(QString,int,int)),
171  this, SLOT(progress(QString,int,int)) );
172  connect( d->m_tasks.get(), SIGNAL(done()),
173  this, SLOT(allDone()) );
174  connect( d->m_tasks.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
175  this, SLOT(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)) );
176  connect( d->m_tasks.get(), SIGNAL(started(boost::shared_ptr<Kleo::Crypto::Task>)),
177  this, SLOT(started(boost::shared_ptr<Kleo::Crypto::Task>)) );
178 
179  Q_FOREACH ( const shared_ptr<Task> & i, d->m_tasks->tasks() ) { // create labels for all tags in collection
180  assert( i && d->labelForTag( i->tag() ) );
181  Q_UNUSED( i );
182  }
183  emit completeChanged();
184 }
185 
186 QLabel* ResultPage::Private::labelForTag( const QString & tag ) {
187  if ( QLabel * const label = m_progressLabelByTag.value( tag ) )
188  return label;
189  QLabel* label = new QLabel;
190  label->setTextFormat( Qt::RichText );
191  label->setWordWrap( true );
192  m_progressLabelLayout->addWidget( label );
193  m_progressLabelByTag.insert( tag, label );
194  return label;
195 }
196 
197 bool ResultPage::isComplete() const
198 {
199  return d->m_tasks ? d->m_tasks->allTasksCompleted() : true;
200 }
201 
202 
203 #include "moc_resultpage.cpp"
QWidget::layout
QLayout * layout() const
flags
static const char * flags[]
Definition: readerstatus.cpp:114
resultlistwidget.h
QProgressBar
QWidget
Kleo::Crypto::Gui::ResultListWidget
Definition: resultlistwidget.h:55
Kleo::Crypto::Gui::ResultPage::setTaskCollection
void setTaskCollection(const boost::shared_ptr< TaskCollection > &coll)
Definition: resultpage.cpp:162
Kleo::Crypto::Gui::WizardPage::completeChanged
void completeChanged()
Kleo::Crypto::Gui::WizardPage::setTitle
void setTitle(const QString &title)
Definition: wizardpage.cpp:102
resultitemwidget.h
boost::shared_ptr
Definition: encryptemailcontroller.h:51
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
d
#define d
Definition: adduseridcommand.cpp:89
QHash< QString, QLabel * >
QCheckBox
QString::isEmpty
bool isEmpty() const
QLabel::setTextFormat
void setTextFormat(Qt::TextFormat)
QVBoxLayout
kdtools::pimpl_ptr::get
T * get()
Definition: pimpl_ptr.h:39
QLabel::setText
void setText(const QString &)
QString
resultpage.h
Kleo::Crypto::Gui::ResultPage::ResultPage
ResultPage(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: resultpage.cpp:143
Kleo::Crypto::Gui::ResultPage::isComplete
bool isComplete() const
Definition: resultpage.cpp:197
scrollarea.h
Kleo::Crypto::Gui::ResultPage::keepOpenWhenDone
bool keepOpenWhenDone() const
Definition: resultpage.cpp:152
q
#define q
Definition: adduseridcommand.cpp:90
QWidget::QWidget
QWidget(QWidget *parent, QFlags< Qt::WindowType > f)
Kleo::Crypto::Gui::ResultPage
Definition: resultpage.h:53
QAbstractButton::setText
void setText(const QString &text)
Qt::WindowFlags
typedef WindowFlags
Kleo::Crypto::Gui::ResultListWidget::linkActivated
void linkActivated(const QString &link)
Kleo::Crypto::Gui::ResultPage::~ResultPage
~ResultPage()
Definition: resultpage.cpp:148
Kleo::Crypto::Gui::WizardPage
Definition: wizardpage.h:48
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
Kleo::Crypto::Gui::ResultPage::setKeepOpenWhenDone
void setKeepOpenWhenDone(bool keep)
Definition: resultpage.cpp:157
QBoxLayout
Kleo::Crypto::Gui::ResultListWidget::ResultListWidget
ResultListWidget(QWidget *parent=0, Qt::WindowFlags flags=0)
Definition: resultlistwidget.cpp:114
QLabel::setWordWrap
void setWordWrap(bool on)
taskcollection.h
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:33:11 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
  • pimprint

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