33 #include <config-kleopatra.h>
37 #ifndef QT_NO_DIRMODEL
40 #include <KLocalizedString>
41 #include <KMessageBox>
43 #include <QHBoxLayout>
45 #include <QStringList>
46 #include <QVBoxLayout>
49 #include <QSortFilterProxyModel>
51 #include <QProgressBar>
52 #include <QDialogButtonBox>
53 #include <QPushButton>
54 #include <QHeaderView>
57 #include <boost/static_assert.hpp>
63 using namespace Kleo::Crypto;
64 using namespace Kleo::Crypto::Gui;
65 using namespace boost;
69 static Qt::GlobalColor statusColor[] = {
77 class ColorizedFileSystemModel :
public QDirModel {
80 explicit ColorizedFileSystemModel(
QObject * parent=0 )
88 if ( mi.
isValid() && role == Qt::BackgroundRole ) {
90 it = statusMap.find( filePath( mi ) );
91 if ( it != statusMap.end() )
92 if (
const Qt::GlobalColor c = statusColor[*it] )
106 const QString canonical = filePath( mi );
108 kDebug() <<
"can't locate file " << file;
113 it = statusMap.find( canonical );
115 if ( it != statusMap.end() )
121 statusMap[canonical] =
status;
123 emitDataChangedFor( mi );
126 void clearStatusInformation() {
130 swap( statusMap, oldStatusMap );
133 emitDataChangedFor( it.key() );
137 void emitDataChangedFor(
const QString & file ) {
138 emitDataChangedFor( index( file ) );
140 void emitDataChangedFor(
const QModelIndex & mi ) {
142 emit dataChanged( index( mi.
row(), 0, p ), index( mi.
row(), columnCount( p ) - 1, p ) );
150 static int find_layout_item(
const QBoxLayout & blay ) {
151 for (
int i = 0, end = blay.
count() ; i < end ; ++i )
153 if ( item->layout() )
172 const int row = find_layout_item( *vlay );
176 proxy.setSourceModel( model );
178 view.setModel( &proxy );
181 for(
int i = 0; i < proxy.columnCount(); ++i )
182 view.resizeColumnToContents( i );
185 view.header()->resizeSection( 0, qMax( view.header()->sectionSize( 0 ), 220 ) );
186 view.header()->resizeSection( 1, qMax( view.header()->sectionSize( 1 ), 75 ) );
187 view.header()->resizeSection( 2, qMax( view.header()->sectionSize( 2 ), 75 ) );
188 view.header()->resizeSection( 3, qMax( view.header()->sectionSize( 3 ), 140 ) );
190 for(
int i = 0; i < proxy.rowCount(); ++i )
191 r = r.
united( view.visualRect( proxy.index( proxy.columnCount() - 1, i ) ) );
192 view.setMinimumSize(
QSize( qBound( r.
width() + 4 * view.frameWidth(), 220+75+75+140 + 4 * view.frameWidth(), 1024 ),
193 qBound( r.
height(), 220, 512 ) ) );
196 void setBase(
const QString & base ) {
197 label.setText( base );
198 if (
QDirModel * fsm = qobject_cast<QDirModel*>( proxy.sourceModel() ) ) {
199 view.setRootIndex( proxy.mapFromSource( fsm->index( base ) ) );
201 kWarning() <<
"expect a QDirModel-derived class as proxy.sourceModel(), got ";
202 if ( !proxy.sourceModel() ) {
203 kWarning() <<
"a null pointer";
205 kWarning() << proxy.sourceModel()->metaObject()->className();
214 class VerifyChecksumsDialog::Private {
215 friend class ::Kleo::Crypto::Gui::VerifyChecksumsDialog;
225 qRegisterMetaType<Status>(
"Kleo::Crypto::Gui::VerifyChecksumsDialog::Status" );
229 void slotErrorButtonClicked() {
230 KMessageBox::errorList(
q, i18n(
"The following errors and warnings were recorded:"),
231 errors, i18n(
"Checksum Verification Errors") );
235 void updateErrors() {
236 const bool active = ui.isProgressBarActive();
237 ui.progressLabel.setVisible( active );
238 ui.progressBar. setVisible( active );
239 ui.errorLabel. setVisible( !active );
240 ui.errorButton. setVisible( !active && !errors.empty() );
241 if ( errors.empty() )
242 ui.errorLabel.setText( i18n(
"No errors occurred" ) );
244 ui.errorLabel.setText( i18np(
"One error occurred",
"%1 errors occurred", errors.size() ) );
250 ColorizedFileSystemModel model;
253 std::vector<BaseWidget*> baseWidgets;
264 progressLabel( i18n(
"Progress:"), q ),
266 errorLabel( i18n(
"No errors occurred"), q ),
267 errorButton( i18nc(
"Show Errors",
"Show"), q ),
280 errorButton.setAutoDefault(
false );
282 hlay[0].addWidget( &progressLabel );
283 hlay[0].addWidget( &progressBar, 1 );
285 hlay[1].addWidget( &errorLabel, 1 );
286 hlay[1].addWidget( &errorButton );
297 connect( close, SIGNAL(clicked()), q, SIGNAL(canceled()) );
298 connect( close, SIGNAL(clicked()), q, SLOT(accept()) );
300 connect( &errorButton, SIGNAL(clicked()), q, SLOT(slotErrorButtonClicked()) );
304 qDeleteAll( baseWidgets );
308 return buttonBox.button( QDialogButtonBox::Close );
314 for (
unsigned int i = baseWidgets.size(), end = bases.
size() ; i < end ; ++i )
315 baseWidgets.push_back(
new BaseWidget( model, vlay.
parentWidget(), &vlay ) );
318 for (
unsigned int i = bases.
size(), end = baseWidgets.size() ; i < end ; ++i ) {
319 delete baseWidgets.back();
320 baseWidgets.pop_back();
323 assert( static_cast<unsigned>( bases.
size() ) == baseWidgets.size() );
326 for (
unsigned int i = 0 ; i < baseWidgets.size() ; ++i )
327 baseWidgets[i]->setBase( bases[i] );
331 void setProgress(
int cur,
int tot ) {
332 progressBar.setMaximum( tot );
333 progressBar.setValue( cur );
336 bool isProgressBarActive()
const {
337 const int tot = progressBar.maximum();
338 const int cur = progressBar.value();
339 return !tot || cur != tot ;
347 d( new Private( this ) )
356 if ( d->bases == bases )
359 d->ui.setBases( bases, &d->model );
364 if ( d->errors == errors )
372 d->ui.setProgress( cur, tot );
378 d->model.setStatus( file, status );
385 d->model.clearStatusInformation();
388 #include "verifychecksumsdialog.moc"
389 #include "moc_verifychecksumsdialog.cpp"
391 #endif // QT_NO_DIRMODEL
VerifyChecksumsDialog(QWidget *parent=0, Qt::WindowFlags flags=0)
static const char * flags[]
void setErrors(const QStringList &errors)
void setStatus(const QString &file, Kleo::Crypto::Gui::VerifyChecksumsDialog::Status status)
virtual int count() const
void setProgress(int current, int total)
VerifyChecksumsDialog::Status status
virtual QVariant data(const QModelIndex &index, int role) const
const_iterator constEnd() const
virtual QLayoutItem * itemAt(int index) const
const_iterator constBegin() const
void clearStatusInformation()
BOOST_STATIC_ASSERT((sizeof icons/sizeof(*icons)==NumStates))
void setBaseDirectories(const QStringList &bases)
QRect united(const QRect &rectangle) const
void addLayout(QLayout *layout, int stretch)