2008-09-24 20:32:01 +01:00
/***************************************************************************
2009-04-21 17:36:43 +01:00
* Copyright ( C ) 2008 , 2009 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"
2008-09-24 20:32:01 +01:00
# include "core/device.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>
2008-09-24 20:32:01 +01:00
# include <QCloseEvent>
2010-02-13 11:25:56 +00:00
# include <QReadLocker>
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
/** 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 ) ,
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
{
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
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 ( ) ) ;
2009-04-22 11:35:44 +01:00
pmWidget ( ) . init ( actionCollection ( ) , " 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 ( ) ;
2008-09-24 20:32:01 +01:00
}
void MainWindow : : closeEvent ( QCloseEvent * event )
{
2010-02-11 18:47:51 +00:00
if ( pmWidget ( ) . applyProgressDialog ( ) . isVisible ( ) )
2008-09-24 20:32:01 +01:00
{
event - > ignore ( ) ;
return ;
}
2009-04-21 17:36:43 +01:00
if ( pmWidget ( ) . 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> " ,
2009-04-21 17:36:43 +01:00
" <para>Do you really want to quit the application?</para><para>There are still %1 operations pending.</para> " , pmWidget ( ) . 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 ;
if ( pmWidget ( ) . applyProgressDialog ( ) . isVisible ( ) )
w = & pmWidget ( ) . applyProgressDialog ( ) ;
else if ( pmWidget ( ) . scanProgressDialog ( ) . isVisible ( ) )
w = & pmWidget ( ) . scanProgressDialog ( ) ;
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 ( ) ) ;
// View actions
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 ( ) ) ;
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-19 21:09:14 +00:00
connect ( & listDevices ( ) , SIGNAL ( deviceDoubleClicked ( const QString & ) ) , & pmWidget ( ) , 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-12 11:29:12 +00:00
void MainWindow : : on_m_PartitionManagerWidget_operationsChanged ( )
2008-09-24 20:32:01 +01:00
{
2010-02-12 11:49:35 +00:00
listOperations ( ) . updateOperations ( pmWidget ( ) . operations ( ) ) ;
2010-02-12 11:29:12 +00:00
2010-02-21 17:54:52 +00:00
if ( ! isKPart ( ) )
statusText ( ) . setText ( i18ncp ( " @info:status " , " One pending operation " , " %1 pending operations " , pmWidget ( ) . numPendingOperations ( ) ) ) ;
2008-09-24 20:32:01 +01:00
}
2010-02-12 11:29:12 +00:00
void MainWindow : : on_m_PartitionManagerWidget_devicesChanged ( )
2008-09-24 20:32:01 +01:00
{
2010-02-13 11:25:56 +00:00
QReadLocker lockDevices ( & pmWidget ( ) . operationStack ( ) . lock ( ) ) ;
2010-02-19 21:25:48 +00:00
listDevices ( ) . updateDevices ( pmWidget ( ) . 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-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-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 ( ) ;
KMessageBox : : information ( this , i18nc ( " @info " , " This will hide the menu bar completely. You can show it again by typing %1. " , accel ) , i18nc ( " @window:title " , " Hide Menu Bar " ) , " hideMenuBarWarning " ) ;
menuBar ( ) - > hide ( ) ;
}
Config : : self ( ) - > setShowMenuBar ( menuBarAction - > isChecked ( ) ) ;
}