kdecore Library API Documentation

kapplication.h

00001 /* This file is part of the KDE libraries
00002     Copyright (C) 1997 Matthias Kalle Dalheimer (kalle@kde.org)
00003     Copyright (c) 1998, 1999 KDE Team
00004 
00005     This library is free software; you can redistribute it and/or
00006     modify it under the terms of the GNU Library General Public
00007     License as published by the Free Software Foundation; either
00008     version 2 of the License, or (at your option) any later version.
00009 
00010     This library is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013     Library General Public License for more details.
00014 
00015     You should have received a copy of the GNU Library General Public License
00016     along with this library; see the file COPYING.LIB.  If not, write to
00017     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00018     Boston, MA 02111-1307, USA.
00019 */
00020 
00021 // $Id: kapplication.h,v 1.322 2004/12/29 15:45:32 harald Exp $
00022 
00023 #ifndef _KAPP_H
00024 #define _KAPP_H
00025 
00026 // Version macros. Never put this further down.
00027 #include "kdeversion.h"
00028 #include "kdelibs_export.h"
00029 
00030 class KConfig;
00031 class KCharsets;
00032 class DCOPClient;
00033 class DCOPObject;
00034 
00035 typedef unsigned long Atom;
00036 #if !defined(Q_WS_X11)
00037 typedef void Display;
00038 #endif
00039 
00040 #include <qapplication.h>
00041 #include <qpixmap.h>
00042 #include <kinstance.h>
00043 
00044 struct _IceConn;
00045 class QPopupMenu;
00046 class QStrList;
00047 class KSessionManaged;
00048 class KStyle;
00049 class KURL;
00050 
00051 #define kapp KApplication::kApplication()
00052 
00053 class KApplicationPrivate;
00054 
00097 class KDECORE_EXPORT KApplication : public QApplication, public KInstance
00098 {
00099 
00100   Q_OBJECT
00101 public:
00102   enum CaptionLayout { CaptionAppLast=1, CaptionAppFirst, CaptionNoApp };
00103 
00117   KApplication( bool allowStyles=true, bool GUIenabled=true);
00118 
00119 #ifdef Q_WS_X11
00120 
00143   KApplication(Display *display, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0,
00144                bool allowStyles=true);
00145 
00170   KApplication(Display *display, int& argc, char** argv, const QCString& rAppName,
00171                bool allowStyles=true, bool GUIenabled=true);
00172 #endif
00173 
00196   // REMOVE FOR KDE 4.0 - using it only gives crashing applications because
00197   // KCmdLineArgs::init isn't called
00198  KApplication(int& argc, char** argv,
00199               const QCString& rAppName, bool allowStyles=true, bool GUIenabled=true) KDE_DEPRECATED;
00200 
00204   static void addCmdLineOptions();
00205 
00206   virtual ~KApplication();
00207 
00218   static KApplication* kApplication() { return KApp; }
00219 
00227   KConfig* sessionConfig();
00228 
00237   bool isRestored() const { return QApplication::isSessionRestored(); }
00238 
00245   void disableSessionManagement();
00246 
00253   void enableSessionManagement();
00254 
00258   enum ShutdownConfirm {
00262     ShutdownConfirmDefault = -1,
00266     ShutdownConfirmNo = 0,
00270     ShutdownConfirmYes = 1
00271   };
00272 
00276   enum ShutdownType {
00280     ShutdownTypeDefault = -1,
00284     ShutdownTypeNone = 0,
00288     ShutdownTypeReboot = 1,
00292     ShutdownTypeHalt = 2
00293   };
00294 
00298   enum ShutdownMode {
00302     ShutdownModeDefault = -1,
00307     ShutdownModeSchedule = 0,
00311     ShutdownModeTryNow = 1,
00315     ShutdownModeForceNow = 2,
00319     ShutdownModeInteractive = 3
00320   };
00321 
00337   bool requestShutDown( ShutdownConfirm confirm = ShutdownConfirmDefault,
00338                         ShutdownType sdtype = ShutdownTypeDefault,
00339             ShutdownMode sdmode = ShutdownModeDefault );
00340 
00354     void propagateSessionManager();
00355 
00356     /*
00357      * Reimplemented for internal purposes, mainly the highlevel
00358      *  handling of session management with KSessionManaged.
00359      * @internal
00360      */
00361   void commitData( QSessionManager& sm );
00362 
00363     /*
00364      * Reimplemented for internal purposes, mainly the highlevel
00365      *  handling of session management with KSessionManaged.
00366      * @internal
00367      */
00368   void saveState( QSessionManager& sm );
00369 
00379   bool sessionSaving() const;
00380 
00387   static DCOPClient *dcopClient();
00388 
00393   static void disableAutoDcopRegistration();
00394 
00399   QPixmap icon() const;
00400 
00405   QString iconName() const;
00406 
00411   QPixmap miniIcon() const;
00412 
00417   QString miniIconName() const;
00418 
00429   void setTopWidget( QWidget *topWidget );
00430 
00443   void invokeHelp( const QString& anchor,
00444                    const QString& appname,
00445                    const QCString& startup_id ) const;
00446 
00447   // KDE4 merge with above with startup_id = ""
00448   void invokeHelp( const QString& anchor = QString::null,
00449                    const QString& appname = QString::null ) const;
00450 
00465   void invokeHTMLHelp( const QString& aFilename, const QString& aTopic = QString::null ) const KDE_DEPRECATED;
00466 
00475   void invokeMailer( const QString &address, const QString &subject, const QCString& startup_id );
00476   // KDE4 merge with above with startup_id = ""
00477   void invokeMailer( const QString &address, const QString &subject );
00478 
00488   void invokeMailer( const KURL &mailtoURL, const QCString& startup_id, bool allowAttachments );
00489   // KDE4 merge with above with allowAttachments = false
00490   void invokeMailer( const KURL &mailtoURL, const QCString& startup_id );
00491   // KDE4 merge with above with startup_id = ""
00492   void invokeMailer( const KURL &mailtoURL );
00493 
00509   void invokeMailer(const QString &to, const QString &cc, const QString &bcc,
00510                     const QString &subject, const QString &body,
00511                     const QString &messageFile, const QStringList &attachURLs,
00512                     const QCString& startup_id );
00513   // KDE4 merge with above with startup_id = ""
00514   void invokeMailer(const QString &to, const QString &cc, const QString &bcc,
00515                     const QString &subject, const QString &body,
00516                     const QString &messageFile = QString::null, const QStringList &attachURLs = QStringList());
00517 
00518 public slots:
00529   void invokeBrowser( const QString &url, const QCString& startup_id );
00530   // KDE4 merge with above with startup_id = ""
00531   void invokeBrowser( const QString &url );
00532 
00540   void cut();
00541 
00549   void copy();
00550 
00558   void paste();
00559 
00585   void clear();
00586 
00594   void selectAll();
00595 
00596 public:
00602   static QCString launcher();
00603 
00624   static int startServiceByName( const QString& _name, const QString &URL,
00625                 QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id = "", bool noWait = false );
00626 
00647   static int startServiceByName( const QString& _name, const QStringList &URLs=QStringList(),
00648                 QString *error=0, QCString *dcopService=0, int *pid=0, const QCString &startup_id = "", bool noWait = false );
00649 
00670   static int startServiceByDesktopPath( const QString& _name, const QString &URL,
00671                 QString *error=0, QCString *dcopService=0, int *pid = 0, const QCString &startup_id = "", bool noWait = false );
00672 
00693   static int startServiceByDesktopPath( const QString& _name, const QStringList &URLs=QStringList(),
00694                 QString *error=0, QCString *dcopService=0, int *pid = 0, const QCString &startup_id = "", bool noWait = false );
00695 
00716   static int startServiceByDesktopName( const QString& _name, const QString &URL,
00717                 QString *error=0, QCString *dcopService=0, int *pid = 0, const QCString &startup_id = "", bool noWait = false );
00718 
00739   static int startServiceByDesktopName( const QString& _name, const QStringList &URLs=QStringList(),
00740                 QString *error=0, QCString *dcopService=0, int *pid = 0, const QCString &startup_id = "", bool noWait = false );
00741 
00761   static int kdeinitExec( const QString& name, const QStringList &args,
00762                 QString *error, int *pid, const QCString& startup_id );
00763   // KDE4 merge with above with startup_id = ""
00764   static int kdeinitExec( const QString& name, const QStringList &args=QStringList(),
00765                 QString *error=0, int *pid = 0 );
00766 
00784   static int kdeinitExecWait( const QString& name, const QStringList &args,
00785                 QString *error, int *pid, const QCString& startup_id );
00786   // KDE4 merge with above with startup_id = ""
00787   static int kdeinitExecWait( const QString& name, const QStringList &args=QStringList(),
00788                 QString *error=0, int *pid = 0 );
00789 
00798   QString caption() const;
00799 
00803   KDE_DEPRECATED KStyle* kstyle() const { return 0; }
00804 
00822   QString makeStdCaption( const QString &userCaption,
00823                           bool withAppName=true, bool modified=false ) const;
00824 
00832   QString tempSaveName( const QString& pFilename ) const;
00833 
00843   QString checkRecoverFile( const QString& pFilename, bool& bRecover ) const;
00844 
00845 #ifdef Q_WS_X11
00846 
00850   Display *getDisplay() { return display; }
00851 #endif
00852 
00860   void enableStyles();
00861 
00869   void disableStyles();
00870 
00880   void installX11EventFilter( QWidget* filter );
00881 
00886   void removeX11EventFilter( const QWidget* filter );
00887 
00892   static int random();
00893 
00899   static QString randomString(int length);
00900 
00910   void addKipcEventMask(int id);
00911 
00920   void removeKipcEventMask(int id);
00921 
00927   QCString startupId() const;
00928 
00936   void setStartupId( const QCString& startup_id );
00937 
00944   void updateUserTimestamp( unsigned long time = 0 );
00945   
00951   unsigned long userTimestamp() const;
00952 
00961   void updateRemoteUserTimestamp( const QCString& dcopId, unsigned long time = 0 );
00962   
00968   QString geometryArgument() const;
00969 
00974   void installKDEPropertyMap();
00975 
00981   bool authorize(const QString &genericAction);
00982 
00990   bool authorizeKAction(const char *action);
00991 
01005   bool authorizeURLAction(const QString &action, const KURL &baseURL, const KURL &destURL);
01006 
01016   void allowURLAction(const QString &action, const KURL &_baseURL, const KURL &_destURL);
01017 
01025   bool authorizeControlModule(const QString &menuId);
01026   
01035   QStringList authorizeControlModules(const QStringList &menuIds);
01036 
01037   // Same values as ShiftMask etc. in X.h
01038   enum { ShiftModifier = 1<<0,
01039          LockModifier = 1<<1,
01040          ControlModifier = 1<<2,
01041          Modifier1 = 1<<3,
01042          Modifier2 = 1<<4,
01043          Modifier3 = 1<<5,
01044          Modifier4 = 1<<6,
01045          Modifier5 = 1<<7 };
01049   static uint keyboardModifiers();
01050 
01052   enum { Button1Pressed = 1<<8,
01053          Button2Pressed = 1<<9,
01054          Button3Pressed = 1<<10,
01055          Button4Pressed = 1<<11,
01056          Button5Pressed = 1<<12 };
01061   static uint mouseState() KDE_DEPRECATED;
01062 
01063 
01064 public slots:
01071   void ref();
01072 
01077   void deref();
01078 
01079 protected:
01083   KApplication( bool allowStyles, bool GUIenabled, KInstance* _instance );
01084 
01085 #ifdef Q_WS_X11
01089   KApplication( Display *display, Qt::HANDLE visual, Qt::HANDLE colormap,
01090           bool allowStyles, KInstance* _instance );
01091 
01095   bool x11EventFilter( XEvent * );
01096 
01097   Display *display;
01098 #endif
01099   Atom kipcCommAtom;
01100   int kipcEventMask;
01101 
01103   static KApplication *KApp;
01104   int pArgc;
01105 
01137   void invokeEditSlot( const char *slot );
01138 
01139 private slots:
01140   void dcopFailure(const QString &);
01141   void dcopBlockUserInput( bool );
01142   void x11FilterDestroyed();
01143   void checkAppStartedSlot();
01144 
01145 private:
01146   QString sessionConfigName() const;
01147   KConfig* pSessionConfig; //instance specific application config object
01148   static DCOPClient *s_DCOPClient; // app specific application communication client
01149   static bool s_dcopClientNeedsPostInit;
01150   QString aCaption; // the name for the window title
01151   bool bSessionManagement;
01152   QPixmap aIconPixmap; // BIC (KDE 4) make a pointer, to avoid creating if noGUI
01153   QPixmap aMiniIconPixmap; // BIC (KDE 4) make a pointer, to avoid creating if noGUI
01154   QString aIconName;
01155   QString aMiniIconName;
01156   bool useStyles;
01157   QWidget *smw;
01158 
01159   void init( bool GUIenabled );
01160 
01161   void parseCommandLine( ); // Handle KDE arguments (Using KCmdLineArgs)
01162 
01163   void read_app_startup_id();
01164 
01165   void dcopAutoRegistration();
01166   void dcopClientPostInit();
01167   void initUrlActionRestrictions();
01168 
01169 public:
01173   bool notify(QObject *receiver, QEvent *event);
01174 
01178   int xErrhandler( Display*, void* );
01179 
01183   int xioErrhandler( Display* );
01184 
01188   void iceIOErrorHandler( _IceConn *conn );
01189 
01193   static bool loadedByKdeinit;
01194 
01198   static void startKdeinit();
01199 
01203   enum SettingsCategory { SETTINGS_MOUSE, SETTINGS_COMPLETION, SETTINGS_PATHS,
01204          SETTINGS_POPUPMENU, SETTINGS_QT, SETTINGS_SHORTCUTS };
01205 
01214   static QPalette createApplicationPalette();
01215 
01220   static QPalette createApplicationPalette( KConfig *config, int contrast );
01221 
01229   static void installSigpipeHandler();
01230 
01237   static bool guiEnabled();
01238 
01239 signals:
01246   void kdisplayPaletteChanged();
01247 
01255   void kdisplayStyleChanged();
01256 
01268   void kdisplayFontChanged();
01269 
01275   void appearanceChanged();
01276 
01280   void toolbarAppearanceChanged(int);
01281 
01287   void backgroundChanged(int desk);
01288 
01295   void settingsChanged(int category);
01296 
01301   void iconChanged(int group);
01302 
01312   void kipcMessage(int id, int data);
01313 
01343   void saveYourself();
01344 
01352   void shutDown();
01353 
01354 private:
01355   void propagateSettings(SettingsCategory category);
01356   void kdisplaySetPalette();
01357   void kdisplaySetStyle();
01358   void kdisplaySetFont();
01359   void applyGUIStyle();
01360   static void sigpipeHandler(int);
01361 
01362   int captionLayout;
01363 
01364   KApplication(const KApplication&);
01365   KApplication& operator=(const KApplication&);
01366 protected:
01367   virtual void virtual_hook( int id, void* data );
01368 private:
01369   KApplicationPrivate* d;
01370 };
01371 
01372 
01390 KDECORE_EXPORT bool checkAccess(const QString& pathname, int mode);
01391 
01392 class KSessionManagedPrivate;
01393 
01410 class KDECORE_EXPORT KSessionManaged
01411 {
01412 public:
01413   KSessionManaged();
01414   virtual ~KSessionManaged();
01415 
01425   virtual bool saveState( QSessionManager& sm );
01435   virtual bool commitData( QSessionManager& sm );
01436 
01437 protected:
01438   virtual void virtual_hook( int id, void* data );
01439 private:
01440   KSessionManagedPrivate *d;
01441 };
01442 
01443 
01444 #endif
01445 
KDE Logo
This file is part of the documentation for kdecore Library Version 3.3.90.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Mar 30 10:09:37 2005 by doxygen 1.3.9.1 written by Dimitri van Heesch, © 1997-2003