00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#include "config.h"
00024
00025
#undef QT_NO_TRANSLATION
00026
#include <qtranslator.h>
00027
#define QT_NO_TRANSLATION
00028
#include <qdir.h>
00029
#include <qptrcollection.h>
00030
#include <qwidgetlist.h>
00031
#include <qstrlist.h>
00032
#include <qfile.h>
00033
#include <qmessagebox.h>
00034
#include <qtextstream.h>
00035
#include <qregexp.h>
00036
#include <qlineedit.h>
00037
#include <qtextedit.h>
00038
#include <qsessionmanager.h>
00039
#include <qptrlist.h>
00040
#include <qtimer.h>
00041
#include <qstylesheet.h>
00042
#include <qpixmapcache.h>
00043
#include <qtooltip.h>
00044
#include <qstylefactory.h>
00045
#include <qmetaobject.h>
00046
#ifndef QT_NO_SQL
00047
#include <qsqlpropertymap.h>
00048
#endif
00049
00050
#undef QT_NO_TRANSLATION
00051
#include "kapplication.h"
00052
#define QT_NO_TRANSLATION
00053
#include <kglobal.h>
00054
#include <kstandarddirs.h>
00055
#include <kdebug.h>
00056
#include <klocale.h>
00057
#include <kstyle.h>
00058
#include <kiconloader.h>
00059
#include <kclipboard.h>
00060
#include <kconfig.h>
00061
#include <ksimpleconfig.h>
00062
#include <kcmdlineargs.h>
00063
#include <kaboutdata.h>
00064
#include <kglobalsettings.h>
00065
#include <kcrash.h>
00066
#include <kdatastream.h>
00067
#include <klibloader.h>
00068
#include <kmimesourcefactory.h>
00069
#include <kstdaccel.h>
00070
#include <kaccel.h>
00071
#include "kcheckaccelerators.h"
00072
#include <qptrdict.h>
00073
#include <kmacroexpander.h>
00074
#include <kshell.h>
00075
#include <kprotocolinfo.h>
00076
00077
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
00078
#include <kstartupinfo.h>
00079
#endif
00080
00081
#include <dcopclient.h>
00082
#include <dcopref.h>
00083
00084
#include <sys/types.h>
00085
#ifdef HAVE_SYS_STAT_H
00086
#include <sys/stat.h>
00087
#endif
00088
#include <sys/wait.h>
00089
00090
#include "kwin.h"
00091
00092
#include <fcntl.h>
00093
#include <stdlib.h>
00094
#include <signal.h>
00095
#include <unistd.h>
00096
#include <time.h>
00097
#include <sys/time.h>
00098
#include <errno.h>
00099
#include <string.h>
00100
#include <netdb.h>
00101
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
00102
00103
#include <netwm.h>
00104
#endif
00105
00106
#include "kprocctrl.h"
00107
00108
#ifdef HAVE_PATHS_H
00109
#include <paths.h>
00110
#endif
00111
00112
00113
#ifdef Q_WS_X11
00114
#include <X11/Xlib.h>
00115
#include <X11/Xutil.h>
00116
#include <X11/Xatom.h>
00117
#include <X11/SM/SMlib.h>
00118
#include <fixx11h.h>
00119
#endif
00120
#include <KDE-ICE/ICElib.h>
00121
00122
#ifdef Q_WS_X11
00123
#define DISPLAY "DISPLAY"
00124
#elif defined(Q_WS_QWS)
00125
#define DISPLAY "QWS_DISPLAY"
00126
#endif
00127
00128
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
00129
#include <kipc.h>
00130
#endif
00131
00132
#include "kappdcopiface.h"
00133
00134
bool kde_have_kipc =
true;
00135
bool kde_kiosk_exception =
false;
00136
bool kde_kiosk_admin =
false;
00137
00138 KApplication*
KApplication::KApp = 0L;
00139
bool KApplication::loadedByKdeinit =
false;
00140
DCOPClient *KApplication::s_DCOPClient = 0L;
00141
bool KApplication::s_dcopClientNeedsPostInit =
false;
00142
00143
static Atom atom_DesktopWindow;
00144
static Atom atom_NetSupported;
00145
#if KDE_IS_VERSION( 3, 2, 91 )
00146
#warning Obsolete, remove.
00147
00148
#endif
00149
static Atom atom_KdeNetUserTime;
00150
static Atom kde_net_wm_user_time = 0;
00151
#if KDE_IS_VERSION( 3, 2, 91 )
00152
#warning This should be in Qt already, check.
00153
00154
#endif
00155
Time qt_x_user_time = CurrentTime;
00156
extern Time qt_x_time;
00157
static Atom kde_xdnd_drop;
00158
00159
00160
00161
bool qt_qclipboard_bailout_hack =
false;
00162
00163
template class QPtrList<KSessionManaged>;
00164
00165
#ifdef Q_WS_X11
00166
extern "C" {
00167
static int kde_xio_errhandler( Display * dpy )
00168 {
00169
return kapp->xioErrhandler( dpy );
00170 }
00171
00172
static int kde_x_errhandler( Display *dpy, XErrorEvent *err )
00173 {
00174
return kapp->xErrhandler( dpy, err );
00175 }
00176
00177 }
00178
#endif
00179
00180
extern "C" {
00181
static void kde_ice_ioerrorhandler( IceConn conn )
00182 {
00183
if(kapp)
00184 kapp->iceIOErrorHandler( conn );
00185
00186 }
00187 }
00188
00189
00190
00191
00192
class KApplicationPrivate
00193 {
00194
public:
00195 KApplicationPrivate()
00196 : actionRestrictions( false ),
00197 refCount( 1 ),
00198 oldIceIOErrorHandler( 0 ),
00199 checkAccelerators( 0 ),
00200 overrideStyle(
QString::null ),
00201 startup_id( "0" ),
00202 app_started_timer( NULL ),
00203 m_KAppDCOPInterface( 0L ),
00204 session_save( false ),
00205 oldXErrorHandler( NULL ),
00206 oldXIOErrorHandler( NULL )
00207 {
00208 }
00209
00210 ~KApplicationPrivate()
00211 {}
00212
00213
00214
bool actionRestrictions : 1;
00215
bool guiEnabled : 1;
00222
int refCount;
00223 IceIOErrorHandler oldIceIOErrorHandler;
00224 KCheckAccelerators* checkAccelerators;
00225
QString overrideStyle;
00226
QString geometry_arg;
00227
QCString startup_id;
00228
QTimer* app_started_timer;
00229
KAppDCOPInterface *m_KAppDCOPInterface;
00230
bool session_save;
00231 int (*oldXErrorHandler)(Display*,XErrorEvent*);
00232 int (*oldXIOErrorHandler)(Display*);
00233
00234
class URLActionRule
00235 {
00236
public:
00237
#define checkExactMatch(s, b) \
00238
if (s.isEmpty()) b = true; \
00239
else if (s[s.length()-1] == '!') \
00240
{ b = false; s.truncate(s.length()-1); } \
00241
else b = true;
00242
#define checkStartWildCard(s, b) \
00243
if (s.isEmpty()) b = true; \
00244
else if (s[0] == '*') \
00245
{ b = true; s = s.mid(1); } \
00246
else b = false;
00247
#define checkEqual(s, b) \
00248
b = (s == "=");
00249
00250 URLActionRule(
const QString &act,
00251
const QString &bProt,
const QString &bHost,
const QString &bPath,
00252
const QString &dProt,
const QString &dHost,
const QString &dPath,
00253
bool perm)
00254 :
action(act),
00255 baseProt(bProt), baseHost(bHost), basePath(bPath),
00256 destProt(dProt), destHost(dHost), destPath(dPath),
00257 permission(perm)
00258 {
00259 checkExactMatch(baseProt, baseProtWildCard);
00260 checkStartWildCard(baseHost, baseHostWildCard);
00261 checkExactMatch(basePath, basePathWildCard);
00262 checkExactMatch(destProt, destProtWildCard);
00263 checkStartWildCard(destHost, destHostWildCard);
00264 checkExactMatch(destPath, destPathWildCard);
00265 checkEqual(destProt, destProtEqual);
00266 checkEqual(destHost, destHostEqual);
00267 }
00268
00269
bool baseMatch(
const KURL &url,
const QString &protClass)
00270 {
00271
if (baseProtWildCard)
00272 {
00273
if ( !baseProt.isEmpty() && !url.
protocol().startsWith(baseProt) &&
00274 (protClass.isEmpty() || (protClass != baseProt)) )
00275
return false;
00276 }
00277
else
00278 {
00279
if ( (url.
protocol() != baseProt) &&
00280 (protClass.isEmpty() || (protClass != baseProt)) )
00281
return false;
00282 }
00283
if (baseHostWildCard)
00284 {
00285
if (!baseHost.isEmpty() && !url.
host().endsWith(baseHost))
00286
return false;
00287 }
00288
else
00289 {
00290
if (url.
host() != baseHost)
00291
return false;
00292 }
00293
if (basePathWildCard)
00294 {
00295
if (!basePath.isEmpty() && !url.
path().startsWith(basePath))
00296
return false;
00297 }
00298
else
00299 {
00300
if (url.
path() != basePath)
00301
return false;
00302 }
00303
return true;
00304 }
00305
00306
bool destMatch(
const KURL &url,
const QString &protClass,
const KURL &base,
const QString &baseClass)
00307 {
00308
if (destProtEqual)
00309 {
00310
if ( (url.
protocol() != base.
protocol()) &&
00311 (protClass.isEmpty() || baseClass.isEmpty() || protClass != baseClass) )
00312
return false;
00313 }
00314
else if (destProtWildCard)
00315 {
00316
if ( !destProt.isEmpty() && !url.
protocol().startsWith(destProt) &&
00317 (protClass.isEmpty() || (protClass != destProt)) )
00318
return false;
00319 }
00320
else
00321 {
00322
if ( (url.
protocol() != destProt) &&
00323 (protClass.isEmpty() || (protClass != destProt)) )
00324
return false;
00325 }
00326
if (destHostWildCard)
00327 {
00328
if (!destHost.isEmpty() && !url.
host().endsWith(destHost))
00329
return false;
00330 }
00331
else if (destHostEqual)
00332 {
00333
if (url.
host() != base.
host())
00334
return false;
00335 }
00336
else
00337 {
00338
if (url.
host() != destHost)
00339
return false;
00340 }
00341
if (destPathWildCard)
00342 {
00343
if (!destPath.isEmpty() && !url.
path().startsWith(destPath))
00344
return false;
00345 }
00346
else
00347 {
00348
if (url.
path() != destPath)
00349
return false;
00350 }
00351
return true;
00352 }
00353
00354
QString action;
00355
QString baseProt;
00356
QString baseHost;
00357
QString basePath;
00358
QString destProt;
00359
QString destHost;
00360
QString destPath;
00361
bool baseProtWildCard : 1;
00362
bool baseHostWildCard : 1;
00363
bool basePathWildCard : 1;
00364
bool destProtWildCard : 1;
00365
bool destHostWildCard : 1;
00366
bool destPathWildCard : 1;
00367
bool destProtEqual : 1;
00368
bool destHostEqual : 1;
00369
bool permission;
00370 };
00371
QPtrList<URLActionRule> urlActionRestrictions;
00372
00373
QString sessionKey;
00374
QString pSessionConfigFile;
00375 };
00376
00377
00378
static QPtrList<QWidget>*x11Filter = 0;
00379
static bool autoDcopRegistration =
true;
00380
00381 void KApplication::installX11EventFilter(
QWidget* filter )
00382 {
00383
if ( !filter )
00384
return;
00385
if (!x11Filter)
00386 x11Filter =
new QPtrList<QWidget>;
00387 connect ( filter, SIGNAL( destroyed() ),
this, SLOT( x11FilterDestroyed() ) );
00388 x11Filter->append( filter );
00389 }
00390
00391
void KApplication::x11FilterDestroyed()
00392 {
00393 removeX11EventFilter( static_cast< const QWidget* >( sender()));
00394 }
00395
00396 void KApplication::removeX11EventFilter(
const QWidget* filter )
00397 {
00398
if ( !x11Filter || !filter )
00399
return;
00400 x11Filter->removeRef( filter );
00401
if ( x11Filter->isEmpty() ) {
00402
delete x11Filter;
00403 x11Filter = 0;
00404 }
00405 }
00406
00407
00408
00409
00410
00411
extern bool kde_g_bKillAccelOverride;
00412
00413
bool KApplication::notify(
QObject *receiver,
QEvent *event)
00414 {
00415 QEvent::Type t = event->type();
00416
if (kde_g_bKillAccelOverride)
00417 {
00418 kde_g_bKillAccelOverride =
false;
00419
00420
if (t == QEvent::AccelOverride)
00421 {
00422 static_cast<QKeyEvent *>(event)->accept();
00423
return true;
00424 }
00425
else
00426 kdWarning(125) <<
"kde_g_bKillAccelOverride set, but received an event other than AccelOverride." <<
endl;
00427 }
00428
00429
if ((t == QEvent::AccelOverride) || (t == QEvent::KeyPress))
00430 {
00431
static const KShortcut& _selectAll =
KStdAccel::selectAll();
00432
if (receiver && receiver->inherits(
"QLineEdit"))
00433 {
00434
QLineEdit *edit = static_cast<QLineEdit *>(receiver);
00435
00436
QKeyEvent *kevent = static_cast<QKeyEvent *>(
event);
00437
KKey key(kevent);
00438
if (_selectAll.
contains(key))
00439 {
00440
if (t == QEvent::KeyPress)
00441 {
00442 edit->selectAll();
00443
return true;
00444 }
00445
else
00446 {
00447 kevent->accept();
00448 }
00449 }
00450
00451
if (
key ==
KKey(Qt::CTRL + Qt::Key_U))
00452 {
00453
if (t == QEvent::KeyPress)
00454 {
00455
if (!edit->isReadOnly())
00456 {
00457
QString t(edit->text());
00458 t = t.mid(edit->cursorPosition());
00459 edit->validateAndSet(t, 0, 0, 0);
00460 }
00461
return true;
00462 }
00463
else
00464 {
00465 kevent->accept();
00466 }
00467
00468 }
00469 }
00470
if (receiver && receiver->inherits(
"QTextEdit"))
00471 {
00472
QTextEdit *medit = static_cast<QTextEdit *>(receiver);
00473
00474
QKeyEvent *kevent = static_cast<QKeyEvent *>(
event);
00475
if (_selectAll.
contains(
KKey(kevent)))
00476 {
00477
if (t == QEvent::KeyPress)
00478 {
00479 medit->selectAll();
00480
return true;
00481 }
00482
else
00483 {
00484 kevent->accept();
00485 }
00486 }
00487 }
00488 }
00489
if(
event->type() == QEvent::Show && receiver->isWidgetType())
00490 {
00491
QWidget* w = static_cast< QWidget* >( receiver );
00492
if( w->isTopLevel() && !
startupId().isEmpty())
00493
KStartupInfo::setWindowStartupId( w->winId(),
startupId());
00494
if( w->isTopLevel() && qt_x_user_time != CurrentTime )
00495 XChangeProperty( qt_xdisplay(), w->winId(), kde_net_wm_user_time, XA_CARDINAL,
00496 32, PropModeReplace, (
unsigned char*)&qt_x_user_time, 1 );
00497 }
00498
if(
event->type() == QEvent::Show && receiver->isWidgetType())
00499 {
00500
QWidget* w = static_cast< QWidget* >( receiver );
00501
if( w->isTopLevel() && !w->testWFlags( WX11BypassWM ) && !w->isPopup() && !
event->spontaneous())
00502 {
00503
if( d->app_started_timer == NULL )
00504 {
00505 d->app_started_timer =
new QTimer(
this );
00506 connect( d->app_started_timer, SIGNAL( timeout()), SLOT( checkAppStartedSlot()));
00507 }
00508
if( !d->app_started_timer->isActive())
00509 d->app_started_timer->start( 0,
true );
00510 }
00511 }
00512
return QApplication::notify(receiver, event);
00513 }
00514
00515
void KApplication::checkAppStartedSlot()
00516 {
00517 KStartupInfo::handleAutoAppStartedSending();
00518 }
00519
00520
00521
static QPtrList<KSessionManaged>* sessionClients()
00522 {
00523
static QPtrList<KSessionManaged>* session_clients = 0L;
00524
if ( !session_clients )
00525 session_clients =
new QPtrList<KSessionManaged>;
00526
return session_clients;
00527 }
00528
00529
00530
00531
00532
00533
00534
QString KApplication::sessionConfigName()
const
00535
{
00536
#if QT_VERSION < 0x030100
00537
return QString(
"session/%1_%2_%3").arg(
name()).arg(sessionId()).arg(d->sessionKey);
00538
#else
00539
QString sessKey = sessionKey();
00540
if ( sessKey.isEmpty() && !d->sessionKey.isEmpty() )
00541 sessKey = d->sessionKey;
00542
return QString(
"session/%1_%2_%3").arg(
name()).arg(sessionId()).arg(sessKey);
00543
#endif
00544
}
00545
00546
#ifndef Q_WS_QWS
00547
static SmcConn mySmcConnection = 0;
00548
static SmcConn tmpSmcConnection = 0;
00549
#else
00550
00551
00552
#endif
00553
static QTime* smModificationTime = 0;
00554
00555 KApplication::KApplication(
int& argc,
char** argv,
const QCString& rAppName,
00556
bool allowStyles,
bool GUIenabled ) :
00557
QApplication( argc, argv, GUIenabled ),
KInstance(rAppName),
00558 #ifdef Q_WS_X11
00559 display(0L),
00560 #endif
00561 d (new KApplicationPrivate())
00562 {
00563 read_app_startup_id();
00564
if (!GUIenabled)
00565 allowStyles =
false;
00566 useStyles = allowStyles;
00567 Q_ASSERT (!rAppName.isEmpty());
00568 setName(rAppName);
00569
00570
installSigpipeHandler();
00571 KCmdLineArgs::initIgnore(argc, argv, rAppName.data());
00572 parseCommandLine( );
00573 init(GUIenabled);
00574 d->m_KAppDCOPInterface =
new KAppDCOPInterface(
this);
00575 }
00576
00577 KApplication::KApplication(
bool allowStyles,
bool GUIenabled ) :
00578
QApplication( *
KCmdLineArgs::qt_argc(), *
KCmdLineArgs::qt_argv(),
00579 GUIenabled ),
00580
KInstance(
KCmdLineArgs::about),
00581 #ifdef Q_WS_X11
00582 display(0L),
00583 #endif
00584 d (new KApplicationPrivate)
00585 {
00586 read_app_startup_id();
00587
if (!GUIenabled)
00588 allowStyles =
false;
00589 useStyles = allowStyles;
00590 setName(
instanceName() );
00591
00592
installSigpipeHandler();
00593 parseCommandLine( );
00594 init(GUIenabled);
00595 d->m_KAppDCOPInterface =
new KAppDCOPInterface(
this);
00596 }
00597
00598 KApplication::KApplication(
bool allowStyles,
bool GUIenabled,
KInstance* _instance ) :
00599
QApplication( *
KCmdLineArgs::qt_argc(), *
KCmdLineArgs::qt_argv(),
00600 GUIenabled ),
00601
KInstance( _instance ),
00602 #ifdef Q_WS_X11
00603 display(0L),
00604 #endif
00605 d (new KApplicationPrivate)
00606 {
00607 read_app_startup_id();
00608
if (!GUIenabled)
00609 allowStyles =
false;
00610 useStyles = allowStyles;
00611 setName(
instanceName() );
00612
00613
installSigpipeHandler();
00614 parseCommandLine( );
00615 init(GUIenabled);
00616 d->m_KAppDCOPInterface =
new KAppDCOPInterface(
this);
00617 }
00618
00619
#ifdef Q_WS_X11
00620
KApplication::KApplication(Display *display,
int& argc,
char** argv,
const QCString& rAppName,
00621
bool allowStyles,
bool GUIenabled ) :
00622
QApplication( display ),
KInstance(rAppName),
00623 display(0L),
00624 d (new KApplicationPrivate())
00625 {
00626 read_app_startup_id();
00627
if (!GUIenabled)
00628 allowStyles =
false;
00629 useStyles = allowStyles;
00630
00631 Q_ASSERT (!rAppName.isEmpty());
00632 setName(rAppName);
00633
00634
installSigpipeHandler();
00635 KCmdLineArgs::initIgnore(argc, argv, rAppName.data());
00636 parseCommandLine( );
00637 init(GUIenabled);
00638 d->m_KAppDCOPInterface =
new KAppDCOPInterface(
this);
00639 }
00640
#endif
00641
00642
int KApplication::xioErrhandler( Display* dpy )
00643 {
00644
if(kapp)
00645 {
00646 emit
shutDown();
00647 d->oldXIOErrorHandler( dpy );
00648 }
00649 exit( 1 );
00650
return 0;
00651 }
00652
00653
int KApplication::xErrhandler( Display* dpy,
void* err_ )
00654 {
00655 XErrorEvent* err = static_cast< XErrorEvent* >( err_ );
00656
if(kapp)
00657 {
00658
00659 d->oldXErrorHandler( dpy, err );
00660 }
00661
return 0;
00662 }
00663
00664
void KApplication::iceIOErrorHandler( _IceConn *conn )
00665 {
00666 emit
shutDown();
00667
00668
if ( d->oldIceIOErrorHandler != NULL )
00669 (*d->oldIceIOErrorHandler)( conn );
00670
00671 exit( 1 );
00672 }
00673
00674
class KDETranslator :
public QTranslator
00675 {
00676
public:
00677 KDETranslator(
QObject *parent) :
QTranslator(parent, "kdetranslator") {}
00678
virtual QTranslatorMessage findMessage(
const char* context,
00679
const char *sourceText,
00680
const char* message)
const
00681
{
00682
QTranslatorMessage res;
00683 res.setTranslation(KGlobal::locale()->translateQt(context, sourceText, message));
00684
return res;
00685 }
00686 };
00687
00688
void KApplication::init(
bool GUIenabled)
00689 {
00690 d->guiEnabled = GUIenabled;
00691
if ((getuid() != geteuid()) ||
00692 (getgid() != getegid()))
00693 {
00694 fprintf(stderr,
"The KDE libraries are not designed to run with suid privileges.\n");
00695 ::exit(127);
00696 }
00697
00698
KProcessController::ref();
00699
00700 (
void)
KClipboardSynchronizer::self();
00701
00702 QApplication::setDesktopSettingsAware(
false );
00703
00704
KApp =
this;
00705
00706
00707
#ifdef Q_WS_X11 //FIXME(E)
00708
00709
if ( GUIenabled ) {
00710
const int max = 20;
00711 Atom* atoms[max];
00712
char* names[max];
00713 Atom atoms_return[max];
00714
int n = 0;
00715
00716 atoms[n] = &kipcCommAtom;
00717 names[n++] = (
char *)
"KIPC_COMM_ATOM";
00718
00719 atoms[n] = &atom_DesktopWindow;
00720 names[n++] = (
char *)
"KDE_DESKTOP_WINDOW";
00721
00722 atoms[n] = &atom_NetSupported;
00723 names[n++] = (
char *)
"_NET_SUPPORTED";
00724
00725 atoms[n] = &atom_KdeNetUserTime;
00726 names[n++] = (
char *)
"_KDE_NET_USER_TIME";
00727
00728 atoms[n] = &kde_net_wm_user_time;
00729 names[n++] = (
char *)
"_NET_WM_USER_TIME";
00730
00731 atoms[n] = &kde_xdnd_drop;
00732 names[n++] = (
char *)
"XdndDrop";
00733
00734 XInternAtoms( qt_xdisplay(), names, n,
false, atoms_return );
00735
00736
for (
int i = 0; i < n; i++ )
00737 *atoms[i] = atoms_return[i];
00738 }
00739
#endif
00740
00741 dcopAutoRegistration();
00742 dcopClientPostInit();
00743
00744 smw = 0;
00745
00746
00747
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
00748
kipcEventMask = (1 << KIPC::StyleChanged) | (1 << KIPC::PaletteChanged) |
00749 (1 << KIPC::FontChanged) | (1 << KIPC::BackgroundChanged) |
00750 (1 << KIPC::ToolbarStyleChanged) | (1 << KIPC::SettingsChanged) |
00751 (1 << KIPC::ClipboardConfigChanged);
00752
#endif
00753
00754
00755 (
void)
KGlobal::locale();
00756
00757
KConfig*
config =
KGlobal::config();
00758 d->actionRestrictions = config->
hasGroup(
"KDE Action Restrictions" ) && !kde_kiosk_exception;
00759
00760
00761
00762
00763
QCString readOnly = getenv(
"KDE_HOME_READONLY");
00764
if (readOnly.isEmpty() && (qstrcmp(
name(),
"kdialog") != 0))
00765 {
00766
KConfigGroupSaver saver(config,
"KDE Action Restrictions");
00767
if (config->
readBoolEntry(
"warn_unwritable_config",
true))
00768 config->
checkConfigFilesWritable(
true);
00769 }
00770
00771
if (GUIenabled)
00772 {
00773
#ifdef Q_WS_X11
00774
00775 fcntl(ConnectionNumber(qt_xdisplay()), F_SETFD, FD_CLOEXEC);
00776
00777 d->oldXErrorHandler = XSetErrorHandler( kde_x_errhandler );
00778 d->oldXIOErrorHandler = XSetIOErrorHandler( kde_xio_errhandler );
00779
#endif
00780
00781 connect(
this, SIGNAL( aboutToQuit() ),
this, SIGNAL(
shutDown() ) );
00782
00783
#ifdef Q_WS_X11 //FIXME(E)
00784
display = desktop()->x11Display();
00785
#endif
00786
00787 {
00788
QStringList plugins =
KGlobal::dirs()->
resourceDirs(
"qtplugins" );
00789 QStringList::Iterator it = plugins.begin();
00790
while (it != plugins.end()) {
00791 addLibraryPath( *it );
00792 ++it;
00793 }
00794
00795 }
00796 kdisplaySetStyle();
00797 kdisplaySetFont();
00798
00799 propagateSettings(SETTINGS_QT);
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
QMimeSourceFactory* oldDefaultFactory = QMimeSourceFactory::takeDefaultFactory();
00810 QMimeSourceFactory::setDefaultFactory(
mimeSourceFactory() );
00811
if ( oldDefaultFactory ) {
00812 QMimeSourceFactory::addFactory( oldDefaultFactory );
00813 }
00814
00815
KConfigGroupSaver saver( config,
"Development" );
00816
if( config->
hasKey(
"CheckAccelerators" ) || config->
hasKey(
"AutoCheckAccelerators" ))
00817 d->checkAccelerators =
new KCheckAccelerators(
this );
00818 }
00819
00820
00821
00822
bool rtl = reverseLayout();
00823 installTranslator(
new KDETranslator(
this));
00824 setReverseLayout( rtl );
00825
if (i18n(
"_: Dear Translator! Translate this string to the string 'LTR' in "
00826
"left-to-right languages (as english) or to 'RTL' in right-to-left "
00827
"languages (such as Hebrew and Arabic) to get proper widget layout." ) ==
"RTL")
00828 setReverseLayout( !rtl );
00829
00830
00831
KGlobal::dirs()->
addResourceType(
"appdata", KStandardDirs::kde_default(
"data")
00832 + QString::fromLatin1(
name()) +
'/');
00833 pSessionConfig = 0L;
00834 bSessionManagement =
true;
00835
00836
#ifdef Q_WS_X11
00837
00838
if (GUIenabled && kde_have_kipc )
00839 {
00840 smw =
new QWidget(0,0);
00841
long data = 1;
00842 XChangeProperty(qt_xdisplay(), smw->winId(),
00843 atom_DesktopWindow, atom_DesktopWindow,
00844 32, PropModeReplace, (
unsigned char *)&data, 1);
00845 }
00846
#else
00847
00848
#endif
00849
00850 d->oldIceIOErrorHandler = IceSetIOErrorHandler( kde_ice_ioerrorhandler );
00851 }
00852
00853
static int my_system (
const char *command) {
00854
int pid, status;
00855
00856 QApplication::flushX();
00857 pid = fork();
00858
if (pid == -1)
00859
return -1;
00860
if (pid == 0) {
00861
const char* shell =
"/bin/sh";
00862 execl(shell, shell,
"-c", command, (
void *)0);
00863 ::exit(127);
00864 }
00865
do {
00866
if (waitpid(pid, &status, 0) == -1) {
00867
if (errno != EINTR)
00868
return -1;
00869 }
else
00870
return status;
00871 }
while(1);
00872 }
00873
00874
00875 DCOPClient *
KApplication::dcopClient()
00876 {
00877
if (s_DCOPClient)
00878
return s_DCOPClient;
00879
00880 s_DCOPClient =
new DCOPClient();
00881
KCmdLineArgs *args = KCmdLineArgs::parsedArgs(
"kde");
00882
if (args && args->
isSet(
"dcopserver"))
00883 {
00884 s_DCOPClient->
setServerAddress( args->
getOption(
"dcopserver"));
00885 }
00886
if( kapp ) {
00887 connect(s_DCOPClient, SIGNAL(attachFailed(
const QString &)),
00888 kapp, SLOT(dcopFailure(
const QString &)));
00889 connect(s_DCOPClient, SIGNAL(blockUserInput(
bool) ),
00890 kapp, SLOT(dcopBlockUserInput(
bool)) );
00891 }
00892
else
00893 s_dcopClientNeedsPostInit =
true;
00894
00895 DCOPClient::setMainClient( s_DCOPClient );
00896
return s_DCOPClient;
00897 }
00898
00899
void KApplication::dcopClientPostInit()
00900 {
00901
if( s_dcopClientNeedsPostInit )
00902 {
00903 s_dcopClientNeedsPostInit =
false;
00904 connect(s_DCOPClient, SIGNAL(blockUserInput(
bool) ),
00905 SLOT(dcopBlockUserInput(
bool)) );
00906 s_DCOPClient->
bindToApp();
00907 }
00908 }
00909
00910
void KApplication::dcopAutoRegistration()
00911 {
00912
if (autoDcopRegistration)
00913 {
00914 (
void )
dcopClient();
00915
if(
dcopClient()->
appId().isEmpty())
00916
dcopClient()->
registerAs(
name());
00917 }
00918 }
00919
00920 void KApplication::disableAutoDcopRegistration()
00921 {
00922 autoDcopRegistration =
false;
00923 }
00924
00925 KConfig*
KApplication::sessionConfig()
00926 {
00927
if (pSessionConfig)
00928
return pSessionConfig;
00929
00930
00931 pSessionConfig =
new KConfig( sessionConfigName(),
false,
false);
00932
return pSessionConfig;
00933 }
00934
00935 void KApplication::ref()
00936 {
00937 d->refCount++;
00938
00939 }
00940
00941 void KApplication::deref()
00942 {
00943 d->refCount--;
00944
00945
if ( d->refCount <= 0 )
00946 quit();
00947 }
00948
00949 KSessionManaged::KSessionManaged()
00950 {
00951 sessionClients()->remove(
this );
00952 sessionClients()->append(
this );
00953 }
00954
00955 KSessionManaged::~KSessionManaged()
00956 {
00957 sessionClients()->remove(
this );
00958 }
00959
00960 bool KSessionManaged::saveState(
QSessionManager&)
00961 {
00962
return true;
00963 }
00964
00965 bool KSessionManaged::commitData(
QSessionManager&)
00966 {
00967
return true;
00968 }
00969
00970
00971 void KApplication::disableSessionManagement() {
00972 bSessionManagement =
false;
00973 }
00974
00975 void KApplication::enableSessionManagement() {
00976 bSessionManagement =
true;
00977
00978
00979
00980
00981
00982
00983
00984
00985
00986
if( mySmcConnection ) {
00987 SmcRequestSaveYourself( mySmcConnection, SmSaveLocal, False,
00988 SmInteractStyleAny,
00989 False, False );
00990
00991
00992 IceFlush(SmcGetIceConnection(mySmcConnection));
00993 }
00994 }
00995
00996
00997 bool KApplication::requestShutDown(
00998 ShutdownConfirm confirm, ShutdownType sdtype, ShutdownMode sdmode )
00999 {
01000
#ifdef Q_WS_X11
01001
QApplication::syncX();
01002
01003
if ( confirm ==
ShutdownConfirmYes ||
01004 sdtype !=
ShutdownTypeDefault ||
01005 sdmode !=
ShutdownModeDefault )
01006 {
01007
QByteArray data;
01008
QDataStream arg(data, IO_WriteOnly);
01009 arg << (
int)confirm << (
int)sdtype << (
int)sdmode;
01010
return dcopClient()->
send(
"ksmserver",
"ksmserver",
01011
"logout(int,int,int)", data );
01012 }
01013
01014
if ( mySmcConnection ) {
01015
01016 SmcRequestSaveYourself( mySmcConnection, SmSaveBoth, True,
01017 SmInteractStyleAny,
01018 confirm ==
ShutdownConfirmNo, True );
01019
01020
01021 IceFlush(SmcGetIceConnection(mySmcConnection));
01022
return true;
01023 }
01024
01025
01026
01027
propagateSessionManager();
01028
QCString smEnv = ::getenv(
"SESSION_MANAGER");
01029
if (smEnv.isEmpty())
01030
return false;
01031
01032
if (! tmpSmcConnection) {
01033
char cerror[256];
01034
char* myId = 0;
01035
char* prevId = 0;
01036 SmcCallbacks cb;
01037 tmpSmcConnection = SmcOpenConnection( 0, 0, 1, 0,
01038 0, &cb,
01039 prevId,
01040 &myId,
01041 255,
01042 cerror );
01043 ::free( myId );
01044
if (!tmpSmcConnection )
01045
return false;
01046 }
01047
01048 SmcRequestSaveYourself( tmpSmcConnection, SmSaveBoth, True,
01049 SmInteractStyleAny, False, True );
01050
01051
01052 IceFlush(SmcGetIceConnection(tmpSmcConnection));
01053
return true;
01054
#else
01055
01056
return false;
01057
#endif
01058
}
01059
01060 void KApplication::propagateSessionManager()
01061 {
01062
QCString fName = QFile::encodeName(locateLocal(
"socket",
"KSMserver"));
01063
QCString display = ::getenv(DISPLAY);
01064
01065 display.replace(
QRegExp(
"\\.[0-9]+$"),
"");
01066
int i;
01067
while( (i = display.find(
':')) >= 0)
01068 display[i] =
'_';
01069
01070 fName +=
"_"+display;
01071
QCString smEnv = ::getenv(
"SESSION_MANAGER");
01072
bool check = smEnv.isEmpty();
01073
if ( !check && smModificationTime ) {
01074
QFileInfo info( fName );
01075
QTime current = info.lastModified().time();
01076 check = current > *smModificationTime;
01077 }
01078
if ( check ) {
01079
delete smModificationTime;
01080
QFile f( fName );
01081
if ( !f.open( IO_ReadOnly ) )
01082
return;
01083
QFileInfo info ( f );
01084 smModificationTime =
new QTime( info.lastModified().time() );
01085
QTextStream t(&f);
01086 t.setEncoding( QTextStream::Latin1 );
01087
QString s = t.readLine();
01088 f.close();
01089 ::setenv(
"SESSION_MANAGER", s.latin1(),
true );
01090 }
01091 }
01092
01093
void KApplication::commitData(
QSessionManager& sm )
01094 {
01095 d->session_save =
true;
01096
bool canceled =
false;
01097
for (
KSessionManaged* it = sessionClients()->first();
01098 it && !canceled;
01099 it = sessionClients()->next() ) {
01100 canceled = !it->
commitData( sm );
01101 }
01102
if ( canceled )
01103 sm.cancel();
01104
01105
if ( sm.allowsInteraction() ) {
01106 QWidgetList done;
01107 QWidgetList *list = QApplication::topLevelWidgets();
01108
bool canceled =
false;
01109
QWidget* w = list->first();
01110
while ( !canceled && w ) {
01111
if ( !w->testWState( WState_ForceHide ) && !w->inherits(
"KMainWindow") ) {
01112
QCloseEvent e;
01113 sendEvent( w, &e );
01114 canceled = !e.isAccepted();
01115
if ( !canceled )
01116 done.append( w );
01117
delete list;
01118 list = QApplication::topLevelWidgets();
01119 w = list->first();
01120 }
else {
01121 w = list->next();
01122 }
01123
while ( w && done.containsRef( w ) )
01124 w = list->next();
01125 }
01126
delete list;
01127 }
01128
01129
01130
if ( !bSessionManagement )
01131 sm.setRestartHint( QSessionManager::RestartNever );
01132
else
01133 sm.setRestartHint( QSessionManager::RestartIfRunning );
01134 d->session_save =
false;
01135 }
01136
01137
void KApplication::saveState(
QSessionManager& sm )
01138 {
01139 d->session_save =
true;
01140
#ifndef Q_WS_QWS
01141
static bool firstTime =
true;
01142 mySmcConnection = (SmcConn) sm.handle();
01143
01144
if ( !bSessionManagement ) {
01145 sm.setRestartHint( QSessionManager::RestartNever );
01146 d->session_save =
false;
01147
return;
01148 }
01149
else
01150 sm.setRestartHint( QSessionManager::RestartIfRunning );
01151
01152
#if QT_VERSION < 0x030100
01153
{
01154
01155 timeval tv;
01156 gettimeofday( &tv, 0 );
01157 d->sessionKey = QString::number( tv.tv_sec ) +
"_" + QString::number(tv.tv_usec);
01158 }
01159
#endif
01160
01161
if ( firstTime ) {
01162 firstTime =
false;
01163 d->session_save =
false;
01164
return;
01165 }
01166
01167
01168
01169
01170
01171
01172
01173
if ( pSessionConfig ) {
01174
delete pSessionConfig;
01175 pSessionConfig = 0;
01176 }
01177
01178
01179
QStringList restartCommand = sm.restartCommand();
01180
#if QT_VERSION < 0x030100
01181
restartCommand.clear();
01182 restartCommand << argv()[0] <<
"-session" << sm.sessionId() <<
"-smkey" << d->sessionKey;
01183 sm.setRestartCommand( restartCommand );
01184
#endif
01185
01186
01187
QCString multiHead = getenv(
"KDE_MULTIHEAD");
01188
if (multiHead.lower() ==
"true") {
01189
01190
01191
01192
01193
01194
01195
QCString displayname = getenv(DISPLAY);
01196
if (! displayname.isNull()) {
01197
01198
01199 restartCommand.append(
"-display");
01200 restartCommand.append(displayname);
01201 }
01202 sm.setRestartCommand( restartCommand );
01203 }
01204
01205
01206
01207 emit
saveYourself();
01208
bool canceled =
false;
01209
for (
KSessionManaged* it = sessionClients()->first();
01210 it && !canceled;
01211 it = sessionClients()->next() ) {
01212 canceled = !it->
saveState( sm );
01213 }
01214
01215
01216
if ( pSessionConfig ) {
01217 pSessionConfig->
sync();
01218
QStringList discard;
01219 discard <<
"rm" << locateLocal(
"config", sessionConfigName());
01220 sm.setDiscardCommand( discard );
01221 }
else {
01222 sm.setDiscardCommand(
"" );
01223 }
01224
01225
if ( canceled )
01226 sm.cancel();
01227
#else
01228
01229
#endif
01230
d->session_save =
false;
01231 }
01232
01233 bool KApplication::sessionSaving()
const
01234
{
01235
return d->session_save;
01236 }
01237
01238
void KApplication::startKdeinit()
01239 {
01240
01241
QString srv = KStandardDirs::findExe(QString::fromLatin1(
"kdeinit"));
01242
if (srv.isEmpty())
01243 srv = KStandardDirs::findExe(QString::fromLatin1(
"kdeinit"), KDEDIR+QString::fromLatin1(
"/bin"));
01244
if (srv.isEmpty())
01245
return;
01246
if (kapp && (Tty != kapp->type()))
01247 setOverrideCursor( Qt::waitCursor );
01248 my_system(QFile::encodeName(srv)+
" --suicide");
01249
if (kapp && (Tty != kapp->type()))
01250 restoreOverrideCursor();
01251 }
01252
01253
void KApplication::dcopFailure(
const QString &msg)
01254 {
01255
static int failureCount = 0;
01256 failureCount++;
01257
if (failureCount == 1)
01258 {
01259 startKdeinit();
01260
return;
01261 }
01262
if (failureCount == 2)
01263 {
01264
QString msgStr(i18n(
"There was an error setting up inter-process\n"
01265
"communications for KDE. The message returned\n"
01266
"by the system was:\n\n"));
01267 msgStr += msg;
01268 msgStr += i18n(
"\n\nPlease check that the \"dcopserver\" program is running!");
01269
01270
if (Tty != kapp->type())
01271 {
01272 QMessageBox::critical
01273 (
01274 kapp->mainWidget(),
01275 i18n(
"DCOP communications error (%1)").arg(kapp->caption()),
01276 msgStr,
01277 i18n(
"OK")
01278 );
01279 }
01280
else
01281 {
01282 fprintf(stderr,
"%s\n", msgStr.local8Bit().data());
01283 }
01284
01285
return;
01286 }
01287 }
01288
01289
static const KCmdLineOptions qt_options[] =
01290 {
01291
01292
#ifdef Q_WS_X11
01293
{
"display <displayname>", I18N_NOOP(
"Use the X-server display 'displayname'."), 0},
01294
#else
01295
{
"display <displayname>", I18N_NOOP(
"Use the QWS display 'displayname'."), 0},
01296
#endif
01297
{
"session <sessionId>", I18N_NOOP(
"Restore the application for the given 'sessionId'."), 0},
01298 {
"cmap", I18N_NOOP(
"Causes the application to install a private color\nmap on an 8-bit display."), 0},
01299 {
"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 QApplication::ManyColor color\nspecification."), 0},
01300 {
"nograb", I18N_NOOP(
"tells Qt to never grab the mouse or the keyboard."), 0},
01301 {
"dograb", I18N_NOOP(
"running under a debugger can cause an implicit\n-nograb, use -dograb to override."), 0},
01302 {
"sync", I18N_NOOP(
"switches to synchronous mode for debugging."), 0},
01303 {
"fn", 0, 0},
01304 {
"font <fontname>", I18N_NOOP(
"defines the application font."), 0},
01305 {
"bg", 0, 0},
01306 {
"background <color>", I18N_NOOP(
"sets the default background color and an\napplication palette (light and dark shades are\ncalculated)."), 0},
01307 {
"fg", 0, 0},
01308 {
"foreground <color>", I18N_NOOP(
"sets the default foreground color."), 0},
01309 {
"btn", 0, 0},
01310 {
"button <color>", I18N_NOOP(
"sets the default button color."), 0},
01311 {
"name <name>", I18N_NOOP(
"sets the application name."), 0},
01312 {
"title <title>", I18N_NOOP(
"sets the application title (caption)."), 0},
01313
#ifdef Q_WS_X11
01314
{
"visual TrueColor", I18N_NOOP(
"forces the application to use a TrueColor visual on\nan 8-bit display."), 0},
01315 {
"inputstyle <inputstyle>", I18N_NOOP(
"sets XIM (X Input Method) input style. Possible\nvalues are onthespot, overthespot, offthespot and\nroot."), 0 },
01316 {
"im <XIM server>", I18N_NOOP(
"set XIM server."),0},
01317 {
"noxim", I18N_NOOP(
"disable XIM."), 0 },
01318
#endif
01319
#ifdef Q_WS_QWS
01320
{
"qws", I18N_NOOP(
"forces the application to run as QWS Server."), 0},
01321
#endif
01322
{
"reverse", I18N_NOOP(
"mirrors the whole layout of widgets."), 0},
01323 KCmdLineLastOption
01324 };
01325
01326
static const KCmdLineOptions kde_options[] =
01327 {
01328 {
"caption <caption>", I18N_NOOP(
"Use 'caption' as name in the titlebar."), 0},
01329 {
"icon <icon>", I18N_NOOP(
"Use 'icon' as the application icon."), 0},
01330 {
"miniicon <icon>", I18N_NOOP(
"Use 'icon' as the icon in the titlebar."), 0},
01331 {
"config <filename>", I18N_NOOP(
"Use alternative configuration file."), 0},
01332 {
"dcopserver <server>", I18N_NOOP(
"Use the DCOP Server specified by 'server'."), 0},
01333 {
"nocrashhandler", I18N_NOOP(
"Disable crash handler, to get core dumps."), 0},
01334 {
"waitforwm", I18N_NOOP(
"Waits for a WM_NET compatible windowmanager."), 0},
01335 {
"style <style>", I18N_NOOP(
"sets the application GUI style."), 0},
01336 {
"geometry <geometry>", I18N_NOOP(
"sets the client geometry of the main widget."), 0},
01337
#if QT_VERSION < 0x030100
01338
{
"smkey <sessionKey>", I18N_NOOP(
"Define a 'sessionKey' for the session id. Only valid with -session"), 0},
01339
#else
01340
{
"smkey <sessionKey>", 0, 0},
01341
01342
01343
#endif
01344
KCmdLineLastOption
01345 };
01346
01347
void
01348 KApplication::addCmdLineOptions()
01349 {
01350 KCmdLineArgs::addCmdLineOptions(qt_options,
"Qt",
"qt");
01351 KCmdLineArgs::addCmdLineOptions(kde_options,
"KDE",
"kde");
01352 }
01353
01354
void KApplication::parseCommandLine( )
01355 {
01356
KCmdLineArgs *args = KCmdLineArgs::parsedArgs(
"kde");
01357
01358
if ( !args )
return;
01359
01360
if (args->
isSet(
"config"))
01361 {
01362
QString config = QString::fromLocal8Bit(args->
getOption(
"config"));
01363 setConfigName(config);
01364 }
01365
01366
if (args->
isSet(
"style"))
01367 {
01368
01369
QStringList styles = QStyleFactory::keys();
01370
QString reqStyle(args->
getOption(
"style").lower());
01371
01372
for (QStringList::ConstIterator it = styles.begin(); it != styles.end(); ++it)
01373
if ((*it).lower() == reqStyle)
01374 {
01375 d->overrideStyle = *it;
01376
break;
01377 }
01378
01379
if (d->overrideStyle.isEmpty())
01380 fprintf(stderr,
"%s", i18n(
"The style %1 was not found\n").arg(reqStyle).local8Bit().data());
01381 }
01382
01383
if (args->
isSet(
"caption"))
01384 {
01385 aCaption = QString::fromLocal8Bit(args->
getOption(
"caption"));
01386 }
01387
01388
if (args->
isSet(
"miniicon"))
01389 {
01390
const char *tmp = args->
getOption(
"miniicon");
01391 aMiniIconPixmap = SmallIcon(tmp);
01392 aMiniIconName = tmp;
01393 }
01394
01395
if (args->
isSet(
"icon"))
01396 {
01397
const char *tmp = args->
getOption(
"icon");
01398 aIconPixmap = DesktopIcon( tmp );
01399 aIconName = tmp;
01400
if (aMiniIconPixmap.isNull())
01401 {
01402 aMiniIconPixmap = SmallIcon( tmp );
01403 aMiniIconName = tmp;
01404 }
01405 }
01406
01407
bool nocrashhandler = (getenv(
"KDE_DEBUG") != NULL);
01408
if (!nocrashhandler && args->
isSet(
"crashhandler"))
01409 {
01410
01411
KCrash::setCrashHandler(KCrash::defaultCrashHandler);
01412
KCrash::setEmergencySaveFunction(NULL);
01413
01414
KCrash::setApplicationName(
QString(args->
appName()));
01415 }
01416
01417
#ifdef Q_WS_X11
01418
if ( args->
isSet(
"waitforwm" ) ) {
01419 Atom type;
01420 (
void) desktop();
01421
int format;
01422
unsigned long length, after;
01423
unsigned char *data;
01424
while ( XGetWindowProperty( qt_xdisplay(), qt_xrootwin(), atom_NetSupported,
01425 0, 1,
false, AnyPropertyType, &type, &format,
01426 &length, &after, &data ) != Success || !length ) {
01427
if ( data )
01428 XFree( data );
01429 XEvent
event;
01430 XWindowEvent( qt_xdisplay(), qt_xrootwin(), PropertyChangeMask, &event );
01431 }
01432
if ( data )
01433 XFree( data );
01434 }
01435
#else
01436
01437
#endif
01438
01439
if (args->
isSet(
"geometry"))
01440 {
01441 d->geometry_arg = args->
getOption(
"geometry");
01442 }
01443
01444
if (args->
isSet(
"smkey"))
01445 {
01446 d->sessionKey = args->
getOption(
"smkey");
01447 }
01448
01449 }
01450
01451 QString KApplication::geometryArgument()
const
01452
{
01453
return d->geometry_arg;
01454 }
01455
01456 QPixmap KApplication::icon()
const
01457
{
01458
if( aIconPixmap.isNull()) {
01459
KApplication *that = const_cast<KApplication *>(
this);
01460 that->
aIconPixmap = DesktopIcon(
instanceName() );
01461 }
01462
return aIconPixmap;
01463 }
01464
01465 QString KApplication::iconName()
const
01466
{
01467
return aIconName.isNull() ? (
QString)
instanceName() : aIconName;
01468 }
01469
01470 QPixmap KApplication::miniIcon()
const
01471
{
01472
if (aMiniIconPixmap.isNull()) {
01473
KApplication *that = const_cast<KApplication *>(
this);
01474 that->
aMiniIconPixmap = SmallIcon(
instanceName() );
01475 }
01476
return aMiniIconPixmap;
01477 }
01478
01479 QString KApplication::miniIconName()
const
01480
{
01481
return aMiniIconName.isNull() ? (
QString)
instanceName() : aMiniIconName;
01482 }
01483
01484
extern void kDebugCleanup();
01485
01486 KApplication::~KApplication()
01487 {
01488
delete d->m_KAppDCOPInterface;
01489
01490
01491
01492
01493
KGlobal::deleteStaticDeleters();
01494 KLibLoader::cleanUp();
01495
01496
delete smw;
01497
01498
01499
delete s_DCOPClient;
01500 s_DCOPClient = 0L;
01501
01502
KProcessController::deref();
01503
01504
if ( d->oldXErrorHandler != NULL )
01505 XSetErrorHandler( d->oldXErrorHandler );
01506
if ( d->oldXIOErrorHandler != NULL )
01507 XSetIOErrorHandler( d->oldXIOErrorHandler );
01508
if ( d->oldIceIOErrorHandler != NULL )
01509 IceSetIOErrorHandler( d->oldIceIOErrorHandler );
01510
01511
delete d;
01512 KApp = 0;
01513
01514
#ifndef Q_WS_QWS
01515
mySmcConnection = 0;
01516
delete smModificationTime;
01517 smModificationTime = 0;
01518
01519
01520
if (tmpSmcConnection) {
01521 SmcCloseConnection( tmpSmcConnection, 0, 0 );
01522 tmpSmcConnection = 0;
01523 }
01524
#else
01525
01526
#endif
01527
}
01528
01529
01530
#ifdef Q_WS_X11
01531
class KAppX11HackWidget:
public QWidget
01532 {
01533
public:
01534
bool publicx11Event( XEvent * e) {
return x11Event( e ); }
01535 };
01536
#endif
01537
01538
01539
01540
static bool kapp_block_user_input =
false;
01541
01542
void KApplication::dcopBlockUserInput(
bool b )
01543 {
01544 kapp_block_user_input = b;
01545 }
01546
01547
#ifdef Q_WS_X11
01548
bool KApplication::x11EventFilter( XEvent *_event )
01549 {
01550
switch ( _event->type ) {
01551
case ButtonPress:
01552
case XKeyPress:
01553 {
01554
if( _event->type == ButtonPress )
01555 qt_x_user_time = _event->xbutton.time;
01556
else
01557 qt_x_user_time = _event->xkey.time;
01558
QWidget* w = activeWindow();
01559
if( w ) {
01560 XChangeProperty( qt_xdisplay(), w->winId(), kde_net_wm_user_time, XA_CARDINAL,
01561 32, PropModeReplace, (
unsigned char*)&qt_x_user_time, 1 );
01562 timeval tv;
01563 gettimeofday( &tv, NULL );
01564
unsigned long now = tv.tv_sec * 10 + tv.tv_usec / 100000;
01565 XChangeProperty(qt_xdisplay(), w->winId(),
01566 atom_KdeNetUserTime, XA_CARDINAL,
01567 32, PropModeReplace, (
unsigned char *)&now, 1);
01568 }
01569 }
01570
break;
01571
case ClientMessage:
01572 {
01573
#if KDE_IS_VERSION( 3, 2, 91 )
01574
#warning This should be already in Qt, check.
01575
#endif
01576
01577
01578
01579
01580
01581
if( _event->xclient.message_type == kde_xdnd_drop )
01582 {
01583
if( _event->xclient.data.l[ 1 ] == 1 << 24
01584 && _event->xclient.data.l[ 2 ] == 0
01585 && _event->xclient.data.l[ 4 ] == 0
01586 && _event->xclient.data.l[ 3 ] != 0 )
01587 {
01588
if( qt_x_user_time == 0
01589 || ( _event->xclient.data.l[ 3 ] - qt_x_user_time ) < 100000U )
01590 {
01591 qt_x_user_time = _event->xclient.data.l[ 3 ];
01592 }
01593 }
01594
else
01595 {
01596
if( qt_x_user_time == 0
01597 || ( _event->xclient.data.l[ 2 ] - qt_x_user_time ) < 100000U )
01598 {
01599 qt_x_user_time = _event->xclient.data.l[ 2 ];
01600 }
01601 }
01602 }
01603 }
01604
default:
break;
01605 }
01606
01607
if ( kapp_block_user_input ) {
01608
switch ( _event->type ) {
01609
case ButtonPress:
01610
case ButtonRelease:
01611
case XKeyPress:
01612
case XKeyRelease:
01613
case MotionNotify:
01614
return true;
01615
default:
01616
break;
01617 }
01618 }
01619
01620
if (x11Filter) {
01621
for (
QWidget *w=x11Filter->first(); w; w=x11Filter->next()) {
01622
if (((KAppX11HackWidget*) w)->publicx11Event(_event))
01623
return true;
01624 }
01625 }
01626
01627
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
01628
if ((_event->type == ClientMessage) &&
01629 (_event->xclient.message_type == kipcCommAtom))
01630 {
01631 XClientMessageEvent *cme = (XClientMessageEvent *) _event;
01632
01633
int id = cme->data.l[0];
01634
int arg = cme->data.l[1];
01635
if ((
id < 32) && (kipcEventMask & (1 <<
id)))
01636 {
01637
switch (
id)
01638 {
01639
case KIPC::StyleChanged:
01640
KGlobal::config()->
reparseConfiguration();
01641 kdisplaySetStyle();
01642
break;
01643
01644
case KIPC::ToolbarStyleChanged:
01645
KGlobal::config()->
reparseConfiguration();
01646
if (useStyles)
01647 emit
toolbarAppearanceChanged(arg);
01648
break;
01649
01650
case KIPC::PaletteChanged:
01651
KGlobal::config()->
reparseConfiguration();
01652 kdisplaySetPalette();
01653
break;
01654
01655
case KIPC::FontChanged:
01656
KGlobal::config()->
reparseConfiguration();
01657 KGlobalSettings::rereadFontSettings();
01658 kdisplaySetFont();
01659
break;
01660
01661
case KIPC::BackgroundChanged:
01662 emit
backgroundChanged(arg);
01663
break;
01664
01665
case KIPC::SettingsChanged:
01666
KGlobal::config()->
reparseConfiguration();
01667
if (arg == SETTINGS_PATHS)
01668 KGlobalSettings::rereadPathSettings();
01669
else if (arg == SETTINGS_MOUSE)
01670 KGlobalSettings::rereadMouseSettings();
01671 propagateSettings((SettingsCategory)arg);
01672
break;
01673
01674
case KIPC::IconChanged:
01675 QPixmapCache::clear();
01676
KGlobal::config()->
reparseConfiguration();
01677
KGlobal::instance()->
newIconLoader();
01678 emit
iconChanged(arg);
01679
break;
01680
01681
case KIPC::ClipboardConfigChanged:
01682 KClipboardSynchronizer::newConfiguration(arg);
01683
break;
01684 }
01685 }
01686
else if (
id >= 32)
01687 {
01688 emit
kipcMessage(
id, arg);
01689 }
01690
return true;
01691 }
01692
#endif // Q_WS_X11 && ! K_WS_QTONLY
01693
return false;
01694 }
01695
#endif
01696
01697 void KApplication::updateUserTimestamp(
unsigned long time )
01698 {
01699
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
01700
if( time == 0 )
01701 {
01702 Window w = XCreateSimpleWindow( qt_xdisplay(), qt_xrootwin(), 0, 0, 1, 1, 0, 0, 0 );
01703 XSelectInput( qt_xdisplay(), w, PropertyChangeMask );
01704
unsigned char data[ 1 ];
01705 XChangeProperty( qt_xdisplay(), w, XA_ATOM, XA_ATOM, 8, PropModeAppend, data, 1 );
01706 XEvent ev;
01707 XWindowEvent( qt_xdisplay(), w, PropertyChangeMask, &ev );
01708 time = ev.xproperty.time;
01709 XDestroyWindow( qt_xdisplay(), w );
01710 }
01711
if( qt_x_user_time == 0
01712 || time - qt_x_user_time < 1000000000U )
01713 qt_x_user_time = time;
01714
#endif
01715
}
01716
01717 unsigned long KApplication::userTimestamp()
const
01718
{
01719
return qt_x_user_time;
01720 }
01721
01722 void KApplication::invokeEditSlot(
const char *slot )
01723 {
01724
QObject *object = focusWidget();
01725
if( !object )
01726
return;
01727
01728
QMetaObject *meta = object->metaObject();
01729
01730
int idx = meta->findSlot( slot + 1,
true );
01731
if( idx < 0 )
01732
return;
01733
01734 object->qt_invoke( idx, 0 );
01735 }
01736
01737 void KApplication::addKipcEventMask(
int id)
01738 {
01739
if (
id >= 32)
01740 {
01741 kdDebug(101) <<
"Cannot use KIPC event mask for message IDs >= 32\n";
01742
return;
01743 }
01744 kipcEventMask |= (1 <<
id);
01745 }
01746
01747 void KApplication::removeKipcEventMask(
int id)
01748 {
01749
if (
id >= 32)
01750 {
01751 kdDebug(101) <<
"Cannot use KIPC event mask for message IDs >= 32\n";
01752
return;
01753 }
01754 kipcEventMask &= ~(1 <<
id);
01755 }
01756
01757 void KApplication::enableStyles()
01758 {
01759
if (!useStyles)
01760 {
01761 useStyles =
true;
01762 applyGUIStyle();
01763 }
01764 }
01765
01766 void KApplication::disableStyles()
01767 {
01768 useStyles =
false;
01769 }
01770
01771
void KApplication::applyGUIStyle()
01772 {
01773
if ( !useStyles )
return;
01774
01775
KConfigGroup pConfig (KGlobal::config(),
"General");
01776
QString defaultStyle = KStyle::defaultStyle();
01777
QString styleStr = pConfig.
readEntry(
"widgetStyle", defaultStyle);
01778
01779
if (d->overrideStyle.isEmpty()) {
01780
01781
01782
01783
QStyle* sp = QStyleFactory::create( styleStr );
01784
01785
01786
if ( !sp && styleStr != defaultStyle)
01787 sp = QStyleFactory::create( defaultStyle );
01788
if ( !sp )
01789 sp = QStyleFactory::create( *(QStyleFactory::keys().begin()) );
01790 setStyle(sp);
01791 }
01792
else
01793 setStyle(d->overrideStyle);
01794
01795 kdisplaySetPalette();
01796 }
01797
01798 QString KApplication::caption()
const
01799
{
01800
01801
if( !aCaption.isNull() )
01802
return aCaption;
01803
else
01804
01805
if (
KGlobal::instance()->
aboutData() )
01806
return KGlobal::instance()->
aboutData()->
programName();
01807
else
01808
01809
return name();
01810 }
01811
01812
01813
01814
01815
01816
01817 QString KApplication::makeStdCaption(
const QString &userCaption,
01818
bool withAppName,
bool modified )
const
01819
{
01820
QString s = userCaption.isEmpty() ?
caption() : userCaption;
01821
01822
01823
if (modified)
01824 s += QString::fromUtf8(
" [") + i18n(
"modified") + QString::fromUtf8(
"]");
01825
01826
if ( !userCaption.isEmpty() ) {
01827
01828
01829
if ( withAppName && !
caption().isNull() && !userCaption.endsWith(
caption()) )
01830 s += QString::fromUtf8(
" - ") +
caption();
01831 }
01832
01833
return s;
01834 }
01835
01836 QPalette KApplication::createApplicationPalette()
01837 {
01838
KConfig *config =
KGlobal::config();
01839
KConfigGroupSaver saver( config,
"General" );
01840
return createApplicationPalette( config, KGlobalSettings::contrast() );
01841 }
01842
01843
QPalette KApplication::createApplicationPalette(
KConfig *config,
int contrast_ )
01844 {
01845
QColor kde31Background( 238, 238, 230 );
01846
QColor kde31Beige( 255,221,118 );
01847
01848
QColor kde31Button;
01849
if ( QPixmap::defaultDepth() > 8 )
01850 kde31Button.setRgb( 238, 234, 222 );
01851
else
01852 kde31Button.setRgb( 220, 220, 220 );
01853
QColor mdkBackground( 33,68,156 );
01854
QColor mdkForeground( 255,255,255);
01855
01856
QColor kde31Link( 0, 0, 192 );
01857
QColor kde31VisitedLink( 128, 0,128 );
01858
01859
QColor background = config->
readColorEntry(
"background", &kde31Background );
01860
QColor foreground = config->
readColorEntry(
"foreground", &black );
01861
QColor button = config->
readColorEntry(
"buttonBackground", &kde31Button );
01862
QColor buttonText = config->
readColorEntry(
"buttonForeground", &foreground );
01863
QColor highlight = config->
readColorEntry(
"selectBackground", &mdkBackground );
01864
QColor highlightedText = config->
readColorEntry(
"selectForeground", &mdkForeground);
01865
QColor base = config->
readColorEntry(
"windowBackground", &white );
01866
QColor baseText = config->
readColorEntry(
"windowForeground", &black );
01867
QColor link = config->
readColorEntry(
"linkColor", &kde31Link );
01868
QColor visitedLink = config->
readColorEntry(
"visitedLinkColor", &kde31VisitedLink );
01869
01870
int highlightVal, lowlightVal;
01871 highlightVal = 100 + (2*contrast_+4)*16/10;
01872 lowlightVal = 100 + (2*contrast_+4)*10;
01873
01874
QColor disfg = foreground;
01875
01876
int h, s, v;
01877 disfg.hsv( &h, &s, &v );
01878
if (v > 128)
01879
01880 disfg = disfg.dark(lowlightVal);
01881
else if (disfg != black)
01882
01883 disfg = disfg.light(highlightVal);
01884
else
01885
01886 disfg = Qt::darkGray;
01887
01888
01889
QColorGroup disabledgrp(disfg, background,
01890 background.light(highlightVal),
01891 background.dark(lowlightVal),
01892 background.dark(120),
01893 background.dark(120), base);
01894
01895
QColorGroup colgrp(foreground, background, background.light(highlightVal),
01896 background.dark(lowlightVal),
01897 background.dark(120),
01898 baseText, base);
01899
01900
int inlowlightVal = lowlightVal-25;
01901
if(inlowlightVal < 120)
01902 inlowlightVal = 120;
01903
01904 colgrp.setColor(QColorGroup::Highlight, highlight);
01905 colgrp.setColor(QColorGroup::HighlightedText, highlightedText);
01906 colgrp.setColor(QColorGroup::Button, button);
01907 colgrp.setColor(QColorGroup::ButtonText, buttonText);
01908 colgrp.setColor(QColorGroup::Midlight, background.light(110));
01909 colgrp.setColor(QColorGroup::Link, link);
01910 colgrp.setColor(QColorGroup::LinkVisited, visitedLink);
01911
01912 disabledgrp.setColor(QColorGroup::Button, button);
01913
01914
QColor disbtntext = buttonText;
01915 disbtntext.hsv( &h, &s, &v );
01916
if (v > 128)
01917
01918 disbtntext = disbtntext.dark(lowlightVal);
01919
else if (disbtntext != black)
01920
01921 disbtntext = disbtntext.light(highlightVal);
01922
else
01923
01924 disbtntext = Qt::darkGray;
01925
01926 disabledgrp.setColor(QColorGroup::ButtonText, disbtntext);
01927 disabledgrp.setColor(QColorGroup::Midlight, background.light(110));
01928 disabledgrp.setColor(QColorGroup::Highlight, highlight.dark(120));
01929 disabledgrp.setColor(QColorGroup::Link, link);
01930 disabledgrp.setColor(QColorGroup::LinkVisited, visitedLink);
01931
01932
return QPalette(colgrp, disabledgrp, colgrp);
01933 }
01934
01935
01936
void KApplication::kdisplaySetPalette()
01937 {
01938 QApplication::setPalette(
createApplicationPalette(),
true);
01939 emit
kdisplayPaletteChanged();
01940 emit
appearanceChanged();
01941 }
01942
01943
01944
void KApplication::kdisplaySetFont()
01945 {
01946 QApplication::setFont(KGlobalSettings::generalFont(),
true);
01947 QApplication::setFont(KGlobalSettings::menuFont(),
true,
"QMenuBar");
01948 QApplication::setFont(KGlobalSettings::menuFont(),
true,
"QPopupMenu");
01949 QApplication::setFont(KGlobalSettings::menuFont(),
true,
"KPopupTitle");
01950
01951
01952
QStyleSheet* sheet = QStyleSheet::defaultSheet();
01953 sheet->item (
"pre")->setFontFamily (KGlobalSettings::fixedFont().family());
01954 sheet->item (
"code")->setFontFamily (KGlobalSettings::fixedFont().family());
01955 sheet->item (
"tt")->setFontFamily (KGlobalSettings::fixedFont().family());
01956
01957 emit
kdisplayFontChanged();
01958 emit
appearanceChanged();
01959 }
01960
01961
01962
void KApplication::kdisplaySetStyle()
01963 {
01964
if (useStyles)
01965 {
01966 applyGUIStyle();
01967 emit
kdisplayStyleChanged();
01968 emit
appearanceChanged();
01969 }
01970 }
01971
01972
01973
void KApplication::propagateSettings(SettingsCategory arg)
01974 {
01975
KConfigBase* config =
KGlobal::config();
01976
KConfigGroupSaver saver( config,
"KDE" );
01977
01978
int num = config->
readNumEntry(
"CursorBlinkRate", QApplication::cursorFlashTime());
01979
if (num < 200)
01980 num = 200;
01981
if (num > 2000)
01982 num = 2000;
01983 QApplication::setCursorFlashTime(num);
01984 num = config->
readNumEntry(
"DoubleClickInterval", QApplication::doubleClickInterval());
01985 QApplication::setDoubleClickInterval(num);
01986 num = config->
readNumEntry(
"StartDragTime", QApplication::startDragTime());
01987 QApplication::setStartDragTime(num);
01988 num = config->
readNumEntry(
"StartDragDist", QApplication::startDragDistance());
01989 QApplication::setStartDragDistance(num);
01990 num = config->
readNumEntry(
"WheelScrollLines", QApplication::wheelScrollLines());
01991 QApplication::setWheelScrollLines(num);
01992
01993
bool b = config->
readBoolEntry(
"EffectAnimateMenu",
false);
01994 QApplication::setEffectEnabled( Qt::UI_AnimateMenu, b);
01995 b = config->
readBoolEntry(
"EffectFadeMenu",
false);
01996 QApplication::setEffectEnabled( Qt::UI_FadeMenu, b);
01997 b = config->
readBoolEntry(
"EffectAnimateCombo",
false);
01998 QApplication::setEffectEnabled( Qt::UI_AnimateCombo, b);
01999 b = config->
readBoolEntry(
"EffectAnimateTooltip",
false);
02000 QApplication::setEffectEnabled( Qt::UI_AnimateTooltip, b);
02001 b = config->
readBoolEntry(
"EffectFadeTooltip",
false);
02002 QApplication::setEffectEnabled( Qt::UI_FadeTooltip, b);
02003 b = !config->
readBoolEntry(
"EffectNoTooltip",
false);
02004 QToolTip::setGloballyEnabled( b );
02005
02006 emit
settingsChanged(arg);
02007 }
02008
02009 void KApplication::installKDEPropertyMap()
02010 {
02011
#ifndef QT_NO_SQL
02012
static bool installed =
false;
02013
if (installed)
return;
02014 installed =
true;
02021
02022
QSqlPropertyMap *kdeMap =
new QSqlPropertyMap;
02023 kdeMap->insert(
"KColorButton",
"color" );
02024 kdeMap->insert(
"KComboBox",
"currentItem" );
02025 kdeMap->insert(
"KDatePicker",
"date" );
02026 kdeMap->insert(
"KEditListBox",
"currentItem" );
02027 kdeMap->insert(
"KFontCombo",
"family" );
02028 kdeMap->insert(
"KFontRequester",
"font" );
02029 kdeMap->insert(
"KFontChooser",
"font" );
02030 kdeMap->insert(
"KHistoryCombo",
"currentItem" );
02031 kdeMap->insert(
"KListBox",
"currentItem" );
02032 kdeMap->insert(
"KLineEdit",
"text" );
02033 kdeMap->insert(
"KRestrictedLine",
"text" );
02034 kdeMap->insert(
"KSqueezedTextLabel",
"text" );
02035 kdeMap->insert(
"KTextBrowser",
"source" );
02036 kdeMap->insert(
"KTextEdit",
"text" );
02037 kdeMap->insert(
"KURLRequester",
"url" );
02038 kdeMap->insert(
"KPasswordEdit",
"password" );
02039 kdeMap->insert(
"KIntNumInput",
"value" );
02040 kdeMap->insert(
"KIntSpinBox",
"value" );
02041 kdeMap->insert(
"KDoubleNumInput",
"value" );
02042
#if QT_VERSION < 0x030200
02043
kdeMap->insert(
"QRadioButton",
"checked" );
02044
#endif
02045
02046
02047 kdeMap->insert(
"QTabWidget",
"currentPage" );
02048
02049 QSqlPropertyMap::installDefaultMap( kdeMap );
02050
#endif
02051
}
02052
02053
void KApplication::invokeHelp(
const QString& anchor,
02054
const QString& _appname)
const
02055
{
02056
return invokeHelp( anchor, _appname,
"" );
02057 }
02058
02059 void KApplication::invokeHelp(
const QString& anchor,
02060
const QString& _appname,
02061
const QCString& startup_id )
const
02062
{
02063
QString url;
02064
QString appname;
02065
if (_appname.isEmpty())
02066 appname = name();
02067
else
02068 appname = _appname;
02069
02070
if (!anchor.isEmpty())
02071 url =
QString(
"help:/%1?anchor=%2").arg(appname).arg(anchor);
02072
else
02073 url = QString(
"help:/%1/index.html").arg(appname);
02074
02075 QString error;
02076
if ( !
dcopClient()->
isApplicationRegistered(
"khelpcenter") )
02077 {
02078
if (
startServiceByDesktopName(
"khelpcenter", url, &error, 0, 0, startup_id,
false))
02079 {
02080 kdWarning() <<
"Could not launch help:\n" << error <<
endl;
02081
return;
02082 }
02083 }
02084
else
02085
DCOPRef(
"khelpcenter",
"KHelpCenterIface" ).send(
"openUrl", url, startup_id );
02086 }
02087
02088 void KApplication::invokeHTMLHelp(
const QString& _filename,
const QString& topic )
const
02089
{
02090 kdWarning() <<
"invoking HTML help is deprecated! use docbook and invokeHelp!\n";
02091
02092
QString filename;
02093
02094
if( _filename.isEmpty() )
02095 filename =
QString(name()) +
"/index.html";
02096
else
02097 filename = _filename;
02098
02099 QString url;
02100
if (!topic.isEmpty())
02101 url = QString(
"help:/%1#%2").arg(filename).arg(topic);
02102
else
02103 url = QString(
"help:/%1").arg(filename);
02104
02105 QString error;
02106
if ( !
dcopClient()->
isApplicationRegistered(
"khelpcenter") )
02107 {
02108
if (
startServiceByDesktopName(
"khelpcenter", url, &error, 0, 0,
"",
false))
02109 {
02110 kdWarning() <<
"Could not launch help:\n" << error <<
endl;
02111
return;
02112 }
02113 }
02114
else
02115
DCOPRef(
"khelpcenter",
"KHelpCenterIface" ).send(
"openUrl", url );
02116 }
02117
02118
02119
void KApplication::invokeMailer(
const QString &address,
const QString &subject)
02120 {
02121
return invokeMailer(address,subject,
"");
02122 }
02123
02124 void KApplication::invokeMailer(
const QString &address,
const QString &subject,
const QCString& startup_id)
02125 {
02126
invokeMailer(address, QString::null, QString::null, subject, QString::null, QString::null,
02127
QStringList(), startup_id );
02128 }
02129
02130
void KApplication::invokeMailer(
const KURL &mailtoURL)
02131 {
02132
return invokeMailer( mailtoURL,
"" );
02133 }
02134
02135 void KApplication::invokeMailer(
const KURL &mailtoURL,
const QCString& startup_id )
02136 {
02137
QString address = KURL::decode_string(mailtoURL.
path()), subject, cc, bcc, body, attach;
02138
QStringList queries = QStringList::split(
'&', mailtoURL.
query().mid(1));
02139
for (QStringList::Iterator it = queries.begin(); it != queries.end(); ++it)
02140 {
02141
QString q = (*it).lower();
02142
if (q.startsWith(
"subject="))
02143 subject = KURL::decode_string((*it).mid(8));
02144
else
02145
if (q.startsWith(
"cc="))
02146 cc = KURL::decode_string((*it).mid(3));
02147
else
02148
if (q.startsWith(
"bcc="))
02149 bcc = KURL::decode_string((*it).mid(4));
02150
else
02151
if (q.startsWith(
"body="))
02152 body = KURL::decode_string((*it).mid(5));
02153
02154
02155
02156 }
02157
02158
invokeMailer( address, cc, bcc, subject, body, QString::null,
QStringList(), startup_id );
02159 }
02160
02161
void KApplication::invokeMailer(
const QString &to,
const QString &cc,
const QString &bcc,
02162
const QString &subject,
const QString &body,
02163
const QString & messageFile,
const QStringList &attachURLs)
02164 {
02165
return invokeMailer(to,cc,bcc,subject,body,messageFile,attachURLs,
"");
02166 }
02167
02168 void KApplication::invokeMailer(
const QString &to,
const QString &cc,
const QString &bcc,
02169
const QString &subject,
const QString &body,
02170
const QString & ,
const QStringList &attachURLs,
02171
const QCString& startup_id )
02172 {
02173
KConfig config(
"emaildefaults");
02174
02175 config.
setGroup(
"Defaults");
02176
QString group = config.
readEntry(
"Profile",
"Default");
02177
02178 config.
setGroup(
QString(
"PROFILE_%1").arg(group) );
02179
QString command = config.
readPathEntry(
"EmailClient");
02180
02181
if (command.isEmpty() || command == QString::fromLatin1(
"kmail")
02182 || command.endsWith(
"/kmail"))
02183 command = QString::fromLatin1(
"kmail --composer -s %s -c %c -b %b --body %B --attach %A -- %t");
02184
02185
02186
02187
02188
02189
02190
if (config.
readBoolEntry(
"TerminalClient",
false))
02191 command =
"konsole -e " + command;
02192
02193
QStringList cmdTokens =
KShell::splitArgs(command);
02194
QString cmd = cmdTokens[0];
02195 cmdTokens.remove(cmdTokens.begin());
02196
02197
QMap<QChar, QString> keyMap;
02198 keyMap.insert(
't', to);
02199 keyMap.insert(
's', subject);
02200 keyMap.insert(
'c', cc);
02201 keyMap.insert(
'b', bcc);
02202 keyMap.insert(
'B', body);
02203
02204
for (QStringList::Iterator it = cmdTokens.begin(); it != cmdTokens.end(); )
02205 {
02206
if (*it ==
"%A")
02207 {
02208
if (it == cmdTokens.begin())
02209
continue;
02210 QStringList::ConstIterator urlit = attachURLs.begin();
02211 QStringList::ConstIterator urlend = attachURLs.end();
02212
if ( urlit != urlend )
02213 {
02214 QStringList::Iterator previt = it;
02215 --previt;
02216 *it = *urlit;
02217 ++it;
02218
while ( ++urlit != urlend )
02219 {
02220 cmdTokens.insert( it, *previt );
02221 cmdTokens.insert( it, *urlit );
02222 }
02223 }
else {
02224 --it;
02225 it = cmdTokens.remove( cmdTokens.remove( it ) );
02226 }
02227 }
else {
02228 *it =
KMacroExpander::expandMacros(*it, keyMap);
02229 ++it;
02230 }
02231 }
02232
02233
QString error;
02234
02235
02236
if (
kdeinitExec(cmd, cmdTokens, &error, NULL, startup_id ))
02237 kdWarning() <<
"Could not launch mail client:\n" << error <<
endl;
02238 }
02239
02240
02241
void KApplication::invokeBrowser(
const QString &url )
02242 {
02243
return invokeBrowser( url,
"" );
02244 }
02245
02246 void KApplication::invokeBrowser(
const QString &url,
const QCString& startup_id )
02247 {
02248
QString error;
02249
02250
if (
startServiceByDesktopName(
"kfmclient", url, &error, 0, 0, startup_id,
false))
02251 {
02252 kdWarning() <<
"Could not launch browser:\n" << error <<
endl;
02253
return;
02254 }
02255 }
02256
02257 void KApplication::cut()
02258 {
02259
invokeEditSlot( SLOT(
cut() ) );
02260 }
02261
02262 void KApplication::copy()
02263 {
02264
invokeEditSlot( SLOT(
copy() ) );
02265 }
02266
02267 void KApplication::paste()
02268 {
02269
invokeEditSlot( SLOT(
paste() ) );
02270 }
02271
02272 void KApplication::clear()
02273 {
02274
invokeEditSlot( SLOT(
clear() ) );
02275 }
02276
02277 void KApplication::selectAll()
02278 {
02279
invokeEditSlot( SLOT(
selectAll() ) );
02280 }
02281
02282
QCString
02283 KApplication::launcher()
02284 {
02285
return "klauncher";
02286 }
02287
02288
static int
02289 startServiceInternal(
const QCString &function,
02290
const QString& _name,
const QStringList &URLs,
02291
QString *error,
QCString *dcopService,
int *pid,
const QCString& startup_id,
bool noWait )
02292 {
02293
struct serviceResult
02294 {
02295
int result;
02296
QCString dcopName;
02297
QString error;
02298 pid_t pid;
02299 };
02300
02301
02302
DCOPClient *dcopClient;
02303
if (kapp)
02304 dcopClient = kapp->dcopClient();
02305
else
02306 dcopClient =
new DCOPClient;
02307
02308
if (!dcopClient->
isAttached())
02309 {
02310
if (!dcopClient->
attach())
02311 {
02312
if (error)
02313 *error = i18n(
"Could not register with DCOP.\n");
02314
return -1;
02315 }
02316 }
02317
QByteArray params;
02318
QDataStream stream(params, IO_WriteOnly);
02319 stream << _name << URLs;
02320
QCString replyType;
02321
QByteArray replyData;
02322
QCString _launcher =
KApplication::launcher();
02323
QValueList<QCString> envs;
02324
#ifdef Q_WS_X11
02325
if (qt_xdisplay()) {
02326
QCString dpystring(XDisplayString(qt_xdisplay()));
02327 envs.append(
QCString(
"DISPLAY=") + dpystring );
02328 }
else if( getenv(
"DISPLAY" )) {
02329
QCString dpystring( getenv(
"DISPLAY" ));
02330 envs.append(
QCString(
"DISPLAY=") + dpystring );
02331 }
02332
#endif
02333
stream << envs << startup_id;
02334
if( function.left( 12 ) !=
"kdeinit_exec" )
02335 stream << noWait;
02336
02337
if (!dcopClient->
call(_launcher, _launcher,
02338 function, params, replyType, replyData))
02339 {
02340
if (error)
02341 *error = i18n(
"KLauncher could not be reached via DCOP.\n");
02342
if (!kapp)
02343
delete dcopClient;
02344
return -1;
02345 }
02346
if (!kapp)
02347
delete dcopClient;
02348
02349
if (noWait)
02350
return 0;
02351
02352
QDataStream stream2(replyData, IO_ReadOnly);
02353 serviceResult result;
02354 stream2 >> result.result >> result.dcopName >> result.error >> result.pid;
02355
if (dcopService)
02356 *dcopService = result.dcopName;
02357
if (error)
02358 *error = result.error;
02359
if (pid)
02360 *pid = result.pid;
02361
return result.result;
02362 }
02363
02364
int
02365 KApplication::startServiceByName(
const QString& _name,
const QString &URL,
02366
QString *error,
QCString *dcopService,
int *pid,
const QCString& startup_id,
bool noWait )
02367 {
02368
QStringList URLs;
02369
if (!URL.isEmpty())
02370 URLs.append(URL);
02371
return startServiceInternal(
02372
"start_service_by_name(QString,QStringList,QValueList<QCString>,QCString,bool)",
02373 _name, URLs, error, dcopService, pid, startup_id, noWait);
02374 }
02375
02376
int
02377 KApplication::startServiceByName(
const QString& _name,
const QStringList &URLs,
02378
QString *error,
QCString *dcopService,
int *pid,
const QCString& startup_id,
bool noWait )
02379 {
02380
return startServiceInternal(
02381
"start_service_by_name(QString,QStringList,QValueList<QCString>,QCString,bool)",
02382 _name, URLs, error, dcopService, pid, startup_id, noWait);
02383 }
02384
02385
int
02386 KApplication::startServiceByDesktopPath(
const QString& _name,
const QString &URL,
02387
QString *error,
QCString *dcopService,
int *pid,
const QCString& startup_id,
bool noWait )
02388 {
02389
QStringList URLs;
02390
if (!URL.isEmpty())
02391 URLs.append(URL);
02392
return startServiceInternal(
02393
"start_service_by_desktop_path(QString,QStringList,QValueList<QCString>,QCString,bool)",
02394 _name, URLs, error, dcopService, pid, startup_id, noWait);
02395 }
02396
02397
int
02398 KApplication::startServiceByDesktopPath(
const QString& _name,
const QStringList &URLs,
02399
QString *error,
QCString *dcopService,
int *pid,
const QCString& startup_id,
bool noWait )
02400 {
02401
return startServiceInternal(
02402
"start_service_by_desktop_path(QString,QStringList,QValueList<QCString>,QCString,bool)",
02403 _name, URLs, error, dcopService, pid, startup_id, noWait);
02404 }
02405
02406
int
02407 KApplication::startServiceByDesktopName(
const QString& _name,
const QString &URL,
02408
QString *error,
QCString *dcopService,
int *pid,
const QCString& startup_id,
bool noWait )
02409 {
02410
QStringList URLs;
02411
if (!URL.isEmpty())
02412 URLs.append(URL);
02413
return startServiceInternal(
02414
"start_service_by_desktop_name(QString,QStringList,QValueList<QCString>,QCString,bool)",
02415 _name, URLs, error, dcopService, pid, startup_id, noWait);
02416 }
02417
02418
int
02419 KApplication::startServiceByDesktopName(
const QString& _name,
const QStringList &URLs,
02420
QString *error,
QCString *dcopService,
int *pid,
const QCString& startup_id,
bool noWait )
02421 {
02422
return startServiceInternal(
02423
"start_service_by_desktop_name(QString,QStringList,QValueList<QCString>,QCString,bool)",
02424 _name, URLs, error, dcopService, pid, startup_id, noWait);
02425 }
02426
02427
int
02428 KApplication::kdeinitExec(
const QString& name,
const QStringList &args,
02429
QString *error,
int *pid )
02430 {
02431
return kdeinitExec( name, args, error, pid,
"" );
02432 }
02433
02434
int
02435 KApplication::kdeinitExec(
const QString& name,
const QStringList &args,
02436
QString *error,
int *pid,
const QCString& startup_id )
02437 {
02438
return startServiceInternal(
"kdeinit_exec(QString,QStringList,QValueList<QCString>,QCString)",
02439 name, args, error, 0, pid, startup_id,
false);
02440 }
02441
02442
int
02443 KApplication::kdeinitExecWait(
const QString& name,
const QStringList &args,
02444
QString *error,
int *pid )
02445 {
02446
return kdeinitExecWait( name, args, error, pid,
"" );
02447 }
02448
02449
int
02450 KApplication::kdeinitExecWait(
const QString& name,
const QStringList &args,
02451
QString *error,
int *pid,
const QCString& startup_id )
02452 {
02453
return startServiceInternal(
"kdeinit_exec_wait(QString,QStringList,QValueList<QCString>,QCString)",
02454 name, args, error, 0, pid, startup_id,
false);
02455 }
02456
02457 QString KApplication::tempSaveName(
const QString& pFilename )
const
02458
{
02459
QString aFilename;
02460
02461
if( pFilename[0] !=
'/' )
02462 {
02463 kdWarning(101) <<
"Relative filename passed to KApplication::tempSaveName" <<
endl;
02464 aFilename =
QFileInfo(
QDir(
"." ), pFilename ).absFilePath();
02465 }
02466
else
02467 aFilename = pFilename;
02468
02469
QDir aAutosaveDir( QDir::homeDirPath() +
"/autosave/" );
02470
if( !aAutosaveDir.exists() )
02471 {
02472
if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
02473 {
02474
02475 aAutosaveDir.setPath( KGlobal::dirs()->saveLocation(
"tmp") );
02476 }
02477 }
02478
02479 aFilename.replace(
"/",
"\\!" ).prepend(
"#" ).append(
"#" ).prepend(
"/" ).prepend( aAutosaveDir.absPath() );
02480
02481
return aFilename;
02482 }
02483
02484
02485 QString KApplication::checkRecoverFile(
const QString& pFilename,
02486
bool& bRecover )
const
02487
{
02488
QString aFilename;
02489
02490
if( pFilename[0] !=
'/' )
02491 {
02492 kdWarning(101) <<
"Relative filename passed to KApplication::tempSaveName" <<
endl;
02493 aFilename =
QFileInfo(
QDir(
"." ), pFilename ).absFilePath();
02494 }
02495
else
02496 aFilename = pFilename;
02497
02498
QDir aAutosaveDir( QDir::homeDirPath() +
"/autosave/" );
02499
if( !aAutosaveDir.exists() )
02500 {
02501
if( !aAutosaveDir.mkdir( aAutosaveDir.absPath() ) )
02502 {
02503
02504 aAutosaveDir.setPath( KGlobal::dirs()->saveLocation(
"tmp") );
02505 }
02506 }
02507
02508 aFilename.replace(
"/",
"\\!" ).prepend(
"#" ).append(
"#" ).prepend(
"/" ).prepend( aAutosaveDir.absPath() );
02509
02510
if(
QFile( aFilename ).exists() )
02511 {
02512 bRecover =
true;
02513
return aFilename;
02514 }
02515
else
02516 {
02517 bRecover =
false;
02518
return pFilename;
02519 }
02520 }
02521
02522
02523 bool checkAccess(
const QString& pathname,
int mode)
02524 {
02525
int accessOK = access( QFile::encodeName(pathname), mode );
02526
if ( accessOK == 0 )
02527
return true;
02528
02529
02530
02531
02532
if ( (mode & W_OK) == 0 )
02533
return false;
02534
02535
02536
if (!access( QFile::encodeName(pathname), F_OK))
02537
return false;
02538
02539
02540
QString dirName(pathname);
02541
int pos = dirName.findRev(
'/');
02542
if ( pos == -1 )
02543
return false;
02544
else if ( pos == 0 )
02545 pos = 1;
02546
02547 dirName.truncate(pos);
02548
02549 accessOK = access( QFile::encodeName(dirName), W_OK );
02550
02551
if ( accessOK == 0 )
02552
return true;
02553
else
02554
return false;
02555 }
02556
02557 void KApplication::setTopWidget(
QWidget *topWidget )
02558 {
02559
if( topWidget != 0 )
02560 {
02561
#ifdef Q_WS_X11 // FIXME(E): Implement for Qt/Embedded
02562
Window leader = topWidget->winId();
02563
char* argv = const_cast< char* >(
KCmdLineArgs::appName());
02564 XSetCommand(display, leader, &argv, 1);
02565
02566 XWMHints *hints = XGetWMHints(display, topWidget->winId());
02567
if (hints)
02568 {
02569
if (!(hints->flags & WindowGroupHint))
02570 {
02571 hints->window_group = leader;
02572 hints->flags |= WindowGroupHint;
02573 }
02574
if (!(hints->flags & InputHint))
02575 {
02576 hints->input = True;
02577 hints->flags |= InputHint;
02578 }
02579 XSetWMHints(display, topWidget->winId(), hints);
02580 XFree(reinterpret_cast<char *>(hints));
02581 }
02582
02583
#endif
02584
02585
if ( !topWidget->inherits(
"KMainWindow") ) {
02586 topWidget->setCaption(
caption() );
02587
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
02588
02589 NETWinInfo info(qt_xdisplay(), topWidget->winId(), qt_xrootwin(), NET::WMName );
02590 info.setName(
caption().utf8().data() );
02591
#endif
02592
}
02593
02594
02595 topWidget->setIcon(
icon() );
02596
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
02597
02598 KWin::setIcons(topWidget->winId(),
icon(),
miniIcon() );
02599
02600
02601 KStartupInfo::setWindowStartupId( topWidget->winId(),
startupId());
02602
#endif
02603
}
02604 }
02605
02606 QCString KApplication::startupId()
const
02607
{
02608
return d->startup_id;
02609 }
02610
02611 void KApplication::setStartupId(
const QCString& startup_id )
02612 {
02613
if( startup_id.isEmpty())
02614 d->startup_id =
"0";
02615
else
02616 d->startup_id = startup_id;
02617 }
02618
02619
02620
02621
void KApplication::read_app_startup_id()
02622 {
02623
#if defined Q_WS_X11 && ! defined K_WS_QTONLY
02624
KStartupInfoId id =
KStartupInfo::currentStartupIdEnv();
02625
KStartupInfo::resetStartupEnv();
02626 d->startup_id =
id.id();
02627
#endif
02628
}
02629
02630 int KApplication::random()
02631 {
02632
static int init =
false;
02633
if (!init)
02634 {
02635
unsigned int seed;
02636 init =
true;
02637
int fd = open(
"/dev/urandom", O_RDONLY);
02638
if (fd <= 0 || ::read(fd, &seed,
sizeof(seed)) !=
sizeof(seed))
02639 {
02640
02641 srand(getpid());
02642 seed = rand()+time(0);
02643 }
02644
if (fd >= 0) close(fd);
02645 srand(seed);
02646 }
02647
return rand();
02648 }
02649
02650 QString KApplication::randomString(
int length)
02651 {
02652
if (length <=0 )
return QString::null;
02653
02654
QString str; str.setLength( length );
02655
int i = 0;
02656
while (length--)
02657 {
02658
int r=
random() % 62;
02659 r+=48;
02660
if (r>57) r+=7;
02661
if (r>90) r+=6;
02662 str[i++] = char(r);
02663
02664 }
02665
return str;
02666 }
02667
02668 bool KApplication::authorize(
const QString &genericAction)
02669 {
02670
if (!d->actionRestrictions)
02671
return true;
02672
02673
KConfig *config =
KGlobal::config();
02674
KConfigGroupSaver saver( config,
"KDE Action Restrictions" );
02675
return config->
readBoolEntry(genericAction,
true);
02676 }
02677
02678 bool KApplication::authorizeKAction(
const char *action)
02679 {
02680
if (!d->actionRestrictions || !action)
02681
return true;
02682
02683
static const QString &action_prefix = KGlobal::staticQString(
"action/" );
02684
02685
return authorize(action_prefix + action);
02686 }
02687
02688 bool KApplication::authorizeControlModule(
const QString &menuId)
02689 {
02690
if (menuId.isEmpty())
02691
return true;
02692
KConfig *config =
KGlobal::config();
02693
KConfigGroupSaver saver( config,
"KDE Control Module Restrictions" );
02694
return config->
readBoolEntry(menuId,
true);
02695 }
02696
02697 QStringList KApplication::authorizeControlModules(
const QStringList &menuIds)
02698 {
02699
KConfig *config =
KGlobal::config();
02700
KConfigGroupSaver saver( config,
"KDE Control Module Restrictions" );
02701
QStringList result;
02702
for(QStringList::ConstIterator it = menuIds.begin();
02703 it != menuIds.end(); ++it)
02704 {
02705
if (config->
readBoolEntry(*it,
true))
02706 result.append(*it);
02707 }
02708
return result;
02709 }
02710
02711
void KApplication::initUrlActionRestrictions()
02712 {
02713 d->urlActionRestrictions.setAutoDelete(
true);
02714 d->urlActionRestrictions.clear();
02715 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02716 (
"open", QString::null, QString::null, QString::null, QString::null, QString::null, QString::null,
true));
02717 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02718 (
"list", QString::null, QString::null, QString::null, QString::null, QString::null, QString::null,
true));
02719
02720
02721
02722
02723
02724 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02725 (
"link", QString::null, QString::null, QString::null,
":internet", QString::null, QString::null,
true));
02726 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02727 (
"redirect", QString::null, QString::null, QString::null,
":internet", QString::null, QString::null,
true));
02728
02729
02730
02731 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02732 (
"redirect", QString::null, QString::null, QString::null,
"file", QString::null, QString::null,
true));
02733 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02734 (
"redirect",
":internet", QString::null, QString::null,
"file", QString::null, QString::null,
false));
02735
02736
02737 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02738 (
"redirect",
":local", QString::null, QString::null, QString::null, QString::null, QString::null,
true));
02739
02740
02741 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02742 (
"redirect", QString::null, QString::null, QString::null,
"about", QString::null, QString::null,
true));
02743
02744
02745 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02746 (
"redirect", QString::null, QString::null, QString::null,
"=", QString::null, QString::null,
true));
02747
02748
KConfig *config =
KGlobal::config();
02749
KConfigGroupSaver saver( config,
"KDE URL Restrictions" );
02750
int count = config->
readNumEntry(
"rule_count");
02751
QString keyFormat =
QString(
"rule_%1");
02752
for(
int i = 1; i <= count; i++)
02753 {
02754 QString key = keyFormat.arg(i);
02755
QStringList rule = config->
readListEntry(key);
02756
if (rule.count() != 8)
02757
continue;
02758 QString action = rule[0];
02759 QString refProt = rule[1];
02760 QString refHost = rule[2];
02761 QString refPath = rule[3];
02762 QString urlProt = rule[4];
02763 QString urlHost = rule[5];
02764 QString urlPath = rule[6];
02765 QString strEnabled = rule[7].lower();
02766
02767
bool bEnabled = (strEnabled ==
"true");
02768
02769
if (refPath.startsWith(
"$HOME"))
02770 refPath.replace(0, 5, QDir::homeDirPath());
02771
else if (refPath.startsWith(
"~"))
02772 refPath.replace(0, 1, QDir::homeDirPath());
02773
if (urlPath.startsWith(
"$HOME"))
02774 urlPath.replace(0, 5, QDir::homeDirPath());
02775
else if (urlPath.startsWith(
"~"))
02776 urlPath.replace(0, 1, QDir::homeDirPath());
02777
02778
if (refPath.startsWith(
"$TMP"))
02779 refPath.replace(0, 4, KGlobal::dirs()->saveLocation(
"tmp"));
02780
if (urlPath.startsWith(
"$TMP"))
02781 urlPath.replace(0, 4, KGlobal::dirs()->saveLocation(
"tmp"));
02782
02783 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02784 ( action, refProt, refHost, refPath, urlProt, urlHost, urlPath, bEnabled));
02785 }
02786 }
02787
02788 void KApplication::allowURLAction(
const QString &action,
const KURL &_baseURL,
const KURL &_destURL)
02789 {
02790
if (
authorizeURLAction(action, _baseURL, _destURL))
02791
return;
02792
02793 d->urlActionRestrictions.append(
new KApplicationPrivate::URLActionRule
02794 ( action, _baseURL.
protocol(), _baseURL.
host(), _baseURL.
path(-1),
02795 _destURL.
protocol(), _destURL.
host(), _destURL.
path(-1),
true));
02796 }
02797
02798 bool KApplication::authorizeURLAction(
const QString &action,
const KURL &_baseURL,
const KURL &_destURL)
02799 {
02800
if (_destURL.
isEmpty())
02801
return true;
02802
02803
bool result =
false;
02804
if (d->urlActionRestrictions.isEmpty())
02805 initUrlActionRestrictions();
02806
02807
KURL baseURL(_baseURL);
02808 baseURL.
setPath(QDir::cleanDirPath(baseURL.
path()));
02809 QString baseClass = KProtocolInfo::protocolClass(baseURL.
protocol());
02810
KURL destURL(_destURL);
02811 destURL.
setPath(QDir::cleanDirPath(destURL.
path()));
02812 QString destClass = KProtocolInfo::protocolClass(destURL.
protocol());
02813
02814
for(KApplicationPrivate::URLActionRule *rule = d->urlActionRestrictions.first();
02815 rule; rule = d->urlActionRestrictions.next())
02816 {
02817
if ((result != rule->permission) &&
02818 (action == rule->action) &&
02819 rule->baseMatch(baseURL, baseClass) &&
02820 rule->destMatch(destURL, destClass, baseURL, baseClass))
02821 {
02822 result = rule->permission;
02823 }
02824 }
02825
return result;
02826 }
02827
02828
02829 uint
KApplication::keyboardModifiers()
02830 {
02831 Window root;
02832 Window child;
02833
int root_x, root_y, win_x, win_y;
02834 uint keybstate;
02835 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
02836 &root_x, &root_y, &win_x, &win_y, &keybstate );
02837
return keybstate & 0x00ff;
02838 }
02839
02840 uint
KApplication::mouseState()
02841 {
02842 Window root;
02843 Window child;
02844
int root_x, root_y, win_x, win_y;
02845 uint keybstate;
02846 XQueryPointer( qt_xdisplay(), qt_xrootwin(), &root, &child,
02847 &root_x, &root_y, &win_x, &win_y, &keybstate );
02848
return keybstate & 0xff00;
02849 }
02850
02851 void KApplication::installSigpipeHandler()
02852 {
02853
struct sigaction act;
02854 act.sa_handler = SIG_IGN;
02855 sigemptyset( &act.sa_mask );
02856 act.sa_flags = 0;
02857 sigaction( SIGPIPE, &act, 0 );
02858 }
02859
02860
void KApplication::sigpipeHandler(
int)
02861 {
02862
int saved_errno = errno;
02863
02864
#ifndef NDEBUG
02865
char msg[1000];
02866 sprintf(msg,
"*** SIGPIPE *** (ignored, pid = %ld)\n", (
long) getpid());
02867 write(2, msg, strlen(msg));
02868
#endif
02869
02870
02871 errno = saved_errno;
02872 }
02873
02874
bool KApplication::guiEnabled()
02875 {
02876
return kapp && kapp->d->guiEnabled;
02877 }
02878
02879
void KApplication::virtual_hook(
int id,
void* data )
02880 { KInstance::virtual_hook(
id, data ); }
02881
02882
void KSessionManaged::virtual_hook(
int,
void* )
02883 { }
02884
02885
#include "kapplication.moc"