• 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
resultlistwidget.cpp
Go to the documentation of this file.
1 /* -*- mode: c++; c-basic-offset:4 -*-
2  crypto/gui/resultlistwidget.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 "resultlistwidget.h"
36 
37 #include "emailoperationspreferences.h"
38 
39 #include <crypto/gui/resultitemwidget.h>
40 #include <crypto/taskcollection.h>
41 
42 #include <utils/scrollarea.h>
43 
44 #include <kleo/stl_util.h>
45 
46 #include <KLocalizedString>
47 #include <KPushButton>
48 #include <KStandardGuiItem>
49 
50 #include <QLabel>
51 #include <QVBoxLayout>
52 
53 #ifndef Q_MOC_RUN
54 #include <boost/bind.hpp>
55 #include <boost/mem_fn.hpp>
56 #endif
57 
58 #include <cassert>
59 
60 using namespace Kleo;
61 using namespace Kleo::Crypto;
62 using namespace Kleo::Crypto::Gui;
63 using namespace boost;
64 
65 class ResultListWidget::Private {
66  ResultListWidget* const q;
67 public:
68  explicit Private( ResultListWidget* qq );
69 
70  void result( const shared_ptr<const Task::Result> & result );
71  void started( const shared_ptr<Task> & task );
72  void detailsToggled( bool );
73  void allTasksDone();
74 
75  void addResultWidget( ResultItemWidget* widget );
76  void setupSingle();
77  void setupMulti();
78  void resizeIfStandalone();
79 
80  std::vector< shared_ptr<TaskCollection> > m_collections;
81  bool m_standaloneMode;
82  int m_lastErrorItemIndex;
83  ScrollArea * m_scrollArea;
84  KPushButton * m_closeButton;
85  QVBoxLayout * m_layout;
86  QLabel * m_progressLabel;
87 };
88 
89 ResultListWidget::Private::Private( ResultListWidget* qq )
90  : q( qq ),
91  m_collections(),
92  m_standaloneMode( false ),
93  m_lastErrorItemIndex( 0 ),
94  m_scrollArea( 0 ),
95  m_closeButton( 0 ),
96  m_layout( 0 ),
97  m_progressLabel( 0 )
98 {
99  m_layout = new QVBoxLayout( q );
100  m_layout->setMargin( 0 );
101  m_layout->setSpacing( 0 );
102  m_progressLabel = new QLabel;
103  m_progressLabel->setWordWrap( true );
104  m_layout->addWidget( m_progressLabel );
105  m_progressLabel->setVisible( false );
106 
107  m_closeButton = new KPushButton;
108  m_closeButton->setGuiItem( KStandardGuiItem::close() );
109  q->connect( m_closeButton, SIGNAL(clicked()), q, SLOT(close()) );
110  m_layout->addWidget( m_closeButton );
111  m_closeButton->setVisible( false );
112 }
113 
114 ResultListWidget::ResultListWidget( QWidget* parent, Qt::WindowFlags f ) : QWidget( parent, f ), d( new Private( this ) )
115 {
116 }
117 
118 ResultListWidget::~ResultListWidget()
119 {
120  if ( !d->m_standaloneMode )
121  return;
122  EMailOperationsPreferences prefs;
123  prefs.setDecryptVerifyPopupGeometry( geometry() );
124  prefs.writeConfig();
125 }
126 
127 void ResultListWidget::Private::setupSingle()
128 {
129  m_layout->addStretch();
130 }
131 
132 void ResultListWidget::Private::resizeIfStandalone()
133 {
134  if ( m_standaloneMode )
135  q->resize( q->size().expandedTo( q->sizeHint() ) );
136 }
137 
138 void ResultListWidget::Private::setupMulti()
139 {
140  if ( m_scrollArea )
141  return; // already been here...
142 
143  m_scrollArea = new ScrollArea;
144  m_scrollArea->setFocusPolicy( Qt::NoFocus );
145  assert( qobject_cast<QBoxLayout*>( m_scrollArea->widget()->layout() ) );
146  static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() )->setMargin( 0 );
147  static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() )->setSpacing( 2 );
148  static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() )->addStretch();
149  m_layout->insertWidget( 0, m_scrollArea );
150 }
151 
152 void ResultListWidget::Private::addResultWidget( ResultItemWidget* widget )
153 {
154  assert( widget );
155  assert( kdtools::any( m_collections, !boost::bind( &TaskCollection::isEmpty, _1 ) ) );
156 
157  assert( m_scrollArea );
158  assert( m_scrollArea->widget() );
159  assert( qobject_cast<QBoxLayout*>( m_scrollArea->widget()->layout() ) );
160  QBoxLayout & blay = *static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() );
161  blay.insertWidget( widget->hasErrorResult() ? m_lastErrorItemIndex++ : ( blay.count() - 1 ), widget );
162 
163  widget->show();
164  resizeIfStandalone();
165 }
166 
167 void ResultListWidget::Private::allTasksDone() {
168  if ( !q->isComplete() )
169  return;
170  m_progressLabel->setVisible( false );
171  resizeIfStandalone();
172  emit q->completeChanged();
173 }
174 
175 void ResultListWidget::Private::result( const shared_ptr<const Task::Result> & result )
176 {
177  assert( result );
178  assert( kdtools::any( m_collections, !boost::bind( &TaskCollection::isEmpty, _1 ) ) );
179  ResultItemWidget* wid = new ResultItemWidget( result );
180  q->connect( wid, SIGNAL(detailsToggled(bool)), q, SLOT(detailsToggled(bool)) );
181  q->connect( wid, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString)) );
182  q->connect( wid, SIGNAL(closeButtonClicked()), q, SLOT(close()) );
183  addResultWidget( wid );
184 }
185 
186 bool ResultListWidget::isComplete() const
187 {
188  return kdtools::all( d->m_collections, mem_fn( &TaskCollection::allTasksCompleted ) );
189 }
190 
191 unsigned int ResultListWidget::totalNumberOfTasks() const {
192  return kdtools::accumulate_transform( d->m_collections, mem_fn( &TaskCollection::size ), 0U );
193 }
194 
195 unsigned int ResultListWidget::numberOfCompletedTasks() const {
196  return kdtools::accumulate_transform( d->m_collections, mem_fn( &TaskCollection::numberOfCompletedTasks ), 0U );
197 }
198 
199 void ResultListWidget::setTaskCollection( const shared_ptr<TaskCollection> & coll )
200 {
201  //clear(); ### PENDING(marc) implement
202  addTaskCollection( coll );
203 }
204 
205 void ResultListWidget::addTaskCollection( const shared_ptr<TaskCollection> & coll )
206 {
207  assert( coll ); assert( !coll->isEmpty() );
208  d->m_collections.push_back( coll );
209  connect( coll.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
210  this, SLOT(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)) );
211  connect( coll.get(), SIGNAL(started(boost::shared_ptr<Kleo::Crypto::Task>)),
212  this, SLOT(started(boost::shared_ptr<Kleo::Crypto::Task>)) );
213  connect( coll.get(), SIGNAL(done()), this, SLOT(allTasksDone()) );
214  d->setupMulti();
215  setStandaloneMode( d->m_standaloneMode );
216 }
217 
218 void ResultListWidget::Private::detailsToggled( bool ) {
219  resizeIfStandalone();
220 }
221 
222 void ResultListWidget::Private::started( const shared_ptr<Task> & task )
223 {
224  assert( task );
225  assert( m_progressLabel );
226  m_progressLabel->setText( i18nc( "number, operation description", "Operation %1: %2", q->numberOfCompletedTasks() + 1, task->label() ) );
227  resizeIfStandalone();
228 }
229 
230 void ResultListWidget::setStandaloneMode( bool standalone ) {
231  d->m_standaloneMode = standalone;
232  if ( totalNumberOfTasks() == 0 )
233  return;
234  d->m_closeButton->setVisible( standalone );
235  d->m_progressLabel->setVisible( standalone );
236 }
237 
238 #include "moc_resultlistwidget.cpp"
resultlistwidget.h
QWidget::close
bool close()
QWidget
Kleo::Crypto::TaskCollection::allTasksCompleted
bool allTasksCompleted() const
Definition: taskcollection.cpp:84
Kleo::Crypto::TaskCollection::isEmpty
bool isEmpty() const
Definition: taskcollection.cpp:155
Kleo::Crypto::Gui::ResultListWidget::setTaskCollection
void setTaskCollection(const boost::shared_ptr< TaskCollection > &coll)
Definition: resultlistwidget.cpp:199
Kleo::Crypto::Gui::ResultListWidget
Definition: resultlistwidget.h:55
QWidget::setFocusPolicy
void setFocusPolicy(Qt::FocusPolicy policy)
Kleo::Crypto::Gui::ResultListWidget::addTaskCollection
void addTaskCollection(const boost::shared_ptr< TaskCollection > &coll)
Definition: resultlistwidget.cpp:205
QBoxLayout::count
virtual int count() const
Kleo::Crypto::Gui::ResultListWidget::numberOfCompletedTasks
unsigned int numberOfCompletedTasks() const
Definition: resultlistwidget.cpp:195
QWidget::geometry
const QRect & geometry() const
resultitemwidget.h
Kleo::Crypto::Gui::ResultListWidget::setStandaloneMode
void setStandaloneMode(bool standalone)
Definition: resultlistwidget.cpp:230
boost::shared_ptr
Definition: encryptemailcontroller.h:51
d
#define d
Definition: adduseridcommand.cpp:89
Kleo::Crypto::Gui::ResultListWidget::~ResultListWidget
~ResultListWidget()
Definition: resultlistwidget.cpp:118
QVBoxLayout
Kleo::ScrollArea
Definition: scrollarea.h:40
QString
Kleo::Crypto::Gui::ResultListWidget::totalNumberOfTasks
unsigned int totalNumberOfTasks() const
Definition: resultlistwidget.cpp:191
Kleo::Crypto::TaskCollection::size
size_t size() const
Definition: taskcollection.cpp:80
Kleo::Crypto::Gui::ResultItemWidget
Definition: resultitemwidget.h:55
scrollarea.h
q
#define q
Definition: adduseridcommand.cpp:90
Kleo::Crypto::Gui::ResultListWidget::isComplete
bool isComplete() const
Definition: resultlistwidget.cpp:186
Qt::WindowFlags
typedef WindowFlags
QBoxLayout::insertWidget
void insertWidget(int index, QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
QWidget::show
void show()
Kleo::Crypto::Gui::ResultItemWidget::hasErrorResult
bool hasErrorResult() const
Definition: resultitemwidget.cpp:179
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
QLabel
Kleo::Crypto::TaskCollection::numberOfCompletedTasks
int numberOfCompletedTasks() const
Definition: taskcollection.cpp:75
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