@ -35,10 +35,10 @@
# include <tdeio/job.h>
# include <tqdir.h>
# include <tqheader.h>
# include <tdemessagebox.h>
# include "autostart.h"
class desktop : public TDEListViewItem {
class CDesktopItem : public TDEListViewItem {
public :
KService * service ;
@ -47,8 +47,7 @@ public:
int iStartOn ;
enum { AutoStart , Shutdown , ENV } ;
desktop ( TQString service , int startOn , TQListView * parent ) : TDEListViewItem ( parent ) {
bisDesktop = false ;
CDesktopItem ( TQString service , int startOn , TQListView * parent ) : TDEListViewItem ( parent ) {
iStartOn = startOn ;
fileName = KURL ( service ) ;
if ( service . endsWith ( " .desktop " ) ) {
@ -57,9 +56,17 @@ desktop( TQString service, int startOn, TQListView *parent ): TDEListViewItem( p
}
}
~ CDesktopItem ( ) {
if ( service ) {
delete service ;
service = NULL ;
}
}
bool isDesktop ( ) { return bisDesktop ; }
int startOn ( ) { return iStartOn ; }
TQString fStartOn ( ) {
switch ( iStartOn ) {
case AutoStart :
@ -99,27 +106,30 @@ void setStartOn(int start) {
}
void updateService ( ) {
if ( bisDesktop ) service = new KService ( fileName . path ( ) ) ;
if ( bisDesktop ) {
if ( service ) {
delete service ;
service = NULL ;
}
service = new KService ( fileName . path ( ) ) ;
setText ( 0 , service - > name ( ) ) ;
setText ( 1 , service - > exec ( ) ) ;
setText ( 2 , fStartOn ( ) ) ;
}
~ desktop ( ) {
if ( service ) {
service = NULL ;
delete service ;
}
}
} ;
}
typedef KGenericFactory < autostart , TQWidget > autostartFactory ;
} ; //class CDesktopItem
typedef KGenericFactory < CAutostart , TQWidget > autostartFactory ;
K_EXPORT_COMPONENT_FACTORY ( kcm_autostart , autostartFactory ( " kcmautostart " ) )
autostart: : a utostart( TQWidget * parent , const char * name , const TQStringList & )
CAutostart: : CA utostart( TQWidget * parent , const char * name , const TQStringList & )
: TDECModule ( parent , name ) , myAboutData ( 0 )
{
TQGridLayout * AutostartConfigLayout = new TQGridLayout ( this , 1 , 1 , 11 , 6 , " AutostartConfigLayout " ) ;
btnAdd = new KPushButton ( this , " btnAdd " ) ;
AutostartConfigLayout - > addWidget ( btnAdd , 0 , 1 ) ;
listCMD = new TDEListView ( this , " listCMD " ) ;
@ -134,15 +144,12 @@ autostart::autostart(TQWidget *parent, const char *name, const TQStringList&)
AutostartConfigLayout - > addItem ( spacer1 , 4 , 1 ) ;
btnRemove = new KPushButton ( this , " btnRemove " ) ;
AutostartConfigLayout - > addWidget ( btnRemove , 1 , 1 ) ;
btnProperties = new TQPushButton ( this , " btnProperties " ) ;
AutostartConfigLayout - > addWidget ( btnProperties , 2 , 1 ) ;
cmbStartOn = new TQComboBox ( this , " cmbStartOn " ) ;
AutostartConfigLayout - > addWidget ( cmbStartOn , 3 , 1 ) ;
cmbStartOn - > insertItem ( i18n ( " Startup " ) ) ;
@ -159,7 +166,7 @@ autostart::autostart(TQWidget *parent, const char *name, const TQStringList&)
connect ( btnAdd , TQT_SIGNAL ( clicked ( ) ) , TQT_SLOT ( addCMD ( ) ) ) ;
connect ( btnRemove , TQT_SIGNAL ( clicked ( ) ) , TQT_SLOT ( removeCMD ( ) ) ) ;
connect ( listCMD , TQT_SIGNAL ( doubleClicked ( TQListViewItem * ) ) , TQT_SLOT ( editCMD ( TQListViewItem * ) ) ) ;
connect ( listCMD , TQT_SIGNAL ( doubleClicked ( TQListViewItem * ) ) , TQT_SLOT ( editCMD ( ) ) ) ;
connect ( btnProperties , TQT_SIGNAL ( clicked ( ) ) , TQT_SLOT ( editCMD ( ) ) ) ;
connect ( cmbStartOn , TQT_SIGNAL ( activated ( int ) ) , TQT_SLOT ( setStartOn ( int ) ) ) ;
connect ( listCMD , TQT_SIGNAL ( selectionChanged ( TQListViewItem * ) ) , TQT_SLOT ( selectionChanged ( TQListViewItem * ) ) ) ;
@ -179,10 +186,10 @@ autostart::autostart(TQWidget *parent, const char *name, const TQStringList&)
} ;
autostart: : ~ a utostart( )
CAutostart: : ~ CA utostart( )
{ }
void a utostart: : load ( )
void CA utostart: : load ( )
{
kgs = new TDEGlobalSettings ( ) ;
kdDebug ( ) < < " According to TDE your Autostart location is: " < < kgs - > autostartPath ( ) < < endl ;
@ -207,7 +214,7 @@ void autostart::load()
TQFileInfo * fi ;
while ( ( fi = it . current ( ) ) ! = 0 ) {
TQString filename = fi - > fileName ( ) ;
desktop * item = new desktop ( fi - > absFilePath ( ) , x , listCMD ) ;
CDesktopItem * item = new CDesktopItem ( fi - > absFilePath ( ) , x , listCMD ) ;
if ( ! item - > isDesktop ( ) ) {
if ( fi - > isSymLink ( ) ) {
TQString link = fi - > readLink ( ) ;
@ -231,7 +238,7 @@ void autostart::load()
}
}
void a utostart: : addCMD ( ) {
void CA utostart: : addCMD ( ) {
KService : : Ptr service = 0L ;
KOpenWithDlg owdlg ( this ) ;
if ( owdlg . exec ( ) ! = TQDialog : : Accepted )
@ -243,8 +250,12 @@ void autostart::addCMD() {
return ; // Don't crash if KOpenWith wasn't able to create service.
KURL desktopTemplate ;
if ( service - > desktopEntryName ( ) . isNull ( ) ) {
if ( service - > type ( ) = = " Service " ) {
KMessageBox : : error ( 0 , i18n ( " Cannot add a Service entry to the list of autostart modules. \n " ) + service - > desktopEntryPath ( ) ) ;
return ;
}
else if ( service - > desktopEntryName ( ) . isNull ( ) ) {
desktopTemplate = KURL ( kgs - > autostartPath ( ) + service - > name ( ) + " .desktop " ) ;
KSimpleConfig ksc ( desktopTemplate . path ( ) ) ;
ksc . setGroup ( " Desktop Entry " ) ;
@ -256,97 +267,83 @@ void autostart::addCMD() {
ksc . writeEntry ( " Type " , " Application " ) ;
ksc . sync ( ) ;
// FIXME: Make it so you can't give focus to the parent before this goes away.
// If the parent closes before this does, a crash is generated.
KPropertiesDialog dlg ( desktopTemplate , this , 0 , true /*modal*/ , false /*no auto-show*/ ) ;
if ( dlg . exec ( ) ! = TQDialog : : Accepted )
KPropertiesDialog * dlg = new KPropertiesDialog ( desktopTemplate , this , 0 , true /*modal*/ , false /*no auto-show*/ ) ;
if ( dlg - > exec ( ) ! = TQDialog : : Accepted )
return ;
}
else {
desktopTemplate = KURL ( locate ( " apps " , service - > desktopEntryPath ( ) ) ) ;
// FIXME: Make it so you can't give focus to the parent before this goes away.
// If the parent closes before this does, a crash is generated.
KPropertiesDialog dlg ( desktopTemplate , KURL ( kgs - > autostartPath ( ) ) ,
// Make sure the URL is not empty to avoid crashing the application
if ( desktopTemplate . isEmpty ( ) ) {
KMessageBox : : error ( 0 , i18n ( " Can't find a matching entry for the selected item. \n " ) + service - > desktopEntryPath ( ) ) ;
return ;
}
KPropertiesDialog * dlg = new KPropertiesDialog ( desktopTemplate , KURL ( kgs - > autostartPath ( ) ) ,
service - > name ( ) + " .desktop " , this , 0 , true /*modal*/ , false /*no auto-show*/ ) ;
if ( dlg . exec ( ) ! = TQDialog : : Accepted )
if ( dlg - > exec ( ) ! = TQDialog : : Accepted )
return ;
}
desktop * item = new desktop ( kgs - > autostartPath ( ) + service - > name ( ) + " .desktop " , desktop : : AutoStart , listCMD ) ;
CDesktopItem * item = new CDesktopItem ( kgs - > autostartPath ( ) + service - > name ( ) + " .desktop " , CDesktopItem : : AutoStart , listCMD ) ;
item - > setText ( 0 , item - > service - > name ( ) ) ;
item - > setText ( 1 , item - > service - > exec ( ) ) ;
item - > setText ( 2 , item - > fStartOn ( ) ) ;
emit changed ( true ) ;
}
void a utostart: : removeCMD ( ) {
void CA utostart: : removeCMD ( ) {
if ( ! listCMD - > selectedItem ( ) )
return ;
TDEIO : : del ( ( ( desktop * ) listCMD - > selectedItem ( ) ) - > fileName ) ;
listCMD - > takeItem ( listCMD - > selectedItem ( ) ) ;
TQListViewItem * currItem = listCMD - > selectedItem ( ) ;
TDEIO : : del ( ( ( CDesktopItem * ) currItem ) - > fileName ) ;
listCMD - > takeItem ( currItem ) ;
delete currItem ;
kdDebug ( ) < < " Deleting file " < < endl ;
emit changed ( true ) ;
}
void autostart : : editCMD ( TQListViewItem * entry ) {
if ( ! entry )
return ;
void CAutostart : : editCMD ( ) {
CDesktopItem * currItem = ( CDesktopItem * ) ( listCMD - > selectedItem ( ) ) ;
if ( ! currItem ) return ;
KFileItem kfi = KFileItem ( KFileItem : : Unknown , KFileItem : : Unknown , KURL ( currItem - > fileName ) , true ) ;
if ( ! editCMD ( kfi ) ) return ;
( ( desktop * ) entry ) - > updateService ( ) ;
KFileItem kfi = KFileItem ( KFileItem : : Unknown , KFileItem : : Unknown , KURL ( ( ( desktop * ) entry ) - > fileName ) , true ) ;
if ( ! editCMD ( kfi ) ) return ;
// Remove and recreate
if ( ( ( desktop * ) entry ) - > isDesktop ( ) ) {
listCMD - > takeItem ( listCMD - > selectedItem ( ) ) ;
desktop * item = new desktop ( ( ( desktop * ) entry ) - > fileName . path ( ) , ( ( desktop * ) entry ) - > startOn ( ) , listCMD ) ;
item - > setText ( 0 , ( ( desktop * ) entry ) - > service - > name ( ) ) ;
item - > setText ( 1 , ( ( desktop * ) entry ) - > service - > exec ( ) ) ;
item - > setText ( 2 , ( ( desktop * ) entry ) - > fStartOn ( ) ) ;
}
currItem - > updateService ( ) ;
}
bool a utostart: : editCMD ( KFileItem item ) {
KPropertiesDialog dlg ( & item , this ) ;
if ( dlg . exec ( ) ! = TQDialog : : Accepted )
bool CAutostart : : editCMD ( KFileItem item ) {
KPropertiesDialog * dlg = new KPropertiesDialog ( & item , this ) ;
if ( dlg - > exec ( ) ! = TQDialog : : Accepted )
return false ;
kdDebug ( ) < < " Saving file " < < endl ;
emit changed ( true ) ;
return true ;
}
void autostart: : editCMD ( ) {
editCMD ( listCMD - > selectedItem ( ) ) ;
void CAutostart: : setStartOn ( int index ) {
( ( CDesktopItem * ) listCMD - > currentItem ( ) ) - > setStartOn ( index ) ;
}
void autostart : : setStartOn ( int index ) {
( ( desktop * ) listCMD - > currentItem ( ) ) - > setStartOn ( index ) ;
}
void autostart : : selectionChanged ( TQListViewItem * entry ) {
void CAutostart : : selectionChanged ( TQListViewItem * entry ) {
cmbStartOn - > setEnabled ( ( entry ! = 0 ) ) ;
cmbStartOn - > setCurrentItem ( ( ( desktop * ) entry ) - > startOn ( ) ) ;
cmbStartOn - > setCurrentItem ( ( ( CDesktopItem * ) entry ) - > startOn ( ) ) ;
}
void autostart : : defaults ( ) { }
void autostart : : save ( )
{ }
void CAutostart : : defaults ( ) { }
void CAutostart : : save ( ) { }
int a utostart: : buttons ( )
int CAutostart : : buttons ( )
{
return TDECModule : : Apply | TDECModule : : Help ;
}
TQString autostart : : quickHelp ( ) const
TQString CAutostart : : quickHelp ( ) const
{
return i18n ( " This module helps configure which applications TDE runs when starting and exiting. " ) ;
}