//
//     Copyright 2006 Jim Bublitz <jbublitz@nwinternet.com>
//     Earlier copyrights 1998 - 2005 Jim Bublitz and/or Phil Thompson
//     may also apply


//                 Generated by preSip
//            module kdecore  version KDE 3.5.3


// This software is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// the License, or (at your option) any later version.
//
// This software is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public
// License along with this library; see the file COPYING.
// If not, write to the Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


class KApplication : QApplication, KInstance
{
%TypeHeaderCode
#include <kapplication.h>
#include <kcmdlineargs.h>
extern char **pyArgvToC(PyObject *argvlist,int *argcp);
extern void updatePyArgv(PyObject *argvlist,int argc,char **argv);
%End


public:

    enum CaptionLayout
    {
        CaptionAppLast, 
        CaptionAppFirst, 
        CaptionNoApp
    };

                         KApplication (bool = 1, bool = 1);

%If ( KDE_3_3_0 -  )
//ig                          KApplication (Display*, Qt::HANDLE = 0, Qt::HANDLE = 0, bool = 1);
%End

//ig                          KApplication (Display*, int&, char**, const QCString&, bool = 1, bool = 1);
                         KApplication (SIP_PYLIST, QCString&, bool = 1, bool = 1) [(int&, char**, const QCString&, bool = 1, bool = 1)];
%MethodCode
//takes argv | (a Python list of strings) | rAppName | (Python string) | allowStyles | (bool = 1)  | GUIenabled | (bool = 1)

        int argc, nargc;
        char **argv;

        // Convert the list.

        if ((argv = pyArgvToC(a0, &argc)) == NULL)
            return NULL;

        // Create it now the arguments are right.

        nargc = argc;

        Py_BEGIN_ALLOW_THREADS

        // The following two lines simulate the actual ctor call
        // which is commented out below
        KCmdLineArgs::init (nargc, argv, (char *)"unknown", (char *)"KDE Application", NULL, false);
        sipCpp = new sipKApplication((bool)a1,(bool)a2);

        // This method calls KCmdLineArgs::initIgnore, which is a private method
//        sipCpp = new sipKApplication (nargc,argv, qc, a1, a2);

        Py_END_ALLOW_THREADS

        // Now modify the original list.

        updatePyArgv(a0, argc, argv);
%End

    static void          addCmdLineOptions ();
    static KApplication* kApplication ();
    KConfig*             sessionConfig ();
    bool                 isRestored () const;
    void                 disableSessionManagement ();

%If ( KDE_3_2_0 -  )
    void                 enableSessionManagement ();
%End


    enum ShutdownConfirm
    {
        ShutdownConfirmDefault, 
        ShutdownConfirmNo, 
        ShutdownConfirmYes
    };


    enum ShutdownType
    {
        ShutdownTypeDefault, 
        ShutdownTypeNone, 
        ShutdownTypeReboot, 
        ShutdownTypeHalt
    };


    enum ShutdownMode
    {
        ShutdownModeDefault, 
        ShutdownModeSchedule, 
        ShutdownModeTryNow, 
        ShutdownModeForceNow, 
        ShutdownModeInteractive
    };

    bool                 requestShutDown (KApplication::ShutdownConfirm = ShutdownConfirmDefault , KApplication::ShutdownType = ShutdownTypeDefault , KApplication::ShutdownMode = ShutdownModeDefault );
    void                 propagateSessionManager ();
    void                 commitData (QSessionManager&);
    void                 saveState (QSessionManager&);

%If ( KDE_3_1_1 -  )
    bool                 sessionSaving () const;
%End

    static DCOPClient*   dcopClient ();
    static void          disableAutoDcopRegistration ();
    QPixmap              icon () const;
    QString              iconName () const;
    QPixmap              miniIcon () const;
    QString              miniIconName () const;
    void                 setTopWidget (QWidget*);

%If ( KDE_3_2_0 -  )
    void                 invokeHelp (const QString&, const QString&, const QCString&) const;
%End

    void                 invokeHelp (const QString& = QString ::null , const QString& = QString ::null ) const;
    void                 invokeHTMLHelp (const QString&, const QString& = QString ::null ) const;

%If ( KDE_3_2_0 -  )
    void                 invokeMailer (const QString&, const QString&, const QCString&);
%End

