Browse Source

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

and 3105.

Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
master
Michele Calgaro 4 months ago
parent
commit
7524af262c
Signed by: MicheleC GPG Key ID: 2A75B7CA8ADED5CF
1 changed files with 64 additions and 72 deletions
  1. +64
    -72
      src/autostart.cpp

+ 64
- 72
src/autostart.cpp View File

@@ -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(){}


Loading…
Cancel
Save