23 #ifdef HAVE_XCOMPOSITE
35 #undef QT_NO_TRANSLATION
36 #undef TQT_NO_TRANSLATION
37 #include <tqtranslator.h>
38 #include "kapplication.h"
39 #define QT_NO_TRANSLATION
40 #define TQT_NO_TRANSLATION
42 #include <tqptrcollection.h>
43 #include <tqwidgetlist.h>
44 #include <tqstrlist.h>
46 #include <tqmessagebox.h>
47 #include <tqtextstream.h>
49 #include <tqlineedit.h>
50 #include <tqtextedit.h>
51 #include <tqsessionmanager.h>
52 #include <tqptrlist.h>
54 #include <tqstylesheet.h>
55 #include <tqpixmapcache.h>
56 #include <tqtooltip.h>
57 #include <tqstylefactory.h>
58 #include <tqmetaobject.h>
61 #include <tqsqlpropertymap.h>
65 #include <kstandarddirs.h>
69 #include <kiconloader.h>
70 #include <kclipboard.h>
72 #include <ksimpleconfig.h>
73 #include <kcmdlineargs.h>
74 #include <kaboutdata.h>
75 #include <kglobalsettings.h>
77 #include <kdatastream.h>
78 #include <klibloader.h>
79 #include <kmimesourcefactory.h>
80 #include <kstdaccel.h>
82 #include "kcheckaccelerators.h"
83 #include <tqptrdict.h>
84 #include <kmacroexpander.h>
86 #include <kprotocolinfo.h>
87 #include <kkeynative.h>
89 #include <kglobalaccel.h>
92 #include <kstartupinfo.h>
95 #include <dcopclient.h>
98 #include <sys/types.h>
99 #ifdef HAVE_SYS_STAT_H
100 #include <sys/stat.h>
102 #include <sys/wait.h>
104 #include <sys/types.h>
115 #include <sys/time.h>
124 #include "kprocctrl.h"
131 #include <X11/Xlib.h>
133 #include <X11/extensions/Xrender.h>
134 #include <X11/extensions/Xcomposite.h>
137 #include <X11/Xutil.h>
138 #include <X11/Xatom.h>
139 #include <X11/SM/SMlib.h>
146 #include <KDE-ICE/ICElib.h>
148 typedef void* IceIOErrorHandler;
151 #define Button1Mask (1<<8)
152 #define Button2Mask (1<<9)
153 #define Button3Mask (1<<10)
157 #define DISPLAY "DISPLAY"
158 #elif defined(Q_WS_QWS)
159 #define DISPLAY "QWS_DISPLAY"
167 #include <Carbon/Carbon.h>
171 #include "kappdcopiface.h"
174 KDE_EXPORT
bool kde_have_kipc =
true;
175 bool kde_kiosk_exception =
false;
176 bool kde_kiosk_admin =
false;
179 bool KApplication::loadedByKdeinit =
false;
181 bool KApplication::s_dcopClientNeedsPostInit =
false;
184 static Atom atom_DesktopWindow;
185 static Atom atom_NetSupported;
186 static Atom kde_xdnd_drop;
190 static int composite_event, composite_error, composite_opcode;
191 static bool x11_composite_error_generated;
192 static int x11_error(Display *dpy, XErrorEvent *ev) {
193 if (ev->request_code == composite_opcode && ev->minor_code == X_CompositeRedirectSubwindows)
195 x11_composite_error_generated =
true;
203 KDECORE_EXPORT
bool qt_qclipboard_bailout_hack =
false;
205 template class TQPtrList<KSessionManaged>;
209 static int kde_xio_errhandler( Display * dpy )
211 return kapp->xioErrhandler( dpy );
214 static int kde_x_errhandler( Display *dpy, XErrorEvent *err )
216 return kapp->xErrhandler( dpy, err );
222 static void kde_ice_ioerrorhandler( IceConn conn )
225 kapp->iceIOErrorHandler( conn );
232 void KApplication_init_windows(
bool GUIenabled);
234 class QAssistantClient;
240 class KApplicationPrivate
243 KApplicationPrivate()
244 : actionRestrictions( false ),
246 oldIceIOErrorHandler( 0 ),
247 checkAccelerators( 0 ),
248 overrideStyle( TQString::null ),
250 app_started_timer( NULL ),
251 m_KAppDCOPInterface( 0L ),
252 session_save( false )
254 ,oldXErrorHandler( NULL )
255 ,oldXIOErrorHandler( NULL )
256 #elif defined Q_WS_WIN
257 ,qassistantclient( 0 )
262 ~KApplicationPrivate()
265 delete qassistantclient;
270 bool actionRestrictions : 1;
279 IceIOErrorHandler oldIceIOErrorHandler;
280 KCheckAccelerators* checkAccelerators;
281 TQString overrideStyle;
282 TQString geometry_arg;
283 TQCString startup_id;
284 TQTimer* app_started_timer;
288 int (*oldXErrorHandler)(Display*,XErrorEvent*);
289 int (*oldXIOErrorHandler)(Display*);
290 #elif defined Q_WS_WIN
291 QAssistantClient* qassistantclient;
297 #define checkExactMatch(s, b) \
298 if (s.isEmpty()) b = true; \
299 else if (s[s.length()-1] == '!') \
300 { b = false; s.truncate(s.length()-1); } \
302 #define checkStartWildCard(s, b) \
303 if (s.isEmpty()) b = true; \
304 else if (s[0] == '*') \
305 { b = true; s = s.mid(1); } \
307 #define checkEqual(s, b) \
310 URLActionRule(
const TQString &act,
311 const TQString &bProt,
const TQString &bHost,
const TQString &bPath,
312 const TQString &dProt,
const TQString &dHost,
const TQString &dPath,
315 baseProt(bProt), baseHost(bHost), basePath(bPath),
316 destProt(dProt), destHost(dHost), destPath(dPath),
319 checkExactMatch(baseProt, baseProtWildCard);
320 checkStartWildCard(baseHost, baseHostWildCard);
321 checkExactMatch(basePath, basePathWildCard);
322 checkExactMatch(destProt, destProtWildCard);
323 checkStartWildCard(destHost, destHostWildCard);
324 checkExactMatch(destPath, destPathWildCard);
325 checkEqual(destProt, destProtEqual);
326 checkEqual(destHost, destHostEqual);
329 bool baseMatch(
const KURL &url,
const TQString &protClass)
331 if (baseProtWildCard)
333 if ( !baseProt.isEmpty() && !url.
protocol().startsWith(baseProt) &&
334 (protClass.isEmpty() || (protClass != baseProt)) )
339 if ( (url.
protocol() != baseProt) &&
340 (protClass.isEmpty() || (protClass != baseProt)) )
343 if (baseHostWildCard)
345 if (!baseHost.isEmpty() && !url.
host().endsWith(baseHost))
350 if (url.
host() != baseHost)
353 if (basePathWildCard)
355 if (!basePath.isEmpty() && !url.
path().startsWith(basePath))
360 if (url.
path() != basePath)
366 bool destMatch(
const KURL &url,
const TQString &protClass,
const KURL &base,
const TQString &baseClass)
371 (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass) )
374 else if (destProtWildCard)
376 if ( !destProt.isEmpty() && !url.
protocol().startsWith(destProt) &&
377 (protClass.isEmpty() || (protClass != destProt)) )
382 if ( (url.
protocol() != destProt) &&
383 (protClass.isEmpty() || (protClass != destProt)) )
386 if (destHostWildCard)
388 if (!destHost.isEmpty() && !url.
host().endsWith(destHost))
391 else if (destHostEqual)
398 if (url.
host() != destHost)
401 if (destPathWildCard)
403 if (!destPath.isEmpty() && !url.
path().startsWith(destPath))
408 if (url.
path() != destPath)
421 bool baseProtWildCard : 1;
422 bool baseHostWildCard : 1;
423 bool basePathWildCard : 1;
424 bool destProtWildCard : 1;
425 bool destHostWildCard : 1;
426 bool destPathWildCard : 1;
427 bool destProtEqual : 1;
428 bool destHostEqual : 1;
431 TQPtrList<URLActionRule> urlActionRestrictions;
434 TQString pSessionConfigFile;
438 static TQPtrList<TQWidget>*x11Filter = 0;
439 static bool autoDcopRegistration =
true;
446 x11Filter =
new TQPtrList<TQWidget>;
447 connect ( filter, TQT_SIGNAL( destroyed() ),
this, TQT_SLOT( x11FilterDestroyed() ) );
448 x11Filter->append( filter );
451 void KApplication::x11FilterDestroyed()
458 if ( !x11Filter || !filter )
460 x11Filter->removeRef( filter );
461 if ( x11Filter->isEmpty() ) {
471 extern bool kde_g_bKillAccelOverride;
473 bool KApplication::notify(TQObject *receiver, TQEvent *event)
475 TQEvent::Type t = event->type();
476 if (kde_g_bKillAccelOverride)
478 kde_g_bKillAccelOverride =
false;
480 if (t == TQEvent::AccelOverride)
482 TQT_TQKEYEVENT(event)->accept();
486 kdWarning(125) <<
"kde_g_bKillAccelOverride set, but received an event other than AccelOverride." <<
endl;
489 if ((t == TQEvent::AccelOverride) || (t == TQEvent::KeyPress))
492 TQLineEdit *edit = ::tqqt_cast<TQLineEdit *>(receiver);
496 TQKeyEvent *kevent = TQT_TQKEYEVENT(event);
500 if (t == TQEvent::KeyPress)
511 if (key ==
KKey(Qt::CTRL + Qt::Key_U))
513 if (t == TQEvent::KeyPress)
515 if (!edit->isReadOnly())
517 TQString t(edit->text());
518 t = t.mid(edit->cursorPosition());
519 edit->validateAndSet(t, 0, 0, 0);
530 TQTextEdit *medit = ::tqqt_cast<TQTextEdit *>(receiver);
534 TQKeyEvent *kevent = TQT_TQKEYEVENT(event);
537 if (t == TQEvent::KeyPress)
549 if( t == TQEvent::Show && receiver->isWidgetType())
551 TQWidget* w = TQT_TQWIDGET( receiver );
553 if( w->isTopLevel() && !
startupId().isEmpty() && !TQT_TQSHOWEVENT(event)->spontaneous())
554 KStartupInfo::setWindowStartupId( w->winId(),
startupId());
556 if( w->isTopLevel() && !w->testWFlags( WX11BypassWM ) && !w->isPopup() && !event->spontaneous())
558 if( d->app_started_timer == NULL )
560 d->app_started_timer =
new TQTimer(
this,
"app_started_timer" );
561 connect( d->app_started_timer, TQT_SIGNAL( timeout()), TQT_SLOT( checkAppStartedSlot()));
563 if( !d->app_started_timer->isActive())
564 d->app_started_timer->start( 0,
true );
566 if( w->isTopLevel() && ( w->icon() == NULL || w->icon()->isNull()))
569 static TQPixmap* ic = NULL;
582 return TQApplication::notify(receiver, event);
585 void KApplication::checkAppStartedSlot()
588 KStartupInfo::handleAutoAppStartedSending();
593 static TQPtrList<KSessionManaged>* sessionClients()
595 static TQPtrList<KSessionManaged>* session_clients = 0L;
596 if ( !session_clients )
597 session_clients =
new TQPtrList<KSessionManaged>;
598 return session_clients;
606 TQString KApplication::sessionConfigName()
const
608 TQString sessKey = sessionKey();
609 if ( sessKey.isEmpty() && !d->sessionKey.isEmpty() )
610 sessKey = d->sessionKey;
611 return TQString(
"session/%1_%2_%3").arg(
name()).arg(sessionId()).arg(sessKey);
615 static SmcConn mySmcConnection = 0;
616 static SmcConn tmpSmcConnection = 0;
621 static TQTime* smModificationTime = 0;
624 bool allowStyles,
bool GUIenabled ) :
625 TQApplication( argc, argv, GUIenabled ),
KInstance(rAppName),
630 d (new KApplicationPrivate())
632 aIconPixmap.pm.icon = 0L;
633 aIconPixmap.pm.miniIcon = 0L;
634 read_app_startup_id();
637 useStyles = allowStyles;
638 Q_ASSERT (!rAppName.isEmpty());
642 KCmdLineArgs::initIgnore(argc, argv, rAppName.data());
655 d (new KApplicationPrivate)
657 aIconPixmap.pm.icon = 0L;
658 aIconPixmap.pm.miniIcon = 0L;
659 read_app_startup_id();
662 useStyles = allowStyles;
674 getX11RGBAVisual(dpy), getX11RGBAColormap(dpy) ),
677 aIconPixmap.pm.icon = 0L;
678 aIconPixmap.pm.miniIcon = 0L;
679 read_app_startup_id();
680 useStyles = allowStyles;
690 disable_argb?visual:getX11RGBAVisual(dpy), disable_argb?colormap:getX11RGBAColormap(dpy) ),
693 aIconPixmap.pm.icon = 0L;
694 aIconPixmap.pm.miniIcon = 0L;
695 read_app_startup_id();
696 useStyles = allowStyles;
697 if (disable_argb) argb_visual =
false;
708 visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ),
711 if ((visual) && (colormap))
712 getX11RGBAInformation(dpy);
713 aIconPixmap.pm.icon = 0L;
714 aIconPixmap.pm.miniIcon = 0L;
715 read_app_startup_id();
716 useStyles = allowStyles;
725 bool allowStyles,
KInstance * _instance ) :
727 visual?visual:getX11RGBAVisual(dpy), colormap?colormap:getX11RGBAColormap(dpy) ),
728 KInstance( _instance ), display(0L), d (new KApplicationPrivate)
730 if ((visual) && (colormap))
731 getX11RGBAInformation(dpy);
732 aIconPixmap.pm.icon = 0L;
733 aIconPixmap.pm.miniIcon = 0L;
734 read_app_startup_id();
735 useStyles = allowStyles;
752 d (new KApplicationPrivate)
754 aIconPixmap.pm.icon = 0L;
755 aIconPixmap.pm.miniIcon = 0L;
756 read_app_startup_id();
759 useStyles = allowStyles;
770 bool allowStyles,
bool GUIenabled ) :
771 TQApplication( display ),
KInstance(rAppName),
774 d (new KApplicationPrivate())
776 aIconPixmap.pm.icon = 0L;
777 aIconPixmap.pm.miniIcon = 0L;
778 read_app_startup_id();
781 useStyles = allowStyles;
783 Q_ASSERT (!rAppName.isEmpty());
787 KCmdLineArgs::initIgnore(argc, argv, rAppName.data());
794 int KApplication::xioErrhandler( Display* dpy )
800 d->oldXIOErrorHandler( dpy );
809 int KApplication::xErrhandler( Display* dpy,
void* err_ )
812 XErrorEvent* err =
static_cast< XErrorEvent*
>( err_ );
816 d->oldXErrorHandler( dpy, err );
822 void KApplication::iceIOErrorHandler( _IceConn *conn )
827 if ( d->oldIceIOErrorHandler != NULL )
828 (*d->oldIceIOErrorHandler)( conn );
833 class KDETranslator :
public TQTranslator
836 KDETranslator(TQObject *parent) : TQTranslator(parent,
"kdetranslator") {}
837 virtual TQTranslatorMessage findMessage(
const char* context,
838 const char *sourceText,
839 const char* message)
const
841 TQTranslatorMessage res;
842 res.setTranslation(
KGlobal::locale()->translateQt(context, sourceText, message));
847 void KApplication::init(
bool GUIenabled)
849 d->guiEnabled = GUIenabled;
850 if ((getuid() != geteuid()) ||
851 (getgid() != getegid()) )
855 struct group *man = getgrnam(
"man");
856 if ( !man || man->gr_gid != getegid() ){
857 fprintf(stderr,
"The KDE libraries are not designed to run with suid privileges.\n");
866 TQApplication::setDesktopSettingsAware(
false );
871 #ifdef Q_WS_X11 //FIXME(E)
877 Atom atoms_return[max];
880 atoms[n] = &kipcCommAtom;
881 names[n++] = (
char *)
"KIPC_COMM_ATOM";
883 atoms[n] = &atom_DesktopWindow;
884 names[n++] = (
char *)
"KDE_DESKTOP_WINDOW";
886 atoms[n] = &atom_NetSupported;
887 names[n++] = (
char *)
"_NET_SUPPORTED";
889 atoms[n] = &kde_xdnd_drop;
890 names[n++] = (
char *)
"XdndDrop";
892 XInternAtoms( qt_xdisplay(), names, n,
false, atoms_return );
894 for (
int i = 0; i < n; i++ )
895 *atoms[i] = atoms_return[i];
899 dcopAutoRegistration();
900 dcopClientPostInit();
906 kipcEventMask = (1 << KIPC::StyleChanged) | (1 << KIPC::PaletteChanged) |
907 (1 << KIPC::FontChanged) | (1 << KIPC::BackgroundChanged) |
908 (1 << KIPC::ToolbarStyleChanged) | (1 << KIPC::SettingsChanged) |
916 d->actionRestrictions = config->
hasGroup(
"KDE Action Restrictions" ) && !kde_kiosk_exception;
921 TQCString readOnly = getenv(
"KDE_HOME_READONLY");
922 if (readOnly.isEmpty() && (tqstrcmp(
name(),
"kdialog") != 0))
933 fcntl(ConnectionNumber(qt_xdisplay()), F_SETFD, FD_CLOEXEC);
935 d->oldXErrorHandler = XSetErrorHandler( kde_x_errhandler );
936 d->oldXIOErrorHandler = XSetIOErrorHandler( kde_xio_errhandler );
939 connect(
this, TQT_SIGNAL( aboutToQuit() ),
this, TQT_SIGNAL(
shutDown() ) );
941 #ifdef Q_WS_X11 //FIXME(E)
942 display = desktop()->x11Display();
947 TQStringList::Iterator it = plugins.begin();
948 while (it != plugins.end()) {
949 addLibraryPath( *it );
957 propagateSettings(SETTINGS_QT);
967 TQMimeSourceFactory* oldDefaultFactory = TQMimeSourceFactory::takeDefaultFactory();
969 if ( oldDefaultFactory ) {
970 TQMimeSourceFactory::addFactory( oldDefaultFactory );
973 d->checkAccelerators =
new KCheckAccelerators( TQT_TQOBJECT(
this) );
980 if (!pixmap.isNull()) {
981 TQImage i = pixmap.convertToImage().convertDepth(32).smoothScale(40, 40);
982 for(
int y = 0; y < i.height(); y++) {
983 uchar *l = i.scanLine(y);
984 for(
int x = 0; x < i.width(); x+=4)
987 CGColorSpaceRef cs = CGColorSpaceCreateDeviceRGB();
988 CGDataProviderRef dp = CGDataProviderCreateWithData(NULL,
989 i.bits(), i.numBytes(), NULL);
990 CGImageRef ir = CGImageCreate(i.width(), i.height(), 8, 32, i.bytesPerLine(),
991 cs, kCGImageAlphaNoneSkipFirst, dp,
992 0, 0, kCGRenderingIntentDefault);
994 SetApplicationDockTileImage(ir);
996 CGColorSpaceRelease(cs);
997 CGDataProviderRelease(dp);
1005 bool rtl = reverseLayout();
1006 installTranslator(
new KDETranslator(TQT_TQOBJECT(
this)));
1007 setReverseLayout( rtl );
1008 if (i18n(
"_: Dear Translator! Translate this string to the string 'LTR' in "
1009 "left-to-right languages (as english) or to 'RTL' in right-to-left "
1010 "languages (such as Hebrew and Arabic) to get proper widget layout." ) ==
"RTL")
1011 setReverseLayout( !rtl );
1015 + TQString::fromLatin1(
name()) +
'/');
1016 pSessionConfig = 0L;
1017 bSessionManagement =
true;
1021 if (GUIenabled && kde_have_kipc )
1023 smw =
new TQWidget(0,0);
1025 XChangeProperty(qt_xdisplay(), smw->winId(),
1026 atom_DesktopWindow, atom_DesktopWindow,
1027 32, PropModeReplace, (
unsigned char *)&data, 1);
1029 d->oldIceIOErrorHandler = IceSetIOErrorHandler( kde_ice_ioerrorhandler );
1030 #elif defined(Q_WS_WIN)
1031 KApplication_init_windows(GUIenabled);
1037 static int my_system (
const char *command) {
1044 const char* shell =
"/bin/sh";
1045 execl(shell, shell,
"-c", command, (
void *)0);
1049 if (waitpid(pid, &status, 0) == -1) {
1061 return s_DCOPClient;
1065 if (args && args->
isSet(
"dcopserver"))
1070 connect(s_DCOPClient, TQT_SIGNAL(attachFailed(
const TQString &)),
1071 kapp, TQT_SLOT(dcopFailure(
const TQString &)));
1072 connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(
bool) ),
1073 kapp, TQT_SLOT(dcopBlockUserInput(
bool)) );
1076 s_dcopClientNeedsPostInit =
true;
1079 return s_DCOPClient;
1082 void KApplication::dcopClientPostInit()
1084 if( s_dcopClientNeedsPostInit )
1086 s_dcopClientNeedsPostInit =
false;
1087 connect(s_DCOPClient, TQT_SIGNAL(blockUserInput(
bool) ),
1088 TQT_SLOT(dcopBlockUserInput(
bool)) );
1089 s_DCOPClient->bindToApp();
1093 void KApplication::dcopAutoRegistration()
1095 if (autoDcopRegistration)
1105 autoDcopRegistration =
false;
1111 return pSessionConfig;
1114 pSessionConfig =
new KConfig( sessionConfigName(),
false,
false);
1115 return pSessionConfig;
1128 if ( d->refCount <= 0 )
1132 KSessionManaged::KSessionManaged()
1134 sessionClients()->remove(
this );
1135 sessionClients()->append(
this );
1138 KSessionManaged::~KSessionManaged()
1140 sessionClients()->remove(
this );
1155 bSessionManagement =
false;
1159 bSessionManagement =
true;
1170 if( mySmcConnection ) {
1171 SmcRequestSaveYourself( mySmcConnection, SmSaveLocal, False,
1176 IceFlush(SmcGetIceConnection(mySmcConnection));
1186 TQApplication::syncX();
1193 TQDataStream arg(data, IO_WriteOnly);
1194 arg << (int)confirm << (
int)sdtype << (int)sdmode;
1196 "logout(int,int,int)", data );
1199 if ( mySmcConnection ) {
1201 SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True,
1206 IceFlush(SmcGetIceConnection(mySmcConnection));
1213 TQCString smEnv = ::getenv(
"SESSION_MANAGER");
1214 if (smEnv.isEmpty())
1217 if (! tmpSmcConnection) {
1222 tmpSmcConnection = SmcOpenConnection( 0, 0, 1, 0,
1229 if (!tmpSmcConnection )
1233 SmcRequestSaveYourself( tmpSmcConnection, SmSaveBoth, True,
1234 SmInteractStyleAny, False, True );
1237 IceFlush(SmcGetIceConnection(tmpSmcConnection));
1248 TQCString fName = TQFile::encodeName(locateLocal(
"socket",
"KSMserver"));
1249 TQCString display = ::getenv(DISPLAY);
1251 display.replace(TQRegExp(
"\\.[0-9]+$"),
"");
1253 while( (i = display.find(
':')) >= 0)
1256 fName +=
"_"+display;
1257 TQCString smEnv = ::getenv(
"SESSION_MANAGER");
1258 bool check = smEnv.isEmpty();
1259 if ( !check && smModificationTime ) {
1260 TQFileInfo info( fName );
1261 TQTime current = TQT_TQTIME_OBJECT(info.lastModified().time());
1262 check = current > *smModificationTime;
1265 delete smModificationTime;
1267 if ( !f.open( IO_ReadOnly ) )
1269 TQFileInfo info ( f );
1270 smModificationTime =
new TQTime( TQT_TQTIME_OBJECT(info.lastModified().time()) );
1272 t.setEncoding( TQTextStream::Latin1 );
1273 TQString s = t.readLine();
1275 ::setenv(
"SESSION_MANAGER", s.latin1(), true );
1282 d->session_save =
true;
1283 bool canceled =
false;
1286 it = sessionClients()->next() ) {
1287 canceled = !it->commitData( sm );
1292 if ( sm.allowsInteraction() ) {
1294 TQWidgetList *list = TQApplication::topLevelWidgets();
1295 bool canceled =
false;
1296 TQWidget* w = list->first();
1297 while ( !canceled && w ) {
1298 if ( !w->testWState( WState_ForceHide ) && !w->inherits(
"KMainWindow") ) {
1301 canceled = !e.isAccepted();
1305 list = TQApplication::topLevelWidgets();
1310 while ( w && done.containsRef( w ) )
1317 if ( !bSessionManagement )
1318 sm.setRestartHint( TQSessionManager::RestartNever );
1320 sm.setRestartHint( TQSessionManager::RestartIfRunning );
1321 d->session_save =
false;
1324 static void checkRestartVersion( TQSessionManager& sm )
1326 Display* dpy = qt_xdisplay();
1329 unsigned long nitems, after;
1330 unsigned char* data;
1331 if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy,
"TDE_FULL_SESSION", False ),
1332 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) {
1335 if( type == XA_STRING && format == 8 ) {
1336 if( XGetWindowProperty( dpy, RootWindow( dpy, 0 ), XInternAtom( dpy,
"KDE_SESSION_VERSION", False ),
1337 0, 1, False, AnyPropertyType, &type, &format, &nitems, &after, &data ) == Success ) {
1348 TQStringList restartCommand = sm.restartCommand();
1349 restartCommand.prepend( wrapper );
1350 sm.setRestartCommand( restartCommand );
1355 d->session_save =
true;
1357 static bool firstTime =
true;
1358 mySmcConnection = (SmcConn) sm.handle();
1360 if ( !bSessionManagement ) {
1361 sm.setRestartHint( TQSessionManager::RestartNever );
1362 d->session_save =
false;
1366 sm.setRestartHint( TQSessionManager::RestartIfRunning );
1370 d->session_save =
false;
1380 if ( pSessionConfig ) {
1381 delete pSessionConfig;
1386 TQStringList restartCommand = sm.restartCommand();
1388 TQCString multiHead = getenv(
"KDE_MULTIHEAD");
1389 if (multiHead.lower() ==
"true") {
1396 TQCString displayname = getenv(DISPLAY);
1397 if (! displayname.isNull()) {
1400 restartCommand.append(
"-display");
1401 restartCommand.append(displayname);
1403 sm.setRestartCommand( restartCommand );
1406 checkRestartVersion( sm );
1410 bool canceled =
false;
1413 it = sessionClients()->next() ) {
1414 canceled = !it->saveState( sm );
1418 if ( pSessionConfig ) {
1419 pSessionConfig->
sync();
1420 TQStringList discard;
1421 discard <<
"rm" << locateLocal(
"config", sessionConfigName());
1422 sm.setDiscardCommand( discard );
1424 sm.setDiscardCommand( TQStringList(
"") );
1432 d->session_save =
false;
1437 return d->session_save;
1440 void KApplication::startKdeinit()
1442 #ifndef Q_WS_WIN //TODO
1444 KLockFile lock( locateLocal(
"tmp",
"startkdeinitlock", &inst ));
1457 if (kapp && (Tty != kapp->type()))
1458 setOverrideCursor( tqwaitCursor );
1459 my_system(TQFile::encodeName(srv)+
" --suicide"+
" --new-startup");
1460 if (kapp && (Tty != kapp->type()))
1461 restoreOverrideCursor();
1465 void KApplication::dcopFailure(
const TQString &msg)
1467 static int failureCount = 0;
1469 if (failureCount == 1)
1474 if (failureCount == 2)
1481 TQString msgStr(i18n(
"There was an error setting up inter-process "
1482 "communications for KDE. The message returned "
1483 "by the system was:\n\n"));
1485 msgStr += i18n(
"\n\nPlease check that the \"dcopserver\" program is running!");
1487 if (Tty != kapp->type())
1489 TQMessageBox::critical
1492 i18n(
"DCOP communications error (%1)").arg(kapp->caption()),
1499 fprintf(stderr,
"%s\n", msgStr.local8Bit().data());
1510 {
"display <displayname>",
I18N_NOOP(
"Use the X-server display 'displayname'"), 0},
1512 {
"display <displayname>",
I18N_NOOP(
"Use the QWS display 'displayname'"), 0},
1514 {
"session <sessionId>",
I18N_NOOP(
"Restore the application for the given 'sessionId'"), 0},
1515 {
"cmap",
I18N_NOOP(
"Causes the application to install a private color\nmap on an 8-bit display"), 0},
1516 {
"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},
1517 {
"nograb",
I18N_NOOP(
"tells Qt to never grab the mouse or the keyboard"), 0},
1518 {
"dograb",
I18N_NOOP(
"running under a debugger can cause an implicit\n-nograb, use -dograb to override"), 0},
1519 {
"sync",
I18N_NOOP(
"switches to synchronous mode for debugging"), 0},
1521 {
"font <fontname>",
I18N_NOOP(
"defines the application font"), 0},
1523 {
"background <color>",
I18N_NOOP(
"sets the default background color and an\napplication palette (light and dark shades are\ncalculated)"), 0},
1525 {
"foreground <color>",
I18N_NOOP(
"sets the default foreground color"), 0},
1527 {
"button <color>",
I18N_NOOP(
"sets the default button color"), 0},
1528 {
"name <name>",
I18N_NOOP(
"sets the application name"), 0},
1529 {
"title <title>",
I18N_NOOP(
"sets the application title (caption)"), 0},
1531 {
"visual TrueColor",
I18N_NOOP(
"forces the application to use a TrueColor visual on\nan 8-bit display"), 0},
1532 {
"inputstyle <inputstyle>",
I18N_NOOP(
"sets XIM (X Input Method) input style. Possible\nvalues are onthespot, overthespot, offthespot and\nroot"), 0 },
1533 {
"im <XIM server>",
I18N_NOOP(
"set XIM server"),0},
1534 {
"noxim",
I18N_NOOP(
"disable XIM"), 0 },
1537 {
"qws",
I18N_NOOP(
"forces the application to run as QWS Server"), 0},
1539 {
"reverse",
I18N_NOOP(
"mirrors the whole layout of widgets"), 0},
1545 {
"caption <caption>",
I18N_NOOP(
"Use 'caption' as name in the titlebar"), 0},
1546 {
"icon <icon>",
I18N_NOOP(
"Use 'icon' as the application icon"), 0},
1547 {
"miniicon <icon>",
I18N_NOOP(
"Use 'icon' as the icon in the titlebar"), 0},
1548 {
"config <filename>",
I18N_NOOP(
"Use alternative configuration file"), 0},
1549 {
"dcopserver <server>",
I18N_NOOP(
"Use the DCOP Server specified by 'server'"), 0},
1550 {
"nocrashhandler",
I18N_NOOP(
"Disable crash handler, to get core dumps"), 0},
1551 {
"waitforwm",
I18N_NOOP(
"Waits for a WM_NET compatible windowmanager"), 0},
1552 {
"style <style>",
I18N_NOOP(
"sets the application GUI style"), 0},
1553 {
"geometry <geometry>",
I18N_NOOP(
"sets the client geometry of the main widget - see man X for the argument format"), 0},
1554 {
"smkey <sessionKey>", 0, 0},
1567 void KApplication::parseCommandLine( )
1571 if ( !args )
return;
1573 if (args->
isSet(
"config"))
1575 TQString config = TQString::fromLocal8Bit(args->
getOption(
"config"));
1579 if (args->
isSet(
"style"))
1583 TQStringList::Iterator itp = plugins.begin();
1584 while (itp != plugins.end()) {
1585 addLibraryPath( *itp );
1589 TQStringList styles = TQStyleFactory::keys();
1590 TQString reqStyle(args->
getOption(
"style").lower());
1592 TQStringList list = libraryPaths();
1593 TQStringList::Iterator it = list.begin();
1594 while( it != list.end() ) {
1598 for (TQStringList::ConstIterator it = styles.begin(); it != styles.end(); ++it) {
1599 if ((*it).lower() == reqStyle)
1601 d->overrideStyle = *it;
1606 if (d->overrideStyle.isEmpty())
1607 fprintf(stderr,
"%s", TQString(i18n(
"The style %1 was not found\n").arg(reqStyle)).local8Bit().data());
1610 if (args->
isSet(
"caption"))
1612 aCaption = TQString::fromLocal8Bit(args->
getOption(
"caption"));
1615 if (args->
isSet(
"miniicon"))
1617 const char *tmp = args->
getOption(
"miniicon");
1618 if (!aIconPixmap.pm.miniIcon) {
1619 aIconPixmap.pm.miniIcon =
new TQPixmap;
1621 *aIconPixmap.pm.miniIcon = SmallIcon(tmp);
1622 aMiniIconName = tmp;
1625 if (args->
isSet(
"icon"))
1627 const char *tmp = args->
getOption(
"icon");
1628 if (!aIconPixmap.pm.icon) {
1629 aIconPixmap.pm.icon =
new TQPixmap;
1631 *aIconPixmap.pm.icon = DesktopIcon( tmp );
1633 if (!aIconPixmap.pm.miniIcon) {
1634 aIconPixmap.pm.miniIcon =
new TQPixmap;
1636 if (aIconPixmap.pm.miniIcon->isNull())
1638 *aIconPixmap.pm.miniIcon = SmallIcon( tmp );
1639 aMiniIconName = tmp;
1643 bool nocrashhandler = (getenv(
"KDE_DEBUG") != NULL);
1644 if (!nocrashhandler && args->
isSet(
"crashhandler"))
1654 if ( args->
isSet(
"waitforwm" ) ) {
1658 unsigned long length, after;
1659 unsigned char *data;
1660 while ( XGetWindowProperty( qt_xdisplay(), qt_xrootwin(), atom_NetSupported,
1661 0, 1,
false, AnyPropertyType, &type, &format,
1662 &length, &after, &data ) != Success || !length ) {
1666 XWindowEvent( qt_xdisplay(), qt_xrootwin(), PropertyChangeMask, &event );
1675 if (args->
isSet(
"geometry"))
1677 d->geometry_arg = args->
getOption(
"geometry");
1680 if (args->
isSet(
"smkey"))
1682 d->sessionKey = args->
getOption(
"smkey");
1689 return d->geometry_arg;
1694 if( !aIconPixmap.pm.icon) {
1695 aIconPixmap.pm.icon =
new TQPixmap;
1697 if( aIconPixmap.pm.icon->isNull()) {
1700 return *aIconPixmap.pm.icon;
1705 return aIconName.isNull() ? (TQString)
instanceName() : aIconName;
1710 if (!aIconPixmap.pm.miniIcon) {
1711 aIconPixmap.pm.miniIcon =
new TQPixmap;
1713 if (aIconPixmap.pm.miniIcon->isNull()) {
1714 *aIconPixmap.pm.miniIcon = SmallIcon(
instanceName() );
1716 return *aIconPixmap.pm.miniIcon;
1721 return aMiniIconName.isNull() ? (TQString)
instanceName() : aMiniIconName;
1724 extern void kDebugCleanup();
1726 KApplication::~KApplication()
1728 delete aIconPixmap.pm.miniIcon;
1729 aIconPixmap.pm.miniIcon = 0L;
1730 delete aIconPixmap.pm.icon;
1731 aIconPixmap.pm.icon = 0L;
1732 delete d->m_KAppDCOPInterface;
1738 KLibLoader::cleanUp();
1743 delete s_DCOPClient;
1749 if ( d->oldXErrorHandler != NULL )
1750 XSetErrorHandler( d->oldXErrorHandler );
1751 if ( d->oldXIOErrorHandler != NULL )
1752 XSetIOErrorHandler( d->oldXIOErrorHandler );
1753 if ( d->oldIceIOErrorHandler != NULL )
1754 IceSetIOErrorHandler( d->oldIceIOErrorHandler );
1761 mySmcConnection = 0;
1762 delete smModificationTime;
1763 smModificationTime = 0;
1766 if (tmpSmcConnection) {
1767 SmcCloseConnection( tmpSmcConnection, 0, 0 );
1768 tmpSmcConnection = 0;
1777 class KAppX11HackWidget:
public QWidget
1780 bool publicx11Event( XEvent * e) {
return x11Event( e ); }
1784 #if defined(Q_WS_X11) && defined(COMPOSITE)
1786 bool have_manager =
false;
1789 p = getpwuid(getuid());
1793 home = getenv(
"HOME");
1796 const char *configfile =
"/.kompmgr.available";
1797 int n = strlen(home)+strlen(configfile)+1;
1798 filename = (
char*)malloc(n*
sizeof(
char));
1799 memset(filename,0,n);
1800 strcat(filename, home);
1801 strcat(filename, configfile);
1805 pFile = fopen(filename,
"r");
1807 have_manager =
true;
1814 return have_manager;
1818 bool compositing_manager_available;
1819 if (force_available) {
1820 compositing_manager_available = available;
1825 char *displayname = 0;
1826 if ( qtargs->
isSet(
"display"))
1827 displayname = qtargs->
getOption(
"display" ).data();
1829 Display *dpy = XOpenDisplay( displayname );
1831 x11_composite_error_generated =
false;
1832 compositing_manager_available =
false;
1833 XSetErrorHandler(x11_error);
1834 if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode, &composite_event, &composite_error)) {
1835 XSetErrorHandler(NULL);
1836 compositing_manager_available =
false;
1840 Window root_window = XDefaultRootWindow(dpy);
1841 XCompositeRedirectSubwindows(dpy, root_window, CompositeRedirectManual);
1843 if (x11_composite_error_generated ==
true) {
1844 compositing_manager_available =
true;
1847 XCompositeUnredirectSubwindows(dpy, root_window, CompositeRedirectManual);
1848 compositing_manager_available =
false;
1850 XSetErrorHandler(NULL);
1854 compositing_manager_available =
true;
1861 p = getpwuid(getuid());
1865 home = getenv(
"HOME");
1868 const char *configfile =
"/.kompmgr.available";
1869 int n = strlen(home)+strlen(configfile)+1;
1870 filename = (
char*)malloc(n*
sizeof(
char));
1871 memset(filename,0,n);
1872 strcat(filename, home);
1873 strcat(filename, configfile);
1876 if (compositing_manager_available) {
1879 sprintf(buffer,
"available");
1880 pFile = fopen(filename,
"w");
1882 fwrite(buffer,1,strlen(buffer), pFile);
1893 return compositing_manager_available;
1896 Display* KApplication::openX11RGBADisplay() {
1899 if ( qtargs->
isSet(
"display"))
1900 display = qtargs->
getOption(
"display" ).data();
1902 Display *dpy = XOpenDisplay( display );
1904 kdError() <<
"cannot connect to X server " << display <<
endl;
1912 getX11RGBAInformation(dpy);
1914 return argb_x11_visual;
1917 return (Qt::HANDLE)NULL;
1922 getX11RGBAInformation(dpy);
1924 return argb_x11_colormap;
1927 return (Qt::HANDLE)NULL;
1935 void KApplication::getX11RGBAInformation(Display *dpy) {
1937 argb_visual =
false;
1941 int screen = DefaultScreen( dpy );
1942 Colormap colormap = 0;
1944 int event_base, error_base;
1946 if ( XRenderQueryExtension( dpy, &event_base, &error_base ) ) {
1949 templ.screen = screen;
1951 templ.c_class = TrueColor;
1952 XVisualInfo *xvi = XGetVisualInfo( dpy, VisualScreenMask | VisualDepthMask
1953 | VisualClassMask, &templ, &nvi );
1955 for (
int i = 0; i < nvi; i++ ) {
1956 XRenderPictFormat *format = XRenderFindVisualFormat( dpy, xvi[i].visual );
1957 if ( format->type == PictTypeDirect && format->direct.alphaMask ) {
1958 visual = xvi[i].visual;
1959 colormap = XCreateColormap( dpy, RootWindow( dpy, screen ), visual, AllocNone );
1960 kdDebug() <<
"found visual with alpha support" <<
endl;
1968 argb_x11_visual = Qt::HANDLE( visual );
1969 argb_x11_colormap = Qt::HANDLE( colormap );
1973 argb_visual =
false;
1977 void KApplication::getX11RGBAInformation(Display *dpy) {
1987 p = getpwuid(getuid());
1991 home = getenv(
"HOME");
1994 const char *configfile =
"/.kompmgr.available";
1995 int n = strlen(home)+strlen(configfile)+1;
1996 filename = (
char*)malloc(n*
sizeof(
char));
1997 memset(filename,0,n);
1998 strcat(filename, home);
1999 strcat(filename, configfile);
2002 if (force_available) {
2005 sprintf(buffer,
"available");
2006 pFile = fopen(filename,
"w");
2008 fwrite(buffer,1,strlen(buffer), pFile);
2022 Display* KApplication::openX11RGBADisplay() {
2038 KApplication KApplication::KARGBApplication(
bool allowStyles ) {
2043 static bool kapp_block_user_input =
false;
2045 void KApplication::dcopBlockUserInput(
bool b )
2047 kapp_block_user_input = b;
2051 bool KApplication::x11EventFilter( XEvent *_event )
2053 switch ( _event->type ) {
2056 #if KDE_IS_VERSION( 3, 90, 90 )
2057 #warning This should be already in Qt, check.
2064 if( _event->xclient.message_type == kde_xdnd_drop )
2066 if( _event->xclient.data.l[ 1 ] == 1 << 24
2067 && _event->xclient.data.l[ 2 ] == 0
2068 && _event->xclient.data.l[ 4 ] == 0
2069 && _event->xclient.data.l[ 3 ] != 0 )
2071 if( GET_QT_X_USER_TIME() == 0
2074 SET_QT_X_USER_TIME(_event->xclient.data.l[ 3 ]);
2079 if( GET_QT_X_USER_TIME() == 0
2082 SET_QT_X_USER_TIME(_event->xclient.data.l[ 2 ]);
2090 if ( kapp_block_user_input ) {
2091 switch ( _event->type ) {
2106 for (TQWidget *w=x11Filter->first(); w; w=x11Filter->next()) {
2107 if (((KAppX11HackWidget*) w)->publicx11Event(_event))
2112 if ((_event->type == ClientMessage) &&
2113 (_event->xclient.message_type == kipcCommAtom))
2115 XClientMessageEvent *cme = (XClientMessageEvent *) _event;
2117 int id = cme->data.l[0];
2118 int arg = cme->data.l[1];
2119 if ((
id < 32) && (kipcEventMask & (1 << id)))
2123 case KIPC::StyleChanged:
2128 case KIPC::ToolbarStyleChanged:
2134 case KIPC::PaletteChanged:
2136 kdisplaySetPalette();
2139 case KIPC::FontChanged:
2141 KGlobalSettings::rereadFontSettings();
2145 case KIPC::BackgroundChanged:
2149 case KIPC::SettingsChanged:
2151 if (arg == SETTINGS_PATHS)
2152 KGlobalSettings::rereadPathSettings();
2153 else if (arg == SETTINGS_MOUSE)
2154 KGlobalSettings::rereadMouseSettings();
2158 case KIPC::IconChanged:
2159 TQPixmapCache::clear();
2162 emit updateIconLoaders();
2166 case KIPC::ClipboardConfigChanged:
2167 KClipboardSynchronizer::newConfiguration(arg);
2171 KGlobalAccel::blockShortcuts(arg);
2188 #if defined Q_WS_X11
2191 Window w = XCreateSimpleWindow( qt_xdisplay(), qt_xrootwin(), 0, 0, 1, 1, 0, 0, 0 );
2192 XSelectInput( qt_xdisplay(), w, PropertyChangeMask );
2193 unsigned char data[ 1 ];
2194 XChangeProperty( qt_xdisplay(), w, XA_ATOM, XA_ATOM, 8, PropModeAppend, data, 1 );
2196 XWindowEvent( qt_xdisplay(), w, PropertyChangeMask, &ev );
2197 time = ev.xproperty.time;
2198 XDestroyWindow( qt_xdisplay(), w );
2200 if( GET_QT_X_USER_TIME() == 0
2202 SET_QT_X_USER_TIME(time);
2208 #if defined Q_WS_X11
2209 return GET_QT_X_USER_TIME();
2217 #if defined Q_WS_X11
2219 time = GET_QT_X_USER_TIME();
2220 DCOPRef( dcopId,
"MainApplication-Interface" ).
call(
"updateUserTimestamp", time );
2226 TQObject *
object = TQT_TQOBJECT(focusWidget());
2230 TQMetaObject *meta =
object->metaObject();
2232 int idx = meta->findSlot( slot + 1,
true );
2236 object->qt_invoke( idx, 0 );
2243 kdDebug(101) <<
"Cannot use KIPC event mask for message IDs >= 32\n";
2246 kipcEventMask |= (1 << id);
2253 kdDebug(101) <<
"Cannot use KIPC event mask for message IDs >= 32\n";
2256 kipcEventMask &= ~(1 << id);
2273 void KApplication::applyGUIStyle()
2275 if ( !useStyles )
return;
2278 TQString defaultStyle = KStyle::defaultStyle();
2279 TQString styleStr = pConfig.readEntry(
"widgetStyle", defaultStyle);
2281 if (d->overrideStyle.isEmpty()) {
2285 TQStyle* sp = TQStyleFactory::create( styleStr );
2288 if ( !sp && styleStr != defaultStyle)
2289 sp = TQStyleFactory::create( defaultStyle );
2291 sp = TQStyleFactory::create( *(TQStyleFactory::keys().begin()) );
2295 setStyle(d->overrideStyle);
2297 kdisplaySetPalette();
2303 if( !aCaption.isNull() )
2320 bool withAppName,
bool modified )
const
2322 TQString s = userCaption.isEmpty() ?
caption() : userCaption;
2326 s += TQString::fromUtf8(
" [") + i18n(
"modified") + TQString::fromUtf8(
"]");
2328 if ( !userCaption.isEmpty() ) {
2331 if ( withAppName && !
caption().isNull() && !userCaption.endsWith(
caption()) )
2332 s += TQString::fromUtf8(
" - ") +
caption();
2347 TQColor trinity4Background( 239, 239, 239 );
2348 TQColor trinity4Blue( 103,141,178 );
2350 TQColor trinity4Button;
2351 if ( TQPixmap::defaultDepth() > 8 )
2352 trinity4Button.setRgb( 221, 223, 228 );
2354 trinity4Button.setRgb( 220, 220, 220 );
2356 TQColor trinity4Link( 0, 0, 238 );
2357 TQColor trinity4VisitedLink( 82, 24, 139 );
2359 TQColor background = config->
readColorEntry(
"background", &trinity4Background );
2360 TQColor foreground = config->
readColorEntry(
"foreground", tqblackptr );
2361 TQColor button = config->
readColorEntry(
"buttonBackground", &trinity4Button );
2362 TQColor buttonText = config->
readColorEntry(
"buttonForeground", tqblackptr );
2363 TQColor highlight = config->
readColorEntry(
"selectBackground", &trinity4Blue );
2364 TQColor highlightedText = config->
readColorEntry(
"selectForeground", tqwhiteptr );
2365 TQColor base = config->
readColorEntry(
"windowBackground", tqwhiteptr );
2366 TQColor baseText = config->
readColorEntry(
"windowForeground", tqblackptr );
2367 TQColor link = config->
readColorEntry(
"linkColor", &trinity4Link );
2368 TQColor visitedLink = config->
readColorEntry(
"visitedLinkColor", &trinity4VisitedLink );
2370 int highlightVal, lowlightVal;
2371 highlightVal = 100 + (2*contrast_+4)*16/10;
2372 lowlightVal = 100 + (2*contrast_+4)*10;
2374 TQColor disfg = foreground;
2377 disfg.hsv( &h, &s, &v );
2380 disfg = disfg.dark(lowlightVal);
2381 else if (disfg != Qt::black)
2383 disfg = disfg.light(highlightVal);
2386 disfg = Qt::darkGray;
2389 TQColorGroup disabledgrp(disfg, background,
2390 background.light(highlightVal),
2391 background.dark(lowlightVal),
2392 background.dark(120),
2393 background.dark(120), base);
2395 TQColorGroup colgrp(foreground, background, background.light(highlightVal),
2396 background.dark(lowlightVal),
2397 background.dark(120),
2400 int inlowlightVal = lowlightVal-25;
2401 if(inlowlightVal < 120)
2402 inlowlightVal = 120;
2404 colgrp.setColor(TQColorGroup::Highlight, highlight);
2405 colgrp.setColor(TQColorGroup::HighlightedText, highlightedText);
2406 colgrp.setColor(TQColorGroup::Button, button);
2407 colgrp.setColor(TQColorGroup::ButtonText, buttonText);
2408 colgrp.setColor(TQColorGroup::Midlight, background.light(110));
2409 colgrp.setColor(TQColorGroup::Link, link);
2410 colgrp.setColor(TQColorGroup::LinkVisited, visitedLink);
2412 disabledgrp.setColor(TQColorGroup::Button, button);
2414 TQColor disbtntext = buttonText;
2415 disbtntext.hsv( &h, &s, &v );
2418 disbtntext = disbtntext.dark(lowlightVal);
2419 else if (disbtntext != Qt::black)
2421 disbtntext = disbtntext.light(highlightVal);
2424 disbtntext = Qt::darkGray;
2426 disabledgrp.setColor(TQColorGroup::ButtonText, disbtntext);
2427 disabledgrp.setColor(TQColorGroup::Midlight, background.light(110));
2428 disabledgrp.setColor(TQColorGroup::Highlight, highlight.dark(120));
2429 disabledgrp.setColor(TQColorGroup::Link, link);
2430 disabledgrp.setColor(TQColorGroup::LinkVisited, visitedLink);
2432 return TQPalette(colgrp, disabledgrp, colgrp);
2436 void KApplication::kdisplaySetPalette()
2443 bool do_not_set_palette = FALSE;
2444 if(config->
readBoolEntry(
"nopaletteChange", &do_not_set_palette))
2454 void KApplication::kdisplaySetFont()
2462 TQStyleSheet* sheet = TQStyleSheet::defaultSheet();
2472 void KApplication::kdisplaySetStyle()
2483 void KApplication::propagateSettings(SettingsCategory arg)
2488 #ifdef QT_HAVE_MAX_IMAGE_SIZE
2489 TQSize maxImageSize(4096, 4096);
2490 maxImageSize = config->
readSizeEntry(
"MaxImageSize", &maxImageSize);
2491 TQImage::setMaxImageSize(maxImageSize);
2494 int num = config->
readNumEntry(
"CursorBlinkRate", TQApplication::cursorFlashTime());
2495 if ((num != 0) && (num < 200))
2499 TQApplication::setCursorFlashTime(num);
2500 num = config->
readNumEntry(
"DoubleClickInterval", TQApplication::doubleClickInterval());
2501 TQApplication::setDoubleClickInterval(num);
2502 num = config->
readNumEntry(
"StartDragTime", TQApplication::startDragTime());
2503 TQApplication::setStartDragTime(num);
2504 num = config->
readNumEntry(
"StartDragDist", TQApplication::startDragDistance());
2505 TQApplication::setStartDragDistance(num);
2506 num = config->
readNumEntry(
"WheelScrollLines", TQApplication::wheelScrollLines());
2507 TQApplication::setWheelScrollLines(num);
2510 TQApplication::setEffectEnabled( Qt::UI_AnimateMenu, b);
2512 TQApplication::setEffectEnabled( Qt::UI_FadeMenu, b);
2514 TQApplication::setEffectEnabled( Qt::UI_AnimateCombo, b);
2516 TQApplication::setEffectEnabled( Qt::UI_AnimateTooltip, b);
2518 TQApplication::setEffectEnabled( Qt::UI_FadeTooltip, b);
2520 TQToolTip::setGloballyEnabled( b );
2528 static bool installed =
false;
2529 if (installed)
return;
2538 TQSqlPropertyMap *kdeMap =
new TQSqlPropertyMap;
2539 kdeMap->insert(
"KColorButton",
"color" );
2540 kdeMap->insert(
"KComboBox",
"currentItem" );
2541 kdeMap->insert(
"KDatePicker",
"date" );
2542 kdeMap->insert(
"KDateWidget",
"date" );
2543 kdeMap->insert(
"KDateTimeWidget",
"dateTime" );
2544 kdeMap->insert(
"KEditListBox",
"items" );
2545 kdeMap->insert(
"KFontCombo",
"family" );
2546 kdeMap->insert(
"KFontRequester",
"font" );
2547 kdeMap->insert(
"KFontChooser",
"font" );
2548 kdeMap->insert(
"KHistoryCombo",
"currentItem" );
2549 kdeMap->insert(
"KListBox",
"currentItem" );
2550 kdeMap->insert(
"KLineEdit",
"text" );
2551 kdeMap->insert(
"KRestrictedLine",
"text" );
2552 kdeMap->insert(
"KSqueezedTextLabel",
"text" );
2553 kdeMap->insert(
"KTextBrowser",
"source" );
2554 kdeMap->insert(
"KTextEdit",
"text" );
2555 kdeMap->insert(
"KURLRequester",
"url" );
2556 kdeMap->insert(
"KPasswordEdit",
"password" );
2557 kdeMap->insert(
"KIntNumInput",
"value" );
2558 kdeMap->insert(
"KIntSpinBox",
"value" );
2559 kdeMap->insert(
"KDoubleNumInput",
"value" );
2561 kdeMap->insert( TQGROUPBOX_OBJECT_NAME_STRING,
"checked" );
2562 kdeMap->insert( TQTABWIDGET_OBJECT_NAME_STRING,
"currentPage" );
2563 TQSqlPropertyMap::installDefaultMap( kdeMap );
2568 const TQString& _appname)
const
2577 const TQString& _appname,
2578 const TQCString& startup_id )
const
2582 if (_appname.isEmpty())
2587 if (!anchor.isEmpty())
2588 url = TQString(
"help:/%1?anchor=%2").arg(appname).arg(anchor);
2590 url = TQString(
"help:/%1/index.html").arg(appname);
2593 if ( !
dcopClient()->isApplicationRegistered(
"khelpcenter") )
2597 if (Tty != kapp->type())
2598 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Help Center"),
2599 i18n(
"Could not launch the KDE Help Center:\n\n%1").arg(error), i18n(
"&OK"));
2601 kdWarning() <<
"Could not launch help:\n" << error <<
endl;
2606 DCOPRef(
"khelpcenter",
"KHelpCenterIface" ).
send(
"openUrl", url, startup_id );
2612 kdWarning() <<
"invoking HTML help is deprecated! use docbook and invokeHelp!\n";
2616 if( _filename.isEmpty() )
2617 filename = TQString(name()) +
"/index.html";
2619 filename = _filename;
2622 if (!topic.isEmpty())
2623 url = TQString(
"help:/%1#%2").arg(filename).arg(topic);
2625 url = TQString(
"help:/%1").arg(filename);
2628 if ( !
dcopClient()->isApplicationRegistered(
"khelpcenter") )
2632 if (Tty != kapp->type())
2633 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Help Center"),
2634 i18n(
"Could not launch the KDE Help Center:\n\n%1").arg(error), i18n(
"&OK"));
2636 kdWarning() <<
"Could not launch help:\n" << error <<
endl;
2641 DCOPRef(
"khelpcenter",
"KHelpCenterIface" ).
send(
"openUrl", url );
2652 invokeMailer(address, TQString::null, TQString::null, subject, TQString::null, TQString::null,
2653 TQStringList(), startup_id );
2669 TQStringList queries = TQStringList::split(
'&', mailtoURL.
query().mid(1));
2670 TQStringList attachURLs;
2671 for (TQStringList::Iterator it = queries.begin(); it != queries.end(); ++it)
2673 TQString q = (*it).lower();
2674 if (q.startsWith(
"subject="))
2677 if (q.startsWith(
"cc="))
2680 if (q.startsWith(
"bcc="))
2683 if (q.startsWith(
"body="))
2686 if (allowAttachments && q.startsWith(
"attach="))
2689 if (allowAttachments && q.startsWith(
"attachment="))
2692 if (q.startsWith(
"to="))
2696 invokeMailer( address, cc, bcc, subject, body, TQString::null, attachURLs, startup_id );
2700 const TQString &subject,
const TQString &body,
2701 const TQString & messageFile,
const TQStringList &attachURLs)
2703 return invokeMailer(to,cc,bcc,subject,body,messageFile,attachURLs,
"");
2710 static TQStringList splitEmailAddressList(
const TQString & aStr )
2728 int commentlevel = 0;
2729 bool insidequote =
false;
2731 for (uint index=0; index<aStr.length(); index++) {
2734 switch (aStr[index].latin1()) {
2736 if (commentlevel == 0)
2737 insidequote = !insidequote;
2745 if (commentlevel > 0)
2758 if (!insidequote && (commentlevel == 0)) {
2759 addr = aStr.mid(addrstart, index-addrstart);
2760 if (!addr.isEmpty())
2761 list += addr.simplifyWhiteSpace();
2762 addrstart = index+1;
2768 if (!insidequote && (commentlevel == 0)) {
2769 addr = aStr.mid(addrstart, aStr.length()-addrstart);
2770 if (!addr.isEmpty())
2771 list += addr.simplifyWhiteSpace();
2782 const TQString &subject,
const TQString &body,
2783 const TQString & ,
const TQStringList &attachURLs,
2784 const TQCString& startup_id )
2789 TQString group = config.
readEntry(
"Profile",
"Default");
2791 config.
setGroup( TQString(
"PROFILE_%1").arg(group) );
2794 TQString to, cc, bcc;
2795 if (command.isEmpty() || command == TQString::fromLatin1(
"kmail")
2796 || command.endsWith(
"/kmail"))
2798 command = TQString::fromLatin1(
"kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t");
2799 if ( !_to.isEmpty() )
2803 to = TQString(
"=?utf8?b?%1?=" )
2806 if ( !_cc.isEmpty() )
2807 cc = TQString(
"=?utf8?b?%1?=" )
2809 if ( !_bcc.isEmpty() )
2810 bcc = TQString(
"=?utf8?b?%1?=" )
2816 if( !command.contains(
'%' ))
2823 TQString preferredTerminal = confGroup.
readPathEntry(
"TerminalApplication",
"konsole");
2824 command = preferredTerminal +
" -e " + command;
2828 TQString cmd = cmdTokens[0];
2829 cmdTokens.remove(cmdTokens.begin());
2835 TQStringList tos = splitEmailAddressList( to );
2837 tos.remove( tos.begin() );
2838 for (TQStringList::ConstIterator it = tos.begin(); it != tos.end(); ++it)
2841 const TQStringList ccs = splitEmailAddressList( cc );
2842 for (TQStringList::ConstIterator it = ccs.begin(); it != ccs.end(); ++it)
2844 const TQStringList bccs = splitEmailAddressList( bcc );
2845 for (TQStringList::ConstIterator it = bccs.begin(); it != bccs.end(); ++it)
2847 for (TQStringList::ConstIterator it = attachURLs.begin(); it != attachURLs.end(); ++it)
2849 if (!subject.isEmpty())
2851 if (!body.isEmpty())
2854 if ( ! (to.isEmpty() && qry.isEmpty()) )
2857 TQMap<TQChar, TQString> keyMap;
2858 keyMap.insert(
't', to);
2859 keyMap.insert(
's', subject);
2860 keyMap.insert(
'c', cc);
2861 keyMap.insert(
'b', bcc);
2862 keyMap.insert(
'B', body);
2863 keyMap.insert(
'u', url.
url());
2865 TQString attachlist = attachURLs.join(
",");
2866 attachlist.prepend(
'\'');
2867 attachlist.append(
'\'');
2868 keyMap.insert(
'A', attachlist);
2870 for (TQStringList::Iterator it = cmdTokens.begin(); it != cmdTokens.end(); )
2874 if (it == cmdTokens.begin())
2876 TQStringList::ConstIterator urlit = attachURLs.begin();
2877 TQStringList::ConstIterator urlend = attachURLs.end();
2878 if ( urlit != urlend )
2880 TQStringList::Iterator previt = it;
2884 while ( ++urlit != urlend )
2886 cmdTokens.insert( it, *previt );
2887 cmdTokens.insert( it, *urlit );
2891 it = cmdTokens.remove( cmdTokens.remove( it ) );
2902 if (
kdeinitExec(cmd, cmdTokens, &error, NULL, startup_id )) {
2903 if (Tty != kapp->type()) {
2904 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Mail Client"),
2905 i18n(
"Could not launch the mail client:\n\n%1").arg(error), i18n(
"&OK"));
2908 kdWarning() <<
"Could not launch mail client:\n" << error <<
endl;
2928 if (Tty != kapp->type())
2929 TQMessageBox::critical(kapp->mainWidget(), i18n(
"Could not Launch Browser"),
2930 i18n(
"Could not launch the browser:\n\n%1").arg(error), i18n(
"&OK"));
2932 kdWarning() <<
"Could not launch browser:\n" << error <<
endl;
2965 emit coreFakeKeyPress(keyCode);
2975 startServiceInternal(
const TQCString &
function,
2976 const TQString& _name,
const TQStringList &URLs,
2977 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
2979 struct serviceResult
2990 dcopClient = kapp->dcopClient();
2996 if (!dcopClient->
attach())
2999 *error =
i18n(
"Could not register with DCOP.\n");
3007 TQDataStream stream(params, IO_WriteOnly);
3008 stream << _name << URLs;
3009 TQCString replyType;
3010 TQByteArray replyData;
3012 TQValueList<TQCString> envs;
3014 if (qt_xdisplay()) {
3015 TQCString dpystring(XDisplayString(qt_xdisplay()));
3016 envs.append( TQCString(
"DISPLAY=") + dpystring );
3017 }
else if( getenv(
"DISPLAY" )) {
3018 TQCString dpystring( getenv(
"DISPLAY" ));
3019 envs.append( TQCString(
"DISPLAY=") + dpystring );
3023 #if defined Q_WS_X11
3025 stream << ( startup_id.isEmpty() ? KStartupInfo::createNewStartupId() : startup_id );
3027 if(
function.left( 12 ) !=
"kdeinit_exec" )
3030 if (!dcopClient->
call(_launcher, _launcher,
3031 function, params, replyType, replyData))
3034 *error =
i18n(
"KLauncher could not be reached via DCOP.\n");
3045 TQDataStream stream2(replyData, IO_ReadOnly);
3046 serviceResult result;
3047 stream2 >> result.result >> result.dcopName >> result.error >> result.pid;
3049 *dcopService = result.dcopName;
3051 *error = result.error;
3054 return result.result;
3059 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3064 return startServiceInternal(
3065 "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3066 _name, URLs, error, dcopService, pid, startup_id, noWait);
3071 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3073 return startServiceInternal(
3074 "start_service_by_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3075 _name, URLs, error, dcopService, pid, startup_id, noWait);
3080 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3085 return startServiceInternal(
3086 "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3087 _name, URLs, error, dcopService, pid, startup_id, noWait);
3092 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3094 return startServiceInternal(
3095 "start_service_by_desktop_path(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3096 _name, URLs, error, dcopService, pid, startup_id, noWait);
3101 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3106 return startServiceInternal(
3107 "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3108 _name, URLs, error, dcopService, pid, startup_id, noWait);
3113 TQString *error, TQCString *dcopService,
int *pid,
const TQCString& startup_id,
bool noWait )
3115 return startServiceInternal(
3116 "start_service_by_desktop_name(TQString,TQStringList,TQValueList<TQCString>,TQCString,bool)",
3117 _name, URLs, error, dcopService, pid, startup_id, noWait);
3122 TQString *error,
int *pid )
3129 TQString *error,
int *pid,
const TQCString& startup_id )
3131 return startServiceInternal(
"kdeinit_exec(TQString,TQStringList,TQValueList<TQCString>,TQCString)",
3132 name, args, error, 0, pid, startup_id,
false);
3137 TQString *error,
int *pid )
3144 TQString *error,
int *pid,
const TQCString& startup_id )
3146 return startServiceInternal(
"kdeinit_exec_wait(TQString,TQStringList,TQValueList<TQCString>,TQCString)",
3147 name, args, error, 0, pid, startup_id,
false);
3154 if( TQDir::isRelativePath(pFilename) )
3156 kdWarning(101) <<
"Relative filename passed to KApplication::tempSaveName" <<
endl;
3157 aFilename = TQFileInfo( TQDir(
"." ), pFilename ).absFilePath();
3160 aFilename = pFilename;
3162 TQDir aAutosaveDir( TQDir::homeDirPath() +
"/autosave/" );
3163 if( !aAutosaveDir.exists() )
3165 if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
3168 aAutosaveDir.setPath(
KGlobal::dirs()->saveLocation(
"tmp") );
3172 aFilename.replace(
"/",
"\\!" ).prepend(
"#" ).append(
"#" ).prepend(
"/" ).prepend( aAutosaveDir.absPath() );
3179 bool& bRecover )
const
3183 if( TQDir::isRelativePath(pFilename) )
3185 kdWarning(101) <<
"Relative filename passed to KApplication::tempSaveName" <<
endl;
3186 aFilename = TQFileInfo( TQDir(
"." ), pFilename ).absFilePath();
3189 aFilename = pFilename;
3191 TQDir aAutosaveDir( TQDir::homeDirPath() +
"/autosave/" );
3192 if( !aAutosaveDir.exists() )
3194 if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
3197 aAutosaveDir.setPath(
KGlobal::dirs()->saveLocation(
"tmp") );
3201 aFilename.replace(
"/",
"\\!" ).prepend(
"#" ).append(
"#" ).prepend(
"/" ).prepend( aAutosaveDir.absPath() );
3203 if( TQFile( aFilename ).exists() )
3218 int accessOK = access( TQFile::encodeName(pathname), mode );
3219 if ( accessOK == 0 )
3225 if ( (mode & W_OK) == 0 )
3229 if (!access( TQFile::encodeName(pathname), F_OK))
3233 TQString dirName(pathname);
3234 int pos = dirName.findRev(
'/');
3237 else if ( pos == 0 )
3240 dirName.truncate(pos);
3242 accessOK = access( TQFile::encodeName(dirName), W_OK );
3244 if ( accessOK == 0 )
3256 if ( !topWidget->inherits(
"KMainWindow") ) {
3257 topWidget->setCaption(
caption() );
3261 topWidget->setIcon(
icon() );
3262 #if defined Q_WS_X11
3267 KStartupInfo::setWindowStartupId( topWidget->winId(),
startupId());
3273 return d->startup_id;
3276 void KApplication::setStartupId(
const TQCString& startup_id )
3278 if( startup_id == d->startup_id )
3280 #if defined Q_WS_X11
3281 KStartupInfo::handleAutoAppStartedSending();
3283 if( startup_id.isEmpty())
3284 d->startup_id =
"0";
3287 d->startup_id = startup_id;
3288 #
if defined Q_WS_X11
3290 id.initId( startup_id );
3291 long timestamp =
id.timestamp();
3292 if( timestamp != 0 )
3300 void KApplication::read_app_startup_id()
3302 #if defined Q_WS_X11
3303 KStartupInfoId
id = KStartupInfo::currentStartupIdEnv();
3304 KStartupInfo::resetStartupEnv();
3305 d->startup_id =
id.id();
3311 static bool init =
false;
3316 int fd = open(
"/dev/urandom", O_RDONLY);
3317 if (fd < 0 || ::read(fd, &seed,
sizeof(seed)) !=
sizeof(seed))
3321 seed = rand()+time(0);
3323 if (fd >= 0) close(fd);
3331 if (length <=0 )
return TQString::null;
3333 TQString str; str.setLength( length );
3349 if (!d->actionRestrictions)
3359 if (!d->actionRestrictions || !action)
3364 return authorize(action_prefix + action);
3369 if (menuId.isEmpty() || kde_kiosk_exception)
3380 TQStringList result;
3381 for(TQStringList::ConstIterator it = menuIds.begin();
3382 it != menuIds.end(); ++it)
3390 void KApplication::initUrlActionRestrictions()
3392 d->urlActionRestrictions.setAutoDelete(
true);
3393 d->urlActionRestrictions.clear();
3394 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3395 (
"open", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null,
true));
3396 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3397 (
"list", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null, TQString::null,
true));
3403 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3404 (
"link", TQString::null, TQString::null, TQString::null,
":internet", TQString::null, TQString::null,
true));
3405 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3406 (
"redirect", TQString::null, TQString::null, TQString::null,
":internet", TQString::null, TQString::null,
true));
3410 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3411 (
"redirect", TQString::null, TQString::null, TQString::null,
"file", TQString::null, TQString::null,
true));
3412 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3413 (
"redirect",
":internet", TQString::null, TQString::null,
"file", TQString::null, TQString::null,
false));
3416 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3417 (
"redirect",
":local", TQString::null, TQString::null, TQString::null, TQString::null, TQString::null,
true));
3420 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3421 (
"redirect", TQString::null, TQString::null, TQString::null,
"about", TQString::null, TQString::null,
true));
3424 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3425 (
"redirect", TQString::null, TQString::null, TQString::null,
"=", TQString::null, TQString::null,
true));
3430 TQString keyFormat = TQString(
"rule_%1");
3431 for(
int i = 1; i <= count; i++)
3433 TQString key = keyFormat.arg(i);
3435 if (rule.count() != 8)
3437 TQString action = rule[0];
3438 TQString refProt = rule[1];
3439 TQString refHost = rule[2];
3440 TQString refPath = rule[3];
3441 TQString urlProt = rule[4];
3442 TQString urlHost = rule[5];
3443 TQString urlPath = rule[6];
3444 TQString strEnabled = rule[7].lower();
3446 bool bEnabled = (strEnabled ==
"true");
3448 if (refPath.startsWith(
"$HOME"))
3449 refPath.replace(0, 5, TQDir::homeDirPath());
3450 else if (refPath.startsWith(
"~"))
3451 refPath.replace(0, 1, TQDir::homeDirPath());
3452 if (urlPath.startsWith(
"$HOME"))
3453 urlPath.replace(0, 5, TQDir::homeDirPath());
3454 else if (urlPath.startsWith(
"~"))
3455 urlPath.replace(0, 1, TQDir::homeDirPath());
3457 if (refPath.startsWith(
"$TMP"))
3459 if (urlPath.startsWith(
"$TMP"))
3462 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3463 ( action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled));
3472 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
3482 bool result =
false;
3483 if (d->urlActionRestrictions.isEmpty())
3484 initUrlActionRestrictions();
3486 KURL baseURL(_baseURL);
3487 baseURL.
setPath(TQDir::cleanDirPath(baseURL.
path()));
3488 TQString baseClass = KProtocolInfo::protocolClass(baseURL.
protocol());
3489 KURL destURL(_destURL);
3490 destURL.setPath(TQDir::cleanDirPath(destURL.path()));
3491 TQString destClass = KProtocolInfo::protocolClass(destURL.protocol());
3493 for(KApplicationPrivate::URLActionRule *rule = d->urlActionRestrictions.first();
3494 rule; rule = d->urlActionRestrictions.next())
3496 if ((result != rule->permission) &&
3497 (action == rule->action) &&
3498 rule->baseMatch(baseURL, baseClass) &&
3499 rule->destMatch(destURL, destClass, baseURL, baseClass))
3501 result = rule->permission;
3513 int root_x, root_y, win_x, win_y;
3515 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
3516 &root_x, &root_y, &win_x, &win_y, &keybstate );
3517 return keybstate & 0x00ff;
3518 #elif defined W_WS_MACX
3519 return GetCurrentEventKeyModifiers() & 0x00ff;
3532 int root_x, root_y, win_x, win_y;
3533 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
3534 &root_x, &root_y, &win_x, &win_y, &mousestate );
3535 #elif defined(Q_WS_WIN)
3536 const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON);
3537 if (GetAsyncKeyState(VK_LBUTTON))
3538 mousestate |= (mousebtn_swapped ? Button3Mask : Button1Mask);
3539 if (GetAsyncKeyState(VK_MBUTTON))
3540 mousestate |= Button2Mask;
3541 if (GetAsyncKeyState(VK_RBUTTON))
3542 mousestate |= (mousebtn_swapped ? Button1Mask : Button3Mask);
3543 #elif defined(Q_WS_MACX)
3544 mousestate = GetCurrentEventButtonState();
3548 return mousestate & 0xff00;
3557 int root_x, root_y, win_x, win_y;
3559 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
3560 &root_x, &root_y, &win_x, &win_y, &state );
3562 if( state & Button1Mask )
3563 ret |= TQ_LeftButton;
3564 if( state & Button2Mask )
3565 ret |= TQ_MidButton;
3566 if( state & Button3Mask )
3567 ret |= TQ_RightButton;
3568 if( state & ShiftMask )
3569 ret |= TQ_ShiftButton;
3570 if( state & ControlMask )
3571 ret |= TQ_ControlButton;
3572 if( state & KKeyNative::modX( KKey::ALT ))
3573 ret |= TQ_AltButton;
3574 if( state & KKeyNative::modX( KKey::WIN ))
3575 ret |= TQ_MetaButton;
3576 #elif defined(Q_WS_WIN)
3577 const bool mousebtn_swapped = GetSystemMetrics(SM_SWAPBUTTON);
3578 if (GetAsyncKeyState(VK_LBUTTON))
3579 ret |= (mousebtn_swapped ? RightButton : LeftButton);
3580 if (GetAsyncKeyState(VK_MBUTTON))
3581 ret |= TQ_MidButton;
3582 if (GetAsyncKeyState(VK_RBUTTON))
3583 ret |= (mousebtn_swapped ? TQ_LeftButton : TQ_RightButton);
3584 if (GetAsyncKeyState(VK_SHIFT))
3585 ret |= TQ_ShiftButton;
3586 if (GetAsyncKeyState(VK_CONTROL))
3587 ret |= TQ_ControlButton;
3588 if (GetAsyncKeyState(VK_MENU))
3589 ret |= TQ_AltButton;
3590 if (GetAsyncKeyState(VK_LWIN) || GetAsyncKeyState(VK_RWIN))
3591 ret |= TQ_MetaButton;
3595 return static_cast< ButtonState
>( ret );
3601 struct sigaction act;
3602 act.sa_handler = SIG_IGN;
3603 sigemptyset( &act.sa_mask );
3605 sigaction( SIGPIPE, &act, 0 );
3609 void KApplication::sigpipeHandler(
int)
3611 int saved_errno = errno;
3615 sprintf(msg,
"*** SIGPIPE *** (ignored, pid = %ld)\n", (
long) getpid());
3616 if (write(2, msg, strlen(msg)) < 0) {
3622 errno = saved_errno;
3625 bool KApplication::guiEnabled()
3627 return kapp && kapp->d->guiEnabled;
3630 void KApplication::virtual_hook(
int id,
void* data )
3631 { KInstance::virtual_hook(
id, data ); }
3633 void KSessionManaged::virtual_hook(
int,
void* )
3636 #include "kapplication.moc"