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

kleopatra

resultlistwidget.cpp

Go to the documentation of this file.
00001 /* -*- mode: c++; c-basic-offset:4 -*-
00002     crypto/gui/resultlistwidget.cpp
00003 
00004     This file is part of Kleopatra, the KDE keymanager
00005     Copyright (c) 2008 Klarälvdalens Datakonsult AB
00006 
00007     Kleopatra is free software; you can redistribute it and/or modify
00008     it under the terms of the GNU General Public License as published by
00009     the Free Software Foundation; either version 2 of the License, or
00010     (at your option) any later version.
00011 
00012     Kleopatra is distributed in the hope that it will be useful,
00013     but WITHOUT ANY WARRANTY; without even the implied warranty of
00014     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015     General Public License for more details.
00016 
00017     You should have received a copy of the GNU General Public License
00018     along with this program; if not, write to the Free Software
00019     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
00020 
00021     In addition, as a special exception, the copyright holders give
00022     permission to link the code of this program with any edition of
00023     the Qt library by Trolltech AS, Norway (or with modified versions
00024     of Qt that use the same license as Qt), and distribute linked
00025     combinations including the two.  You must obey the GNU General
00026     Public License in all respects for all of the code used other than
00027     Qt.  If you modify this file, you may extend this exception to
00028     your version of the file, but you are not obligated to do so.  If
00029     you do not wish to do so, delete this exception statement from
00030     your version.
00031 */
00032 
00033 #include <config-kleopatra.h>
00034 
00035 #include "resultlistwidget.h"
00036 
00037 #include "emailoperationspreferences.h"
00038 
00039 #include <crypto/gui/resultitemwidget.h>
00040 #include <crypto/taskcollection.h>
00041 
00042 #include <utils/scrollarea.h>
00043 
00044 #include <KLocalizedString>
00045 #include <KPushButton>
00046 #include <KStandardGuiItem>
00047 
00048 #include <QLabel>
00049 #include <QMoveEvent>
00050 #include <QVBoxLayout>
00051 
00052 #include <cassert>
00053 
00054 using namespace Kleo;
00055 using namespace Kleo::Crypto;
00056 using namespace Kleo::Crypto::Gui;
00057 using namespace boost;
00058 
00059 class ResultListWidget::Private {
00060     ResultListWidget* const q;
00061 public:
00062     explicit Private( ResultListWidget* qq );
00063 
00064     void result( const shared_ptr<const Task::Result> & result );
00065     void started( const shared_ptr<Task> & task );
00066     void detailsToggled( bool );
00067     void allTasksDone();
00068 
00069     void addResultWidget( ResultItemWidget* widget );
00070     void setupSingle();
00071     void setupMulti();
00072     void resizeIfStandalone();
00073     
00074     shared_ptr<TaskCollection> m_tasks;
00075     bool m_standaloneMode;
00076     int m_lastErrorItemIndex;
00077     ScrollArea * m_scrollArea;
00078     KPushButton * m_closeButton;
00079     QVBoxLayout * m_layout;
00080     QLabel * m_progressLabel;
00081 };
00082 
00083 ResultListWidget::Private::Private( ResultListWidget* qq ) 
00084     : q( qq ),
00085     m_tasks(),
00086     m_standaloneMode( false ),
00087     m_lastErrorItemIndex( 0 ),
00088     m_scrollArea( 0 ),
00089     m_closeButton( 0 ),
00090     m_layout( 0 ),
00091     m_progressLabel( 0 )
00092 {
00093     m_layout = new QVBoxLayout( q );
00094     m_layout->setMargin( 0 );
00095     m_layout->setSpacing( 0 );
00096     m_progressLabel = new QLabel;
00097     m_progressLabel->setWordWrap( true );
00098     m_layout->addWidget( m_progressLabel );
00099     m_progressLabel->setVisible( false );
00100     
00101     m_closeButton = new KPushButton;
00102     m_closeButton->setGuiItem( KStandardGuiItem::close() );
00103     q->connect( m_closeButton, SIGNAL(clicked()), q, SLOT(close()) );
00104     m_layout->addWidget( m_closeButton );
00105     m_closeButton->setVisible( false );
00106 }
00107 
00108 ResultListWidget::ResultListWidget( QWidget* parent, Qt::WindowFlags f ) : QWidget( parent, f ), d( new Private( this ) )
00109 {
00110 }
00111 
00112 ResultListWidget::~ResultListWidget()
00113 {
00114     if ( !d->m_standaloneMode )
00115         return;
00116     EMailOperationsPreferences prefs;
00117     prefs.setDecryptVerifyPopupGeometry( geometry() );
00118     prefs.writeConfig();
00119 }
00120 
00121 void ResultListWidget::Private::setupSingle()
00122 {
00123     m_layout->addStretch();
00124 }
00125 
00126 void ResultListWidget::Private::resizeIfStandalone()
00127 {
00128     if ( m_standaloneMode )
00129         q->resize( q->sizeHint() );
00130 }
00131 
00132 void ResultListWidget::Private::setupMulti()
00133 {
00134     m_scrollArea = new ScrollArea;
00135     assert( qobject_cast<QBoxLayout*>( m_scrollArea->widget()->layout() ) );
00136     static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() )->setMargin( 0 );
00137     static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() )->setSpacing( 2 );
00138     static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() )->addStretch();
00139     m_layout->insertWidget( 0, m_scrollArea );
00140 }
00141 
00142 void ResultListWidget::Private::addResultWidget( ResultItemWidget* widget )
00143 {
00144     assert( widget );
00145     assert( m_tasks && !m_tasks->isEmpty() );
00146     
00147     if ( m_tasks->size() > 1 ) {
00148         assert( m_scrollArea );
00149         assert( m_scrollArea->widget() );
00150         assert( qobject_cast<QBoxLayout*>( m_scrollArea->widget()->layout() ) );
00151         QBoxLayout & blay = *static_cast<QBoxLayout*>( m_scrollArea->widget()->layout() );
00152         blay.insertWidget( widget->hasErrorResult() ? m_lastErrorItemIndex++ : ( blay.count() - 1 ), widget );
00153     } else { // single task
00154         widget->showCloseButton( m_standaloneMode );
00155         m_layout->insertWidget( m_layout->count() - 1, widget, m_standaloneMode ? 1 : 0 );
00156     }
00157     widget->show();
00158     resizeIfStandalone();
00159 }
00160 
00161 void ResultListWidget::Private::allTasksDone() {
00162     m_progressLabel->setVisible( false );
00163     resizeIfStandalone();
00164     emit q->completeChanged();
00165 }
00166 
00167 void ResultListWidget::Private::result( const shared_ptr<const Task::Result> & result )
00168 {
00169     assert( result );
00170     assert( m_tasks && !m_tasks->isEmpty() );
00171     ResultItemWidget* wid = new ResultItemWidget( result );
00172     q->connect( wid, SIGNAL(detailsToggled(bool)), q, SLOT(detailsToggled(bool)) );
00173     q->connect( wid, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString)) );
00174     q->connect( wid, SIGNAL(closeButtonClicked()), q, SLOT(close()) );
00175     addResultWidget( wid );
00176 }
00177 
00178 bool ResultListWidget::isComplete() const
00179 {
00180     return d->m_tasks ? d->m_tasks->allTasksCompleted() : false;
00181 }
00182 
00183 void ResultListWidget::setTaskCollection( const shared_ptr<TaskCollection> & coll )
00184 {
00185     assert( !d->m_tasks );
00186     assert( coll && !coll->isEmpty() );
00187     d->m_tasks = coll;
00188     connect( d->m_tasks.get(), SIGNAL(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)),
00189              this, SLOT(result(boost::shared_ptr<const Kleo::Crypto::Task::Result>)) );
00190     connect( d->m_tasks.get(), SIGNAL(started(boost::shared_ptr<Kleo::Crypto::Task>)),
00191              this, SLOT(started(boost::shared_ptr<Kleo::Crypto::Task>)) );
00192     connect( d->m_tasks.get(), SIGNAL(done()), this, SLOT(allTasksDone()) );
00193     if ( coll->size() == 1 )
00194         d->setupSingle();
00195     else
00196         d->setupMulti();
00197     setStandaloneMode( d->m_standaloneMode );
00198 }
00199 
00200 void ResultListWidget::Private::detailsToggled( bool ) {
00201     resizeIfStandalone();
00202 }
00203 
00204 void ResultListWidget::Private::started( const shared_ptr<Task> & task )
00205 {
00206     assert( m_tasks );
00207     assert( task );
00208     assert( m_progressLabel );
00209     m_progressLabel->setText( i18nc( "number, operation description", "Operation %1: %2", m_tasks->numberOfCompletedTasks() + 1, task->label() ) );
00210     resizeIfStandalone();
00211 }
00212 
00213 void ResultListWidget::setStandaloneMode( bool standalone ) {
00214     d->m_standaloneMode = standalone;
00215     if ( !d->m_tasks || d->m_tasks->isEmpty() )
00216         return;
00217     d->m_closeButton->setVisible( standalone && d->m_tasks->size() > 1 );
00218     d->m_progressLabel->setVisible( standalone );
00219 }
00220 
00221 #include "resultlistwidget.moc"

kleopatra

Skip menu "kleopatra"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members

kdepim

Skip menu "kdepim"
  • akonadi
  •   clients
  •   kabc
  •   kcal
  •   kcm
  • akregator
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt
  • kdgantt1
  • kjots
  • kleopatra
  • kmail
  • kmobiletools
  • knode
  • knotes
  • kontact
  • kontactinterfaces
  • korganizer
  •   korgac
  • kpilot
  • ktimetracker
  • libkdepim
  • libkholidays
  • libkleo
  • libkpgp
  • maildir
Generated for kdepim by doxygen 1.5.4
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal