@ -37,7 +37,6 @@
# include <stdlib.h>
TrayLabelMgr * TrayLabelMgr : : gTrayLabelMgr = NULL ;
const char * TrayLabelMgr : : mOptionString = " +bdefi:lmop:qtw: " ;
TrayLabelMgr * TrayLabelMgr : : instance ( )
{
@ -85,7 +84,7 @@ void TrayLabelMgr::startup(void)
state = = SysTrayAbsent ? i18n ( " No system tray found " ) : i18n ( " System tray appears to be hidden " ) ,
i18n ( " TDEDocker " ) ) = = KMessageBox : : Cancel )
{
tqApp - > quit ( ) ;
TDEApplication: : kApplication ( ) - > quit ( ) ;
return ;
}
}
@ -106,8 +105,13 @@ void TrayLabelMgr::startup(void)
// Process the request Q from previous instances
TRACE ( " Request queue has %i requests " , mRequestQ . count ( ) ) ;
for ( unsigned i = 0 ; i < mRequestQ . count ( ) ; i + + )
{
ok | = processCommand ( mRequestQ [ i ] ) ;
if ( ! ok ) tqApp - > quit ( ) ;
}
if ( ! ok )
{
TDEApplication : : kApplication ( ) - > quit ( ) ;
}
}
// Initialize a TQTrayLabel after its creation
@ -258,7 +262,7 @@ bool TrayLabelMgr::processCommand(int argc, char** argv)
optind = 0 ; // initialise the getopt static
while ( ( option = getopt ( argc , argv , mOptionString ) ) ! = EOF )
while ( ( option = getopt ( argc , argv , " +bdefi:lmop:qtw: " ) ) ! = EOF )
{
switch ( option )
{
@ -364,7 +368,7 @@ TQTrayLabel *TrayLabelMgr::selectAndDock(Window w, bool checkNormality)
if ( ! isWindowDocked ( w ) ) return new CustomTrayLabel ( w ) ;
TRACE ( " 0x%x is not docked" , ( unsigned ) w ) ;
TRACE ( " 0x%x is alredy docked" , ( unsigned ) w ) ;
KMessageBox : : error ( NULL , i18n ( " This window is already docked. \n "
" Click on system tray icon to toggle docking. " ) , i18n ( " TDEDocker " ) ) ;
@ -407,7 +411,9 @@ TQTrayLabel *TrayLabelMgr::dockApplication(char *argv[])
if ( execvp ( argv [ 0 ] , argv ) = = - 1 )
{
tqDebug ( " %s " , i18n ( " Failed to exec [%1]: %2 " ) . arg ( argv [ 0 ] ) . arg ( strerror ( errno ) ) . local8Bit ( ) . data ( ) ) ;
: : exit ( 0 ) ; // will become a zombie in some systems :(
// Exit the forked process only.
// Using TDEApplication::kApplication()->quit() crashes the parent application.
exit ( 0 ) ;
return NULL ;
}
}
@ -423,7 +429,7 @@ TQTrayLabel *TrayLabelMgr::dockApplication(char *argv[])
if ( argv [ i ] ) cmd_line < < argv [ i ] ; else break ;
TQTrayLabel * label = new CustomTrayLabel ( cmd_line , pid ) ;
tqApp - > syncX ( ) ;
TDEApplication: : kApplication ( ) - > syncX ( ) ;
write ( filedes [ 1 ] , buf , sizeof ( buf ) ) ;
close ( filedes [ 0 ] ) ;
close ( filedes [ 1 ] ) ;
@ -453,7 +459,10 @@ void TrayLabelMgr::trayLabelDestroyed(TQObject *t)
{
bool reconnect = ( ( TQObject * ) mTrayLabels . getLast ( ) = = t ) ;
mTrayLabels . removeRef ( ( TQTrayLabel * ) t ) ;
if ( mTrayLabels . isEmpty ( ) ) tqApp - > quit ( ) ;
if ( mTrayLabels . isEmpty ( ) )
{
TDEApplication : : kApplication ( ) - > quit ( ) ;
}
else if ( reconnect )
{
TRACE ( " Reconnecting " ) ;
@ -500,13 +509,17 @@ void TrayLabelMgr::doRestoreSession()
TRACE ( " Restoring session " ) ;
TDEConfig * config = TDEApplication : : kApplication ( ) - > sessionConfig ( ) ;
for ( int i = 1 ; ; + + i )
if ( config - > hasGroup ( " General " ) )
{
if ( ! config - > hasGroup ( " Instance " + TQString : : number ( i ) ) )
config - > setGroup ( " General " ) ;
int count = config - > readNumEntry ( " InstanceCount " , 0 ) ;
for ( int i = 0 ; i < count ; + + i )
{
return ;
if ( ! config - > hasGroup ( TQString : : number ( i ) ) )
{
break ;
}
config - > setGroup ( " Instance " + TQString : : number ( i ) ) ;
config - > setGroup ( TQString : : number ( i ) ) ;
TQString pname = config - > readEntry ( " Application " , TQString : : null ) ;
if ( ! pname . isEmpty ( ) )
{
@ -515,24 +528,39 @@ void TrayLabelMgr::doRestoreSession()
mTrayLabels . getFirst ( ) - > restoreState ( config ) ;
}
}
}
// Exit if no application could be restored
if ( mTrayLabels . isEmpty ( ) )
{
TDEApplication : : kApplication ( ) - > quit ( ) ;
}
}
bool TrayLabelMgr : : saveState ( TQSessionManager & sm )
{
TRACE ( " Saving session " ) ;
int i = 1 ;
int i = 0 ;
TQTrayLabel * t ;
TDEConfig * config = TDEApplication : : kApplication ( ) - > sessionConfig ( ) ;
TQPtrListIterator < TQTrayLabel > it ( mTrayLabels ) ;
TQPtrListIterator < TQTrayLabel > it ( mTrayLabels ) ;
for ( it . toFirst ( ) ; it . current ( ) ; + + it )
{
t = it . current ( ) ;
TRACE ( " Saving instance %i " , i ) ;
config - > setGroup ( " Instance " + TQString : : number ( i ) ) ;
t - > saveState ( config ) ;
config - > setGroup ( TQString : : number ( i ) ) ;
if ( t - > saveState ( config ) )
{
TRACE ( " Saved instance %i " , i ) ;
+ + i ;
}
else
{
config - > deleteGroup ( TQString : : number ( i ) ) ;
}
}
config - > setGroup ( " General " ) ;
config - > writeEntry ( " InstanceCount " , i ) ;
return true ;
}