source: calamares/trunk/fuentes/src/modules/partition/gui/ScanningDialog.cpp @ 7538

Last change on this file since 7538 was 7538, checked in by kbut, 13 months ago

sync with github

File size: 2.8 KB
Line 
1/* === This file is part of Calamares - <https://github.com/calamares> ===
2 *
3 *   Copyright 2015, Teo Mrnjavac <teo@kde.org>
4 *   Copyright 2017, Adriaan de Groot <groot@kde.org>
5 *
6 *   Calamares is free software: you can redistribute it and/or modify
7 *   it under the terms of the GNU General Public License as published by
8 *   the Free Software Foundation, either version 3 of the License, or
9 *   (at your option) any later version.
10 *
11 *   Calamares is distributed in the hope that it will be useful,
12 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
13 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 *   GNU General Public License for more details.
15 *
16 *   You should have received a copy of the GNU General Public License
17 *   along with Calamares. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include "ScanningDialog.h"
21
22#include "widgets/waitingspinnerwidget.h"
23
24#include <QBoxLayout>
25#include <QLabel>
26#include <QFutureWatcher>
27#include <QtConcurrent/QtConcurrent>
28
29
30ScanningDialog::ScanningDialog( const QString& text,
31                                const QString& windowTitle,
32                                QWidget* parent )
33    : QDialog( parent )
34{
35    setModal( true );
36    setWindowTitle( windowTitle );
37
38    QHBoxLayout* dialogLayout = new QHBoxLayout;
39    setLayout( dialogLayout );
40
41    WaitingSpinnerWidget* spinner = new WaitingSpinnerWidget();
42    dialogLayout->addWidget( spinner );
43    spinner->start();
44
45    QLabel* rescanningLabel = new QLabel( text,
46                                          this );
47    dialogLayout->addWidget( rescanningLabel );
48}
49
50
51void
52ScanningDialog::run( const QFuture< void >& future,
53                     const QString& text,
54                     const QString& windowTitle,
55                     const std::function< void() >& callback,
56                     QWidget* parent )
57{
58    ScanningDialog* theDialog =
59            new ScanningDialog( text,
60                                windowTitle,
61                                parent );
62    theDialog->show();
63
64    QFutureWatcher< void >* watcher = new QFutureWatcher< void >();
65    connect( watcher, &QFutureWatcher< void >::finished,
66             theDialog, [ watcher, theDialog, callback ]
67    {
68        watcher->deleteLater();
69        theDialog->hide();
70        theDialog->deleteLater();
71        callback();
72    } );
73
74    watcher->setFuture( future );
75}
76
77
78void
79ScanningDialog::run( const QFuture< void >& future,
80                     const std::function< void() >& callback,
81                     QWidget* parent )
82{
83    ScanningDialog::run( future,
84                         tr( "Scanning storage devices..." ),
85                         tr( "Partitioning" ),
86                         callback,
87                         parent );
88}
89
90void ScanningDialog::setVisible(bool visible)
91{
92    QDialog::setVisible( visible );
93    emit visibilityChanged();
94}
Note: See TracBrowser for help on using the repository browser.