26 #include <KCmdLineArgs>
29 #include <TelepathyQt/Types>
30 #include <TelepathyQt/Debug>
38 class TelepathyHandlerApplication::Private
44 void _k_onInitialTimeout();
47 static KComponentData initHack();
48 void init(
int initialTimeout,
int timeout);
52 static bool s_persist;
62 TelepathyHandlerApplication::Private::Private(TelepathyHandlerApplication *q)
64 firstJobStarted(false),
69 TelepathyHandlerApplication::Private::~Private()
73 void TelepathyHandlerApplication::Private::_k_onInitialTimeout()
75 if (jobCount == 0 && jobCount.fetchAndAddOrdered(-1) == 0) {
77 kDebug() <<
"No job received. Exiting";
78 QCoreApplication::quit();
82 void TelepathyHandlerApplication::Private::_k_onTimeout()
84 if (jobCount == 0 && jobCount.fetchAndAddOrdered(-1) == 0) {
86 kDebug() <<
"Timeout. Exiting";
87 QCoreApplication::quit();
92 KComponentData TelepathyHandlerApplication::Private::initHack()
108 setenv(
"KDE_FULL_SESSION",
"true", 0);
109 setenv(
"KDE_SESSION_VERSION",
"4", 0);
111 KComponentData cData(KCmdLineArgs::aboutData());
112 KCmdLineOptions handler_options;
113 handler_options.add(
"persist", ki18n(
"Persistent mode (do not exit on timeout)"));
114 handler_options.add(
"debug", ki18n(
"Show Telepathy debugging information"));
115 KCmdLineArgs::addCmdLineOptions(handler_options, ki18n(
"KDE Telepathy"),
"kde-telepathy",
"kde");
116 KCmdLineArgs *args = KCmdLineArgs::parsedArgs(
"kde-telepathy");
117 Private::s_persist = args->isSet(
"persist");
118 Private::s_debug = args->isSet(
"debug");
123 void TelepathyHandlerApplication::Private::init(
int initialTimeout,
int timeout)
125 this->initialTimeout = initialTimeout;
126 this->timeout = timeout;
131 q->setQuitOnLastWindowClosed(
false);
145 if (!Private::s_persist) {
146 timer =
new QTimer(q);
147 if (initialTimeout >= 0) {
148 q->connect(timer, SIGNAL(timeout()), q, SLOT(_k_onInitialTimeout()));
149 timer->start(initialTimeout);
154 bool TelepathyHandlerApplication::Private::s_persist =
false;
155 bool TelepathyHandlerApplication::Private::s_debug =
false;
164 d->init(initialTimeout, timeout);
172 :
KApplication(display, visual, colormap, Private::initHack()),
175 d->init(initialTimeout, timeout);
186 TelepathyHandlerApplication::Private *d = app->d;
188 int ret = d->jobCount.fetchAndAddOrdered(1);
189 if (!Private::s_persist) {
190 if (d->timer->isActive()) {
193 if (!d->firstJobStarted) {
194 if (d->initialTimeout) {
195 disconnect(d->timer, SIGNAL(timeout()), app, SLOT(_k_onInitialTimeout()));
197 if (d->timeout >= 0) {
198 connect(d->timer, SIGNAL(timeout()), app, SLOT(_k_onTimeout()));
200 d->firstJobStarted =
true;
203 kDebug() <<
"New job started." << d->jobCount <<
"jobs currently running";
210 TelepathyHandlerApplication::Private *d = app->d;
212 if (d->jobCount.fetchAndAddOrdered(-1) <= 1) {
213 if (!Private::s_persist && d->timeout >= 0) {
214 kDebug() <<
"No other jobs at the moment. Starting timer.";
215 d->timer->start(d->timeout);
218 kDebug() <<
"Job finished." << d->jobCount <<
"jobs currently running";
223 #include "telepathy-handler-application.moc"