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.
1530 lines
45 KiB
1530 lines
45 KiB
15 years ago
|
/****************************************************************************
|
||
|
|
||
|
$Id$
|
||
|
|
||
|
Copyright (C) 2001-2003 Lubos Lunak <l.lunak@kde.org>
|
||
|
|
||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||
|
copy of this software and associated documentation files (the "Software"),
|
||
|
to deal in the Software without restriction, including without limitation
|
||
|
the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
||
|
and/or sell copies of the Software, and to permit persons to whom the
|
||
|
Software is furnished to do so, subject to the following conditions:
|
||
|
|
||
|
The above copyright notice and this permission notice shall be included in
|
||
|
all copies or substantial portions of the Software.
|
||
|
|
||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
||
|
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||
|
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
||
|
DEALINGS IN THE SOFTWARE.
|
||
|
|
||
|
****************************************************************************/
|
||
|
|
||
13 years ago
|
// kdDebug() can't be turned off in tdeinit
|
||
15 years ago
|
#if 0
|
||
|
#define KSTARTUPINFO_ALL_DEBUG
|
||
12 years ago
|
#warning Extra TDEStartupInfo debug messages enabled.
|
||
15 years ago
|
#endif
|
||
|
|
||
15 years ago
|
#include <tqwidget.h>
|
||
15 years ago
|
|
||
|
#include "config.h"
|
||
|
#ifdef Q_WS_X11
|
||
|
//#ifdef Q_WS_X11 // FIXME(E): Re-implement in a less X11 specific way
|
||
15 years ago
|
#include <tqglobal.h>
|
||
15 years ago
|
#ifdef HAVE_CONFIG_H
|
||
|
#include <config.h>
|
||
|
#endif
|
||
|
|
||
15 years ago
|
// need to resolve INT32(tqglobal.h)<>INT32(Xlibint.h) conflict
|
||
15 years ago
|
#ifndef QT_CLEAN_NAMESPACE
|
||
|
#define QT_CLEAN_NAMESPACE
|
||
|
#endif
|
||
|
|
||
12 years ago
|
#include "tdestartupinfo.h"
|
||
15 years ago
|
|
||
|
#include <unistd.h>
|
||
|
#include <sys/time.h>
|
||
|
#include <stdlib.h>
|
||
15 years ago
|
#include <tqtimer.h>
|
||
15 years ago
|
#ifdef Q_WS_X11
|
||
|
#include <netwm.h>
|
||
|
#endif
|
||
|
#include <kdebug.h>
|
||
12 years ago
|
#include <tdeapplication.h>
|
||
15 years ago
|
#include <signal.h>
|
||
|
#ifdef Q_WS_X11
|
||
13 years ago
|
#include <twinmodule.h>
|
||
15 years ago
|
#include <kxmessages.h>
|
||
13 years ago
|
#include <twin.h>
|
||
15 years ago
|
#endif
|
||
|
|
||
|
static const char* const NET_STARTUP_MSG = "_NET_STARTUP_INFO";
|
||
|
static const char* const NET_STARTUP_WINDOW = "_NET_STARTUP_ID";
|
||
|
// DESKTOP_STARTUP_ID is used also in kinit/wrapper.c ,
|
||
13 years ago
|
// tdesu in both tdelibs and tdebase and who knows where else
|
||
15 years ago
|
static const char* const NET_STARTUP_ENV = "DESKTOP_STARTUP_ID";
|
||
|
|
||
|
static bool auto_app_started_sending = true;
|
||
|
|
||
15 years ago
|
static long get_num( const TQString& item_P );
|
||
|
static unsigned long get_unum( const TQString& item_P );
|
||
|
static TQString get_str( const TQString& item_P );
|
||
|
static TQCString get_cstr( const TQString& item_P );
|
||
|
static TQStringList get_fields( const TQString& txt_P );
|
||
|
static TQString escape_str( const TQString& str_P );
|
||
15 years ago
|
|
||
|
static Atom utf8_string_atom = None;
|
||
|
|
||
12 years ago
|
class TDEStartupInfo::Data
|
||
|
: public TDEStartupInfoData
|
||
15 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
Data() : TDEStartupInfoData(), age(0) {} // just because it's in a QMap
|
||
15 years ago
|
Data( const TQString& txt_P )
|
||
12 years ago
|
: TDEStartupInfoData( txt_P ), age( 0 ) {}
|
||
15 years ago
|
unsigned int age;
|
||
|
};
|
||
|
|
||
12 years ago
|
struct TDEStartupInfoPrivate
|
||
15 years ago
|
{
|
||
|
public:
|
||
12 years ago
|
TQMap< TDEStartupInfoId, TDEStartupInfo::Data > startups;
|
||
14 years ago
|
// contains silenced ASN's only if !AnnounceSilencedChanges
|
||
12 years ago
|
TQMap< TDEStartupInfoId, TDEStartupInfo::Data > silent_startups;
|
||
14 years ago
|
// contains ASN's that had change: but no new: yet
|
||
12 years ago
|
TQMap< TDEStartupInfoId, TDEStartupInfo::Data > uninited_startups;
|
||
15 years ago
|
#ifdef Q_WS_X11
|
||
|
KWinModule* wm_module;
|
||
|
KXMessages msgs;
|
||
|
#endif
|
||
15 years ago
|
TQTimer* cleanup;
|
||
15 years ago
|
int flags;
|
||
12 years ago
|
TDEStartupInfoPrivate( int flags_P )
|
||
15 years ago
|
:
|
||
|
#ifdef Q_WS_X11
|
||
|
msgs( NET_STARTUP_MSG, NULL, false ),
|
||
|
#endif
|
||
|
flags( flags_P ) {}
|
||
|
};
|
||
|
|
||
12 years ago
|
TDEStartupInfo::TDEStartupInfo( int flags_P, TQObject* parent_P, const char* name_P )
|
||
15 years ago
|
: TQObject( parent_P, name_P ),
|
||
15 years ago
|
timeout( 60 ), d( NULL )
|
||
|
{
|
||
|
init( flags_P );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfo::TDEStartupInfo( bool clean_on_cantdetect_P, TQObject* parent_P, const char* name_P )
|
||
15 years ago
|
: TQObject( parent_P, name_P ),
|
||
15 years ago
|
timeout( 60 ), d( NULL )
|
||
|
{
|
||
|
init( clean_on_cantdetect_P ? CleanOnCantDetect : 0 );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::init( int flags_P )
|
||
15 years ago
|
{
|
||
|
// d == NULL means "disabled"
|
||
12 years ago
|
if( !TDEApplication::kApplication())
|
||
15 years ago
|
return;
|
||
12 years ago
|
if( !TDEApplication::kApplication()->getDisplay())
|
||
15 years ago
|
return;
|
||
|
|
||
12 years ago
|
d = new TDEStartupInfoPrivate( flags_P );
|
||
15 years ago
|
#ifdef Q_WS_X11
|
||
|
if( !( d->flags & DisableKWinModule ))
|
||
|
{
|
||
|
d->wm_module = new KWinModule( this );
|
||
15 years ago
|
connect( d->wm_module, TQT_SIGNAL( windowAdded( WId )), TQT_SLOT( slot_window_added( WId )));
|
||
|
connect( d->wm_module, TQT_SIGNAL( systemTrayWindowAdded( WId )), TQT_SLOT( slot_window_added( WId )));
|
||
15 years ago
|
}
|
||
|
else
|
||
|
d->wm_module = NULL;
|
||
15 years ago
|
connect( &d->msgs, TQT_SIGNAL( gotMessage( const TQString& )), TQT_SLOT( got_message( const TQString& )));
|
||
15 years ago
|
#endif
|
||
15 years ago
|
d->cleanup = new TQTimer( this, "cleanup" );
|
||
|
connect( d->cleanup, TQT_SIGNAL( timeout()), TQT_SLOT( startups_cleanup()));
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfo::~TDEStartupInfo()
|
||
15 years ago
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::got_message( const TQString& msg_P )
|
||
15 years ago
|
{
|
||
|
// TODO do something with SCREEN= ?
|
||
|
kdDebug( 172 ) << "got:" << msg_P << endl;
|
||
15 years ago
|
TQString msg = msg_P.stripWhiteSpace();
|
||
15 years ago
|
if( msg.startsWith( "new:" )) // must match length below
|
||
|
got_startup_info( msg.mid( 4 ), false );
|
||
|
else if( msg.startsWith( "change:" )) // must match length below
|
||
|
got_startup_info( msg.mid( 7 ), true );
|
||
|
else if( msg.startsWith( "remove:" )) // must match length below
|
||
|
got_remove_startup_info( msg.mid( 7 ));
|
||
|
}
|
||
|
|
||
|
// if the application stops responding for a while, KWinModule may get
|
||
|
// the information about the already mapped window before KXMessages
|
||
|
// actually gets the info about the started application (depends
|
||
12 years ago
|
// on their order in X11 event filter in TDEApplication)
|
||
15 years ago
|
// simply delay info from KWinModule a bit
|
||
|
// SELI???
|
||
|
namespace
|
||
|
{
|
||
|
class DelayedWindowEvent
|
||
14 years ago
|
: public TQCustomEvent
|
||
15 years ago
|
{
|
||
|
public:
|
||
|
DelayedWindowEvent( WId w_P )
|
||
15 years ago
|
: TQCustomEvent( TQEvent::User + 15 ), w( w_P ) {}
|
||
15 years ago
|
Window w;
|
||
|
};
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::slot_window_added( WId w_P )
|
||
15 years ago
|
{
|
||
|
kapp->postEvent( this, new DelayedWindowEvent( w_P ));
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::customEvent( TQCustomEvent* e_P )
|
||
15 years ago
|
{
|
||
15 years ago
|
if( e_P->type() == TQEvent::User + 15 )
|
||
15 years ago
|
window_added( static_cast< DelayedWindowEvent* >( e_P )->w );
|
||
|
else
|
||
15 years ago
|
TQObject::customEvent( e_P );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::window_added( WId w_P )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
|
TDEStartupInfoData data;
|
||
15 years ago
|
startup_t ret = check_startup_internal( w_P, &id, &data );
|
||
|
switch( ret )
|
||
|
{
|
||
|
case Match:
|
||
|
kdDebug( 172 ) << "new window match" << endl;
|
||
|
break;
|
||
|
case NoMatch:
|
||
|
break; // nothing
|
||
|
case CantDetect:
|
||
|
if( d->flags & CleanOnCantDetect )
|
||
|
clean_all_noncompliant();
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::got_startup_info( const TQString& msg_P, bool update_P )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEStartupInfoId id( msg_P );
|
||
15 years ago
|
if( id.none())
|
||
|
return;
|
||
12 years ago
|
TDEStartupInfo::Data data( msg_P );
|
||
15 years ago
|
new_startup_info_internal( id, data, update_P );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::new_startup_info_internal( const TDEStartupInfoId& id_P,
|
||
15 years ago
|
Data& data_P, bool update_P )
|
||
|
{
|
||
|
if( d == NULL )
|
||
|
return;
|
||
|
if( id_P.none())
|
||
|
return;
|
||
13 years ago
|
if( d->startups.contains( id_P ))
|
||
15 years ago
|
{ // already reported, update
|
||
|
d->startups[ id_P ].update( data_P );
|
||
|
d->startups[ id_P ].age = 0; // CHECKME
|
||
|
kdDebug( 172 ) << "updating" << endl;
|
||
|
if( d->startups[ id_P ].silent() == Data::Yes
|
||
|
&& !( d->flags & AnnounceSilenceChanges ))
|
||
|
{
|
||
|
d->silent_startups[ id_P ] = d->startups[ id_P ];
|
||
|
d->startups.remove( id_P );
|
||
|
emit gotRemoveStartup( id_P, d->silent_startups[ id_P ] );
|
||
|
return;
|
||
|
}
|
||
|
emit gotStartupChange( id_P, d->startups[ id_P ] );
|
||
|
return;
|
||
|
}
|
||
13 years ago
|
if( d->silent_startups.contains( id_P ))
|
||
15 years ago
|
{ // already reported, update
|
||
|
d->silent_startups[ id_P ].update( data_P );
|
||
|
d->silent_startups[ id_P ].age = 0; // CHECKME
|
||
|
kdDebug( 172 ) << "updating silenced" << endl;
|
||
|
if( d->silent_startups[ id_P ].silent() != Data::Yes )
|
||
|
{
|
||
|
d->startups[ id_P ] = d->silent_startups[ id_P ];
|
||
|
d->silent_startups.remove( id_P );
|
||
|
emit gotNewStartup( id_P, d->startups[ id_P ] );
|
||
|
return;
|
||
|
}
|
||
|
emit gotStartupChange( id_P, d->silent_startups[ id_P ] );
|
||
|
return;
|
||
|
}
|
||
13 years ago
|
if( d->uninited_startups.contains( id_P ))
|
||
15 years ago
|
{
|
||
|
d->uninited_startups[ id_P ].update( data_P );
|
||
|
kdDebug( 172 ) << "updating uninited" << endl;
|
||
|
if( !update_P ) // uninited finally got new:
|
||
|
{
|
||
|
d->startups[ id_P ] = d->uninited_startups[ id_P ];
|
||
|
d->uninited_startups.remove( id_P );
|
||
|
emit gotNewStartup( id_P, d->startups[ id_P ] );
|
||
|
return;
|
||
|
}
|
||
|
// no change announce, it's still uninited
|
||
|
return;
|
||
|
}
|
||
|
if( update_P ) // change: without any new: first
|
||
|
{
|
||
|
kdDebug( 172 ) << "adding uninited" << endl;
|
||
|
d->uninited_startups.insert( id_P, data_P );
|
||
|
}
|
||
|
else if( data_P.silent() != Data::Yes || d->flags & AnnounceSilenceChanges )
|
||
|
{
|
||
|
kdDebug( 172 ) << "adding" << endl;
|
||
|
d->startups.insert( id_P, data_P );
|
||
|
emit gotNewStartup( id_P, data_P );
|
||
|
}
|
||
|
else // new silenced, and silent shouldn't be announced
|
||
|
{
|
||
|
kdDebug( 172 ) << "adding silent" << endl;
|
||
|
d->silent_startups.insert( id_P, data_P );
|
||
|
}
|
||
|
d->cleanup->start( 1000 ); // 1 sec
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::got_remove_startup_info( const TQString& msg_P )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEStartupInfoId id( msg_P );
|
||
|
TDEStartupInfoData data( msg_P );
|
||
15 years ago
|
if( data.pids().count() > 0 )
|
||
|
{
|
||
|
if( !id.none())
|
||
|
remove_startup_pids( id, data );
|
||
|
else
|
||
|
remove_startup_pids( data );
|
||
|
return;
|
||
|
}
|
||
|
remove_startup_info_internal( id );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::remove_startup_info_internal( const TDEStartupInfoId& id_P )
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return;
|
||
13 years ago
|
if( d->startups.contains( id_P ))
|
||
15 years ago
|
{
|
||
|
kdDebug( 172 ) << "removing" << endl;
|
||
|
emit gotRemoveStartup( id_P, d->startups[ id_P ]);
|
||
|
d->startups.remove( id_P );
|
||
|
}
|
||
13 years ago
|
else if( d->silent_startups.contains( id_P ))
|
||
15 years ago
|
{
|
||
|
kdDebug( 172 ) << "removing silent" << endl;
|
||
|
d->silent_startups.remove( id_P );
|
||
|
}
|
||
13 years ago
|
else if( d->uninited_startups.contains( id_P ))
|
||
15 years ago
|
{
|
||
|
kdDebug( 172 ) << "removing uninited" << endl;
|
||
|
d->uninited_startups.remove( id_P );
|
||
|
}
|
||
|
return;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::remove_startup_pids( const TDEStartupInfoData& data_P )
|
||
14 years ago
|
{ // first find the matching info
|
||
15 years ago
|
if( d == NULL )
|
||
|
return;
|
||
12 years ago
|
for( TQMap< TDEStartupInfoId, Data >::Iterator it = d->startups.begin();
|
||
15 years ago
|
it != d->startups.end();
|
||
|
++it )
|
||
|
{
|
||
|
if( ( *it ).hostname() != data_P.hostname())
|
||
|
continue;
|
||
|
if( !( *it ).is_pid( data_P.pids().first()))
|
||
|
continue; // not the matching info
|
||
|
remove_startup_pids( it.key(), data_P );
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::remove_startup_pids( const TDEStartupInfoId& id_P,
|
||
|
const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return;
|
||
|
kdFatal( data_P.pids().count() == 0, 172 );
|
||
|
Data* data = NULL;
|
||
13 years ago
|
if( d->startups.contains( id_P ))
|
||
15 years ago
|
data = &d->startups[ id_P ];
|
||
13 years ago
|
else if( d->silent_startups.contains( id_P ))
|
||
15 years ago
|
data = &d->silent_startups[ id_P ];
|
||
13 years ago
|
else if( d->uninited_startups.contains( id_P ))
|
||
15 years ago
|
data = &d->uninited_startups[ id_P ];
|
||
|
else
|
||
|
return;
|
||
15 years ago
|
for( TQValueList< pid_t >::ConstIterator it2 = data_P.pids().begin();
|
||
15 years ago
|
it2 != data_P.pids().end();
|
||
|
++it2 )
|
||
|
data->remove_pid( *it2 ); // remove all pids from the info
|
||
|
if( data->pids().count() == 0 ) // all pids removed -> remove info
|
||
|
remove_startup_info_internal( id_P );
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendStartup( const TDEStartupInfoId& id_P, const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
if( id_P.none())
|
||
|
return false;
|
||
|
KXMessages msgs;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "new: %1 %2" )
|
||
15 years ago
|
.arg( id_P.to_text()).arg( data_P.to_text());
|
||
13 years ago
|
msg = check_required_startup_fields( msg, data_P, tqt_xscreen());
|
||
15 years ago
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
msgs.broadcastMessage( NET_STARTUP_MSG, msg, -1, false );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendStartupX( Display* disp_P, const TDEStartupInfoId& id_P,
|
||
|
const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
if( id_P.none())
|
||
|
return false;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "new: %1 %2" )
|
||
15 years ago
|
.arg( id_P.to_text()).arg( data_P.to_text());
|
||
|
msg = check_required_startup_fields( msg, data_P, DefaultScreen( disp_P ));
|
||
|
#ifdef KSTARTUPINFO_ALL_DEBUG
|
||
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
#endif
|
||
|
return KXMessages::broadcastMessageX( disp_P, NET_STARTUP_MSG, msg, -1, false );
|
||
|
}
|
||
|
|
||
12 years ago
|
TQString TDEStartupInfo::check_required_startup_fields( const TQString& msg, const TDEStartupInfoData& data_P,
|
||
15 years ago
|
int screen )
|
||
|
{
|
||
15 years ago
|
TQString ret = msg;
|
||
15 years ago
|
if( data_P.name().isEmpty())
|
||
|
{
|
||
|
// kdWarning( 172 ) << "NAME not specified in initial startup message" << endl;
|
||
15 years ago
|
TQString name = data_P.bin();
|
||
15 years ago
|
if( name.isEmpty())
|
||
|
name = "UNKNOWN";
|
||
15 years ago
|
ret += TQString( " NAME=\"%1\"" ).arg( escape_str( name ));
|
||
15 years ago
|
}
|
||
|
if( data_P.screen() == -1 ) // add automatically if needed
|
||
15 years ago
|
ret += TQString( " SCREEN=%1" ).arg( screen );
|
||
15 years ago
|
return ret;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendChange( const TDEStartupInfoId& id_P, const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
if( id_P.none())
|
||
|
return false;
|
||
|
KXMessages msgs;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "change: %1 %2" )
|
||
15 years ago
|
.arg( id_P.to_text()).arg( data_P.to_text());
|
||
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
msgs.broadcastMessage( NET_STARTUP_MSG, msg, -1, false );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendChangeX( Display* disp_P, const TDEStartupInfoId& id_P,
|
||
|
const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
if( id_P.none())
|
||
|
return false;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "change: %1 %2" )
|
||
15 years ago
|
.arg( id_P.to_text()).arg( data_P.to_text());
|
||
|
#ifdef KSTARTUPINFO_ALL_DEBUG
|
||
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
#endif
|
||
|
return KXMessages::broadcastMessageX( disp_P, NET_STARTUP_MSG, msg, -1, false );
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendFinish( const TDEStartupInfoId& id_P )
|
||
15 years ago
|
{
|
||
|
if( id_P.none())
|
||
|
return false;
|
||
|
KXMessages msgs;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "remove: %1" ).arg( id_P.to_text());
|
||
15 years ago
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
msgs.broadcastMessage( NET_STARTUP_MSG, msg, -1, false );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendFinishX( Display* disp_P, const TDEStartupInfoId& id_P )
|
||
15 years ago
|
{
|
||
|
if( id_P.none())
|
||
|
return false;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "remove: %1" ).arg( id_P.to_text());
|
||
15 years ago
|
#ifdef KSTARTUPINFO_ALL_DEBUG
|
||
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
#endif
|
||
|
return KXMessages::broadcastMessageX( disp_P, NET_STARTUP_MSG, msg, -1, false );
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendFinish( const TDEStartupInfoId& id_P, const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
// if( id_P.none()) // id may be none, the pids and hostname matter then
|
||
|
// return false;
|
||
|
KXMessages msgs;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "remove: %1 %2" )
|
||
15 years ago
|
.arg( id_P.to_text()).arg( data_P.to_text());
|
||
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
msgs.broadcastMessage( NET_STARTUP_MSG, msg, -1, false );
|
||
|
return true;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::sendFinishX( Display* disp_P, const TDEStartupInfoId& id_P,
|
||
|
const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
// if( id_P.none()) // id may be none, the pids and hostname matter then
|
||
|
// return false;
|
||
13 years ago
|
TQString msg = TQString::fromLatin1( "remove: %1 %2" )
|
||
15 years ago
|
.arg( id_P.to_text()).arg( data_P.to_text());
|
||
|
#ifdef KSTARTUPINFO_ALL_DEBUG
|
||
|
kdDebug( 172 ) << "sending " << msg << endl;
|
||
|
#endif
|
||
|
return KXMessages::broadcastMessageX( disp_P, NET_STARTUP_MSG, msg, -1, false );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::appStarted()
|
||
15 years ago
|
{
|
||
12 years ago
|
if( kapp != NULL ) // TDEApplication constructor unsets the env. variable
|
||
15 years ago
|
appStarted( kapp->startupId());
|
||
|
else
|
||
12 years ago
|
appStarted( TDEStartupInfo::currentStartupIdEnv().id());
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::appStarted( const TQCString& startup_id )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
15 years ago
|
id.initId( startup_id );
|
||
|
if( id.none())
|
||
|
return;
|
||
|
if( kapp != NULL )
|
||
12 years ago
|
TDEStartupInfo::sendFinish( id );
|
||
13 years ago
|
else if( getenv( "DISPLAY" ) != NULL ) // don't rely on tqt_xdisplay()
|
||
15 years ago
|
{
|
||
|
#ifdef Q_WS_X11
|
||
|
Display* disp = XOpenDisplay( NULL );
|
||
|
if( disp != NULL )
|
||
|
{
|
||
12 years ago
|
TDEStartupInfo::sendFinishX( disp, id );
|
||
15 years ago
|
XCloseDisplay( disp );
|
||
|
}
|
||
|
#endif
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::disableAutoAppStartedSending( bool disable )
|
||
15 years ago
|
{
|
||
|
auto_app_started_sending = !disable;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::silenceStartup( bool silence )
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
15 years ago
|
id.initId( kapp->startupId());
|
||
|
if( id.none())
|
||
|
return;
|
||
12 years ago
|
TDEStartupInfoData data;
|
||
|
data.setSilent( silence ? TDEStartupInfoData::Yes : TDEStartupInfoData::No );
|
||
15 years ago
|
sendChange( id, data );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::handleAutoAppStartedSending()
|
||
15 years ago
|
{
|
||
|
if( auto_app_started_sending )
|
||
|
appStarted();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::setNewStartupId( TQWidget* window, const TQCString& startup_id )
|
||
15 years ago
|
{
|
||
|
bool activate = true;
|
||
|
kapp->setStartupId( startup_id );
|
||
|
if( window != NULL )
|
||
|
{
|
||
|
if( !startup_id.isEmpty() && startup_id != "0" )
|
||
|
{
|
||
13 years ago
|
NETRootInfo i( tqt_xdisplay(), NET::Supported );
|
||
15 years ago
|
if( i.isSupported( NET::WM2StartupId ))
|
||
|
{
|
||
12 years ago
|
TDEStartupInfo::setWindowStartupId( window->winId(), startup_id );
|
||
15 years ago
|
activate = false; // WM will take care of it
|
||
|
}
|
||
|
}
|
||
|
if( activate )
|
||
|
{
|
||
|
KWin::setOnDesktop( window->winId(), KWin::currentDesktop());
|
||
|
// This is not very nice, but there's no way how to get any
|
||
|
// usable timestamp without ASN, so force activating the window.
|
||
|
// And even with ASN, it's not possible to get the timestamp here,
|
||
|
// so if the WM doesn't have support for ASN, it can't be used either.
|
||
|
KWin::forceActiveWindow( window->winId());
|
||
|
}
|
||
|
}
|
||
12 years ago
|
TDEStartupInfo::handleAutoAppStartedSending();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfo::startup_t TDEStartupInfo::checkStartup( WId w_P, TDEStartupInfoId& id_O,
|
||
|
TDEStartupInfoData& data_O )
|
||
15 years ago
|
{
|
||
|
return check_startup_internal( w_P, &id_O, &data_O );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfo::startup_t TDEStartupInfo::checkStartup( WId w_P, TDEStartupInfoId& id_O )
|
||
15 years ago
|
{
|
||
|
return check_startup_internal( w_P, &id_O, NULL );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfo::startup_t TDEStartupInfo::checkStartup( WId w_P, TDEStartupInfoData& data_O )
|
||
15 years ago
|
{
|
||
|
return check_startup_internal( w_P, NULL, &data_O );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfo::startup_t TDEStartupInfo::checkStartup( WId w_P )
|
||
15 years ago
|
{
|
||
|
return check_startup_internal( w_P, NULL, NULL );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfo::startup_t TDEStartupInfo::check_startup_internal( WId w_P, TDEStartupInfoId* id_O,
|
||
|
TDEStartupInfoData* data_O )
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return NoMatch;
|
||
|
if( d->startups.count() == 0 )
|
||
|
return NoMatch; // no startups
|
||
|
// Strategy:
|
||
|
//
|
||
|
// Is this a compliant app ?
|
||
|
// - Yes - test for match
|
||
|
// - No - Is this a NET_WM compliant app ?
|
||
|
// - Yes - test for pid match
|
||
|
// - No - test for WM_CLASS match
|
||
|
kdDebug( 172 ) << "check_startup" << endl;
|
||
15 years ago
|
TQCString id = windowStartupId( w_P );
|
||
15 years ago
|
if( !id.isNull())
|
||
|
{
|
||
|
if( id.isEmpty() || id == "0" ) // means ignore this window
|
||
|
{
|
||
|
kdDebug( 172 ) << "ignore" << endl;
|
||
|
return NoMatch;
|
||
|
}
|
||
14 years ago
|
return find_id( id, id_O, data_O ) ? Match : NoMatch;
|
||
15 years ago
|
}
|
||
|
#ifdef Q_WS_X11
|
||
13 years ago
|
NETWinInfo info( tqt_xdisplay(), w_P, tqt_xrootwin(),
|
||
15 years ago
|
NET::WMWindowType | NET::WMPid | NET::WMState );
|
||
|
pid_t pid = info.pid();
|
||
|
if( pid > 0 )
|
||
|
{
|
||
15 years ago
|
TQCString hostname = get_window_hostname( w_P );
|
||
15 years ago
|
if( !hostname.isEmpty()
|
||
14 years ago
|
&& find_pid( pid, hostname, id_O, data_O ))
|
||
15 years ago
|
return Match;
|
||
|
// try XClass matching , this PID stuff sucks :(
|
||
|
}
|
||
|
XClassHint hint;
|
||
13 years ago
|
if( XGetClassHint( tqt_xdisplay(), w_P, &hint ) != 0 )
|
||
15 years ago
|
{ // We managed to read the class hint
|
||
15 years ago
|
TQCString res_name = hint.res_name;
|
||
|
TQCString res_class = hint.res_class;
|
||
15 years ago
|
XFree( hint.res_name );
|
||
|
XFree( hint.res_class );
|
||
14 years ago
|
if( find_wclass( res_name, res_class, id_O, data_O ))
|
||
15 years ago
|
return Match;
|
||
|
}
|
||
|
// ignore NET::Tool and other special window types, if they can't be matched
|
||
|
NET::WindowType type = info.windowType( NET::NormalMask | NET::DesktopMask
|
||
|
| NET::DockMask | NET::ToolbarMask | NET::MenuMask | NET::DialogMask
|
||
|
| NET::OverrideMask | NET::TopMenuMask | NET::UtilityMask | NET::SplashMask );
|
||
|
if( type != NET::Normal
|
||
|
&& type != NET::Override
|
||
|
&& type != NET::Unknown
|
||
|
&& type != NET::Dialog
|
||
|
&& type != NET::Utility )
|
||
|
// && type != NET::Dock ) why did I put this here?
|
||
|
return NoMatch;
|
||
|
// lets see if this is a transient
|
||
|
Window transient_for;
|
||
13 years ago
|
if( XGetTransientForHint( tqt_xdisplay(), static_cast< Window >( w_P ), &transient_for )
|
||
|
&& static_cast< WId >( transient_for ) != tqt_xrootwin()
|
||
15 years ago
|
&& transient_for != None )
|
||
|
return NoMatch;
|
||
|
#endif
|
||
|
kdDebug( 172 ) << "check_startup:cantdetect" << endl;
|
||
|
return CantDetect;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::find_id( const TQCString& id_P, TDEStartupInfoId* id_O,
|
||
|
TDEStartupInfoData* data_O )
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return false;
|
||
14 years ago
|
kdDebug( 172 ) << "find_id:" << id_P << endl;
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
15 years ago
|
id.initId( id_P );
|
||
13 years ago
|
if( d->startups.contains( id ))
|
||
15 years ago
|
{
|
||
|
if( id_O != NULL )
|
||
|
*id_O = id;
|
||
|
if( data_O != NULL )
|
||
|
*data_O = d->startups[ id ];
|
||
|
kdDebug( 172 ) << "check_startup_id:match" << endl;
|
||
|
return true;
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::find_pid( pid_t pid_P, const TQCString& hostname_P,
|
||
|
TDEStartupInfoId* id_O, TDEStartupInfoData* data_O )
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return false;
|
||
14 years ago
|
kdDebug( 172 ) << "find_pid:" << pid_P << endl;
|
||
12 years ago
|
for( TQMap< TDEStartupInfoId, Data >::Iterator it = d->startups.begin();
|
||
15 years ago
|
it != d->startups.end();
|
||
|
++it )
|
||
|
{
|
||
|
if( ( *it ).is_pid( pid_P ) && ( *it ).hostname() == hostname_P )
|
||
|
{ // Found it !
|
||
|
if( id_O != NULL )
|
||
|
*id_O = it.key();
|
||
|
if( data_O != NULL )
|
||
|
*data_O = *it;
|
||
|
// non-compliant, remove on first match
|
||
|
remove_startup_info_internal( it.key());
|
||
|
kdDebug( 172 ) << "check_startup_pid:match" << endl;
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfo::find_wclass( TQCString res_name, TQCString res_class,
|
||
|
TDEStartupInfoId* id_O, TDEStartupInfoData* data_O )
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return false;
|
||
|
res_name = res_name.lower();
|
||
|
res_class = res_class.lower();
|
||
14 years ago
|
kdDebug( 172 ) << "find_wclass:" << res_name << ":" << res_class << endl;
|
||
12 years ago
|
for( TQMap< TDEStartupInfoId, Data >::Iterator it = d->startups.begin();
|
||
15 years ago
|
it != d->startups.end();
|
||
|
++it )
|
||
|
{
|
||
14 years ago
|
const TQCString wmclass = ( *it ).findWMClass();
|
||
15 years ago
|
if( wmclass.lower() == res_name || wmclass.lower() == res_class )
|
||
|
{ // Found it !
|
||
|
if( id_O != NULL )
|
||
|
*id_O = it.key();
|
||
|
if( data_O != NULL )
|
||
|
*data_O = *it;
|
||
|
// non-compliant, remove on first match
|
||
|
remove_startup_info_internal( it.key());
|
||
|
kdDebug( 172 ) << "check_startup_wclass:match" << endl;
|
||
|
return true;
|
||
|
}
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
#ifdef Q_WS_X11
|
||
|
static Atom net_startup_atom = None;
|
||
|
|
||
15 years ago
|
static TQCString read_startup_id_property( WId w_P )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQCString ret;
|
||
15 years ago
|
unsigned char *name_ret;
|
||
|
Atom type_ret;
|
||
|
int format_ret;
|
||
|
unsigned long nitems_ret = 0, after_ret = 0;
|
||
13 years ago
|
if( XGetWindowProperty( tqt_xdisplay(), w_P, net_startup_atom, 0l, 4096,
|
||
15 years ago
|
False, utf8_string_atom, &type_ret, &format_ret, &nitems_ret, &after_ret, &name_ret )
|
||
|
== Success )
|
||
|
{
|
||
|
if( type_ret == utf8_string_atom && format_ret == 8 && name_ret != NULL )
|
||
|
ret = reinterpret_cast< char* >( name_ret );
|
||
|
if ( name_ret != NULL )
|
||
|
XFree( name_ret );
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
|
#endif
|
||
|
|
||
12 years ago
|
TQCString TDEStartupInfo::windowStartupId( WId w_P )
|
||
15 years ago
|
{
|
||
|
#ifdef Q_WS_X11
|
||
|
if( net_startup_atom == None )
|
||
13 years ago
|
net_startup_atom = XInternAtom( tqt_xdisplay(), NET_STARTUP_WINDOW, False );
|
||
15 years ago
|
if( utf8_string_atom == None )
|
||
13 years ago
|
utf8_string_atom = XInternAtom( tqt_xdisplay(), "UTF8_STRING", False );
|
||
15 years ago
|
TQCString ret = read_startup_id_property( w_P );
|
||
15 years ago
|
if( ret.isEmpty())
|
||
|
{ // retry with window group leader, as the spec says
|
||
13 years ago
|
XWMHints* hints = XGetWMHints( tqt_xdisplay(), w_P );
|
||
15 years ago
|
if( hints && ( hints->flags & WindowGroupHint ) != 0 )
|
||
|
ret = read_startup_id_property( hints->window_group );
|
||
|
if( hints )
|
||
|
XFree( hints );
|
||
|
}
|
||
|
return ret;
|
||
|
#else
|
||
15 years ago
|
return TQCString();
|
||
15 years ago
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::setWindowStartupId( WId w_P, const TQCString& id_P )
|
||
15 years ago
|
{
|
||
|
#ifdef Q_WS_X11
|
||
|
if( id_P.isNull())
|
||
|
return;
|
||
|
if( net_startup_atom == None )
|
||
13 years ago
|
net_startup_atom = XInternAtom( tqt_xdisplay(), NET_STARTUP_WINDOW, False );
|
||
15 years ago
|
if( utf8_string_atom == None )
|
||
13 years ago
|
utf8_string_atom = XInternAtom( tqt_xdisplay(), "UTF8_STRING", False );
|
||
|
XChangeProperty( tqt_xdisplay(), w_P, net_startup_atom, utf8_string_atom, 8,
|
||
14 years ago
|
PropModeReplace, reinterpret_cast< unsigned char* >( const_cast<TQCString&>(id_P).data()), id_P.length());
|
||
15 years ago
|
#endif
|
||
|
}
|
||
|
|
||
12 years ago
|
TQCString TDEStartupInfo::get_window_hostname( WId w_P )
|
||
15 years ago
|
{
|
||
|
#ifdef Q_WS_X11
|
||
|
XTextProperty tp;
|
||
|
char** hh;
|
||
|
int cnt;
|
||
13 years ago
|
if( XGetWMClientMachine( tqt_xdisplay(), w_P, &tp ) != 0
|
||
15 years ago
|
&& XTextPropertyToStringList( &tp, &hh, &cnt ) != 0 )
|
||
|
{
|
||
|
if( cnt == 1 )
|
||
|
{
|
||
15 years ago
|
TQCString hostname = hh[ 0 ];
|
||
15 years ago
|
XFreeStringList( hh );
|
||
|
return hostname;
|
||
|
}
|
||
|
XFreeStringList( hh );
|
||
|
}
|
||
|
#endif
|
||
|
// no hostname
|
||
15 years ago
|
return TQCString();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::setTimeout( unsigned int secs_P )
|
||
15 years ago
|
{
|
||
|
timeout = secs_P;
|
||
|
// schedule removing entries that are older than the new timeout
|
||
15 years ago
|
TQTimer::singleShot( 0, this, TQT_SLOT( startups_cleanup_no_age()));
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::startups_cleanup_no_age()
|
||
15 years ago
|
{
|
||
|
startups_cleanup_internal( false );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::startups_cleanup()
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return;
|
||
|
if( d->startups.count() == 0 && d->silent_startups.count() == 0
|
||
|
&& d->uninited_startups.count() == 0 )
|
||
|
{
|
||
|
d->cleanup->stop();
|
||
|
return;
|
||
|
}
|
||
|
startups_cleanup_internal( true );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::startups_cleanup_internal( bool age_P )
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return;
|
||
12 years ago
|
for( TQMap< TDEStartupInfoId, Data >::Iterator it = d->startups.begin();
|
||
15 years ago
|
it != d->startups.end();
|
||
|
)
|
||
|
{
|
||
|
if( age_P )
|
||
|
( *it ).age++;
|
||
|
unsigned int tout = timeout;
|
||
|
if( ( *it ).silent() == Data::Yes ) // TODO
|
||
|
tout *= 20;
|
||
|
if( ( *it ).age >= tout )
|
||
|
{
|
||
12 years ago
|
const TDEStartupInfoId& key = it.key();
|
||
15 years ago
|
++it;
|
||
|
kdDebug( 172 ) << "startups entry timeout:" << key.id() << endl;
|
||
|
remove_startup_info_internal( key );
|
||
|
}
|
||
|
else
|
||
|
++it;
|
||
|
}
|
||
12 years ago
|
for( TQMap< TDEStartupInfoId, Data >::Iterator it = d->silent_startups.begin();
|
||
15 years ago
|
it != d->silent_startups.end();
|
||
|
)
|
||
|
{
|
||
|
if( age_P )
|
||
|
( *it ).age++;
|
||
|
unsigned int tout = timeout;
|
||
|
if( ( *it ).silent() == Data::Yes ) // TODO
|
||
|
tout *= 20;
|
||
|
if( ( *it ).age >= tout )
|
||
|
{
|
||
12 years ago
|
const TDEStartupInfoId& key = it.key();
|
||
15 years ago
|
++it;
|
||
|
kdDebug( 172 ) << "silent entry timeout:" << key.id() << endl;
|
||
|
remove_startup_info_internal( key );
|
||
|
}
|
||
|
else
|
||
|
++it;
|
||
|
}
|
||
12 years ago
|
for( TQMap< TDEStartupInfoId, Data >::Iterator it = d->uninited_startups.begin();
|
||
15 years ago
|
it != d->uninited_startups.end();
|
||
|
)
|
||
|
{
|
||
|
if( age_P )
|
||
|
( *it ).age++;
|
||
|
unsigned int tout = timeout;
|
||
|
if( ( *it ).silent() == Data::Yes ) // TODO
|
||
|
tout *= 20;
|
||
|
if( ( *it ).age >= tout )
|
||
|
{
|
||
12 years ago
|
const TDEStartupInfoId& key = it.key();
|
||
15 years ago
|
++it;
|
||
|
kdDebug( 172 ) << "uninited entry timeout:" << key.id() << endl;
|
||
|
remove_startup_info_internal( key );
|
||
|
}
|
||
|
else
|
||
|
++it;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::clean_all_noncompliant()
|
||
15 years ago
|
{
|
||
|
if( d == NULL )
|
||
|
return;
|
||
12 years ago
|
for( TQMap< TDEStartupInfoId, Data >::Iterator it = d->startups.begin();
|
||
15 years ago
|
it != d->startups.end();
|
||
|
)
|
||
|
{
|
||
|
if( ( *it ).WMClass() != "0" )
|
||
|
{
|
||
|
++it;
|
||
|
continue;
|
||
|
}
|
||
12 years ago
|
const TDEStartupInfoId& key = it.key();
|
||
15 years ago
|
++it;
|
||
|
kdDebug( 172 ) << "entry cleaning:" << key.id() << endl;
|
||
|
remove_startup_info_internal( key );
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
TQCString TDEStartupInfo::createNewStartupId()
|
||
15 years ago
|
{
|
||
|
// Assign a unique id, use hostname+time+pid, that should be 200% unique.
|
||
|
// Also append the user timestamp (for focus stealing prevention).
|
||
|
struct timeval tm;
|
||
|
gettimeofday( &tm, NULL );
|
||
|
char hostname[ 256 ];
|
||
|
hostname[ 0 ] = '\0';
|
||
|
if (!gethostname( hostname, 255 ))
|
||
|
hostname[sizeof(hostname)-1] = '\0';
|
||
14 years ago
|
TQCString id = TQString(TQString( "%1;%2;%3;%4_TIME%5" ).arg( hostname ).arg( tm.tv_sec )
|
||
14 years ago
|
.arg( tm.tv_usec ).arg( getpid()).arg( GET_QT_X_USER_TIME() )).utf8();
|
||
14 years ago
|
kdDebug( 172 ) << "creating: " << id << ":" << tqAppName() << endl;
|
||
15 years ago
|
return id;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
struct TDEStartupInfoIdPrivate
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEStartupInfoIdPrivate() : id( "" ) {}
|
||
15 years ago
|
TQCString id; // id
|
||
15 years ago
|
};
|
||
|
|
||
12 years ago
|
const TQCString& TDEStartupInfoId::id() const
|
||
15 years ago
|
{
|
||
|
return d->id;
|
||
|
}
|
||
|
|
||
|
|
||
12 years ago
|
TQString TDEStartupInfoId::to_text() const
|
||
15 years ago
|
{
|
||
13 years ago
|
return TQString::fromLatin1( " ID=\"%1\" " ).arg( escape_str( id()));
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoId::TDEStartupInfoId( const TQString& txt_P )
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDEStartupInfoIdPrivate;
|
||
15 years ago
|
TQStringList items = get_fields( txt_P );
|
||
13 years ago
|
const TQString id_str = TQString::fromLatin1( "ID=" );
|
||
15 years ago
|
for( TQStringList::Iterator it = items.begin();
|
||
15 years ago
|
it != items.end();
|
||
|
++it )
|
||
|
{
|
||
|
if( ( *it ).startsWith( id_str ))
|
||
|
d->id = get_cstr( *it );
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoId::initId( const TQCString& id_P )
|
||
15 years ago
|
{
|
||
|
if( !id_P.isEmpty())
|
||
|
{
|
||
|
d->id = id_P;
|
||
|
#ifdef KSTARTUPINFO_ALL_DEBUG
|
||
|
kdDebug( 172 ) << "using: " << d->id << endl;
|
||
|
#endif
|
||
|
return;
|
||
|
}
|
||
|
const char* startup_env = getenv( NET_STARTUP_ENV );
|
||
|
if( startup_env != NULL && *startup_env != '\0' )
|
||
|
{ // already has id
|
||
|
d->id = startup_env;
|
||
|
#ifdef KSTARTUPINFO_ALL_DEBUG
|
||
|
kdDebug( 172 ) << "reusing: " << d->id << endl;
|
||
|
#endif
|
||
|
return;
|
||
|
}
|
||
12 years ago
|
d->id = TDEStartupInfo::createNewStartupId();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfoId::setupStartupEnv() const
|
||
15 years ago
|
{
|
||
|
if( id().isEmpty())
|
||
|
{
|
||
|
unsetenv( NET_STARTUP_ENV );
|
||
|
return false;
|
||
|
}
|
||
|
return setenv( NET_STARTUP_ENV, id(), true ) == 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoId TDEStartupInfo::currentStartupIdEnv()
|
||
15 years ago
|
{
|
||
|
const char* startup_env = getenv( NET_STARTUP_ENV );
|
||
12 years ago
|
TDEStartupInfoId id;
|
||
15 years ago
|
if( startup_env != NULL && *startup_env != '\0' )
|
||
|
id.d->id = startup_env;
|
||
|
else
|
||
|
id.d->id = "0";
|
||
|
return id;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfo::resetStartupEnv()
|
||
15 years ago
|
{
|
||
|
unsetenv( NET_STARTUP_ENV );
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoId::TDEStartupInfoId()
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDEStartupInfoIdPrivate;
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoId::~TDEStartupInfoId()
|
||
15 years ago
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoId::TDEStartupInfoId( const TDEStartupInfoId& id_P )
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDEStartupInfoIdPrivate( *id_P.d );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoId& TDEStartupInfoId::operator=( const TDEStartupInfoId& id_P )
|
||
15 years ago
|
{
|
||
|
if( &id_P == this )
|
||
|
return *this;
|
||
|
delete d;
|
||
12 years ago
|
d = new TDEStartupInfoIdPrivate( *id_P.d );
|
||
15 years ago
|
return *this;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfoId::operator==( const TDEStartupInfoId& id_P ) const
|
||
15 years ago
|
{
|
||
|
return id() == id_P.id();
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfoId::operator!=( const TDEStartupInfoId& id_P ) const
|
||
15 years ago
|
{
|
||
|
return !(*this == id_P );
|
||
|
}
|
||
|
|
||
|
// needed for QMap
|
||
12 years ago
|
bool TDEStartupInfoId::operator<( const TDEStartupInfoId& id_P ) const
|
||
15 years ago
|
{
|
||
|
return id() < id_P.id();
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfoId::none() const
|
||
15 years ago
|
{
|
||
|
return d->id.isEmpty() || d->id == "0";
|
||
|
}
|
||
|
|
||
12 years ago
|
unsigned long TDEStartupInfoId::timestamp() const
|
||
15 years ago
|
{
|
||
|
if( none())
|
||
|
return 0;
|
||
13 years ago
|
int pos = d->id.findRev( "_TIME" );
|
||
15 years ago
|
if( pos >= 0 )
|
||
|
{
|
||
|
bool ok;
|
||
|
unsigned long time = d->id.mid( pos + 5 ).toULong( &ok );
|
||
|
if( !ok && d->id[ pos + 5 ] == '-' ) // try if it's as a negative signed number perhaps
|
||
|
time = d->id.mid( pos + 5 ).toLong( &ok );
|
||
|
if( ok )
|
||
|
return time;
|
||
|
}
|
||
|
// libstartup-notification style :
|
||
|
// snprintf (s, len, "%s/%s/%lu/%d-%d-%s",
|
||
|
// canonicalized_launcher, canonicalized_launchee, (unsigned long) timestamp,
|
||
|
// (int) getpid (), (int) sequence_number, hostbuf);
|
||
13 years ago
|
int pos1 = d->id.findRev( '/' );
|
||
15 years ago
|
if( pos1 > 0 )
|
||
|
{
|
||
13 years ago
|
int pos2 = d->id.findRev( '/', pos1 - 1 );
|
||
15 years ago
|
if( pos2 >= 0 )
|
||
|
{
|
||
|
bool ok;
|
||
|
unsigned long time = d->id.mid( pos2 + 1, pos1 - pos2 - 1 ).toULong( &ok );
|
||
|
if( !ok && d->id[ pos2 + 1 ] == '-' ) // try if it's as a negative signed number perhaps
|
||
|
time = d->id.mid( pos2 + 1, pos1 - pos2 - 1 ).toLong( &ok );
|
||
|
if( ok )
|
||
|
return time;
|
||
|
}
|
||
|
}
|
||
12 years ago
|
// bah ... old TDEStartupInfo or a problem
|
||
15 years ago
|
return 0;
|
||
|
}
|
||
|
|
||
12 years ago
|
struct TDEStartupInfoDataPrivate
|
||
15 years ago
|
{
|
||
12 years ago
|
TDEStartupInfoDataPrivate() : desktop( 0 ), wmclass( "" ), hostname( "" ),
|
||
|
silent( TDEStartupInfoData::Unknown ), timestamp( -1U ), screen( -1 ), xinerama( -1 ), launched_by( 0 ) {}
|
||
15 years ago
|
TQString bin;
|
||
|
TQString name;
|
||
|
TQString description;
|
||
|
TQString icon;
|
||
15 years ago
|
int desktop;
|
||
15 years ago
|
TQValueList< pid_t > pids;
|
||
|
TQCString wmclass;
|
||
|
TQCString hostname;
|
||
12 years ago
|
TDEStartupInfoData::TriState silent;
|
||
15 years ago
|
unsigned long timestamp;
|
||
|
int screen;
|
||
15 years ago
|
int xinerama;
|
||
|
WId launched_by;
|
||
15 years ago
|
};
|
||
|
|
||
12 years ago
|
TQString TDEStartupInfoData::to_text() const
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString ret = "";
|
||
15 years ago
|
if( !d->bin.isEmpty())
|
||
13 years ago
|
ret += TQString::fromLatin1( " BIN=\"%1\"" ).arg( escape_str( d->bin ));
|
||
15 years ago
|
if( !d->name.isEmpty())
|
||
13 years ago
|
ret += TQString::fromLatin1( " NAME=\"%1\"" ).arg( escape_str( d->name ));
|
||
15 years ago
|
if( !d->description.isEmpty())
|
||
13 years ago
|
ret += TQString::fromLatin1( " DESCRIPTION=\"%1\"" ).arg( escape_str( d->description ));
|
||
15 years ago
|
if( !d->icon.isEmpty())
|
||
13 years ago
|
ret += TQString::fromLatin1( " ICON=%1" ).arg( d->icon );
|
||
15 years ago
|
if( d->desktop != 0 )
|
||
13 years ago
|
ret += TQString::fromLatin1( " DESKTOP=%1" )
|
||
15 years ago
|
.arg( d->desktop == NET::OnAllDesktops ? NET::OnAllDesktops : d->desktop - 1 ); // spec counts from 0
|
||
|
if( !d->wmclass.isEmpty())
|
||
13 years ago
|
ret += TQString::fromLatin1( " WMCLASS=\"%1\"" ).arg( QString(d->wmclass) );
|
||
15 years ago
|
if( !d->hostname.isEmpty())
|
||
13 years ago
|
ret += TQString::fromLatin1( " HOSTNAME=%1" ).arg( QString(d->hostname) );
|
||
15 years ago
|
for( TQValueList< pid_t >::ConstIterator it = d->pids.begin();
|
||
15 years ago
|
it != d->pids.end();
|
||
|
++it )
|
||
13 years ago
|
ret += TQString::fromLatin1( " PID=%1" ).arg( *it );
|
||
15 years ago
|
if( d->silent != Unknown )
|
||
13 years ago
|
ret += TQString::fromLatin1( " SILENT=%1" ).arg( d->silent == Yes ? 1 : 0 );
|
||
15 years ago
|
if( d->timestamp != -1U )
|
||
13 years ago
|
ret += TQString::fromLatin1( " TIMESTAMP=%1" ).arg( d->timestamp );
|
||
15 years ago
|
if( d->screen != -1 )
|
||
13 years ago
|
ret += TQString::fromLatin1( " SCREEN=%1" ).arg( d->screen );
|
||
15 years ago
|
if( d->xinerama != -1 )
|
||
13 years ago
|
ret += TQString::fromLatin1( " XINERAMA=%1" ).arg( d->xinerama );
|
||
15 years ago
|
if( d->launched_by != 0 )
|
||
13 years ago
|
ret += TQString::fromLatin1( " LAUNCHED_BY=%1" ).arg( d->launched_by );
|
||
15 years ago
|
return ret;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoData::TDEStartupInfoData( const TQString& txt_P )
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDEStartupInfoDataPrivate;
|
||
15 years ago
|
TQStringList items = get_fields( txt_P );
|
||
13 years ago
|
const TQString bin_str = TQString::fromLatin1( "BIN=" );
|
||
|
const TQString name_str = TQString::fromLatin1( "NAME=" );
|
||
|
const TQString description_str = TQString::fromLatin1( "DESCRIPTION=" );
|
||
|
const TQString icon_str = TQString::fromLatin1( "ICON=" );
|
||
|
const TQString desktop_str = TQString::fromLatin1( "DESKTOP=" );
|
||
|
const TQString wmclass_str = TQString::fromLatin1( "WMCLASS=" );
|
||
|
const TQString hostname_str = TQString::fromLatin1( "HOSTNAME=" ); // SELI nonstd
|
||
|
const TQString pid_str = TQString::fromLatin1( "PID=" ); // SELI nonstd
|
||
|
const TQString silent_str = TQString::fromLatin1( "SILENT=" );
|
||
|
const TQString timestamp_str = TQString::fromLatin1( "TIMESTAMP=" );
|
||
|
const TQString screen_str = TQString::fromLatin1( "SCREEN=" );
|
||
|
const TQString xinerama_str = TQString::fromLatin1( "XINERAMA=" );
|
||
|
const TQString launched_by_str = TQString::fromLatin1( "LAUNCHED_BY=" );
|
||
15 years ago
|
for( TQStringList::Iterator it = items.begin();
|
||
15 years ago
|
it != items.end();
|
||
|
++it )
|
||
|
{
|
||
|
if( ( *it ).startsWith( bin_str ))
|
||
|
d->bin = get_str( *it );
|
||
|
else if( ( *it ).startsWith( name_str ))
|
||
|
d->name = get_str( *it );
|
||
|
else if( ( *it ).startsWith( description_str ))
|
||
|
d->description = get_str( *it );
|
||
|
else if( ( *it ).startsWith( icon_str ))
|
||
|
d->icon = get_str( *it );
|
||
|
else if( ( *it ).startsWith( desktop_str ))
|
||
|
{
|
||
|
d->desktop = get_num( *it );
|
||
|
if( d->desktop != NET::OnAllDesktops )
|
||
|
++d->desktop; // spec counts from 0
|
||
|
}
|
||
|
else if( ( *it ).startsWith( wmclass_str ))
|
||
|
d->wmclass = get_cstr( *it );
|
||
|
else if( ( *it ).startsWith( hostname_str ))
|
||
|
d->hostname = get_cstr( *it );
|
||
|
else if( ( *it ).startsWith( pid_str ))
|
||
|
addPid( get_num( *it ));
|
||
|
else if( ( *it ).startsWith( silent_str ))
|
||
|
d->silent = get_num( *it ) != 0 ? Yes : No;
|
||
|
else if( ( *it ).startsWith( timestamp_str ))
|
||
|
d->timestamp = get_unum( *it );
|
||
|
else if( ( *it ).startsWith( screen_str ))
|
||
|
d->screen = get_num( *it );
|
||
15 years ago
|
else if( ( *it ).startsWith( xinerama_str ))
|
||
|
d->xinerama = get_num( *it );
|
||
|
else if( ( *it ).startsWith( launched_by_str ))
|
||
|
d->launched_by = get_num( *it );
|
||
15 years ago
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoData::TDEStartupInfoData( const TDEStartupInfoData& data )
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDEStartupInfoDataPrivate( *data.d );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoData& TDEStartupInfoData::operator=( const TDEStartupInfoData& data )
|
||
15 years ago
|
{
|
||
|
if( &data == this )
|
||
|
return *this;
|
||
|
delete d;
|
||
12 years ago
|
d = new TDEStartupInfoDataPrivate( *data.d );
|
||
15 years ago
|
return *this;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::update( const TDEStartupInfoData& data_P )
|
||
15 years ago
|
{
|
||
|
if( !data_P.bin().isEmpty())
|
||
|
d->bin = data_P.bin();
|
||
|
if( !data_P.name().isEmpty() && name().isEmpty()) // don't overwrite
|
||
|
d->name = data_P.name();
|
||
|
if( !data_P.description().isEmpty() && description().isEmpty()) // don't overwrite
|
||
|
d->description = data_P.description();
|
||
|
if( !data_P.icon().isEmpty() && icon().isEmpty()) // don't overwrite
|
||
|
d->icon = data_P.icon();
|
||
|
if( data_P.desktop() != 0 && desktop() == 0 ) // don't overwrite
|
||
|
d->desktop = data_P.desktop();
|
||
|
if( !data_P.d->wmclass.isEmpty())
|
||
|
d->wmclass = data_P.d->wmclass;
|
||
|
if( !data_P.d->hostname.isEmpty())
|
||
|
d->hostname = data_P.d->hostname;
|
||
15 years ago
|
for( TQValueList< pid_t >::ConstIterator it = data_P.d->pids.begin();
|
||
15 years ago
|
it != data_P.d->pids.end();
|
||
|
++it )
|
||
|
addPid( *it );
|
||
|
if( data_P.silent() != Unknown )
|
||
|
d->silent = data_P.silent();
|
||
|
if( data_P.timestamp() != -1U && timestamp() == -1U ) // don't overwrite
|
||
|
d->timestamp = data_P.timestamp();
|
||
|
if( data_P.screen() != -1 )
|
||
|
d->screen = data_P.screen();
|
||
15 years ago
|
if( data_P.xinerama() != -1 && xinerama() != -1 ) // don't overwrite
|
||
|
d->xinerama = data_P.xinerama();
|
||
|
if( data_P.launchedBy() != 0 && launchedBy() != 0 ) // don't overwrite
|
||
|
d->launched_by = data_P.launchedBy();
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoData::TDEStartupInfoData()
|
||
15 years ago
|
{
|
||
12 years ago
|
d = new TDEStartupInfoDataPrivate;
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoData::~TDEStartupInfoData()
|
||
15 years ago
|
{
|
||
|
delete d;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setBin( const TQString& bin_P )
|
||
15 years ago
|
{
|
||
|
d->bin = bin_P;
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQString& TDEStartupInfoData::bin() const
|
||
15 years ago
|
{
|
||
|
return d->bin;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setName( const TQString& name_P )
|
||
15 years ago
|
{
|
||
|
d->name = name_P;
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQString& TDEStartupInfoData::name() const
|
||
15 years ago
|
{
|
||
|
return d->name;
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQString& TDEStartupInfoData::findName() const
|
||
15 years ago
|
{
|
||
|
if( !name().isEmpty())
|
||
|
return name();
|
||
|
return bin();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setDescription( const TQString& desc_P )
|
||
15 years ago
|
{
|
||
|
d->description = desc_P;
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQString& TDEStartupInfoData::description() const
|
||
15 years ago
|
{
|
||
|
return d->description;
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQString& TDEStartupInfoData::findDescription() const
|
||
15 years ago
|
{
|
||
|
if( !description().isEmpty())
|
||
|
return description();
|
||
|
return name();
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setIcon( const TQString& icon_P )
|
||
15 years ago
|
{
|
||
|
d->icon = icon_P;
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQString& TDEStartupInfoData::findIcon() const
|
||
15 years ago
|
{
|
||
|
if( !icon().isEmpty())
|
||
|
return icon();
|
||
|
return bin();
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQString& TDEStartupInfoData::icon() const
|
||
15 years ago
|
{
|
||
|
return d->icon;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setDesktop( int desktop_P )
|
||
15 years ago
|
{
|
||
|
d->desktop = desktop_P;
|
||
|
}
|
||
|
|
||
12 years ago
|
int TDEStartupInfoData::desktop() const
|
||
15 years ago
|
{
|
||
|
return d->desktop;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setWMClass( const TQCString& wmclass_P )
|
||
15 years ago
|
{
|
||
|
d->wmclass = wmclass_P;
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQCString TDEStartupInfoData::findWMClass() const
|
||
15 years ago
|
{
|
||
|
if( !WMClass().isEmpty() && WMClass() != "0" )
|
||
|
return WMClass();
|
||
|
return bin().utf8();
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQCString& TDEStartupInfoData::WMClass() const
|
||
15 years ago
|
{
|
||
|
return d->wmclass;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setHostname( const TQCString& hostname_P )
|
||
15 years ago
|
{
|
||
|
if( !hostname_P.isNull())
|
||
|
d->hostname = hostname_P;
|
||
|
else
|
||
|
{
|
||
|
char tmp[ 256 ];
|
||
|
tmp[ 0 ] = '\0';
|
||
|
if (!gethostname( tmp, 255 ))
|
||
|
tmp[sizeof(tmp)-1] = '\0';
|
||
|
d->hostname = tmp;
|
||
|
}
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQCString& TDEStartupInfoData::hostname() const
|
||
15 years ago
|
{
|
||
|
return d->hostname;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::addPid( pid_t pid_P )
|
||
15 years ago
|
{
|
||
13 years ago
|
if( !d->pids.contains( pid_P ))
|
||
15 years ago
|
d->pids.append( pid_P );
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::remove_pid( pid_t pid_P )
|
||
15 years ago
|
{
|
||
|
d->pids.remove( pid_P );
|
||
|
}
|
||
|
|
||
12 years ago
|
const TQValueList< pid_t >& TDEStartupInfoData::pids() const
|
||
15 years ago
|
{
|
||
|
return d->pids;
|
||
|
}
|
||
|
|
||
12 years ago
|
bool TDEStartupInfoData::is_pid( pid_t pid_P ) const
|
||
15 years ago
|
{
|
||
13 years ago
|
return d->pids.contains( pid_P );
|
||
15 years ago
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setSilent( TriState state_P )
|
||
15 years ago
|
{
|
||
|
d->silent = state_P;
|
||
|
}
|
||
|
|
||
12 years ago
|
TDEStartupInfoData::TriState TDEStartupInfoData::silent() const
|
||
15 years ago
|
{
|
||
|
return d->silent;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setTimestamp( unsigned long time )
|
||
15 years ago
|
{
|
||
|
d->timestamp = time;
|
||
|
}
|
||
|
|
||
12 years ago
|
unsigned long TDEStartupInfoData::timestamp() const
|
||
15 years ago
|
{
|
||
|
return d->timestamp;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setScreen( int screen )
|
||
15 years ago
|
{
|
||
|
d->screen = screen;
|
||
|
}
|
||
|
|
||
12 years ago
|
int TDEStartupInfoData::screen() const
|
||
15 years ago
|
{
|
||
|
return d->screen;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setXinerama( int xinerama )
|
||
15 years ago
|
{
|
||
|
d->xinerama = xinerama;
|
||
|
}
|
||
|
|
||
12 years ago
|
int TDEStartupInfoData::xinerama() const
|
||
15 years ago
|
{
|
||
|
return d->xinerama;
|
||
|
}
|
||
|
|
||
12 years ago
|
void TDEStartupInfoData::setLaunchedBy( WId window )
|
||
15 years ago
|
{
|
||
|
d->launched_by = window;
|
||
|
}
|
||
|
|
||
12 years ago
|
WId TDEStartupInfoData::launchedBy() const
|
||
15 years ago
|
{
|
||
|
return d->launched_by;
|
||
|
}
|
||
|
|
||
15 years ago
|
static
|
||
15 years ago
|
long get_num( const TQString& item_P )
|
||
15 years ago
|
{
|
||
13 years ago
|
unsigned int pos = item_P.find( '=' );
|
||
15 years ago
|
return item_P.mid( pos + 1 ).toLong();
|
||
|
}
|
||
|
|
||
|
static
|
||
15 years ago
|
unsigned long get_unum( const TQString& item_P )
|
||
15 years ago
|
{
|
||
13 years ago
|
unsigned int pos = item_P.find( '=' );
|
||
15 years ago
|
return item_P.mid( pos + 1 ).toULong();
|
||
|
}
|
||
|
|
||
|
static
|
||
15 years ago
|
TQString get_str( const TQString& item_P )
|
||
15 years ago
|
{
|
||
13 years ago
|
unsigned int pos = item_P.find( '=' );
|
||
15 years ago
|
if( item_P.length() > pos + 2 && item_P[ pos + 1 ] == (QChar)'\"' )
|
||
15 years ago
|
{
|
||
13 years ago
|
int pos2 = item_P.left( pos + 2 ).find( '\"' );
|
||
15 years ago
|
if( pos2 < 0 )
|
||
15 years ago
|
return TQString::null; // 01234
|
||
15 years ago
|
return item_P.mid( pos + 2, pos2 - 2 - pos ); // A="C"
|
||
|
}
|
||
|
return item_P.mid( pos + 1 );
|
||
|
}
|
||
|
|
||
|
static
|
||
15 years ago
|
TQCString get_cstr( const TQString& item_P )
|
||
15 years ago
|
{
|
||
|
return get_str( item_P ).utf8();
|
||
|
}
|
||
|
|
||
|
static
|
||
15 years ago
|
TQStringList get_fields( const TQString& txt_P )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString txt = txt_P.simplifyWhiteSpace();
|
||
|
TQStringList ret;
|
||
|
TQString item = "";
|
||
15 years ago
|
bool in = false;
|
||
|
bool escape = false;
|
||
|
for( unsigned int pos = 0;
|
||
|
pos < txt.length();
|
||
|
++pos )
|
||
|
{
|
||
|
if( escape )
|
||
|
{
|
||
|
item += txt[ pos ];
|
||
|
escape = false;
|
||
|
}
|
||
|
else if( txt[ pos ] == '\\' )
|
||
|
escape = true;
|
||
|
else if( txt[ pos ] == '\"' )
|
||
|
in = !in;
|
||
|
else if( txt[ pos ] == ' ' && !in )
|
||
|
{
|
||
|
ret.append( item );
|
||
|
item = "";
|
||
|
}
|
||
|
else
|
||
|
item += txt[ pos ];
|
||
|
}
|
||
|
ret.append( item );
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
15 years ago
|
static TQString escape_str( const TQString& str_P )
|
||
15 years ago
|
{
|
||
15 years ago
|
TQString ret = "";
|
||
15 years ago
|
for( unsigned int pos = 0;
|
||
|
pos < str_P.length();
|
||
|
++pos )
|
||
|
{
|
||
15 years ago
|
if( str_P[ pos ] == (QChar)'\\'
|
||
|
|| str_P[ pos ] == (QChar)'"' )
|
||
15 years ago
|
ret += '\\';
|
||
|
ret += str_P[ pos ];
|
||
|
}
|
||
|
return ret;
|
||
|
}
|
||
|
|
||
12 years ago
|
#include "tdestartupinfo.moc"
|
||
15 years ago
|
#endif
|