From 7524af262cebd82c0285e0e90add99b1fc7a85d1 Mon Sep 17 00:00:00 2001 From: Michele Calgaro Date: Fri, 8 May 2020 14:41:32 +0900 Subject: Fixed TCC crash when using non .desktop entries. This resolves bug 2990 and 3105. Signed-off-by: Michele Calgaro --- src/autostart.cpp | 136 +++++++++++++++++++++++++----------------------------- 1 file changed, 64 insertions(+), 72 deletions(-) (limited to 'src') diff --git a/src/autostart.cpp b/src/autostart.cpp index 188b3c9..9e68188 100644 --- a/src/autostart.cpp +++ b/src/autostart.cpp @@ -41,80 +41,72 @@ class CDesktopItem : public TDEListViewItem { public: - KService * service; - bool bisDesktop; + KService *mService; KURL fileName; int iStartOn; enum { AutoStart, Shutdown, ENV }; -CDesktopItem( TQString service, int startOn, TQListView *parent ): TDEListViewItem( parent ) { - iStartOn = startOn; - fileName = KURL(service); - if (service.endsWith(".desktop")) { - this->service = new KService(service); - bisDesktop = true; - } -} + CDesktopItem( TQString service, int startOn, TQListView *parent ): TDEListViewItem( parent ), + mService(NULL), iStartOn(startOn), fileName(KURL(service)) + { + if (service.endsWith(".desktop")) { + mService = new KService(service); + } + } -~CDesktopItem() { - if(service) { - delete service; - service = NULL; + ~CDesktopItem() { + if (mService) { + delete mService; + mService = NULL; + } } -} -bool isDesktop() { return bisDesktop; } - -int startOn() { return iStartOn; } - -TQString fStartOn() { - switch (iStartOn) { - case AutoStart: - return i18n("Startup"); - break; - case Shutdown: - return i18n("Shutdown"); - break; - case ENV: - return i18n("ENV"); - break; - default: - return ""; - break; - } -} + TQString fStartOn() { + switch (iStartOn) { + case AutoStart: + return i18n("Startup"); + break; + case Shutdown: + return i18n("Shutdown"); + break; + case ENV: + return i18n("ENV"); + break; + default: + return ""; + break; + } + } -void setStartOn(int start) { - iStartOn = start; - setText(2, fStartOn()); - TQString path; - switch (iStartOn) { - case AutoStart: - path = TDEGlobalSettings::autostartPath()+"/"; - break; - case Shutdown: - path = TDEGlobal::dirs()->localtdedir()+"shutdown/"; - break; - case ENV: - path = TDEGlobal::dirs()->localtdedir()+"env/"; - break; - } - TDEIO::file_move(fileName, KURL( path + fileName.fileName() )); - fileName = path + fileName.fileName(); -} + void setStartOn(int start) { + iStartOn = start; + setText(2, fStartOn()); + TQString path; + switch (iStartOn) { + case AutoStart: + path = TDEGlobalSettings::autostartPath()+"/"; + break; + case Shutdown: + path = TDEGlobal::dirs()->localtdedir()+"shutdown/"; + break; + case ENV: + path = TDEGlobal::dirs()->localtdedir()+"env/"; + break; + } + TDEIO::file_move(fileName, KURL( path + fileName.fileName() )); + fileName = path + fileName.fileName(); + } -void updateService() { - if (bisDesktop) { - if (service) { - delete service; - service = NULL; - } - service = new KService( fileName.path() ); - setText( 0, service->name() ); - setText( 1, service->exec() ); - setText( 2, fStartOn() ); - } -} + void updateService() { + if (mService) { + delete mService; + mService = NULL; + } + mService = new KService( fileName.path() ); + setText( 0, mService->name() ); + setText( 1, mService->exec() ); + setText( 2, fStartOn() ); + } }; //class CDesktopItem @@ -210,8 +202,8 @@ void CAutostart::load() TQFileInfo *fi; while ( (fi = it.current()) != 0 ) { TQString filename = fi->fileName(); - CDesktopItem * item = new CDesktopItem( fi->absFilePath(), x, listCMD ); - if ( ! item->isDesktop() ) { + CDesktopItem *item = new CDesktopItem( fi->absFilePath(), x, listCMD ); + if ( !item->mService ) { if ( fi->isSymLink() ) { TQString link = fi->readLink(); item->setText( 0, filename ); @@ -225,8 +217,8 @@ void CAutostart::load() } } else { - item->setText( 0, item->service->name() ); - item->setText( 1, item->service->exec() ); + item->setText( 0, item->mService->name() ); + item->setText( 1, item->mService->exec() ); item->setText( 2, item->fStartOn() ); } ++it; @@ -282,8 +274,8 @@ void CAutostart::addCMD() { } CDesktopItem * item = new CDesktopItem( TDEGlobalSettings::autostartPath() + service->name() + ".desktop", CDesktopItem::AutoStart, listCMD ); - item->setText( 0, item->service->name() ); - item->setText( 1, item->service->exec() ); + item->setText( 0, item->mService->name() ); + item->setText( 1, item->mService->exec() ); item->setText( 2, item->fStartOn() ); emit changed(true); } @@ -327,7 +319,7 @@ void CAutostart::setStartOn( int index ) { void CAutostart::selectionChanged(TQListViewItem* entry) { cmbStartOn->setEnabled( (entry != 0) ); - cmbStartOn->setCurrentItem( ((CDesktopItem*)entry)->startOn() ); + cmbStartOn->setCurrentItem( ((CDesktopItem*)entry)->iStartOn ); } void CAutostart::defaults(){} -- cgit v1.2.1