summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-05-05 17:47:47 -0500
committerTimothy Pearson <kb9vqf@pearsoncomputing.net>2012-05-05 17:47:47 -0500
commit81dce195f1f6b18b66f2bbbe4ec6b10bb1387379 (patch)
tree0c3e06a8a35224dc79a29edfeb502f650add547c /src
downloadkcmautostart-81dce195f1f6b18b66f2bbbe4ec6b10bb1387379.tar.gz
kcmautostart-81dce195f1f6b18b66f2bbbe4ec6b10bb1387379.zip
Initial import
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am19
-rw-r--r--src/autostart.cpp349
-rw-r--r--src/autostart.desktop21
-rw-r--r--src/autostart.h71
4 files changed, 460 insertions, 0 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
new file mode 100644
index 0000000..bb48a2e
--- /dev/null
+++ b/src/Makefile.am
@@ -0,0 +1,19 @@
+INCLUDES = $(all_includes)
+METASOURCES = AUTO
+
+# Install this plugin in the KDE modules directory
+kde_module_LTLIBRARIES = kcm_autostart.la
+
+kcm_autostart_la_SOURCES = autostart.cpp
+kcm_autostart_la_LIBADD = -lkio $(LIB_TDEUI)
+kcm_autostart_la_LDFLAGS = -avoid-version -module -no-undefined \
+ $(all_libraries)
+
+
+xdg_apps_DATA = autostart.desktop
+
+
+messages: rc.cpp
+ $(EXTRACTRC) `find -name \*.ui -o -name \*.rc` > rc.cpp
+ $(XGETTEXT) *.cpp -o $(podir)/kcmautostart.pot
+
diff --git a/src/autostart.cpp b/src/autostart.cpp
new file mode 100644
index 0000000..5c07d5f
--- /dev/null
+++ b/src/autostart.cpp
@@ -0,0 +1,349 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Stephen Leaf *
+ * smileaf@smileaf.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+/* Adapted for use in the Trinity Desktop Environment */
+
+#include <tqlayout.h>
+
+#include <klocale.h>
+#include <kglobal.h>
+#include <kparts/genericfactory.h>
+#include <ksimpleconfig.h>
+#include <kglobalsettings.h>
+#include <kstandarddirs.h>
+#include <kurlrequester.h>
+#include <klistview.h>
+#include <kopenwith.h>
+#include <kpropertiesdialog.h>
+#include <kio/job.h>
+#include <tqdir.h>
+#include <tqheader.h>
+
+#include "autostart.h"
+
+class desktop : public KListViewItem {
+
+public:
+ KService * service;
+ bool bisDesktop;
+ KURL fileName;
+ int iStartOn;
+ enum { AutoStart, Shutdown, ENV };
+
+desktop( TQString service, int startOn, TQListView *parent ): KListViewItem( parent ) {
+ bisDesktop = false;
+ iStartOn = startOn;
+ fileName = KURL(service);
+ if (service.endsWith(".desktop")) {
+ this->service = new KService(service);
+ bisDesktop = true;
+ }
+}
+
+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;
+ }
+}
+
+void setStartOn(int start) {
+ iStartOn = start;
+ setText(2, fStartOn() );
+ KStandardDirs *ksd = new KStandardDirs();
+ KGlobalSettings * kgs = new KGlobalSettings();
+ TQString path;
+ switch (iStartOn) {
+ case AutoStart:
+ path = kgs->autostartPath()+"/";
+ break;
+ case Shutdown:
+ path = ksd->localtdedir()+"shutdown/";
+ break;
+ case ENV:
+ path = ksd->localtdedir()+"env/";
+ break;
+ }
+ KIO::file_move(fileName, KURL( path + fileName.fileName() ));
+ fileName = path + fileName.fileName();
+}
+
+void updateService() {
+ if (bisDesktop) service = new KService( fileName.path() );
+ }
+ ~desktop() {
+ delete service;
+ }
+};
+
+typedef KGenericFactory<autostart, TQWidget> autostartFactory;
+
+K_EXPORT_COMPONENT_FACTORY( kcm_autostart, autostartFactory("kcmautostart"))
+
+autostart::autostart(TQWidget *parent, const char *name, const TQStringList&)
+ : KCModule(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 KListView( this, "listCMD" );
+ listCMD->addColumn( i18n( "Name" ) );
+ listCMD->addColumn( i18n( "Command" ) );
+ listCMD->addColumn( i18n( "Run on" ) );
+ listCMD->setAllColumnsShowFocus( TRUE );
+ listCMD->setShowSortIndicator( TRUE );
+
+ AutostartConfigLayout->addMultiCellWidget( listCMD, 0, 4, 0, 0 );
+ TQSpacerItem * spacer1 = new TQSpacerItem( 71, 170, TQSizePolicy::Minimum, TQSizePolicy::Expanding );
+ 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") );
+ cmbStartOn->insertItem( i18n("Shutdown") );
+ cmbStartOn->insertItem( i18n("ENV") );
+ cmbStartOn->setEnabled(false);
+
+ btnAdd->setText( i18n( "&Add" ) );
+ btnAdd->setAccel( TQKeySequence( i18n( "Alt+A" ) ) );
+ btnRemove->setText( i18n( "&Remove" ) );
+ btnRemove->setAccel( TQKeySequence( i18n( "Alt+R" ) ) );
+ btnProperties->setText( i18n( "&Properties" ) );
+ btnProperties->setAccel( TQKeySequence( i18n( "Alt+P" ) ) );
+
+ 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( 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*)) );
+
+ listCMD->setFocus();
+
+ load();
+
+ KAboutData* about = new KAboutData("autostart", I18N_NOOP("TDE Autostart Manager"), "0.5",
+ I18N_NOOP("TDE Autostart Manager Control Panel Module"),
+ KAboutData::License_GPL,
+ I18N_NOOP("(c) 2006 Stephen Leaf"), 0, 0);
+
+ about->addAuthor("Stephen Leaf", 0, "smileaf@smileaf.org");
+ setAboutData( about );
+
+};
+
+
+autostart::~autostart()
+{}
+
+void autostart::load()
+{
+ kgs = new KGlobalSettings();
+ kdDebug() << "According to TDE your Autostart location is: " << kgs->autostartPath() << endl;
+ KStandardDirs *ksd = new KStandardDirs();
+
+ TQString path;
+ for (int x=0;x<3;x++) {
+ if (x==0)
+ path = kgs->autostartPath();
+ else if (x==1)
+ path = ksd->localtdedir() + "/shutdown";
+ else if (x==2)
+ path = ksd->localtdedir() + "/env";
+
+ if (! KStandardDirs::exists(path))
+ KStandardDirs::makeDir(path);
+
+ TQDir *autostartdir = new TQDir( path );
+ autostartdir->setFilter( TQDir::Files);
+ const TQFileInfoList *list = autostartdir->entryInfoList();
+ TQFileInfoListIterator it( *list );
+ TQFileInfo *fi;
+ while ( (fi = it.current()) != 0 ) {
+ TQString filename = fi->fileName();
+ desktop * item = new desktop( fi->absFilePath(), x, listCMD );
+ if ( ! item->isDesktop() ) {
+ if ( fi->isSymLink() ) {
+ TQString link = fi->readLink();
+ item->setText( 0, filename );
+ item->setText( 1, link );
+ item->setText( 2, item->fStartOn() );
+ }
+ else {
+ item->setText( 0, filename );
+ item->setText( 1, filename );
+ item->setText( 2, item->fStartOn() );
+ }
+ }
+ else {
+ item->setText( 0, item->service->name() );
+ item->setText( 1, item->service->exec() );
+ item->setText( 2, item->fStartOn() );
+ }
+ ++it;
+ }
+ }
+}
+
+void autostart::addCMD() {
+ KService::Ptr service = 0L;
+ KOpenWithDlg owdlg( this );
+ if (owdlg.exec() != TQDialog::Accepted)
+ return;
+ service = owdlg.service();
+
+ Q_ASSERT(service);
+ if (!service)
+ return; // Don't crash if KOpenWith wasn't able to create service.
+
+ KURL desktopTemplate;
+
+ if ( service->desktopEntryName().isNull() ) {
+ desktopTemplate = KURL( kgs->autostartPath() + service->name() + ".desktop" );
+ KSimpleConfig ksc(desktopTemplate.path());
+ ksc.setGroup("Desktop Entry");
+ ksc.writeEntry("Encoding","UTF-8");
+ ksc.writeEntry("Exec",service->exec());
+ ksc.writeEntry("Icon","exec");
+ ksc.writeEntry("Path","");
+ ksc.writeEntry("Terminal",false);
+ 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 )
+ 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()),
+ service->name() + ".desktop", this, 0, true /*modal*/, false /*no auto-show*/ );
+ if ( dlg.exec() != TQDialog::Accepted )
+ return;
+ }
+
+ desktop * item = new desktop( kgs->autostartPath() + service->name() + ".desktop", desktop::AutoStart, listCMD );
+ item->setText( 0, item->service->name() );
+ item->setText( 1, item->service->exec() );
+ item->setText( 2, item->fStartOn() );
+ emit changed(true);
+}
+
+void autostart::removeCMD() {
+ if (!listCMD->selectedItem())
+ return;
+
+ KIO::del(((desktop *)listCMD->selectedItem())->fileName);
+
+ listCMD->takeItem( listCMD->selectedItem() );
+ kdDebug() << "Deleting file" << endl;
+
+ emit changed(true);
+}
+
+void autostart::editCMD(TQListViewItem* entry) {
+ if (!entry)
+ 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() );
+ }
+}
+
+bool autostart::editCMD( KFileItem item) {
+ KPropertiesDialog dlg( &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 autostart::setStartOn( int index ) {
+ ((desktop*)listCMD->currentItem())->setStartOn(index);
+}
+
+void autostart::selectionChanged(TQListViewItem* entry) {
+ cmbStartOn->setEnabled( (entry != 0) );
+ cmbStartOn->setCurrentItem( ((desktop*)entry)->startOn() );
+}
+
+void autostart::defaults(){}
+
+
+void autostart::save()
+{}
+
+
+int autostart::buttons()
+{
+ return KCModule::Apply|KCModule::Help;
+}
+
+
+TQString autostart::quickHelp() const
+{
+ return i18n("This module helps configure which applications TDE runs when starting and exiting.");
+}
diff --git a/src/autostart.desktop b/src/autostart.desktop
new file mode 100644
index 0000000..be1fc68
--- /dev/null
+++ b/src/autostart.desktop
@@ -0,0 +1,21 @@
+[Desktop Entry]
+Encoding=UTF-8
+Exec=kcmshell autostart
+Icon=launch
+Type=Application
+
+X-KDE-ModuleType=Library
+X-KDE-Library=autostart
+X-KDE-HasReadOnlyMode=false
+X-KDE-ParentApp=kcontrol
+
+[Desktop Entry]
+Encoding=UTF-8
+Comment=A KControl tool for managing what programs start up with TDE.
+Comment[ca]=Panell de control per a gestionar els programes que s'inicien amb la sessió de TDE.
+Comment[es]=Panel de control para gestionar los programas que se inician con la sesión de TDE.
+Keywords=autostart manager
+Name=Autostart Manager
+Name[ca]=Autoengega
+Name[es]=Arranque automático
+Categories=Qt;KDE;X-KDE-settings-components;
diff --git a/src/autostart.h b/src/autostart.h
new file mode 100644
index 0000000..6877e4e
--- /dev/null
+++ b/src/autostart.h
@@ -0,0 +1,71 @@
+/***************************************************************************
+ * Copyright (C) 2006 by Stephen Leaf *
+ * smileaf@smileaf.org *
+ * *
+ * This program is free software; you can redistribute it and/or modify *
+ * it under the terms of the GNU General Public License as published by *
+ * the Free Software Foundation; either version 2 of the License, or *
+ * (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the *
+ * Free Software Foundation, Inc., *
+ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
+ ***************************************************************************/
+
+/* Adapted for use in the Trinity Desktop Environment */
+
+
+#ifndef _AUTOSTART_H_
+#define _AUTOSTART_H_
+
+#include <kcmodule.h>
+#include <kaboutdata.h>
+#include <kpushbutton.h>
+#include <klistview.h>
+#include <kfileitem.h>
+#include <kglobalsettings.h>
+#include <tqpushbutton.h>
+#include <tqcombobox.h>
+
+class autostart: public KCModule
+{
+ Q_OBJECT
+
+public:
+ autostart( TQWidget *parent=0, const char *name=0, const TQStringList& = TQStringList() );
+ ~autostart();
+
+ virtual void load();
+ virtual void save();
+ virtual void defaults();
+ virtual int buttons();
+ virtual TQString quickHelp() const;
+ virtual const KAboutData *aboutData() const
+ { return myAboutData; };
+
+public slots:
+ void addCMD();
+ void removeCMD();
+ void editCMD(TQListViewItem*);
+ bool editCMD(KFileItem);
+ void editCMD();
+ void setStartOn(int);
+ void selectionChanged(TQListViewItem*);
+
+private:
+ KAboutData *myAboutData;
+ KGlobalSettings *kgs;
+ KPushButton* btnAdd;
+ KListView* listCMD;
+ KPushButton* btnRemove;
+ TQPushButton* btnProperties;
+ TQComboBox* cmbStartOn;
+};
+
+#endif