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