2020-09-16 00:35:12 +01:00
/*
SPDX - FileCopyrightText : 2008 - 2012 Volker Lanz < vl @ fidra . de >
SPDX - FileCopyrightText : 2014 - 2020 Andrius Š tikonas < andrius @ stikonas . eu >
SPDX - FileCopyrightText : 2015 Teo Mrnjavac < teo @ kde . org >
SPDX - FileCopyrightText : 2016 Chantara Tith < tith . chantara @ gmail . com >
SPDX - FileCopyrightText : 2018 Caio Jordão Carvalho < caiojcarvalho @ gmail . com >
SPDX - FileCopyrightText : 2018 René J . V . Bertin < rjvbertin @ gmail . com >
SPDX - FileCopyrightText : 2018 Huzaifa Faruqui < huzaifafaruqui @ gmail . com >
SPDX - License - Identifier : GPL - 3.0 - or - later
*/
2008-09-24 20:32:01 +01:00
# include "gui/mainwindow.h"
# include "gui/infopane.h"
2010-02-11 18:47:51 +00:00
# include "gui/applyprogressdialog.h"
2010-02-12 11:29:12 +00:00
# include "gui/scanprogressdialog.h"
2010-02-23 16:30:05 +00:00
# include "gui/createpartitiontabledialog.h"
2016-09-04 12:25:43 +01:00
# include "gui/createvolumegroupdialog.h"
# include "gui/resizevolumegroupdialog.h"
2010-02-23 16:30:05 +00:00
# include "gui/filesystemsupportdialog.h"
# include "gui/devicepropsdialog.h"
2010-03-27 13:47:32 +00:00
# include "gui/smartdialog.h"
2008-09-24 20:32:01 +01:00
2010-03-21 11:32:31 +00:00
# include "config/configureoptionsdialog.h"
2016-01-12 00:12:49 +00:00
# include <backend/corebackendmanager.h>
# include <backend/corebackend.h>
2010-03-21 10:50:44 +00:00
2016-01-12 00:12:49 +00:00
# include <core/device.h>
# include <core/partitionalignment.h>
# include <core/smartstatus.h>
2010-02-23 16:30:05 +00:00
2016-01-12 00:12:49 +00:00
# include <ops/operation.h>
# include <ops/createpartitiontableoperation.h>
2016-06-30 00:17:05 +01:00
# include <ops/createvolumegroupoperation.h>
2016-07-09 01:12:31 +01:00
# include <ops/resizevolumegroupoperation.h>
2016-07-03 18:02:16 +01:00
# include <ops/removevolumegroupoperation.h>
2016-08-08 06:54:24 +01:00
# include <ops/deactivatevolumegroupoperation.h>
2016-01-12 00:12:49 +00:00
# include <ops/resizeoperation.h>
# include <ops/copyoperation.h>
# include <ops/deleteoperation.h>
# include <ops/newoperation.h>
# include <ops/backupoperation.h>
# include <ops/restoreoperation.h>
# include <ops/checkoperation.h>
2020-10-04 16:58:38 +01:00
# include <ops/setpartflagsoperation.h>
2010-02-23 16:30:05 +00:00
2016-01-12 00:12:49 +00:00
# include <fs/filesystem.h>
# include <fs/filesystemfactory.h>
2016-03-31 17:20:34 +01:00
# include <fs/luks.h>
2009-04-22 13:54:37 +01:00
2018-04-14 21:56:10 +01:00
# include <util/externalcommand.h>
2016-01-12 00:12:49 +00:00
# include <util/helpers.h>
2016-08-11 22:33:51 +01:00
# include <util/guihelpers.h>
# include <util/report.h>
2010-03-21 10:50:44 +00:00
2014-05-18 21:41:48 +01:00
# include <QApplication>
2008-09-24 20:32:01 +01:00
# include <QCloseEvent>
2015-03-28 16:55:06 +00:00
# include <QCollator>
2010-03-02 13:35:57 +00:00
# include <QDateTime>
2014-05-18 21:41:48 +01:00
# include <QFile>
# include <QFileDialog>
2017-10-09 13:54:31 +01:00
# include <QtGlobal>
2014-05-17 03:20:43 +01:00
# include <QMenu>
2014-05-18 21:41:48 +01:00
# include <QPointer>
2015-02-05 00:09:39 +00:00
# include <QPushButton>
2014-05-18 21:41:48 +01:00
# include <QReadLocker>
2016-05-10 14:53:26 +01:00
# include <QRegularExpression>
2014-05-18 21:41:48 +01:00
# include <QStatusBar>
# include <QTemporaryFile>
2010-03-02 13:35:57 +00:00
# include <QTextStream>
2008-09-24 20:32:01 +01:00
2016-08-25 00:15:07 +01:00
# include <KAboutApplicationDialog>
2014-11-19 12:05:22 +00:00
# include <KActionCollection>
2014-05-18 21:41:48 +01:00
# include <KMessageBox>
# include <KAboutData>
# include <KLocalizedString>
2014-11-19 12:05:22 +00:00
# include <KXMLGUIFactory>
2014-05-18 21:41:48 +01:00
# include <KJobUiDelegate>
# include <KIO/CopyJob>
# include <KIO/Job>
2014-11-19 12:05:22 +00:00
# include <KJobWidgets>
2018-04-03 20:01:14 +01:00
# include "config.h"
2010-02-23 16:30:05 +00:00
2008-09-24 20:32:01 +01:00
/** Creates a new MainWindow instance.
2015-07-13 15:17:41 +01:00
@ param parent the parent widget
2008-09-24 20:32:01 +01:00
*/
2010-06-03 15:02:35 +01:00
MainWindow : : MainWindow ( QWidget * parent ) :
2015-07-13 15:17:41 +01:00
KXmlGuiWindow ( parent ) ,
Ui : : MainWindowBase ( ) ,
m_OperationStack ( new OperationStack ( this ) ) ,
m_OperationRunner ( new OperationRunner ( this , operationStack ( ) ) ) ,
m_DeviceScanner ( new DeviceScanner ( this , operationStack ( ) ) ) ,
m_ApplyProgressDialog ( new ApplyProgressDialog ( this , operationRunner ( ) ) ) ,
m_ScanProgressDialog ( new ScanProgressDialog ( this ) ) ,
m_StatusText ( new QLabel ( this ) )
2008-09-24 20:32:01 +01:00
{
2015-07-13 15:17:41 +01:00
setupObjectNames ( ) ;
setupUi ( this ) ;
2016-07-02 12:12:56 +01:00
connect ( & m_ListDevices - > listDevices ( ) , & QListWidget : : customContextMenuRequested , this , & MainWindow : : listDevicesContextMenuRequested ) ;
connect ( & m_TreeLog - > treeLog ( ) , & QTreeWidget : : customContextMenuRequested , this , & MainWindow : : treeLogContextMenuRequested ) ;
connect ( & m_ListOperations - > listOperations ( ) , & QListWidget : : customContextMenuRequested , this , & MainWindow : : listOperationsContextMenuRequested ) ;
2015-07-13 15:17:41 +01:00
init ( ) ;
2009-04-16 12:37:00 +01:00
}
2008-12-25 16:46:40 +00:00
2010-02-23 16:30:05 +00:00
void MainWindow : : setupObjectNames ( )
{
2015-07-13 15:17:41 +01:00
m_OperationStack - > setObjectName ( QStringLiteral ( " m_OperationStack " ) ) ;
m_OperationRunner - > setObjectName ( QStringLiteral ( " m_OperationRunner " ) ) ;
m_DeviceScanner - > setObjectName ( QStringLiteral ( " m_DeviceScanner " ) ) ;
m_ApplyProgressDialog - > setObjectName ( QStringLiteral ( " m_ApplyProgressDialog " ) ) ;
m_ScanProgressDialog - > setObjectName ( QStringLiteral ( " m_ScanProgressDialog " ) ) ;
2010-02-23 16:30:05 +00:00
}
2009-04-16 12:37:00 +01:00
void MainWindow : : init ( )
{
2015-07-13 15:17:41 +01:00
treeLog ( ) . init ( ) ;
2009-04-22 13:41:30 +01:00
2016-05-18 22:23:59 +01:00
connect ( GlobalLog : : instance ( ) , & GlobalLog : : newMessage , & treeLog ( ) , & TreeLog : : onNewLogMessage ) ;
2008-09-24 20:32:01 +01:00
2015-07-13 15:17:41 +01:00
setupActions ( ) ;
setupStatusBar ( ) ;
setupConnections ( ) ;
2008-09-24 20:32:01 +01:00
2015-07-13 15:17:41 +01:00
listDevices ( ) . setActionCollection ( actionCollection ( ) ) ;
listOperations ( ) . setActionCollection ( actionCollection ( ) ) ;
2009-04-21 17:36:43 +01:00
2015-07-13 15:17:41 +01:00
setupGUI ( ) ;
2008-09-24 20:32:01 +01:00
2015-07-13 15:17:41 +01:00
loadConfig ( ) ;
2008-09-24 20:32:01 +01:00
2018-04-14 23:03:41 +01:00
show ( ) ;
pmWidget ( ) . init ( & operationStack ( ) ) ;
2015-07-13 15:17:41 +01:00
scanDevices ( ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : closeEvent ( QCloseEvent * event )
{
2015-07-13 15:17:41 +01:00
if ( applyProgressDialog ( ) . isVisible ( ) ) {
event - > ignore ( ) ;
return ;
}
if ( operationStack ( ) . size ( ) > 0 ) {
if ( KMessageBox : : warningContinueCancel ( this ,
xi18ncp ( " @info " , " <para>Do you really want to quit the application?</para><para>There is still an operation pending.</para> " ,
" <para>Do you really want to quit the application?</para><para>There are still %1 operations pending.</para> " , operationStack ( ) . size ( ) ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " , " Discard Pending Operations and Quit? " ) ,
2015-07-13 15:17:41 +01:00
KGuiItem ( xi18nc ( " @action:button " , " Quit <application>%1</application> " , QGuiApplication : : applicationDisplayName ( ) ) , QStringLiteral ( " arrow-right " ) ) ,
KStandardGuiItem : : cancel ( ) , QStringLiteral ( " reallyQuit " ) ) = = KMessageBox : : Cancel ) {
event - > ignore ( ) ;
return ;
}
}
saveConfig ( ) ;
KXmlGuiWindow : : closeEvent ( event ) ;
2018-09-01 22:34:46 +01:00
delete m_ApplyProgressDialog ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : changeEvent ( QEvent * event )
{
2015-07-13 15:17:41 +01:00
if ( ( event - > type ( ) = = QEvent : : ActivationChange | | event - > type ( ) = = QEvent : : WindowStateChange ) & & event - > spontaneous ( ) & & isActiveWindow ( ) ) {
2016-03-31 17:20:34 +01:00
QWidget * w = nullptr ;
2015-07-13 15:17:41 +01:00
if ( applyProgressDialog ( ) . isVisible ( ) )
w = & applyProgressDialog ( ) ;
else if ( scanProgressDialog ( ) . isVisible ( ) )
w = & scanProgressDialog ( ) ;
2016-03-31 17:20:34 +01:00
if ( w ! = nullptr ) {
2015-07-13 15:17:41 +01:00
w - > activateWindow ( ) ;
w - > raise ( ) ;
w - > setFocus ( ) ;
}
}
KXmlGuiWindow : : changeEvent ( event ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : setupActions ( )
{
2015-07-13 15:17:41 +01:00
// File actions
2016-07-01 15:42:12 +01:00
KStandardAction : : quit ( this , & MainWindow : : close , actionCollection ( ) ) ;
2015-07-13 15:17:41 +01:00
// Edit actions
2016-05-22 20:03:49 +01:00
QAction * undoOperation = actionCollection ( ) - > addAction ( QStringLiteral ( " undoOperation " ) ) ;
connect ( undoOperation , & QAction : : triggered , this , & MainWindow : : onUndoOperation ) ;
2015-07-13 15:17:41 +01:00
undoOperation - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
undoOperation - > setText ( xi18nc ( " @action:inmenu " , " Undo " ) ) ;
undoOperation - > setToolTip ( xi18nc ( " @info:tooltip " , " Undo the last operation " ) ) ;
undoOperation - > setStatusTip ( xi18nc ( " @info:status " , " Remove the last operation from the list. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( undoOperation , QKeySequence ( Qt : : CTRL + Qt : : Key_Z ) ) ;
2020-09-29 17:54:53 +01:00
undoOperation - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-undo " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * clearAllOperations = actionCollection ( ) - > addAction ( QStringLiteral ( " clearAllOperations " ) ) ;
connect ( clearAllOperations , & QAction : : triggered , this , & MainWindow : : onClearAllOperations ) ;
2015-07-13 15:17:41 +01:00
clearAllOperations - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
clearAllOperations - > setText ( xi18nc ( " @action:inmenu clear the list of operations " , " Clear " ) ) ;
clearAllOperations - > setToolTip ( xi18nc ( " @info:tooltip " , " Clear all operations " ) ) ;
clearAllOperations - > setStatusTip ( xi18nc ( " @info:status " , " Empty the list of pending operations. " ) ) ;
2020-09-29 17:54:53 +01:00
clearAllOperations - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " dialog-cancel " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * applyAllOperations = actionCollection ( ) - > addAction ( QStringLiteral ( " applyAllOperations " ) ) ;
connect ( applyAllOperations , & QAction : : triggered , this , & MainWindow : : onApplyAllOperations ) ;
2015-07-13 15:17:41 +01:00
applyAllOperations - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
applyAllOperations - > setText ( xi18nc ( " @action:inmenu apply all operations " , " Apply " ) ) ;
applyAllOperations - > setToolTip ( xi18nc ( " @info:tooltip " , " Apply all operations " ) ) ;
applyAllOperations - > setStatusTip ( xi18nc ( " @info:status " , " Apply the pending operations in the list. " ) ) ;
2020-09-29 17:54:53 +01:00
applyAllOperations - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " dialog-ok-apply " ) ) ) ;
2015-07-13 15:17:41 +01:00
// Device actions
2016-05-22 20:03:49 +01:00
QAction * createNewPartitionTable = actionCollection ( ) - > addAction ( QStringLiteral ( " createNewPartitionTable " ) ) ;
connect ( createNewPartitionTable , & QAction : : triggered , this , & MainWindow : : onCreateNewPartitionTable ) ;
2015-07-13 15:17:41 +01:00
createNewPartitionTable - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
createNewPartitionTable - > setText ( xi18nc ( " @action:inmenu " , " New Partition Table " ) ) ;
createNewPartitionTable - > setToolTip ( xi18nc ( " @info:tooltip " , " Create a new partition table " ) ) ;
createNewPartitionTable - > setStatusTip ( xi18nc ( " @info:status " , " Create a new and empty partition table on a device. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( createNewPartitionTable , QKeySequence ( Qt : : CTRL + Qt : : SHIFT + Qt : : Key_N ) ) ;
2020-09-29 17:54:53 +01:00
createNewPartitionTable - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-clear " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * exportPartitionTable = actionCollection ( ) - > addAction ( QStringLiteral ( " exportPartitionTable " ) ) ;
connect ( exportPartitionTable , & QAction : : triggered , this , & MainWindow : : onExportPartitionTable ) ;
2015-07-13 15:17:41 +01:00
exportPartitionTable - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
exportPartitionTable - > setText ( xi18nc ( " @action:inmenu " , " Export Partition Table " ) ) ;
exportPartitionTable - > setToolTip ( xi18nc ( " @info:tooltip " , " Export a partition table " ) ) ;
exportPartitionTable - > setStatusTip ( xi18nc ( " @info:status " , " Export the device's partition table to a text file. " ) ) ;
2020-09-29 17:54:53 +01:00
exportPartitionTable - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-export " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * importPartitionTable = actionCollection ( ) - > addAction ( QStringLiteral ( " importPartitionTable " ) ) ;
connect ( importPartitionTable , & QAction : : triggered , this , & MainWindow : : onImportPartitionTable ) ;
2015-07-13 15:17:41 +01:00
importPartitionTable - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
importPartitionTable - > setText ( xi18nc ( " @action:inmenu " , " Import Partition Table " ) ) ;
importPartitionTable - > setToolTip ( xi18nc ( " @info:tooltip " , " Import a partition table " ) ) ;
importPartitionTable - > setStatusTip ( xi18nc ( " @info:status " , " Import a partition table from a text file. " ) ) ;
2020-09-29 17:54:53 +01:00
importPartitionTable - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-import " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-07-03 18:02:16 +01:00
QAction * removeVolumeGroup = actionCollection ( ) - > addAction ( QStringLiteral ( " removeVolumeGroup " ) ) ;
connect ( removeVolumeGroup , & QAction : : triggered , this , & MainWindow : : onRemoveVolumeGroup ) ;
removeVolumeGroup - > setEnabled ( false ) ;
2016-08-11 17:03:43 +01:00
removeVolumeGroup - > setVisible ( false ) ;
2016-08-25 15:51:15 +01:00
removeVolumeGroup - > setText ( i18nc ( " @action:inmenu " , " Remove Volume Group " ) ) ;
removeVolumeGroup - > setToolTip ( i18nc ( " @info:tooltip " , " Remove selected Volume Group " ) ) ;
removeVolumeGroup - > setStatusTip ( i18nc ( " @info:status " , " Remove selected Volume Group. " ) ) ;
2016-07-03 18:02:16 +01:00
//actionCollection()->setDefaultShortcut(removeVolumeGroup, QKeySequence(/*SHORTCUT KEY HERE*/));
2020-09-29 17:54:53 +01:00
removeVolumeGroup - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-delete " ) ) ) ;
2016-07-03 18:02:16 +01:00
QAction * resizeVolumeGroup = actionCollection ( ) - > addAction ( QStringLiteral ( " resizeVolumeGroup " ) ) ;
connect ( resizeVolumeGroup , & QAction : : triggered , this , & MainWindow : : onResizeVolumeGroup ) ;
resizeVolumeGroup - > setEnabled ( false ) ;
2016-08-11 17:03:43 +01:00
resizeVolumeGroup - > setVisible ( false ) ;
2016-08-25 15:51:15 +01:00
resizeVolumeGroup - > setText ( i18nc ( " @action:inmenu " , " Resize Volume Group " ) ) ;
resizeVolumeGroup - > setToolTip ( i18nc ( " @info:tooltip " , " Resize selected Volume Group " ) ) ;
resizeVolumeGroup - > setStatusTip ( i18nc ( " @info:status " , " Extend or reduce selected Volume Group. " ) ) ;
2016-07-03 18:02:16 +01:00
//actionCollection()->setDefaultShortcut(resizeVolumeGroup, QKeySequence(/*SHORTCUT KEY HERE*/));
2020-09-29 17:54:53 +01:00
resizeVolumeGroup - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " arrow-right-double " ) ) ) ;
2016-07-03 18:02:16 +01:00
2016-08-08 06:54:24 +01:00
QAction * deactivateVolumeGroup = actionCollection ( ) - > addAction ( QStringLiteral ( " deactivateVolumeGroup " ) ) ;
connect ( deactivateVolumeGroup , & QAction : : triggered , this , & MainWindow : : onDeactivateVolumeGroup ) ;
deactivateVolumeGroup - > setEnabled ( false ) ;
2016-08-11 17:03:43 +01:00
deactivateVolumeGroup - > setVisible ( false ) ;
2016-08-25 15:51:15 +01:00
deactivateVolumeGroup - > setText ( i18nc ( " @action:inmenu " , " Deactivate Volume Group " ) ) ;
deactivateVolumeGroup - > setToolTip ( i18nc ( " @info:tooltip " , " Deactivate selected Volume Group " ) ) ;
deactivateVolumeGroup - > setStatusTip ( i18nc ( " @info:status " , " Deactivate selected Volume Group before unplugging removable devices. " ) ) ;
2020-09-29 17:54:53 +01:00
deactivateVolumeGroup - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " media-eject " ) ) ) ;
2016-08-08 06:54:24 +01:00
2016-05-22 20:03:49 +01:00
QAction * smartStatusDevice = actionCollection ( ) - > addAction ( QStringLiteral ( " smartStatusDevice " ) ) ;
connect ( smartStatusDevice , & QAction : : triggered , this , & MainWindow : : onSmartStatusDevice ) ;
2015-07-13 15:17:41 +01:00
smartStatusDevice - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
smartStatusDevice - > setText ( xi18nc ( " @action:inmenu " , " SMART Status " ) ) ;
smartStatusDevice - > setToolTip ( xi18nc ( " @info:tooltip " , " Show SMART status " ) ) ;
smartStatusDevice - > setStatusTip ( xi18nc ( " @info:status " , " Show the device's SMART status if supported " ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * propertiesDevice = actionCollection ( ) - > addAction ( QStringLiteral ( " propertiesDevice " ) ) ;
2016-07-01 15:51:28 +01:00
connect ( propertiesDevice , & QAction : : triggered , [ this ] { onPropertiesDevice ( { } ) ; } ) ;
2015-07-13 15:17:41 +01:00
propertiesDevice - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
propertiesDevice - > setText ( xi18nc ( " @action:inmenu " , " Properties " ) ) ;
propertiesDevice - > setToolTip ( xi18nc ( " @info:tooltip " , " Show device properties dialog " ) ) ;
propertiesDevice - > setStatusTip ( xi18nc ( " @info:status " , " View and modify device properties " ) ) ;
2020-09-29 17:54:53 +01:00
propertiesDevice - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-properties " ) ) ) ;
2015-07-13 15:17:41 +01:00
// Partition actions
2016-05-22 20:03:49 +01:00
QAction * newPartition = actionCollection ( ) - > addAction ( QStringLiteral ( " newPartition " ) ) ;
connect ( newPartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onNewPartition ) ;
2015-07-13 15:17:41 +01:00
newPartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
newPartition - > setText ( xi18nc ( " @action:inmenu create a new partition " , " New " ) ) ;
newPartition - > setToolTip ( xi18nc ( " @info:tooltip " , " New partition " ) ) ;
newPartition - > setStatusTip ( xi18nc ( " @info:status " , " Create a new partition. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( newPartition , QKeySequence ( Qt : : CTRL + Qt : : Key_N ) ) ;
2020-09-29 17:54:53 +01:00
newPartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-new " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * resizePartition = actionCollection ( ) - > addAction ( QStringLiteral ( " resizePartition " ) ) ;
connect ( resizePartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onResizePartition ) ;
2015-07-13 15:17:41 +01:00
resizePartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
resizePartition - > setText ( xi18nc ( " @action:inmenu " , " Resize/Move " ) ) ;
resizePartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Resize or move partition " ) ) ;
resizePartition - > setStatusTip ( xi18nc ( " @info:status " , " Shrink, grow or move an existing partition. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( resizePartition , QKeySequence ( Qt : : CTRL + Qt : : Key_R ) ) ;
2020-09-29 17:54:53 +01:00
resizePartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " arrow-right-double " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * deletePartition = actionCollection ( ) - > addAction ( QStringLiteral ( " deletePartition " ) ) ;
connect ( deletePartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onDeletePartition ) ;
2015-07-13 15:17:41 +01:00
deletePartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
deletePartition - > setText ( xi18nc ( " @action:inmenu " , " Delete " ) ) ;
deletePartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Delete partition " ) ) ;
deletePartition - > setStatusTip ( xi18nc ( " @info:status " , " Delete a partition. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( deletePartition , QKeySequence : : Delete ) ;
2020-09-29 17:54:53 +01:00
deletePartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-delete " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * shredPartition = actionCollection ( ) - > addAction ( QStringLiteral ( " shredPartition " ) ) ;
connect ( shredPartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onShredPartition ) ;
2015-07-13 15:17:41 +01:00
shredPartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
shredPartition - > setText ( xi18nc ( " @action:inmenu " , " Shred " ) ) ;
shredPartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Shred partition " ) ) ;
shredPartition - > setStatusTip ( xi18nc ( " @info:status " , " Shred a partition so that its contents cannot be restored. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( shredPartition , QKeySequence ( Qt : : SHIFT + Qt : : Key_Delete ) ) ;
2020-09-29 17:54:53 +01:00
shredPartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-delete-shred " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * copyPartition = actionCollection ( ) - > addAction ( QStringLiteral ( " copyPartition " ) ) ;
connect ( copyPartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onCopyPartition ) ;
2015-07-13 15:17:41 +01:00
copyPartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
copyPartition - > setText ( xi18nc ( " @action:inmenu " , " Copy " ) ) ;
copyPartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Copy partition " ) ) ;
copyPartition - > setStatusTip ( xi18nc ( " @info:status " , " Copy an existing partition. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( copyPartition , QKeySequence ( Qt : : CTRL + Qt : : Key_C ) ) ;
2020-09-29 17:54:53 +01:00
copyPartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-copy " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * pastePartition = actionCollection ( ) - > addAction ( QStringLiteral ( " pastePartition " ) ) ;
connect ( pastePartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onPastePartition ) ;
2015-07-13 15:17:41 +01:00
pastePartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
pastePartition - > setText ( xi18nc ( " @action:inmenu " , " Paste " ) ) ;
pastePartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Paste partition " ) ) ;
pastePartition - > setStatusTip ( xi18nc ( " @info:status " , " Paste a copied partition. " ) ) ;
2016-05-08 02:29:49 +01:00
actionCollection ( ) - > setDefaultShortcut ( pastePartition , QKeySequence ( Qt : : CTRL + Qt : : Key_V ) ) ;
2020-09-29 17:54:53 +01:00
pastePartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-paste " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * editMountPoint = actionCollection ( ) - > addAction ( QStringLiteral ( " editMountPoint " ) ) ;
connect ( editMountPoint , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onEditMountPoint ) ;
2015-07-13 15:17:41 +01:00
editMountPoint - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
editMountPoint - > setText ( xi18nc ( " @action:inmenu " , " Edit Mount Point " ) ) ;
editMountPoint - > setToolTip ( xi18nc ( " @info:tooltip " , " Edit mount point " ) ) ;
editMountPoint - > setStatusTip ( xi18nc ( " @info:status " , " Edit a partition's mount point and options. " ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * mountPartition = actionCollection ( ) - > addAction ( QStringLiteral ( " mountPartition " ) ) ;
connect ( mountPartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onMountPartition ) ;
2015-07-13 15:17:41 +01:00
mountPartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
mountPartition - > setText ( xi18nc ( " @action:inmenu " , " Mount " ) ) ;
mountPartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Mount or unmount partition " ) ) ;
mountPartition - > setStatusTip ( xi18nc ( " @info:status " , " Mount or unmount a partition. " ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * decryptPartition = actionCollection ( ) - > addAction ( QStringLiteral ( " decryptPartition " ) ) ;
connect ( decryptPartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onDecryptPartition ) ;
2016-03-31 17:20:34 +01:00
decryptPartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
decryptPartition - > setText ( xi18nc ( " @action:inmenu " , " Unlock " ) ) ;
decryptPartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Unlock or lock encrypted partition " ) ) ;
decryptPartition - > setStatusTip ( xi18nc ( " @info:status " , " Unlock or lock encrypted partition. " ) ) ;
2016-03-31 17:20:34 +01:00
2016-05-22 20:03:49 +01:00
QAction * checkPartition = actionCollection ( ) - > addAction ( QStringLiteral ( " checkPartition " ) ) ;
connect ( checkPartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onCheckPartition ) ;
2015-07-13 15:17:41 +01:00
checkPartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
checkPartition - > setText ( xi18nc ( " @action:inmenu " , " Check " ) ) ;
checkPartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Check partition " ) ) ;
checkPartition - > setStatusTip ( xi18nc ( " @info:status " , " Check a filesystem on a partition for errors. " ) ) ;
2020-09-29 17:54:53 +01:00
checkPartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " flag " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * propertiesPartition = actionCollection ( ) - > addAction ( QStringLiteral ( " propertiesPartition " ) ) ;
connect ( propertiesPartition , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onPropertiesPartition ) ;
2015-07-13 15:17:41 +01:00
propertiesPartition - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
propertiesPartition - > setText ( xi18nc ( " @action:inmenu " , " Properties " ) ) ;
propertiesPartition - > setToolTip ( xi18nc ( " @info:tooltip " , " Show partition properties dialog " ) ) ;
propertiesPartition - > setStatusTip ( xi18nc ( " @info:status " , " View and modify partition properties (label, partition flags, etc.) " ) ) ;
2020-09-29 17:54:53 +01:00
propertiesPartition - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-properties " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * backup = actionCollection ( ) - > addAction ( QStringLiteral ( " backupPartition " ) ) ;
connect ( backup , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onBackupPartition ) ;
2015-07-13 15:17:41 +01:00
backup - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
backup - > setText ( xi18nc ( " @action:inmenu " , " Backup " ) ) ;
backup - > setToolTip ( xi18nc ( " @info:tooltip " , " Backup partition " ) ) ;
backup - > setStatusTip ( xi18nc ( " @info:status " , " Backup a partition to an image file. " ) ) ;
2020-09-29 17:54:53 +01:00
backup - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-export " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * restore = actionCollection ( ) - > addAction ( QStringLiteral ( " restorePartition " ) ) ;
connect ( restore , & QAction : : triggered , & pmWidget ( ) , & PartitionManagerWidget : : onRestorePartition ) ;
2015-07-13 15:17:41 +01:00
restore - > setEnabled ( false ) ;
2016-07-18 02:21:14 +01:00
restore - > setText ( xi18nc ( " @action:inmenu " , " Restore " ) ) ;
restore - > setToolTip ( xi18nc ( " @info:tooltip " , " Restore partition " ) ) ;
restore - > setStatusTip ( xi18nc ( " @info:status " , " Restore a partition from an image file. " ) ) ;
2020-09-29 17:54:53 +01:00
restore - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-import " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-08-25 00:15:07 +01:00
// Tools actions
QAction * createVolumeGroup = actionCollection ( ) - > addAction ( QStringLiteral ( " createVolumeGroup " ) ) ;
connect ( createVolumeGroup , & QAction : : triggered , this , & MainWindow : : onCreateNewVolumeGroup ) ;
createVolumeGroup - > setEnabled ( false ) ;
2016-08-25 15:51:15 +01:00
createVolumeGroup - > setText ( i18nc ( " @action:inmenu " , " New Volume Group " ) ) ;
2016-08-25 00:15:07 +01:00
createVolumeGroup - > setToolTip ( i18nc ( " @info:tooltip " , " Create a new LVM Volume Group " ) ) ;
createVolumeGroup - > setStatusTip ( i18nc ( " @info:status " , " Create a new LVM Volume Group as a device. " ) ) ;
actionCollection ( ) - > setDefaultShortcut ( createVolumeGroup , QKeySequence ( Qt : : CTRL + Qt : : SHIFT + Qt : : Key_L ) ) ;
2020-09-29 17:54:53 +01:00
createVolumeGroup - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-new " ) ) ) ;
2016-08-25 00:15:07 +01:00
2016-05-22 20:03:49 +01:00
QAction * fileSystemSupport = actionCollection ( ) - > addAction ( QStringLiteral ( " fileSystemSupport " ) ) ;
connect ( fileSystemSupport , & QAction : : triggered , this , & MainWindow : : onFileSystemSupport ) ;
2016-07-18 02:21:14 +01:00
fileSystemSupport - > setText ( xi18nc ( " @action:inmenu " , " File System Support " ) ) ;
fileSystemSupport - > setToolTip ( xi18nc ( " @info:tooltip " , " View file system support information " ) ) ;
fileSystemSupport - > setStatusTip ( xi18nc ( " @info:status " , " Show information about supported file systems. " ) ) ;
2015-07-13 15:17:41 +01:00
2016-08-25 00:15:07 +01:00
QAction * refreshDevices = actionCollection ( ) - > addAction ( QStringLiteral ( " refreshDevices " ) ) ;
connect ( refreshDevices , & QAction : : triggered , this , & MainWindow : : onRefreshDevices ) ;
refreshDevices - > setText ( xi18nc ( " @action:inmenu refresh list of devices " , " Refresh Devices " ) ) ;
refreshDevices - > setToolTip ( xi18nc ( " @info:tooltip " , " Refresh all devices " ) ) ;
refreshDevices - > setStatusTip ( xi18nc ( " @info:status " , " Renew the devices list. " ) ) ;
actionCollection ( ) - > setDefaultShortcut ( refreshDevices , Qt : : Key_F5 ) ;
2020-09-29 17:54:53 +01:00
refreshDevices - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " view-refresh " ) ) ) ;
2016-08-25 00:15:07 +01:00
2015-07-13 15:17:41 +01:00
// Settings Actions
2016-08-25 15:51:15 +01:00
actionCollection ( ) - > addAction ( QStringLiteral ( " toggleDockDevices " ) , dockDevices ( ) . toggleViewAction ( ) ) ;
actionCollection ( ) - > addAction ( QStringLiteral ( " toggleDockOperations " ) , dockOperations ( ) . toggleViewAction ( ) ) ;
actionCollection ( ) - > addAction ( QStringLiteral ( " toggleDockInformation " ) , dockInformation ( ) . toggleViewAction ( ) ) ;
actionCollection ( ) - > addAction ( QStringLiteral ( " toggleDockLog " ) , dockLog ( ) . toggleViewAction ( ) ) ;
2016-07-01 15:42:12 +01:00
KStandardAction : : preferences ( this , & MainWindow : : onConfigureOptions , actionCollection ( ) ) ;
2015-07-13 15:17:41 +01:00
// Log Actions
2016-05-22 20:03:49 +01:00
QAction * clearLog = actionCollection ( ) - > addAction ( QStringLiteral ( " clearLog " ) ) ;
connect ( clearLog , & QAction : : triggered , & treeLog ( ) , & TreeLog : : onClearLog ) ;
2016-07-18 02:21:14 +01:00
clearLog - > setText ( xi18nc ( " @action:inmenu " , " Clear Log " ) ) ;
clearLog - > setToolTip ( xi18nc ( " @info:tooltip " , " Clear the log output " ) ) ;
clearLog - > setStatusTip ( xi18nc ( " @info:status " , " Clear the log output panel. " ) ) ;
2020-09-29 17:54:53 +01:00
clearLog - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " edit-clear-list " ) ) ) ;
2015-07-13 15:17:41 +01:00
2016-05-22 20:03:49 +01:00
QAction * saveLog = actionCollection ( ) - > addAction ( QStringLiteral ( " saveLog " ) ) ;
connect ( saveLog , & QAction : : triggered , & treeLog ( ) , & TreeLog : : onSaveLog ) ;
2016-07-18 02:21:14 +01:00
saveLog - > setText ( xi18nc ( " @action:inmenu " , " Save Log " ) ) ;
saveLog - > setToolTip ( xi18nc ( " @info:tooltip " , " Save the log output " ) ) ;
saveLog - > setStatusTip ( xi18nc ( " @info:status " , " Save the log output to a file. " ) ) ;
2020-09-29 17:54:53 +01:00
saveLog - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " document-save " ) ) ) ;
2016-08-25 00:15:07 +01:00
// Help Actions
QAction * aboutKPMcore = actionCollection ( ) - > addAction ( QStringLiteral ( " aboutKPMcore " ) ) ;
connect ( aboutKPMcore , & QAction : : triggered , this , & MainWindow : : onShowAboutKPMcore ) ;
aboutKPMcore - > setText ( xi18nc ( " @action:inmenu " , " About KPMcore Library " ) ) ;
aboutKPMcore - > setToolTip ( xi18nc ( " @info:tooltip " , " Show About KPMcore dialog " ) ) ;
aboutKPMcore - > setStatusTip ( xi18nc ( " @info:status " , " Show About KPMcore dialog. " ) ) ;
2020-09-29 17:54:53 +01:00
aboutKPMcore - > setIcon ( QIcon : : fromTheme ( QStringLiteral ( " partitionmanager " ) ) ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : setupConnections ( )
{
2017-10-09 13:54:31 +01:00
connect ( & listDevices ( ) , & ListDevices : : selectionChanged , & pmWidget ( ) , qOverload < const QString & > ( & PartitionManagerWidget : : setSelectedDevice ) ) ;
2016-05-22 20:03:49 +01:00
connect ( & listDevices ( ) , & ListDevices : : deviceDoubleClicked , this , & MainWindow : : onPropertiesDevice ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : setupStatusBar ( )
{
2015-07-13 15:17:41 +01:00
statusBar ( ) - > addWidget ( & statusText ( ) ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : loadConfig ( )
{
2015-07-13 15:17:41 +01:00
if ( Config : : firstRun ( ) ) {
dockLog ( ) . setVisible ( false ) ;
dockInformation ( ) . setVisible ( false ) ;
}
2015-07-15 18:03:39 +01:00
PartitionAlignment : : setSectorAlignment ( Config : : sectorAlignment ( ) ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : saveConfig ( ) const
{
2015-07-13 15:17:41 +01:00
Config : : setFirstRun ( false ) ;
Config : : self ( ) - > save ( ) ;
2008-09-24 20:32:01 +01:00
}
2010-02-23 16:30:05 +00:00
void MainWindow : : enableActions ( )
{
2016-03-31 17:20:34 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " createNewPartitionTable " ) )
- > setEnabled ( CreatePartitionTableOperation : : canCreate ( pmWidget ( ) . selectedDevice ( ) ) ) ;
2016-08-14 18:25:01 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " createNewPartitionTable " ) )
2018-07-11 16:23:10 +01:00
- > setVisible ( pmWidget ( ) . selectedDevice ( ) & & ( pmWidget ( ) . selectedDevice ( ) - > type ( ) = = Device : : Type : : Disk_Device | |
pmWidget ( ) . selectedDevice ( ) - > type ( ) = = Device : : Type : : SoftwareRAID_Device ) ) ;
2016-03-31 17:20:34 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " exportPartitionTable " ) )
- > setEnabled ( pmWidget ( ) . selectedDevice ( ) & &
pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) & &
operationStack ( ) . size ( ) = = 0 ) ;
actionCollection ( ) - > action ( QStringLiteral ( " importPartitionTable " ) )
- > setEnabled ( CreatePartitionTableOperation : : canCreate ( pmWidget ( ) . selectedDevice ( ) ) ) ;
actionCollection ( ) - > action ( QStringLiteral ( " smartStatusDevice " ) )
2018-04-09 02:58:03 +01:00
- > setEnabled ( pmWidget ( ) . selectedDevice ( ) ! = nullptr & & pmWidget ( ) . selectedDevice ( ) - > type ( ) = = Device : : Type : : Disk_Device & &
2016-03-31 17:20:34 +01:00
pmWidget ( ) . selectedDevice ( ) - > smartStatus ( ) . isValid ( ) ) ;
2016-08-14 18:25:01 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " smartStatusDevice " ) )
2018-04-09 02:58:03 +01:00
- > setVisible ( pmWidget ( ) . selectedDevice ( ) ! = nullptr & & pmWidget ( ) . selectedDevice ( ) - > type ( ) = = Device : : Type : : Disk_Device ) ;
2016-03-31 17:20:34 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " propertiesDevice " ) )
- > setEnabled ( pmWidget ( ) . selectedDevice ( ) ! = nullptr ) ;
actionCollection ( ) - > action ( QStringLiteral ( " undoOperation " ) )
- > setEnabled ( operationStack ( ) . size ( ) > 0 ) ;
actionCollection ( ) - > action ( QStringLiteral ( " clearAllOperations " ) )
- > setEnabled ( operationStack ( ) . size ( ) > 0 ) ;
actionCollection ( ) - > action ( QStringLiteral ( " applyAllOperations " ) )
2018-04-03 20:01:14 +01:00
- > setEnabled ( operationStack ( ) . size ( ) > 0 ) ;
2016-03-31 17:20:34 +01:00
const bool readOnly = pmWidget ( ) . selectedDevice ( ) = = nullptr | |
pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) = = nullptr | |
2015-07-13 15:17:41 +01:00
pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) - > isReadOnly ( ) ;
2010-02-23 16:30:05 +00:00
2016-06-30 00:17:05 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " createVolumeGroup " ) )
- > setEnabled ( CreateVolumeGroupOperation : : canCreate ( ) ) ;
2018-04-09 02:58:03 +01:00
bool lvmDevice = pmWidget ( ) . selectedDevice ( ) & & pmWidget ( ) . selectedDevice ( ) - > type ( ) = = Device : : Type : : LVM_Device ;
2016-09-04 23:34:16 +01:00
bool removable = false ;
2016-09-05 17:29:09 +01:00
2016-11-05 15:35:27 +00:00
if ( lvmDevice )
removable = RemoveVolumeGroupOperation : : isRemovable ( dynamic_cast < LvmDevice * > ( pmWidget ( ) . selectedDevice ( ) ) ) ;
2016-08-11 17:03:43 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " removeVolumeGroup " ) ) - > setEnabled ( removable ) ;
2016-08-14 17:16:52 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " removeVolumeGroup " ) ) - > setVisible ( lvmDevice ) ;
2016-07-03 18:02:16 +01:00
2016-08-14 18:28:30 +01:00
bool deactivatable = lvmDevice ?
DeactivateVolumeGroupOperation : : isDeactivatable ( dynamic_cast < LvmDevice * > ( pmWidget ( ) . selectedDevice ( ) ) ) : false ;
2016-08-11 17:03:43 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " deactivateVolumeGroup " ) ) - > setEnabled ( deactivatable ) ;
2016-08-14 17:16:52 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " deactivateVolumeGroup " ) ) - > setVisible ( lvmDevice ) ;
2016-08-08 06:54:24 +01:00
2016-08-14 17:16:52 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " resizeVolumeGroup " ) ) - > setEnabled ( lvmDevice ) ;
actionCollection ( ) - > action ( QStringLiteral ( " resizeVolumeGroup " ) ) - > setVisible ( lvmDevice ) ;
2016-07-03 18:02:16 +01:00
2016-07-09 01:12:31 +01:00
const Partition * part = pmWidget ( ) . selectedPartition ( ) ;
actionCollection ( ) - > action ( QStringLiteral ( " newPartition " ) )
- > setEnabled ( ! readOnly & & NewOperation : : canCreateNew ( part ) ) ;
2016-03-31 17:20:34 +01:00
const bool canResize = ResizeOperation : : canGrow ( part ) | |
ResizeOperation : : canShrink ( part ) | |
ResizeOperation : : canMove ( part ) ;
actionCollection ( ) - > action ( QStringLiteral ( " resizePartition " ) )
- > setEnabled ( ! readOnly & & canResize ) ;
actionCollection ( ) - > action ( QStringLiteral ( " copyPartition " ) )
- > setEnabled ( CopyOperation : : canCopy ( part ) ) ;
actionCollection ( ) - > action ( QStringLiteral ( " deletePartition " ) )
- > setEnabled ( ! readOnly & & DeleteOperation : : canDelete ( part ) ) ;
actionCollection ( ) - > action ( QStringLiteral ( " shredPartition " ) )
- > setEnabled ( ! readOnly & & DeleteOperation : : canDelete ( part ) ) ;
actionCollection ( ) - > action ( QStringLiteral ( " pastePartition " ) )
- > setEnabled ( ! readOnly & & CopyOperation : : canPaste ( part , pmWidget ( ) . clipboardPartition ( ) ) ) ;
actionCollection ( ) - > action ( QStringLiteral ( " propertiesPartition " ) )
- > setEnabled ( part ! = nullptr ) ;
actionCollection ( ) - > action ( QStringLiteral ( " editMountPoint " ) )
2016-05-24 16:44:07 +01:00
- > setEnabled ( part & & ! part - > isMounted ( ) & & part - > fileSystem ( ) . canMount ( part - > deviceNode ( ) , QStringLiteral ( " / " ) ) ) ;
2016-03-31 17:20:34 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " mountPartition " ) )
- > setEnabled ( part & &
( part - > canMount ( ) | | part - > canUnmount ( ) ) ) ;
if ( part ! = nullptr )
actionCollection ( ) - > action ( QStringLiteral ( " mountPartition " ) )
- > setText ( part - > isMounted ( ) ?
part - > fileSystem ( ) . unmountTitle ( ) :
part - > fileSystem ( ) . mountTitle ( ) ) ;
2016-04-20 13:44:55 +01:00
if ( part & & part - > roles ( ) . has ( PartitionRole : : Luks ) ) {
const FileSystem & fsRef = part - > fileSystem ( ) ;
const FS : : luks * luksFs = dynamic_cast < const FS : : luks * > ( & fsRef ) ;
2016-09-06 00:34:16 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " decryptPartition " ) )
- > setVisible ( true ) ;
2016-04-19 15:54:33 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " decryptPartition " ) )
2016-05-18 14:56:57 +01:00
- > setEnabled ( luksFs & & ! operationStack ( ) . contains ( part ) & &
2016-04-20 13:44:55 +01:00
( luksFs - > canCryptOpen ( part - > partitionPath ( ) ) | |
luksFs - > canCryptClose ( part - > partitionPath ( ) ) ) ) ;
if ( luksFs ) {
actionCollection ( ) - > action ( QStringLiteral ( " decryptPartition " ) )
- > setText ( luksFs - > isCryptOpen ( ) ?
luksFs - > cryptCloseTitle ( ) :
luksFs - > cryptOpenTitle ( ) ) ;
2016-04-19 15:54:33 +01:00
}
2016-04-20 13:44:55 +01:00
}
else {
2016-03-31 17:20:34 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " decryptPartition " ) )
2016-04-19 15:54:33 +01:00
- > setEnabled ( false ) ;
2016-09-06 00:34:16 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " decryptPartition " ) )
- > setVisible ( false ) ;
2016-03-31 17:20:34 +01:00
}
2010-02-23 16:30:05 +00:00
2016-04-19 15:54:33 +01:00
2016-03-31 17:20:34 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " checkPartition " ) )
- > setEnabled ( ! readOnly & & CheckOperation : : canCheck ( part ) ) ;
2010-02-23 16:30:05 +00:00
2016-03-31 17:20:34 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " backupPartition " ) )
- > setEnabled ( BackupOperation : : canBackup ( part ) ) ;
actionCollection ( ) - > action ( QStringLiteral ( " restorePartition " ) )
- > setEnabled ( RestoreOperation : : canRestore ( part ) ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : on_m_ApplyProgressDialog_finished ( )
2008-09-24 20:32:01 +01:00
{
2015-07-13 15:17:41 +01:00
scanDevices ( ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : on_m_OperationStack_operationsChanged ( )
{
2015-07-13 15:17:41 +01:00
listOperations ( ) . updateOperations ( operationStack ( ) . operations ( ) ) ;
pmWidget ( ) . updatePartitions ( ) ;
enableActions ( ) ;
2010-03-03 00:15:26 +00:00
2015-07-13 15:17:41 +01:00
// this will make sure that the info pane gets updated
on_m_PartitionManagerWidget_selectedPartitionChanged ( pmWidget ( ) . selectedPartition ( ) ) ;
2010-02-12 11:29:12 +00:00
2016-07-18 02:21:14 +01:00
statusText ( ) . setText ( xi18ncp ( " @info:status " , " One pending operation " , " %1 pending operations " , operationStack ( ) . size ( ) ) ) ;
2008-09-24 20:32:01 +01:00
}
2010-02-23 16:30:05 +00:00
void MainWindow : : on_m_OperationStack_devicesChanged ( )
2008-09-24 20:32:01 +01:00
{
2015-07-13 15:17:41 +01:00
QReadLocker lockDevices ( & operationStack ( ) . lock ( ) ) ;
2010-02-13 11:25:56 +00:00
2015-07-13 15:17:41 +01:00
listDevices ( ) . updateDevices ( operationStack ( ) . previewDevices ( ) ) ;
2010-01-28 16:27:28 +00:00
2015-07-13 15:17:41 +01:00
if ( pmWidget ( ) . selectedDevice ( ) )
infoPane ( ) . showDevice ( dockWidgetArea ( & dockInformation ( ) ) , * pmWidget ( ) . selectedDevice ( ) ) ;
else
infoPane ( ) . clear ( ) ;
2008-09-24 20:32:01 +01:00
2015-07-13 15:17:41 +01:00
updateWindowTitle ( ) ;
2008-09-24 20:32:01 +01:00
}
2010-02-12 11:29:12 +00:00
void MainWindow : : on_m_DockInformation_dockLocationChanged ( Qt : : DockWidgetArea )
2010-01-16 21:14:19 +00:00
{
2015-07-13 15:17:41 +01:00
on_m_PartitionManagerWidget_selectedPartitionChanged ( pmWidget ( ) . selectedPartition ( ) ) ;
2010-01-16 21:14:19 +00:00
}
2008-09-24 20:32:01 +01:00
void MainWindow : : updateWindowTitle ( )
{
2015-07-13 15:17:41 +01:00
QString title ;
2008-09-24 20:32:01 +01:00
2015-07-13 15:17:41 +01:00
if ( pmWidget ( ) . selectedDevice ( ) )
title = pmWidget ( ) . selectedDevice ( ) - > deviceNode ( ) ;
2008-09-24 20:32:01 +01:00
2015-07-13 15:17:41 +01:00
setWindowTitle ( title ) ;
2008-09-24 20:32:01 +01:00
}
2016-07-02 12:12:56 +01:00
void MainWindow : : listOperationsContextMenuRequested ( const QPoint & pos )
2010-03-07 19:02:02 +00:00
{
2015-07-13 15:17:41 +01:00
QMenu * menu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " edit " ) , this ) ) ;
2010-03-07 19:02:02 +00:00
2015-07-13 15:17:41 +01:00
if ( menu )
2016-07-02 12:12:56 +01:00
menu - > exec ( m_ListOperations - > listOperations ( ) . viewport ( ) - > mapToGlobal ( pos ) ) ;
2010-03-07 19:02:02 +00:00
}
2016-07-02 12:12:56 +01:00
void MainWindow : : treeLogContextMenuRequested ( const QPoint & pos )
2010-03-07 19:02:02 +00:00
{
2015-07-13 15:17:41 +01:00
QMenu * menu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " log " ) , this ) ) ;
2010-03-07 19:02:02 +00:00
2015-07-13 15:17:41 +01:00
if ( menu )
2016-07-02 12:12:56 +01:00
menu - > exec ( m_TreeLog - > treeLog ( ) . viewport ( ) - > mapToGlobal ( pos ) ) ;
2010-03-07 19:02:02 +00:00
}
2016-07-02 12:12:56 +01:00
void MainWindow : : listDevicesContextMenuRequested ( const QPoint & pos )
2010-02-23 16:30:05 +00:00
{
2015-07-13 15:17:41 +01:00
QMenu * menu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " device " ) , this ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
if ( menu )
2016-07-02 12:12:56 +01:00
menu - > exec ( m_ListDevices - > listDevices ( ) . viewport ( ) - > mapToGlobal ( pos ) ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : on_m_PartitionManagerWidget_contextMenuRequested ( const QPoint & pos )
{
2016-03-31 17:20:34 +01:00
QMenu * menu = nullptr ;
2015-07-13 15:17:41 +01:00
2016-03-31 17:20:34 +01:00
if ( pmWidget ( ) . selectedPartition ( ) = = nullptr ) {
if ( pmWidget ( ) . selectedDevice ( ) ! = nullptr )
2015-07-13 15:17:41 +01:00
menu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " device " ) , this ) ) ;
} else
menu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " partition " ) , this ) ) ;
if ( menu )
menu - > exec ( pos ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : on_m_PartitionManagerWidget_deviceDoubleClicked ( const Device * )
{
2015-07-13 15:17:41 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " propertiesDevice " ) ) - > trigger ( ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : on_m_PartitionManagerWidget_partitionDoubleClicked ( const Partition * )
{
2015-07-13 15:17:41 +01:00
actionCollection ( ) - > action ( QStringLiteral ( " propertiesPartition " ) ) - > trigger ( ) ;
2010-02-23 16:30:05 +00:00
}
2010-02-12 11:29:12 +00:00
void MainWindow : : on_m_PartitionManagerWidget_selectedPartitionChanged ( const Partition * p )
2008-09-24 20:32:01 +01:00
{
2015-07-13 15:17:41 +01:00
if ( p )
infoPane ( ) . showPartition ( dockWidgetArea ( & dockInformation ( ) ) , * p ) ;
else if ( pmWidget ( ) . selectedDevice ( ) )
infoPane ( ) . showDevice ( dockWidgetArea ( & dockInformation ( ) ) , * pmWidget ( ) . selectedDevice ( ) ) ;
else
infoPane ( ) . clear ( ) ;
updateWindowTitle ( ) ;
enableActions ( ) ;
2008-09-24 20:32:01 +01:00
}
2010-02-23 16:30:05 +00:00
void MainWindow : : scanDevices ( )
{
2018-04-09 15:14:48 +01:00
Log ( Log : : Level : : information ) < < xi18nc ( " @info:progress " , " Using backend plugin: %1 (%2) " ,
2015-07-13 15:17:41 +01:00
CoreBackendManager : : self ( ) - > backend ( ) - > id ( ) ,
CoreBackendManager : : self ( ) - > backend ( ) - > version ( ) ) ;
2012-01-18 11:17:25 +00:00
2016-07-18 02:21:14 +01:00
Log ( ) < < xi18nc ( " @info:progress " , " Scanning devices... " ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
// remember the currently selected device's node
setSavedSelectedDeviceNode ( pmWidget ( ) . selectedDevice ( ) ? pmWidget ( ) . selectedDevice ( ) - > deviceNode ( ) : QString ( ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
pmWidget ( ) . clear ( ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
QApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
scanProgressDialog ( ) . setEnabled ( true ) ;
scanProgressDialog ( ) . show ( ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
deviceScanner ( ) . start ( ) ;
2010-02-23 16:30:05 +00:00
}
2017-10-06 23:13:08 +01:00
void MainWindow : : on_m_DeviceScanner_progress ( const QString & deviceNode , int percent )
2010-02-23 16:30:05 +00:00
{
2015-07-13 15:17:41 +01:00
scanProgressDialog ( ) . setProgress ( percent ) ;
2017-10-06 23:13:08 +01:00
scanProgressDialog ( ) . setDeviceName ( deviceNode ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : on_m_DeviceScanner_finished ( )
{
2015-07-13 15:17:41 +01:00
QReadLocker lockDevices ( & operationStack ( ) . lock ( ) ) ;
2010-04-27 13:11:50 +01:00
2015-07-13 15:17:41 +01:00
scanProgressDialog ( ) . setProgress ( 100 ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
if ( ! operationStack ( ) . previewDevices ( ) . isEmpty ( ) )
pmWidget ( ) . setSelectedDevice ( operationStack ( ) . previewDevices ( ) [ 0 ] ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
pmWidget ( ) . updatePartitions ( ) ;
2010-02-23 16:30:05 +00:00
2016-07-18 02:21:14 +01:00
Log ( ) < < xi18nc ( " @info:progress " , " Scan finished. " ) ;
2015-07-13 15:17:41 +01:00
QApplication : : restoreOverrideCursor ( ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
// try to set the seleted device, either from the saved one or just select the
// first device
if ( ! listDevices ( ) . setSelectedDevice ( savedSelectedDeviceNode ( ) ) & & ! operationStack ( ) . previewDevices ( ) . isEmpty ( ) )
listDevices ( ) . setSelectedDevice ( operationStack ( ) . previewDevices ( ) [ 0 ] - > deviceNode ( ) ) ;
2010-05-19 19:39:40 +01:00
2015-07-13 15:17:41 +01:00
updateSeletedDeviceMenu ( ) ;
checkFileSystemSupport ( ) ;
2010-05-19 19:39:40 +01:00
}
void MainWindow : : updateSeletedDeviceMenu ( )
{
2015-07-13 15:17:41 +01:00
QMenu * devicesMenu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " selectedDevice " ) , this ) ) ;
2018-06-09 13:27:35 +01:00
if ( ! devicesMenu )
return ;
2015-07-13 15:17:41 +01:00
devicesMenu - > clear ( ) ;
devicesMenu - > setEnabled ( ! operationStack ( ) . previewDevices ( ) . isEmpty ( ) ) ;
2016-09-01 00:44:33 +01:00
const auto previewDevices = operationStack ( ) . previewDevices ( ) ;
for ( auto const & d : previewDevices ) {
2015-07-13 15:17:41 +01:00
QAction * action = new QAction ( d - > prettyName ( ) , devicesMenu ) ;
action - > setCheckable ( true ) ;
action - > setChecked ( d - > deviceNode ( ) = = pmWidget ( ) . selectedDevice ( ) - > deviceNode ( ) ) ;
action - > setData ( d - > deviceNode ( ) ) ;
2016-05-18 22:23:59 +01:00
connect ( action , & QAction : : triggered , this , & MainWindow : : onSelectedDeviceMenuTriggered ) ;
2015-07-13 15:17:41 +01:00
devicesMenu - > addAction ( action ) ;
}
2010-05-19 19:39:40 +01:00
}
void MainWindow : : onSelectedDeviceMenuTriggered ( bool )
{
2015-07-13 15:17:41 +01:00
QAction * action = qobject_cast < QAction * > ( sender ( ) ) ;
QMenu * devicesMenu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " selectedDevice " ) , this ) ) ;
2010-05-19 19:39:40 +01:00
2018-06-09 13:27:35 +01:00
if ( action = = nullptr | | action - > parent ( ) ! = devicesMenu | | ! devicesMenu )
2015-07-13 15:17:41 +01:00
return ;
2010-05-19 19:39:40 +01:00
2016-09-01 00:44:33 +01:00
const auto children = devicesMenu - > findChildren < QAction * > ( ) ;
for ( auto & entry : children )
2016-08-08 19:39:20 +01:00
entry - > setChecked ( entry = = action ) ;
2010-05-19 19:39:40 +01:00
2015-07-13 15:17:41 +01:00
listDevices ( ) . setSelectedDevice ( action - > data ( ) . toString ( ) ) ;
2010-05-19 19:39:40 +01:00
}
void MainWindow : : on_m_ListDevices_selectionChanged ( const QString & device_node )
{
2015-07-13 15:17:41 +01:00
QMenu * devicesMenu = static_cast < QMenu * > ( guiFactory ( ) - > container ( QStringLiteral ( " selectedDevice " ) , this ) ) ;
2018-06-09 13:27:35 +01:00
if ( ! devicesMenu )
return ;
2010-05-19 19:39:40 +01:00
2016-09-01 00:44:33 +01:00
const auto children = devicesMenu - > findChildren < QAction * > ( ) ;
for ( auto & entry : children )
2016-08-08 19:39:20 +01:00
entry - > setChecked ( entry - > data ( ) . toString ( ) = = device_node ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : onRefreshDevices ( )
{
2015-07-13 15:17:41 +01:00
if ( operationStack ( ) . size ( ) = = 0 | | KMessageBox : : warningContinueCancel ( this ,
xi18nc ( " @info " ,
" <para>Do you really want to rescan the devices?</para> "
" <para><warning>This will also clear the list of pending operations.</warning></para> " ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " , " Really Rescan the Devices? " ) ,
KGuiItem ( xi18nc ( " @action:button " , " Rescan Devices " ) , QStringLiteral ( " arrow-right " ) ) ,
2015-07-13 15:17:41 +01:00
KStandardGuiItem : : cancel ( ) , QStringLiteral ( " reallyRescanDevices " ) ) = = KMessageBox : : Continue ) {
scanDevices ( ) ;
}
2010-02-23 16:30:05 +00:00
}
void MainWindow : : onApplyAllOperations ( )
{
2015-07-13 15:17:41 +01:00
QStringList opList ;
2010-02-23 16:30:05 +00:00
2016-09-01 00:44:33 +01:00
const auto operations = operationStack ( ) . operations ( ) ;
for ( const auto & op : operations )
2016-08-08 19:39:20 +01:00
opList . append ( op - > description ( ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
if ( KMessageBox : : warningContinueCancelList ( this ,
xi18nc ( " @info " ,
" <para>Do you really want to apply the pending operations listed below?</para> "
" <para><warning>This will permanently modify your disks.</warning></para> " ) ,
2016-07-18 02:21:14 +01:00
opList , xi18nc ( " @title:window " , " Apply Pending Operations? " ) ,
KGuiItem ( xi18nc ( " @action:button " , " Apply Pending Operations " ) , QStringLiteral ( " arrow-right " ) ) ,
2015-07-13 15:17:41 +01:00
KStandardGuiItem : : cancel ( ) ) = = KMessageBox : : Continue ) {
2016-07-18 02:21:14 +01:00
Log ( ) < < xi18nc ( " @info:status " , " Applying operations... " ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
applyProgressDialog ( ) . show ( ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
operationRunner ( ) . setReport ( & applyProgressDialog ( ) . report ( ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
// Undo all operations so the runner has a defined starting point
for ( int i = operationStack ( ) . operations ( ) . size ( ) - 1 ; i > = 0 ; i - - ) {
operationStack ( ) . operations ( ) [ i ] - > undo ( ) ;
operationStack ( ) . operations ( ) [ i ] - > setStatus ( Operation : : StatusNone ) ;
}
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
pmWidget ( ) . updatePartitions ( ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
operationRunner ( ) . start ( ) ;
}
2010-02-23 16:30:05 +00:00
}
void MainWindow : : onUndoOperation ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( operationStack ( ) . size ( ) > 0 ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
if ( operationStack ( ) . size ( ) = = 0 )
return ;
2010-02-23 16:30:05 +00:00
2016-07-18 02:21:14 +01:00
Log ( ) < < xi18nc ( " @info:status " , " Undoing operation: %1 " , operationStack ( ) . operations ( ) . last ( ) - > description ( ) ) ;
2015-07-13 15:17:41 +01:00
operationStack ( ) . pop ( ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
// it's possible the undo killed the partition in the clipboard. if there's a partition in the clipboard, try
// to find a device for it (OperationStack::findDeviceForPartition() only compares pointers, so an invalid
// pointer is not a problem). if no device is found, the pointer must be dangling, so clear the clipboard.
2016-03-31 17:20:34 +01:00
if ( pmWidget ( ) . clipboardPartition ( ) ! = nullptr & & operationStack ( ) . findDeviceForPartition ( pmWidget ( ) . clipboardPartition ( ) ) = = nullptr )
pmWidget ( ) . setClipboardPartition ( nullptr ) ;
2010-05-24 02:52:36 +01:00
2015-07-13 15:17:41 +01:00
pmWidget ( ) . updatePartitions ( ) ;
enableActions ( ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : onClearAllOperations ( )
{
2015-07-13 15:17:41 +01:00
if ( KMessageBox : : warningContinueCancel ( this ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @info " , " Do you really want to clear the list of pending operations? " ) ,
xi18nc ( " @title:window " , " Clear Pending Operations? " ) ,
KGuiItem ( xi18nc ( " @action:button " , " Clear Pending Operations " ) , QStringLiteral ( " arrow-right " ) ) ,
2015-07-13 15:17:41 +01:00
KStandardGuiItem : : cancel ( ) , QStringLiteral ( " reallyClearPendingOperations " ) ) = = KMessageBox : : Continue ) {
2016-07-18 02:21:14 +01:00
Log ( ) < < xi18nc ( " @info:status " , " Clearing the list of pending operations. " ) ;
2015-07-13 15:17:41 +01:00
operationStack ( ) . clearOperations ( ) ;
pmWidget ( ) . updatePartitions ( ) ;
enableActions ( ) ;
}
2010-02-23 16:30:05 +00:00
}
void MainWindow : : onCreateNewPartitionTable ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
2010-02-23 16:30:05 +00:00
2016-03-31 17:20:34 +01:00
if ( pmWidget ( ) . selectedDevice ( ) = = nullptr ) {
2015-07-13 15:17:41 +01:00
qWarning ( ) < < " selected device is null. " ;
return ;
}
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
QPointer < CreatePartitionTableDialog > dlg = new CreatePartitionTableDialog ( this , * pmWidget ( ) . selectedDevice ( ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
if ( dlg - > exec ( ) = = QDialog : : Accepted )
operationStack ( ) . push ( new CreatePartitionTableOperation ( * pmWidget ( ) . selectedDevice ( ) , dlg - > type ( ) ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
delete dlg ;
2010-03-03 00:15:26 +00:00
}
void MainWindow : : onImportPartitionTable ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
2016-05-10 14:49:57 +01:00
const QUrl url = QFileDialog : : getOpenFileUrl ( this , QStringLiteral ( " Import Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
if ( url . isEmpty ( ) )
return ;
2016-05-10 14:49:57 +01:00
QFile file ;
if ( url . isLocalFile ( ) )
{
file . setFileName ( url . toLocalFile ( ) ) ;
if ( ! file . open ( QFile : : ReadOnly ) )
{
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Could not open input file <filename>%1</filename> for import " , url . toLocalFile ( ) ) , xi18nc ( " @title:window " , " Error Importing Partition Table " ) ) ;
2016-05-10 14:49:57 +01:00
return ;
}
2015-07-13 15:17:41 +01:00
}
2016-05-10 14:49:57 +01:00
else
{
QTemporaryFile tempFile ;
2015-07-13 15:17:41 +01:00
2016-05-10 14:49:57 +01:00
if ( ! tempFile . open ( ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Could not create temporary file when trying to save to <filename>%1</filename>. " , tempFile . fileName ( ) ) , xi18nc ( " @title:window " , " Error Importing Partition Table " ) ) ;
2016-05-10 14:49:57 +01:00
return ;
}
2015-07-13 15:17:41 +01:00
2016-05-10 14:49:57 +01:00
KIO : : FileCopyJob * job = KIO : : file_copy ( url , QUrl : : fromLocalFile ( tempFile . fileName ( ) ) ) ;
KJobWidgets : : setWindow ( job , this ) ;
job - > exec ( ) ;
if ( job - > error ( ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Could not open input file <filename>%1</filename> for import: %2 " , url . fileName ( ) , job - > errorString ( ) ) , xi18nc ( " @title:window " , " Error Importing Partition Table " ) ) ;
2016-05-10 14:49:57 +01:00
return ;
}
2016-05-10 15:16:05 +01:00
file . setFileName ( tempFile . fileName ( ) ) ;
2016-05-10 14:49:57 +01:00
if ( ! file . open ( QFile : : ReadOnly ) )
{
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Could not open temporary file <filename>%1</filename> while trying to import from <filename>%2</filename>. " , tempFile . fileName ( ) , url . fileName ( ) ) , xi18nc ( " @title:window " , " Error Importing Partition Table " ) ) ;
2016-05-10 14:49:57 +01:00
return ;
}
2015-07-13 15:17:41 +01:00
}
Device & device = * pmWidget ( ) . selectedDevice ( ) ;
2016-05-10 14:53:26 +01:00
QString line ;
2015-07-13 15:17:41 +01:00
quint32 lineNo = 0 ;
bool haveMagic = false ;
2016-03-31 17:20:34 +01:00
PartitionTable * ptable = nullptr ;
2015-07-13 15:17:41 +01:00
PartitionTable : : TableType tableType = PartitionTable : : unknownTableType ;
2016-05-10 14:53:26 +01:00
while ( ! ( line = QString : : fromUtf8 ( file . readLine ( ) ) ) . isEmpty ( ) ) {
2015-07-13 15:17:41 +01:00
lineNo + + ;
2016-05-10 14:53:26 +01:00
line = line . trimmed ( ) ;
2015-07-13 15:17:41 +01:00
if ( line . isEmpty ( ) )
continue ;
2016-05-10 14:53:26 +01:00
QRegularExpression re ( QStringLiteral ( " ( \\ d+) ; ( \ \ d + ) ; ( \ \ d + ) ; ( \ \ w + ) ; ( \ \ w + ) ; ( \ " \\ w* \" );( \" [^ \" ]* \" ) " ) ) ;
QRegularExpressionMatch rePartition = re . match ( line ) ;
re . setPattern ( QStringLiteral ( " type: \\ s \" (.+) \" " ) ) ;
QRegularExpressionMatch reType = re . match ( line ) ;
re . setPattern ( QStringLiteral ( " align: \\ s \" (cylinder|sector) \" " ) ) ;
QRegularExpressionMatch reAlign = re . match ( line ) ;
re . setPattern ( QStringLiteral ( " ^##|v( \\ d+)|## " ) ) ;
QRegularExpressionMatch reMagic = re . match ( line ) ;
if ( ! ( haveMagic | | reMagic . hasMatch ( ) ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " The import file <filename>%1</filename> does not contain a valid partition table. " , url . fileName ( ) ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
} else
haveMagic = true ;
2016-05-10 14:53:26 +01:00
if ( line . startsWith ( QStringLiteral ( " # " ) ) )
2015-07-13 15:17:41 +01:00
continue ;
2016-05-10 14:53:26 +01:00
if ( reType . hasMatch ( ) ) {
2016-03-31 17:20:34 +01:00
if ( ptable ! = nullptr ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Found more than one partition table type in import file (line %1). " , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
2016-05-10 14:53:26 +01:00
tableType = PartitionTable : : nameToTableType ( reType . captured ( 1 ) ) ;
2015-07-13 15:17:41 +01:00
if ( tableType = = PartitionTable : : unknownTableType ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Partition table type \" %1 \" is unknown (line %2). " , reType . captured ( 1 ) , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
2020-10-04 15:21:15 +01:00
if ( tableType ! = PartitionTable : : msdos & & tableType ! = PartitionTable : : gpt & & tableType ! = PartitionTable : : none ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Partition table type \" %1 \" is not supported for import (line %2). " , reType . captured ( 1 ) , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
ptable = new PartitionTable ( tableType , PartitionTable : : defaultFirstUsable ( device , tableType ) , PartitionTable : : defaultLastUsable ( device , tableType ) ) ;
operationStack ( ) . push ( new CreatePartitionTableOperation ( device , ptable ) ) ;
2016-05-10 14:53:26 +01:00
} else if ( reAlign . hasMatch ( ) ) {
2015-07-13 15:17:41 +01:00
// currently ignored
2016-05-10 14:53:26 +01:00
} else if ( rePartition . hasMatch ( ) ) {
2016-03-31 17:20:34 +01:00
if ( ptable = = nullptr ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Found partition but no partition table type (line %1). " , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
2016-05-10 14:53:26 +01:00
qint32 num = rePartition . captured ( 1 ) . toInt ( ) ;
qint64 firstSector = rePartition . captured ( 2 ) . toLongLong ( ) ;
qint64 lastSector = rePartition . captured ( 3 ) . toLongLong ( ) ;
2019-02-27 23:15:17 +00:00
QString fsName = rePartition . captured ( 4 ) ;
2016-05-10 14:53:26 +01:00
QString roleNames = rePartition . captured ( 5 ) ;
QString volumeLabel = rePartition . captured ( 6 ) . replace ( QStringLiteral ( " \" " ) , QString ( ) ) ;
QStringList flags = rePartition . captured ( 7 ) . replace ( QStringLiteral ( " \" " ) , QString ( ) ) . split ( QStringLiteral ( " , " ) ) ;
2015-07-13 15:17:41 +01:00
if ( firstSector < ptable - > firstUsable ( ) | | lastSector > ptable - > lastUsable ( ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info the partition is NOT a device path, just a number " , " Partition %1 would be outside the device's boundaries (line %2). " , num , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
if ( firstSector > = lastSector ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Partition %1 has end before start sector (line %2). " , num , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
PartitionNode * parent = ptable ;
Q_ASSERT ( parent ) ;
PartitionRole role ( PartitionRole : : None ) ;
if ( roleNames = = QStringLiteral ( " extended " ) )
role = PartitionRole ( PartitionRole : : Extended ) ;
else if ( roleNames = = QStringLiteral ( " logical " ) ) {
role = PartitionRole ( PartitionRole : : Logical ) ;
parent = ptable - > findPartitionBySector ( firstSector , PartitionRole ( PartitionRole : : Extended ) ) ;
} else if ( roleNames = = QStringLiteral ( " primary " ) )
role = PartitionRole ( PartitionRole : : Primary ) ;
if ( role = = PartitionRole ( PartitionRole : : None ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info the partition is NOT a device path, just a number " , " Unrecognized partition role \" %1 \" for partition %2 (line %3). " , roleNames , num , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
2016-03-31 17:20:34 +01:00
if ( parent = = nullptr ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info the partition is NOT a device path, just a number " , " No parent partition or partition table found for partition %1 (line %2). " , num , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
if ( role . has ( PartitionRole : : Extended ) & & ! PartitionTable : : tableTypeSupportsExtended ( tableType ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " The partition table type \" %1 \" does not support extended partitions, but one was found (line %2). " , PartitionTable : : tableTypeToName ( tableType ) , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
2017-09-15 12:47:28 +01:00
FileSystem * fs = FileSystemFactory : : create ( FileSystem : : typeForName ( fsName , { QStringLiteral ( " C " ) } ) , firstSector , lastSector , device . logicalSize ( ) ) ;
2015-07-13 15:17:41 +01:00
2016-03-31 17:20:34 +01:00
if ( fs = = nullptr ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info the partition is NOT a device path, just a number " , " Could not create file system \" %1 \" for partition %2 (line %3). " , fsName , num , lineNo ) , xi18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
if ( fs - > supportSetLabel ( ) ! = FileSystem : : cmdSupportNone & & ! volumeLabel . isEmpty ( ) )
fs - > setLabel ( volumeLabel ) ;
2020-10-04 16:58:38 +01:00
Partition * p = new Partition ( parent , device , role , fs , firstSector , lastSector , QString ( ) , PartitionTable : : Flag : : None , QString ( ) , false , PartitionTable : : Flag : : None , Partition : : State : : New ) ;
2015-07-13 15:17:41 +01:00
operationStack ( ) . push ( new NewOperation ( device , p ) ) ;
2020-10-04 16:58:38 +01:00
auto newFlags = PartitionTable : : flagsFromList ( flags ) ;
if ( newFlags ! = PartitionTable : : Flag : : None )
operationStack ( ) . push ( new SetPartFlagsOperation ( device , * p , newFlags ) ) ;
2015-07-13 15:17:41 +01:00
} else
2018-04-09 15:14:48 +01:00
Log ( Log : : Level : : warning ) < < xi18nc ( " @info:status " , " Could not parse line %1 from import file. Ignoring it. " , lineNo ) ;
2015-07-13 15:17:41 +01:00
}
if ( ptable - > type ( ) = = PartitionTable : : msdos & & ptable - > isSectorBased ( device ) )
ptable - > setType ( device , PartitionTable : : msdos_sectorbased ) ;
2010-02-23 16:30:05 +00:00
}
2010-03-02 13:35:57 +00:00
void MainWindow : : onExportPartitionTable ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) ) ;
2010-03-02 13:35:57 +00:00
2015-07-13 15:17:41 +01:00
const QUrl url = QFileDialog : : getSaveFileUrl ( ) ;
2010-03-02 13:35:57 +00:00
2015-07-13 15:17:41 +01:00
if ( url . isEmpty ( ) )
return ;
2010-03-02 13:35:57 +00:00
2015-07-13 15:17:41 +01:00
QTemporaryFile tempFile ;
2010-03-02 13:35:57 +00:00
2015-07-13 15:17:41 +01:00
if ( ! tempFile . open ( ) ) {
2016-07-18 02:21:14 +01:00
KMessageBox : : error ( this , xi18nc ( " @info " , " Could not create temporary file when trying to save to <filename>%1</filename>. " , url . fileName ( ) ) , xi18nc ( " @title:window " , " Error Exporting Partition Table " ) ) ;
2015-07-13 15:17:41 +01:00
return ;
}
2010-03-02 13:35:57 +00:00
2015-07-13 15:17:41 +01:00
QTextStream stream ( & tempFile ) ;
2010-03-02 13:35:57 +00:00
2015-07-13 15:17:41 +01:00
stream < < " ##|v1|## partition table of " < < pmWidget ( ) . selectedDevice ( ) - > deviceNode ( ) < < " \n " ;
2017-09-15 12:47:28 +01:00
stream < < " # on " < < QLocale : : c ( ) . toString ( QDateTime : : currentDateTime ( ) ) < < " \n " ;
2015-07-13 15:17:41 +01:00
stream < < * pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) ;
2010-04-11 17:12:16 +01:00
2015-07-13 15:17:41 +01:00
tempFile . close ( ) ;
2010-04-11 17:12:16 +01:00
2015-07-13 15:17:41 +01:00
KIO : : CopyJob * job = KIO : : move ( QUrl : : fromLocalFile ( tempFile . fileName ( ) ) , url , KIO : : HideProgressInfo ) ;
job - > exec ( ) ;
if ( job - > error ( ) )
2017-04-11 20:49:46 +01:00
job - > uiDelegate ( ) - > showErrorMessage ( ) ;
2010-03-02 13:35:57 +00:00
}
2016-06-30 00:17:05 +01:00
void MainWindow : : onCreateNewVolumeGroup ( )
{
2016-09-18 01:55:14 +01:00
QString vgName ;
2017-08-31 10:34:58 +01:00
QVector < const Partition * > pvList ;
2016-09-18 01:55:14 +01:00
qint32 peSize = 4 ;
// *NOTE*: vgName & pvList will be modified and validated by the dialog
2018-05-04 00:50:42 +01:00
QPointer < CreateVolumeGroupDialog > dlg = new CreateVolumeGroupDialog ( this , vgName , pvList , peSize , operationStack ( ) . previewDevices ( ) , operationStack ( ) . operations ( ) ) ;
2016-09-18 01:55:14 +01:00
if ( dlg - > exec ( ) = = QDialog : : Accepted )
2017-08-31 10:49:26 +01:00
operationStack ( ) . push ( new CreateVolumeGroupOperation ( vgName , pvList , peSize ) ) ;
2016-09-18 01:55:14 +01:00
2016-06-30 00:17:05 +01:00
delete dlg ;
2016-09-18 01:55:14 +01:00
}
void MainWindow : : onResizeVolumeGroup ( )
{
2018-04-09 02:58:03 +01:00
if ( pmWidget ( ) . selectedDevice ( ) - > type ( ) = = Device : : Type : : LVM_Device ) {
2016-09-24 21:09:16 +01:00
LvmDevice * d = dynamic_cast < LvmDevice * > ( pmWidget ( ) . selectedDevice ( ) ) ;
2016-09-18 01:55:14 +01:00
2017-08-31 10:34:58 +01:00
QVector < const Partition * > pvList ;
2016-09-18 01:55:14 +01:00
// *NOTE*: pvList will be modified and validated by the dialog
2018-07-16 00:20:00 +01:00
QPointer < ResizeVolumeGroupDialog > dlg = new ResizeVolumeGroupDialog ( this , d , pvList , operationStack ( ) . previewDevices ( ) , operationStack ( ) . operations ( ) ) ;
2016-09-18 01:55:14 +01:00
if ( dlg - > exec ( ) = = QDialog : : Accepted )
2017-08-31 10:49:26 +01:00
operationStack ( ) . push ( new ResizeVolumeGroupOperation ( * d , pvList ) ) ;
2016-09-18 01:55:14 +01:00
delete dlg ;
}
2016-07-03 18:02:16 +01:00
}
void MainWindow : : onRemoveVolumeGroup ( )
{
Device * tmpDev = pmWidget ( ) . selectedDevice ( ) ;
2018-04-09 02:58:03 +01:00
if ( tmpDev - > type ( ) = = Device : : Type : : LVM_Device ) {
2016-11-05 15:35:27 +00:00
operationStack ( ) . push ( new RemoveVolumeGroupOperation ( * ( dynamic_cast < LvmDevice * > ( tmpDev ) ) ) ) ;
2016-07-03 18:02:16 +01:00
}
}
2016-08-08 06:54:24 +01:00
void MainWindow : : onDeactivateVolumeGroup ( )
{
Device * tmpDev = pmWidget ( ) . selectedDevice ( ) ;
2018-04-09 02:58:03 +01:00
if ( tmpDev - > type ( ) = = Device : : Type : : LVM_Device ) {
2016-08-11 22:33:51 +01:00
DeactivateVolumeGroupOperation * deactivate = new DeactivateVolumeGroupOperation ( * ( dynamic_cast < LvmDevice * > ( tmpDev ) ) ) ;
Report * tmpReport = new Report ( nullptr ) ;
2016-08-14 17:48:36 +01:00
if ( deactivate - > execute ( * tmpReport ) ) {
deactivate - > preview ( ) ;
actionCollection ( ) - > action ( QStringLiteral ( " resizeVolumeGroup " ) ) - > setEnabled ( false ) ;
actionCollection ( ) - > action ( QStringLiteral ( " deactivateVolumeGroup " ) ) - > setEnabled ( false ) ;
}
2016-08-11 22:33:51 +01:00
delete tmpReport ;
pmWidget ( ) . updatePartitions ( ) ;
2016-10-30 02:32:26 +00:00
enableActions ( ) ;
2016-08-08 06:54:24 +01:00
}
}
2010-02-23 16:30:05 +00:00
void MainWindow : : onFileSystemSupport ( )
{
2015-07-13 15:17:41 +01:00
FileSystemSupportDialog dlg ( this ) ;
dlg . exec ( ) ;
2010-02-23 16:30:05 +00:00
}
2016-08-25 00:15:07 +01:00
void MainWindow : : onShowAboutKPMcore ( )
{
KAboutApplicationDialog dlg ( aboutKPMcore ( ) , this ) ;
dlg . exec ( ) ;
}
2010-03-21 10:50:44 +00:00
void MainWindow : : onSettingsChanged ( )
2010-02-23 16:30:05 +00:00
{
2015-07-13 15:17:41 +01:00
if ( CoreBackendManager : : self ( ) - > backend ( ) - > id ( ) ! = Config : : backend ( ) ) {
CoreBackendManager : : self ( ) - > unload ( ) ;
// FIXME: if loadBackend() fails to load the configured backend and loads the default
// one instead it also sets the default backend in the config; the config dialog will
// overwrite that again, however, after we're done here.
if ( loadBackend ( ) ) {
deviceScanner ( ) . setupConnections ( ) ;
scanDevices ( ) ;
FileSystemFactory : : init ( ) ;
} else
close ( ) ;
}
enableActions ( ) ;
pmWidget ( ) . updatePartitions ( ) ;
2015-07-15 18:03:39 +01:00
PartitionAlignment : : setSectorAlignment ( Config : : sectorAlignment ( ) ) ;
2015-07-17 12:37:30 +01:00
2020-09-15 02:26:38 +01:00
Q_EMIT settingsChanged ( ) ;
2010-02-23 16:30:05 +00:00
}
void MainWindow : : onConfigureOptions ( )
{
2015-07-13 15:17:41 +01:00
if ( ConfigureOptionsDialog : : showDialog ( QStringLiteral ( " Settings " ) ) )
return ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
QPointer < ConfigureOptionsDialog > dlg = new ConfigureOptionsDialog ( this , operationStack ( ) , QStringLiteral ( " Settings " ) ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
// FIXME: we'd normally use settingsChanged(), according to the kde api docs. however, this
// is emitted each time the user changes any of our own settings (backend, default file system), without
// applying or clicking ok. so the below is the workaround for that.
connect ( dlg - > button ( QDialogButtonBox : : Apply ) , & QPushButton : : clicked , this , & MainWindow : : onSettingsChanged ) ;
connect ( dlg - > button ( QDialogButtonBox : : Ok ) , & QPushButton : : clicked , this , & MainWindow : : onSettingsChanged ) ;
2010-02-23 16:30:05 +00:00
2015-07-13 15:17:41 +01:00
dlg - > show ( ) ;
2010-02-23 16:30:05 +00:00
}
2010-03-27 13:47:32 +00:00
void MainWindow : : onSmartStatusDevice ( )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
if ( pmWidget ( ) . selectedDevice ( ) ) {
QPointer < SmartDialog > dlg = new SmartDialog ( this , * pmWidget ( ) . selectedDevice ( ) ) ;
dlg - > exec ( ) ;
delete dlg ;
}
2010-03-27 13:47:32 +00:00
}
2010-02-23 16:30:05 +00:00
void MainWindow : : onPropertiesDevice ( const QString & )
{
2015-07-13 15:17:41 +01:00
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
if ( pmWidget ( ) . selectedDevice ( ) ) {
Device & d = * pmWidget ( ) . selectedDevice ( ) ;
QPointer < DevicePropsDialog > dlg = new DevicePropsDialog ( this , d ) ;
if ( dlg - > exec ( ) = = QDialog : : Accepted ) {
if ( d . partitionTable ( ) - > type ( ) = = PartitionTable : : msdos & & dlg - > sectorBasedAlignment ( ) )
d . partitionTable ( ) - > setType ( d , PartitionTable : : msdos_sectorbased ) ;
else if ( d . partitionTable ( ) - > type ( ) = = PartitionTable : : msdos_sectorbased & & dlg - > cylinderBasedAlignment ( ) )
d . partitionTable ( ) - > setType ( d , PartitionTable : : msdos ) ;
on_m_OperationStack_devicesChanged ( ) ;
pmWidget ( ) . updatePartitions ( ) ;
}
delete dlg ;
}
2010-02-23 16:30:05 +00:00
}
2010-05-20 16:25:55 +01:00
2016-02-18 14:59:59 +00:00
static KLocalizedString checkSupportInNode ( const PartitionNode * parent )
2010-05-20 16:25:55 +01:00
{
2016-04-14 19:18:36 +01:00
if ( parent = = nullptr )
2016-02-18 14:59:59 +00:00
return KLocalizedString ( ) ;
2015-07-13 15:17:41 +01:00
2016-02-18 14:59:59 +00:00
KLocalizedString rval ;
2015-07-13 15:17:41 +01:00
2016-09-07 14:36:59 +01:00
for ( const auto & node : parent - > children ( ) ) {
2015-07-13 15:17:41 +01:00
const Partition * p = dynamic_cast < const Partition * > ( node ) ;
2016-03-31 17:20:34 +01:00
if ( p = = nullptr )
2015-07-13 15:17:41 +01:00
continue ;
2016-07-06 16:02:06 +01:00
if ( node - > children ( ) . size ( ) > 0 & & ! rval . isEmpty ( ) )
2016-02-29 01:05:24 +00:00
rval = kxi18n ( " %1%2 " ) . subs ( rval ) . subs ( checkSupportInNode ( node ) ) ;
2016-07-06 16:02:06 +01:00
else
rval = checkSupportInNode ( node ) ;
2015-07-13 15:17:41 +01:00
2016-07-24 19:07:31 +01:00
if ( ( ! p - > fileSystem ( ) . supportToolFound ( ) & & ! p - > fileSystem ( ) . supportToolName ( ) . name . isEmpty ( ) ) & & ! rval . isEmpty ( ) )
2016-02-29 01:05:24 +00:00
rval = kxi18n ( " %1%2 " ) . subs ( rval ) . subs ( kxi18n ( " <tr> "
2015-07-13 15:17:41 +01:00
" <td>%1</td> "
" <td>%2</td> "
" <td>%3</td> "
2016-07-18 02:21:14 +01:00
" <td><link>%4</link></td> "
2015-07-13 15:17:41 +01:00
" </tr> " )
2016-02-18 14:59:59 +00:00
. subs ( p - > deviceNode ( ) )
. subs ( p - > fileSystem ( ) . name ( ) )
. subs ( p - > fileSystem ( ) . supportToolName ( ) . name )
. subs ( p - > fileSystem ( ) . supportToolName ( ) . url . toString ( ) ) ) ;
2016-07-24 19:07:31 +01:00
else if ( ! p - > fileSystem ( ) . supportToolFound ( ) & & ! p - > fileSystem ( ) . supportToolName ( ) . name . isEmpty ( ) )
2016-07-24 18:47:33 +01:00
rval = kxi18n ( " <tr> "
" <td>%1</td> "
" <td>%2</td> "
" <td>%3</td> "
" <td><link>%4</link></td> "
" </tr> " )
. subs ( p - > deviceNode ( ) )
. subs ( p - > fileSystem ( ) . name ( ) )
. subs ( p - > fileSystem ( ) . supportToolName ( ) . name )
. subs ( p - > fileSystem ( ) . supportToolName ( ) . url . toString ( ) ) ;
2015-07-13 15:17:41 +01:00
}
return rval ;
2010-05-20 16:25:55 +01:00
}
void MainWindow : : checkFileSystemSupport ( )
{
2016-02-18 14:59:59 +00:00
KLocalizedString supportList , supportInNode ;
bool missingSupportTools = false ;
2015-07-13 15:17:41 +01:00
2016-09-01 00:44:33 +01:00
const auto previewDevices = operationStack ( ) . previewDevices ( ) ;
for ( auto const & d : previewDevices ) {
2016-02-18 14:59:59 +00:00
supportInNode = checkSupportInNode ( d - > partitionTable ( ) ) ;
2016-07-24 18:47:33 +01:00
if ( ! supportInNode . isEmpty ( ) & & ! supportList . isEmpty ( ) ) {
2016-02-18 14:59:59 +00:00
missingSupportTools = true ;
2016-02-29 01:05:24 +00:00
supportList = kxi18n ( " %1%2 " ) . subs ( supportList ) . subs ( supportInNode ) ;
2016-02-18 14:59:59 +00:00
}
2016-07-24 19:07:31 +01:00
else if ( ! supportInNode . isEmpty ( ) ) {
2016-07-24 18:47:33 +01:00
missingSupportTools = true ;
supportList = supportInNode ;
}
2016-02-18 14:59:59 +00:00
}
2015-07-13 15:17:41 +01:00
2016-02-18 14:59:59 +00:00
if ( missingSupportTools )
2015-07-13 15:17:41 +01:00
KMessageBox : : information ( this ,
xi18nc ( " @info " ,
" <para>No support tools were found for file systems currently present on hard disks in this computer:</para> "
" <table style='margin-top:12px'> "
" <tr> "
" <td style='font-weight:bold;padding-right:12px;white-space:nowrap;'>Partition</td> "
" <td style='font-weight:bold;padding-right:12px;white-space:nowrap;'>File System</td> "
" <td style='font-weight:bold;padding-right:12px;white-space:nowrap;'>Support Tools</td> "
" <td style='font-weight:bold;padding-right:12px;white-space:nowrap;'>URL</td> "
" </tr> "
" %1 "
" </table> "
" <para>As long as the support tools for these file systems are not installed you will not be able to modify them.</para> "
" <para>You should find packages with these support tools in your distribution's package manager.</para> " ,
2016-02-18 14:59:59 +00:00
supportList ) ,
2016-07-18 02:21:14 +01:00
xi18nc ( " @title:window " , " Missing File System Support Packages " ) ,
2015-07-13 15:17:41 +01:00
QStringLiteral ( " showInformationOnMissingFileSystemSupport " ) , KMessageBox : : Notify | KMessageBox : : AllowLink ) ;
2010-05-20 16:25:55 +01:00
}