• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdecore
 

tdecore

  • tdecore
tdeapplication.cpp
1/* This file is part of the TDE libraries
2 Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
3 Copyright (C) 1998, 1999, 2000 KDE Team
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
9
10 This library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
14
15 You should have received a copy of the GNU Library General Public License
16 along with this library; see the file COPYING.LIB. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 Boston, MA 02110-1301, USA.
19 */
20
21#include "config.h"
22
23#ifdef HAVE_XCOMPOSITE
24#define COMPOSITE
25#endif
26
27// #ifdef QTRANSLATOR_H
28// #error qtranslator.h was already included
29// #endif // QTRANSLATOR_H
30//
31// #ifdef TQTRANSLATOR_H
32// #error tqtranslator.h was already included
33// #endif // TQTRANSLATOR_H
34
35#undef TQT_NO_TRANSLATION
36#undef TQT_NO_TRANSLATION
37#include <tqtranslator.h>
38
39// FIXME
40// FOR BINARY COMPATIBILITY ONLY
41// REMOVE WHEN PRACTICAL!
42#define TDEAPPLICATION_BINARY_COMPAT_HACK 1
43#include "tdeapplication.h"
44#undef TDEAPPLICATION_BINARY_COMPAT_HACK
45
46#define TQT_NO_TRANSLATION
47#define TQT_NO_TRANSLATION
48#include <tqdir.h>
49#include <tqptrcollection.h>
50#include <tqwidgetlist.h>
51#include <tqstrlist.h>
52#include <tqfile.h>
53#include <tqmessagebox.h>
54#include <tqtextstream.h>
55#include <tqregexp.h>
56#include <tqlineedit.h>
57#include <tqtextedit.h>
58#include <tqsessionmanager.h>
59#include <tqptrlist.h>
60#include <tqtimer.h>
61#include <tqstylesheet.h>
62#include <tqpixmapcache.h>
63#include <tqtooltip.h>
64#include <tqstylefactory.h>
65#include <tqmetaobject.h>
66#include <tqimage.h>
67#ifndef TQT_NO_SQL
68#include <tqsqlpropertymap.h>
69#endif
70
71#include <tdeglobal.h>
72#include <tdestandarddirs.h>
73#include <kdebug.h>
74#include <tdelocale.h>
75#include <tdestyle.h>
76#include <kiconloader.h>
77#include <kclipboard.h>
78#include <tdeconfig.h>
79#include <ksimpleconfig.h>
80#include <tdecmdlineargs.h>
81#include <tdeaboutdata.h>
82#include <tdeglobalsettings.h>
83#include <tdecrash.h>
84#include <kdatastream.h>
85#include <klibloader.h>
86#include <kmimesourcefactory.h>
87#include <tdestdaccel.h>
88#include <tdeaccel.h>
89#include "kcheckaccelerators.h"
90#include <tqptrdict.h>
91#include <kmacroexpander.h>
92#include <kshell.h>
93#include <kprotocolinfo.h>
94#include <kkeynative.h>
95#include <kmdcodec.h>
96#include <tdeglobalaccel.h>
97
98#if defined TQ_WS_X11
99#include <tdestartupinfo.h>
100#endif
101
102#include <dcopclient.h>
103#include <dcopref.h>
104
105#include <sys/types.h>
106#ifdef HAVE_SYS_STAT_H
107#include <sys/stat.h>
108#endif
109#include <sys/wait.h>
110#include <grp.h>
111#include <sys/types.h>
112
113#ifndef TQ_WS_WIN
114#include "twin.h"
115#endif
116
117#include <fcntl.h>
118#include <stdlib.h> // getenv(), srand(), rand()
119#include <signal.h>
120#include <unistd.h>
121#include <time.h>
122#include <sys/time.h>
123#include <errno.h>
124#include <string.h>
125#include <netdb.h>
126#if defined TQ_WS_X11
127//#ifndef TQ_WS_QWS //FIXME(E): NetWM should talk to QWS...
128#include <netwm.h>
129#endif
130
131#include "tdeprocctrl.h"
132
133#ifdef HAVE_PATHS_H
134#include <paths.h>
135#endif
136
137#ifdef TQ_WS_X11
138#include <X11/Xlib.h>
139#ifdef COMPOSITE
140#include <X11/extensions/Xrender.h>
141#include <X11/extensions/Xcomposite.h>
142#include <dlfcn.h>
143#endif
144#include <X11/Xutil.h>
145#include <X11/Xatom.h>
146#include <X11/SM/SMlib.h>
147#include <fixx11h.h>
148#endif
149
150#include <pwd.h>
151
152#ifndef TQ_WS_WIN
153#include <KDE-ICE/ICElib.h>
154#else
155typedef void* IceIOErrorHandler;
156#include <windows.h>
157//KDE4: remove
158#define Button1Mask (1<<8)
159#define Button2Mask (1<<9)
160#define Button3Mask (1<<10)
161#endif
162
163#ifdef TQ_WS_X11
164#define DISPLAY "DISPLAY"
165#elif defined(TQ_WS_QWS)
166#define DISPLAY "QWS_DISPLAY"
167#endif
168
169#if defined TQ_WS_X11
170#include <kipc.h>
171#endif
172
173#ifdef TQ_WS_MACX
174#include <Carbon/Carbon.h>
175#include <tqimage.h>
176#endif
177
178#if defined TQ_WS_X11
179#include <sys/ioctl.h>
180#ifdef __linux__
181#include <linux/vt.h>
182#endif
183extern "C" {
184extern int getfd(const char *fnam);
185}
186#endif
187
188#include "tdeappdcopinterface.h"
189
190// exported for tdm kfrontend
191TDE_EXPORT bool kde_have_kipc = true; // magic hook to disable kipc in tdm
192bool kde_kiosk_exception = false; // flag to disable kiosk restrictions
193bool kde_kiosk_admin = false;
194
195TDEApplication* TDEApplication::TDEApp = nullptr;
196bool TDEApplication::loadedByKdeinit = false;
197DCOPClient *TDEApplication::s_DCOPClient = nullptr;
198bool TDEApplication::s_dcopClientNeedsPostInit = false;
199
200#ifdef TQ_WS_X11
201static Atom atom_DesktopWindow;
202static Atom atom_NetSupported;
203#endif
204
205#if defined(TQ_WS_X11) && defined(COMPOSITE)
206static int composite_event, composite_error, composite_opcode;
207static bool x11_composite_error_generated;
208static int x11_error(Display *dpy, XErrorEvent *ev) {
209 if (ev->request_code == composite_opcode && ev->minor_code == X_CompositeRedirectSubwindows)
210 {
211 x11_composite_error_generated = true;
212 return 0;
213 }
214 return 1;
215}
216#endif
217
218// duplicated from patched Qt, so that there won't be unresolved symbols if Qt gets
219// replaced by unpatched one
220TDECORE_EXPORT bool tqt_qclipboard_bailout_hack = false;
221
222template class TQPtrList<KSessionManaged>;
223
224#ifdef TQ_WS_X11
225extern "C" {
226static int kde_xio_errhandler( Display * dpy )
227{
228 return tdeApp->xioErrhandler( dpy );
229}
230
231static int kde_x_errhandler( Display *dpy, XErrorEvent *err )
232{
233 return tdeApp->xErrhandler( dpy, err );
234}
235
236}
237
238extern "C" {
239static void kde_ice_ioerrorhandler( IceConn conn )
240{
241 if(tdeApp)
242 tdeApp->iceIOErrorHandler( conn );
243 // else ignore the error for now
244}
245}
246#endif
247
248#ifdef TQ_WS_WIN
249void TDEApplication_init_windows(bool GUIenabled);
250
251class QAssistantClient;
252#endif
253
254#ifdef TQ_WS_X11
255// --------------------------------------------------------------------------------------
256// Get the VT number X is running on
257// (code taken from GDM, daemon/getvt.c, GPLv2+)
258// --------------------------------------------------------------------------------------
259int get_x_vtnum(Display *dpy)
260{
261 Atom prop;
262 Atom actualtype;
263 int actualformat;
264 unsigned long nitems;
265 unsigned long bytes_after;
266 unsigned char *buf;
267 int num;
268
269 prop = XInternAtom (dpy, "XFree86_VT", False);
270 if (prop == None)
271 return -1;
272
273 if (XGetWindowProperty (dpy, DefaultRootWindow (dpy), prop, 0, 1,
274 False, AnyPropertyType, &actualtype, &actualformat,
275 &nitems, &bytes_after, &buf)) {
276 return -1;
277 }
278
279 if (nitems != 1) {
280 XFree (buf);
281 return -1;
282 }
283
284 switch (actualtype) {
285 case XA_CARDINAL:
286 case XA_INTEGER:
287 case XA_WINDOW:
288 switch (actualformat) {
289 case 8:
290 num = (*(uint8_t *)(void *)buf);
291 break;
292 case 16:
293 num = (*(uint16_t *)(void *)buf);
294 break;
295 case 32:
296 num = (*(uint32_t *)(void *)buf);
297 break;
298 default:
299 XFree (buf);
300 return -1;
301 }
302 break;
303 default:
304 XFree (buf);
305 return -1;
306 }
307
308 XFree (buf);
309
310 return num;
311}
312// --------------------------------------------------------------------------------------
313#endif // TQ_WS_X11
314
315/*
316 Private data to make keeping binary compatibility easier
317 */
318class TDEApplicationPrivate
319{
320public:
321 TDEApplicationPrivate()
322 : actionRestrictions( false ),
323 refCount( 1 ),
324 oldIceIOErrorHandler( 0 ),
325 checkAccelerators( 0 ),
326 overrideStyle( TQString::null ),
327 startup_id( "0" ),
328 app_started_timer( NULL ),
329 m_TDEAppDCOPInterface( 0L ),
330 session_save( false )
331#ifdef TQ_WS_X11
332 ,oldXErrorHandler( NULL )
333 ,oldXIOErrorHandler( NULL )
334#elif defined TQ_WS_WIN
335 ,qassistantclient( 0 )
336#endif
337 {
338 }
339
340 ~TDEApplicationPrivate()
341 {
342#ifdef TQ_WS_WIN
343 delete qassistantclient;
344#endif
345 }
346
347
348 bool actionRestrictions : 1;
349 bool guiEnabled : 1;
356 int refCount;
357 IceIOErrorHandler oldIceIOErrorHandler;
358 KCheckAccelerators* checkAccelerators;
359 TQString overrideStyle;
360 TQString geometry_arg;
361 TQCString startup_id;
362 TQTimer* app_started_timer;
363 TDEAppDCOPInterface *m_TDEAppDCOPInterface;
364 bool session_save;
365#ifdef TQ_WS_X11
366 int (*oldXErrorHandler)(Display*,XErrorEvent*);
367 int (*oldXIOErrorHandler)(Display*);
368#elif defined TQ_WS_WIN
369 QAssistantClient* qassistantclient;
370#endif
371
372 class URLActionRule
373 {
374 public:
375#define checkExactMatch(s, b) \
376 if (s.isEmpty()) b = true; \
377 else if (s[s.length()-1] == '!') \
378 { b = false; s.truncate(s.length()-1); } \
379 else b = true;
380#define checkStartWildCard(s, b) \
381 if (s.isEmpty()) b = true; \
382 else if (s[0] == '*') \
383 { b = true; s = s.mid(1); } \
384 else b = false;
385#define checkEqual(s, b) \
386 b = (s == "=");
387
388 URLActionRule(const TQString &act,
389 const TQString &bProt, const TQString &bHost, const TQString &bPath,
390 const TQString &dProt, const TQString &dHost, const TQString &dPath,
391 bool perm)
392 : action(act),
393 baseProt(bProt), baseHost(bHost), basePath(bPath),
394 destProt(dProt), destHost(dHost), destPath(dPath),
395 permission(perm)
396 {
397 checkExactMatch(baseProt, baseProtWildCard);
398 checkStartWildCard(baseHost, baseHostWildCard);
399 checkExactMatch(basePath, basePathWildCard);
400 checkExactMatch(destProt, destProtWildCard);
401 checkStartWildCard(destHost, destHostWildCard);
402 checkExactMatch(destPath, destPathWildCard);
403 checkEqual(destProt, destProtEqual);
404 checkEqual(destHost, destHostEqual);
405 }
406
407 bool baseMatch(const KURL &url, const TQString &protClass)
408 {
409 if (baseProtWildCard)
410 {
411 if ( !baseProt.isEmpty() && !url.protocol().startsWith(baseProt) &&
412 (protClass.isEmpty() || (protClass != baseProt)) )
413 return false;
414 }
415 else
416 {
417 if ( (url.protocol() != baseProt) &&
418 (protClass.isEmpty() || (protClass != baseProt)) )
419 return false;
420 }
421 if (baseHostWildCard)
422 {
423 if (!baseHost.isEmpty() && !url.host().endsWith(baseHost))
424 return false;
425 }
426 else
427 {
428 if (url.host() != baseHost)
429 return false;
430 }
431 if (basePathWildCard)
432 {
433 if (!basePath.isEmpty() && !url.path().startsWith(basePath))
434 return false;
435 }
436 else
437 {
438 if (url.path() != basePath)
439 return false;
440 }
441 return true;
442 }
443
444 bool destMatch(const KURL &url, const TQString &protClass, const KURL &base, const TQString &baseClass)
445 {
446 if (destProtEqual)
447 {
448 if ( (url.protocol() != base.protocol()) &&
449 (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass) )
450 return false;
451 }
452 else if (destProtWildCard)
453 {
454 if ( !destProt.isEmpty() && !url.protocol().startsWith(destProt) &&
455 (protClass.isEmpty() || (protClass != destProt)) )
456 return false;
457 }
458 else
459 {
460 if ( (url.protocol() != destProt) &&
461 (protClass.isEmpty() || (protClass != destProt)) )
462 return false;
463 }
464 if (destHostWildCard)
465 {
466 if (!destHost.isEmpty() && !url.host().endsWith(destHost))
467 return false;
468 }
469 else if (destHostEqual)
470 {
471 if (url.host() != base.host())
472 return false;
473 }
474 else
475 {
476 if (url.host() != destHost)
477 return false;
478 }
479 if (destPathWildCard)
480 {
481 if (!destPath.isEmpty() && !url.path().startsWith(destPath))
482 return false;
483 }
484 else
485 {
486 if (url.path() != destPath)
487 return false;
488 }
489 return true;
490 }
491
492 TQString action;
493 TQString baseProt;
494 TQString baseHost;
495 TQString basePath;
496 TQString destProt;
497 TQString destHost;
498 TQString destPath;
499 bool baseProtWildCard : 1;
500 bool baseHostWildCard : 1;
501 bool basePathWildCard : 1;
502 bool destProtWildCard : 1;
503 bool destHostWildCard : 1;
504 bool destPathWildCard : 1;
505 bool destProtEqual : 1;
506 bool destHostEqual : 1;
507 bool permission;
508 };
509 TQPtrList<URLActionRule> urlActionRestrictions;
510
511 TQString sessionKey;
512 TQString pSessionConfigFile;
513};
514
515
516static TQPtrList<TQWidget>*x11Filter = 0;
517static bool autoDcopRegistration = true;
518
519void TDEApplication::installX11EventFilter( TQWidget* filter )
520{
521 if ( !filter )
522 return;
523 if (!x11Filter)
524 x11Filter = new TQPtrList<TQWidget>;
525 connect ( filter, TQ_SIGNAL( destroyed() ), this, TQ_SLOT( x11FilterDestroyed() ) );
526 x11Filter->append( filter );
527}
528
529void TDEApplication::x11FilterDestroyed()
530{
531 removeX11EventFilter( static_cast< const TQWidget* >( sender()));
532}
533
534void TDEApplication::removeX11EventFilter( const TQWidget* filter )
535{
536 if ( !x11Filter || !filter )
537 return;
538 x11Filter->removeRef( filter );
539 if ( x11Filter->isEmpty() ) {
540 delete x11Filter;
541 x11Filter = 0;
542 }
543}
544
545// FIXME: remove this when we've get a better method of
546// customizing accelerator handling -- hopefully in Qt.
547// For now, this is set whenever an accelerator is overridden
548// in TDEAccelEventHandler so that the AccelOverride isn't sent twice. -- ellis, 19/10/02
549extern bool kde_g_bKillAccelOverride;
550
551bool TDEApplication::notify(TQObject *receiver, TQEvent *event)
552{
553 TQEvent::Type t = event->type();
554 if (kde_g_bKillAccelOverride)
555 {
556 kde_g_bKillAccelOverride = false;
557 // Indicate that the accelerator has been overridden.
558 if (t == TQEvent::AccelOverride)
559 {
560 static_cast<TQKeyEvent*>(event)->accept();
561 return true;
562 }
563 else
564 kdWarning(125) << "kde_g_bKillAccelOverride set, but received an event other than AccelOverride." << endl;
565 }
566
567 if ((t == TQEvent::AccelOverride) || (t == TQEvent::KeyPress))
568 {
569 static const TDEShortcut& _selectAll = TDEStdAccel::selectAll();
570 TQLineEdit *edit = ::tqt_cast<TQLineEdit *>(receiver);
571 if (edit)
572 {
573 // We have a keypress for a lineedit...
574 TQKeyEvent *kevent = static_cast<TQKeyEvent*>(event);
575 KKey key(kevent);
576 if (_selectAll.contains(key))
577 {
578 if (t == TQEvent::KeyPress)
579 {
580 edit->selectAll();
581 return true;
582 }
583 else
584 {
585 kevent->accept();
586 }
587 }
588 // Ctrl-U deletes from start of line.
589 if (key == KKey(TQt::CTRL + TQt::Key_U))
590 {
591 if (t == TQEvent::KeyPress)
592 {
593 if (!edit->isReadOnly())
594 {
595 TQString t(edit->text());
596 t = t.mid(edit->cursorPosition());
597 edit->validateAndSet(t, 0, 0, 0);
598 }
599 return true;
600 }
601 else
602 {
603 kevent->accept();
604 }
605
606 }
607 }
608 TQTextEdit *medit = ::tqt_cast<TQTextEdit *>(receiver);
609 if (medit)
610 {
611 // We have a keypress for a multilineedit...
612 TQKeyEvent *kevent = static_cast<TQKeyEvent*>(event);
613 if (_selectAll.contains(KKey(kevent)))
614 {
615 if (t == TQEvent::KeyPress)
616 {
617 medit->selectAll();
618 return true;
619 }
620 else
621 {
622 kevent->accept();
623 }
624 }
625 }
626 }
627 if( t == TQEvent::Show && receiver->isWidgetType())
628 {
629 TQWidget* w = static_cast<TQWidget*>( receiver );
630#if defined TQ_WS_X11
631 if( w->isTopLevel() && !startupId().isEmpty() && !static_cast<TQShowEvent*>(event)->spontaneous()) // TODO better done using window group leader?
632 TDEStartupInfo::setWindowStartupId( w->winId(), startupId());
633#endif
634 if( w->isTopLevel() && !w->testWFlags( WX11BypassWM ) && !w->isPopup() && !event->spontaneous())
635 {
636 if( d->app_started_timer == NULL )
637 {
638 d->app_started_timer = new TQTimer( this, "app_started_timer" );
639 connect( d->app_started_timer, TQ_SIGNAL( timeout()), TQ_SLOT( checkAppStartedSlot()));
640 }
641 if( !d->app_started_timer->isActive())
642 d->app_started_timer->start( 0, true );
643 }
644 if( w->isTopLevel() && ( w->icon() == NULL || w->icon()->isNull()))
645 {
646 // icon() cannot be null pixmap, it'll be the "unknown" icon - so check if there is this application icon
647 static TQPixmap* ic = NULL;
648 if( ic == NULL )
649 ic = new TQPixmap( TDEGlobal::iconLoader()->loadIcon( iconName(),
650 TDEIcon::NoGroup, 0, TDEIcon::DefaultState, NULL, true ));
651 if( !ic->isNull())
652 {
653 w->setIcon( *ic );
654#if defined TQ_WS_X11
655 KWin::setIcons( w->winId(), *ic, miniIcon());
656#endif
657 }
658 }
659 }
660 return TQApplication::notify(receiver, event);
661}
662
663void TDEApplication::checkAppStartedSlot()
664{
665#if defined TQ_WS_X11
666 TDEStartupInfo::handleAutoAppStartedSending();
667#endif
668}
669
670// the help class for session management communication
671static TQPtrList<KSessionManaged>* sessionClients()
672{
673 static TQPtrList<KSessionManaged>* session_clients = 0L;
674 if ( !session_clients )
675 session_clients = new TQPtrList<KSessionManaged>;
676 return session_clients;
677}
678
679/*
680 Auxiliary function to calculate a a session config name used for the
681 instance specific config object.
682 Syntax: "session/<appname>_<sessionId>"
683 */
684TQString TDEApplication::sessionConfigName() const
685{
686 TQString sessKey = sessionKey();
687 if ( sessKey.isEmpty() && !d->sessionKey.isEmpty() )
688 sessKey = d->sessionKey;
689 return TQString("session/%1_%2_%3").arg(name()).arg(sessionId()).arg(sessKey);
690}
691
692#ifdef TQ_WS_X11
693static SmcConn mySmcConnection = 0;
694static SmcConn tmpSmcConnection = 0;
695#else
696// FIXME(E): Implement for Qt Embedded
697// Possibly "steal" XFree86's libSM?
698#endif
699static TQTime* smModificationTime = 0;
700
701TDEApplication::TDEApplication( int& argc, char** argv, const TQCString& rAppName,
702 bool allowStyles, bool GUIenabled, bool SMenabled ) :
703 TQApplication( argc, argv, GUIenabled, SMenabled ), TDEInstance(rAppName),
704#ifdef TQ_WS_X11
705 display(0L),
706 argb_visual(false),
707#endif
708 d (new TDEApplicationPrivate())
709{
710 aIconPixmap.pm.icon = 0L;
711 aIconPixmap.pm.miniIcon = 0L;
712 read_app_startup_id();
713 if (!GUIenabled)
714 allowStyles = false;
715 useStyles = allowStyles;
716 Q_ASSERT (!rAppName.isEmpty());
717 setName(rAppName);
718
719 installSigpipeHandler();
720 TDECmdLineArgs::initIgnore(argc, argv, rAppName.data());
721 parseCommandLine( );
722 init(GUIenabled);
723 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
724}
725
726// FIXME
727// FOR BINARY COMPATIBILITY ONLY
728// REMOVE WHEN PRACTICAL!
729TDEApplication::TDEApplication( int& argc, char** argv, const TQCString& rAppName,
730 bool allowStyles, bool GUIenabled ) :
731 TQApplication( argc, argv, GUIenabled ), TDEInstance(rAppName),
732#ifdef TQ_WS_X11
733 display(0L),
734 argb_visual(false),
735#endif
736 d (new TDEApplicationPrivate())
737{
738 aIconPixmap.pm.icon = 0L;
739 aIconPixmap.pm.miniIcon = 0L;
740 read_app_startup_id();
741 if (!GUIenabled)
742 allowStyles = false;
743 useStyles = allowStyles;
744 Q_ASSERT (!rAppName.isEmpty());
745 setName(rAppName);
746
747 installSigpipeHandler();
748 TDECmdLineArgs::initIgnore(argc, argv, rAppName.data());
749 parseCommandLine( );
750 init(GUIenabled);
751 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
752}
753
754TDEApplication::TDEApplication( bool allowStyles, bool GUIenabled, bool SMenabled ) :
755 TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), GUIenabled, SMenabled ), // We need to be able to run command line apps
756 TDEInstance( TDECmdLineArgs::about),
757#ifdef TQ_WS_X11
758 display(0L),
759 argb_visual(false),
760#endif
761 d (new TDEApplicationPrivate)
762{
763 aIconPixmap.pm.icon = 0L;
764 aIconPixmap.pm.miniIcon = 0L;
765 read_app_startup_id();
766 if (!GUIenabled)
767 allowStyles = false;
768 useStyles = allowStyles;
769 setName( instanceName() );
770
771 installSigpipeHandler();
772 parseCommandLine( );
773 init(GUIenabled);
774 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
775}
776
777// FIXME
778// FOR BINARY COMPATIBILITY ONLY
779// REMOVE WHEN PRACTICAL!
780TDEApplication::TDEApplication( bool allowStyles, bool GUIenabled ) :
781 TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(), GUIenabled ), // We need to be able to run command line apps
782 TDEInstance( TDECmdLineArgs::about),
783#ifdef TQ_WS_X11
784 display(0L),
785 argb_visual(false),
786#endif
787 d (new TDEApplicationPrivate)
788{
789 aIconPixmap.pm.icon = 0L;
790 aIconPixmap.pm.miniIcon = 0L;
791 read_app_startup_id();
792 if (!GUIenabled)
793 allowStyles = false;
794 useStyles = allowStyles;
795 setName( instanceName() );
796
797 installSigpipeHandler();
798 parseCommandLine( );
799 init(GUIenabled);
800 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
801}
802
803#ifdef TQ_WS_X11
804TDEApplication::TDEApplication( Display *dpy, bool allowStyles ) :
805 TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(),
806 getX11RGBAVisual(dpy), getX11RGBAColormap(dpy) ),
807 TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate)
808{
809 aIconPixmap.pm.icon = 0L;
810 aIconPixmap.pm.miniIcon = 0L;
811 read_app_startup_id();
812 useStyles = allowStyles;
813 setName( instanceName() );
814 installSigpipeHandler();
815 parseCommandLine( );
816 init( true );
817 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
818}
819
820TDEApplication::TDEApplication( Display *dpy, bool disable_argb, TQt::HANDLE visual, TQt::HANDLE colormap, bool allowStyles ) :
821 TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(),
822 disable_argb?visual:getX11RGBAVisual(dpy), disable_argb?colormap:getX11RGBAColormap(dpy) ),
823 TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate)
824{
825 aIconPixmap.pm.icon = 0L;
826 aIconPixmap.pm.miniIcon = 0L;
827 read_app_startup_id();
828 useStyles = allowStyles;
829 if (disable_argb) argb_visual = false;
830 setName( instanceName() );
831 installSigpipeHandler();
832 parseCommandLine( );
833 init( true );
834 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
835}
836
837TDEApplication::TDEApplication( Display *dpy, TQt::HANDLE visual, TQt::HANDLE colormap,
838 bool allowStyles ) :
839 TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(),
840 visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ),
841 TDEInstance( TDECmdLineArgs::about), display(0L), d (new TDEApplicationPrivate)
842{
843 if ((visual) && (colormap))
844 getX11RGBAInformation(dpy);
845 aIconPixmap.pm.icon = 0L;
846 aIconPixmap.pm.miniIcon = 0L;
847 read_app_startup_id();
848 useStyles = allowStyles;
849 setName( instanceName() );
850 installSigpipeHandler();
851 parseCommandLine( );
852 init( true );
853 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
854}
855
856TDEApplication::TDEApplication( Display *dpy, TQt::HANDLE visual, TQt::HANDLE colormap,
857 bool allowStyles, TDEInstance * _instance ) :
858 TQApplication( dpy, *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(),
859 visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ),
860 TDEInstance( _instance ), display(0L), d (new TDEApplicationPrivate)
861{
862 if ((visual) && (colormap))
863 getX11RGBAInformation(dpy);
864 aIconPixmap.pm.icon = 0L;
865 aIconPixmap.pm.miniIcon = 0L;
866 read_app_startup_id();
867 useStyles = allowStyles;
868 setName( instanceName() );
869 installSigpipeHandler();
870 parseCommandLine( );
871 init( true );
872 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
873}
874#endif
875
876TDEApplication::TDEApplication( bool allowStyles, bool GUIenabled, TDEInstance* _instance ) :
877 TQApplication( *TDECmdLineArgs::tqt_argc(), *TDECmdLineArgs::tqt_argv(),
878 GUIenabled ),
879 TDEInstance( _instance ),
880#ifdef TQ_WS_X11
881 display(0L),
882#endif
883 argb_visual(false),
884 d (new TDEApplicationPrivate)
885{
886 aIconPixmap.pm.icon = 0L;
887 aIconPixmap.pm.miniIcon = 0L;
888 read_app_startup_id();
889 if (!GUIenabled)
890 allowStyles = false;
891 useStyles = allowStyles;
892 setName( instanceName() );
893
894 installSigpipeHandler();
895 parseCommandLine( );
896 init(GUIenabled);
897 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
898}
899
900#ifdef TQ_WS_X11
901TDEApplication::TDEApplication(Display *display, int& argc, char** argv, const TQCString& rAppName,
902 bool allowStyles, bool GUIenabled ) :
903 TQApplication( display ), TDEInstance(rAppName),
904 display(0L),
905 argb_visual(false),
906 d (new TDEApplicationPrivate())
907{
908 aIconPixmap.pm.icon = 0L;
909 aIconPixmap.pm.miniIcon = 0L;
910 read_app_startup_id();
911 if (!GUIenabled)
912 allowStyles = false;
913 useStyles = allowStyles;
914
915 Q_ASSERT (!rAppName.isEmpty());
916 setName(rAppName);
917
918 installSigpipeHandler();
919 TDECmdLineArgs::initIgnore(argc, argv, rAppName.data());
920 parseCommandLine( );
921 init(GUIenabled);
922 d->m_TDEAppDCOPInterface = new TDEAppDCOPInterface(this);
923}
924#endif
925
926int TDEApplication::xioErrhandler( Display* dpy )
927{
928 if(tdeApp)
929 {
930 emit shutDown();
931#ifdef TQ_WS_X11
932 d->oldXIOErrorHandler( dpy );
933#else
934 Q_UNUSED(dpy);
935#endif
936 }
937 exit( 1 );
938 return 0;
939}
940
941int TDEApplication::xErrhandler( Display* dpy, void* err_ )
942{ // no idea how to make forward decl. for XErrorEvent
943#ifdef TQ_WS_X11
944 XErrorEvent* err = static_cast< XErrorEvent* >( err_ );
945 if(tdeApp)
946 {
947 // add KDE specific stuff here
948 d->oldXErrorHandler( dpy, err );
949 }
950#endif
951 return 0;
952}
953
954void TDEApplication::iceIOErrorHandler( _IceConn *conn )
955{
956 emit shutDown();
957
958#ifdef TQ_WS_X11
959 if ( d->oldIceIOErrorHandler != NULL )
960 (*d->oldIceIOErrorHandler)( conn );
961#endif
962 exit( 1 );
963}
964
965class KDETranslator : public TQTranslator
966{
967public:
968 KDETranslator(TQObject *parent) : TQTranslator(parent, "kdetranslator") {}
969 virtual TQTranslatorMessage findMessage(const char* context,
970 const char *sourceText,
971 const char* message) const
972 {
973 TQTranslatorMessage res;
974 res.setTranslation(TDEGlobal::locale()->translateQt(context, sourceText, message));
975 return res;
976 }
977};
978
979void TDEApplication::init(bool GUIenabled)
980{
981 d->guiEnabled = GUIenabled;
982 if ((getuid() != geteuid()) ||
983 (getgid() != getegid()) )
984 {
985 // man permissions are not exploitable and better than
986 // world writable directories
987 struct group *man = getgrnam("man");
988 if ( !man || man->gr_gid != getegid() ){
989 fprintf(stderr, "The TDE libraries are not designed to run with suid privileges.\n");
990 ::exit(127);
991 }
992 }
993
994 TDEProcessController::ref();
995
996 (void) TDEClipboardSynchronizer::self();
997
998 TQApplication::setDesktopSettingsAware( false );
999
1000 TDEApp = this;
1001
1002
1003#ifdef TQ_WS_X11 //FIXME(E)
1004 // create all required atoms in _one_ roundtrip to the X server
1005 if ( GUIenabled ) {
1006 const int max = 20;
1007 Atom* atoms[max];
1008 char* names[max];
1009 Atom atoms_return[max];
1010 int n = 0;
1011
1012 atoms[n] = &kipcCommAtom;
1013 names[n++] = (char *) "KIPC_COMM_ATOM";
1014
1015 atoms[n] = &atom_DesktopWindow;
1016 names[n++] = (char *) "KDE_DESKTOP_WINDOW";
1017
1018 atoms[n] = &atom_NetSupported;
1019 names[n++] = (char *) "_NET_SUPPORTED";
1020
1021 XInternAtoms( tqt_xdisplay(), names, n, false, atoms_return );
1022
1023 for (int i = 0; i < n; i++ )
1024 *atoms[i] = atoms_return[i];
1025 }
1026#endif
1027
1028 dcopAutoRegistration();
1029 dcopClientPostInit();
1030
1031 smw = 0;
1032
1033 // Initial KIPC event mask.
1034#if defined TQ_WS_X11
1035 kipcEventMask = (1 << KIPC::StyleChanged) | (1 << KIPC::PaletteChanged) |
1036 (1 << KIPC::FontChanged) | (1 << KIPC::BackgroundChanged) |
1037 (1 << KIPC::ToolbarStyleChanged) | (1 << KIPC::SettingsChanged) |
1038 (1 << KIPC::ClipboardConfigChanged) | (1 << KIPC::BlockShortcuts);
1039#endif
1040
1041 // Trigger creation of locale.
1042 (void) TDEGlobal::locale();
1043
1044 TDEConfig* config = TDEGlobal::config();
1045 d->actionRestrictions = config->hasGroup("KDE Action Restrictions" ) && !kde_kiosk_exception;
1046 // For brain-dead configurations where the user's local config file is not writable.
1047 // * We use kdialog to warn the user, so we better not generate warnings from
1048 // kdialog itself.
1049 // * Don't warn if we run with a read-only $HOME
1050 TQCString readOnly = getenv("TDE_HOME_READONLY");
1051 if (readOnly.isEmpty() && (qstrcmp(name(), "kdialog") != 0))
1052 {
1053 TDEConfigGroupSaver saver(config, "KDE Action Restrictions");
1054 if (config->readBoolEntry("warn_unwritable_config",true))
1055 config->checkConfigFilesWritable(true);
1056 }
1057
1058 if (GUIenabled)
1059 {
1060#ifdef TQ_WS_X11
1061 // this is important since we fork() to launch the help (Matthias)
1062 fcntl(ConnectionNumber(tqt_xdisplay()), F_SETFD, FD_CLOEXEC);
1063 // set up the fancy (=robust and error ignoring ) KDE xio error handlers (Matthias)
1064 d->oldXErrorHandler = XSetErrorHandler( kde_x_errhandler );
1065 d->oldXIOErrorHandler = XSetIOErrorHandler( kde_xio_errhandler );
1066#endif
1067
1068 connect( this, TQ_SIGNAL( aboutToQuit() ), this, TQ_SIGNAL( shutDown() ) );
1069
1070#ifdef TQ_WS_X11 //FIXME(E)
1071 display = desktop()->x11Display();
1072#endif
1073
1074 {
1075 TQStringList plugins = TDEGlobal::dirs()->resourceDirs( "tqtplugins" );
1076 TQStringList::Iterator it = plugins.begin();
1077 while (it != plugins.end()) {
1078 addLibraryPath( *it );
1079 ++it;
1080 }
1081
1082 }
1083 tdedisplaySetStyle();
1084 tdedisplaySetFont();
1085// tdedisplaySetPalette(); done by tdedisplaySetStyle
1086 propagateSettings(SETTINGS_QT);
1087
1088 // Set default mime-source factory
1089 // XXX: This is a hack. Make our factory the default factory, but add the
1090 // previous default factory to the list of factories. Why? When the default
1091 // factory can't resolve something, it iterates in the list of factories.
1092 // But it TQWhatsThis only uses the default factory. So if there was already
1093 // a default factory (which happens when using an image library using uic),
1094 // we prefer KDE's factory and so we put that old default factory in the
1095 // list and use KDE as the default. This may speed up things as well.
1096 TQMimeSourceFactory* oldDefaultFactory = TQMimeSourceFactory::takeDefaultFactory();
1097 TQMimeSourceFactory::setDefaultFactory( mimeSourceFactory() );
1098 if ( oldDefaultFactory ) {
1099 TQMimeSourceFactory::addFactory( oldDefaultFactory );
1100 }
1101
1102 d->checkAccelerators = new KCheckAccelerators( this );
1103 }
1104
1105#ifdef TQ_WS_MACX
1106 if (GUIenabled) {
1107 TQPixmap pixmap = TDEGlobal::iconLoader()->loadIcon( TDECmdLineArgs::appName(),
1108 TDEIcon::NoGroup, TDEIcon::SizeLarge, TDEIcon::DefaultState, 0L, false );
1109 if (!pixmap.isNull()) {
1110 TQImage i = pixmap.convertToImage().convertDepth(32).smoothScale(40, 40);
1111 for(int y = 0; y < i.height(); y++) {
1112 uchar *l = i.scanLine(y);
1113 for(int x = 0; x < i.width(); x+=4)
1114 *(l+x) = 255;
1115 }
1116 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
1117 CGDataProviderRef dp = CGDataProviderCreateWithData(NULL,
1118 i.bits(), i.numBytes(), NULL);
1119 CGImageRef ir = CGImageCreate(i.width(), i.height(), 8, 32, i.bytesPerLine(),
1120 cs, kCGImageAlphaNoneSkipFirst, dp,
1121 0, 0, kCGRenderingIntentDefault);
1122 //cleanup
1123 SetApplicationDockTileImage(ir);
1124 CGImageRelease(ir);
1125 CGColorSpaceRelease(cs);
1126 CGDataProviderRelease(dp);
1127 }
1128 }
1129#endif
1130
1131
1132 // save and restore the RTL setting, as installTranslator calls qt_detectRTLLanguage,
1133 // which makes it impossible to use the -reverse cmdline switch with KDE apps
1134 bool rtl = reverseLayout();
1135 installTranslator(new KDETranslator(this));
1136 setReverseLayout( rtl );
1137 if (i18n( "_: Dear Translator! Translate this string to the string 'LTR' in "
1138 "left-to-right languages (as english) or to 'RTL' in right-to-left "
1139 "languages (such as Hebrew and Arabic) to get proper widget layout." ) == "RTL")
1140 setReverseLayout( !rtl );
1141
1142 // install appdata resource type
1143 TDEGlobal::dirs()->addResourceType("appdata", TDEStandardDirs::kde_default("data")
1144 + TQString::fromLatin1(name()) + '/');
1145 pSessionConfig = 0L;
1146 bSessionManagement = true;
1147
1148#ifdef TQ_WS_X11
1149 // register a communication window for desktop changes (Matthias)
1150 if (GUIenabled && kde_have_kipc )
1151 {
1152 smw = new TQWidget(0,0);
1153 long data = 1;
1154 XChangeProperty(tqt_xdisplay(), smw->winId(),
1155 atom_DesktopWindow, atom_DesktopWindow,
1156 32, PropModeReplace, (unsigned char *)&data, 1);
1157 }
1158 d->oldIceIOErrorHandler = IceSetIOErrorHandler( kde_ice_ioerrorhandler );
1159#elif defined(TQ_WS_WIN)
1160 TDEApplication_init_windows(GUIenabled);
1161#else
1162 // FIXME(E): Implement for Qt Embedded
1163#endif
1164}
1165
1166static int my_system (const char *command) {
1167 int pid, status;
1168
1169 pid = fork();
1170 if (pid == -1)
1171 return -1;
1172 if (pid == 0) {
1173 const char* shell = "/bin/sh";
1174 execl(shell, shell, "-c", command, (void *)0);
1175 ::_exit(127);
1176 }
1177 do {
1178 if (waitpid(pid, &status, 0) == -1) {
1179 if (errno != EINTR)
1180 return -1;
1181 } else
1182 return status;
1183 } while(1);
1184}
1185
1186
1187DCOPClient *TDEApplication::dcopClient()
1188{
1189 if (s_DCOPClient)
1190 return s_DCOPClient;
1191
1192 s_DCOPClient = new DCOPClient();
1193 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("tde");
1194 if (args && args->isSet("dcopserver"))
1195 {
1196 s_DCOPClient->setServerAddress( args->getOption("dcopserver"));
1197 }
1198 if( tdeApp ) {
1199 connect(s_DCOPClient, TQ_SIGNAL(attachFailed(const TQString &)),
1200 tdeApp, TQ_SLOT(dcopFailure(const TQString &)));
1201 connect(s_DCOPClient, TQ_SIGNAL(blockUserInput(bool) ),
1202 tdeApp, TQ_SLOT(dcopBlockUserInput(bool)) );
1203 }
1204 else
1205 s_dcopClientNeedsPostInit = true;
1206
1207 DCOPClient::setMainClient( s_DCOPClient );
1208 return s_DCOPClient;
1209}
1210
1211void TDEApplication::dcopClientPostInit()
1212{
1213 if( s_dcopClientNeedsPostInit )
1214 {
1215 s_dcopClientNeedsPostInit = false;
1216 connect(s_DCOPClient, TQ_SIGNAL(blockUserInput(bool) ),
1217 TQ_SLOT(dcopBlockUserInput(bool)) );
1218 s_DCOPClient->bindToApp(); // Make sure we get events from the DCOPClient.
1219 }
1220}
1221
1222void TDEApplication::dcopAutoRegistration()
1223{
1224 if (autoDcopRegistration)
1225 {
1226 ( void ) dcopClient();
1227 if( dcopClient()->appId().isEmpty())
1228 dcopClient()->registerAs(name());
1229 }
1230}
1231
1232void TDEApplication::disableAutoDcopRegistration()
1233{
1234 autoDcopRegistration = false;
1235}
1236
1237TDEConfig* TDEApplication::sessionConfig()
1238{
1239 if (pSessionConfig)
1240 return pSessionConfig;
1241
1242 // create an instance specific config object
1243 pSessionConfig = new TDEConfig( sessionConfigName(), false, false);
1244 return pSessionConfig;
1245}
1246
1247void TDEApplication::ref()
1248{
1249 d->refCount++;
1250 //kdDebug() << "[tdecore-tdeapplication] TDEApplication::ref() : refCount = " << d->refCount << endl;
1251}
1252
1253void TDEApplication::deref()
1254{
1255 d->refCount--;
1256 //kdDebug() << "[tdecore-tdeapplication] TDEApplication::deref() : refCount = " << d->refCount << endl;
1257 if ( d->refCount <= 0 )
1258 quit();
1259}
1260
1261KSessionManaged::KSessionManaged()
1262{
1263 sessionClients()->remove( this );
1264 sessionClients()->append( this );
1265}
1266
1267KSessionManaged::~KSessionManaged()
1268{
1269 sessionClients()->remove( this );
1270}
1271
1272bool KSessionManaged::saveState(TQSessionManager&)
1273{
1274 return true;
1275}
1276
1277bool KSessionManaged::commitData(TQSessionManager&)
1278{
1279 return true;
1280}
1281
1282
1283void TDEApplication::disableSessionManagement() {
1284 bSessionManagement = false;
1285}
1286
1287void TDEApplication::enableSessionManagement() {
1288 bSessionManagement = true;
1289#ifdef TQ_WS_X11
1290 // Session management support in Qt/TDE is awfully broken.
1291 // If konqueror disables session management right after its startup,
1292 // and enables it later (preloading stuff), it won't be properly
1293 // saved on session shutdown.
1294 // I'm not actually sure why it doesn't work, but saveState()
1295 // doesn't seem to be called on session shutdown, possibly
1296 // because disabling session management after konqueror startup
1297 // disabled it somehow. Forcing saveState() here for this application
1298 // seems to fix it.
1299 if( mySmcConnection ) {
1300 SmcRequestSaveYourself( mySmcConnection, SmSaveLocal, False,
1301 SmInteractStyleAny,
1302 False, False );
1303
1304 // flush the request
1305 IceFlush(SmcGetIceConnection(mySmcConnection));
1306 }
1307#endif
1308}
1309
1310
1311bool TDEApplication::requestShutDown(
1312 ShutdownConfirm confirm, ShutdownType sdtype, ShutdownMode sdmode )
1313{
1314#ifdef TQ_WS_X11
1315 TQApplication::syncX();
1316 /* use ksmserver's dcop interface if necessary */
1317 if ( confirm == ShutdownConfirmYes ||
1318 sdtype != ShutdownTypeDefault ||
1319 sdmode != ShutdownModeDefault )
1320 {
1321 TQByteArray data;
1322 TQDataStream arg(data, IO_WriteOnly);
1323 arg << (int)confirm << (int)sdtype << (int)sdmode;
1324 return dcopClient()->send( "ksmserver", "ksmserver",
1325 "logout(int,int,int)", data );
1326 }
1327
1328 if ( mySmcConnection ) {
1329 // we already have a connection to the session manager, use it.
1330 SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True,
1331 SmInteractStyleAny,
1332 confirm == ShutdownConfirmNo, True );
1333
1334 // flush the request
1335 IceFlush(SmcGetIceConnection(mySmcConnection));
1336 return true;
1337 }
1338
1339 // open a temporary connection, if possible
1340
1341 propagateSessionManager();
1342 TQCString smEnv = ::getenv("SESSION_MANAGER");
1343 if (smEnv.isEmpty())
1344 return false;
1345
1346 if (! tmpSmcConnection) {
1347 char cerror[256];
1348 char* myId = 0;
1349 char* prevId = 0;
1350 SmcCallbacks cb;
1351 tmpSmcConnection = SmcOpenConnection( 0, 0, 1, 0,
1352 0, &cb,
1353 prevId,
1354 &myId,
1355 255,
1356 cerror );
1357 ::free( myId ); // it was allocated by C
1358 if (!tmpSmcConnection )
1359 return false;
1360 }
1361
1362 SmcRequestSaveYourself( tmpSmcConnection, SmSaveBoth, True,
1363 SmInteractStyleAny, False, True );
1364
1365 // flush the request
1366 IceFlush(SmcGetIceConnection(tmpSmcConnection));
1367 return true;
1368#else
1369 // FIXME(E): Implement for Qt Embedded
1370 return false;
1371#endif
1372}
1373
1374void TDEApplication::propagateSessionManager()
1375{
1376#ifdef TQ_WS_X11
1377 TQCString fName = TQFile::encodeName(locateLocal("socket", "KSMserver"));
1378 TQCString display = ::getenv(DISPLAY);
1379 // strip the screen number from the display
1380 display.replace(TQRegExp("\\.[0-9]+$"), "");
1381 int i;
1382 while( (i = display.find(':')) >= 0)
1383 display[i] = '_';
1384
1385 fName += "_"+display;
1386 TQCString smEnv = ::getenv("SESSION_MANAGER");
1387 bool check = smEnv.isEmpty();
1388 if ( !check && smModificationTime ) {
1389 TQFileInfo info( fName );
1390 TQTime current = info.lastModified().time();
1391 check = current > *smModificationTime;
1392 }
1393 if ( check ) {
1394 delete smModificationTime;
1395 TQFile f( fName );
1396 if ( !f.open( IO_ReadOnly ) )
1397 return;
1398 TQFileInfo info ( f );
1399 smModificationTime = new TQTime( info.lastModified().time() );
1400 TQTextStream t(&f);
1401 t.setEncoding( TQTextStream::Latin1 );
1402 TQString s = t.readLine();
1403 f.close();
1404 ::setenv( "SESSION_MANAGER", s.latin1(), true );
1405 }
1406#endif
1407}
1408
1409void TDEApplication::commitData( TQSessionManager& sm )
1410{
1411 d->session_save = true;
1412 bool canceled = false;
1413 for (KSessionManaged* it = sessionClients()->first();
1414 it && !canceled;
1415 it = sessionClients()->next() ) {
1416 canceled = !it->commitData( sm );
1417 }
1418 if ( canceled )
1419 sm.cancel();
1420
1421 if ( sm.allowsInteraction() ) {
1422 TQWidgetList done;
1423 TQWidgetList *list = TQApplication::topLevelWidgets();
1424 bool canceled = false;
1425 TQWidget* w = list->first();
1426 while ( !canceled && w ) {
1427 if ( !w->testWState( WState_ForceHide ) && !w->inherits("TDEMainWindow") ) {
1428 TQCloseEvent e;
1429 sendEvent( w, &e );
1430 canceled = !e.isAccepted();
1431 if ( !canceled )
1432 done.append( w );
1433 delete list; // one never knows...
1434 list = TQApplication::topLevelWidgets();
1435 w = list->first();
1436 } else {
1437 w = list->next();
1438 }
1439 while ( w && done.containsRef( w ) )
1440 w = list->next();
1441 }
1442 delete list;
1443 }
1444
1445
1446 if ( !bSessionManagement )
1447 sm.setRestartHint( TQSessionManager::RestartNever );
1448 else
1449 sm.setRestartHint( TQSessionManager::RestartIfRunning );
1450 d->session_save = false;
1451}
1452
1453static void checkRestartVersion( TQSessionManager& sm )
1454{
1455 Display* dpy = tqt_xdisplay();
1456 Atom type;
1457 int format;
1458 unsigned long nitems, after;
1459 unsigned char* data;
1460 if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy, "TDE_FULL_SESSION", False ),
1461 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) {
1462 if( data != NULL )
1463 XFree( data );
1464 if( type == XA_STRING && format == 8 ) { // session set, check if TDE_SESSION_VERSION is not set (meaning KDE3)
1465 if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy, "TDE_SESSION_VERSION", False ),
1466 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) {
1467 if( data != NULL )
1468 XFree( data ); // KDE4 or newer
1469 if( type == None )
1470 return; // we run in our native session, no need to wrap
1471 } else {
1472 return; // we run in our native session, no need to wrap
1473 }
1474 }
1475 }
1476 TQString wrapper = TDEStandardDirs::findExe( "trinity" );
1477 TQStringList restartCommand = sm.restartCommand();
1478 restartCommand.prepend( wrapper );
1479 sm.setRestartCommand( restartCommand );
1480}
1481
1482void TDEApplication::saveState( TQSessionManager& sm )
1483{
1484 d->session_save = true;
1485#ifdef TQ_WS_X11
1486 static bool firstTime = true;
1487 mySmcConnection = (SmcConn) sm.handle();
1488
1489 if ( !bSessionManagement ) {
1490 sm.setRestartHint( TQSessionManager::RestartNever );
1491 d->session_save = false;
1492 return;
1493 }
1494 else
1495 sm.setRestartHint( TQSessionManager::RestartIfRunning );
1496
1497 if ( firstTime ) {
1498 firstTime = false;
1499 d->session_save = false;
1500 return; // no need to save the state.
1501 }
1502
1503 // remove former session config if still existing, we want a new
1504 // and fresh one. Note that we do not delete the config file here,
1505 // this is done by the session manager when it executes the
1506 // discard commands. In fact it would be harmful to remove the
1507 // file here, as the session might be stored under a different
1508 // name, meaning the user still might need it eventually.
1509 if ( pSessionConfig ) {
1510 delete pSessionConfig;
1511 pSessionConfig = 0;
1512 }
1513
1514 // tell the session manager about our new lifecycle
1515 TQStringList restartCommand = sm.restartCommand();
1516
1517 TQCString multiHead = getenv("TDE_MULTIHEAD");
1518 if (multiHead.lower() == "true") {
1519 // if multihead is enabled, we save our -display argument so that
1520 // we are restored onto the correct head... one problem with this
1521 // is that the display is hard coded, which means we cannot restore
1522 // to a different display (ie. if we are in a university lab and try,
1523 // try to restore a multihead session, our apps could be started on
1524 // someone else's display instead of our own)
1525 TQCString displayname = getenv(DISPLAY);
1526 if (! displayname.isNull()) {
1527 // only store the command if we actually have a DISPLAY
1528 // environment variable
1529 restartCommand.append("-display");
1530 restartCommand.append(displayname);
1531 }
1532 sm.setRestartCommand( restartCommand );
1533 }
1534
1535 checkRestartVersion( sm );
1536
1537 // finally: do session management
1538 emit saveYourself(); // for compatibility
1539 bool canceled = false;
1540 for (KSessionManaged* it = sessionClients()->first();
1541 it && !canceled;
1542 it = sessionClients()->next() ) {
1543 canceled = !it->saveState( sm );
1544 }
1545
1546 // if we created a new session config object, register a proper discard command
1547 if ( pSessionConfig ) {
1548 pSessionConfig->sync();
1549 TQStringList discard;
1550 discard << "rm" << locateLocal("config", sessionConfigName());
1551 sm.setDiscardCommand( discard );
1552 } else {
1553 sm.setDiscardCommand( TQStringList("") );
1554 }
1555
1556 if ( canceled )
1557 sm.cancel();
1558#else
1559 // FIXME(E): Implement for Qt Embedded
1560#endif
1561 d->session_save = false;
1562}
1563
1564bool TDEApplication::sessionSaving() const
1565{
1566 return d->session_save;
1567}
1568
1569void TDEApplication::startKdeinit()
1570{
1571#ifndef TQ_WS_WIN //TODO
1572 TDEInstance inst( "starttdeinitlock" );
1573 TDELockFile lock( locateLocal( "tmp", "starttdeinitlock", &inst ));
1574 if( lock.lock( TDELockFile::LockNoBlock ) != TDELockFile::LockOK ) {
1575 lock.lock();
1576 DCOPClient cl;
1577 if( cl.attach())
1578 return; // whoever held the lock has already started dcopserver
1579 }
1580 // Try to launch tdeinit.
1581 TQString srv = TDEStandardDirs::findExe(TQString::fromLatin1("tdeinit"));
1582 if (srv.isEmpty())
1583 srv = TDEStandardDirs::findExe(TQString::fromLatin1("tdeinit"), TDEGlobal::dirs()->kfsstnd_defaultbindir());
1584 if (srv.isEmpty())
1585 return;
1586 if (tdeApp && (Tty != tdeApp->type()))
1587 setOverrideCursor( TQt::waitCursor );
1588 my_system(TQFile::encodeName(srv)+" --suicide"+" --new-startup");
1589 if (tdeApp && (Tty != tdeApp->type()))
1590 restoreOverrideCursor();
1591#endif
1592}
1593
1594void TDEApplication::dcopFailure(const TQString &msg)
1595{
1596 static int failureCount = 0;
1597 failureCount++;
1598 if (failureCount == 1)
1599 {
1600 startKdeinit();
1601 return;
1602 }
1603 if (failureCount == 2)
1604 {
1605#ifdef TQ_WS_WIN
1606 TDEGlobal::config()->setGroup("General");
1607 if (TDEGlobal::config()->readBoolEntry("ignoreDCOPFailures", false))
1608 return;
1609#endif
1610 TQString msgStr(i18n("There was an error setting up inter-process "
1611 "communications for TDE. The message returned "
1612 "by the system was:\n\n"));
1613 msgStr += msg;
1614 msgStr += i18n("\n\nPlease check that the \"dcopserver\" program is running!");
1615
1616 if (Tty != tdeApp->type())
1617 {
1618 TQMessageBox::critical
1619 (
1620 tdeApp->mainWidget(),
1621 i18n("DCOP communications error (%1)").arg(tdeApp->caption()),
1622 msgStr,
1623 i18n("&OK")
1624 );
1625 }
1626 else
1627 {
1628 fprintf(stderr, "%s\n", msgStr.local8Bit().data());
1629 }
1630
1631 return;
1632 }
1633}
1634
1635static const TDECmdLineOptions qt_options[] =
1636{
1637 //FIXME: Check if other options are specific to Qt/X11
1638#ifdef TQ_WS_X11
1639 { "display <displayname>", I18N_NOOP("Use the X-server display 'displayname'"), 0},
1640#else
1641 { "display <displayname>", I18N_NOOP("Use the QWS display 'displayname'"), 0},
1642#endif
1643 { "session <sessionId>", I18N_NOOP("Restore the application for the given 'sessionId'"), 0},
1644 { "cmap", I18N_NOOP("Causes the application to install a private color\nmap on an 8-bit display"), 0},
1645 { "ncols <count>", I18N_NOOP("Limits the number of colors allocated in the color\ncube on an 8-bit display, if the application is\nusing the TQApplication::ManyColor color\nspecification"), 0},
1646 { "nograb", I18N_NOOP("tells TQt to never grab the mouse or the keyboard"), 0},
1647 { "dograb", I18N_NOOP("running under a debugger can cause an implicit\n-nograb, use -dograb to override"), 0},
1648 { "sync", I18N_NOOP("switches to synchronous mode for debugging"), 0},
1649 { "fn", 0, 0},
1650 { "font <fontname>", I18N_NOOP("defines the application font"), 0},
1651 { "bg", 0, 0},
1652 { "background <color>", I18N_NOOP("sets the default background color and an\napplication palette (light and dark shades are\ncalculated)"), 0},
1653 { "fg", 0, 0},
1654 { "foreground <color>", I18N_NOOP("sets the default foreground color"), 0},
1655 { "btn", 0, 0},
1656 { "button <color>", I18N_NOOP("sets the default button color"), 0},
1657 { "name <name>", I18N_NOOP("sets the application name"), 0},
1658 { "title <title>", I18N_NOOP("sets the application title (caption)"), 0},
1659#ifdef TQ_WS_X11
1660 { "visual TrueColor", I18N_NOOP("forces the application to use a TrueColor visual on\nan 8-bit display"), 0},
1661 { "inputstyle <inputstyle>", I18N_NOOP("sets XIM (X Input Method) input style. Possible\nvalues are onthespot, overthespot, offthespot and\nroot"), 0 },
1662 { "im <XIM server>", I18N_NOOP("set XIM server"),0},
1663 { "noxim", I18N_NOOP("disable XIM"), 0 },
1664#endif
1665#ifdef TQ_WS_QWS
1666 { "qws", I18N_NOOP("forces the application to run as QWS Server"), 0},
1667#endif
1668 { "reverse", I18N_NOOP("mirrors the whole layout of widgets"), 0},
1669 TDECmdLineLastOption
1670};
1671
1672static const TDECmdLineOptions kde_options[] =
1673{
1674 { "caption <caption>", I18N_NOOP("Use 'caption' as name in the titlebar"), 0},
1675 { "icon <icon>", I18N_NOOP("Use 'icon' as the application icon"), 0},
1676 { "miniicon <icon>", I18N_NOOP("Use 'icon' as the icon in the titlebar"), 0},
1677 { "config <filename>", I18N_NOOP("Use alternative configuration file"), 0},
1678 { "dcopserver <server>", I18N_NOOP("Use the DCOP Server specified by 'server'"), 0},
1679 { "nocrashhandler", I18N_NOOP("Disable crash handler, to get core dumps"), 0},
1680 { "waitforwm", I18N_NOOP("Waits for a WM_NET compatible windowmanager"), 0},
1681 { "style <style>", I18N_NOOP("sets the application GUI style"), 0},
1682 { "geometry <geometry>", I18N_NOOP("sets the client geometry of the main widget - see man X for the argument format"), 0},
1683 { "smkey <sessionKey>", 0, 0}, // this option is obsolete and exists only to allow smooth upgrades from sessions
1684 // saved under Qt 3.0.x -- Qt 3.1.x includes the session key now automatically in
1685 // the session id (Simon)
1686 TDECmdLineLastOption
1687};
1688
1689void
1690TDEApplication::addCmdLineOptions()
1691{
1692 TDECmdLineArgs::addCmdLineOptions(qt_options, "Qt", "qt");
1693 TDECmdLineArgs::addCmdLineOptions(kde_options, "TDE", "tde");
1694}
1695
1696void TDEApplication::parseCommandLine( )
1697{
1698 TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs("tde");
1699
1700 if ( !args ) return;
1701
1702 if (args->isSet("config"))
1703 {
1704 TQString config = TQString::fromLocal8Bit(args->getOption("config"));
1705 setConfigName(config);
1706 }
1707
1708 if (args->isSet("style"))
1709 {
1710
1711 TQStringList plugins = TDEGlobal::dirs()->resourceDirs( "tqtplugins" );
1712 TQStringList::Iterator itp = plugins.begin();
1713 while (itp != plugins.end()) {
1714 addLibraryPath( *itp );
1715 ++itp;
1716 }
1717
1718 TQStringList styles = TQStyleFactory::keys();
1719 TQString reqStyle(args->getOption("style").lower());
1720
1721 TQStringList list = libraryPaths();
1722 TQStringList::Iterator it = list.begin();
1723 while( it != list.end() ) {
1724 ++it;
1725 }
1726
1727 for (TQStringList::ConstIterator it = styles.begin(); it != styles.end(); ++it) {
1728 if ((*it).lower() == reqStyle)
1729 {
1730 d->overrideStyle = *it;
1731 break;
1732 }
1733 }
1734
1735 if (d->overrideStyle.isEmpty())
1736 fprintf(stderr, "%s", TQString(i18n("The style %1 was not found\n").arg(reqStyle)).local8Bit().data());
1737 }
1738
1739 if (args->isSet("caption"))
1740 {
1741 aCaption = TQString::fromLocal8Bit(args->getOption("caption"));
1742 }
1743
1744 if (args->isSet("miniicon"))
1745 {
1746 const char *tmp = args->getOption("miniicon");
1747 if (!aIconPixmap.pm.miniIcon) {
1748 aIconPixmap.pm.miniIcon = new TQPixmap;
1749 }
1750 *aIconPixmap.pm.miniIcon = SmallIcon(tmp);
1751 aMiniIconName = tmp;
1752 }
1753
1754 if (args->isSet("icon"))
1755 {
1756 const char *tmp = args->getOption("icon");
1757 if (!aIconPixmap.pm.icon) {
1758 aIconPixmap.pm.icon = new TQPixmap;
1759 }
1760 *aIconPixmap.pm.icon = DesktopIcon( tmp );
1761 aIconName = tmp;
1762 if (!aIconPixmap.pm.miniIcon) {
1763 aIconPixmap.pm.miniIcon = new TQPixmap;
1764 }
1765 if (aIconPixmap.pm.miniIcon->isNull())
1766 {
1767 *aIconPixmap.pm.miniIcon = SmallIcon( tmp );
1768 aMiniIconName = tmp;
1769 }
1770 }
1771
1772 bool nocrashhandler = (getenv("TDE_DEBUG") != NULL);
1773 if (!nocrashhandler && args->isSet("crashhandler"))
1774 {
1775 // set default crash handler / set emergency save function to nothing
1776 TDECrash::setCrashHandler(TDECrash::defaultCrashHandler);
1777 TDECrash::setEmergencySaveFunction(NULL);
1778
1779 TDECrash::setApplicationName(TQString(args->appName()));
1780 }
1781
1782#ifdef TQ_WS_X11
1783 if ( args->isSet( "waitforwm" ) ) {
1784 Atom type;
1785 (void) desktop(); // trigger desktop creation, we need PropertyNotify events for the root window
1786 int format;
1787 unsigned long length, after;
1788 unsigned char *data;
1789 while ( XGetWindowProperty( tqt_xdisplay(), tqt_xrootwin(), atom_NetSupported,
1790 0, 1, false, AnyPropertyType, &type, &format,
1791 &length, &after, &data ) != Success || !length ) {
1792 if ( data )
1793 XFree( data );
1794 XEvent event;
1795 XWindowEvent( tqt_xdisplay(), tqt_xrootwin(), PropertyChangeMask, &event );
1796 }
1797 if ( data )
1798 XFree( data );
1799 }
1800#else
1801 // FIXME(E): Implement for Qt Embedded
1802#endif
1803
1804 if (args->isSet("geometry"))
1805 {
1806 d->geometry_arg = args->getOption("geometry");
1807 }
1808
1809 if (args->isSet("smkey"))
1810 {
1811 d->sessionKey = args->getOption("smkey");
1812 }
1813
1814}
1815
1816TQString TDEApplication::geometryArgument() const
1817{
1818 return d->geometry_arg;
1819}
1820
1821TQPixmap TDEApplication::icon() const
1822{
1823 if( !aIconPixmap.pm.icon) {
1824 aIconPixmap.pm.icon = new TQPixmap;
1825 }
1826 if( aIconPixmap.pm.icon->isNull()) {
1827 *aIconPixmap.pm.icon = DesktopIcon( instanceName() );
1828 }
1829 return *aIconPixmap.pm.icon;
1830}
1831
1832TQString TDEApplication::iconName() const
1833{
1834 return aIconName.isNull() ? (TQString)instanceName() : aIconName;
1835}
1836
1837TQPixmap TDEApplication::miniIcon() const
1838{
1839 if (!aIconPixmap.pm.miniIcon) {
1840 aIconPixmap.pm.miniIcon = new TQPixmap;
1841 }
1842 if (aIconPixmap.pm.miniIcon->isNull()) {
1843 *aIconPixmap.pm.miniIcon = SmallIcon( instanceName() );
1844 }
1845 return *aIconPixmap.pm.miniIcon;
1846}
1847
1848TQString TDEApplication::miniIconName() const
1849{
1850 return aMiniIconName.isNull() ? (TQString)instanceName() : aMiniIconName;
1851}
1852
1853extern void kDebugCleanup();
1854
1855TDEApplication::~TDEApplication()
1856{
1857 delete aIconPixmap.pm.miniIcon;
1858 aIconPixmap.pm.miniIcon = 0L;
1859 delete aIconPixmap.pm.icon;
1860 aIconPixmap.pm.icon = 0L;
1861 delete d->m_TDEAppDCOPInterface;
1862
1863 // First call the static deleters and then call KLibLoader::cleanup()
1864 // The static deleters may delete libraries for which they need KLibLoader.
1865 // KLibLoader will take care of the remaining ones.
1866 TDEGlobal::deleteStaticDeleters();
1867 KLibLoader::cleanUp();
1868
1869 delete smw;
1870
1871 // close down IPC
1872 delete s_DCOPClient;
1873 s_DCOPClient = nullptr;
1874
1875 TDEProcessController::deref();
1876
1877#ifdef TQ_WS_X11
1878 if ( d->oldXErrorHandler != NULL )
1879 XSetErrorHandler( d->oldXErrorHandler );
1880 if ( d->oldXIOErrorHandler != NULL )
1881 XSetIOErrorHandler( d->oldXIOErrorHandler );
1882 if ( d->oldIceIOErrorHandler != NULL )
1883 IceSetIOErrorHandler( d->oldIceIOErrorHandler );
1884#endif
1885
1886 delete d;
1887 TDEApp = nullptr;
1888
1889#ifdef TQ_WS_X11
1890 mySmcConnection = 0;
1891 delete smModificationTime;
1892 smModificationTime = 0;
1893
1894 // close the temporary smc connection
1895 if (tmpSmcConnection) {
1896 SmcCloseConnection( tmpSmcConnection, 0, 0 );
1897 tmpSmcConnection = 0;
1898 }
1899#else
1900 // FIXME(E): Implement for Qt Embedded
1901#endif
1902}
1903
1904
1905#ifdef TQ_WS_X11
1906class KAppX11HackWidget: public TQWidget
1907{
1908public:
1909 bool publicx11Event( XEvent * e) { return x11Event( e ); }
1910};
1911#endif
1912
1913#if defined(TQ_WS_X11) && defined(COMPOSITE)
1914bool TDEApplication::isCompositionManagerAvailable() {
1915 bool have_manager = false;
1916
1917 char *filename;
1918 const char *pidfile = "compton-tde.available";
1919 char uidstr[sizeof(uid_t)*8+1];
1920 sprintf(uidstr, "%d", getuid());
1921 int n = strlen(P_tmpdir)+strlen(uidstr)+strlen(pidfile)+3;
1922 filename = (char*)malloc(n*sizeof(char)+1);
1923 memset(filename,0,n);
1924 strcat(filename, P_tmpdir);
1925 strcat(filename, "/.");
1926 strcat(filename, uidstr);
1927 strcat(filename, "-");
1928 strcat(filename, pidfile);
1929
1930 // Now that we did all that by way of introduction...read the file!
1931 FILE *pFile;
1932 pFile = fopen(filename, "r");
1933 if (pFile) {
1934 have_manager = true;
1935 fclose(pFile);
1936 }
1937
1938 free(filename);
1939 filename = NULL;
1940
1941 return have_manager;
1942}
1943
1944bool TDEApplication::detectCompositionManagerAvailable(bool force_available, bool available) {
1945 bool compositing_manager_available;
1946 if (force_available) {
1947 compositing_manager_available = available;
1948 }
1949 else {
1950 // See if compositing has been enabled
1951 TDECmdLineArgs *qtargs = TDECmdLineArgs::parsedArgs("qt");
1952 char *displayname = 0;
1953 if ( qtargs->isSet("display"))
1954 displayname = qtargs->getOption( "display" ).data();
1955
1956 Display *dpy = XOpenDisplay( displayname );
1957
1958 x11_composite_error_generated = false;
1959 compositing_manager_available = false;
1960 XSetErrorHandler(x11_error);
1961 if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode, &composite_event, &composite_error)) {
1962 XSetErrorHandler(NULL);
1963 compositing_manager_available = false;
1964 }
1965 else {
1966 if (available) { // FIXME This variable does double duty to avoid breaking the ABI for R14.0. In reality it should be called perform_deep_check
1967 Window root_window = XDefaultRootWindow(dpy);
1968 XCompositeRedirectSubwindows(dpy, root_window, CompositeRedirectManual);
1969 XSync(dpy, false);
1970 if (x11_composite_error_generated == true) {
1971 compositing_manager_available = true;
1972 }
1973 else {
1974 XCompositeUnredirectSubwindows(dpy, root_window, CompositeRedirectManual);
1975 compositing_manager_available = false;
1976 }
1977 XSetErrorHandler(NULL);
1978 XCloseDisplay(dpy);
1979 }
1980 else {
1981 compositing_manager_available = true;
1982 }
1983 }
1984 }
1985
1986 char *filename;
1987 const char *pidfile = "compton-tde.available";
1988 char uidstr[sizeof(uid_t)*8+1];
1989 sprintf(uidstr, "%d", getuid());
1990 int n = strlen(P_tmpdir)+strlen(uidstr)+strlen(pidfile)+3;
1991 filename = (char*)malloc(n*sizeof(char)+1);
1992 memset(filename,0,n);
1993 strcat(filename, P_tmpdir);
1994 strcat(filename, "/.");
1995 strcat(filename, uidstr);
1996 strcat(filename, "-");
1997 strcat(filename, pidfile);
1998
1999 /* now that we did all that by way of introduction...create or remove the file! */
2000 if (compositing_manager_available) {
2001 FILE *pFile;
2002 char buffer[255];
2003 sprintf(buffer, "available");
2004 pFile = fopen(filename, "w");
2005 if (pFile) {
2006 fwrite(buffer,1,strlen(buffer), pFile);
2007 fclose(pFile);
2008 }
2009 }
2010 else {
2011 unlink(filename);
2012 }
2013
2014 free(filename);
2015 filename = NULL;
2016
2017 return compositing_manager_available;
2018}
2019
2020Display* TDEApplication::openX11RGBADisplay() {
2021 TDECmdLineArgs *qtargs = TDECmdLineArgs::parsedArgs("qt");
2022 char *display = 0;
2023 if ( qtargs->isSet("display"))
2024 display = qtargs->getOption( "display" ).data();
2025
2026 Display *dpy = XOpenDisplay( display );
2027 if ( !dpy ) {
2028 kdError() << "cannot connect to X server " << display << endl;
2029 exit( 1 );
2030 }
2031
2032 return dpy;
2033}
2034
2035TQt::HANDLE TDEApplication::getX11RGBAVisual(Display *dpy) {
2036 getX11RGBAInformation(dpy);
2037 if (TDEApplication::isCompositionManagerAvailable() == true) {
2038 return argb_x11_visual;
2039 }
2040 else {
2041 return (TQt::HANDLE)NULL;
2042 }
2043}
2044
2045TQt::HANDLE TDEApplication::getX11RGBAColormap(Display *dpy) {
2046 getX11RGBAInformation(dpy);
2047 if (TDEApplication::isCompositionManagerAvailable() == true) {
2048 return argb_x11_colormap;
2049 }
2050 else {
2051 return (TQt::HANDLE)NULL;
2052 }
2053}
2054
2055bool TDEApplication::isX11CompositionAvailable() {
2056 return (argb_visual & isCompositionManagerAvailable());
2057}
2058
2059void TDEApplication::getX11RGBAInformation(Display *dpy) {
2060 if ( !dpy ) {
2061 argb_visual = false;
2062 return;
2063 }
2064
2065 int screen = DefaultScreen( dpy );
2066 Colormap colormap = 0;
2067 Visual *visual = 0;
2068 int event_base, error_base;
2069
2070 if ( XRenderQueryExtension( dpy, &event_base, &error_base ) ) {
2071 int nvi;
2072 XVisualInfo templ;
2073 templ.screen = screen;
2074 templ.depth = 32;
2075 templ.c_class = TrueColor;
2076 XVisualInfo *xvi = XGetVisualInfo( dpy, VisualScreenMask | VisualDepthMask
2077 | VisualClassMask, &templ, &nvi );
2078
2079 for ( int i = 0; i < nvi; i++ ) {
2080 XRenderPictFormat *format = XRenderFindVisualFormat( dpy, xvi[i].visual );
2081 if ( format->type == PictTypeDirect && format->direct.alphaMask ) {
2082 visual = xvi[i].visual;
2083 colormap = XCreateColormap( dpy, RootWindow( dpy, screen ), visual, AllocNone );
2084 kdDebug() << "[tdecore-tdeapplication] Found visual with alpha support" << endl;
2085 argb_visual = true;
2086 break;
2087 }
2088 }
2089 }
2090
2091 if( argb_visual ) {
2092 argb_x11_visual = TQt::HANDLE( visual );
2093 argb_x11_colormap = TQt::HANDLE( colormap );
2094 argb_visual = true;
2095 return;
2096 }
2097 argb_visual = false;
2098 return;
2099}
2100#else
2101void TDEApplication::getX11RGBAInformation(Display *dpy) {
2102}
2103
2104bool TDEApplication::isCompositionManagerAvailable() {
2105 return false;
2106}
2107
2108bool TDEApplication::detectCompositionManagerAvailable(bool force_available, bool available) {
2109 char *filename;
2110 const char *pidfile = "compton-tde.available";
2111 char uidstr[sizeof(uid_t)*8+1];
2112 sprintf(uidstr, "%d", getuid());
2113 int n = strlen(P_tmpdir)+strlen(uidstr)+strlen(pidfile)+3;
2114 filename = (char*)malloc(n*sizeof(char)+1);
2115 memset(filename,0,n);
2116 strcat(filename, P_tmpdir);
2117 strcat(filename, "/.");
2118 strcat(filename, uidstr);
2119 strcat(filename, "-");
2120 strcat(filename, pidfile);
2121
2122 /* now that we did all that by way of introduction...create or remove the file! */
2123 if (force_available) {
2124 FILE *pFile;
2125 char buffer[255];
2126 sprintf(buffer, "available");
2127 pFile = fopen(filename, "w");
2128 if (pFile) {
2129 fwrite(buffer,1,strlen(buffer), pFile);
2130 fclose(pFile);
2131 }
2132 }
2133 else {
2134 unlink(filename);
2135 }
2136
2137 free(filename);
2138 filename = NULL;
2139
2140 return false;
2141}
2142
2143Display* TDEApplication::openX11RGBADisplay() {
2144 return 0;
2145}
2146
2147TQt::HANDLE TDEApplication::getX11RGBAVisual(Display *dpy) {
2148 return 0;
2149}
2150
2151TQt::HANDLE TDEApplication::getX11RGBAColormap(Display *dpy) {
2152 return 0;
2153}
2154
2155bool TDEApplication::isX11CompositionAvailable() {
2156 return false;
2157}
2158#endif
2159
2160static bool kapp_block_user_input = false;
2161
2162void TDEApplication::dcopBlockUserInput( bool b )
2163{
2164 kapp_block_user_input = b;
2165}
2166
2167#ifdef TQ_WS_X11
2168bool TDEApplication::x11EventFilter( XEvent *_event )
2169{
2170 if ( kapp_block_user_input ) {
2171 switch ( _event->type ) {
2172 case ButtonPress:
2173 case ButtonRelease:
2174 case XKeyPress:
2175 case XKeyRelease:
2176 case MotionNotify:
2177 case EnterNotify:
2178 case LeaveNotify:
2179 return true;
2180 default:
2181 break;
2182 }
2183 }
2184
2185 if (x11Filter) {
2186 for (TQWidget *w=x11Filter->first(); w; w=x11Filter->next()) {
2187 if (((KAppX11HackWidget*) w)->publicx11Event(_event))
2188 return true;
2189 }
2190 }
2191
2192 if ((_event->type == ClientMessage) &&
2193 (_event->xclient.message_type == kipcCommAtom))
2194 {
2195 XClientMessageEvent *cme = (XClientMessageEvent *) _event;
2196
2197 int id = cme->data.l[0];
2198 int arg = cme->data.l[1];
2199 if ((id < 32) && (kipcEventMask & (1 << id)))
2200 {
2201 switch (id)
2202 {
2203 case KIPC::StyleChanged:
2204 TDEGlobal::config()->reparseConfiguration();
2205 tdedisplaySetStyle();
2206 break;
2207
2208 case KIPC::ToolbarStyleChanged:
2209 TDEGlobal::config()->reparseConfiguration();
2210 if (useStyles)
2211 emit toolbarAppearanceChanged(arg);
2212 break;
2213
2214 case KIPC::PaletteChanged:
2215 TDEGlobal::config()->reparseConfiguration();
2216 tdedisplaySetPalette();
2217 break;
2218
2219 case KIPC::FontChanged:
2220 TDEGlobal::config()->reparseConfiguration();
2221 TDEGlobalSettings::rereadFontSettings();
2222 tdedisplaySetFont();
2223 break;
2224
2225 case KIPC::BackgroundChanged:
2226 emit backgroundChanged(arg);
2227 break;
2228
2229 case KIPC::SettingsChanged:
2230 TDEGlobal::config()->reparseConfiguration();
2231 if (arg == SETTINGS_PATHS)
2232 TDEGlobalSettings::rereadPathSettings();
2233 else if (arg == SETTINGS_MOUSE)
2234 TDEGlobalSettings::rereadMouseSettings();
2235 propagateSettings((SettingsCategory)arg);
2236 break;
2237
2238 case KIPC::IconChanged:
2239 TQPixmapCache::clear();
2240 TDEGlobal::config()->reparseConfiguration();
2241 TDEGlobal::instance()->newIconLoader();
2242 emit updateIconLoaders();
2243 emit iconChanged(arg);
2244 break;
2245
2246 case KIPC::ClipboardConfigChanged:
2247 TDEClipboardSynchronizer::newConfiguration(arg);
2248 break;
2249
2250 case KIPC::BlockShortcuts:
2251 TDEGlobalAccel::blockShortcuts(arg);
2252 emit kipcMessage(id, arg); // some apps may do additional things
2253 break;
2254 }
2255 }
2256 else if (id >= 32)
2257 {
2258 emit kipcMessage(id, arg);
2259 }
2260 return true;
2261 }
2262 return false;
2263}
2264#endif // TQ_WS_X11
2265
2266void TDEApplication::updateUserTimestamp( unsigned long time )
2267{
2268#if defined TQ_WS_X11
2269 Display *display = tqt_xdisplay();
2270 if (!display) {
2271 return;
2272 }
2273 if( time == 0 )
2274 { // get current X timestamp
2275 Window w = XCreateSimpleWindow( display, tqt_xrootwin(), 0, 0, 1, 1, 0, 0, 0 );
2276 XSelectInput( tqt_xdisplay(), w, PropertyChangeMask );
2277 unsigned char data[ 1 ];
2278 XChangeProperty( display, w, XA_ATOM, XA_ATOM, 8, PropModeAppend, data, 1 );
2279 XEvent ev;
2280 XWindowEvent( display, w, PropertyChangeMask, &ev );
2281 time = ev.xproperty.time;
2282 XDestroyWindow( display, w );
2283 }
2284 if( get_tqt_x_user_time() == 0
2285 || NET::timestampCompare( time, get_tqt_x_user_time() ) > 0 ) // check time > tqt_x_user_time
2286 set_tqt_x_user_time(time);
2287#endif
2288}
2289
2290unsigned long TDEApplication::userTimestamp() const
2291{
2292#if defined TQ_WS_X11
2293 return get_tqt_x_user_time();
2294#else
2295 return 0;
2296#endif
2297}
2298
2299void TDEApplication::updateRemoteUserTimestamp( const TQCString& dcopId, unsigned long time )
2300{
2301#if defined TQ_WS_X11
2302 if( time == 0 )
2303 time = get_tqt_x_user_time();
2304 DCOPRef( dcopId, "MainApplication-Interface" ).call( "updateUserTimestamp", time );
2305#endif
2306}
2307
2308void TDEApplication::invokeEditSlot( const char *slot )
2309{
2310 TQObject *object = focusWidget();
2311 if( !object )
2312 return;
2313
2314 TQMetaObject *meta = object->metaObject();
2315
2316 int idx = meta->findSlot( slot + 1, true );
2317 if( idx < 0 )
2318 return;
2319
2320 object->tqt_invoke( idx, 0 );
2321}
2322
2323void TDEApplication::addKipcEventMask(int id)
2324{
2325 if (id >= 32)
2326 {
2327 kdDebug(101) << "[tdecore-tdeapplication] Cannot use KIPC event mask for message IDs >= 32\n";
2328 return;
2329 }
2330 kipcEventMask |= (1 << id);
2331}
2332
2333void TDEApplication::removeKipcEventMask(int id)
2334{
2335 if (id >= 32)
2336 {
2337 kdDebug(101) << "[tdecore-tdeapplication] Cannot use KIPC event mask for message IDs >= 32\n";
2338 return;
2339 }
2340 kipcEventMask &= ~(1 << id);
2341}
2342
2343void TDEApplication::enableStyles()
2344{
2345 if (!useStyles)
2346 {
2347 useStyles = true;
2348 applyGUIStyle();
2349 }
2350}
2351
2352void TDEApplication::disableStyles()
2353{
2354 useStyles = false;
2355}
2356
2357void TDEApplication::applyGUIStyle()
2358{
2359 if ( !useStyles ) return;
2360
2361 TDEConfigGroup pConfig (TDEGlobal::config(), "General");
2362 TQString defaultStyle = TDEStyle::defaultStyle();
2363 TQString styleStr = pConfig.readEntry("widgetStyle", defaultStyle);
2364
2365 if (d->overrideStyle.isEmpty()) {
2366 // ### add check whether we already use the correct style to return then
2367 // (workaround for Qt misbehavior to avoid double style initialization)
2368
2369 TQStyle* sp = TQStyleFactory::create( styleStr );
2370
2371 // If there is no default style available, try falling back any available style
2372 if ( !sp && styleStr != defaultStyle)
2373 sp = TQStyleFactory::create( defaultStyle );
2374 if ( !sp )
2375 sp = TQStyleFactory::create( *(TQStyleFactory::keys().begin()) );
2376 setStyle(sp);
2377 }
2378 else
2379 setStyle(d->overrideStyle);
2380 // Reread palette from config file.
2381 tdedisplaySetPalette();
2382}
2383
2384TQString TDEApplication::caption() const
2385{
2386 // Caption set from command line ?
2387 if( !aCaption.isNull() )
2388 return aCaption;
2389 else
2390 // We have some about data ?
2391 if ( TDEGlobal::instance()->aboutData() )
2392 return TDEGlobal::instance()->aboutData()->programName();
2393 else
2394 // Last resort : application name
2395 return name();
2396}
2397
2398
2399//
2400// 1999-09-20: Espen Sand
2401// An attempt to simplify consistent captions.
2402//
2403TQString TDEApplication::makeStdCaption( const TQString &userCaption,
2404 bool withAppName, bool modified ) const
2405{
2406 TQString s = userCaption.isEmpty() ? caption() : userCaption;
2407
2408 // If the document is modified, add '[modified]'.
2409 if (modified)
2410 s += TQString::fromUtf8(" [") + i18n("modified") + TQString::fromUtf8("]");
2411
2412 if ( !userCaption.isEmpty() ) {
2413 // Add the application name if:
2414 // User asked for it, it's not a duplication and the app name (caption()) is not empty
2415 if ( withAppName && !caption().isNull() && !userCaption.endsWith(caption()) )
2416 s += TQString::fromUtf8(" - ") + caption();
2417 }
2418
2419 return s;
2420}
2421
2422TQPalette TDEApplication::createApplicationPalette()
2423{
2424 TDEConfig *config = TDEGlobal::config();
2425 TDEConfigGroupSaver saver( config, "General" );
2426 return createApplicationPalette( config, TDEGlobalSettings::contrast() );
2427}
2428
2429TQPalette TDEApplication::createApplicationPalette( TDEConfig *config, int contrast_ )
2430{
2431 TQColor trinity4Background( 239, 239, 239 );
2432 TQColor trinity4Blue( 103,141,178 );
2433
2434 TQColor trinity4Button;
2435 if ( TQPixmap::defaultDepth() > 8 )
2436 trinity4Button.setRgb( 221, 223, 228 );
2437 else
2438 trinity4Button.setRgb( 220, 220, 220 );
2439
2440 TQColor trinity4Link( 0, 0, 238 );
2441 TQColor trinity4VisitedLink( 82, 24, 139 );
2442
2443 TQColor background = config->readColorEntry( "background", &trinity4Background );
2444 TQColor foreground = config->readColorEntry( "foreground", &TQt::black );
2445 TQColor button = config->readColorEntry( "buttonBackground", &trinity4Button );
2446 TQColor buttonText = config->readColorEntry( "buttonForeground", &TQt::black );
2447 TQColor highlight = config->readColorEntry( "selectBackground", &trinity4Blue );
2448 TQColor highlightedText = config->readColorEntry( "selectForeground", &TQt::white );
2449 TQColor base = config->readColorEntry( "windowBackground", &TQt::white );
2450 TQColor baseText = config->readColorEntry( "windowForeground", &TQt::black );
2451 TQColor link = config->readColorEntry( "linkColor", &trinity4Link );
2452 TQColor visitedLink = config->readColorEntry( "visitedLinkColor", &trinity4VisitedLink );
2453
2454 int highlightVal, lowlightVal;
2455 highlightVal = 100 + (2*contrast_+4)*16/10;
2456 lowlightVal = 100 + (2*contrast_+4)*10;
2457
2458 TQColor disfg = foreground;
2459
2460 int h, s, v;
2461 disfg.hsv( &h, &s, &v );
2462 if (v > 128)
2463 // dark bg, light fg - need a darker disabled fg
2464 disfg = disfg.dark(lowlightVal);
2465 else if (disfg != TQt::black)
2466 // light bg, dark fg - need a lighter disabled fg - but only if !black
2467 disfg = disfg.light(highlightVal);
2468 else
2469 // black fg - use darkgray disabled fg
2470 disfg = TQt::darkGray;
2471
2472
2473 TQColorGroup disabledgrp(disfg, background,
2474 background.light(highlightVal),
2475 background.dark(lowlightVal),
2476 background.dark(120),
2477 background.dark(120), base);
2478
2479 TQColorGroup colgrp(foreground, background, background.light(highlightVal),
2480 background.dark(lowlightVal),
2481 background.dark(120),
2482 baseText, base);
2483
2484 int inlowlightVal = lowlightVal-25;
2485 if(inlowlightVal < 120)
2486 inlowlightVal = 120;
2487
2488 colgrp.setColor(TQColorGroup::Highlight, highlight);
2489 colgrp.setColor(TQColorGroup::HighlightedText, highlightedText);
2490 colgrp.setColor(TQColorGroup::Button, button);
2491 colgrp.setColor(TQColorGroup::ButtonText, buttonText);
2492 colgrp.setColor(TQColorGroup::Midlight, background.light(110));
2493 colgrp.setColor(TQColorGroup::Link, link);
2494 colgrp.setColor(TQColorGroup::LinkVisited, visitedLink);
2495
2496 disabledgrp.setColor(TQColorGroup::Button, button);
2497
2498 TQColor disbtntext = buttonText;
2499 disbtntext.hsv( &h, &s, &v );
2500 if (v > 128)
2501 // dark button, light buttonText - need a darker disabled buttonText
2502 disbtntext = disbtntext.dark(lowlightVal);
2503 else if (disbtntext != TQt::black)
2504 // light buttonText, dark button - need a lighter disabled buttonText - but only if !black
2505 disbtntext = disbtntext.light(highlightVal);
2506 else
2507 // black button - use darkgray disabled buttonText
2508 disbtntext = TQt::darkGray;
2509
2510 disabledgrp.setColor(TQColorGroup::ButtonText, disbtntext);
2511 disabledgrp.setColor(TQColorGroup::Midlight, background.light(110));
2512 disabledgrp.setColor(TQColorGroup::Highlight, highlight.dark(120));
2513 disabledgrp.setColor(TQColorGroup::Link, link);
2514 disabledgrp.setColor(TQColorGroup::LinkVisited, visitedLink);
2515
2516 return TQPalette(colgrp, disabledgrp, colgrp);
2517}
2518
2519
2520void TDEApplication::tdedisplaySetPalette()
2521{
2522#ifdef TQ_WS_MACX
2523 //Can I have this on other platforms, please!? --Sam
2524 {
2525 TDEConfig *config = TDEGlobal::config();
2526 TDEConfigGroupSaver saver( config, "General" );
2527 bool do_not_set_palette = false;
2528 if(config->readBoolEntry("nopaletteChange", &do_not_set_palette))
2529 return;
2530 }
2531#endif
2532 TQApplication::setPalette( createApplicationPalette(), true);
2533 emit tdedisplayPaletteChanged();
2534 emit appearanceChanged();
2535}
2536
2537
2538void TDEApplication::tdedisplaySetFont()
2539{
2540 TQApplication::setFont(TDEGlobalSettings::generalFont(), true);
2541 TQApplication::setFont(TDEGlobalSettings::menuFont(), true, "TQMenuBar");
2542 TQApplication::setFont(TDEGlobalSettings::menuFont(), true, "TQPopupMenu");
2543 TQApplication::setFont(TDEGlobalSettings::menuFont(), true, "TDEPopupTitle");
2544
2545 // "patch" standard TQStyleSheet to follow our fonts
2546 TQStyleSheet* sheet = TQStyleSheet::defaultSheet();
2547 sheet->item ("pre")->setFontFamily (TDEGlobalSettings::fixedFont().family());
2548 sheet->item ("code")->setFontFamily (TDEGlobalSettings::fixedFont().family());
2549 sheet->item ("tt")->setFontFamily (TDEGlobalSettings::fixedFont().family());
2550
2551 emit tdedisplayFontChanged();
2552 emit appearanceChanged();
2553}
2554
2555
2556void TDEApplication::tdedisplaySetStyle()
2557{
2558 if (useStyles)
2559 {
2560 applyGUIStyle();
2561 emit tdedisplayStyleChanged();
2562 emit appearanceChanged();
2563 }
2564}
2565
2566
2567void TDEApplication::propagateSettings(SettingsCategory arg)
2568{
2569 TDEConfigBase* config = TDEGlobal::config();
2570 TDEConfigGroupSaver saver( config, "KDE" );
2571
2572#ifdef QT_HAVE_MAX_IMAGE_SIZE
2573 TQSize maxImageSize(4096, 4096);
2574 maxImageSize = config->readSizeEntry("MaxImageSize", &maxImageSize);
2575 TQImage::setMaxImageSize(maxImageSize);
2576#endif
2577
2578 int num = config->readNumEntry("CursorBlinkRate", TQApplication::cursorFlashTime());
2579 if ((num != 0) && (num < 200))
2580 num = 200;
2581 if (num > 2000)
2582 num = 2000;
2583 TQApplication::setCursorFlashTime(num);
2584 num = config->readNumEntry("DoubleClickInterval", TQApplication::doubleClickInterval());
2585 TQApplication::setDoubleClickInterval(num);
2586 num = config->readNumEntry("StartDragTime", TQApplication::startDragTime());
2587 TQApplication::setStartDragTime(num);
2588 num = config->readNumEntry("StartDragDist", TQApplication::startDragDistance());
2589 TQApplication::setStartDragDistance(num);
2590 num = config->readNumEntry("WheelScrollLines", TQApplication::wheelScrollLines());
2591 TQApplication::setWheelScrollLines(num);
2592
2593 bool b = config->readBoolEntry("EffectAnimateMenu", false);
2594 TQApplication::setEffectEnabled( TQt::UI_AnimateMenu, b);
2595 b = config->readBoolEntry("EffectFadeMenu", false);
2596 TQApplication::setEffectEnabled( TQt::UI_FadeMenu, b);
2597 b = config->readBoolEntry("EffectAnimateCombo", false);
2598 TQApplication::setEffectEnabled( TQt::UI_AnimateCombo, b);
2599 b = config->readBoolEntry("EffectAnimateTooltip", false);
2600 TQApplication::setEffectEnabled( TQt::UI_AnimateTooltip, b);
2601 b = config->readBoolEntry("EffectFadeTooltip", false);
2602 TQApplication::setEffectEnabled( TQt::UI_FadeTooltip, b);
2603 b = !config->readBoolEntry("EffectNoTooltip", false);
2604 TQToolTip::setGloballyEnabled( b );
2605
2606 emit settingsChanged(arg);
2607}
2608
2609void TDEApplication::installKDEPropertyMap()
2610{
2611#ifndef TQT_NO_SQL
2612 static bool installed = false;
2613 if (installed) return;
2614 installed = true;
2621 // TQSqlPropertyMap takes ownership of the new default map.
2622 TQSqlPropertyMap *kdeMap = new TQSqlPropertyMap;
2623 kdeMap->insert( "KColorButton", "color" );
2624 kdeMap->insert( "KComboBox", "currentItem" );
2625 kdeMap->insert( "KDatePicker", "date" );
2626 kdeMap->insert( "KDateWidget", "date" );
2627 kdeMap->insert( "KDateTimeWidget", "dateTime" );
2628 kdeMap->insert( "KEditListBox", "items" );
2629 kdeMap->insert( "TDEFontCombo", "family" );
2630 kdeMap->insert( "TDEFontRequester", "font" );
2631 kdeMap->insert( "TDEFontChooser", "font" );
2632 kdeMap->insert( "KHistoryCombo", "currentItem" );
2633 kdeMap->insert( "TDEListBox", "currentItem" );
2634 kdeMap->insert( "KLineEdit", "text" );
2635 kdeMap->insert( "KRestrictedLine", "text" );
2636 kdeMap->insert( "KSqueezedTextLabel", "text" );
2637 kdeMap->insert( "KTextBrowser", "source" );
2638 kdeMap->insert( "KTextEdit", "text" );
2639 kdeMap->insert( "KURLRequester", "url" );
2640 kdeMap->insert( "KPasswordEdit", "password" );
2641 kdeMap->insert( "KIntNumInput", "value" );
2642 kdeMap->insert( "KIntSpinBox", "value" );
2643 kdeMap->insert( "KDoubleNumInput", "value" );
2644 // Temp til fixed in QT then enable ifdef with the correct version num
2645 kdeMap->insert( "TQGroupBox", "checked" );
2646 kdeMap->insert( "TQTabWidget", "currentPage" );
2647 TQSqlPropertyMap::installDefaultMap( kdeMap );
2648#endif
2649}
2650
2651void TDEApplication::invokeHelp( const TQString& anchor,
2652 const TQString& _appname) const
2653{
2654 return invokeHelp( anchor, _appname, "" );
2655}
2656
2657#ifndef TQ_WS_WIN
2658// for win32 we're using simple help tools like Qt Assistant,
2659// see kapplication_win.cpp
2660void TDEApplication::invokeHelp( const TQString& anchor,
2661 const TQString& _appname,
2662 const TQCString& startup_id ) const
2663{
2664 TQString url;
2665 TQString appname;
2666 if (_appname.isEmpty())
2667 appname = name();
2668 else
2669 appname = _appname;
2670
2671 if (!anchor.isEmpty())
2672 url = TQString("help:/%1?anchor=%2").arg(appname).arg(anchor);
2673 else
2674 url = TQString("help:/%1/index.html").arg(appname);
2675
2676 TQString error;
2677 if ( !dcopClient()->isApplicationRegistered("khelpcenter") )
2678 {
2679 if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, startup_id, false))
2680 {
2681 if (Tty != tdeApp->type())
2682 TQMessageBox::critical(tdeApp->mainWidget(), i18n("Could not Launch Help Center"),
2683 i18n("Could not launch the TDE Help Center:\n\n%1").arg(error), i18n("&OK"));
2684 else
2685 kdWarning() << "Could not launch help:\n" << error << endl;
2686 return;
2687 }
2688 }
2689 else
2690 DCOPRef( "khelpcenter", "KHelpCenterIface" ).send( "openUrl", url, startup_id );
2691}
2692#endif
2693
2694void TDEApplication::invokeHTMLHelp( const TQString& _filename, const TQString& topic ) const
2695{
2696 kdWarning() << "invoking HTML help is deprecated! use docbook and invokeHelp!\n";
2697
2698 TQString filename;
2699
2700 if( _filename.isEmpty() )
2701 filename = TQString(name()) + "/index.html";
2702 else
2703 filename = _filename;
2704
2705 TQString url;
2706 if (!topic.isEmpty())
2707 url = TQString("help:/%1#%2").arg(filename).arg(topic);
2708 else
2709 url = TQString("help:/%1").arg(filename);
2710
2711 TQString error;
2712 if ( !dcopClient()->isApplicationRegistered("khelpcenter") )
2713 {
2714 if (startServiceByDesktopName("khelpcenter", url, &error, 0, 0, "", false))
2715 {
2716 if (Tty != tdeApp->type())
2717 TQMessageBox::critical(tdeApp->mainWidget(), i18n("Could not Launch Help Center"),
2718 i18n("Could not launch the TDE Help Center:\n\n%1").arg(error), i18n("&OK"));
2719 else
2720 kdWarning() << "Could not launch help:\n" << error << endl;
2721 return;
2722 }
2723 }
2724 else
2725 DCOPRef( "khelpcenter", "KHelpCenterIface" ).send( "openUrl", url );
2726}
2727
2728
2729void TDEApplication::invokeMailer(const TQString &address, const TQString &subject)
2730{
2731 return invokeMailer(address,subject,"");
2732}
2733
2734void TDEApplication::invokeMailer(const TQString &address, const TQString &subject, const TQCString& startup_id)
2735{
2736 invokeMailer(address, TQString::null, TQString::null, subject, TQString::null, TQString::null,
2737 TQStringList(), startup_id );
2738}
2739
2740void TDEApplication::invokeMailer(const KURL &mailtoURL)
2741{
2742 return invokeMailer( mailtoURL, "" );
2743}
2744
2745void TDEApplication::invokeMailer(const KURL &mailtoURL, const TQCString& startup_id )
2746{
2747 return invokeMailer( mailtoURL, startup_id, false);
2748}
2749
2750void TDEApplication::invokeMailer(const KURL &mailtoURL, const TQCString& startup_id, bool allowAttachments )
2751{
2752 TQString address = KURL::decode_string(mailtoURL.path()), subject, cc, bcc, body;
2753 TQStringList queries = TQStringList::split('&', mailtoURL.query().mid(1));
2754 TQStringList attachURLs;
2755 for (TQStringList::Iterator it = queries.begin(); it != queries.end(); ++it)
2756 {
2757 TQString q = (*it).lower();
2758 if (q.startsWith("subject="))
2759 subject = KURL::decode_string((*it).mid(8));
2760 else
2761 if (q.startsWith("cc="))
2762 cc = cc.isEmpty()? KURL::decode_string((*it).mid(3)): cc + ',' + KURL::decode_string((*it).mid(3));
2763 else
2764 if (q.startsWith("bcc="))
2765 bcc = bcc.isEmpty()? KURL::decode_string((*it).mid(4)): bcc + ',' + KURL::decode_string((*it).mid(4));
2766 else
2767 if (q.startsWith("body="))
2768 body = KURL::decode_string((*it).mid(5));
2769 else
2770 if (allowAttachments && q.startsWith("attach="))
2771 attachURLs.push_back(KURL::decode_string((*it).mid(7)));
2772 else
2773 if (allowAttachments && q.startsWith("attachment="))
2774 attachURLs.push_back(KURL::decode_string((*it).mid(11)));
2775 else
2776 if (q.startsWith("to="))
2777 address = address.isEmpty()? KURL::decode_string((*it).mid(3)): address + ',' + KURL::decode_string((*it).mid(3));
2778 }
2779
2780 invokeMailer( address, cc, bcc, subject, body, TQString::null, attachURLs, startup_id );
2781}
2782
2783void TDEApplication::invokeMailer(const TQString &to, const TQString &cc, const TQString &bcc,
2784 const TQString &subject, const TQString &body,
2785 const TQString & messageFile, const TQStringList &attachURLs)
2786{
2787 return invokeMailer(to,cc,bcc,subject,body,messageFile,attachURLs,"");
2788}
2789
2790#ifndef TQ_WS_WIN
2791// on win32, for invoking browser we're using win32 API
2792// see kapplication_win.cpp
2793
2794static TQStringList splitEmailAddressList( const TQString & aStr )
2795{
2796 // This is a copy of KPIM::splitEmailAddrList().
2797 // Features:
2798 // - always ignores quoted characters
2799 // - ignores everything (including parentheses and commas)
2800 // inside quoted strings
2801 // - supports nested comments
2802 // - ignores everything (including double quotes and commas)
2803 // inside comments
2804
2805 TQStringList list;
2806
2807 if (aStr.isEmpty())
2808 return list;
2809
2810 TQString addr;
2811 uint addrstart = 0;
2812 int commentlevel = 0;
2813 bool insidequote = false;
2814
2815 for (uint index=0; index<aStr.length(); index++) {
2816 // the following conversion to latin1 is o.k. because
2817 // we can safely ignore all non-latin1 characters
2818 switch (aStr[index].latin1()) {
2819 case '"' : // start or end of quoted string
2820 if (commentlevel == 0)
2821 insidequote = !insidequote;
2822 break;
2823 case '(' : // start of comment
2824 if (!insidequote)
2825 commentlevel++;
2826 break;
2827 case ')' : // end of comment
2828 if (!insidequote) {
2829 if (commentlevel > 0)
2830 commentlevel--;
2831 else {
2832 //kdDebug() << "[tdecore-tdeapplication] Error in address splitting: Unmatched ')'"
2833 // << endl;
2834 return list;
2835 }
2836 }
2837 break;
2838 case '\\' : // quoted character
2839 index++; // ignore the quoted character
2840 break;
2841 case ',' :
2842 if (!insidequote && (commentlevel == 0)) {
2843 addr = aStr.mid(addrstart, index-addrstart);
2844 if (!addr.isEmpty())
2845 list += addr.simplifyWhiteSpace();
2846 addrstart = index+1;
2847 }
2848 break;
2849 }
2850 }
2851 // append the last address to the list
2852 if (!insidequote && (commentlevel == 0)) {
2853 addr = aStr.mid(addrstart, aStr.length()-addrstart);
2854 if (!addr.isEmpty())
2855 list += addr.simplifyWhiteSpace();
2856 }
2857 //else
2858 // kdDebug() << "[tdecore-tdeapplication] Error in address splitting: "
2859 // << "Unexpected end of address list"
2860 // << endl;
2861
2862 return list;
2863}
2864
2865void TDEApplication::invokeMailer(const TQString &_to, const TQString &_cc, const TQString &_bcc,
2866 const TQString &subject, const TQString &body,
2867 const TQString & /*messageFile TODO*/, const TQStringList &attachURLs,
2868 const TQCString& startup_id )
2869{
2870 TDEConfig config("emaildefaults");
2871
2872 config.setGroup("Defaults");
2873 TQString group = config.readEntry("Profile","Default");
2874
2875 config.setGroup( TQString("PROFILE_%1").arg(group) );
2876 TQString command = config.readPathEntry("EmailClient");
2877
2878 TQString to, cc, bcc;
2879 if (command.isEmpty() || command == TQString::fromLatin1("kmail")
2880 || command.endsWith("/kmail"))
2881 {
2882 command = TQString::fromLatin1("kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t");
2883 if ( !_to.isEmpty() )
2884 {
2885 // put the whole address lists into RFC2047 encoded blobs; technically
2886 // this isn't correct, but KMail understands it nonetheless
2887 to = TQString( "=?utf8?b?%1?=" )
2888 .arg( TQString(KCodecs::base64Encode( _to.utf8(), false )) );
2889 }
2890 if ( !_cc.isEmpty() )
2891 cc = TQString( "=?utf8?b?%1?=" )
2892 .arg( TQString(KCodecs::base64Encode( _cc.utf8(), false )) );
2893 if ( !_bcc.isEmpty() )
2894 bcc = TQString( "=?utf8?b?%1?=" )
2895 .arg( TQString(KCodecs::base64Encode( _bcc.utf8(), false )) );
2896 } else {
2897 to = _to;
2898 cc = _cc;
2899 bcc = _bcc;
2900 if( !command.contains( '%' ))
2901 command += " %u";
2902 }
2903
2904 if (config.readBoolEntry("TerminalClient", false))
2905 {
2906 TDEConfigGroup confGroup( TDEGlobal::config(), "General" );
2907 TQString preferredTerminal = confGroup.readPathEntry("TerminalApplication", "konsole");
2908 command = preferredTerminal + " -e " + command;
2909 }
2910
2911 TQStringList cmdTokens = KShell::splitArgs(command);
2912 TQString cmd = cmdTokens[0];
2913 cmdTokens.remove(cmdTokens.begin());
2914
2915 KURL url;
2916 TQStringList qry;
2917 if (!to.isEmpty())
2918 {
2919 TQStringList tos = splitEmailAddressList( to );
2920 url.setPath( tos.first() );
2921 tos.remove( tos.begin() );
2922 for (TQStringList::ConstIterator it = tos.begin(); it != tos.end(); ++it)
2923 qry.append( "to=" + KURL::encode_string( *it ) );
2924 }
2925 const TQStringList ccs = splitEmailAddressList( cc );
2926 for (TQStringList::ConstIterator it = ccs.begin(); it != ccs.end(); ++it)
2927 qry.append( "cc=" + KURL::encode_string( *it ) );
2928 const TQStringList bccs = splitEmailAddressList( bcc );
2929 for (TQStringList::ConstIterator it = bccs.begin(); it != bccs.end(); ++it)
2930 qry.append( "bcc=" + KURL::encode_string( *it ) );
2931 for (TQStringList::ConstIterator it = attachURLs.begin(); it != attachURLs.end(); ++it)
2932 qry.append( "attach=" + KURL::encode_string( *it ) );
2933 if (!subject.isEmpty())
2934 qry.append( "subject=" + KURL::encode_string( subject ) );
2935 if (!body.isEmpty())
2936 qry.append( "body=" + KURL::encode_string( body ) );
2937 url.setQuery( qry.join( "&" ) );
2938 if ( ! (to.isEmpty() && qry.isEmpty()) )
2939 url.setProtocol("mailto");
2940
2941 TQMap<TQChar, TQString> keyMap;
2942 keyMap.insert('t', to);
2943 keyMap.insert('s', subject);
2944 keyMap.insert('c', cc);
2945 keyMap.insert('b', bcc);
2946 keyMap.insert('B', body);
2947 keyMap.insert('u', url.url());
2948
2949 TQString attachlist = attachURLs.join(",");
2950 attachlist.prepend('\'');
2951 attachlist.append('\'');
2952 keyMap.insert('A', attachlist);
2953
2954 for (TQStringList::Iterator it = cmdTokens.begin(); it != cmdTokens.end(); )
2955 {
2956 if (*it == "%A")
2957 {
2958 if (it == cmdTokens.begin()) // better safe than sorry ...
2959 continue;
2960 TQStringList::ConstIterator urlit = attachURLs.begin();
2961 TQStringList::ConstIterator urlend = attachURLs.end();
2962 if ( urlit != urlend )
2963 {
2964 TQStringList::Iterator previt = it;
2965 --previt;
2966 *it = *urlit;
2967 ++it;
2968 while ( ++urlit != urlend )
2969 {
2970 cmdTokens.insert( it, *previt );
2971 cmdTokens.insert( it, *urlit );
2972 }
2973 } else {
2974 --it;
2975 it = cmdTokens.remove( cmdTokens.remove( it ) );
2976 }
2977 } else {
2978 *it = KMacroExpander::expandMacros(*it, keyMap);
2979 ++it;
2980 }
2981 }
2982
2983 TQString error;
2984 // TODO this should check if cmd has a .desktop file, and use data from it, together
2985 // with sending more ASN data
2986 if (tdeinitExec(cmd, cmdTokens, &error, NULL, startup_id )) {
2987 if (Tty != tdeApp->type()) {
2988 TQMessageBox::critical(tdeApp->mainWidget(), i18n("Could not Launch Mail Client"),
2989 i18n("Could not launch the mail client:\n\n%1").arg(error), i18n("&OK"));
2990 }
2991 else {
2992 kdWarning() << "Could not launch mail client:\n" << error << endl;
2993 }
2994 }
2995}
2996#endif
2997
2998void TDEApplication::invokeBrowser( const TQString &url )
2999{
3000 return invokeBrowser( url, "" );
3001}
3002
3003#ifndef TQ_WS_WIN
3004// on win32, for invoking browser we're using win32 API
3005// see kapplication_win.cpp
3006void TDEApplication::invokeBrowser( const TQString &url, const TQCString& startup_id )
3007{
3008 TQString error;
3009
3010 if (startServiceByDesktopName("kfmclient", url, &error, 0, 0, startup_id, false))
3011 {
3012 if (Tty != tdeApp->type())
3013 TQMessageBox::critical(tdeApp->mainWidget(), i18n("Could not Launch Browser"),
3014 i18n("Could not launch the browser:\n\n%1").arg(error), i18n("&OK"));
3015 else
3016 kdWarning() << "Could not launch browser:\n" << error << endl;
3017 return;
3018 }
3019}
3020#endif
3021
3022void TDEApplication::cut()
3023{
3024 invokeEditSlot( TQ_SLOT( cut() ) );
3025}
3026
3027void TDEApplication::copy()
3028{
3029 invokeEditSlot( TQ_SLOT( copy() ) );
3030}
3031
3032void TDEApplication::paste()
3033{
3034 invokeEditSlot( TQ_SLOT( paste() ) );
3035}
3036
3037void TDEApplication::clear()
3038{
3039 invokeEditSlot( TQ_SLOT( clear() ) );
3040}
3041
3042void TDEApplication::selectAll()
3043{
3044 invokeEditSlot( TQ_SLOT( selectAll() ) );
3045}
3046
3047void TDEApplication::broadcastKeyCode(unsigned int keyCode)
3048{
3049 emit coreFakeKeyPress(keyCode);
3050}
3051
3052TQCString
3053TDEApplication::launcher()
3054{
3055 return "tdelauncher";
3056}
3057
3058static int
3059startServiceInternal( const TQCString &function,
3060 const TQString& _name, const TQStringList &URLs,
3061 TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait )
3062{
3063 struct serviceResult
3064 {
3065 int result;
3066 TQCString dcopName;
3067 TQString error;
3068 pid_t pid;
3069 };
3070
3071 // Register app as able to send DCOP messages
3072 DCOPClient *dcopClient;
3073 if (tdeApp)
3074 dcopClient = tdeApp->dcopClient();
3075 else
3076 dcopClient = new DCOPClient;
3077
3078 if (!dcopClient->isAttached())
3079 {
3080 if (!dcopClient->attach())
3081 {
3082 if (error)
3083 *error = i18n("Could not register with DCOP.\n");
3084 if (!tdeApp)
3085 delete dcopClient;
3086
3087 return -1;
3088 }
3089 }
3090 TQByteArray params;
3091 TQDataStream stream(params, IO_WriteOnly);
3092 stream << _name << URLs;
3093 TQCString replyType;
3094 TQByteArray replyData;
3095 TQCString _launcher = TDEApplication::launcher();
3096 TQValueList<TQCString> envs;
3097#ifdef TQ_WS_X11
3098 if (tqt_xdisplay()) {
3099 TQCString dpystring(XDisplayString(tqt_xdisplay()));
3100 envs.append( TQCString("DISPLAY=") + dpystring );
3101 } else if( getenv( "DISPLAY" )) {
3102 TQCString dpystring( getenv( "DISPLAY" ));
3103 envs.append( TQCString("DISPLAY=") + dpystring );
3104 }
3105#endif
3106 stream << envs;
3107#if defined TQ_WS_X11
3108 // make sure there is id, so that user timestamp exists
3109 stream << ( startup_id.isEmpty() ? TDEStartupInfo::createNewStartupId() : startup_id );
3110#endif
3111 if( function.left( 12 ) != "tdeinit_exec" )
3112 stream << noWait;
3113
3114 if (!dcopClient->call(_launcher, _launcher,
3115 function, params, replyType, replyData))
3116 {
3117 if (error)
3118 *error = i18n("TDELauncher could not be reached via DCOP.\n");
3119 if (!tdeApp)
3120 delete dcopClient;
3121 return -1;
3122 }
3123 if (!tdeApp)
3124 delete dcopClient;
3125
3126 if (noWait)
3127 return 0;
3128
3129 TQDataStream stream2(replyData, IO_ReadOnly);
3130 serviceResult result;
3131 stream2 >> result.result >> result.dcopName >> result.error >> result.pid;
3132 if (dcopService)
3133 *dcopService = result.dcopName;
3134 if (error)
3135 *error = result.error;
3136 if (pid)
3137 *pid = result.pid;
3138 return result.result;
3139}
3140
3141int
3142TDEApplication::startServiceByName( const TQString& _name, const TQString &URL,
3143 TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait )
3144{
3145 TQStringList URLs;
3146 if (!URL.isEmpty())
3147 URLs.append(URL);
3148 return startServiceInternal(
3149 "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3150 _name, URLs, error, dcopService, pid, startup_id, noWait);
3151}
3152
3153int
3154TDEApplication::startServiceByName( const TQString& _name, const TQStringList &URLs,
3155 TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait )
3156{
3157 return startServiceInternal(
3158 "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3159 _name, URLs, error, dcopService, pid, startup_id, noWait);
3160}
3161
3162int
3163TDEApplication::startServiceByDesktopPath( const TQString& _name, const TQString &URL,
3164 TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait )
3165{
3166 TQStringList URLs;
3167 if (!URL.isEmpty())
3168 URLs.append(URL);
3169 return startServiceInternal(
3170 "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3171 _name, URLs, error, dcopService, pid, startup_id, noWait);
3172}
3173
3174int
3175TDEApplication::startServiceByDesktopPath( const TQString& _name, const TQStringList &URLs,
3176 TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait )
3177{
3178 return startServiceInternal(
3179 "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3180 _name, URLs, error, dcopService, pid, startup_id, noWait);
3181}
3182
3183int
3184TDEApplication::startServiceByDesktopName( const TQString& _name, const TQString &URL,
3185 TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait )
3186{
3187 TQStringList URLs;
3188 if (!URL.isEmpty())
3189 URLs.append(URL);
3190 return startServiceInternal(
3191 "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3192 _name, URLs, error, dcopService, pid, startup_id, noWait);
3193}
3194
3195int
3196TDEApplication::startServiceByDesktopName( const TQString& _name, const TQStringList &URLs,
3197 TQString *error, TQCString *dcopService, int *pid, const TQCString& startup_id, bool noWait )
3198{
3199 return startServiceInternal(
3200 "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3201 _name, URLs, error, dcopService, pid, startup_id, noWait);
3202}
3203
3204int
3205TDEApplication::tdeinitExec( const TQString& name, const TQStringList &args,
3206 TQString *error, int *pid )
3207{
3208 return tdeinitExec( name, args, error, pid, "" );
3209}
3210
3211int
3212TDEApplication::tdeinitExec( const TQString& name, const TQStringList &args,
3213 TQString *error, int *pid, const TQCString& startup_id )
3214{
3215 return startServiceInternal("tdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)",
3216 name, args, error, 0, pid, startup_id, false);
3217}
3218
3219int
3220TDEApplication::tdeinitExecWait( const TQString& name, const TQStringList &args,
3221 TQString *error, int *pid )
3222{
3223 return tdeinitExecWait( name, args, error, pid, "" );
3224}
3225
3226int
3227TDEApplication::tdeinitExecWait( const TQString& name, const TQStringList &args,
3228 TQString *error, int *pid, const TQCString& startup_id )
3229{
3230 return startServiceInternal("tdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>,TQCString)",
3231 name, args, error, 0, pid, startup_id, false);
3232}
3233
3234TQString TDEApplication::tempSaveName( const TQString& pFilename ) const
3235{
3236 TQString aFilename;
3237
3238 if( TQDir::isRelativePath(pFilename) )
3239 {
3240 kdWarning(101) << "Relative filename passed to TDEApplication::tempSaveName" << endl;
3241 aFilename = TQFileInfo( TQDir( "." ), pFilename ).absFilePath();
3242 }
3243 else
3244 aFilename = pFilename;
3245
3246 TQDir aAutosaveDir( TQDir::homeDirPath() + "/autosave/" );
3247 if( !aAutosaveDir.exists() )
3248 {
3249 if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
3250 {
3251 // Last chance: use temp dir
3252 aAutosaveDir.setPath( TDEGlobal::dirs()->saveLocation("tmp") );
3253 }
3254 }
3255
3256 aFilename.replace( "/", "\\!" ).prepend( "#" ).append( "#" ).prepend( "/" ).prepend( aAutosaveDir.absPath() );
3257
3258 return aFilename;
3259}
3260
3261
3262TQString TDEApplication::checkRecoverFile( const TQString& pFilename,
3263 bool& bRecover ) const
3264{
3265 TQString aFilename;
3266
3267 if( TQDir::isRelativePath(pFilename) )
3268 {
3269 kdWarning(101) << "Relative filename passed to TDEApplication::tempSaveName" << endl;
3270 aFilename = TQFileInfo( TQDir( "." ), pFilename ).absFilePath();
3271 }
3272 else
3273 aFilename = pFilename;
3274
3275 TQDir aAutosaveDir( TQDir::homeDirPath() + "/autosave/" );
3276 if( !aAutosaveDir.exists() )
3277 {
3278 if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
3279 {
3280 // Last chance: use temp dir
3281 aAutosaveDir.setPath( TDEGlobal::dirs()->saveLocation("tmp") );
3282 }
3283 }
3284
3285 aFilename.replace( "/", "\\!" ).prepend( "#" ).append( "#" ).prepend( "/" ).prepend( aAutosaveDir.absPath() );
3286
3287 if( TQFile( aFilename ).exists() )
3288 {
3289 bRecover = true;
3290 return aFilename;
3291 }
3292 else
3293 {
3294 bRecover = false;
3295 return pFilename;
3296 }
3297}
3298
3299
3300bool checkAccess(const TQString& pathname, int mode)
3301{
3302 int accessOK = access( TQFile::encodeName(pathname), mode );
3303 if ( accessOK == 0 )
3304 return true; // OK, I can really access the file
3305
3306 // else
3307 // if we want to write the file would be created. Check, if the
3308 // user may write to the directory to create the file.
3309 if ( (mode & W_OK) == 0 )
3310 return false; // Check for write access is not part of mode => bail out
3311
3312
3313 if (!access( TQFile::encodeName(pathname), F_OK)) // if it already exists
3314 return false;
3315
3316 //strip the filename (everything until '/' from the end
3317 TQString dirName(pathname);
3318 int pos = dirName.findRev('/');
3319 if ( pos == -1 )
3320 return false; // No path in argument. This is evil, we won't allow this
3321 else if ( pos == 0 ) // don't turn e.g. /root into an empty string
3322 pos = 1;
3323
3324 dirName.truncate(pos); // strip everything starting from the last '/'
3325
3326 accessOK = access( TQFile::encodeName(dirName), W_OK );
3327 // -?- Can I write to the accessed diretory
3328 if ( accessOK == 0 )
3329 return true; // Yes
3330 else
3331 return false; // No
3332}
3333
3334void TDEApplication::setTopWidget( TQWidget *topWidget )
3335{
3336 if( !topWidget )
3337 return;
3338
3339 // set the specified caption
3340 if ( !topWidget->inherits("TDEMainWindow") ) { // TDEMainWindow does this already for us
3341 topWidget->setCaption( caption() );
3342 }
3343
3344 // set the specified icons
3345 topWidget->setIcon( icon() ); //standard X11
3346#if defined TQ_WS_X11
3347//#ifdef TQ_WS_X11 // FIXME(E): Implement for Qt/Embedded
3348 KWin::setIcons(topWidget->winId(), icon(), miniIcon() ); // NET_WM hints for KWin
3349
3350 // set the app startup notification window property
3351 TDEStartupInfo::setWindowStartupId( topWidget->winId(), startupId());
3352#endif
3353}
3354
3355TQCString TDEApplication::startupId() const
3356{
3357 return d->startup_id;
3358}
3359
3360void TDEApplication::setStartupId( const TQCString& startup_id )
3361{
3362 if( startup_id == d->startup_id )
3363 return;
3364#if defined TQ_WS_X11
3365 TDEStartupInfo::handleAutoAppStartedSending(); // finish old startup notification if needed
3366#endif
3367 if( startup_id.isEmpty())
3368 d->startup_id = "0";
3369 else
3370 {
3371 d->startup_id = startup_id;
3372#if defined TQ_WS_X11
3373 TDEStartupInfoId id;
3374 id.initId( startup_id );
3375 long timestamp = id.timestamp();
3376 if( timestamp != 0 )
3377 updateUserTimestamp( timestamp );
3378#endif
3379 }
3380}
3381
3382// read the startup notification env variable, save it and unset it in order
3383// not to propagate it to processes started from this app
3384void TDEApplication::read_app_startup_id()
3385{
3386#if defined TQ_WS_X11
3387 TDEStartupInfoId id = TDEStartupInfo::currentStartupIdEnv();
3388 TDEStartupInfo::resetStartupEnv();
3389 d->startup_id = id.id();
3390#endif
3391}
3392
3393int TDEApplication::random()
3394{
3395 static bool init = false;
3396 if (!init)
3397 {
3398 unsigned int seed;
3399 init = true;
3400 int fd = open("/dev/urandom", O_RDONLY);
3401 if (fd < 0 || ::read(fd, &seed, sizeof(seed)) != sizeof(seed))
3402 {
3403 // No /dev/urandom... try something else.
3404 srand(getpid());
3405 seed = rand()+time(0);
3406 }
3407 if (fd >= 0) close(fd);
3408 srand(seed);
3409 }
3410 return rand();
3411}
3412
3413TQString TDEApplication::randomString(int length)
3414{
3415 if (length <=0 ) return TQString::null;
3416
3417 TQString str; str.setLength( length );
3418 int i = 0;
3419 while (length--)
3420 {
3421 int r=random() % 62;
3422 r+=48;
3423 if (r>57) r+=7;
3424 if (r>90) r+=6;
3425 str[i++] = char(r);
3426 // so what if I work backwards?
3427 }
3428 return str;
3429}
3430
3431bool TDEApplication::authorize(const TQString &genericAction)
3432{
3433 if (!d->actionRestrictions)
3434 return true;
3435
3436 TDEConfig *config = TDEGlobal::config();
3437 TDEConfigGroupSaver saver( config, "KDE Action Restrictions" );
3438 return config->readBoolEntry(genericAction, true);
3439}
3440
3441bool TDEApplication::authorizeTDEAction(const char *action)
3442{
3443 if (!d->actionRestrictions || !action)
3444 return true;
3445
3446 static const TQString &action_prefix = TDEGlobal::staticQString( "action/" );
3447
3448 return authorize(action_prefix + action);
3449}
3450
3451bool TDEApplication::authorizeControlModule(const TQString &menuId)
3452{
3453 if (menuId.isEmpty() || kde_kiosk_exception)
3454 return true;
3455 TDEConfig *config = TDEGlobal::config();
3456 TDEConfigGroupSaver saver( config, "TDE Control Module Restrictions" );
3457 return config->readBoolEntry(menuId, true);
3458}
3459
3460TQStringList TDEApplication::authorizeControlModules(const TQStringList &menuIds)
3461{
3462 TDEConfig *config = TDEGlobal::config();
3463 TDEConfigGroupSaver saver( config, "TDE Control Module Restrictions" );
3464 TQStringList result;
3465 for(TQStringList::ConstIterator it = menuIds.begin();
3466 it != menuIds.end(); ++it)
3467 {
3468 if (config->readBoolEntry(*it, true))
3469 result.append(*it);
3470 }
3471 return result;
3472}
3473
3474void TDEApplication::initUrlActionRestrictions()
3475{
3476 d->urlActionRestrictions.setAutoDelete(true);
3477 d->urlActionRestrictions.clear();
3478 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3479 ("open", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true));
3480 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3481 ("list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true));
3482// TEST:
3483// d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3484// ("list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, false));
3485// d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3486// ("list", TQString::null, TQString::null, TQString::null, "file", TQString::null, TQDir::homeDirPath(), true));
3487 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3488 ("link", TQString::null, TQString::null, TQString::null, ":internet", TQString::null, TQString::null, true));
3489 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3490 ("redirect", TQString::null, TQString::null, TQString::null, ":internet", TQString::null, TQString::null, true));
3491
3492 // We allow redirections to file: but not from internet protocols, redirecting to file:
3493 // is very popular among io-slaves and we don't want to break them
3494 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3495 ("redirect", TQString::null, TQString::null, TQString::null, "file", TQString::null, TQString::null, true));
3496 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3497 ("redirect", ":internet", TQString::null, TQString::null, "file", TQString::null, TQString::null, false));
3498
3499 // local protocols may redirect everywhere
3500 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3501 ("redirect", ":local", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, true));
3502
3503 // Anyone may redirect to about:
3504 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3505 ("redirect", TQString::null, TQString::null, TQString::null, "about", TQString::null, TQString::null, true));
3506
3507 // Anyone may redirect to itself, cq. within it's own group
3508 d->urlActionRestrictions.append( new TDEApplicationPrivate::URLActionRule
3509 ("redirect", TQString::null, TQString::null, TQString::null, "=", TQString::null, TQString::null, true));
3510
3511 TDEConfig *config = TDEGlobal::config();
3512 TDEConfigGroupSaver saver( config, "KDE URL Restrictions" );
3513 int count = config->readNumEntry("rule_count");
3514 TQString keyFormat = TQString("rule_%1");
3515 for(int i = 1; i <= count; i++)
3516 {
3517 TQString key = keyFormat.arg(i);
3518 TQStringList rule = config->readListEntry(key);
3519 if (rule.count() != 8)
3520 continue;
3521 TQString action = rule[0];
3522 TQString refProt = rule[1];
3523 TQString refHost = rule[2];
3524 TQString refPath = rule[3];
3525 TQString urlProt = rule[4];
3526 TQString urlHost = rule[5];
3527 TQString urlPath = rule[6];
3528 TQString strEnabled = rule[7].lower();
3529
3530 bool bEnabled = (strEnabled == "true");
3531
3532 if (refPath.startsWith("$HOME"))
3533 refPath.replace(0, 5, TQDir::homeDirPath());
3534 else if (refPath.startsWith("~"))
3535 refPath.replace(0, 1, TQDir::homeDirPath());
3536 if (urlPath.startsWith("$HOME"))
3537 urlPath.replace(0, 5, TQDir::homeDirPath());
3538 else if (urlPath.startsWith("~"))
3539 urlPath.replace(0, 1, TQDir::homeDirPath());
3540
3541 if (refPath.startsWith("$TMP"))
3542 refPath.replace(0, 4, TDEGlobal::dirs()->saveLocation("tmp"));
3543 if (urlPath.startsWith("$TMP"))
3544 urlPath.replace(0, 4, TDEGlobal::dirs()->saveLocation("tmp"));
3545
3546 d->urlActionRestrictions.append(new TDEApplicationPrivate::URLActionRule
3547 ( action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled));
3548 }
3549}
3550
3551void TDEApplication::allowURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL)
3552{
3553 if (authorizeURLAction(action, _baseURL, _destURL))
3554 return;
3555
3556 d->urlActionRestrictions.append(new TDEApplicationPrivate::URLActionRule
3557 ( action, _baseURL.protocol(), _baseURL.host(), _baseURL.path(-1),
3558 _destURL.protocol(), _destURL.host(), _destURL.path(-1), true));
3559}
3560
3561bool TDEApplication::authorizeURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL)
3562{
3563 if (_destURL.isEmpty())
3564 return true;
3565
3566 bool result = false;
3567 if (d->urlActionRestrictions.isEmpty())
3568 initUrlActionRestrictions();
3569
3570 KURL baseURL(_baseURL);
3571 baseURL.setPath(TQDir::cleanDirPath(baseURL.path()));
3572 TQString baseClass = KProtocolInfo::protocolClass(baseURL.protocol());
3573 KURL destURL(_destURL);
3574 destURL.setPath(TQDir::cleanDirPath(destURL.path()));
3575 TQString destClass = KProtocolInfo::protocolClass(destURL.protocol());
3576
3577 for(TDEApplicationPrivate::URLActionRule *rule = d->urlActionRestrictions.first();
3578 rule; rule = d->urlActionRestrictions.next())
3579 {
3580 if ((result != rule->permission) && // No need to check if it doesn't make a difference
3581 (action == rule->action) &&
3582 rule->baseMatch(baseURL, baseClass) &&
3583 rule->destMatch(destURL, destClass, baseURL, baseClass))
3584 {
3585 result = rule->permission;
3586 }
3587 }
3588 return result;
3589}
3590
3591
3592uint TDEApplication::keyboardModifiers()
3593{
3594#ifdef TQ_WS_X11
3595 Window root;
3596 Window child;
3597 int root_x, root_y, win_x, win_y;
3598 uint keybstate;
3599 XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child,
3600 &root_x, &root_y, &win_x, &win_y, &keybstate );
3601 return keybstate & 0x00ff;
3602#elif defined W_WS_MACX
3603 return GetCurrentEventKeyModifiers() & 0x00ff;
3604#else
3605 //TODO for win32
3606 return 0;
3607#endif
3608}
3609
3610uint TDEApplication::mouseState()
3611{
3612 uint mousestate;
3613#ifdef TQ_WS_X11
3614 Window root;
3615 Window child;
3616 int root_x, root_y, win_x, win_y;
3617 XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child,
3618 &root_x, &root_y, &win_x, &win_y, &mousestate );
3619#elif defined(TQ_WS_WIN)
3620 const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON);
3621 if (GetAsyncKeyState(VK_LBUTTON))
3622 mousestate |= (mousebtn_swapped ? Button3Mask : Button1Mask);
3623 if (GetAsyncKeyState(VK_MBUTTON))
3624 mousestate |= Button2Mask;
3625 if (GetAsyncKeyState(VK_RBUTTON))
3626 mousestate |= (mousebtn_swapped ? Button1Mask : Button3Mask);
3627#elif defined(TQ_WS_MACX)
3628 mousestate = GetCurrentEventButtonState();
3629#else
3630 //TODO: other platforms
3631#endif
3632 return mousestate & 0xff00;
3633}
3634
3635TQt::ButtonState TDEApplication::keyboardMouseState()
3636{
3637 int ret = 0;
3638#ifdef TQ_WS_X11
3639 Window root;
3640 Window child;
3641 int root_x, root_y, win_x, win_y;
3642 uint state;
3643 XQueryPointer( tqt_xdisplay(), tqt_xrootwin(), &root, &child,
3644 &root_x, &root_y, &win_x, &win_y, &state );
3645 // transform the same way like Qt's qt_x11_translateButtonState()
3646 if( state & Button1Mask )
3647 ret |= LeftButton;
3648 if( state & Button2Mask )
3649 ret |= MidButton;
3650 if( state & Button3Mask )
3651 ret |= RightButton;
3652 if( state & ShiftMask )
3653 ret |= ShiftButton;
3654 if( state & ControlMask )
3655 ret |= ControlButton;
3656 if( state & KKeyNative::modX( KKey::ALT ))
3657 ret |= AltButton;
3658 if( state & KKeyNative::modX( KKey::WIN ))
3659 ret |= MetaButton;
3660#elif defined(TQ_WS_WIN)
3661 const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON);
3662 if (GetAsyncKeyState(VK_LBUTTON))
3663 ret |= (mousebtn_swapped ? RightButton : LeftButton);
3664 if (GetAsyncKeyState(VK_MBUTTON))
3665 ret |= MidButton;
3666 if (GetAsyncKeyState(VK_RBUTTON))
3667 ret |= (mousebtn_swapped ? LeftButton : RightButton);
3668 if (GetAsyncKeyState(VK_SHIFT))
3669 ret |= ShiftButton;
3670 if (GetAsyncKeyState(VK_CONTROL))
3671 ret |= ControlButton;
3672 if (GetAsyncKeyState(VK_MENU))
3673 ret |= AltButton;
3674 if (GetAsyncKeyState(VK_LWIN) || GetAsyncKeyState(VK_RWIN))
3675 ret |= MetaButton;
3676#else
3677 //TODO: other platforms
3678#endif
3679 return static_cast< ButtonState >( ret );
3680}
3681
3682#if defined TQ_WS_X11
3683int TDEApplication::currentX11VT()
3684{
3685 return get_x_vtnum(TQPaintDevice::x11AppDisplay());
3686}
3687#else // TQ_WS_X11
3688int TDEApplication::currentX11VT()
3689{
3690 return -1;
3691}
3692#endif // TQ_WS_X11
3693
3694void TDEApplication::installSigpipeHandler()
3695{
3696#ifdef Q_OS_UNIX
3697 struct sigaction act;
3698 act.sa_handler = SIG_IGN;
3699 sigemptyset( &act.sa_mask );
3700 act.sa_flags = 0;
3701 sigaction( SIGPIPE, &act, 0 );
3702#endif
3703}
3704
3705void TDEApplication::sigpipeHandler(int)
3706{
3707 int saved_errno = errno;
3708 // Using kdDebug from a signal handler is not a good idea.
3709#ifndef NDEBUG
3710 char msg[1000];
3711 sprintf(msg, "*** SIGPIPE *** (ignored, pid = %ld)\n", (long) getpid());
3712 if (write(2, msg, strlen(msg)) < 0) {
3713 // ERROR
3714 }
3715#endif
3716
3717 // Do nothing.
3718 errno = saved_errno;
3719}
3720
3721bool TDEApplication::guiEnabled()
3722{
3723 return tdeApp && tdeApp->d->guiEnabled;
3724}
3725
3726void TDEApplication::virtual_hook( int id, void* data )
3727{ TDEInstance::virtual_hook( id, data ); }
3728
3729void KSessionManaged::virtual_hook( int, void* )
3730{ /*BASE::virtual_hook( id, data );*/ }
3731
3732#include "tdeapplication.moc"
DCOPClient
DCOPClient::appId
TQCString appId() const
DCOPClient::attach
bool attach()
DCOPClient::send
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
DCOPClient::isAttached
bool isAttached() const
DCOPClient::call
bool call(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData, bool useEventLoop, int timeout, bool forceRemote)
DCOPClient::setMainClient
static void setMainClient(DCOPClient *mainClient)
DCOPClient::setServerAddress
static void setServerAddress(const TQCString &addr)
DCOPClient::registerAs
TQCString registerAs(const TQCString &appId, bool addPID=true)
DCOPRef
DCOPRef::call
DCOPReply call(const TQCString &fun)
DCOPRef::send
bool send(const TQCString &fun)
KCodecs::base64Encode
static TQCString base64Encode(const TQByteArray &in, bool insertLFs=false)
Encodes the given data using the base64 algorithm.
Definition: kmdcodec.cpp:373
KIPC::BlockShortcuts
@ BlockShortcuts
Definition: kipc.h:59
KKey
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
Definition: tdeshortcut.h:41
KSessionManaged
Provides highlevel access to session management on a per-object base.
Definition: tdeapplication.h:1612
KSessionManaged::saveState
virtual bool saveState(TQSessionManager &sm)
See TQApplication::saveState() for documentation.
Definition: tdeapplication.cpp:1272
KSessionManaged::commitData
virtual bool commitData(TQSessionManager &sm)
See TQApplication::commitData() for documentation.
Definition: tdeapplication.cpp:1277
KURL
Represents and parses a URL.
Definition: kurl.h:128
KURL::path
TQString path() const
Returns the current decoded path.
Definition: kurl.h:532
KURL::query
TQString query() const
Returns the encoded query of the URL.
Definition: kurl.cpp:2094
KURL::encode_string
static TQString encode_string(const TQString &str, int encoding_hint=0)
Encodes a string for use in URLs.
Definition: kurl.cpp:2106
KURL::setPath
void setPath(const TQString &path)
Sets the decoded path of the URL.
Definition: kurl.cpp:2025
KURL::protocol
TQString protocol() const
Returns the protocol for the URL.
Definition: kurl.h:367
KURL::isEmpty
bool isEmpty() const
Tests if the KURL is empty.
Definition: kurl.cpp:652
KURL::setQuery
void setQuery(const TQString &_txt, int encoding_hint=0)
Sets the encoded query of the URL.
Definition: kurl.cpp:2047
KURL::url
TQString url(int _trailing=0, int encoding_hint=0) const
Returns the URL as string, with all escape sequences intact, encoded in a given charset.
Definition: kurl.cpp:1499
KURL::host
TQString host() const
Returns the decoded hostname included in the URL.
Definition: kurl.h:477
KURL::decode_string
static TQString decode_string(const TQString &str, int encoding_hint=0)
Decodes a string as used in URLs.
Definition: kurl.cpp:2101
KURL::setProtocol
void setProtocol(const TQString &_txt)
Sets the protocol for the URL.
Definition: kurl.cpp:1972
KWin::setIcons
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
Sets an icon and a miniIcon on window win.
Definition: twin.cpp:515
NET::timestampCompare
static int timestampCompare(unsigned long time1, unsigned long time2)
Compares two X timestamps, taking into account wrapping and 64bit architectures.
TDEAboutData::programName
TQString programName() const
Returns the translated program name.
Definition: tdeaboutdata.cpp:252
TDEAppDCOPInterface
This is the main interface to the TDEApplication.
Definition: tdeappdcopinterface.h:38
TDEApplication
Controls and provides information to all KDE applications.
Definition: tdeapplication.h:95
TDEApplication::getX11RGBAVisual
TQt::HANDLE getX11RGBAVisual(Display *dpy)
Returns the X11 display visual.
Definition: tdeapplication.cpp:2147
TDEApplication::invokeHTMLHelp
void invokeHTMLHelp(const TQString &aFilename, const TQString &aTopic=TQString::null) const TDE_DEPRECATED
Definition: tdeapplication.cpp:2694
TDEApplication::authorize
bool authorize(const TQString &genericAction)
Returns whether a certain action is authorized.
Definition: tdeapplication.cpp:3431
TDEApplication::caption
TQString caption() const
Returns a text for the window caption.
Definition: tdeapplication.cpp:2384
TDEApplication::appearanceChanged
void appearanceChanged()
Emitted when TDEApplication has changed either its GUI style, its font or its palette in response to ...
TDEApplication::copy
void copy()
If the widget with focus provides a copy() slot, call that slot.
Definition: tdeapplication.cpp:3027
TDEApplication::settingsChanged
void settingsChanged(int category)
Emitted when the global settings have been changed - see TDEGlobalSettings TDEApplication takes care ...
TDEApplication::startServiceByName
static int startServiceByName(const TQString &_name, const TQString &URL, TQString *error=0, TQCString *dcopService=0, int *pid=0, const TQCString &startup_id="", bool noWait=false)
Starts a service based on the (translated) name of the service.
Definition: tdeapplication.cpp:3142
TDEApplication::TDEApp
static TDEApplication * TDEApp
Current application object.
Definition: tdeapplication.h:1281
TDEApplication::installSigpipeHandler
static void installSigpipeHandler()
Installs a handler for the SIGPIPE signal.
Definition: tdeapplication.cpp:3694
TDEApplication::ShutdownType
ShutdownType
The possible values for the sdtype parameter of requestShutDown().
Definition: tdeapplication.h:357
TDEApplication::ShutdownTypeDefault
@ ShutdownTypeDefault
Select previous action or the default if it's the first time.
Definition: tdeapplication.h:361
TDEApplication::addKipcEventMask
void addKipcEventMask(int id)
Adds a message type to the KIPC event mask.
Definition: tdeapplication.cpp:2323
TDEApplication::tdedisplayStyleChanged
void tdedisplayStyleChanged()
Emitted when TDEApplication has changed its GUI style in response to a KControl request.
TDEApplication::startupId
TQCString startupId() const
Returns the app startup notification identifier for this running application.
Definition: tdeapplication.cpp:3355
TDEApplication::removeX11EventFilter
void removeX11EventFilter(const TQWidget *filter)
Removes global X11 event filter previously installed by installX11EventFilter().
Definition: tdeapplication.cpp:534
TDEApplication::ShutdownMode
ShutdownMode
The possible values for the sdmode parameter of requestShutDown().
Definition: tdeapplication.h:379
TDEApplication::ShutdownModeDefault
@ ShutdownModeDefault
Select previous mode or the default if it's the first time.
Definition: tdeapplication.h:383
TDEApplication::TDEApplication
TDEApplication(bool allowStyles=true, bool GUIenabled=true, bool SMenabled=true)
This constructor takes aboutData and command line arguments from TDECmdLineArgs.
Definition: tdeapplication.cpp:754
TDEApplication::installX11EventFilter
void installX11EventFilter(TQWidget *filter)
Installs widget filter as global X11 event filter.
Definition: tdeapplication.cpp:519
TDEApplication::propagateSessionManager
void propagateSessionManager()
Propagates the network address of the session manager in the SESSION_MANAGER environment variable so ...
Definition: tdeapplication.cpp:1374
TDEApplication::mouseState
static uint mouseState() TDE_DEPRECATED
Definition: tdeapplication.cpp:3610
TDEApplication::tdeinitExec
static int tdeinitExec(const TQString &name, const TQStringList &args, TQString *error, int *pid, const TQCString &startup_id)
Starts a program via tdeinit.
Definition: tdeapplication.cpp:3212
TDEApplication::detectCompositionManagerAvailable
bool detectCompositionManagerAvailable(bool force_available=false, bool available=true)
Detects the availability of a composition manager such as kompmgr Note that calling this method will ...
Definition: tdeapplication.cpp:2108
TDEApplication::authorizeURLAction
bool authorizeURLAction(const TQString &action, const KURL &baseURL, const KURL &destURL)
Returns whether a certain URL related action is authorized.
Definition: tdeapplication.cpp:3561
TDEApplication::toolbarAppearanceChanged
void toolbarAppearanceChanged(int)
Emitted when the settings for toolbars have been changed.
TDEApplication::launcher
static TQCString launcher()
Returns the DCOP name of the service launcher.
Definition: tdeapplication.cpp:3053
TDEApplication::tdedisplayPaletteChanged
void tdedisplayPaletteChanged()
Emitted when TDEApplication has changed its palette due to a KControl request.
TDEApplication::isX11CompositionAvailable
bool isX11CompositionAvailable()
Returns whether or not X11 composition is available.
Definition: tdeapplication.cpp:2155
TDEApplication::disableSessionManagement
void disableSessionManagement()
Disables session management for this application.
Definition: tdeapplication.cpp:1283
TDEApplication::random
static int random()
Generates a uniform random number.
Definition: tdeapplication.cpp:3393
TDEApplication::shutDown
void shutDown()
Your application is killed.
TDEApplication::invokeBrowser
void invokeBrowser(const TQString &url, const TQCString &startup_id)
Invokes the standard browser.
Definition: kapplication_win.cpp:93
TDEApplication::keyboardModifiers
static uint keyboardModifiers() TDE_DEPRECATED
Definition: tdeapplication.cpp:3592
TDEApplication::makeStdCaption
TQString makeStdCaption(const TQString &userCaption, bool withAppName=true, bool modified=false) const
Builds a caption that contains the application name along with the userCaption using a standard layou...
Definition: tdeapplication.cpp:2403
TDEApplication::broadcastKeyCode
void broadcastKeyCode(unsigned int keyCode)
Broadcast a received keycode to all listening KDE applications The primary use for this feature is to...
Definition: tdeapplication.cpp:3047
TDEApplication::invokeMailer
void invokeMailer(const TQString &address, const TQString &subject, const TQCString &startup_id)
Convenience method; invokes the standard email application.
Definition: tdeapplication.cpp:2734
TDEApplication::enableSessionManagement
void enableSessionManagement()
Enables again session management for this application, formerly disabled by calling disableSessionMan...
Definition: tdeapplication.cpp:1287
TDEApplication::installKDEPropertyMap
void installKDEPropertyMap()
Install a Qt SQL property map with entries for all KDE widgets Call this in any application using KDE...
Definition: tdeapplication.cpp:2609
TDEApplication::paste
void paste()
If the widget with focus provides a paste() slot, call that slot.
Definition: tdeapplication.cpp:3032
TDEApplication::commitData
void commitData(TQSessionManager &sm)
Reimplemented for internal purposes, mainly the highlevel handling of session management with KSessio...
Definition: tdeapplication.cpp:1409
TDEApplication::randomString
static TQString randomString(int length)
Generates a random string.
Definition: tdeapplication.cpp:3413
TDEApplication::keyboardMouseState
static ButtonState keyboardMouseState()
Returns the state of the currently pressed keyboard modifiers (e.g.
Definition: tdeapplication.cpp:3635
TDEApplication::allowURLAction
void allowURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL)
Allow a certain URL action.
Definition: tdeapplication.cpp:3551
TDEApplication::authorizeControlModules
TQStringList authorizeControlModules(const TQStringList &menuIds)
Returns whether access to a certain control modules is authorized.
Definition: tdeapplication.cpp:3460
TDEApplication::startServiceByDesktopPath
static int startServiceByDesktopPath(const TQString &_name, const TQString &URL, TQString *error=0, TQCString *dcopService=0, int *pid=0, const TQCString &startup_id="", bool noWait=false)
Starts a service based on the desktop path of the service.
Definition: tdeapplication.cpp:3163
TDEApplication::iconName
TQString iconName() const
Returns the name of the application icon.
Definition: tdeapplication.cpp:1832
TDEApplication::tdedisplayFontChanged
void tdedisplayFontChanged()
Emitted when TDEApplication has changed its font in response to a KControl request.
TDEApplication::invokeHelp
void invokeHelp(const TQString &anchor, const TQString &appname, const TQCString &startup_id) const
Invokes the KHelpCenter HTML help viewer from docbook sources.
Definition: kapplication_win.cpp:77
TDEApplication::currentX11VT
static int currentX11VT()
Returns the VT that the current X server is running on, or -1 if this information is unavailable.
Definition: tdeapplication.cpp:3688
TDEApplication::deref
void deref()
Tells TDEApplication that one operation such as those described in ref() just finished.
Definition: tdeapplication.cpp:1253
TDEApplication::saveYourself
void saveYourself()
TDEApplication::sessionSaving
bool sessionSaving() const
Returns true if the application is currently saving its session data (most probably before KDE logout...
Definition: tdeapplication.cpp:1564
TDEApplication::ref
void ref()
Tells TDEApplication about one more operation that should be finished before the application exits.
Definition: tdeapplication.cpp:1247
TDEApplication::authorizeControlModule
bool authorizeControlModule(const TQString &menuId)
Returns whether access to a certain control module is authorized.
Definition: tdeapplication.cpp:3451
TDEApplication::kipcMessage
void kipcMessage(int id, int data)
Emitted when a KIPC user message has been received.
TDEApplication::backgroundChanged
void backgroundChanged(int desk)
Emitted when the desktop background has been changed by kcmdisplay.
TDEApplication::updateUserTimestamp
void updateUserTimestamp(unsigned long time=0)
Updates the last user action timestamp to the given time, or to the current time, if 0 is given.
Definition: tdeapplication.cpp:2266
TDEApplication::checkRecoverFile
TQString checkRecoverFile(const TQString &pFilename, bool &bRecover) const
Check whether an auto-save file exists for the document you want to open.
Definition: tdeapplication.cpp:3262
TDEApplication::sessionConfig
TDEConfig * sessionConfig()
Returns the application session config object.
Definition: tdeapplication.cpp:1237
TDEApplication::clear
void clear()
If the widget with focus provides a clear() slot, call that slot.
Definition: tdeapplication.cpp:3037
TDEApplication::miniIconName
TQString miniIconName() const
Returns the name of the mini-icon for the application.
Definition: tdeapplication.cpp:1848
TDEApplication::setTopWidget
void setTopWidget(TQWidget *topWidget)
Sets the top widget of the application.
Definition: tdeapplication.cpp:3334
TDEApplication::createApplicationPalette
static TQPalette createApplicationPalette()
Used to obtain the TQPalette that will be used to set the application palette.
Definition: tdeapplication.cpp:2422
TDEApplication::authorizeTDEAction
bool authorizeTDEAction(const char *action)
Returns whether a certain TDEAction is authorized.
Definition: tdeapplication.cpp:3441
TDEApplication::geometryArgument
TQString geometryArgument() const
Returns the argument to –geometry if any, so the geometry can be set wherever necessary.
Definition: tdeapplication.cpp:1816
TDEApplication::saveState
void saveState(TQSessionManager &sm)
Reimplemented for internal purposes, mainly the highlevel handling of session management with KSessio...
Definition: tdeapplication.cpp:1482
TDEApplication::invokeEditSlot
void invokeEditSlot(const char *slot)
This method is used internally to determine which edit slots are implemented by the widget that has t...
Definition: tdeapplication.cpp:2308
TDEApplication::cut
void cut()
If the widget with focus provides a cut() slot, call that slot.
Definition: tdeapplication.cpp:3022
TDEApplication::SettingsCategory
SettingsCategory
Valid values for the settingsChanged signal.
Definition: tdeapplication.h:1392
TDEApplication::updateRemoteUserTimestamp
void updateRemoteUserTimestamp(const TQCString &dcopId, unsigned long time=0)
Updates the last user action timestamp in the application registered to DCOP with dcopId to the given...
Definition: tdeapplication.cpp:2299
TDEApplication::iconChanged
void iconChanged(int group)
Emitted when the global icon settings have been changed.
TDEApplication::disableStyles
void disableStyles()
Disables style plugins.
Definition: tdeapplication.cpp:2352
TDEApplication::selectAll
void selectAll()
If the widget with focus provides a selectAll() slot, call that slot.
Definition: tdeapplication.cpp:3042
TDEApplication::ShutdownConfirm
ShutdownConfirm
The possible values for the confirm parameter of requestShutDown().
Definition: tdeapplication.h:339
TDEApplication::ShutdownConfirmYes
@ ShutdownConfirmYes
Always confirm, ask even if the user turned it off.
Definition: tdeapplication.h:351
TDEApplication::ShutdownConfirmNo
@ ShutdownConfirmNo
Don't confirm, shutdown without asking.
Definition: tdeapplication.h:347
TDEApplication::tdeinitExecWait
static int tdeinitExecWait(const TQString &name, const TQStringList &args, TQString *error, int *pid, const TQCString &startup_id)
Starts a program via tdeinit and wait for it to finish.
Definition: tdeapplication.cpp:3227
TDEApplication::addCmdLineOptions
static void addCmdLineOptions()
Add Qt and KDE command line options to TDECmdLineArgs.
Definition: tdeapplication.cpp:1690
TDEApplication::startServiceByDesktopName
static int startServiceByDesktopName(const TQString &_name, const TQString &URL, TQString *error=0, TQCString *dcopService=0, int *pid=0, const TQCString &startup_id="", bool noWait=false)
Starts a service based on the desktop name of the service.
Definition: tdeapplication.cpp:3184
TDEApplication::userTimestamp
unsigned long userTimestamp() const
Returns the last user action timestamp or 0 if no user activity has taken place yet.
Definition: tdeapplication.cpp:2290
TDEApplication::getX11RGBAColormap
TQt::HANDLE getX11RGBAColormap(Display *dpy)
Returns the X11 display colormap.
Definition: tdeapplication.cpp:2151
TDEApplication::removeKipcEventMask
void removeKipcEventMask(int id)
Removes a message type from the KIPC event mask.
Definition: tdeapplication.cpp:2333
TDEApplication::isCompositionManagerAvailable
static bool isCompositionManagerAvailable()
Gets the availability of a composition manager such as kompmgr Note that at least one application mus...
Definition: tdeapplication.cpp:2104
TDEApplication::disableAutoDcopRegistration
static void disableAutoDcopRegistration()
Disable automatic dcop registration Must be called before creating a TDEApplication instance to have ...
Definition: tdeapplication.cpp:1232
TDEApplication::enableStyles
void enableStyles()
Enables style plugins.
Definition: tdeapplication.cpp:2343
TDEApplication::tempSaveName
TQString tempSaveName(const TQString &pFilename) const
Get a file name in order to make a temporary copy of your document.
Definition: tdeapplication.cpp:3234
TDEApplication::requestShutDown
bool requestShutDown(ShutdownConfirm confirm=ShutdownConfirmDefault, ShutdownType sdtype=ShutdownTypeDefault, ShutdownMode sdmode=ShutdownModeDefault)
Asks the session manager to shut the session down.
Definition: tdeapplication.cpp:1311
TDEApplication::dcopClient
static DCOPClient * dcopClient()
Returns a pointer to a DCOPClient for the application.
Definition: tdeapplication.cpp:1187
TDEClipboardSynchronizer::self
static TDEClipboardSynchronizer * self()
Returns the TDEClipboardSynchronizer singleton object.
Definition: kclipboard.cpp:97
TDECmdLineArgs
A class for command-line argument handling.
Definition: tdecmdlineargs.h:223
TDECmdLineArgs::isSet
bool isSet(const char *option) const
Read out a boolean option or check for the presence of string option.
Definition: tdecmdlineargs.cpp:1181
TDECmdLineArgs::appName
static const char * appName()
Get the appname according to argv[0].
Definition: tdecmdlineargs.cpp:199
TDECmdLineArgs::parsedArgs
static TDECmdLineArgs * parsedArgs(const char *id=0)
Access parsed arguments.
Definition: tdecmdlineargs.cpp:310
TDECmdLineArgs::addCmdLineOptions
static void addCmdLineOptions(const TDECmdLineOptions *options, const char *name=0, const char *id=0, const char *afterId=0)
Add options to your application.
Definition: tdecmdlineargs.cpp:206
TDECmdLineArgs::getOption
TQCString getOption(const char *option) const
Read out a string option.
Definition: tdecmdlineargs.cpp:1119
TDEConfigBase
KDE Configuration Management abstract base class.
Definition: tdeconfigbase.h:71
TDEConfigBase::readEntry
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
Definition: tdeconfigbase.cpp:221
TDEConfigBase::readColorEntry
TQColor readColorEntry(const TQString &pKey, const TQColor *pDefault=0L) const
Reads a TQColor entry.
Definition: tdeconfigbase.cpp:947
TDEConfigBase::readNumEntry
int readNumEntry(const TQString &pKey, int nDefault=0) const
Reads a numerical value.
Definition: tdeconfigbase.cpp:613
TDEConfigBase::readBoolEntry
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
Definition: tdeconfigbase.cpp:748
TDEConfigBase::readSizeEntry
TQSize readSizeEntry(const TQString &pKey, const TQSize *pDefault=0L) const
Reads a TQSize entry.
Definition: tdeconfigbase.cpp:921
TDEConfigBase::hasGroup
bool hasGroup(const TQString &group) const
Returns true if the specified group is known about.
Definition: tdeconfigbase.cpp:152
TDEConfigBase::readListEntry
int readListEntry(const TQString &pKey, TQStrList &list, char sep=',') const
Reads a list of strings.
Definition: tdeconfigbase.cpp:467
TDEConfigBase::sync
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage.
Definition: tdeconfigbase.cpp:1738
TDEConfigBase::checkConfigFilesWritable
bool checkConfigFilesWritable(bool warnUser)
Check whether the config files are writable.
Definition: tdeconfigbase.cpp:1904
TDEConfigBase::readPathEntry
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads a path.
Definition: tdeconfigbase.cpp:585
TDEConfigBase::setGroup
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
Definition: tdeconfigbase.cpp:79
TDEConfigGroupSaver
Helper class to facilitate working with TDEConfig / KSimpleConfig groups.
Definition: tdeconfigbase.h:2083
TDEConfigGroup
A TDEConfigBase derived class for one specific group in a TDEConfig object.
Definition: tdeconfigbase.h:2127
TDEConfig
Access KDE Configuration entries.
Definition: tdeconfig.h:44
TDEConfig::reparseConfiguration
virtual void reparseConfiguration()
Clears all internal data structures and then reread configuration information from disk.
Definition: tdeconfig.cpp:161
TDECrash::setEmergencySaveFunction
static void setEmergencySaveFunction(HandlerType saveFunction=(HandlerType) 0)
Installs a function which should try to save the applications data.
Definition: tdecrash.cpp:70
TDECrash::defaultCrashHandler
static void defaultCrashHandler(int signal)
The default crash handler.
Definition: tdecrash.cpp:119
TDECrash::setCrashHandler
static void setCrashHandler(HandlerType handler=defaultCrashHandler)
Install a function to be called in case a SIGSEGV is caught.
Definition: tdecrash.cpp:86
TDECrash::setApplicationName
static void setApplicationName(TQString name)
Sets the application name name which should be passed to Dr.
Definition: tdecrash.h:108
TDEGlobalSettings::menuFont
static TQFont menuFont()
Returns the default menu font.
Definition: tdeglobalsettings.cpp:518
TDEGlobalSettings::generalFont
static TQFont generalFont()
Returns the default general font.
Definition: tdeglobalsettings.cpp:470
TDEGlobalSettings::contrast
static int contrast()
Returns the contrast for borders.
Definition: tdeglobalsettings.cpp:363
TDEGlobalSettings::fixedFont
static TQFont fixedFont()
Returns the default fixed font.
Definition: tdeglobalsettings.cpp:486
TDEGlobal::iconLoader
static TDEIconLoader * iconLoader()
Returns an iconloader object.
Definition: tdeglobal.cpp:79
TDEGlobal::config
static TDEConfig * config()
Returns the general config object.
Definition: tdeglobal.cpp:65
TDEGlobal::dirs
static TDEStandardDirs * dirs()
Returns the application standard dirs object.
Definition: tdeglobal.cpp:58
TDEGlobal::instance
static TDEInstance * instance()
Returns the global instance.
Definition: tdeglobal.cpp:102
TDEGlobal::checkAccess
bool checkAccess(const TQString &pathname, int mode)
Check, if a file may be accessed in a given mode.
Definition: tdeapplication.cpp:3300
TDEGlobal::locale
static TDELocale * locale()
Returns the global locale object.
Definition: tdeglobal.cpp:108
TDEGlobal::deleteStaticDeleters
static void deleteStaticDeleters()
Calls KStaticDeleterBase::destructObject() on all registered static deleters and unregisters them all...
Definition: tdeglobal.cpp:205
TDEGlobal::staticQString
static const TQString & staticQString(const char *str)
Creates a static TQString.
Definition: tdeglobal.cpp:148
TDEIconLoader::loadIcon
TQPixmap loadIcon(const TQString &name, TDEIcon::Group group, int size=0, int state=TDEIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
Loads an icon.
Definition: kiconloader.cpp:583
TDEIcon::DefaultState
@ DefaultState
The default state.
Definition: kicontheme.h:130
TDEIcon::NoGroup
@ NoGroup
No group.
Definition: kicontheme.h:90
TDEIcon::SizeLarge
@ SizeLarge
large sized icons for the panel
Definition: kicontheme.h:120
TDEInstance
Access to KDE global objects for use in shared libraries.
Definition: kinstance.h:48
TDEInstance::instanceName
TQCString instanceName() const
Returns the name of the instance.
Definition: kinstance.cpp:342
TDEInstance::config
TDEConfig * config() const
Returns the general config object ("appnamerc").
Definition: kinstance.cpp:212
TDEInstance::mimeSourceFactory
KMimeSourceFactory * mimeSourceFactory() const
Returns the KMimeSourceFactory of the instance.
Definition: kinstance.cpp:348
TDEInstance::newIconLoader
void newIconLoader() const
Re-allocate the global iconloader.
Definition: kinstance.cpp:329
TDEInstance::aboutData
const TDEAboutData * aboutData() const
Returns the about data of this instance Warning, can be 0L.
Definition: kinstance.cpp:336
TDEInstance::setConfigName
void setConfigName(const TQString &name)
Set name of default config file.
Definition: kinstance.cpp:270
TDELocale::i18n
TQString i18n(const char *text)
i18n is the function that does everything you need to translate a string.
Definition: tdelocale.cpp:1976
TDELocale::I18N_NOOP
#define I18N_NOOP(x)
I18N_NOOP marks a string to be translated without translating it.
Definition: tdelocale.h:51
TDELockFile
The TDELockFile class provides NFS safe lockfiles.
Definition: klockfile.h:34
TDELockFile::LockOK
@ LockOK
Lock was acquired successfully.
Definition: klockfile.h:52
TDELockFile::LockNoBlock
@ LockNoBlock
Return immediately, do not wait for the lock to become available.
Definition: klockfile.h:74
TDEProcessController::deref
static void deref()
Destroy the instance if one exists and it is not referenced any more.
Definition: tdeprocctrl.cpp:48
TDEProcessController::ref
static void ref()
Create an instance if none exists yet.
Definition: tdeprocctrl.cpp:39
TDEShortcut
The TDEShortcut class is used to represent a keyboard shortcut to an action.
Definition: tdeshortcut.h:544
TDEShortcut::contains
bool contains(const KKey &key) const
Checks whether this shortcut contains a sequence that starts with the given key.
Definition: tdeshortcut.cpp:532
TDEStandardDirs::saveLocation
TQString saveLocation(const char *type, const TQString &suffix=TQString::null, bool create=true) const
Finds a location to save files into for the given type in the user's home directory.
Definition: tdestandarddirs.cpp:1099
TDEStandardDirs::resourceDirs
TQStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
Definition: tdestandarddirs.cpp:795
TDEStandardDirs::findExe
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
Finds the executable in the system path.
Definition: tdestandarddirs.cpp:932
TDEStandardDirs::addResourceType
bool addResourceType(const char *type, const TQString &relativename)
Adds suffixes for types.
Definition: tdestandarddirs.cpp:255
TDEStandardDirs::kde_default
static TQString kde_default(const char *type)
This returns a default relative path for the standard TDE resource types.
Definition: tdestandarddirs.cpp:1036
endl
kndbgstream & endl(kndbgstream &s)
Does nothing.
Definition: kdebug.h:583
KMacroExpander::expandMacros
TQString expandMacros(const TQString &ostr, const TQMap< TQChar, TQString > &map, TQChar c)
Perform safe macro expansion (substitution) on a string.
Definition: kmacroexpander.cpp:520
KNotifyClient::event
int event(const TQString &message, const TQString &text=TQString::null) TDE_DEPRECATED
Definition: knotifyclient.cpp:125
KShell::splitArgs
TQStringList splitArgs(const TQString &cmd, int flags=0, int *err=0)
Splits cmd according to POSIX shell word splitting and quoting rules.
Definition: kshell.cpp:65
KStdAction::action
TDEAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, TDEActionCollection *parent, const char *name=0L)
KStdAction::name
const char * name(StdAction id)
TDEStdAccel::key
int key(StdAccel id)
Definition: tdestdaccel.cpp:383
TDEStdAccel::selectAll
const TDEShortcut & selectAll()
Reload.
Definition: tdestdaccel.cpp:313
TDECmdLineOptions
Structure that holds command line options.
Definition: tdecmdlineargs.h:41
tdelocale.h

tdecore

Skip menu "tdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdecore

Skip menu "tdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdecore by doxygen 1.9.4
This website is maintained by Timothy Pearson.