1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270
|
/* -*- mode: c++; c-basic-offset:4 -*-
crypto/gui/decryptverifywizard.cpp
This file is part of Kleopatra, the KDE keymanager
Copyright (c) 2007 Klarälvdalens Datakonsult AB
Kleopatra is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
Kleopatra is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
In addition, as a special exception, the copyright holders give
permission to link the code of this program with any edition of
the Qt library by Trolltech AS, Norway (or with modified versions
of Qt that use the same license as Qt), and distribute linked
combinations including the two. You must obey the GNU General
Public License in all respects for all of the code used other than
Qt. If you modify this file, you may extend this exception to
your version of the file, but you are not obligated to do so. If
you do not wish to do so, delete this exception statement from
your version.
*/
#include <config-kleopatra.h>
#include "decryptverifyfileswizard.h"
#include "decryptverifyoperationwidget.h"
#include <crypto/gui/resultpage.h>
#include <crypto/gui/wizardpage.h>
#include <crypto/task.h>
#include <crypto/taskcollection.h>
#include <utils/scrollarea.h>
#include <utils/kleo_assert.h>
#include <kleo/stl_util.h>
#include "libkleo/ui/filenamerequester.h"
#include <KLocalizedString>
#include <KGuiItem>
#include <QBoxLayout>
#include <QCheckBox>
#include <QLabel>
#include <QTimer>
#include <QTreeView>
#ifndef Q_MOC_RUN
#include <boost/bind.hpp>
#endif
#include <vector>
#include <cassert>
using namespace Kleo;
using namespace Kleo::Crypto;
using namespace Kleo::Crypto::Gui;
using namespace boost;
namespace {
class HLine : public QFrame {
Q_OBJECT
public:
explicit HLine( QWidget * p=0, Qt::WindowFlags f=0 )
: QFrame( p, f )
{
setFrameStyle( QFrame::HLine|QFrame::Sunken );
}
};
class OperationsWidget : public WizardPage {
Q_OBJECT
public:
explicit OperationsWidget( QWidget * p=0 );
~OperationsWidget();
void setOutputDirectory( const QString & dir ) {
m_ui.outputDirectoryFNR.setFileName( dir );
}
QString outputDirectory() const {
return m_ui.outputDirectoryFNR.fileName();
}
bool useOutputDirectory() const {
return m_ui.useOutputDirectoryCB.isChecked();
}
void ensureIndexAvailable( unsigned int idx );
DecryptVerifyOperationWidget * widget( unsigned int idx ) {
return m_widgets.at( idx );
}
bool isComplete() const { return true; }
private:
std::vector<DecryptVerifyOperationWidget*> m_widgets;
struct UI {
QCheckBox useOutputDirectoryCB;
QLabel outputDirectoryLB;
FileNameRequester outputDirectoryFNR;
ScrollArea scrollArea; // ### replace with KDScrollArea when done
QVBoxLayout vlay;
QHBoxLayout hlay;
explicit UI( OperationsWidget * q );
} m_ui;
};
}
class DecryptVerifyFilesWizard::Private {
friend class ::Kleo::Crypto::Gui::DecryptVerifyFilesWizard;
DecryptVerifyFilesWizard * const q;
public:
Private( DecryptVerifyFilesWizard * qq );
~Private();
void ensureIndexAvailable( unsigned int idx ) {
operationsPage.ensureIndexAvailable( idx );
}
private:
OperationsWidget operationsPage;
Gui::ResultPage resultPage;
};
DecryptVerifyFilesWizard::DecryptVerifyFilesWizard( QWidget * p, Qt::WindowFlags f )
: Wizard( p, f ), d( new Private( this ) )
{
}
DecryptVerifyFilesWizard::~DecryptVerifyFilesWizard() {}
void DecryptVerifyFilesWizard::setOutputDirectory( const QString & dir ) {
d->operationsPage.setOutputDirectory( dir );
}
QString DecryptVerifyFilesWizard::outputDirectory() const {
return d->operationsPage.outputDirectory();
}
bool DecryptVerifyFilesWizard::useOutputDirectory() const {
return d->operationsPage.useOutputDirectory();
}
DecryptVerifyOperationWidget * DecryptVerifyFilesWizard::operationWidget( unsigned int idx ) {
d->ensureIndexAvailable( idx );
return d->operationsPage.widget( idx );
}
void DecryptVerifyFilesWizard::onNext( int id )
{
if ( id == OperationsPage )
QTimer::singleShot( 0, this, SIGNAL(operationPrepared()) );
Wizard::onNext( id );
}
void DecryptVerifyFilesWizard::setTaskCollection( const shared_ptr<TaskCollection> & coll )
{
kleo_assert( coll );
d->resultPage.setTaskCollection( coll );
}
DecryptVerifyFilesWizard::Private::Private( DecryptVerifyFilesWizard * qq )
: q( qq ),
operationsPage( q ),
resultPage( q )
{
q->setPage( DecryptVerifyFilesWizard::OperationsPage, &operationsPage );
q->setPage( DecryptVerifyFilesWizard::ResultPage, &resultPage );
connect( &resultPage, SIGNAL(linkActivated(QString)), q, SIGNAL(linkActivated(QString)) );
std::vector<int> order;
order.push_back( DecryptVerifyFilesWizard::OperationsPage );
order.push_back( DecryptVerifyFilesWizard::ResultPage );
q->setPageOrder( order );
operationsPage.setCommitPage( true );
}
DecryptVerifyFilesWizard::Private::~Private() {}
OperationsWidget::OperationsWidget( QWidget * p )
: WizardPage( p ), m_widgets(), m_ui( this )
{
setTitle( i18n("<b>Choose operations to be performed</b>") );
setSubTitle( i18n("Here you can check and, if needed, override "
"the operations Kleopatra detected for the input given.") );
setCommitPage( true );
setCustomNextButton( KGuiItem( i18n( "&Decrypt/Verify" ) ) );
}
OperationsWidget::~OperationsWidget() {}
OperationsWidget::UI::UI( OperationsWidget * q )
: useOutputDirectoryCB( i18n( "Create all output files in a single folder" ), q ),
outputDirectoryLB( i18n("&Output folder:"), q ),
outputDirectoryFNR( q ),
scrollArea( q ),
vlay( q ),
hlay()
{
KDAB_SET_OBJECT_NAME( useOutputDirectoryCB );
KDAB_SET_OBJECT_NAME( outputDirectoryLB );
KDAB_SET_OBJECT_NAME( outputDirectoryFNR );
KDAB_SET_OBJECT_NAME( scrollArea );
KDAB_SET_OBJECT_NAME( vlay );
KDAB_SET_OBJECT_NAME( hlay );
outputDirectoryFNR.setFilter( QDir::Dirs );
useOutputDirectoryCB.setChecked( true );
connect( &useOutputDirectoryCB, SIGNAL(toggled(bool)), &outputDirectoryLB, SLOT(setEnabled(bool)) );
connect( &useOutputDirectoryCB, SIGNAL(toggled(bool)), &outputDirectoryFNR, SLOT(setEnabled(bool)) );
assert( qobject_cast<QBoxLayout*>(scrollArea.widget()->layout()) );
static_cast<QBoxLayout*>(scrollArea.widget()->layout())->addStretch( 1 );
outputDirectoryLB.setBuddy( &outputDirectoryFNR );
hlay.setMargin( 0 );
vlay.addWidget( &scrollArea, 1 );
vlay.addWidget( &useOutputDirectoryCB );
vlay.addLayout( &hlay );
hlay.addWidget( &outputDirectoryLB );
hlay.addWidget( &outputDirectoryFNR );
}
void OperationsWidget::ensureIndexAvailable( unsigned int idx ) {
if ( idx < m_widgets.size() )
return;
assert( m_ui.scrollArea.widget() );
assert( qobject_cast<QBoxLayout*>( m_ui.scrollArea.widget()->layout() ) );
QBoxLayout & blay = *static_cast<QBoxLayout*>( m_ui.scrollArea.widget()->layout() );
for ( unsigned int i = m_widgets.size() ; i < idx+1 ; ++i ) {
if ( i )
blay.insertWidget( blay.count()-1, new HLine( m_ui.scrollArea.widget() ) );
DecryptVerifyOperationWidget * w = new DecryptVerifyOperationWidget( m_ui.scrollArea.widget() );
blay.insertWidget( blay.count()-1, w );
w->show();
m_widgets.push_back( w );
}
}
#include "decryptverifyfileswizard.moc"
|