2017-12-20 14:39:09 +01:00
|
|
|
/* === This file is part of Calamares - <https://github.com/calamares> ===
|
2015-12-30 16:36:30 +01:00
|
|
|
*
|
|
|
|
* Copyright 2015, Teo Mrnjavac <teo@kde.org>
|
2017-09-19 15:56:29 +02:00
|
|
|
* Copyright 2017, Adriaan de Groot <groot@kde.org>
|
2015-12-30 16:36:30 +01:00
|
|
|
*
|
|
|
|
* Calamares 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 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* Calamares 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 Calamares. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "ScanningDialog.h"
|
|
|
|
|
2017-09-19 15:56:29 +02:00
|
|
|
#include "widgets/waitingspinnerwidget.h"
|
2015-12-30 16:36:30 +01:00
|
|
|
|
|
|
|
#include <QBoxLayout>
|
|
|
|
#include <QLabel>
|
2015-12-31 13:55:33 +01:00
|
|
|
#include <QFutureWatcher>
|
|
|
|
#include <QtConcurrent/QtConcurrent>
|
2015-12-30 16:36:30 +01:00
|
|
|
|
|
|
|
|
2015-12-31 13:55:33 +01:00
|
|
|
ScanningDialog::ScanningDialog( const QString& text,
|
|
|
|
const QString& windowTitle,
|
|
|
|
QWidget* parent )
|
2015-12-30 16:36:30 +01:00
|
|
|
: QDialog( parent )
|
|
|
|
{
|
|
|
|
setModal( true );
|
2015-12-31 13:55:33 +01:00
|
|
|
setWindowTitle( windowTitle );
|
2015-12-30 16:36:30 +01:00
|
|
|
|
|
|
|
QHBoxLayout* dialogLayout = new QHBoxLayout;
|
|
|
|
setLayout( dialogLayout );
|
|
|
|
|
2017-09-19 15:56:29 +02:00
|
|
|
WaitingSpinnerWidget* spinner = new WaitingSpinnerWidget();
|
2015-12-30 16:36:30 +01:00
|
|
|
dialogLayout->addWidget( spinner );
|
|
|
|
spinner->start();
|
|
|
|
|
|
|
|
QLabel* rescanningLabel = new QLabel( text,
|
|
|
|
this );
|
|
|
|
dialogLayout->addWidget( rescanningLabel );
|
|
|
|
}
|
|
|
|
|
2015-12-31 13:55:33 +01:00
|
|
|
|
|
|
|
void
|
|
|
|
ScanningDialog::run( const QFuture< void >& future,
|
|
|
|
const QString& text,
|
|
|
|
const QString& windowTitle,
|
2015-12-31 15:38:50 +01:00
|
|
|
const std::function< void() >& callback,
|
2015-12-31 13:55:33 +01:00
|
|
|
QWidget* parent )
|
|
|
|
{
|
|
|
|
ScanningDialog* theDialog =
|
|
|
|
new ScanningDialog( text,
|
|
|
|
windowTitle,
|
|
|
|
parent );
|
|
|
|
theDialog->show();
|
|
|
|
|
|
|
|
QFutureWatcher< void >* watcher = new QFutureWatcher< void >();
|
|
|
|
connect( watcher, &QFutureWatcher< void >::finished,
|
2015-12-31 15:38:50 +01:00
|
|
|
theDialog, [ watcher, theDialog, callback ]
|
2015-12-31 13:55:33 +01:00
|
|
|
{
|
|
|
|
watcher->deleteLater();
|
|
|
|
theDialog->hide();
|
|
|
|
theDialog->deleteLater();
|
2015-12-31 15:38:50 +01:00
|
|
|
callback();
|
2015-12-31 13:55:33 +01:00
|
|
|
} );
|
|
|
|
|
|
|
|
watcher->setFuture( future );
|
|
|
|
}
|
|
|
|
|
2015-12-31 14:13:43 +01:00
|
|
|
|
|
|
|
void
|
2015-12-31 15:38:50 +01:00
|
|
|
ScanningDialog::run( const QFuture< void >& future,
|
|
|
|
const std::function< void() >& callback,
|
|
|
|
QWidget* parent )
|
2015-12-31 14:13:43 +01:00
|
|
|
{
|
|
|
|
ScanningDialog::run( future,
|
|
|
|
tr( "Scanning storage devices..." ),
|
2015-12-31 14:16:33 +01:00
|
|
|
tr( "Partitioning" ),
|
2015-12-31 15:38:50 +01:00
|
|
|
callback,
|
2015-12-31 14:13:43 +01:00
|
|
|
parent );
|
|
|
|
}
|
|
|
|
|
2015-12-30 16:36:30 +01:00
|
|
|
void ScanningDialog::setVisible(bool visible)
|
|
|
|
{
|
|
|
|
QDialog::setVisible( visible );
|
|
|
|
emit visibilityChanged();
|
|
|
|
}
|