You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
311 lines
8.8 KiB
311 lines
8.8 KiB
15 years ago
|
/*
|
||
|
*
|
||
|
* This file is part of the KDE libraries
|
||
|
* Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
|
||
|
*
|
||
|
* $Id$
|
||
|
*
|
||
|
* This library is free software; you can redistribute it and/or
|
||
|
* modify it under the terms of the GNU Library General Public
|
||
|
* License version 2 as published by the Free Software Foundation.
|
||
|
*
|
||
|
* This library 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
|
||
|
* Library General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Library General Public License
|
||
|
* along with this library; see the file COPYING.LIB. If not, write to
|
||
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
**/
|
||
|
|
||
|
#include "autostart.h"
|
||
|
|
||
12 years ago
|
#include <tdeconfig.h>
|
||
15 years ago
|
#include <kdesktopfile.h>
|
||
12 years ago
|
#include <tdeglobal.h>
|
||
15 years ago
|
#include <kstandarddirs.h>
|
||
|
|
||
14 years ago
|
#include <stdlib.h>
|
||
|
|
||
15 years ago
|
class AutoStartItem
|
||
|
{
|
||
|
public:
|
||
15 years ago
|
TQString name;
|
||
|
TQString service;
|
||
|
TQString startAfter;
|
||
15 years ago
|
int phase;
|
||
|
};
|
||
|
|
||
15 years ago
|
class AutoStartList: public TQPtrList<AutoStartItem>
|
||
15 years ago
|
{
|
||
|
public:
|
||
|
AutoStartList() { }
|
||
|
};
|
||
|
|
||
|
AutoStart::AutoStart( bool new_startup )
|
||
|
: m_newStartup( new_startup ), m_phase( new_startup ? -1 : 0), m_phasedone(false)
|
||
|
{
|
||
|
m_startList = new AutoStartList;
|
||
|
m_startList->setAutoDelete(true);
|
||
12 years ago
|
TDEGlobal::dirs()->addResourceType("autostart", "share/autostart");
|
||
15 years ago
|
TQString xdgdirs = getenv("XDG_CONFIG_DIRS");
|
||
15 years ago
|
if (xdgdirs.isEmpty())
|
||
|
xdgdirs = "/etc/xdg";
|
||
|
|
||
15 years ago
|
TQStringList xdgdirslist = TQStringList::split( ':', xdgdirs );
|
||
|
for ( TQStringList::Iterator itr = xdgdirslist.begin(); itr != xdgdirslist.end(); ++itr ) {
|
||
12 years ago
|
TDEGlobal::dirs()->addResourceDir("autostart", (*itr) +"/autostart");
|
||
15 years ago
|
}
|
||
15 years ago
|
}
|
||
|
|
||
|
AutoStart::~AutoStart()
|
||
|
{
|
||
|
delete m_startList;
|
||
|
}
|
||
|
|
||
|
void
|
||
|
AutoStart::setPhase(int phase)
|
||
|
{
|
||
|
if (phase > m_phase)
|
||
|
{
|
||
|
m_phase = phase;
|
||
|
m_phasedone = false;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void AutoStart::setPhaseDone()
|
||
|
{
|
||
|
m_phasedone = true;
|
||
|
}
|
||
|
|
||
15 years ago
|
static TQString extractName(TQString path)
|
||
15 years ago
|
{
|
||
14 years ago
|
int i = path.findRev('/');
|
||
15 years ago
|
if (i >= 0)
|
||
|
path = path.mid(i+1);
|
||
14 years ago
|
i = path.findRev('.');
|
||
15 years ago
|
if (i >= 0)
|
||
|
path = path.left(i);
|
||
|
return path;
|
||
|
}
|
||
|
|
||
15 years ago
|
static bool startCondition(const TQString &condition)
|
||
15 years ago
|
{
|
||
|
if (condition.isEmpty())
|
||
|
return true;
|
||
|
|
||
15 years ago
|
TQStringList list = TQStringList::split(':', condition, true);
|
||
15 years ago
|
if (list.count() < 4)
|
||
|
return true;
|
||
|
if (list[0].isEmpty() || list[2].isEmpty())
|
||
|
return true;
|
||
|
|
||
12 years ago
|
TDEConfig config(list[0], true, false);
|
||
15 years ago
|
if (!list[1].isEmpty())
|
||
|
config.setGroup(list[1]);
|
||
|
|
||
|
bool defaultValue = (list[3].lower() == "true");
|
||
|
|
||
|
return config.readBoolEntry(list[2], defaultValue);
|
||
|
}
|
||
|
|
||
|
void
|
||
|
AutoStart::loadAutoStartList()
|
||
|
{
|
||
12 years ago
|
TQStringList files = TDEGlobal::dirs()->findAllResources("xdgconf-autostart", "*.desktop", false, true);
|
||
|
TQStringList kdefiles = TDEGlobal::dirs()->findAllResources("autostart", "*.desktop", false, true);
|
||
14 years ago
|
files += kdefiles;
|
||
15 years ago
|
|
||
15 years ago
|
for(TQStringList::ConstIterator it = files.begin();
|
||
15 years ago
|
it != files.end();
|
||
|
++it)
|
||
|
{
|
||
|
KDesktopFile config(*it, true);
|
||
14 years ago
|
if (config.hasKey("X-TDE-autostart-condition")) {
|
||
14 years ago
|
if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
|
||
|
continue;
|
||
|
}
|
||
|
else {
|
||
13 years ago
|
if (!startCondition(config.readEntry("X-TDE-autostart-condition")))
|
||
14 years ago
|
continue;
|
||
|
}
|
||
15 years ago
|
if (!config.tryExec())
|
||
|
continue;
|
||
|
if (config.readBoolEntry("Hidden", false))
|
||
|
continue;
|
||
|
|
||
13 years ago
|
// Check to see if the most important ( usually ~/.config/autostart or ~/.trinity/Autostart) XDG directory
|
||
14 years ago
|
// has overridden the Hidden directive and honor it if set to True
|
||
|
bool autostartOverriddenAndDisabled = false;
|
||
14 years ago
|
for(TQStringList::ConstIterator localit = files.begin();
|
||
|
localit != files.end();
|
||
14 years ago
|
++localit)
|
||
|
{
|
||
12 years ago
|
if (((*localit).startsWith(TDEGlobal::dirs()->localxdgconfdir()) == true) || ((*localit).startsWith(TDEGlobal::dirs()->localtdedir()) == true)) {
|
||
14 years ago
|
// Same local file name?
|
||
|
TQString localOuter;
|
||
|
TQString localInner;
|
||
14 years ago
|
int slashPos = (*it).findRev( '/', -1, TRUE );
|
||
14 years ago
|
if (slashPos == -1) {
|
||
|
localOuter = (*it);
|
||
|
}
|
||
|
else {
|
||
|
localOuter = (*it).mid(slashPos+1);
|
||
|
}
|
||
14 years ago
|
slashPos = (*localit).findRev( '/', -1, TRUE );
|
||
14 years ago
|
if (slashPos == -1) {
|
||
|
localInner = (*localit);
|
||
|
}
|
||
|
else {
|
||
|
localInner = (*localit).mid(slashPos+1);
|
||
|
}
|
||
|
if (localOuter == localInner) {
|
||
|
// Overridden!
|
||
|
// But is Hidden == True?
|
||
|
KDesktopFile innerConfig(*localit, true);
|
||
|
if (innerConfig.readBoolEntry("Hidden", false)) {
|
||
|
// Override confirmed; exit speedily without autostarting
|
||
|
autostartOverriddenAndDisabled = true;
|
||
|
}
|
||
14 years ago
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
if (autostartOverriddenAndDisabled == true)
|
||
|
continue;
|
||
|
|
||
15 years ago
|
if (config.hasKey("OnlyShowIn"))
|
||
|
{
|
||
12 years ago
|
#ifdef WITH_OLD_XDG_STD
|
||
14 years ago
|
if ((!config.readListEntry("OnlyShowIn", ';').contains("TDE")) && (!config.readListEntry("OnlyShowIn", ';').contains("KDE")))
|
||
15 years ago
|
continue;
|
||
12 years ago
|
#else
|
||
|
if (!config.readListEntry("OnlyShowIn", ';').contains("TDE"))
|
||
|
continue;
|
||
|
#endif
|
||
15 years ago
|
}
|
||
|
if (config.hasKey("NotShowIn"))
|
||
|
{
|
||
12 years ago
|
#ifdef WITH_OLD_XDG_STD
|
||
14 years ago
|
if ((config.readListEntry("NotShowIn", ';').contains("TDE")) || (config.readListEntry("NotShowIn", ';').contains("KDE")))
|
||
14 years ago
|
continue;
|
||
12 years ago
|
#else
|
||
|
if (config.readListEntry("NotShowIn", ';').contains("TDE"))
|
||
|
continue;
|
||
|
#endif
|
||
14 years ago
|
}
|
||
|
|
||
15 years ago
|
AutoStartItem *item = new AutoStartItem;
|
||
|
item->name = extractName(*it);
|
||
|
item->service = *it;
|
||
14 years ago
|
if (config.hasKey("X-TDE-autostart-after"))
|
||
14 years ago
|
item->startAfter = config.readEntry("X-TDE-autostart-after");
|
||
|
else
|
||
13 years ago
|
item->startAfter = config.readEntry("X-TDE-autostart-after");
|
||
15 years ago
|
if( m_newStartup )
|
||
|
{
|
||
14 years ago
|
if (config.hasKey("X-TDE-autostart-phase"))
|
||
14 years ago
|
item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
|
||
|
else
|
||
13 years ago
|
item->phase = config.readNumEntry("X-TDE-autostart-phase", 2);
|
||
15 years ago
|
if (item->phase < 0)
|
||
|
item->phase = 0;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
14 years ago
|
if (config.hasKey("X-TDE-autostart-phase"))
|
||
14 years ago
|
item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
|
||
|
else
|
||
13 years ago
|
item->phase = config.readNumEntry("X-TDE-autostart-phase", 1);
|
||
15 years ago
|
if (item->phase < 1)
|
||
|
item->phase = 1;
|
||
|
}
|
||
|
m_startList->append(item);
|
||
|
}
|
||
13 years ago
|
|
||
|
// Check for duplicate entries and remove if found
|
||
|
TQPtrListIterator<AutoStartItem> it1(*m_startList);
|
||
|
TQPtrListIterator<AutoStartItem> it2(*m_startList);
|
||
|
AutoStartItem *item1;
|
||
|
AutoStartItem *item2;
|
||
|
while ((item1 = it1.current()) != 0) {
|
||
|
bool dupfound1 = false;
|
||
|
it2.toFirst();
|
||
|
while ((item2 = it2.current()) != 0) {
|
||
|
bool dupfound2 = false;
|
||
|
if (item2 != item1) {
|
||
|
if (item1->service == item2->service) {
|
||
|
m_startList->removeRef(item2);
|
||
|
dupfound1 = true;
|
||
|
dupfound2 = true;
|
||
|
}
|
||
|
}
|
||
|
if (!dupfound2) {
|
||
|
++it2;
|
||
|
}
|
||
|
}
|
||
|
if (!dupfound1) {
|
||
|
++it1;
|
||
|
}
|
||
|
}
|
||
14 years ago
|
}
|
||
15 years ago
|
|
||
14 years ago
|
TQString
|
||
15 years ago
|
AutoStart::startService()
|
||
|
{
|
||
|
if (m_startList->isEmpty())
|
||
|
return 0;
|
||
|
|
||
|
while(!m_started.isEmpty())
|
||
|
{
|
||
|
|
||
|
// Check for items that depend on previously started items
|
||
15 years ago
|
TQString lastItem = m_started[0];
|
||
15 years ago
|
for(AutoStartItem *item = m_startList->first();
|
||
|
item; item = m_startList->next())
|
||
|
{
|
||
|
if (item->phase == m_phase
|
||
|
&& item->startAfter == lastItem)
|
||
|
{
|
||
|
m_started.prepend(item->name);
|
||
15 years ago
|
TQString service = item->service;
|
||
15 years ago
|
m_startList->remove();
|
||
|
return service;
|
||
|
}
|
||
|
}
|
||
|
m_started.remove(m_started.begin());
|
||
|
}
|
||
13 years ago
|
|
||
15 years ago
|
// Check for items that don't depend on anything
|
||
|
AutoStartItem *item;
|
||
|
for(item = m_startList->first();
|
||
|
item; item = m_startList->next())
|
||
|
{
|
||
|
if (item->phase == m_phase
|
||
|
&& item->startAfter.isEmpty())
|
||
|
{
|
||
|
m_started.prepend(item->name);
|
||
15 years ago
|
TQString service = item->service;
|
||
15 years ago
|
m_startList->remove();
|
||
|
return service;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Just start something in this phase
|
||
|
for(item = m_startList->first();
|
||
|
item; item = m_startList->next())
|
||
|
{
|
||
|
if (item->phase == m_phase)
|
||
|
{
|
||
|
m_started.prepend(item->name);
|
||
15 years ago
|
TQString service = item->service;
|
||
15 years ago
|
m_startList->remove();
|
||
|
return service;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return 0;
|
||
|
}
|