2008-09-24 20:32:01 +01:00
/***************************************************************************
2010-02-23 16:30:05 +00:00
* Copyright ( C ) 2008 , 2009 , 2010 by Volker Lanz < vl @ fidra . de > *
2008-09-24 20:32:01 +01:00
* *
* This program 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 2 of the License , or *
* ( at your option ) any later version . *
* *
* This program 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 this program ; if not , write to the *
* Free Software Foundation , Inc . , *
* 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 USA *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# 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"
# include "gui/filesystemsupportdialog.h"
# include "gui/configureoptionsdialog.h"
# include "gui/devicepropsdialog.h"
2008-09-24 20:32:01 +01:00
# include "core/device.h"
2010-02-23 16:30:05 +00:00
# include "core/partition.h"
# include "ops/operation.h"
# include "ops/createpartitiontableoperation.h"
# 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"
# include "fs/filesystem.h"
2010-03-03 00:15:26 +00:00
# include "fs/filesystemfactory.h"
2009-04-22 13:54:37 +01:00
2008-09-24 20:32:01 +01:00
# include <kstandardaction.h>
# include <kactioncollection.h>
# include <ktoolbar.h>
# include <kstatusbar.h>
2010-02-21 16:58:27 +00:00
# include <kmenubar.h>
2008-09-24 20:32:01 +01:00
# include <kmessagebox.h>
# include <kaboutdata.h>
2009-04-22 13:54:37 +01:00
# include <kcomponentdata.h>
# include <kstandardguiitem.h>
2010-02-23 16:30:05 +00:00
# include <kaction.h>
# include <kapplication.h>
# include <kmenu.h>
# include <kxmlguifactory.h>
2010-03-02 13:35:57 +00:00
# include <kfiledialog.h>
2008-09-24 20:32:01 +01:00
# include <QCloseEvent>
2010-02-13 11:25:56 +00:00
# include <QReadLocker>
2010-02-23 16:30:05 +00:00
# include <QPointer>
2010-03-02 13:35:57 +00:00
# include <QFile>
# include <QDateTime>
# include <QTextStream>
2008-09-24 20:32:01 +01:00
2008-10-08 17:26:10 +01:00
# include <config.h>
2008-09-24 20:32:01 +01:00
2010-02-23 16:30:05 +00:00
# include <unistd.h>
2008-09-24 20:32:01 +01:00
/** Creates a new MainWindow instance.
@ param parent the parent widget
2008-12-27 22:12:42 +00:00
@ param coll an action collection if used as a KPart
2008-09-24 20:32:01 +01:00
*/
2008-12-27 22:12:42 +00:00
MainWindow : : MainWindow ( QWidget * parent , KActionCollection * coll ) :
2008-09-24 20:32:01 +01:00
KXmlGuiWindow ( parent ) ,
Ui : : MainWindowBase ( ) ,
2010-02-21 17:54:52 +00:00
m_ActionCollection ( coll ) ,
2010-02-23 16:30:05 +00:00
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 ) ) ,
2008-09-24 20:32:01 +01:00
m_StatusText ( new QLabel ( this ) ) ,
2010-02-21 17:54:52 +00:00
m_InfoPane ( new InfoPane ( this ) )
2008-09-24 20:32:01 +01:00
{
2010-02-23 16:30:05 +00:00
setupObjectNames ( ) ;
2008-09-24 20:32:01 +01:00
setupUi ( this ) ;
2009-04-23 08:27:27 +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 ( )
{
m_OperationStack - > setObjectName ( " m_OperationStack " ) ;
m_OperationRunner - > setObjectName ( " m_OperationRunner " ) ;
m_DeviceScanner - > setObjectName ( " m_DeviceScanner " ) ;
m_ApplyProgressDialog - > setObjectName ( " m_ApplyProgressDialog " ) ;
m_ScanProgressDialog - > setObjectName ( " m_ScanProgressDialog " ) ;
}
2009-04-16 12:37:00 +01:00
void MainWindow : : init ( )
{
2009-04-22 13:41:30 +01:00
treeLog ( ) . init ( actionCollection ( ) , & pmWidget ( ) ) ;
2010-01-26 21:12:42 +00:00
connect ( GlobalLog : : instance ( ) , SIGNAL ( newMessage ( Log : : Level , const QString & ) ) , & treeLog ( ) , SLOT ( onNewLogMessage ( Log : : Level , const QString & ) ) ) ;
2008-09-24 20:32:01 +01:00
setupActions ( ) ;
2009-04-16 12:37:00 +01:00
setupStatusBar ( ) ;
2008-09-24 20:32:01 +01:00
setupConnections ( ) ;
2010-02-12 11:29:12 +00:00
listDevices ( ) . setActionCollection ( actionCollection ( ) ) ;
2010-02-12 11:49:35 +00:00
listOperations ( ) . setActionCollection ( actionCollection ( ) ) ;
2010-02-23 16:30:05 +00:00
pmWidget ( ) . init ( & operationStack ( ) , " partitionmanagerrc " ) ;
2009-04-21 17:36:43 +01:00
2010-02-13 14:21:05 +00:00
if ( isKPart ( ) )
2010-02-21 17:54:52 +00:00
{
setupGUI ( ToolBar | Keys | Save ) ;
statusBar ( ) - > hide ( ) ;
}
2008-12-27 22:12:42 +00:00
else
setupGUI ( ToolBar | Keys | StatusBar | Save | Create ) ;
2008-09-24 20:32:01 +01:00
loadConfig ( ) ;
dockInformation ( ) . setWidget ( & infoPane ( ) ) ;
2010-01-19 10:31:42 +00:00
2010-02-12 11:29:12 +00:00
infoPane ( ) . clear ( ) ;
2010-02-23 16:30:05 +00:00
scanDevices ( ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : closeEvent ( QCloseEvent * event )
{
2010-02-23 16:30:05 +00:00
if ( applyProgressDialog ( ) . isVisible ( ) )
2008-09-24 20:32:01 +01:00
{
event - > ignore ( ) ;
return ;
}
2010-02-23 16:30:05 +00:00
if ( numPendingOperations ( ) > 0 )
2008-09-24 20:32:01 +01:00
{
if ( KMessageBox : : warningContinueCancel ( this ,
i18ncp ( " @info " , " <para>Do you really want to quit the application?</para><para>There is still an operation pending.</para> " ,
2010-02-23 16:30:05 +00:00
" <para>Do you really want to quit the application?</para><para>There are still %1 operations pending.</para> " , numPendingOperations ( ) ) ,
2008-12-27 12:01:29 +00:00
i18nc ( " @title:window " , " Discard Pending Operations and Quit? " ) ,
2008-09-24 20:32:01 +01:00
KGuiItem ( i18nc ( " @action:button " , " &Quit <application>%1</application> " , KGlobal : : mainComponent ( ) . aboutData ( ) - > programName ( ) ) ) ,
KStandardGuiItem : : cancel ( ) , " reallyQuit " ) = = KMessageBox : : Cancel )
{
event - > ignore ( ) ;
return ;
}
}
saveConfig ( ) ;
KXmlGuiWindow : : closeEvent ( event ) ;
}
void MainWindow : : changeEvent ( QEvent * event )
{
2010-02-12 11:29:12 +00:00
if ( ( event - > type ( ) = = QEvent : : ActivationChange | | event - > type ( ) = = QEvent : : WindowStateChange ) & & event - > spontaneous ( ) & & isActiveWindow ( ) )
2008-09-24 20:32:01 +01:00
{
2010-02-12 11:29:12 +00:00
QWidget * w = NULL ;
2010-02-23 16:30:05 +00:00
if ( applyProgressDialog ( ) . isVisible ( ) )
w = & applyProgressDialog ( ) ;
else if ( scanProgressDialog ( ) . isVisible ( ) )
w = & scanProgressDialog ( ) ;
2010-02-12 11:29:12 +00:00
if ( w ! = NULL )
{
w - > activateWindow ( ) ;
w - > raise ( ) ;
w - > setFocus ( ) ;
}
2008-09-24 20:32:01 +01:00
}
KXmlGuiWindow : : changeEvent ( event ) ;
}
void MainWindow : : setupActions ( )
{
// File actions
KStandardAction : : quit ( this , SLOT ( close ( ) ) , actionCollection ( ) ) ;
2010-02-23 16:30:05 +00:00
// Edit actions
KAction * undoOperation = actionCollection ( ) - > addAction ( " undoOperation " , this , SLOT ( onUndoOperation ( ) ) ) ;
undoOperation - > setEnabled ( false ) ;
undoOperation - > setText ( i18nc ( " @action:inmenu " , " Undo " ) ) ;
undoOperation - > setToolTip ( i18nc ( " @info:tooltip " , " Undo the last operation " ) ) ;
undoOperation - > setStatusTip ( i18nc ( " @info:status " , " Remove the last operation from the list. " ) ) ;
undoOperation - > setShortcut ( Qt : : CTRL | Qt : : Key_Z ) ;
undoOperation - > setIcon ( BarIcon ( " edit-undo " ) ) ;
KAction * clearAllOperations = actionCollection ( ) - > addAction ( " clearAllOperations " , this , SLOT ( onClearAllOperations ( ) ) ) ;
clearAllOperations - > setEnabled ( false ) ;
clearAllOperations - > setText ( i18nc ( " @action:inmenu clear the list of operations " , " Clear " ) ) ;
clearAllOperations - > setToolTip ( i18nc ( " @info:tooltip " , " Clear all operations " ) ) ;
clearAllOperations - > setStatusTip ( i18nc ( " @info:status " , " Empty the list of pending operations. " ) ) ;
clearAllOperations - > setIcon ( BarIcon ( " dialog-cancel " ) ) ;
KAction * applyAllOperations = actionCollection ( ) - > addAction ( " applyAllOperations " , this , SLOT ( onApplyAllOperations ( ) ) ) ;
applyAllOperations - > setEnabled ( false ) ;
applyAllOperations - > setText ( i18nc ( " @action:inmenu apply all operations " , " Apply " ) ) ;
applyAllOperations - > setToolTip ( i18nc ( " @info:tooltip " , " Apply all operations " ) ) ;
applyAllOperations - > setStatusTip ( i18nc ( " @info:status " , " Apply the pending operations in the list. " ) ) ;
applyAllOperations - > setIcon ( BarIcon ( " dialog-ok-apply " ) ) ;
// Device actions
KAction * refreshDevices = actionCollection ( ) - > addAction ( " refreshDevices " , this , SLOT ( onRefreshDevices ( ) ) ) ;
refreshDevices - > setText ( i18nc ( " @action:inmenu refresh list of devices " , " Refresh Devices " ) ) ;
refreshDevices - > setToolTip ( i18nc ( " @info:tooltip " , " Refresh all devices " ) ) ;
refreshDevices - > setStatusTip ( i18nc ( " @info:status " , " Renew the devices list. " ) ) ;
refreshDevices - > setShortcut ( Qt : : Key_F5 ) ;
refreshDevices - > setIcon ( BarIcon ( " view-refresh " ) ) ;
KAction * createNewPartitionTable = actionCollection ( ) - > addAction ( " createNewPartitionTable " , this , SLOT ( onCreateNewPartitionTable ( ) ) ) ;
createNewPartitionTable - > setEnabled ( false ) ;
createNewPartitionTable - > setText ( i18nc ( " @action:inmenu " , " New Partition Table " ) ) ;
createNewPartitionTable - > setToolTip ( i18nc ( " @info:tooltip " , " Create a new partition table " ) ) ;
createNewPartitionTable - > setStatusTip ( i18nc ( " @info:status " , " Create a new and empty partition table on a device. " ) ) ;
createNewPartitionTable - > setShortcut ( Qt : : CTRL | Qt : : SHIFT | Qt : : Key_N ) ;
createNewPartitionTable - > setIcon ( BarIcon ( " edit-clear " ) ) ;
2010-03-02 13:35:57 +00:00
KAction * exportPartitionTable = actionCollection ( ) - > addAction ( " exportPartitionTable " , this , SLOT ( onExportPartitionTable ( ) ) ) ;
exportPartitionTable - > setEnabled ( false ) ;
exportPartitionTable - > setText ( i18nc ( " @action:inmenu " , " Export Partition Table " ) ) ;
exportPartitionTable - > setToolTip ( i18nc ( " @info:tooltip " , " Export a partition table " ) ) ;
2010-03-03 00:15:26 +00:00
exportPartitionTable - > setStatusTip ( i18nc ( " @info:status " , " Export the device's partition table to a text file. " ) ) ;
2010-03-02 13:35:57 +00:00
exportPartitionTable - > setIcon ( BarIcon ( " document-export " ) ) ;
2010-03-03 00:15:26 +00:00
KAction * importPartitionTable = actionCollection ( ) - > addAction ( " importPartitionTable " , this , SLOT ( onImportPartitionTable ( ) ) ) ;
importPartitionTable - > setEnabled ( false ) ;
importPartitionTable - > setText ( i18nc ( " @action:inmenu " , " Import Partition Table " ) ) ;
importPartitionTable - > setToolTip ( i18nc ( " @info:tooltip " , " Import a partition table " ) ) ;
importPartitionTable - > setStatusTip ( i18nc ( " @info:status " , " Import a partition table from a text file. " ) ) ;
importPartitionTable - > setIcon ( BarIcon ( " document-import " ) ) ;
2010-02-23 16:30:05 +00:00
KAction * propertiesDevice = actionCollection ( ) - > addAction ( " propertiesDevice " , this , SLOT ( onPropertiesDevice ( ) ) ) ;
2010-03-03 00:15:26 +00:00
propertiesDevice - > setEnabled ( false ) ;
2010-02-23 16:30:05 +00:00
propertiesDevice - > setText ( i18nc ( " @action:inmenu " , " Properties " ) ) ;
propertiesDevice - > setToolTip ( i18nc ( " @info:tooltip " , " Show device properties dialog " ) ) ;
propertiesDevice - > setStatusTip ( i18nc ( " @info:status " , " View and modify device properties " ) ) ;
propertiesDevice - > setIcon ( BarIcon ( " document-properties " ) ) ;
// Partition actions
KAction * newPartition = actionCollection ( ) - > addAction ( " newPartition " , & pmWidget ( ) , SLOT ( onNewPartition ( ) ) ) ;
newPartition - > setEnabled ( false ) ;
newPartition - > setText ( i18nc ( " @action:inmenu create a new partition " , " New " ) ) ;
newPartition - > setToolTip ( i18nc ( " @info:tooltip " , " New partition " ) ) ;
newPartition - > setStatusTip ( i18nc ( " @info:status " , " Create a new partition. " ) ) ;
newPartition - > setShortcut ( Qt : : CTRL | Qt : : Key_N ) ;
newPartition - > setIcon ( BarIcon ( " document-new " ) ) ;
KAction * resizePartition = actionCollection ( ) - > addAction ( " resizePartition " , & pmWidget ( ) , SLOT ( onResizePartition ( ) ) ) ;
resizePartition - > setEnabled ( false ) ;
resizePartition - > setText ( i18nc ( " @action:inmenu " , " Resize/Move " ) ) ;
resizePartition - > setToolTip ( i18nc ( " @info:tooltip " , " Resize or move partition " ) ) ;
resizePartition - > setStatusTip ( i18nc ( " @info:status " , " Shrink, grow or move an existing partition. " ) ) ;
resizePartition - > setShortcut ( Qt : : CTRL | Qt : : Key_R ) ;
resizePartition - > setIcon ( BarIcon ( " arrow-right-double " ) ) ;
KAction * deletePartition = actionCollection ( ) - > addAction ( " deletePartition " , & pmWidget ( ) , SLOT ( onDeletePartition ( ) ) ) ;
deletePartition - > setEnabled ( false ) ;
deletePartition - > setText ( i18nc ( " @action:inmenu " , " Delete " ) ) ;
deletePartition - > setToolTip ( i18nc ( " @info:tooltip " , " Delete partition " ) ) ;
deletePartition - > setStatusTip ( i18nc ( " @info:status " , " Delete a partition. " ) ) ;
deletePartition - > setShortcut ( Qt : : Key_Delete ) ;
deletePartition - > setIcon ( BarIcon ( " edit-delete " ) ) ;
KAction * shredPartition = actionCollection ( ) - > addAction ( " shredPartition " , & pmWidget ( ) , SLOT ( onShredPartition ( ) ) ) ;
shredPartition - > setEnabled ( false ) ;
shredPartition - > setText ( i18nc ( " @action:inmenu " , " Shred " ) ) ;
shredPartition - > setToolTip ( i18nc ( " @info:tooltip " , " Shred partition " ) ) ;
shredPartition - > setStatusTip ( i18nc ( " @info:status " , " Shred a partition so that its contents cannot be restored. " ) ) ;
shredPartition - > setShortcut ( Qt : : SHIFT | Qt : : Key_Delete ) ;
shredPartition - > setIcon ( BarIcon ( " edit-delete-shred " ) ) ;
KAction * copyPartition = actionCollection ( ) - > addAction ( " copyPartition " , & pmWidget ( ) , SLOT ( onCopyPartition ( ) ) ) ;
copyPartition - > setEnabled ( false ) ;
copyPartition - > setText ( i18nc ( " @action:inmenu " , " Copy " ) ) ;
copyPartition - > setToolTip ( i18nc ( " @info:tooltip " , " Copy partition " ) ) ;
copyPartition - > setStatusTip ( i18nc ( " @info:status " , " Copy an existing partition. " ) ) ;
copyPartition - > setShortcut ( Qt : : CTRL | Qt : : Key_C ) ;
copyPartition - > setIcon ( BarIcon ( " edit-copy " ) ) ;
KAction * pastePartition = actionCollection ( ) - > addAction ( " pastePartition " , & pmWidget ( ) , SLOT ( onPastePartition ( ) ) ) ;
pastePartition - > setEnabled ( false ) ;
pastePartition - > setText ( i18nc ( " @action:inmenu " , " Paste " ) ) ;
pastePartition - > setToolTip ( i18nc ( " @info:tooltip " , " Paste partition " ) ) ;
pastePartition - > setStatusTip ( i18nc ( " @info:status " , " Paste a copied partition. " ) ) ;
pastePartition - > setShortcut ( Qt : : CTRL | Qt : : Key_V ) ;
pastePartition - > setIcon ( BarIcon ( " edit-paste " ) ) ;
KAction * editMountPoint = actionCollection ( ) - > addAction ( " editMountPoint " , & pmWidget ( ) , SLOT ( onEditMountPoint ( ) ) ) ;
editMountPoint - > setEnabled ( false ) ;
editMountPoint - > setText ( i18nc ( " @action:inmenu " , " Edit Mount Point " ) ) ;
editMountPoint - > setToolTip ( i18nc ( " @info:tooltip " , " Edit mount point " ) ) ;
editMountPoint - > setStatusTip ( i18nc ( " @info:status " , " Edit a partition's mount point and options. " ) ) ;
KAction * mountPartition = actionCollection ( ) - > addAction ( " mountPartition " , & pmWidget ( ) , SLOT ( onMountPartition ( ) ) ) ;
mountPartition - > setEnabled ( false ) ;
mountPartition - > setText ( i18nc ( " @action:inmenu " , " Mount " ) ) ;
mountPartition - > setToolTip ( i18nc ( " @info:tooltip " , " Mount or unmount partition " ) ) ;
mountPartition - > setStatusTip ( i18nc ( " @info:status " , " Mount or unmount a partition. " ) ) ;
KAction * checkPartition = actionCollection ( ) - > addAction ( " checkPartition " , & pmWidget ( ) , SLOT ( onCheckPartition ( ) ) ) ;
checkPartition - > setEnabled ( false ) ;
checkPartition - > setText ( i18nc ( " @action:inmenu " , " Check " ) ) ;
checkPartition - > setToolTip ( i18nc ( " @info:tooltip " , " Check partition " ) ) ;
checkPartition - > setStatusTip ( i18nc ( " @info:status " , " Check a filesystem on a partition for errors. " ) ) ;
checkPartition - > setIcon ( BarIcon ( " flag " ) ) ;
KAction * propertiesPartition = actionCollection ( ) - > addAction ( " propertiesPartition " , & pmWidget ( ) , SLOT ( onPropertiesPartition ( ) ) ) ;
propertiesPartition - > setEnabled ( false ) ;
propertiesPartition - > setText ( i18nc ( " @action:inmenu " , " Properties " ) ) ;
propertiesPartition - > setToolTip ( i18nc ( " @info:tooltip " , " Show partition properties dialog " ) ) ;
propertiesPartition - > setStatusTip ( i18nc ( " @info:status " , " View and modify partition properties (label, partition flags, etc.) " ) ) ;
propertiesPartition - > setIcon ( BarIcon ( " document-properties " ) ) ;
KAction * backup = actionCollection ( ) - > addAction ( " backupPartition " , & pmWidget ( ) , SLOT ( onBackupPartition ( ) ) ) ;
backup - > setEnabled ( false ) ;
backup - > setText ( i18nc ( " @action:inmenu " , " Backup " ) ) ;
backup - > setToolTip ( i18nc ( " @info:tooltip " , " Backup partition " ) ) ;
backup - > setStatusTip ( i18nc ( " @info:status " , " Backup a partition to an image file. " ) ) ;
backup - > setIcon ( BarIcon ( " document-export " ) ) ;
KAction * restore = actionCollection ( ) - > addAction ( " restorePartition " , & pmWidget ( ) , SLOT ( onRestorePartition ( ) ) ) ;
restore - > setEnabled ( false ) ;
restore - > setText ( i18nc ( " @action:inmenu " , " Restore " ) ) ;
restore - > setToolTip ( i18nc ( " @info:tooltip " , " Restore partition " ) ) ;
restore - > setStatusTip ( i18nc ( " @info:status " , " Restore a partition from an image file. " ) ) ;
restore - > setIcon ( BarIcon ( " document-import " ) ) ;
2008-09-24 20:32:01 +01:00
// View actions
2010-02-23 16:30:05 +00:00
KAction * fileSystemSupport = actionCollection ( ) - > addAction ( " fileSystemSupport " , this , SLOT ( onFileSystemSupport ( ) ) ) ;
fileSystemSupport - > setText ( i18nc ( " @action:inmenu " , " File System Support " ) ) ;
fileSystemSupport - > setToolTip ( i18nc ( " @info:tooltip " , " View file system support information " ) ) ;
fileSystemSupport - > setStatusTip ( i18nc ( " @info:status " , " Show information about supported file systems. " ) ) ;
2010-01-28 16:27:28 +00:00
actionCollection ( ) - > addAction ( " toggleDockDevices " , dockDevices ( ) . toggleViewAction ( ) ) ;
2008-09-24 20:32:01 +01:00
actionCollection ( ) - > addAction ( " toggleDockOperations " , dockOperations ( ) . toggleViewAction ( ) ) ;
actionCollection ( ) - > addAction ( " toggleDockInformation " , dockInformation ( ) . toggleViewAction ( ) ) ;
actionCollection ( ) - > addAction ( " toggleDockLog " , dockLog ( ) . toggleViewAction ( ) ) ;
2010-02-21 16:58:27 +00:00
// Settings Actions
KStandardAction : : showMenubar ( this , SLOT ( onShowMenuBar ( ) ) , actionCollection ( ) ) ;
2010-02-23 16:30:05 +00:00
KStandardAction : : preferences ( this , SLOT ( onConfigureOptions ( ) ) , actionCollection ( ) ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : setupConnections ( )
{
2010-02-12 11:29:12 +00:00
connect ( & listDevices ( ) , SIGNAL ( selectionChanged ( const QString & ) ) , & pmWidget ( ) , SLOT ( setSelectedDevice ( const QString & ) ) ) ;
2010-02-23 16:30:05 +00:00
connect ( & listDevices ( ) , SIGNAL ( deviceDoubleClicked ( const QString & ) ) , SLOT ( onPropertiesDevice ( const QString & ) ) ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : setupStatusBar ( )
{
2010-02-21 17:54:52 +00:00
if ( ! isKPart ( ) )
statusBar ( ) - > addWidget ( & statusText ( ) ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : loadConfig ( )
{
2009-04-22 13:54:37 +01:00
if ( Config : : firstRun ( ) )
2008-09-24 20:32:01 +01:00
{
dockLog ( ) . setVisible ( false ) ;
dockInformation ( ) . setVisible ( false ) ;
toolBar ( " deviceToolBar " ) - > setVisible ( false ) ;
}
}
void MainWindow : : saveConfig ( ) const
{
Config : : setFirstRun ( false ) ;
Config : : self ( ) - > writeConfig ( ) ;
}
2010-02-23 16:30:05 +00:00
void MainWindow : : enableActions ( )
{
actionCollection ( ) - > action ( " createNewPartitionTable " ) - > setEnabled ( CreatePartitionTableOperation : : canCreate ( pmWidget ( ) . selectedDevice ( ) ) ) ;
2010-03-02 13:35:57 +00:00
actionCollection ( ) - > action ( " exportPartitionTable " ) - > setEnabled ( pmWidget ( ) . selectedDevice ( ) & & pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) & & numPendingOperations ( ) = = 0 ) ;
2010-03-03 00:15:26 +00:00
actionCollection ( ) - > action ( " importPartitionTable " ) - > setEnabled ( CreatePartitionTableOperation : : canCreate ( pmWidget ( ) . selectedDevice ( ) ) ) ;
actionCollection ( ) - > action ( " propertiesDevice " ) - > setEnabled ( pmWidget ( ) . selectedDevice ( ) ! = NULL ) ;
2010-02-23 16:30:05 +00:00
actionCollection ( ) - > action ( " undoOperation " ) - > setEnabled ( numPendingOperations ( ) > 0 ) ;
actionCollection ( ) - > action ( " clearAllOperations " ) - > setEnabled ( numPendingOperations ( ) > 0 ) ;
actionCollection ( ) - > action ( " applyAllOperations " ) - > setEnabled ( numPendingOperations ( ) > 0 & & ( geteuid ( ) = = 0 | | Config : : allowApplyOperationsAsNonRoot ( ) ) ) ;
const bool readOnly = pmWidget ( ) . selectedDevice ( ) = = NULL | |
pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) = = NULL | |
pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) - > isReadOnly ( ) ;
const Partition * part = pmWidget ( ) . selectedPartition ( ) ;
actionCollection ( ) - > action ( " newPartition " ) - > setEnabled ( ! readOnly & & NewOperation : : canCreateNew ( part ) ) ;
const bool canResize = ResizeOperation : : canGrow ( part ) | | ResizeOperation : : canShrink ( part ) | | ResizeOperation : : canMove ( part ) ;
actionCollection ( ) - > action ( " resizePartition " ) - > setEnabled ( ! readOnly & & canResize ) ;
actionCollection ( ) - > action ( " copyPartition " ) - > setEnabled ( CopyOperation : : canCopy ( part ) ) ;
actionCollection ( ) - > action ( " deletePartition " ) - > setEnabled ( ! readOnly & & DeleteOperation : : canDelete ( part ) ) ;
actionCollection ( ) - > action ( " shredPartition " ) - > setEnabled ( ! readOnly & & DeleteOperation : : canDelete ( part ) ) ;
actionCollection ( ) - > action ( " pastePartition " ) - > setEnabled ( ! readOnly & & CopyOperation : : canPaste ( part , pmWidget ( ) . clipboardPartition ( ) ) ) ;
actionCollection ( ) - > action ( " propertiesPartition " ) - > setEnabled ( part ! = NULL ) ;
actionCollection ( ) - > action ( " editMountPoint " ) - > setEnabled ( part & & part - > canMount ( ) ) ;
actionCollection ( ) - > action ( " mountPartition " ) - > setEnabled ( part & & ( part - > canMount ( ) | | part - > canUnmount ( ) ) ) ;
if ( part ! = NULL )
actionCollection ( ) - > action ( " mountPartition " ) - > setText ( part - > isMounted ( ) ? part - > fileSystem ( ) . unmountTitle ( ) : part - > fileSystem ( ) . mountTitle ( ) ) ;
actionCollection ( ) - > action ( " checkPartition " ) - > setEnabled ( ! readOnly & & CheckOperation : : canCheck ( part ) ) ;
actionCollection ( ) - > action ( " backupPartition " ) - > setEnabled ( BackupOperation : : canBackup ( part ) ) ;
actionCollection ( ) - > action ( " restorePartition " ) - > setEnabled ( RestoreOperation : : canRestore ( part ) ) ;
}
void MainWindow : : on_m_ApplyProgressDialog_finished ( )
2008-09-24 20:32:01 +01:00
{
2010-02-23 16:30:05 +00:00
scanDevices ( ) ;
}
void MainWindow : : on_m_OperationStack_operationsChanged ( )
{
listOperations ( ) . updateOperations ( operationStack ( ) . operations ( ) ) ;
2010-03-03 00:15:26 +00:00
pmWidget ( ) . updatePartitions ( ) ;
enableActions ( ) ;
// this will make sure that the info pane gets updated
on_m_PartitionManagerWidget_selectedPartitionChanged ( pmWidget ( ) . selectedPartition ( ) ) ;
2010-02-12 11:29:12 +00:00
2010-02-21 17:54:52 +00:00
if ( ! isKPart ( ) )
2010-02-23 16:30:05 +00:00
statusText ( ) . setText ( i18ncp ( " @info:status " , " One pending operation " , " %1 pending operations " , numPendingOperations ( ) ) ) ;
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
{
2010-03-03 18:58:14 +00:00
# if defined(THREADED_DEVICE_SCANNER)
2010-02-23 16:30:05 +00:00
QReadLocker lockDevices ( & operationStack ( ) . lock ( ) ) ;
2010-03-03 18:58:14 +00:00
# endif
2010-02-13 11:25:56 +00:00
2010-02-23 16:30:05 +00:00
listDevices ( ) . updateDevices ( operationStack ( ) . previewDevices ( ) ) ;
2010-01-28 16:27:28 +00:00
2009-04-21 17:36:43 +01:00
if ( pmWidget ( ) . selectedDevice ( ) )
2010-01-12 14:36:16 +00:00
infoPane ( ) . showDevice ( dockWidgetArea ( & dockInformation ( ) ) , * pmWidget ( ) . selectedDevice ( ) ) ;
2008-09-24 20:32:01 +01:00
else
infoPane ( ) . clear ( ) ;
2009-04-21 17:36:43 +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
{
2010-02-12 11:29:12 +00: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 ( )
{
QString title ;
2009-04-21 17:36:43 +01:00
if ( pmWidget ( ) . selectedDevice ( ) )
title = pmWidget ( ) . selectedDevice ( ) - > deviceNode ( ) + " - " ;
2008-09-24 20:32:01 +01:00
title + = KGlobal : : mainComponent ( ) . aboutData ( ) - > programName ( ) + ' ' + KGlobal : : mainComponent ( ) . aboutData ( ) - > version ( ) ;
setWindowTitle ( title ) ;
}
2010-02-23 16:30:05 +00:00
void MainWindow : : on_m_ListDevices_contextMenuRequested ( const QPoint & pos )
{
KMenu * menu = static_cast < KMenu * > ( guiFactory ( ) - > container ( " device " , this ) ) ;
if ( menu )
menu - > exec ( pos ) ;
}
void MainWindow : : on_m_PartitionManagerWidget_contextMenuRequested ( const QPoint & pos )
{
KMenu * menu = NULL ;
if ( pmWidget ( ) . selectedPartition ( ) = = NULL )
{
if ( pmWidget ( ) . selectedDevice ( ) ! = NULL )
menu = static_cast < KMenu * > ( guiFactory ( ) - > container ( " device " , this ) ) ;
}
else
menu = static_cast < KMenu * > ( guiFactory ( ) - > container ( " partition " , this ) ) ;
if ( menu )
menu - > exec ( pos ) ;
}
void MainWindow : : on_m_PartitionManagerWidget_deviceDoubleClicked ( const Device * )
{
actionCollection ( ) - > action ( " propertiesDevice " ) - > trigger ( ) ;
}
void MainWindow : : on_m_PartitionManagerWidget_partitionDoubleClicked ( const Partition * )
{
actionCollection ( ) - > action ( " propertiesPartition " ) - > trigger ( ) ;
}
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
{
2009-04-21 17:36:43 +01:00
if ( p )
2010-01-12 14:36:16 +00:00
infoPane ( ) . showPartition ( dockWidgetArea ( & dockInformation ( ) ) , * p ) ;
2009-04-21 17:36:43 +01:00
else if ( pmWidget ( ) . selectedDevice ( ) )
2010-01-12 14:36:16 +00:00
infoPane ( ) . showDevice ( dockWidgetArea ( & dockInformation ( ) ) , * pmWidget ( ) . selectedDevice ( ) ) ;
2008-09-24 20:32:01 +01:00
else
2009-04-21 17:36:43 +01:00
infoPane ( ) . clear ( ) ;
2008-09-24 20:32:01 +01:00
updateWindowTitle ( ) ;
2010-02-23 16:30:05 +00:00
enableActions ( ) ;
2008-09-24 20:32:01 +01:00
}
2010-02-13 14:21:05 +00:00
bool MainWindow : : isKPart ( ) const
{
// If we were instantiated with an action collection we're supposed to be a KPart
return m_ActionCollection ! = NULL ;
}
2010-02-21 16:58:27 +00:00
void MainWindow : : onShowMenuBar ( )
{
QAction * menuBarAction = actionCollection ( ) - > action ( KStandardAction : : name ( KStandardAction : : ShowMenubar ) ) ;
if ( menuBarAction - > isChecked ( ) )
menuBar ( ) - > show ( ) ;
else
{
const QString accel = menuBarAction - > shortcut ( ) . toString ( ) ;
2010-03-03 00:15:26 +00:00
KMessageBox : : information ( this , i18nc ( " @info " , " This will hide the menu bar completely. You can show it again by typing %1. " , accel ) , i18nc ( " @title:window " , " Hide Menu Bar " ) , " hideMenuBarWarning " ) ;
2010-02-21 16:58:27 +00:00
menuBar ( ) - > hide ( ) ;
}
Config : : self ( ) - > setShowMenuBar ( menuBarAction - > isChecked ( ) ) ;
}
2010-02-23 16:30:05 +00:00
void MainWindow : : scanDevices ( )
{
Log ( ) < < i18nc ( " @info/plain " , " Scanning devices... " ) ;
// remember the currently selected device's node
setSavedSelectedDeviceNode ( pmWidget ( ) . selectedDevice ( ) ? pmWidget ( ) . selectedDevice ( ) - > deviceNode ( ) : QString ( ) ) ;
pmWidget ( ) . clear ( ) ;
KApplication : : setOverrideCursor ( QCursor ( Qt : : WaitCursor ) ) ;
2010-03-03 18:58:14 +00:00
# if defined(THREADED_DEVICE_SCANNER)
2010-02-23 16:30:05 +00:00
scanProgressDialog ( ) . setEnabled ( true ) ;
scanProgressDialog ( ) . show ( ) ;
deviceScanner ( ) . start ( ) ;
2010-03-03 18:58:14 +00:00
# else
deviceScanner ( ) . scan ( ) ;
on_m_DeviceScanner_finished ( ) ;
# endif
2010-02-23 16:30:05 +00:00
}
2010-03-03 09:18:59 +00:00
void MainWindow : : on_m_DeviceScanner_progress ( const QString & device_node , int percent )
2010-02-23 16:30:05 +00:00
{
scanProgressDialog ( ) . setProgress ( percent ) ;
scanProgressDialog ( ) . setDeviceName ( device_node ) ;
}
void MainWindow : : on_m_DeviceScanner_finished ( )
{
2010-03-03 18:58:14 +00:00
# if defined(THREADED_DEVICE_SCANNER)
2010-02-23 16:30:05 +00:00
QReadLocker lockDevices ( & operationStack ( ) . lock ( ) ) ;
2010-03-03 18:58:14 +00:00
# endif
2010-02-23 16:30:05 +00:00
if ( ! operationStack ( ) . previewDevices ( ) . isEmpty ( ) )
pmWidget ( ) . setSelectedDevice ( operationStack ( ) . previewDevices ( ) [ 0 ] ) ;
pmWidget ( ) . updatePartitions ( ) ;
Log ( ) < < i18nc ( " @info/plain " , " Scan finished. " ) ;
KApplication : : restoreOverrideCursor ( ) ;
// 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 ( ) ) ;
}
void MainWindow : : onRefreshDevices ( )
{
if ( numPendingOperations ( ) = = 0 | | KMessageBox : : warningContinueCancel ( this ,
i18nc ( " @info " ,
" <para>Do you really want to rescan the devices?</para> "
" <para><warning>This will also clear the list of pending operations.</warning></para> " ) ,
i18nc ( " @title:window " , " Really Rescan the Devices? " ) ,
KGuiItem ( i18nc ( " @action:button " , " &Rescan Devices " ) ) ,
KStandardGuiItem : : cancel ( ) , " reallyRescanDevices " ) = = KMessageBox : : Continue )
{
scanDevices ( ) ;
}
}
void MainWindow : : onApplyAllOperations ( )
{
QStringList opList ;
foreach ( const Operation * op , operationStack ( ) . operations ( ) )
opList . append ( op - > description ( ) ) ;
if ( KMessageBox : : warningContinueCancelList ( this ,
i18nc ( " @info " ,
" <para>Do you really want to apply the pending operations listed below?</para> "
" <para><warning>This will permanently modify your disks.</warning></para> " ) ,
opList , i18nc ( " @title:window " , " Apply Pending Operations? " ) ,
KGuiItem ( i18nc ( " @action:button " , " &Apply Pending Operations " ) ) ,
KStandardGuiItem : : cancel ( ) ) = = KMessageBox : : Continue )
{
Log ( ) < < i18nc ( " @info/plain " , " Applying operations... " ) ;
applyProgressDialog ( ) . show ( ) ;
operationRunner ( ) . setReport ( & applyProgressDialog ( ) . report ( ) ) ;
// 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 ) ;
}
pmWidget ( ) . updatePartitions ( ) ;
operationRunner ( ) . start ( ) ;
}
}
void MainWindow : : onUndoOperation ( )
{
Q_ASSERT ( numPendingOperations ( ) > 0 ) ;
if ( numPendingOperations ( ) = = 0 )
return ;
Log ( ) < < i18nc ( " @info/plain " , " Undoing operation: %1 " , operationStack ( ) . operations ( ) . last ( ) - > description ( ) ) ;
operationStack ( ) . pop ( ) ;
pmWidget ( ) . updatePartitions ( ) ;
enableActions ( ) ;
}
void MainWindow : : onClearAllOperations ( )
{
if ( KMessageBox : : warningContinueCancel ( this ,
i18nc ( " @info " , " Do you really want to clear the list of pending operations? " ) ,
i18nc ( " @title:window " , " Clear Pending Operations? " ) ,
KGuiItem ( i18nc ( " @action:button " , " &Clear Pending Operations " ) ) ,
KStandardGuiItem : : cancel ( ) , " reallyClearPendingOperations " ) = = KMessageBox : : Continue )
{
Log ( ) < < i18nc ( " @info/plain " , " Clearing the list of pending operations. " ) ;
operationStack ( ) . clearOperations ( ) ;
pmWidget ( ) . updatePartitions ( ) ;
enableActions ( ) ;
}
}
quint32 MainWindow : : numPendingOperations ( ) const
{
return operationStack ( ) . size ( ) ;
}
void MainWindow : : onCreateNewPartitionTable ( )
{
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
if ( pmWidget ( ) . selectedDevice ( ) = = NULL )
{
kWarning ( ) < < " selected device is null. " ;
return ;
}
QPointer < CreatePartitionTableDialog > dlg = new CreatePartitionTableDialog ( this , * pmWidget ( ) . selectedDevice ( ) ) ;
if ( dlg - > exec ( ) = = KDialog : : Accepted )
operationStack ( ) . push ( new CreatePartitionTableOperation ( * pmWidget ( ) . selectedDevice ( ) , dlg - > type ( ) ) ) ;
2010-03-03 00:15:26 +00:00
delete dlg ;
}
void MainWindow : : onImportPartitionTable ( )
{
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
Device & device = * pmWidget ( ) . selectedDevice ( ) ;
QString fileName = KFileDialog : : getOpenFileName ( KUrl ( " kfiledialog://importPartitionTable " ) ) ;
if ( fileName . isEmpty ( ) )
return ;
QFile file ( fileName ) ;
if ( ! file . open ( QFile : : ReadOnly ) )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Could not open input file <filename>%1</filename>. " , fileName ) , i18nc ( " @title:window " , " Error Importing Partition Table " ) ) ;
return ;
2010-02-23 16:30:05 +00:00
}
2010-03-03 00:15:26 +00:00
QByteArray line ;
QRegExp rxPartition ( " ( \\ d+) ; ( \ \ d + ) ; ( \ \ d + ) ; ( \ \ w + ) ; ( \ \ w + ) ; ( \ " \\ w* \" );( \" [^ \" ]* \" ) " ) ;
QRegExp rxType ( " type: \\ s \" (.+) \ " " ) ;
QRegExp rxMagic ( " ^##|v( \\ d+) | # # " ) ;
quint32 lineNo = 0 ;
bool haveMagic = false ;
PartitionTable * ptable = NULL ;
PartitionTable : : TableType tableType = PartitionTable : : unknownTableType ;
while ( ! ( line = file . readLine ( ) ) . isEmpty ( ) )
{
lineNo + + ;
line = line . simplified ( ) ;
if ( line . isEmpty ( ) )
continue ;
if ( ! haveMagic & & rxMagic . indexIn ( line ) = = - 1 )
{
KMessageBox : : error ( this , i18nc ( " @info " , " The file <filename>%1</filename> is not a valid partition table text file. " , fileName ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
else
haveMagic = true ;
if ( line . startsWith ( ' # ' ) )
continue ;
if ( rxType . indexIn ( line ) ! = - 1 )
{
if ( ptable ! = NULL )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Found more than one partition table type in import file (line %1). " , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
tableType = PartitionTable : : nameToTableType ( rxType . cap ( 1 ) ) ;
if ( tableType = = PartitionTable : : unknownTableType )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Partition table type \" %1 \" is unknown (line %2). " , rxType . cap ( 1 ) , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
if ( tableType ! = PartitionTable : : msdos & & tableType ! = PartitionTable : : gpt )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Partition table type \" %1 \" is not supported for import (line %2). " , rxType . cap ( 1 ) , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
ptable = new PartitionTable ( tableType , PartitionTable : : defaultFirstUsable ( device , tableType ) , PartitionTable : : defaultLastUsable ( device , tableType ) ) ;
operationStack ( ) . push ( new CreatePartitionTableOperation ( device , ptable ) ) ;
}
else if ( rxPartition . indexIn ( line ) ! = - 1 )
{
if ( ptable = = NULL )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Found partition but no partition table type (line %1). " , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
qint32 num = rxPartition . cap ( 1 ) . toInt ( ) ;
qint64 firstSector = rxPartition . cap ( 2 ) . toLongLong ( ) ;
qint64 lastSector = rxPartition . cap ( 3 ) . toLongLong ( ) ;
QString fsName = rxPartition . cap ( 4 ) ;
QString roleNames = rxPartition . cap ( 5 ) ;
QString volumeLabel = rxPartition . cap ( 6 ) . replace ( ' " ' , " " ) ;
QStringList flags = rxPartition . cap ( 7 ) . replace ( ' " ' , " " ) . split ( ' , ' ) ;
if ( firstSector < ptable - > firstUsable ( ) | | lastSector > ptable - > lastUsable ( ) )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Partition %1 would be outside the device's boundaries (line %2). " , num , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
if ( firstSector > = lastSector )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Partition %1 has end before start sector (line %2). " , num , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
PartitionNode * parent = ptable ;
Q_ASSERT ( parent ) ;
PartitionRole role ( PartitionRole : : None ) ;
if ( roleNames = = " extended " )
role = PartitionRole ( PartitionRole : : Extended ) ;
else if ( roleNames = = " logical " )
{
role = PartitionRole ( PartitionRole : : Logical ) ;
parent = ptable - > findPartitionBySector ( firstSector , PartitionRole ( PartitionRole : : Extended ) ) ;
}
else if ( roleNames = = " primary " )
role = PartitionRole ( PartitionRole : : Primary ) ;
if ( role = = PartitionRole ( PartitionRole : : None ) )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Unrecognized partition role \" %1 \" for partition %2 (line %3). " , roleNames , num , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
if ( parent = = NULL )
{
KMessageBox : : error ( this , i18nc ( " @info " , " No parent partition or partition table found for partition %1 (line %2). " , num , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
if ( role . has ( PartitionRole : : Extended ) & & ! PartitionTable : : tableTypeSupportsExtended ( tableType ) )
{
KMessageBox : : error ( this , i18nc ( " @info " , " The partition table type \" %1 \" does not support extended partitions, but one was found (line %2). " , PartitionTable : : tableTypeToName ( tableType ) , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
FileSystem * fs = FileSystemFactory : : create ( FileSystem : : typeForName ( fsName ) , firstSector , lastSector ) ;
if ( fs = = NULL )
{
KMessageBox : : error ( this , i18nc ( " @info " , " Could not create file system \" %1 \" for partition %2 (line %3). " , fsName , num , lineNo ) , i18nc ( " @title:window " , " Error While Importing Partition Table " ) ) ;
return ;
}
if ( fs - > supportSetLabel ( ) ! = FileSystem : : cmdSupportNone & & ! volumeLabel . isEmpty ( ) )
fs - > setLabel ( volumeLabel ) ;
Partition * p = new Partition ( parent , device , role , fs , firstSector , lastSector , - 1 , PartitionTable : : FlagNone , QStringList ( ) , false , PartitionTable : : FlagNone , Partition : : StateNew ) ;
operationStack ( ) . push ( new NewOperation ( device , p ) ) ;
}
else
Log ( Log : : warning ) < < i18nc ( " @info/plain " , " Could not parse line %1 from import file. Ignoring it. " , lineNo ) ;
}
if ( ptable - > type ( ) = = PartitionTable : : msdos & & ptable - > isSectorBased ( ) )
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 ( )
{
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) ) ;
QString fileName = KFileDialog : : getSaveFileName ( KUrl ( " kfiledialog://exportPartitionTable " ) ) ;
if ( fileName . isEmpty ( ) )
return ;
if ( QFile : : exists ( fileName ) & & KMessageBox : : warningContinueCancel ( this , i18nc ( " @info " , " Do you want to overwrite the existing file <filename>%1</filename>? " , fileName ) , i18nc ( " @title:window " , " Overwrite Existing File? " ) , KGuiItem ( i18nc ( " @action:button " , " &Overwrite File " ) ) , KStandardGuiItem : : cancel ( ) ) ! = KMessageBox : : Continue )
return ;
QFile file ( fileName ) ;
if ( ! file . open ( QFile : : WriteOnly | QFile : : Truncate ) )
{
2010-03-03 00:15:26 +00:00
KMessageBox : : error ( this , i18nc ( " @info " , " Could not create output file <filename>%1</filename>. " , fileName ) , i18nc ( " @title:window " , " Error Exporting Partition Table " ) ) ;
2010-03-02 13:35:57 +00:00
return ;
}
QTextStream stream ( & file ) ;
2010-03-03 00:15:26 +00:00
stream < < " ##|v1|## partition table of " < < pmWidget ( ) . selectedDevice ( ) - > deviceNode ( ) < < " \n " ;
2010-03-02 13:35:57 +00:00
stream < < " # on " < < QDateTime : : currentDateTime ( ) . toString ( ) < < " \n " ;
stream < < * pmWidget ( ) . selectedDevice ( ) - > partitionTable ( ) ;
}
2010-02-23 16:30:05 +00:00
void MainWindow : : onFileSystemSupport ( )
{
FileSystemSupportDialog dlg ( this ) ;
dlg . exec ( ) ;
}
void MainWindow : : onSettingsChanged ( const QString & )
{
enableActions ( ) ;
pmWidget ( ) . updatePartitions ( ) ;
}
void MainWindow : : onConfigureOptions ( )
{
if ( ConfigureOptionsDialog : : showDialog ( " Settings " ) )
return ;
QPointer < ConfigureOptionsDialog > dlg = new ConfigureOptionsDialog ( this , " Settings " , Config : : self ( ) ) ;
connect ( dlg , SIGNAL ( settingsChanged ( const QString & ) ) , SLOT ( onSettingsChanged ( const QString & ) ) ) ;
dlg - > show ( ) ;
}
void MainWindow : : onPropertiesDevice ( const QString & )
{
Q_ASSERT ( pmWidget ( ) . selectedDevice ( ) ) ;
if ( pmWidget ( ) . selectedDevice ( ) )
{
2010-02-24 10:47:22 +00:00
Device & d = * pmWidget ( ) . selectedDevice ( ) ;
QPointer < DevicePropsDialog > dlg = new DevicePropsDialog ( this , d ) ;
if ( dlg - > exec ( ) = = KDialog : : Accepted )
{
2010-03-01 12:00:07 +00:00
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 ( ) )
2010-02-24 10:47:22 +00:00
d . partitionTable ( ) - > setType ( d , PartitionTable : : msdos ) ;
on_m_OperationStack_devicesChanged ( ) ;
}
2010-02-23 16:30:05 +00:00
delete dlg ;
}
}