|
|
|
@ -45,7 +45,7 @@
|
|
|
|
|
|
|
|
|
|
#include <tdeconfig.h>
|
|
|
|
|
#include "kdebug.h"
|
|
|
|
|
#include "kuniqueapplication.h"
|
|
|
|
|
#include "tdeuniqueapplication.h"
|
|
|
|
|
|
|
|
|
|
#if defined TQ_WS_X11
|
|
|
|
|
#include <netwm.h>
|
|
|
|
@ -59,12 +59,12 @@
|
|
|
|
|
# endif
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
bool KUniqueApplication::s_nofork = false;
|
|
|
|
|
bool KUniqueApplication::s_multipleInstances = false;
|
|
|
|
|
bool KUniqueApplication::s_uniqueTestDone = false;
|
|
|
|
|
bool KUniqueApplication::s_handleAutoStarted = false;
|
|
|
|
|
bool TDEUniqueApplication::s_nofork = false;
|
|
|
|
|
bool TDEUniqueApplication::s_multipleInstances = false;
|
|
|
|
|
bool TDEUniqueApplication::s_uniqueTestDone = false;
|
|
|
|
|
bool TDEUniqueApplication::s_handleAutoStarted = false;
|
|
|
|
|
|
|
|
|
|
static TDECmdLineOptions kunique_options[] =
|
|
|
|
|
static TDECmdLineOptions tdeunique_options[] =
|
|
|
|
|
{
|
|
|
|
|
{ "nofork", "Don't run in the background.", 0 },
|
|
|
|
|
TDECmdLineLastOption
|
|
|
|
@ -76,7 +76,7 @@ struct DCOPRequest {
|
|
|
|
|
DCOPClientTransaction *transaction;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class KUniqueApplicationPrivate {
|
|
|
|
|
class TDEUniqueApplicationPrivate {
|
|
|
|
|
public:
|
|
|
|
|
TQPtrList <DCOPRequest> requestList;
|
|
|
|
|
bool processingRequest;
|
|
|
|
@ -84,13 +84,13 @@ public:
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
KUniqueApplication::addCmdLineOptions()
|
|
|
|
|
TDEUniqueApplication::addCmdLineOptions()
|
|
|
|
|
{
|
|
|
|
|
TDECmdLineArgs::addCmdLineOptions(kunique_options, 0, "kuniqueapp", "tde" );
|
|
|
|
|
TDECmdLineArgs::addCmdLineOptions(tdeunique_options, 0, "tdeuniqueapp", "tde" );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
|
|
|
|
KUniqueApplication::start()
|
|
|
|
|
TDEUniqueApplication::start()
|
|
|
|
|
{
|
|
|
|
|
if( s_uniqueTestDone )
|
|
|
|
|
return true;
|
|
|
|
@ -99,7 +99,7 @@ KUniqueApplication::start()
|
|
|
|
|
#ifdef TQ_WS_WIN
|
|
|
|
|
s_nofork = true;
|
|
|
|
|
#else
|
|
|
|
|
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("kuniqueapp");
|
|
|
|
|
TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("tdeuniqueapp");
|
|
|
|
|
s_nofork = !args->isSet("fork");
|
|
|
|
|
delete args;
|
|
|
|
|
#endif
|
|
|
|
@ -122,7 +122,7 @@ KUniqueApplication::start()
|
|
|
|
|
if(dcopClient()->registerAs(appName, false).isEmpty()) {
|
|
|
|
|
startKdeinit();
|
|
|
|
|
if(dcopClient()->registerAs(appName, false).isEmpty()) {
|
|
|
|
|
kdError() << "KUniqueApplication: Can't setup DCOP communication." << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: Can't setup DCOP communication." << endl;
|
|
|
|
|
::exit(255);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -136,13 +136,13 @@ KUniqueApplication::start()
|
|
|
|
|
signed char result;
|
|
|
|
|
if (0 > pipe(fd))
|
|
|
|
|
{
|
|
|
|
|
kdError() << "KUniqueApplication: pipe() failed!" << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: pipe() failed!" << endl;
|
|
|
|
|
::exit(255);
|
|
|
|
|
}
|
|
|
|
|
int fork_result = fork();
|
|
|
|
|
switch(fork_result) {
|
|
|
|
|
case -1:
|
|
|
|
|
kdError() << "KUniqueApplication: fork() failed!" << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: fork() failed!" << endl;
|
|
|
|
|
::exit(255);
|
|
|
|
|
break;
|
|
|
|
|
case 0:
|
|
|
|
@ -158,7 +158,7 @@ KUniqueApplication::start()
|
|
|
|
|
// Check DISPLAY
|
|
|
|
|
if (TQCString(getenv(DISPLAY)).isEmpty())
|
|
|
|
|
{
|
|
|
|
|
kdError() << "KUniqueApplication: Can't determine DISPLAY. Aborting." << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: Can't determine DISPLAY. Aborting." << endl;
|
|
|
|
|
result = -1; // Error
|
|
|
|
|
::write(fd[1], &result, 1);
|
|
|
|
|
::exit(255);
|
|
|
|
@ -169,7 +169,7 @@ KUniqueApplication::start()
|
|
|
|
|
regName = dc->registerAs(appName, false);
|
|
|
|
|
if (regName.isEmpty())
|
|
|
|
|
{
|
|
|
|
|
kdError() << "KUniqueApplication: Can't setup DCOP communication." << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: Can't setup DCOP communication." << endl;
|
|
|
|
|
result = -1;
|
|
|
|
|
delete dc; // Clean up DCOP commmunication
|
|
|
|
|
::write(fd[1], &result, 1);
|
|
|
|
@ -246,12 +246,12 @@ KUniqueApplication::start()
|
|
|
|
|
if (n == 1) break;
|
|
|
|
|
if (n == 0)
|
|
|
|
|
{
|
|
|
|
|
kdError() << "KUniqueApplication: Pipe closed unexpectedly." << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: Pipe closed unexpectedly." << endl;
|
|
|
|
|
::exit(255);
|
|
|
|
|
}
|
|
|
|
|
if (errno != EINTR)
|
|
|
|
|
{
|
|
|
|
|
kdError() << "KUniqueApplication: Error reading from pipe." << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: Error reading from pipe." << endl;
|
|
|
|
|
::exit(255);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -263,12 +263,12 @@ KUniqueApplication::start()
|
|
|
|
|
dc = new DCOPClient();
|
|
|
|
|
if (!dc->attach())
|
|
|
|
|
{
|
|
|
|
|
kdError() << "KUniqueApplication: Parent process can't attach to DCOP." << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: Parent process can't attach to DCOP." << endl;
|
|
|
|
|
delete dc; // Clean up DCOP commmunication
|
|
|
|
|
::exit(255);
|
|
|
|
|
}
|
|
|
|
|
if (!dc->isApplicationRegistered(appName)) {
|
|
|
|
|
kdError() << "KUniqueApplication: Registering failed!" << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: Registering failed!" << endl;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TQCString new_asn_id;
|
|
|
|
@ -299,7 +299,7 @@ KUniqueApplication::start()
|
|
|
|
|
dc->setPriorityCall(false);
|
|
|
|
|
if (replyType != "int")
|
|
|
|
|
{
|
|
|
|
|
kdError() << "KUniqueApplication: DCOP communication error!" << endl;
|
|
|
|
|
kdError() << "TDEUniqueApplication: DCOP communication error!" << endl;
|
|
|
|
|
delete dc; // Clean up DCOP commmunication
|
|
|
|
|
::exit(255);
|
|
|
|
|
}
|
|
|
|
@ -314,11 +314,11 @@ KUniqueApplication::start()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KUniqueApplication::KUniqueApplication(bool allowStyles, bool GUIenabled, bool configUnique)
|
|
|
|
|
TDEUniqueApplication::TDEUniqueApplication(bool allowStyles, bool GUIenabled, bool configUnique)
|
|
|
|
|
: TDEApplication( allowStyles, GUIenabled, initHack( configUnique )),
|
|
|
|
|
DCOPObject(TDECmdLineArgs::about->appName())
|
|
|
|
|
{
|
|
|
|
|
d = new KUniqueApplicationPrivate;
|
|
|
|
|
d = new TDEUniqueApplicationPrivate;
|
|
|
|
|
d->processingRequest = false;
|
|
|
|
|
d->firstInstance = true;
|
|
|
|
|
|
|
|
|
@ -334,12 +334,12 @@ KUniqueApplication::KUniqueApplication(bool allowStyles, bool GUIenabled, bool c
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef TQ_WS_X11
|
|
|
|
|
KUniqueApplication::KUniqueApplication(Display *display, TQt::HANDLE visual,
|
|
|
|
|
TDEUniqueApplication::TDEUniqueApplication(Display *display, TQt::HANDLE visual,
|
|
|
|
|
TQt::HANDLE colormap, bool allowStyles, bool configUnique)
|
|
|
|
|
: TDEApplication( display, visual, colormap, allowStyles, initHack( configUnique )),
|
|
|
|
|
DCOPObject(TDECmdLineArgs::about->appName())
|
|
|
|
|
{
|
|
|
|
|
d = new KUniqueApplicationPrivate;
|
|
|
|
|
d = new TDEUniqueApplicationPrivate;
|
|
|
|
|
d->processingRequest = false;
|
|
|
|
|
d->firstInstance = true;
|
|
|
|
|
|
|
|
|
@ -355,13 +355,13 @@ KUniqueApplication::KUniqueApplication(Display *display, TQt::HANDLE visual,
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
KUniqueApplication::~KUniqueApplication()
|
|
|
|
|
TDEUniqueApplication::~TDEUniqueApplication()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// this gets called before even entering TQApplication::TQApplication()
|
|
|
|
|
TDEInstance* KUniqueApplication::initHack( bool configUnique )
|
|
|
|
|
TDEInstance* TDEUniqueApplication::initHack( bool configUnique )
|
|
|
|
|
{
|
|
|
|
|
TDEInstance* inst = new TDEInstance( TDECmdLineArgs::about );
|
|
|
|
|
if (configUnique)
|
|
|
|
@ -375,7 +375,7 @@ TDEInstance* KUniqueApplication::initHack( bool configUnique )
|
|
|
|
|
return inst;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KUniqueApplication::newInstanceNoFork()
|
|
|
|
|
void TDEUniqueApplication::newInstanceNoFork()
|
|
|
|
|
{
|
|
|
|
|
if (dcopClient()->isSuspended())
|
|
|
|
|
{
|
|
|
|
@ -400,7 +400,7 @@ void KUniqueApplication::newInstanceNoFork()
|
|
|
|
|
// What to do with the return value ?
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool KUniqueApplication::process(const TQCString &fun, const TQByteArray &data,
|
|
|
|
|
bool TDEUniqueApplication::process(const TQCString &fun, const TQByteArray &data,
|
|
|
|
|
TQCString &replyType, TQByteArray &replyData)
|
|
|
|
|
{
|
|
|
|
|
if (fun == "newInstance()")
|
|
|
|
@ -412,7 +412,7 @@ bool KUniqueApplication::process(const TQCString &fun, const TQByteArray &data,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
KUniqueApplication::delayRequest(const TQCString &fun, const TQByteArray &data)
|
|
|
|
|
TDEUniqueApplication::delayRequest(const TQCString &fun, const TQByteArray &data)
|
|
|
|
|
{
|
|
|
|
|
DCOPRequest *request = new DCOPRequest;
|
|
|
|
|
request->fun = fun;
|
|
|
|
@ -426,7 +426,7 @@ KUniqueApplication::delayRequest(const TQCString &fun, const TQByteArray &data)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
KUniqueApplication::processDelayed()
|
|
|
|
|
TDEUniqueApplication::processDelayed()
|
|
|
|
|
{
|
|
|
|
|
if (dcopClient()->isSuspended())
|
|
|
|
|
{
|
|
|
|
@ -468,12 +468,12 @@ KUniqueApplication::processDelayed()
|
|
|
|
|
d->processingRequest = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool KUniqueApplication::restoringSession()
|
|
|
|
|
bool TDEUniqueApplication::restoringSession()
|
|
|
|
|
{
|
|
|
|
|
return d->firstInstance && isRestored();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int KUniqueApplication::newInstance()
|
|
|
|
|
int TDEUniqueApplication::newInstance()
|
|
|
|
|
{
|
|
|
|
|
if (!d->firstInstance)
|
|
|
|
|
{
|
|
|
|
@ -493,13 +493,13 @@ int KUniqueApplication::newInstance()
|
|
|
|
|
return 0; // do nothing in default implementation
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KUniqueApplication::setHandleAutoStarted()
|
|
|
|
|
void TDEUniqueApplication::setHandleAutoStarted()
|
|
|
|
|
{
|
|
|
|
|
s_handleAutoStarted = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void KUniqueApplication::virtual_hook( int id, void* data )
|
|
|
|
|
void TDEUniqueApplication::virtual_hook( int id, void* data )
|
|
|
|
|
{ TDEApplication::virtual_hook( id, data );
|
|
|
|
|
DCOPObject::virtual_hook( id, data ); }
|
|
|
|
|
|
|
|
|
|
#include "kuniqueapplication.moc"
|
|
|
|
|
#include "tdeuniqueapplication.moc"
|