    void                 invokeMailer (const QString&, const QString&);

%If ( KDE_3_3_0 -  )
    void                 invokeMailer (const KURL&, const QCString&, bool);
%End


%If ( KDE_3_2_0 -  )
    void                 invokeMailer (const KURL&, const QCString&);
%End

    void                 invokeMailer (const KURL&);

%If ( KDE_3_2_0 -  )
    void                 invokeMailer (const QString&, const QString&, const QString&, const QString&, const QString&, const QString&, const QStringList&, const QCString&);
%End

    void                 invokeMailer (const QString&, const QString&, const QString&, const QString&, const QString&, const QString& = QString ::null , const QStringList& = QStringList ());

public slots:

%If ( KDE_3_2_0 -  )
    void                 invokeBrowser (const QString&, const QCString&);
%End

    void                 invokeBrowser (const QString&);

%If ( KDE_3_2_0 -  )
    void                 cut ();
    void                 copy ();
    void                 paste ();
    void                 clear ();
    void                 selectAll ();
%End


public:
    static QCString      launcher ();
    static int           startServiceByName (const QString&, const QString&, QString* /Out/, QCString* /Out/, int*, const QCString& = QCString ("" ), bool = 0);
    static int           startServiceByName (const QString&, const QStringList&, QString* /Out/, QCString* /Out/, int*, const QCString& = QCString ("" ), bool = 0);
    static int           startServiceByDesktopPath (const QString&, const QString&, QString* /Out/, QCString* /Out/, int*, const QCString& = QCString ("" ), bool = 0);
    static int           startServiceByDesktopPath (const QString&, const QStringList&, QString* /Out/, QCString* /Out/, int*, const QCString& = QCString ("" ), bool = 0);
    static int           startServiceByDesktopName (const QString&, const QString&, QString* /Out/, QCString* /Out/, int*, const QCString& = QCString ("" ), bool = 0);
    static int           startServiceByDesktopName (const QString&, const QStringList&, QString* /Out/, QCString* /Out/, int*, const QCString& = QCString ("" ), bool = 0);

%If ( KDE_3_2_0 -  )
    static int           kdeinitExec (const QString&, const QStringList&, QString* /Out/, int*, QCString&);
%End

    static int           kdeinitExec (const QString&, const QStringList&, QString* /Out/, int*);

%If ( KDE_3_2_0 -  )
    static int           kdeinitExecWait (const QString&, const QStringList&, QString* /Out/, int*, QCString&);
%End

    static int           kdeinitExecWait (const QString&, const QStringList&, QString* /Out/, int*);
    QString              caption () const;
//ig     KStyle*              kstyle () const;
    QString              makeStdCaption (const QString&, bool = 1, bool = 0) const;
    QString              tempSaveName (const QString&) const;
    QString              checkRecoverFile (const QString&, bool&) const;
    Display*             getDisplay ();
    void                 enableStyles ();
    void                 disableStyles ();
    void                 installX11EventFilter (QWidget*);

%If ( KDE_3_2_0 -  )
    void                 removeX11EventFilter (const QWidget*);
%End

    static int           random ();
    static QString       randomString (int);
    void                 addKipcEventMask (int);
    void                 removeKipcEventMask (int);
    QCString             startupId () const;
    void                 setStartupId (const QCString&);

%If ( KDE_3_2_0 -  )
    void                 updateUserTimestamp (ulong = 0);

%If ( KDE_3_2_3 -  )
    ulong                userTimestamp () const;

%If ( KDE_3_3_0 -  )
    void                 updateRemoteUserTimestamp (const QCString&, ulong = 0);
%End

%End

%End

    QString              geometryArgument () const;
    void                 installKDEPropertyMap ();
    bool                 authorize (const QString&);
    bool                 authorizeKAction (const char*);

%If ( KDE_3_1_0 -  )
    bool                 authorizeURLAction (const QString&, const KURL&, const KURL&);

%If ( KDE_3_2_0 -  )
    void                 allowURLAction (const QString&, const KURL&, const KURL&);
    bool                 authorizeControlModule (const QString&);
    QStringList          authorizeControlModules (const QStringList&);

%If ( KDE_3_4_0 -  )
    static ButtonState   keyboardMouseState ();
%End

%End


    enum 
    {
        ShiftModifier, 
        LockModifier, 
        ControlModifier, 
        Modifier1, 
        Modifier2, 
        Modifier3, 
        Modifier4, 
        Modifier5
    };

