Fixed TCC crash when using non .desktop entries. This resolves bug 2990

and 3105.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
(cherry picked from commit 7524af262c)
r14.0.x
Michele Calgaro 5 years ago
parent 39b6edb10d
commit cb6772b714
Signed by: MicheleC
GPG Key ID: 2A75B7CA8ADED5CF

@ -41,80 +41,72 @@
class CDesktopItem : public TDEListViewItem { class CDesktopItem : public TDEListViewItem {
public: public:
KService * service; KService *mService;
bool bisDesktop;
KURL fileName; KURL fileName;
int iStartOn; int iStartOn;
enum { AutoStart, Shutdown, ENV }; enum { AutoStart, Shutdown, ENV };
CDesktopItem( TQString service, int startOn, TQListView *parent ): TDEListViewItem( parent ) { CDesktopItem( TQString service, int startOn, TQListView *parent ): TDEListViewItem( parent ),
iStartOn = startOn; mService(NULL), iStartOn(startOn), fileName(KURL(service))
fileName = KURL(service); {
if (service.endsWith(".desktop")) { if (service.endsWith(".desktop")) {
this->service = new KService(service); mService = new KService(service);
bisDesktop = true; }
} }
}
~CDesktopItem() { ~CDesktopItem() {
if(service) { if (mService) {
delete service; delete mService;
service = NULL; mService = NULL;
}
} }
}
bool isDesktop() { return bisDesktop; } TQString fStartOn() {
switch (iStartOn) {
int startOn() { return iStartOn; } case AutoStart:
return i18n("Startup");
TQString fStartOn() { break;
switch (iStartOn) { case Shutdown:
case AutoStart: return i18n("Shutdown");
return i18n("Startup"); break;
break; case ENV:
case Shutdown: return i18n("ENV");
return i18n("Shutdown"); break;
break; default:
case ENV: return "";
return i18n("ENV"); break;
break; }
default: }
return "";
break;
}
}
void setStartOn(int start) { void setStartOn(int start) {
iStartOn = start; iStartOn = start;
setText(2, fStartOn()); setText(2, fStartOn());
TQString path; TQString path;
switch (iStartOn) { switch (iStartOn) {
case AutoStart: case AutoStart:
path = TDEGlobalSettings::autostartPath()+"/"; path = TDEGlobalSettings::autostartPath()+"/";
break; break;
case Shutdown: case Shutdown:
path = TDEGlobal::dirs()->localtdedir()+"shutdown/"; path = TDEGlobal::dirs()->localtdedir()+"shutdown/";
break; break;
case ENV: case ENV:
path = TDEGlobal::dirs()->localtdedir()+"env/"; path = TDEGlobal::dirs()->localtdedir()+"env/";
break; break;
} }
TDEIO::file_move(fileName, KURL( path + fileName.fileName() )); TDEIO::file_move(fileName, KURL( path + fileName.fileName() ));
fileName = path + fileName.fileName(); fileName = path + fileName.fileName();
} }
void updateService() { void updateService() {
if (bisDesktop) { if (mService) {
if (service) { delete mService;
delete service; mService = NULL;
service = NULL; }
} mService = new KService( fileName.path() );
service = new KService( fileName.path() ); setText( 0, mService->name() );
setText( 0, service->name() ); setText( 1, mService->exec() );
setText( 1, service->exec() ); setText( 2, fStartOn() );
setText( 2, fStartOn() ); }
}
}
}; //class CDesktopItem }; //class CDesktopItem
@ -210,8 +202,8 @@ void CAutostart::load()
TQFileInfo *fi; TQFileInfo *fi;
while ( (fi = it.current()) != 0 ) { while ( (fi = it.current()) != 0 ) {
TQString filename = fi->fileName(); TQString filename = fi->fileName();
CDesktopItem * item = new CDesktopItem( fi->absFilePath(), x, listCMD ); CDesktopItem *item = new CDesktopItem( fi->absFilePath(), x, listCMD );
if ( ! item->isDesktop() ) { if ( !item->mService ) {
if ( fi->isSymLink() ) { if ( fi->isSymLink() ) {
TQString link = fi->readLink(); TQString link = fi->readLink();
item->setText( 0, filename ); item->setText( 0, filename );
@ -225,8 +217,8 @@ void CAutostart::load()
} }
} }
else { else {
item->setText( 0, item->service->name() ); item->setText( 0, item->mService->name() );
item->setText( 1, item->service->exec() ); item->setText( 1, item->mService->exec() );
item->setText( 2, item->fStartOn() ); item->setText( 2, item->fStartOn() );
} }
++it; ++it;
@ -282,8 +274,8 @@ void CAutostart::addCMD() {
} }
CDesktopItem * item = new CDesktopItem( TDEGlobalSettings::autostartPath() + service->name() + ".desktop", CDesktopItem::AutoStart, listCMD ); CDesktopItem * item = new CDesktopItem( TDEGlobalSettings::autostartPath() + service->name() + ".desktop", CDesktopItem::AutoStart, listCMD );
item->setText( 0, item->service->name() ); item->setText( 0, item->mService->name() );
item->setText( 1, item->service->exec() ); item->setText( 1, item->mService->exec() );
item->setText( 2, item->fStartOn() ); item->setText( 2, item->fStartOn() );
emit changed(true); emit changed(true);
} }
@ -327,7 +319,7 @@ void CAutostart::setStartOn( int index ) {
void CAutostart::selectionChanged(TQListViewItem* entry) { void CAutostart::selectionChanged(TQListViewItem* entry) {
cmbStartOn->setEnabled( (entry != 0) ); cmbStartOn->setEnabled( (entry != 0) );
cmbStartOn->setCurrentItem( ((CDesktopItem*)entry)->startOn() ); cmbStartOn->setCurrentItem( ((CDesktopItem*)entry)->iStartOn );
} }
void CAutostart::defaults(){} void CAutostart::defaults(){}

Loading…
Cancel
Save