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