    static uint          keyboardModifiers ();

    enum 
    {
        Button1Pressed, 
        Button2Pressed, 
        Button3Pressed, 
        Button4Pressed, 
        Button5Pressed
    };

    static uint          mouseState ();
%End


public slots:
    void                 ref ();
    void                 deref ();

protected:
                         KApplication (bool, bool, KInstance*);

%If ( KDE_3_3_0 -  )
//ig                          KApplication (Display*, Qt::HANDLE, Qt::HANDLE, bool, KInstance*);
%End

//ig     bool                 x11EventFilter (XEvent*);

%If ( KDE_3_2_0 -  )
    void                 invokeEditSlot (const char*);
%End


public:
    bool                 notify (QObject*, QEvent*);

%If ( KDE_3_2_0 -  )
//ig     int                  xErrhandler (Display*, void*);
//ig     int                  xioErrhandler (Display*);
%End


%If ( KDE_3_0_1 -  )
//ig     void                 iceIOErrorHandler (_IceConn*);
%End

    bool                 loadedByKdeinit;
    static void          startKdeinit ();

    enum SettingsCategory
    {
        SETTINGS_MOUSE, 
        SETTINGS_COMPLETION, 
        SETTINGS_PATHS, 
        SETTINGS_POPUPMENU, 
        SETTINGS_QT, 
        SETTINGS_SHORTCUTS
    };


%If ( KDE_3_1_0 -  )
    static QPalette      createApplicationPalette ();
    static QPalette      createApplicationPalette (KConfig*, int);

%If ( KDE_3_2_0 -  )
    static void          installSigpipeHandler ();
    static bool          guiEnabled ();
%End

%End


signals:
    void                 kdisplayPaletteChanged ();
    void                 kdisplayStyleChanged ();
    void                 kdisplayFontChanged ();
    void                 appearanceChanged ();
    void                 toolbarAppearanceChanged (int);
    void                 backgroundChanged (int);
    void                 settingsChanged (int);
    void                 iconChanged (int);
    void                 kipcMessage (int, int);
    void                 saveYourself ();
    void                 shutDown ();

private:
                         KApplication (const KApplication&);

protected:
//igx     virtual void         virtual_hook (int, void*);

public:

%If (  - KDE_3_2_0 )
    int                  xioErrhandler ();
%End


};  // class KApplication


class KSessionManaged
{
%TypeHeaderCode
#include <kapplication.h>
%End


public:
                         KSessionManaged ();
    virtual bool         saveState (QSessionManager&);
    virtual bool         commitData (QSessionManager&);

protected:
//igx     virtual void         virtual_hook (int, void*);

};  // class KSessionManaged

typedef ulong Atom;
//ig typedef void Display;
//ig bool                 checkAccess (const QString&, int);


%ModuleCode
#include <string.h>

// Convert a Python argv list to a conventional C argc count and argv array.
char **pyArgvToC(PyObject *argvlist,int *argcp)
{
    int argc;
    char **argv;

    argc = PyList_Size(argvlist);

    // Allocate space for two copies of the argument pointers, plus the
    // terminating NULL.
    if ((argv = (char **)sipMalloc(2 * (argc + 1) * sizeof (char *))) == NULL)
        return NULL;

    // Convert the list.
    for (int a = 0; a < argc; ++a)
    {
        char *arg;

        // Get the argument and allocate memory for it.
        if ((arg = PyString_AsString(PyList_GetItem(argvlist,a))) == NULL ||
            (argv[a] = (char *)sipMalloc(strlen(arg) + 1)) == NULL)
            return NULL;

        // Copy the argument and save a pointer to it.
        strcpy(argv[a],arg);
        argv[a + argc + 1] = argv[a];
    }

    argv[argc + argc + 1] = argv[argc] = NULL;

    *argcp = argc;

    return argv;
}


// Remove arguments from the Python argv list that have been removed from the
// C argv array.
void updatePyArgv(PyObject *argvlist,int argc,char **argv)
{
    for (int a = 0, na = 0; a < argc; ++a)
    {
        // See if it was removed.
        if (argv[na] == argv[a + argc + 1])
            ++na;
        else
            PyList_SetSlice(argvlist,na,na + 1,NULL);
    }
}
%End
