calamares/src/modules/partition/gui/ScanningDialog.cpp

73 lines
2.0 KiB
C++
Raw Normal View History

/* === This file is part of Calamares - <https://calamares.io> ===
2015-12-30 16:36:30 +01:00
*
2020-08-22 01:19:58 +02:00
* SPDX-FileCopyrightText: 2015 Teo Mrnjavac <teo@kde.org>
* SPDX-FileCopyrightText: 2017 Adriaan de Groot <groot@kde.org>
* SPDX-License-Identifier: GPL-3.0-or-later
2015-12-30 16:36:30 +01:00
*
* Calamares is Free Software: see the License-Identifier above.
2015-12-30 16:36:30 +01:00
*
*/
#include "ScanningDialog.h"
2019-08-08 18:42:47 +02:00
#include "3rdparty/waitingspinnerwidget.h"
2015-12-30 16:36:30 +01:00
#include <QBoxLayout>
#include <QFutureWatcher>
2020-08-22 01:19:58 +02:00
#include <QLabel>
#include <QtConcurrent/QtConcurrent>
2015-12-30 16:36:30 +01:00
2020-08-22 01:19:58 +02:00
ScanningDialog::ScanningDialog( const QString& text, const QString& windowTitle, QWidget* parent )
2015-12-30 16:36:30 +01:00
: QDialog( parent )
{
setModal( true );
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();
2020-08-22 01:19:58 +02:00
QLabel* rescanningLabel = new QLabel( text, this );
2015-12-30 16:36:30 +01:00
dialogLayout->addWidget( rescanningLabel );
}
void
ScanningDialog::run( const QFuture< void >& future,
const QString& text,
const QString& windowTitle,
const std::function< void() >& callback,
QWidget* parent )
{
2020-08-22 01:19:58 +02:00
ScanningDialog* theDialog = new ScanningDialog( text, windowTitle, parent );
theDialog->show();
QFutureWatcher< void >* watcher = new QFutureWatcher< void >();
2020-09-29 14:04:12 +02:00
connect( watcher, &QFutureWatcher< void >::finished, theDialog, [ watcher, theDialog, callback ] {
watcher->deleteLater();
theDialog->hide();
theDialog->deleteLater();
callback();
} );
watcher->setFuture( future );
}
void
2020-08-22 01:19:58 +02:00
ScanningDialog::run( const QFuture< void >& future, const std::function< void() >& callback, QWidget* parent )
{
2020-08-22 01:19:58 +02:00
ScanningDialog::run( future, tr( "Scanning storage devices..." ), tr( "Partitioning" ), callback, parent );
}
2020-08-22 01:19:58 +02:00
void
ScanningDialog::setVisible( bool visible )
2015-12-30 16:36:30 +01:00
{
QDialog::setVisible( visible );
emit visibilityChanged();
}