23 #ifdef HAVE_XCOMPOSITE 35 #undef QT_NO_TRANSLATION 36 #undef TQT_NO_TRANSLATION 37 #include <tqtranslator.h> 42 #define TDEAPPLICATION_BINARY_COMPAT_HACK 1 43 #include "kapplication.h" 44 #undef TDEAPPLICATION_BINARY_COMPAT_HACK 46 #define QT_NO_TRANSLATION 47 #define TQT_NO_TRANSLATION 49 #include <tqptrcollection.h> 50 #include <tqwidgetlist.h> 51 #include <tqstrlist.h> 53 #include <tqmessagebox.h> 54 #include <tqtextstream.h> 56 #include <tqlineedit.h> 57 #include <tqtextedit.h> 58 #include <tqsessionmanager.h> 59 #include <tqptrlist.h> 61 #include <tqstylesheet.h> 62 #include <tqpixmapcache.h> 63 #include <tqtooltip.h> 64 #include <tqstylefactory.h> 65 #include <tqmetaobject.h> 68 #include <tqsqlpropertymap.h> 72 #include <kstandarddirs.h> 76 #include <kiconloader.h> 77 #include <kclipboard.h> 79 #include <ksimpleconfig.h> 80 #include <kcmdlineargs.h> 81 #include <kaboutdata.h> 82 #include <kglobalsettings.h> 84 #include <kdatastream.h> 85 #include <klibloader.h> 86 #include <kmimesourcefactory.h> 87 #include <kstdaccel.h> 89 #include "kcheckaccelerators.h" 90 #include <tqptrdict.h> 91 #include <kmacroexpander.h> 93 #include <kprotocolinfo.h> 94 #include <kkeynative.h> 96 #include <kglobalaccel.h> 99 #include <kstartupinfo.h> 102 #include <dcopclient.h> 105 #include <sys/types.h> 106 #ifdef HAVE_SYS_STAT_H 107 #include <sys/stat.h> 109 #include <sys/wait.h> 111 #include <sys/types.h> 122 #include <sys/time.h> 131 #include "kprocctrl.h" 138 #include <X11/Xlib.h> 140 #include <X11/extensions/Xrender.h> 141 #include <X11/extensions/Xcomposite.h> 144 #include <X11/Xutil.h> 145 #include <X11/Xatom.h> 146 #include <X11/SM/SMlib.h> 153 #include <KDE-ICE/ICElib.h> 155 typedef void* IceIOErrorHandler;
158 #define Button1Mask (1<<8) 159 #define Button2Mask (1<<9) 160 #define Button3Mask (1<<10) 164 #define DISPLAY "DISPLAY" 165 #elif defined(Q_WS_QWS) 166 #define DISPLAY "QWS_DISPLAY" 174 #include <Carbon/Carbon.h> 178 #include "kappdcopiface.h" 181 KDE_EXPORT
bool kde_have_kipc =
true;
182 bool kde_kiosk_exception =
false;
183 bool kde_kiosk_admin =
false;
186 bool KApplication::loadedByKdeinit =
false;
188 bool KApplication::s_dcopClientNeedsPostInit =
false;
191 static Atom atom_DesktopWindow;
192 static Atom atom_NetSupported;
195 #if defined(Q_WS_X11) && defined(COMPOSITE) 196 static int composite_event, composite_error, composite_opcode;
197 static bool x11_composite_error_generated;
198 static int x11_error(Display *dpy, XErrorEvent *ev) {
199 if (ev->request_code == composite_opcode && ev->minor_code == X_CompositeRedirectSubwindows)
201 x11_composite_error_generated =
true;
209 KDECORE_EXPORT
bool qt_qclipboard_bailout_hack =
false;
211 template class TQPtrList<KSessionManaged>;
215 static int kde_xio_errhandler( Display * dpy )
217 return kapp->xioErrhandler( dpy );
220 static int kde_x_errhandler( Display *dpy, XErrorEvent *err )
222 return kapp->xErrhandler( dpy, err );
228 static void kde_ice_ioerrorhandler( IceConn conn )
231 kapp->iceIOErrorHandler( conn );
238 void KApplication_init_windows(
bool GUIenabled);
240 class QAssistantClient;
246 class KApplicationPrivate
249 KApplicationPrivate()
250 : actionRestrictions( false ),
252 oldIceIOErrorHandler( 0 ),
253 checkAccelerators( 0 ),
254 overrideStyle( TQString::null ),
256 app_started_timer( NULL ),
257 m_KAppDCOPInterface( 0L ),
258 session_save( false )
260 ,oldXErrorHandler( NULL )
261 ,oldXIOErrorHandler( NULL )
262 #elif defined Q_WS_WIN
263 ,qassistantclient( 0 )
268 ~KApplicationPrivate()
271 delete qassistantclient;
276 bool actionRestrictions : 1;
285 IceIOErrorHandler oldIceIOErrorHandler;
286 KCheckAccelerators* checkAccelerators;
287 TQString overrideStyle;
288 TQString geometry_arg;
289 TQCString startup_id;
290 TQTimer* app_started_timer;
294 int (*oldXErrorHandler)(Display*,XErrorEvent*);
295 int (*oldXIOErrorHandler)(Display*);
296 #elif defined Q_WS_WIN 297 QAssistantClient* qassistantclient;
303 #define checkExactMatch(s, b) \ 304 if (s.isEmpty()) b = true; \ 305 else if (s[s.length()-1] == '!') \ 306 { b = false; s.truncate(s.length()-1); } \ 308 #define checkStartWildCard(s, b) \ 309 if (s.isEmpty()) b = true; \ 310 else if (s[0] == '*') \ 311 { b = true; s = s.mid(1); } \ 313 #define checkEqual(s, b) \ 316 URLActionRule(
const TQString &act,
317 const TQString &bProt,
const TQString &bHost,
const TQString &bPath,
318 const TQString &dProt,
const TQString &dHost,
const TQString &dPath,
321 baseProt(bProt), baseHost(bHost), basePath(bPath),
322 destProt(dProt), destHost(dHost), destPath(dPath),
325 checkExactMatch(baseProt, baseProtWildCard);
326 checkStartWildCard(baseHost, baseHostWildCard);
327 checkExactMatch(basePath, basePathWildCard);
328 checkExactMatch(destProt, destProtWildCard);
329 checkStartWildCard(destHost, destHostWildCard);
330 checkExactMatch(destPath, destPathWildCard);
331 checkEqual(destProt, destProtEqual);
332 checkEqual(destHost, destHostEqual);
335 bool baseMatch(
const KURL &url,
const TQString &protClass)
337 if (baseProtWildCard)
339 if ( !baseProt.isEmpty() && !url.
protocol().startsWith(baseProt) &&
340 (protClass.isEmpty() || (protClass != baseProt)) )
345 if ( (url.
protocol() != baseProt) &&
346 (protClass.isEmpty() || (protClass != baseProt)) )
349 if (baseHostWildCard)
351 if (!baseHost.isEmpty() && !url.
host().endsWith(baseHost))
356 if (url.
host() != baseHost)
359 if (basePathWildCard)
361 if (!basePath.isEmpty() && !url.
path().startsWith(basePath))
366 if (url.
path() != basePath)
372 bool destMatch(
const KURL &url,
const TQString &protClass,
const KURL &base,
const TQString &baseClass)
377 (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass) )
380 else if (destProtWildCard)
382 if ( !destProt.isEmpty() && !url.
protocol().startsWith(destProt) &&
383 (protClass.isEmpty() || (protClass != destProt)) )
388 if ( (url.
protocol() != destProt) &&
389 (protClass.isEmpty() || (protClass != destProt)) )
392 if (destHostWildCard)
394 if (!destHost.isEmpty() && !url.
host().endsWith(destHost))
397 else if (destHostEqual)
404 if (url.
host() != destHost)
407 if (destPathWildCard)
409 if (!destPath.isEmpty() && !url.
path().startsWith(destPath))
414 if (url.
path() != destPath)
427 bool baseProtWildCard : 1;
428 bool baseHostWildCard : 1;
429 bool basePathWildCard : 1;
430 bool destProtWildCard : 1;
431 bool destHostWildCard : 1;
432 bool destPathWildCard : 1;
433 bool destProtEqual : 1;
434 bool destHostEqual : 1;
437 TQPtrList<URLActionRule> urlActionRestrictions;
440 TQString pSessionConfigFile;
444 static TQPtrList<TQWidget>*x11Filter = 0;
445 static bool autoDcopRegistration =
true;
452 x11Filter =
new TQPtrList<TQWidget>;
453 connect ( filter, TQT_SIGNAL( destroyed() ),
this, TQT_SLOT( x11FilterDestroyed() ) );
454 x11Filter->append( filter );
457 void KApplication::x11FilterDestroyed()
464 if ( !x11Filter || !filter )
466 x11Filter->removeRef( filter );
467 if ( x11Filter->isEmpty() ) {
477 extern bool kde_g_bKillAccelOverride;
479 bool KApplication::notify(TQObject *receiver, TQEvent *event)
481 TQEvent::Type t = event->type();
482 if (kde_g_bKillAccelOverride)
484 kde_g_bKillAccelOverride =
false;
486 if (t == TQEvent::AccelOverride)
488 TQT_TQKEYEVENT(event)->accept();
492 kdWarning(125) <<
"kde_g_bKillAccelOverride set, but received an event other than AccelOverride." <<
endl;
495 if ((t == TQEvent::AccelOverride) || (t == TQEvent::KeyPress))
498 TQLineEdit *edit = ::tqqt_cast<TQLineEdit *>(receiver);
502 TQKeyEvent *kevent = TQT_TQKEYEVENT(event);
506 if (t == TQEvent::KeyPress)
517 if (key ==
KKey(Qt::CTRL + Qt::Key_U))
519 if (t == TQEvent::KeyPress)
521 if (!edit->isReadOnly())
523 TQString t(edit->text());
524 t = t.mid(edit->cursorPosition());
525 edit->validateAndSet(t, 0, 0, 0);
536 TQTextEdit *medit = ::tqqt_cast<TQTextEdit *>(receiver);
540 TQKeyEvent *kevent = TQT_TQKEYEVENT(event);
543 if (t == TQEvent::KeyPress)
555 if( t == TQEvent::Show && receiver->isWidgetType())
557 TQWidget* w = TQT_TQWIDGET( receiver );
559 if( w->isTopLevel() && !
startupId().isEmpty() && !TQT_TQSHOWEVENT(event)->spontaneous())
560 KStartupInfo::setWindowStartupId( w->winId(),
startupId());
562 if( w->isTopLevel() && !w->testWFlags( WX11BypassWM ) && !w->isPopup() && !event->spontaneous())
564 if( d->app_started_timer == NULL )
566 d->app_started_timer =
new TQTimer(
this,
"app_started_timer" );
567 connect( d->app_started_timer, TQT_SIGNAL( timeout()), TQT_SLOT( checkAppStartedSlot()));
569 if( !d->app_started_timer->isActive())
570 d->app_started_timer->start( 0,
true );
572 if( w->isTopLevel() && ( w->icon() == NULL || w->icon()->isNull()))
575 static TQPixmap* ic = NULL;
588 return TQApplication::notify(receiver, event);
591 void KApplication::checkAppStartedSlot()
594 KStartupInfo::handleAutoAppStartedSending();
599 static TQPtrList<KSessionManaged>* sessionClients()
601 static TQPtrList<KSessionManaged>* session_clients = 0L;
602 if ( !session_clients )
603 session_clients =
new TQPtrList<KSessionManaged>;
604 return session_clients;
612 TQString KApplication::sessionConfigName()
const 614 TQString sessKey = sessionKey();
615 if ( sessKey.isEmpty() && !d->sessionKey.isEmpty() )
616 sessKey = d->sessionKey;
617 return TQString(
"session/%1_%2_%3").arg(name()).arg(sessionId()).arg(sessKey);
621 static SmcConn mySmcConnection = 0;
622 static SmcConn tmpSmcConnection = 0;
627 static TQTime* smModificationTime = 0;
630 bool allowStyles,
bool GUIenabled,
bool SMenabled ) :
631 TQApplication( argc, argv, GUIenabled, SMenabled ),
KInstance(rAppName),
636 d (new KApplicationPrivate())
638 aIconPixmap.pm.icon = 0L;
639 aIconPixmap.pm.miniIcon = 0L;
640 read_app_startup_id();
643 useStyles = allowStyles;
644 Q_ASSERT (!rAppName.isEmpty());
648 KCmdLineArgs::initIgnore(argc, argv, rAppName.data());
658 bool allowStyles,
bool GUIenabled ) :
659 TQApplication( argc, argv, GUIenabled ),
KInstance(rAppName),
664 d (
new KApplicationPrivate())
666 aIconPixmap.pm.icon = 0L;
667 aIconPixmap.pm.miniIcon = 0L;
668 read_app_startup_id();
671 useStyles = allowStyles;
672 Q_ASSERT (!rAppName.isEmpty());
676 KCmdLineArgs::initIgnore(argc, argv, rAppName.data());
690 d (new KApplicationPrivate)
692 aIconPixmap.pm.icon = 0L;
693 aIconPixmap.pm.miniIcon = 0L;
694 read_app_startup_id();
697 useStyles = allowStyles;
711 TQApplication( *KCmdLineArgs::qt_argc(), *KCmdLineArgs::qt_argv(), GUIenabled ),
717 d (
new KApplicationPrivate)
719 aIconPixmap.pm.icon = 0L;
720 aIconPixmap.pm.miniIcon = 0L;
721 read_app_startup_id();
724 useStyles = allowStyles;
735 TQApplication( dpy, *KCmdLineArgs::qt_argc(), *KCmdLineArgs::qt_argv(),
737 KInstance( KCmdLineArgs::about), display(0L), d (
new KApplicationPrivate)
739 aIconPixmap.pm.icon = 0L;
740 aIconPixmap.pm.miniIcon = 0L;
741 read_app_startup_id();
742 useStyles = allowStyles;
751 TQApplication( dpy, *KCmdLineArgs::qt_argc(), *KCmdLineArgs::qt_argv(),
753 KInstance( KCmdLineArgs::about), display(0L), d (
new KApplicationPrivate)
755 aIconPixmap.pm.icon = 0L;
756 aIconPixmap.pm.miniIcon = 0L;
757 read_app_startup_id();
758 useStyles = allowStyles;
759 if (disable_argb) argb_visual =
false;
769 TQApplication( dpy, *KCmdLineArgs::qt_argc(), *KCmdLineArgs::qt_argv(),
771 KInstance( KCmdLineArgs::about), display(0L), d (
new KApplicationPrivate)
773 if ((visual) && (colormap))
774 getX11RGBAInformation(dpy);
775 aIconPixmap.pm.icon = 0L;
776 aIconPixmap.pm.miniIcon = 0L;
777 read_app_startup_id();
778 useStyles = allowStyles;
787 bool allowStyles,
KInstance * _instance ) :
788 TQApplication( dpy, *KCmdLineArgs::qt_argc(), *KCmdLineArgs::qt_argv(),
790 KInstance( _instance ), display(0L), d (
new KApplicationPrivate)
792 if ((visual) && (colormap))
793 getX11RGBAInformation(dpy);
794 aIconPixmap.pm.icon = 0L;
795 aIconPixmap.pm.miniIcon = 0L;
796 read_app_startup_id();
797 useStyles = allowStyles;
807 TQApplication( *KCmdLineArgs::qt_argc(), *KCmdLineArgs::qt_argv(),
814 d (
new KApplicationPrivate)
816 aIconPixmap.pm.icon = 0L;
817 aIconPixmap.pm.miniIcon = 0L;
818 read_app_startup_id();
821 useStyles = allowStyles;
832 bool allowStyles,
bool GUIenabled ) :
833 TQApplication( display ),
KInstance(rAppName),
836 d (
new KApplicationPrivate())
838 aIconPixmap.pm.icon = 0L;
839 aIconPixmap.pm.miniIcon = 0L;
840 read_app_startup_id();
843 useStyles = allowStyles;
845 Q_ASSERT (!rAppName.isEmpty());
849 KCmdLineArgs::initIgnore(argc, argv, rAppName.data());
856 int KApplication::xioErrhandler( Display* dpy )
862 d->oldXIOErrorHandler( dpy );
871 int KApplication::xErrhandler( Display* dpy,
void* err_ )
874 XErrorEvent* err =
static_cast< XErrorEvent*
>( err_ );
878 d->oldXErrorHandler( dpy, err );
884 void KApplication::iceIOErrorHandler( _IceConn *conn )
889 if ( d->oldIceIOErrorHandler != NULL )
890 (*d->oldIceIOErrorHandler)( conn );
895 class KDETranslator :
public TQTranslator
898 KDETranslator(TQObject *parent) : TQTranslator(parent,
"kdetranslator") {}
899 virtual TQTranslatorMessage findMessage(
const char* context,
900 const char *sourceText,
901 const char* message)
const 903 TQTranslatorMessage res;
904 res.setTranslation(
KGlobal::locale()->translateQt(context, sourceText, message));
909 void KApplication::init(
bool GUIenabled)
911 d->guiEnabled = GUIenabled;
912 if ((getuid() != geteuid()) ||
913 (getgid() != getegid()) )
917 struct group *man = getgrnam(
"man");
918 if ( !man || man->gr_gid != getegid() ){
919 fprintf(stderr,
"The KDE libraries are not designed to run with suid privileges.\n");
928 TQApplication::setDesktopSettingsAware(
false );
933 #ifdef Q_WS_X11 //FIXME(E) 939 Atom atoms_return[max];
942 atoms[n] = &kipcCommAtom;
943 names[n++] = (
char *)
"KIPC_COMM_ATOM";
945 atoms[n] = &atom_DesktopWindow;
946 names[n++] = (
char *)
"KDE_DESKTOP_WINDOW";
948 atoms[n] = &atom_NetSupported;
949 names[n++] = (
char *)
"_NET_SUPPORTED";
951 XInternAtoms( qt_xdisplay(), names, n,
false, atoms_return );
953 for (
int i = 0; i < n; i++ )
954 *atoms[i] = atoms_return[i];
958 dcopAutoRegistration();
959 dcopClientPostInit();
965 kipcEventMask = (1 << KIPC::StyleChanged) | (1 << KIPC::PaletteChanged) |
966 (1 << KIPC::FontChanged) | (1 << KIPC::BackgroundChanged) |
967 (1 << KIPC::ToolbarStyleChanged) | (1 << KIPC::SettingsChanged) |
975 d->actionRestrictions = config->
hasGroup(
"KDE Action Restrictions" ) && !kde_kiosk_exception;
980 TQCString readOnly = getenv(
"KDE_HOME_READONLY");
981 if (readOnly.isEmpty() && (tqstrcmp(name(),
"kdialog") != 0))
992 fcntl(ConnectionNumber(qt_xdisplay()), F_SETFD, FD_CLOEXEC);
994 d->oldXErrorHandler = XSetErrorHandler( kde_x_errhandler );
995 d->oldXIOErrorHandler = XSetIOErrorHandler( kde_xio_errhandler );
998 connect(
this, TQT_SIGNAL( aboutToQuit() ),
this, TQT_SIGNAL(
shutDown() ) );
1000 #ifdef Q_WS_X11 //FIXME(E) 1001 display = desktop()->x11Display();
1006 TQStringList::Iterator it = plugins.begin();
1007 while (it != plugins.end()) {
1008 addLibraryPath( *it );
1016 propagateSettings(SETTINGS_QT);
1026 TQMimeSourceFactory* oldDefaultFactory = TQMimeSourceFactory::takeDefaultFactory();
1028 if ( oldDefaultFactory ) {
1029 TQMimeSourceFactory::addFactory( oldDefaultFactory );
1032 d->checkAccelerators =
new KCheckAccelerators( TQT_TQOBJECT(
this) );
1039 if (!pixmap.isNull()) {
1040 TQImage i = pixmap.convertToImage().convertDepth(32).smoothScale(40, 40);
1041 for(
int y = 0; y < i.height(); y++) {
1042 uchar *l = i.scanLine(y);
1043 for(
int x = 0; x < i.width(); x+=4)
1046 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
1047 CGDataProviderRef dp = CGDataProviderCreateWithData(NULL,
1048 i.bits(), i.numBytes(), NULL);
1049 CGImageRef ir = CGImageCreate(i.width(), i.height(), 8, 32, i.bytesPerLine(),
1050 cs, kCGImageAlphaNoneSkipFirst, dp,
1051 0, 0, kCGRenderingIntentDefault);
1053 SetApplicationDockTileImage(ir);
1055 CGColorSpaceRelease(cs);
1056 CGDataProviderRelease(dp);
1064 bool rtl = reverseLayout();
1065 installTranslator(
new KDETranslator(TQT_TQOBJECT(
this)));
1066 setReverseLayout( rtl );
1067 if (i18n(
"_: Dear Translator! Translate this string to the string 'LTR' in " 1068 "left-to-right languages (as english) or to 'RTL' in right-to-left " 1069 "languages (such as Hebrew and Arabic) to get proper widget layout." ) ==
"RTL")
1070 setReverseLayout( !rtl );
1074 + TQString::fromLatin1(name()) +
'/');
1075 pSessionConfig = 0L;
1076 bSessionManagement =
true;
1080 if (GUIenabled && kde_have_kipc )
1082 smw =
new TQWidget(0,0);
1084 XChangeProperty(qt_xdisplay(), smw->winId(),
1085 atom_DesktopWindow, atom_DesktopWindow,
1086 32, PropModeReplace, (
unsigned char *)&data, 1);
1088 d->oldIceIOErrorHandler = IceSetIOErrorHandler( kde_ice_ioerrorhandler );
1089 #elif defined(Q_WS_WIN) 1090 KApplication_init_windows(GUIenabled);
1096 static int my_system (
const char *command) {
1103 const char* shell =
"/bin/sh";
1104 execl(shell, shell,
"-c", command, (
void *)0);
1108 if (waitpid(pid, &status, 0) == -1) {
1120 return s_DCOPClient;
1124 if (args && args->
isSet(
"dcopserver"))
1129 connect(s_DCOPClient, TQT_SIGNAL(attachFailed(
const TQString &)),
1130 kapp, TQT_SLOT(dcopFailure(
const TQString &)));
1131 connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(
bool) ),
1132 kapp, TQT_SLOT(dcopBlockUserInput(
bool)) );
1135 s_dcopClientNeedsPostInit =
true;
1138 return s_DCOPClient;
1141 void KApplication::dcopClientPostInit()
1143 if( s_dcopClientNeedsPostInit )
1145 s_dcopClientNeedsPostInit =
false;
1146 connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(
bool) ),
1147 TQT_SLOT(dcopBlockUserInput(
bool)) );
1148 s_DCOPClient->bindToApp();
1152 void KApplication::dcopAutoRegistration()
1154 if (autoDcopRegistration)
1164 autoDcopRegistration =
false;
1170 return pSessionConfig;
1173 pSessionConfig =
new KConfig( sessionConfigName(),
false,
false);
1174 return pSessionConfig;
1187 if ( d->refCount <= 0 )
1191 KSessionManaged::KSessionManaged()
1193 sessionClients()->remove(
this );
1194 sessionClients()->append(
this );
1197 KSessionManaged::~KSessionManaged()
1199 sessionClients()->remove(
this );
1214 bSessionManagement =
false;
1218 bSessionManagement =
true;
1229 if( mySmcConnection ) {
1230 SmcRequestSaveYourself( mySmcConnection, SmSaveLocal, False,
1235 IceFlush(SmcGetIceConnection(mySmcConnection));
1245 TQApplication::syncX();
1252 TQDataStream arg(data, IO_WriteOnly);
1253 arg << (int)confirm << (
int)sdtype << (int)sdmode;
1255 "logout(int,int,int)", data );
1258 if ( mySmcConnection ) {
1260 SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True,
1265 IceFlush(SmcGetIceConnection(mySmcConnection));
1272 TQCString smEnv = ::getenv(
"SESSION_MANAGER");
1273 if (smEnv.isEmpty())
1276 if (! tmpSmcConnection) {
1281 tmpSmcConnection = SmcOpenConnection( 0, 0, 1, 0,
1288 if (!tmpSmcConnection )
1292 SmcRequestSaveYourself( tmpSmcConnection, SmSaveBoth, True,
1293 SmInteractStyleAny, False, True );
1296 IceFlush(SmcGetIceConnection(tmpSmcConnection));
1307 TQCString fName = TQFile::encodeName(locateLocal(
"socket",
"KSMserver"));
1308 TQCString display = ::getenv(DISPLAY);
1310 display.replace(TQRegExp(
"\\.[0-9]+$"),
"");
1312 while( (i = display.find(
':')) >= 0)
1315 fName +=
"_"+display;
1316 TQCString smEnv = ::getenv(
"SESSION_MANAGER");
1317 bool check = smEnv.isEmpty();
1318 if ( !check && smModificationTime ) {
1319 TQFileInfo info( fName );
1320 TQTime current = TQT_TQTIME_OBJECT(info.lastModified().time());
1321 check = current > *smModificationTime;
1324 delete smModificationTime;
1326 if ( !f.open( IO_ReadOnly ) )
1328 TQFileInfo info ( f );
1329 smModificationTime =
new TQTime( TQT_TQTIME_OBJECT(info.lastModified().time()) );
1331 t.setEncoding( TQTextStream::Latin1 );
1332 TQString s = t.readLine();
1334 ::setenv(
"SESSION_MANAGER", s.latin1(), true );
1341 d->session_save =
true;
1342 bool canceled =
false;
1345 it = sessionClients()->next() ) {
1346 canceled = !it->commitData( sm );
1351 if ( sm.allowsInteraction() ) {
1353 TQWidgetList *list = TQApplication::topLevelWidgets();
1354 bool canceled =
false;
1355 TQWidget* w = list->first();
1356 while ( !canceled && w ) {
1357 if ( !w->testWState( WState_ForceHide ) && !w->inherits(
"KMainWindow") ) {
1360 canceled = !e.isAccepted();
1364 list = TQApplication::topLevelWidgets();
1369 while ( w && done.containsRef( w ) )
1376 if ( !bSessionManagement )
1377 sm.setRestartHint( TQSessionManager::RestartNever );
1379 sm.setRestartHint( TQSessionManager::RestartIfRunning );
1380 d->session_save =
false;
1383 static void checkRestartVersion( TQSessionManager& sm )
1385 Display* dpy = qt_xdisplay();
1388 unsigned long nitems, after;
1389 unsigned char* data;
1390 if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy,
"TDE_FULL_SESSION", False ),
1391 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) {
1394 if( type == XA_STRING && format == 8 ) {
1395 if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy,
"KDE_SESSION_VERSION", False ),
1396 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) {
1407 TQStringList restartCommand = sm.restartCommand();
1408 restartCommand.prepend( wrapper );
1409 sm.setRestartCommand( restartCommand );
1414 d->session_save =
true;
1416 static bool firstTime =
true;
1417 mySmcConnection = (SmcConn) sm.handle();
1419 if ( !bSessionManagement ) {
1420 sm.setRestartHint( TQSessionManager::RestartNever );
1421 d->session_save =
false;
1425 sm.setRestartHint( TQSessionManager::RestartIfRunning );
1429 d->session_save =
false;
1439 if ( pSessionConfig ) {
1440 delete pSessionConfig;
1445 TQStringList restartCommand = sm.restartCommand();
1447 TQCString multiHead = getenv(
"KDE_MULTIHEAD");
1448 if (multiHead.lower() ==
"true") {
1455 TQCString displayname = getenv(DISPLAY);
1456 if (! displayname.isNull()) {
1459 restartCommand.append(
"-display");
1460 restartCommand.append(displayname);
1462 sm.setRestartCommand( restartCommand );
1465 checkRestartVersion( sm );
1469 bool canceled =
false;
1472 it = sessionClients()->next() ) {
1473 canceled = !it->saveState( sm );
1477 if ( pSessionConfig ) {
1478 pSessionConfig->
sync();
1479 TQStringList discard;
1480 discard <<
"rm" << locateLocal(
"config", sessionConfigName());
1481 sm.setDiscardCommand( discard );
1483 sm.setDiscardCommand( TQStringList(
"") );
1491 d->session_save =
false;
1496 return d->session_save;
1499 void KApplication::startKdeinit()
1501 #ifndef Q_WS_WIN //TODO 1503 KLockFile lock( locateLocal(
"tmp",
"startkdeinitlock", &inst ));
1516 if (kapp && (Tty != kapp->type()))
1517 setOverrideCursor( tqwaitCursor );
1518 my_system(TQFile::encodeName(srv)+
" --suicide"+
" --new-startup");
1519 if (kapp && (Tty != kapp->type()))
1520 restoreOverrideCursor();
1524 void KApplication::dcopFailure(
const TQString &msg)
1526 static int failureCount = 0;
1528 if (failureCount == 1)
1533 if (failureCount == 2)
1540 TQString msgStr(i18n(
"There was an error setting up inter-process " 1541 "communications for KDE. The message returned " 1542 "by the system was:\n\n"));
1544 msgStr += i18n(
"\n\nPlease check that the \"dcopserver\" program is running!");
1546 if (Tty != kapp->type())
1548 TQMessageBox::critical
1551 i18n(
"DCOP communications error (%1)").arg(kapp->caption()),
1558 fprintf(stderr,
"%s\n", msgStr.local8Bit().data());
1569 {
"display <displayname>", I18N_NOOP(
"Use the X-server display 'displayname'"), 0},
1571 {
"display <displayname>", I18N_NOOP(
"Use the QWS display 'displayname'"), 0},
1573 {
"session <sessionId>", I18N_NOOP(
"Restore the application for the given 'sessionId'"), 0},
1574 {
"cmap", I18N_NOOP(
"Causes the application to install a private color\nmap on an 8-bit display"), 0},
1575 {
"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},
1576 {
"nograb", I18N_NOOP(
"tells Qt to never grab the mouse or the keyboard"), 0},
1577 {
"dograb", I18N_NOOP(
"running under a debugger can cause an implicit\n-nograb, use -dograb to override"), 0},
1578 {
"sync", I18N_NOOP(
"switches to synchronous mode for debugging"), 0},
1580 {
"font <fontname>", I18N_NOOP(
"defines the application font"), 0},
1582 {
"background <color>", I18N_NOOP(
"sets the default background color and an\napplication palette (light and dark shades are\ncalculated)"), 0},
1584 {
"foreground <color>", I18N_NOOP(
"sets the default foreground color"), 0},
1586 {
"button <color>", I18N_NOOP(
"sets the default button color"), 0},
1587 {
"name <name>", I18N_NOOP(
"sets the application name"), 0},
1588 {
"title <title>", I18N_NOOP(
"sets the application title (caption)"), 0},
1590 {
"visual TrueColor", I18N_NOOP(
"forces the application to use a TrueColor visual on\nan 8-bit display"), 0},
1591 {
"inputstyle <inputstyle>", I18N_NOOP(
"sets XIM (X Input Method) input style. Possible\nvalues are onthespot, overthespot, offthespot and\nroot"), 0 },
1592 {
"im <XIM server>", I18N_NOOP(
"set XIM server"),0},
1593 {
"noxim", I18N_NOOP(
"disable XIM"), 0 },
1596 {
"qws", I18N_NOOP(
"forces the application to run as QWS Server"), 0},
1598 {
"reverse", I18N_NOOP(
"mirrors the whole layout of widgets"), 0},
1604 {
"caption <caption>", I18N_NOOP(
"Use 'caption' as name in the titlebar"), 0},
1605 {
"icon <icon>", I18N_NOOP(
"Use 'icon' as the application icon"), 0},
1606 {
"miniicon <icon>", I18N_NOOP(
"Use 'icon' as the icon in the titlebar"), 0},
1607 {
"config <filename>", I18N_NOOP(
"Use alternative configuration file"), 0},
1608 {
"dcopserver <server>", I18N_NOOP(
"Use the DCOP Server specified by 'server'"), 0},
1609 {
"nocrashhandler", I18N_NOOP(
"Disable crash handler, to get core dumps"), 0},
1610 {
"waitforwm", I18N_NOOP(
"Waits for a WM_NET compatible windowmanager"), 0},
1611 {
"style <style>", I18N_NOOP(
"sets the application GUI style"), 0},
1612 {
"geometry <geometry>", I18N_NOOP(
"sets the client geometry of the main widget - see man X for the argument format"), 0},
1613 {
"smkey <sessionKey>", 0, 0},
1626 void KApplication::parseCommandLine( )
1630 if ( !args )
return;
1632 if (args->
isSet(
"config"))
1638 if (args->
isSet(
"style"))
1642 TQStringList::Iterator itp = plugins.begin();
1643 while (itp != plugins.end()) {
1644 addLibraryPath( *itp );
1648 TQStringList styles = TQStyleFactory::keys();
1649 TQString reqStyle(args->
getOption(
"style").lower());
1651 TQStringList list = libraryPaths();
1652 TQStringList::Iterator it = list.begin();
1653 while( it != list.end() ) {
1657 for (TQStringList::ConstIterator it = styles.begin(); it != styles.end(); ++it) {
1658 if ((*it).lower() == reqStyle)
1660 d->overrideStyle = *it;
1665 if (d->overrideStyle.isEmpty())
1666 fprintf(stderr,
"%s", TQString(i18n(
"The style %1 was not found\n").arg(reqStyle)).local8Bit().data());
1669 if (args->
isSet(
"caption"))
1671 aCaption = TQString::fromLocal8Bit(args->
getOption(
"caption"));
1674 if (args->
isSet(
"miniicon"))
1676 const char *tmp = args->
getOption(
"miniicon");
1677 if (!aIconPixmap.pm.miniIcon) {
1678 aIconPixmap.pm.miniIcon =
new TQPixmap;
1680 *aIconPixmap.pm.miniIcon = SmallIcon(tmp);
1681 aMiniIconName = tmp;
1684 if (args->
isSet(
"icon"))
1686 const char *tmp = args->
getOption(
"icon");
1687 if (!aIconPixmap.pm.icon) {
1688 aIconPixmap.pm.icon =
new TQPixmap;
1690 *aIconPixmap.pm.icon = DesktopIcon( tmp );
1692 if (!aIconPixmap.pm.miniIcon) {
1693 aIconPixmap.pm.miniIcon =
new TQPixmap;
1695 if (aIconPixmap.pm.miniIcon->isNull())
1697 *aIconPixmap.pm.miniIcon = SmallIcon( tmp );
1698 aMiniIconName = tmp;
1702 bool nocrashhandler = (getenv(
"KDE_DEBUG") != NULL);
1703 if (!nocrashhandler && args->
isSet(
"crashhandler"))
1713 if ( args->
isSet(
"waitforwm" ) ) {
1717 unsigned long length, after;
1718 unsigned char *data;
1719 while ( XGetWindowProperty( qt_xdisplay(), qt_xrootwin(), atom_NetSupported,
1720 0, 1,
false, AnyPropertyType, &type, &format,
1721 &length, &after, &data ) != Success || !length ) {
1725 XWindowEvent( qt_xdisplay(), qt_xrootwin(), PropertyChangeMask, &event );
1734 if (args->
isSet(
"geometry"))
1736 d->geometry_arg = args->
getOption(
"geometry");
1739 if (args->
isSet(
"smkey"))
1741 d->sessionKey = args->
getOption(
"smkey");
1748 return d->geometry_arg;
1753 if( !aIconPixmap.pm.icon) {
1754 aIconPixmap.pm.icon =
new TQPixmap;
1756 if( aIconPixmap.pm.icon->isNull()) {
1759 return *aIconPixmap.pm.icon;
1764 return aIconName.isNull() ? (TQString)
instanceName() : aIconName;
1769 if (!aIconPixmap.pm.miniIcon) {
1770 aIconPixmap.pm.miniIcon =
new TQPixmap;
1772 if (aIconPixmap.pm.miniIcon->isNull()) {
1773 *aIconPixmap.pm.miniIcon = SmallIcon(
instanceName() );
1775 return *aIconPixmap.pm.miniIcon;
1780 return aMiniIconName.isNull() ? (TQString)
instanceName() : aMiniIconName;
1783 extern void kDebugCleanup();
1785 KApplication::~KApplication()
1787 delete aIconPixmap.pm.miniIcon;
1788 aIconPixmap.pm.miniIcon = 0L;
1789 delete aIconPixmap.pm.icon;
1790 aIconPixmap.pm.icon = 0L;
1791 delete d->m_KAppDCOPInterface;
1797 KLibLoader::cleanUp();
1802 delete s_DCOPClient;
1808 if ( d->oldXErrorHandler != NULL )
1809 XSetErrorHandler( d->oldXErrorHandler );
1810 if ( d->oldXIOErrorHandler != NULL )
1811 XSetIOErrorHandler( d->oldXIOErrorHandler );
1812 if ( d->oldIceIOErrorHandler != NULL )
1813 IceSetIOErrorHandler( d->oldIceIOErrorHandler );
1820 mySmcConnection = 0;
1821 delete smModificationTime;
1822 smModificationTime = 0;
1825 if (tmpSmcConnection) {
1826 SmcCloseConnection( tmpSmcConnection, 0, 0 );
1827 tmpSmcConnection = 0;
1836 class KAppX11HackWidget:
public QWidget
1839 bool publicx11Event( XEvent * e) {
return x11Event( e ); }
1843 #if defined(Q_WS_X11) && defined(COMPOSITE) 1845 bool have_manager =
false;
1848 p = getpwuid(getuid());
1852 home = getenv(
"HOME");
1855 const char *configfile =
"/.kompmgr.available";
1856 int n = strlen(home)+strlen(configfile)+1;
1857 filename = (
char*)malloc(n*
sizeof(
char));
1858 memset(filename,0,n);
1859 strcat(filename, home);
1860 strcat(filename, configfile);
1864 pFile = fopen(filename,
"r");
1866 have_manager =
true;
1873 return have_manager;
1877 bool compositing_manager_available;
1878 if (force_available) {
1879 compositing_manager_available = available;
1884 char *displayname = 0;
1885 if ( qtargs->
isSet(
"display"))
1886 displayname = qtargs->
getOption(
"display" ).data();
1888 Display *dpy = XOpenDisplay( displayname );
1890 x11_composite_error_generated =
false;
1891 compositing_manager_available =
false;
1892 XSetErrorHandler(x11_error);
1893 if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode, &composite_event, &composite_error)) {
1894 XSetErrorHandler(NULL);
1895 compositing_manager_available =
false;
1899 Window root_window = XDefaultRootWindow(dpy);
1900 XCompositeRedirectSubwindows(dpy, root_window, CompositeRedirectManual);
1902 if (x11_composite_error_generated ==
true) {
1903 compositing_manager_available =
true;
1906 XCompositeUnredirectSubwindows(dpy, root_window, CompositeRedirectManual);
1907 compositing_manager_available =
false;
1909 XSetErrorHandler(NULL);
1913 compositing_manager_available =
true;
1920 p = getpwuid(getuid());
1924 home = getenv(
"HOME");
1927 const char *configfile =
"/.kompmgr.available";
1928 int n = strlen(home)+strlen(configfile)+1;
1929 filename = (
char*)malloc(n*
sizeof(
char));
1930 memset(filename,0,n);
1931 strcat(filename, home);
1932 strcat(filename, configfile);
1935 if (compositing_manager_available) {
1938 sprintf(buffer,
"available");
1939 pFile = fopen(filename,
"w");
1941 fwrite(buffer,1,strlen(buffer), pFile);
1952 return compositing_manager_available;
1955 Display* KApplication::openX11RGBADisplay() {
1958 if ( qtargs->
isSet(
"display"))
1959 display = qtargs->
getOption(
"display" ).data();
1961 Display *dpy = XOpenDisplay( display );
1963 kdError() <<
"cannot connect to X server " << display <<
endl;
1971 getX11RGBAInformation(dpy);
1973 return argb_x11_visual;
1976 return (Qt::HANDLE)NULL;
1981 getX11RGBAInformation(dpy);
1983 return argb_x11_colormap;
1986 return (Qt::HANDLE)NULL;
1994 void KApplication::getX11RGBAInformation(Display *dpy) {
1996 argb_visual =
false;
2000 int screen = DefaultScreen( dpy );
2001 Colormap colormap = 0;
2003 int event_base, error_base;
2005 if ( XRenderQueryExtension( dpy, &event_base, &error_base ) ) {
2008 templ.screen = screen;
2010 templ.c_class = TrueColor;
2011 XVisualInfo *xvi = XGetVisualInfo( dpy, VisualScreenMask | VisualDepthMask
2012 | VisualClassMask, &templ, &nvi );
2014 for (
int i = 0; i < nvi; i++ ) {
2015 XRenderPictFormat *format = XRenderFindVisualFormat( dpy, xvi[i].visual );
2016 if ( format->type == PictTypeDirect && format->direct.alphaMask ) {
2017 visual = xvi[i].visual;
2018 colormap = XCreateColormap( dpy, RootWindow( dpy, screen ), visual, AllocNone );
2019 kdDebug() <<
"[kdecore-kapplication] Found visual with alpha support" <<
endl;
2027 argb_x11_visual = Qt::HANDLE( visual );
2028 argb_x11_colormap = Qt::HANDLE( colormap );
2032 argb_visual =
false;
2036 void KApplication::getX11RGBAInformation(Display *dpy) {
2046 p = getpwuid(getuid());
2050 home = getenv(
"HOME");
2053 const char *configfile =
"/.kompmgr.available";
2054 int n = strlen(home)+strlen(configfile)+1;
2055 filename = (
char*)malloc(n*
sizeof(
char));
2056 memset(filename,0,n);
2057 strcat(filename, home);
2058 strcat(filename, configfile);
2061 if (force_available) {
2064 sprintf(buffer,
"available");
2065 pFile = fopen(filename,
"w");
2067 fwrite(buffer,1,strlen(buffer), pFile);
2081 Display* KApplication::openX11RGBADisplay() {
2098 static bool kapp_block_user_input =
false;
2100 void KApplication::dcopBlockUserInput(
bool b )
2102 kapp_block_user_input = b;
2106 bool KApplication::x11EventFilter( XEvent *_event )
2108 if ( kapp_block_user_input ) {
2109 switch ( _event->type ) {
2124 for (TQWidget *w=x11Filter->first(); w; w=x11Filter->next()) {
2125 if (((KAppX11HackWidget*) w)->publicx11Event(_event))
2130 if ((_event->type == ClientMessage) &&
2131 (_event->xclient.message_type == kipcCommAtom))
2133 XClientMessageEvent *cme = (XClientMessageEvent *) _event;
2135 int id = cme->data.l[0];
2136 int arg = cme->data.l[1];
2137 if ((
id < 32) && (kipcEventMask & (1 << id)))
2141 case KIPC::StyleChanged:
2146 case KIPC::ToolbarStyleChanged:
2152 case KIPC::PaletteChanged:
2154 kdisplaySetPalette();
2157 case KIPC::FontChanged:
2159 KGlobalSettings::rereadFontSettings();
2163 case KIPC::BackgroundChanged:
2167 case KIPC::SettingsChanged:
2169 if (arg == SETTINGS_PATHS)
2170 KGlobalSettings::rereadPathSettings();
2171 else if (arg == SETTINGS_MOUSE)
2172 KGlobalSettings::rereadMouseSettings();
2176 case KIPC::IconChanged:
2177 TQPixmapCache::clear();
2180 emit updateIconLoaders();
2184 case KIPC::ClipboardConfigChanged:
2185 KClipboardSynchronizer::newConfiguration(arg);
2189 KGlobalAccel::blockShortcuts(arg);
2206 #if defined Q_WS_X11 2207 Display *display = qt_xdisplay();
2213 Window w = XCreateSimpleWindow( display, qt_xrootwin(), 0, 0, 1, 1, 0, 0, 0 );
2214 XSelectInput( qt_xdisplay(), w, PropertyChangeMask );
2215 unsigned char data[ 1 ];
2216 XChangeProperty( display, w, XA_ATOM, XA_ATOM, 8, PropModeAppend, data, 1 );
2218 XWindowEvent( display, w, PropertyChangeMask, &ev );
2219 time = ev.xproperty.time;
2220 XDestroyWindow( display, w );
2222 if( GET_QT_X_USER_TIME() == 0
2224 SET_QT_X_USER_TIME(time);
2230 #if defined Q_WS_X11 2231 return GET_QT_X_USER_TIME();
2239 #if defined Q_WS_X11 2241 time = GET_QT_X_USER_TIME();
2242 DCOPRef( dcopId,
"MainApplication-Interface" ).
call(
"updateUserTimestamp", time );
2248 TQObject *
object = TQT_TQOBJECT(focusWidget());
2252 TQMetaObject *meta =
object->metaObject();
2254 int idx = meta->findSlot( slot + 1,
true );
2258 object->qt_invoke( idx, 0 );
2265 kdDebug(101) <<
"[kdecore-kapplication] Cannot use KIPC event mask for message IDs >= 32\n";
2268 kipcEventMask |= (1 << id);
2275 kdDebug(101) <<
"[kdecore-kapplication] Cannot use KIPC event mask for message IDs >= 32\n";
2278 kipcEventMask &= ~(1 << id);
2295 void KApplication::applyGUIStyle()
2297 if ( !useStyles )
return;
2300 TQString defaultStyle = KStyle::defaultStyle();
2301 TQString styleStr = pConfig.
readEntry(
"widgetStyle", defaultStyle);
2303 if (d->overrideStyle.isEmpty()) {
2307 TQStyle* sp = TQStyleFactory::create( styleStr );
2310 if ( !sp && styleStr != defaultStyle)
2311 sp = TQStyleFactory::create( defaultStyle );
2313 sp = TQStyleFactory::create( *(TQStyleFactory::keys().begin()) );
2317 setStyle(d->overrideStyle);
2319 kdisplaySetPalette();
2325 if( !aCaption.isNull() )
2342 bool withAppName,
bool modified )
const 2344 TQString s = userCaption.isEmpty() ?
caption() : userCaption;
2348 s += TQString::fromUtf8(
" [") + i18n(
"modified") + TQString::fromUtf8(
"]");
2350 if ( !userCaption.isEmpty() ) {
2353 if ( withAppName && !
caption().isNull() && !userCaption.endsWith(
caption()) )
2354 s += TQString::fromUtf8(
" - ") +
caption();
2369 TQColor trinity4Background( 239, 239, 239 );
2370 TQColor trinity4Blue( 103,141,178 );
2372 TQColor trinity4Button;
2373 if ( TQPixmap::defaultDepth() > 8 )
2374 trinity4Button.setRgb( 221, 223, 228 );
2376 trinity4Button.setRgb( 220, 220, 220 );
2378 TQColor trinity4Link( 0, 0, 238 );
2379 TQColor trinity4VisitedLink( 82, 24, 139 );
2381 TQColor background = config->
readColorEntry(
"background", &trinity4Background );
2382 TQColor foreground = config->
readColorEntry(
"foreground", tqblackptr );
2383 TQColor button = config->
readColorEntry(
"buttonBackground", &trinity4Button );
2384 TQColor buttonText = config->
readColorEntry(
"buttonForeground", tqblackptr );
2385 TQColor highlight = config->
readColorEntry(
"selectBackground", &trinity4Blue );
2386 TQColor highlightedText = config->
readColorEntry(
"selectForeground", tqwhiteptr );
2387 TQColor base = config->
readColorEntry(
"windowBackground", tqwhiteptr );
2388 TQColor baseText = config->
readColorEntry(
"windowForeground", tqblackptr );
2389 TQColor link = config->
readColorEntry(
"linkColor", &trinity4Link );
2390 TQColor visitedLink = config->
readColorEntry(
"visitedLinkColor", &trinity4VisitedLink );
2392 int highlightVal, lowlightVal;
2393 highlightVal = 100 + (2*contrast_+4)*16/10;
2394 lowlightVal = 100 + (2*contrast_+4)*10;
2396 TQColor disfg = foreground;
2399 disfg.hsv( &h, &s, &v );
2402 disfg = disfg.dark(lowlightVal);
2403 else if (disfg != Qt::black)
2405 disfg = disfg.light(highlightVal);
2408 disfg = Qt::darkGray;
2411 TQColorGroup disabledgrp(disfg, background,
2412 background.light(highlightVal),
2413 background.dark(lowlightVal),
2414 background.dark(120),
2415 background.dark(120), base);
2417 TQColorGroup colgrp(foreground, background, background.light(highlightVal),
2418 background.dark(lowlightVal),
2419 background.dark(120),
2422 int inlowlightVal = lowlightVal-25;
2423 if(inlowlightVal < 120)
2424 inlowlightVal = 120;
2426 colgrp.setColor(TQColorGroup::Highlight, highlight);
2427 colgrp.setColor(TQColorGroup::HighlightedText, highlightedText);
2428 colgrp.setColor(TQColorGroup::Button, button);
2429 colgrp.setColor(TQColorGroup::ButtonText, buttonText);
2430 colgrp.setColor(TQColorGroup::Midlight, background.light(110));
2431 colgrp.setColor(TQColorGroup::Link, link);
2432 colgrp.setColor(TQColorGroup::LinkVisited, visitedLink);
2434 disabledgrp.setColor(TQColorGroup::Button, button);
2436 TQColor disbtntext = buttonText;
2437 disbtntext.hsv( &h, &s, &v );
2440 disbtntext = disbtntext.dark(lowlightVal);
2441 else if (disbtntext != Qt::black)
2443 disbtntext = disbtntext.light(highlightVal);
2446 disbtntext = Qt::darkGray;
2448 disabledgrp.setColor(TQColorGroup::ButtonText, disbtntext);
2449 disabledgrp.setColor(TQColorGroup::Midlight, background.light(110));
2450 disabledgrp.setColor(TQColorGroup::Highlight, highlight.dark(120));
2451 disabledgrp.setColor(TQColorGroup::Link, link);
2452 disabledgrp.setColor(TQColorGroup::LinkVisited, visitedLink);
2454 return TQPalette(colgrp, disabledgrp, colgrp);
2458 void KApplication::kdisplaySetPalette()
2465 bool do_not_set_palette = FALSE;
2466 if(config->
readBoolEntry(
"nopaletteChange", &do_not_set_palette))
2476 void KApplication::kdisplaySetFont()
2484 TQStyleSheet* sheet = TQStyleSheet::defaultSheet();
2494 void KApplication::kdisplaySetStyle()
2510 #ifdef QT_HAVE_MAX_IMAGE_SIZE 2511 TQSize maxImageSize(4096, 4096);
2512 maxImageSize = config->
readSizeEntry(
"MaxImageSize", &maxImageSize);
2513 TQImage::setMaxImageSize(maxImageSize);
2516 int num = config->
readNumEntry(
"CursorBlinkRate", TQApplication::cursorFlashTime());
2517 if ((num != 0) && (num < 200))
2521 TQApplication::setCursorFlashTime(num);
2522 num = config->
readNumEntry(
"DoubleClickInterval", TQApplication::doubleClickInterval());
2523 TQApplication::setDoubleClickInterval(num);
2524 num = config->
readNumEntry(
"StartDragTime", TQApplication::startDragTime());
2525 TQApplication::setStartDragTime(num);
2526 num = config->
readNumEntry(
"StartDragDist", TQApplication::startDragDistance());
2527 TQApplication::setStartDragDistance(num);
2528 num = config->
readNumEntry(
"WheelScrollLines", TQApplication::wheelScrollLines());
2529 TQApplication::setWheelScrollLines(num);
2532 TQApplication::setEffectEnabled( Qt::UI_AnimateMenu, b);
2534 TQApplication::setEffectEnabled( Qt::UI_FadeMenu, b);
2536 TQApplication::setEffectEnabled( Qt::UI_AnimateCombo, b);
2538 TQApplication::setEffectEnabled( Qt::UI_AnimateTooltip, b);
2540 TQApplication::setEffectEnabled( Qt::UI_FadeTooltip, b);
2542 TQToolTip::setGloballyEnabled( b );
2550 static bool installed =
false;
2551 if (installed)
return;
2560 TQSqlPropertyMap *kdeMap =
new TQSqlPropertyMap;
2561 kdeMap->insert(
"KColorButton",
"color" );
2562 kdeMap->insert(
"KComboBox",
"currentItem" );
2563 kdeMap->insert(
"KDatePicker",
"date" );
2564 kdeMap->insert(
"KDateWidget",
"date" );
2565 kdeMap->insert(
"KDateTimeWidget",
"dateTime" );
2566 kdeMap->insert(
"KEditListBox",
"items" );
2567 kdeMap->insert(
"KFontCombo",
"family" );
2568 kdeMap->insert(
"KFontRequester",
"font" );
2569 kdeMap->insert(
"KFontChooser",
"font" );
2570 kdeMap->insert(
"KHistoryCombo",
"currentItem" );
2571 kdeMap->insert(
"KListBox",
"currentItem" );
2572 kdeMap->insert(
"KLineEdit",
"text" );
2573 kdeMap->insert(
"KRestrictedLine",
"text" );
2574 kdeMap->insert(
"KSqueezedTextLabel",
"text" );
2575 kdeMap->insert(
"KTextBrowser",
"source" );
2576 kdeMap->insert(
"KTextEdit",
"text" );
2577 kdeMap->insert(
"KURLRequester",
"url" );
2578 kdeMap->insert(
"KPasswordEdit",
"password" );
2579 kdeMap->insert(
"KIntNumInput",
"value" );
2580 kdeMap->insert(
"KIntSpinBox",
"value" );
2581 kdeMap->insert(
"KDoubleNumInput",
"value" );
2583 kdeMap->insert( TQGROUPBOX_OBJECT_NAME_STRING,
"checked" );
2584 kdeMap->insert( TQTABWIDGET_OBJECT_NAME_STRING,
"currentPage" );
2585 TQSqlPropertyMap::installDefaultMap( kdeMap );
2590 const TQString& _appname)
const 2599 const TQString& _appname,
2600 const TQCString& startup_id )
const 2604 if (_appname.isEmpty())
2609 if (!anchor.isEmpty())
2610 url = TQString(
"help:/%1?anchor=%2").arg(appname).arg(anchor);
2612 url = TQString(
"help:/%1/index.html").arg(appname);
2615 if ( !
dcopClient()->isApplicationRegistered(
"khelpcenter") )
2619 if (Tty != kapp->type())
2620 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Help Center"),
2621 i18n(
"Could not launch the KDE Help Center:\n\n%1").arg(error), i18n(
"&OK"));
2623 kdWarning() <<
"Could not launch help:\n" << error <<
endl;
2628 DCOPRef(
"khelpcenter",
"KHelpCenterIface" ).
send(
"openUrl", url, startup_id );
2634 kdWarning() <<
"invoking HTML help is deprecated! use docbook and invokeHelp!\n";
2638 if( _filename.isEmpty() )
2639 filename = TQString(name()) +
"/index.html";
2641 filename = _filename;
2644 if (!topic.isEmpty())
2645 url = TQString(
"help:/%1#%2").arg(filename).arg(topic);
2647 url = TQString(
"help:/%1").arg(filename);
2650 if ( !
dcopClient()->isApplicationRegistered(
"khelpcenter") )
2654 if (Tty != kapp->type())
2655 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Help Center"),
2656 i18n(
"Could not launch the KDE Help Center:\n\n%1").arg(error), i18n(
"&OK"));
2658 kdWarning() <<
"Could not launch help:\n" << error <<
endl;
2663 DCOPRef(
"khelpcenter",
"KHelpCenterIface" ).
send(
"openUrl", url );
2674 invokeMailer(address, TQString::null, TQString::null, subject, TQString::null, TQString::null,
2675 TQStringList(), startup_id );
2691 TQStringList queries = TQStringList::split(
'&', mailtoURL.
query().mid(1));
2692 TQStringList attachURLs;
2693 for (TQStringList::Iterator it = queries.begin(); it != queries.end(); ++it)
2695 TQString q = (*it).lower();
2696 if (q.startsWith(
"subject="))
2699 if (q.startsWith(
"cc="))
2702 if (q.startsWith(
"bcc="))
2705 if (q.startsWith(
"body="))
2708 if (allowAttachments && q.startsWith(
"attach="))
2711 if (allowAttachments && q.startsWith(
"attachment="))
2714 if (q.startsWith(
"to="))
2718 invokeMailer( address, cc, bcc, subject, body, TQString::null, attachURLs, startup_id );
2722 const TQString &subject,
const TQString &body,
2723 const TQString & messageFile,
const TQStringList &attachURLs)
2725 return invokeMailer(to,cc,bcc,subject,body,messageFile,attachURLs,
"");
2732 static TQStringList splitEmailAddressList(
const TQString & aStr )
2750 int commentlevel = 0;
2751 bool insidequote =
false;
2753 for (uint index=0; index<aStr.length(); index++) {
2756 switch (aStr[index].latin1()) {
2758 if (commentlevel == 0)
2759 insidequote = !insidequote;
2767 if (commentlevel > 0)
2780 if (!insidequote && (commentlevel == 0)) {
2781 addr = aStr.mid(addrstart, index-addrstart);
2782 if (!addr.isEmpty())
2783 list += addr.simplifyWhiteSpace();
2784 addrstart = index+1;
2790 if (!insidequote && (commentlevel == 0)) {
2791 addr = aStr.mid(addrstart, aStr.length()-addrstart);
2792 if (!addr.isEmpty())
2793 list += addr.simplifyWhiteSpace();
2804 const TQString &subject,
const TQString &body,
2805 const TQString & ,
const TQStringList &attachURLs,
2806 const TQCString& startup_id )
2811 TQString group = config.
readEntry(
"Profile",
"Default");
2813 config.
setGroup( TQString(
"PROFILE_%1").arg(group) );
2816 TQString to, cc, bcc;
2817 if (command.isEmpty() || command == TQString::fromLatin1(
"kmail")
2818 || command.endsWith(
"/kmail"))
2820 command = TQString::fromLatin1(
"kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t");
2821 if ( !_to.isEmpty() )
2825 to = TQString(
"=?utf8?b?%1?=" )
2828 if ( !_cc.isEmpty() )
2829 cc = TQString(
"=?utf8?b?%1?=" )
2831 if ( !_bcc.isEmpty() )
2832 bcc = TQString(
"=?utf8?b?%1?=" )
2838 if( !command.contains(
'%' ))
2845 TQString preferredTerminal = confGroup.
readPathEntry(
"TerminalApplication",
"konsole");
2846 command = preferredTerminal +
" -e " + command;
2850 TQString cmd = cmdTokens[0];
2851 cmdTokens.remove(cmdTokens.begin());
2857 TQStringList tos = splitEmailAddressList( to );
2859 tos.remove( tos.begin() );
2860 for (TQStringList::ConstIterator it = tos.begin(); it != tos.end(); ++it)
2863 const TQStringList ccs = splitEmailAddressList( cc );
2864 for (TQStringList::ConstIterator it = ccs.begin(); it != ccs.end(); ++it)
2866 const TQStringList bccs = splitEmailAddressList( bcc );
2867 for (TQStringList::ConstIterator it = bccs.begin(); it != bccs.end(); ++it)
2869 for (TQStringList::ConstIterator it = attachURLs.begin(); it != attachURLs.end(); ++it)
2871 if (!subject.isEmpty())
2873 if (!body.isEmpty())
2876 if ( ! (to.isEmpty() && qry.isEmpty()) )
2879 TQMap<TQChar, TQString> keyMap;
2880 keyMap.insert(
't', to);
2881 keyMap.insert(
's', subject);
2882 keyMap.insert(
'c', cc);
2883 keyMap.insert(
'b', bcc);
2884 keyMap.insert(
'B', body);
2885 keyMap.insert(
'u', url.
url());
2887 TQString attachlist = attachURLs.join(
",");
2888 attachlist.prepend(
'\'');
2889 attachlist.append(
'\'');
2890 keyMap.insert(
'A', attachlist);
2892 for (TQStringList::Iterator it = cmdTokens.begin(); it != cmdTokens.end(); )
2896 if (it == cmdTokens.begin())
2898 TQStringList::ConstIterator urlit = attachURLs.begin();
2899 TQStringList::ConstIterator urlend = attachURLs.end();
2900 if ( urlit != urlend )
2902 TQStringList::Iterator previt = it;
2906 while ( ++urlit != urlend )
2908 cmdTokens.insert( it, *previt );
2909 cmdTokens.insert( it, *urlit );
2913 it = cmdTokens.remove( cmdTokens.remove( it ) );
2924 if (
kdeinitExec(cmd, cmdTokens, &error, NULL, startup_id )) {
2925 if (Tty != kapp->type()) {
2926 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Mail Client"),
2927 i18n(
"Could not launch the mail client:\n\n%1").arg(error), i18n(
"&OK"));
2930 kdWarning() <<
"Could not launch mail client:\n" << error <<
endl;
2950 if (Tty != kapp->type())
2951 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Browser"),
2952 i18n(
"Could not launch the browser:\n\n%1").arg(error), i18n(
"&OK"));
2954 kdWarning() <<
"Could not launch browser:\n" << error <<
endl;
2987 emit coreFakeKeyPress(keyCode);
2997 startServiceInternal(
const TQCString &
function,
2998 const TQString& _name,
const TQStringList &URLs,
2999 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3001 struct serviceResult
3012 dcopClient = kapp->dcopClient();
3018 if (!dcopClient->
attach())
3021 *error = i18n(
"Could not register with DCOP.\n");
3029 TQDataStream stream(params, IO_WriteOnly);
3030 stream << _name << URLs;
3031 TQCString replyType;
3032 TQByteArray replyData;
3034 TQValueList<TQCString> envs;
3036 if (qt_xdisplay()) {
3037 TQCString dpystring(XDisplayString(qt_xdisplay()));
3038 envs.append( TQCString(
"DISPLAY=") + dpystring );
3039 }
else if( getenv(
"DISPLAY" )) {
3040 TQCString dpystring( getenv(
"DISPLAY" ));
3041 envs.append( TQCString(
"DISPLAY=") + dpystring );
3045 #if defined Q_WS_X11 3047 stream << ( startup_id.isEmpty() ? KStartupInfo::createNewStartupId() : startup_id );
3049 if(
function.left( 12 ) !=
"kdeinit_exec" )
3052 if (!dcopClient->
call(_launcher, _launcher,
3053 function, params, replyType, replyData))
3056 *error = i18n(
"KLauncher could not be reached via DCOP.\n");
3067 TQDataStream stream2(replyData, IO_ReadOnly);
3068 serviceResult result;
3069 stream2 >> result.result >> result.dcopName >> result.error >> result.pid;
3071 *dcopService = result.dcopName;
3073 *error = result.error;
3076 return result.result;
3081 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3086 return startServiceInternal(
3087 "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3088 _name, URLs, error, dcopService, pid, startup_id, noWait);
3093 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3095 return startServiceInternal(
3096 "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3097 _name, URLs, error, dcopService, pid, startup_id, noWait);
3102 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3107 return startServiceInternal(
3108 "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3109 _name, URLs, error, dcopService, pid, startup_id, noWait);
3114 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3116 return startServiceInternal(
3117 "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3118 _name, URLs, error, dcopService, pid, startup_id, noWait);
3123 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3128 return startServiceInternal(
3129 "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3130 _name, URLs, error, dcopService, pid, startup_id, noWait);
3135 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3137 return startServiceInternal(
3138 "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3139 _name, URLs, error, dcopService, pid, startup_id, noWait);
3144 TQString *error,
int *pid )
3151 TQString *error,
int *pid,
const TQCString& startup_id )
3153 return startServiceInternal(
"kdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)",
3154 name, args, error, 0, pid, startup_id,
false);
3159 TQString *error,
int *pid )
3166 TQString *error,
int *pid,
const TQCString& startup_id )
3168 return startServiceInternal(
"kdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>,TQCString)",
3169 name, args, error, 0, pid, startup_id,
false);
3176 if( TQDir::isRelativePath(pFilename) )
3178 kdWarning(101) <<
"Relative filename passed to KApplication::tempSaveName" <<
endl;
3179 aFilename = TQFileInfo( TQDir(
"." ), pFilename ).absFilePath();
3182 aFilename = pFilename;
3184 TQDir aAutosaveDir( TQDir::homeDirPath() +
"/autosave/" );
3185 if( !aAutosaveDir.exists() )
3187 if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
3190 aAutosaveDir.setPath(
KGlobal::dirs()->saveLocation(
"tmp") );
3194 aFilename.replace(
"/",
"\\!" ).prepend(
"#" ).append(
"#" ).prepend(
"/" ).prepend( aAutosaveDir.absPath() );
3201 bool& bRecover )
const 3205 if( TQDir::isRelativePath(pFilename) )
3207 kdWarning(101) <<
"Relative filename passed to KApplication::tempSaveName" <<
endl;
3208 aFilename = TQFileInfo( TQDir(
"." ), pFilename ).absFilePath();
3211 aFilename = pFilename;
3213 TQDir aAutosaveDir( TQDir::homeDirPath() +
"/autosave/" );
3214 if( !aAutosaveDir.exists() )
3216 if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
3219 aAutosaveDir.setPath(
KGlobal::dirs()->saveLocation(
"tmp") );
3223 aFilename.replace(
"/",
"\\!" ).prepend(
"#" ).append(
"#" ).prepend(
"/" ).prepend( aAutosaveDir.absPath() );
3225 if( TQFile( aFilename ).exists() )
3238 bool checkAccess(
const TQString& pathname,
int mode)
3240 int accessOK = access( TQFile::encodeName(pathname), mode );
3241 if ( accessOK == 0 )
3247 if ( (mode & W_OK) == 0 )
3251 if (!access( TQFile::encodeName(pathname), F_OK))
3255 TQString dirName(pathname);
3256 int pos = dirName.findRev(
'/');
3259 else if ( pos == 0 )
3262 dirName.truncate(pos);
3264 accessOK = access( TQFile::encodeName(dirName), W_OK );
3266 if ( accessOK == 0 )
3278 if ( !topWidget->inherits(
"KMainWindow") ) {
3279 topWidget->setCaption(
caption() );
3283 topWidget->setIcon(
icon() );
3284 #if defined Q_WS_X11 3289 KStartupInfo::setWindowStartupId( topWidget->winId(),
startupId());
3295 return d->startup_id;
3298 void KApplication::setStartupId(
const TQCString& startup_id )
3300 if( startup_id == d->startup_id )
3302 #if defined Q_WS_X11 3303 KStartupInfo::handleAutoAppStartedSending();
3305 if( startup_id.isEmpty())
3306 d->startup_id =
"0";
3309 d->startup_id = startup_id;
3310 #
if defined Q_WS_X11
3312 id.initId( startup_id );
3313 long timestamp =
id.timestamp();
3314 if( timestamp != 0 )
3322 void KApplication::read_app_startup_id()
3324 #if defined Q_WS_X11 3325 KStartupInfoId
id = KStartupInfo::currentStartupIdEnv();
3326 KStartupInfo::resetStartupEnv();
3327 d->startup_id =
id.id();
3333 static bool init =
false;
3338 int fd = open(
"/dev/urandom", O_RDONLY);
3339 if (fd < 0 || ::read(fd, &seed,
sizeof(seed)) !=
sizeof(seed))
3343 seed = rand()+time(0);
3345 if (fd >= 0) close(fd);
3353 if (length <=0 )
return TQString::null;
3355 TQString str; str.setLength( length );
3371 if (!d->actionRestrictions)
3381 if (!d->actionRestrictions || !action)
3386 return authorize(action_prefix + action);
3391 if (menuId.isEmpty() || kde_kiosk_exception)
3402 TQStringList result;
3403 for(TQStringList::ConstIterator it = menuIds.begin();
3404 it != menuIds.end(); ++it)
3412 void KApplication::initUrlActionRestrictions()
3414 d->urlActionRestrictions.setAutoDelete(
true);
3415 d->urlActionRestrictions.clear();
3416 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3417 (
"open", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null,
true));
3418 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3419 (
"list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null,
true));
3425 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3426 (
"link", TQString::null, TQString::null, TQString::null,
":internet", TQString::null, TQString::null,
true));
3427 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3428 (
"redirect", TQString::null, TQString::null, TQString::null,
":internet", TQString::null, TQString::null,
true));
3432 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3433 (
"redirect", TQString::null, TQString::null, TQString::null,
"file", TQString::null, TQString::null,
true));
3434 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3435 (
"redirect",
":internet", TQString::null, TQString::null,
"file", TQString::null, TQString::null,
false));
3438 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3439 (
"redirect",
":local", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null,
true));
3442 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3443 (
"redirect", TQString::null, TQString::null, TQString::null,
"about", TQString::null, TQString::null,
true));
3446 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3447 (
"redirect", TQString::null, TQString::null, TQString::null,
"=", TQString::null, TQString::null,
true));
3452 TQString keyFormat = TQString(
"rule_%1");
3453 for(
int i = 1; i <= count; i++)
3455 TQString key = keyFormat.arg(i);
3457 if (rule.count() != 8)
3459 TQString action = rule[0];
3460 TQString refProt = rule[1];
3461 TQString refHost = rule[2];
3462 TQString refPath = rule[3];
3463 TQString urlProt = rule[4];
3464 TQString urlHost = rule[5];
3465 TQString urlPath = rule[6];
3466 TQString strEnabled = rule[7].lower();
3468 bool bEnabled = (strEnabled ==
"true");
3470 if (refPath.startsWith(
"$HOME"))
3471 refPath.replace(0, 5, TQDir::homeDirPath());
3472 else if (refPath.startsWith(
"~"))
3473 refPath.replace(0, 1, TQDir::homeDirPath());
3474 if (urlPath.startsWith(
"$HOME"))
3475 urlPath.replace(0, 5, TQDir::homeDirPath());
3476 else if (urlPath.startsWith(
"~"))
3477 urlPath.replace(0, 1, TQDir::homeDirPath());
3479 if (refPath.startsWith(
"$TMP"))
3481 if (urlPath.startsWith(
"$TMP"))
3484 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3485 ( action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled));
3494 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3504 bool result =
false;
3505 if (d->urlActionRestrictions.isEmpty())
3506 initUrlActionRestrictions();
3508 KURL baseURL(_baseURL);
3509 baseURL.
setPath(TQDir::cleanDirPath(baseURL.
path()));
3510 TQString baseClass = KProtocolInfo::protocolClass(baseURL.
protocol());
3511 KURL destURL(_destURL);
3512 destURL.setPath(TQDir::cleanDirPath(destURL.path()));
3513 TQString destClass = KProtocolInfo::protocolClass(destURL.protocol());
3515 for(KApplicationPrivate::URLActionRule *rule = d->urlActionRestrictions.first();
3516 rule; rule = d->urlActionRestrictions.next())
3518 if ((result != rule->permission) &&
3519 (action == rule->action) &&
3520 rule->baseMatch(baseURL, baseClass) &&
3521 rule->destMatch(destURL, destClass, baseURL, baseClass))
3523 result = rule->permission;
3535 int root_x, root_y, win_x, win_y;
3537 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
3538 &root_x, &root_y, &win_x, &win_y, &keybstate );
3539 return keybstate & 0x00ff;
3540 #elif defined W_WS_MACX 3541 return GetCurrentEventKeyModifiers() & 0x00ff;
3554 int root_x, root_y, win_x, win_y;
3555 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
3556 &root_x, &root_y, &win_x, &win_y, &mousestate );
3557 #elif defined(Q_WS_WIN) 3558 const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON);
3559 if (GetAsyncKeyState(VK_LBUTTON))
3560 mousestate |= (mousebtn_swapped ? Button3Mask : Button1Mask);
3561 if (GetAsyncKeyState(VK_MBUTTON))
3562 mousestate |= Button2Mask;
3563 if (GetAsyncKeyState(VK_RBUTTON))
3564 mousestate |= (mousebtn_swapped ? Button1Mask : Button3Mask);
3565 #elif defined(Q_WS_MACX) 3566 mousestate = GetCurrentEventButtonState();
3570 return mousestate & 0xff00;
3579 int root_x, root_y, win_x, win_y;
3581 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
3582 &root_x, &root_y, &win_x, &win_y, &state );
3584 if( state & Button1Mask )
3585 ret |= TQ_LeftButton;
3586 if( state & Button2Mask )
3587 ret |= TQ_MidButton;
3588 if( state & Button3Mask )
3589 ret |= TQ_RightButton;
3590 if( state & ShiftMask )
3591 ret |= TQ_ShiftButton;
3592 if( state & ControlMask )
3593 ret |= TQ_ControlButton;
3594 if( state & KKeyNative::modX( KKey::ALT ))
3595 ret |= TQ_AltButton;
3596 if( state & KKeyNative::modX( KKey::WIN ))
3597 ret |= TQ_MetaButton;
3598 #elif defined(Q_WS_WIN) 3599 const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON);
3600 if (GetAsyncKeyState(VK_LBUTTON))
3601 ret |= (mousebtn_swapped ? RightButton : LeftButton);
3602 if (GetAsyncKeyState(VK_MBUTTON))
3603 ret |= TQ_MidButton;
3604 if (GetAsyncKeyState(VK_RBUTTON))
3605 ret |= (mousebtn_swapped ? TQ_LeftButton : TQ_RightButton);
3606 if (GetAsyncKeyState(VK_SHIFT))
3607 ret |= TQ_ShiftButton;
3608 if (GetAsyncKeyState(VK_CONTROL))
3609 ret |= TQ_ControlButton;
3610 if (GetAsyncKeyState(VK_MENU))
3611 ret |= TQ_AltButton;
3612 if (GetAsyncKeyState(VK_LWIN) || GetAsyncKeyState(VK_RWIN))
3613 ret |= TQ_MetaButton;
3617 return static_cast< ButtonState
>( ret );
3623 struct sigaction act;
3624 act.sa_handler = SIG_IGN;
3625 sigemptyset( &act.sa_mask );
3627 sigaction( SIGPIPE, &act, 0 );
3631 void KApplication::sigpipeHandler(
int)
3633 int saved_errno = errno;
3637 sprintf(msg,
"*** SIGPIPE *** (ignored, pid = %ld)\n", (
long) getpid());
3638 if (write(2, msg, strlen(msg)) < 0) {
3644 errno = saved_errno;
3647 bool KApplication::guiEnabled()
3649 return kapp && kapp->d->guiEnabled;
3652 void KApplication::virtual_hook(
int id,
void* data )
3653 { KInstance::virtual_hook(
id, data ); }
3655 void KSessionManaged::virtual_hook(
int,
void* )
3658 #include "kapplication.moc" void setQuery(const TQString &_txt, int encoding_hint=0)
Sets the encoded query of the URL.
void allowURLAction(const TQString &action, const KURL &_baseURL, const KURL &_destURL)
Allow a certain URL action.
static void setServerAddress(const TQCString &addr)
Represents and parses a URL.
Qt::HANDLE getX11RGBAColormap(Display *dpy)
Returns the X11 display colormap.
Controls and provides information to all KDE applications.
static void addCmdLineOptions()
Add Qt and KDE command line options to KCmdLineArgs.
void removeX11EventFilter(const TQWidget *filter)
Removes global X11 event filter previously installed by installX11EventFilter().
ShutdownConfirm
The possible values for the confirm parameter of requestShutDown().
ShutdownType
The possible values for the sdtype parameter of requestShutDown().
virtual bool commitData(TQSessionManager &sm)
See TQApplication::commitData() for documentation.
bool checkConfigFilesWritable(bool warnUser)
Check whether the config files are writable.
static KLocale * locale()
Returns the global locale object.
Always confirm, ask even if the user turned it off.
void newIconLoader() const
Re-allocate the global iconloader.
TQString tempSaveName(const TQString &pFilename) const
Get a file name in order to make a temporary copy of your document.
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.
SettingsCategory
Valid values for the settingsChanged signal.
TQString geometryArgument() const
Returns the argument to –geometry if any, so the geometry can be set wherever necessary.
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.
TQString checkRecoverFile(const TQString &pFilename, bool &bRecover) const
Check whether an auto-save file exists for the document you want to open.
void disableStyles()
Disables style plugins.
static void disableAutoDcopRegistration()
Disable automatic dcop registration Must be called before creating a KApplication instance to have an...
TQCString startupId() const
Returns the app startup notification identifier for this running application.
TQString expandMacros(const TQString &ostr, const TQMap< TQChar, TQString > &map, TQChar c)
Perform safe macro expansion (substitution) on a string.
static void setCrashHandler(HandlerType handler=defaultCrashHandler)
Install a function to be called in case a SIGSEGV is caught.
TQString miniIconName() const
Returns the name of the mini-icon for the application.
TQString query() const
Returns the encoded query of the URL.
static KIconLoader * iconLoader()
Returns an iconloader object.
static const TQString & staticQString(const char *str)
Creates a static TQString.
A class for command-line argument handling.
void appearanceChanged()
Emitted when KApplication has changed either its GUI style, its font or its palette in response to a ...
TQPixmap icon() const
Returns a TQPixmap with the application icon.
bool send(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data)
TQString protocol() const
Returns the protocol for the URL.
KConfig * config() const
Returns the general config object ("appnamerc").
static TQString findExe(const TQString &appname, const TQString &pathstr=TQString::null, bool ignoreExecBit=false)
Finds the executable in the system path.
void cut()
If the widget with focus provides a cut() slot, call that slot.
void saveState(TQSessionManager &sm)
Reimplemented for internal purposes, mainly the highlevel handling of session management with KSessio...
void ref()
Tells KApplication about one more operation that should be finished before the application exits...
static KCmdLineArgs * parsedArgs(const char *id=0)
Access parsed arguments.
void installX11EventFilter(TQWidget *filter)
Installs widget filter as global X11 event filter.
void toolbarAppearanceChanged(int)
Emitted when the settings for toolbars have been changed.
const KAboutData * aboutData() const
Returns the about data of this instance Warning, can be 0L.
void invokeHTMLHelp(const TQString &aFilename, const TQString &aTopic=TQString::null) const KDE_DEPRECATED
void backgroundChanged(int desk)
Emitted when the desktop background has been changed by kcmdisplay.
void disableSessionManagement()
Disables session management for this application.
static TQPalette createApplicationPalette()
Used to obtain the TQPalette that will be used to set the application palette.
virtual void sync()
Flushes all changes that currently reside only in memory back to disk / permanent storage...
TQColor readColorEntry(const TQString &pKey, const TQColor *pDefault=0L) const
Reads a TQColor entry.
KInstance(const TQCString &instanceName)
Constructor.
void kdisplayFontChanged()
Emitted when KApplication has changed its font in response to a KControl request. ...
void enableSessionManagement()
Enables again session management for this application, formerly disabled by calling disableSessionMan...
void setGroup(const TQString &group)
Specifies the group in which keys will be read and written.
void invokeBrowser(const TQString &url, const TQCString &startup_id)
Invokes the standard browser.
bool isEmpty() const
Tests if the KURL is empty.
Select previous mode or the default if it's the first time.
static KApplication * KApp
Current application object.
static void ref()
Create an instance if none exists yet.
TQString readPathEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads a path.
TQString readEntry(const TQString &pKey, const TQString &aDefault=TQString::null) const
Reads the value of an entry specified by pKey in the current group.
TQCString instanceName() const
Returns the name of the instance.
TQString iconName() const
Returns the name of the application icon.
TQString caption() const
Returns a text for the window caption.
The KShortcut class is used to represent a keyboard shortcut to an action.
bool send(const TQCString &fun)
static TQCString launcher()
Returns the DCOP name of the service launcher.
The KLockFile class provides NFS safe lockfiles.
static uint mouseState() KDE_DEPRECATED
bool call(const TQCString &remApp, const TQCString &remObj, const TQCString &remFun, const TQByteArray &data, TQCString &replyType, TQByteArray &replyData, bool useEventLoop, int timeout)
bool authorizeKAction(const char *action)
Returns whether a certain KAction is authorized.
TQString host() const
Returns the decoded hostname included in the URL.
Structure that holds command line options.
void paste()
If the widget with focus provides a paste() slot, call that slot.
TQPixmap miniIcon() const
Returns the mini-icon for the application as a TQPixmap.
static int contrast()
Returns the contrast for borders.
virtual bool saveState(TQSessionManager &sm)
See TQApplication::saveState() for documentation.
bool readBoolEntry(const TQString &pKey, bool bDefault=false) const
Reads a boolean entry.
static TQFont generalFont()
Returns the default general font.
static void setApplicationName(TQString name)
Sets the application name name which should be passed to Dr.
static KStandardDirs * dirs()
Returns the application standard dirs object.
bool isX11CompositionAvailable()
Returns whether or not X11 composition is available.
bool authorizeURLAction(const TQString &action, const KURL &baseURL, const KURL &destURL)
Returns whether a certain URL related action is authorized.
static TQFont menuFont()
Returns the default menu font.
void kipcMessage(int id, int data)
Emitted when a KIPC user message has been received.
KApplication(bool allowStyles=true, bool GUIenabled=true, bool SMenabled=true)
This constructor takes aboutData and command line arguments from KCmdLineArgs.
LockResult lock(int options=0)
Attempt to acquire the lock.
Return immediately, do not wait for the lock to become available.
Select previous action or the default if it's the first time.
void saveYourself()
Session management asks you to save the state of your application.
static const char * appName()
Get the appname according to argv[0].
bool isSet(const char *option) const
Read out a boolean option or check for the presence of string option.
TQStringList authorizeControlModules(const TQStringList &menuIds)
Returns whether access to a certain control modules is authorized.
void setPath(const TQString &path)
Sets the decoded path of the URL.
void copy()
If the widget with focus provides a copy() slot, call that slot.
TQCString registerAs(const TQCString &appId, bool addPID=true)
bool requestShutDown(ShutdownConfirm confirm=ShutdownConfirmDefault, ShutdownType sdtype=ShutdownTypeDefault, ShutdownMode sdmode=ShutdownModeDefault)
Asks the session manager to shut the session down.
Access to KDE global objects for use in shared libraries.
static void setMainClient(DCOPClient *mainClient)
static TQString randomString(int length)
Generates a random string.
static void setEmergencySaveFunction(HandlerType saveFunction=(HandlerType) 0)
Installs a function which should try to save the applications data.
void setConfigName(const TQString &name)
Set name of default config file.
DCOPReply call(const TQCString &fun)
void iconChanged(int group)
Emitted when the global icon settings have been changed.
void clear()
If the widget with focus provides a clear() slot, call that slot.
void removeKipcEventMask(int id)
Removes a message type from the KIPC event mask.
static TQFont fixedFont()
Returns the default fixed font.
void commitData(TQSessionManager &sm)
Reimplemented for internal purposes, mainly the highlevel handling of session management with KSessio...
Helper class to facilitate working with KConfig / KSimpleConfig groups.
static bool isCompositionManagerAvailable()
Gets the availability of a composition manager such as kompmgr Note that at least one application mus...
void installKDEPropertyMap()
Install a Qt SQL property map with entries for all KDE widgets Call this in any application using KDE...
KDE Configuration Management abstract base class.
static KInstance * instance()
Returns the global instance.
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...
static int kdeinitExecWait(const TQString &name, const TQStringList &args, TQString *error, int *pid, const TQCString &startup_id)
Starts a program via kdeinit and wait for it to finish.
Qt::HANDLE getX11RGBAVisual(Display *dpy)
Returns the X11 display visual.
void settingsChanged(int category)
Emitted when the global settings have been changed - see KGlobalSettings KApplication takes care of c...
large sized icons for the panel
const KShortcut & selectAll()
Reload.
void shutDown()
Your application is killed.
static void installSigpipeHandler()
Installs a handler for the SIGPIPE signal.
void selectAll()
If the widget with focus provides a selectAll() slot, call that slot.
TQSize readSizeEntry(const TQString &pKey, const TQSize *pDefault=0L) const
Reads a TQSize entry.
TQPixmap loadIcon(const TQString &name, KIcon::Group group, int size=0, int state=KIcon::DefaultState, TQString *path_store=0L, bool canReturnNull=false) const
Loads an icon.
Lock was acquired successfully.
static TQString encode_string(const TQString &str, int encoding_hint=0)
Encodes a string for use in URLs.
TQString programName() const
Returns the translated program name.
A KConfigBase derived class for one specific group in a KConfig object.
bool sessionSaving() const
Returns true if the application is currently saving its session data (most probably before KDE logout...
void propagateSessionManager()
Propagates the network address of the session manager in the SESSION_MANAGER environment variable so ...
void addKipcEventMask(int id)
Adds a message type to the KIPC event mask.
Access KDE Configuration entries.
static int random()
Generates a uniform random number.
KAction * action(StdAction act_enum, const TQObject *recvr, const char *slot, KActionCollection *parent, const char *name=0L)
void enableStyles()
Enables style plugins.
A KKey object represents a single key with possible modifiers (Shift, Ctrl, Alt, Win).
static TQCString base64Encode(const TQByteArray &in, bool insertLFs=false)
Encodes the given data using the base64 algorithm.
static TQString decode_string(const TQString &str, int encoding_hint=0)
Decodes a string as used in URLs.
int readNumEntry(const TQString &pKey, int nDefault=0) const
Reads a numerical value.
static void addCmdLineOptions(const KCmdLineOptions *options, const char *name=0, const char *id=0, const char *afterId=0)
Add options to your application.
void invokeEditSlot(const char *slot)
This method is used internally to determine which edit slots are implemented by the widget that has t...
static void deleteStaticDeleters()
Calls KStaticDeleterBase::destructObject() on all registered static deleters and unregisters them all...
virtual void reparseConfiguration()
Clears all internal data structures and then reread configuration information from disk...
bool addResourceType(const char *type, const TQString &relativename)
Adds suffixes for types.
void deref()
Tells KApplication that one operation such as those described in ref() just finished.
static DCOPClient * dcopClient()
Returns a pointer to a DCOPClient for the application.
static void deref()
Destroy the instance if one exists and it is not referenced any more.
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...
void setTopWidget(TQWidget *topWidget)
Sets the top widget of the application.
static KClipboardSynchronizer * self()
Returns the KClipboardSynchronizer singleton object.
bool contains(const KKey &key) const
Checks whether this shortcut contains a sequence that starts with the given key.
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...
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.
void invokeMailer(const TQString &address, const TQString &subject, const TQCString &startup_id)
Convenience method; invokes the standard email application.
static int timestampCompare(unsigned long time1, unsigned long time2)
Compares two X timestamps, taking into account wrapping and 64bit architectures.
KConfig * sessionConfig()
Returns the application session config object.
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.
TQString path() const
Returns the current decoded path.
void kdisplayStyleChanged()
Emitted when KApplication has changed its GUI style in response to a KControl request.
void broadcastKeyCode(unsigned int keyCode)
Broadcast a received keycode to all listening KDE applications The primary use for this feature is to...
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.
unsigned long userTimestamp() const
Returns the last user action timestamp or 0 if no user activity has taken place yet.
bool authorize(const TQString &genericAction)
Returns whether a certain action is authorized.
kndbgstream & endl(kndbgstream &s)
Does nothing.
void kdisplayPaletteChanged()
Emitted when KApplication has changed its palette due to a KControl request.
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 ...
This is the main interface to the KApplication.
static TQString kde_default(const char *type)
This returns a default relative path for the standard KDE resource types.
static int kdeinitExec(const TQString &name, const TQStringList &args, TQString *error, int *pid, const TQCString &startup_id)
Starts a program via kdeinit.
TQStringList splitArgs(const TQString &cmd, int flags=0, int *err=0)
Splits cmd according to POSIX shell word splitting and quoting rules.
bool hasGroup(const TQString &group) const
Returns true if the specified group is known about.
TQStringList resourceDirs(const char *type) const
This function is used internally by almost all other function as it serves and fills the directories ...
static void setIcons(WId win, const TQPixmap &icon, const TQPixmap &miniIcon)
Sets an icon and a miniIcon on window win.
static KConfig * config()
Returns the general config object.
Provides highlevel access to session management on a per-object base.
static void defaultCrashHandler(int signal)
The default crash handler.
bool authorizeControlModule(const TQString &menuId)
Returns whether access to a certain control module is authorized.
TQCString getOption(const char *option) const
Read out a string option.
void invokeHelp(const TQString &anchor, const TQString &appname, const TQCString &startup_id) const
Invokes the KHelpCenter HTML help viewer from docbook sources.
static uint keyboardModifiers() KDE_DEPRECATED
Don't confirm, shutdown without asking.
int readListEntry(const TQString &pKey, TQStrList &list, char sep= ',') const
Reads a list of strings.
ShutdownMode
The possible values for the sdmode parameter of requestShutDown().
KMimeSourceFactory * mimeSourceFactory() const
Returns the KMimeSourceFactory of the instance.
void setProtocol(const TQString &_txt)
Sets the protocol for the URL.
static ButtonState keyboardMouseState()
Returns the state of the currently pressed keyboard modifiers (e.g.