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