//
//     Copyright 2008 Jim Bublitz <jbublitz@nwinternet.com>
//     Earlier copyrights 1998 - 2007 Jim Bublitz also apply

//                 Generated by twine

// This file is part of PyKDE4.

// PyKDE4 is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of
// the License, or (at your option) any later version.

// PyKDE4 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 program.  If not, see <http://www.gnu.org/licenses/>.

typedef unsigned long Atom;

%ModuleHeaderCode
#include <kapplication.h>
%End


class KApplication : QApplication
{
%TypeHeaderCode
#include <kapplication.h>
%End

%TypeCode
// Convert a Python argv list to a conventional C argc count and argv array.
static char **kdeui_ArgvToC(PyObject *argvlist, int &argc)
{
    char **argv;

    argc = PyList_GET_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_GET_ITEM(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;

    return argv;
}


// Remove arguments from the Python argv list that have been removed from the
// C argv array.
static void kdeui_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


public:
    explicit                KApplication (bool GUIenabled = 1);
    explicit                KApplication (Display* display, Qt::HANDLE visual = 0, Qt::HANDLE colormap = 0);
                            KApplication (Display* display, SIP_PYLIST list, const QByteArray& rAppName, bool GUIenabled = 1) [(Display*, int&, char**, const QByteArray&, bool = 1)];
%MethodCode
// The Python interface is a list of argument strings that is modified.

        int argc;
        char **argv;
        
        // Convert the list.
        if ((argv = kdeui_ArgvToC(a1, argc)) == NULL)
            sipIsErr = 1;
        else
        {
            // Create it now the arguments are right.
            static int nargc;
            nargc = argc;
        
            Py_BEGIN_ALLOW_THREADS
            sipCpp = new sipKApplication(a0, nargc, argv, *a2, a3);
            Py_END_ALLOW_THREADS
        
            // Now modify the original list.
            kdeui_UpdatePyArgv(a1, argc, argv);
        }
%End

    static KApplication*    kApplication ();
    KConfig*                sessionConfig ();
    void                    disableSessionManagement ();
    void                    enableSessionManagement ();
    void                    commitData (QSessionManager& sm);
    void                    saveState (QSessionManager& sm);
    bool                    sessionSaving () const;
    void                    setTopWidget (QWidget* topWidget);
    static QString          tempSaveName (const QString& pFilename);
    static QString          checkRecoverFile (const QString& pFilename, bool& bRecover /Out/);
//ig     static Display*    getDisplay ();
    void                    installX11EventFilter (QWidget* filter);
    void                    removeX11EventFilter (const QWidget* filter);
    QByteArray              startupId () const;
    void                    setStartupId (const QByteArray& startup_id);
    void                    clearStartupId ();
    void                    setSynchronizeClipboard (bool synchronize);
    unsigned long           userTimestamp () const;
    void                    updateRemoteUserTimestamp (const QString& service, int time = 0);
    bool                    notify (QObject* receiver, QEvent* event);
//ig     int                xErrhandler (Display*, void*);
    int                     xioErrhandler (Display*);
//ig     void               iceIOErrorHandler (_IceConn* conn);
    bool loadedByKdeinit;
    void                    updateUserTimestamp (int time = 0);
    void                    reparseConfiguration ();
    void                    quit ();

signals:
    void                    saveYourself ();

protected:
                            KApplication (bool GUIenabled, const KComponentData& cData);
                            KApplication (Display* display, Qt::HANDLE visual, Qt::HANDLE colormap, const KComponentData& cData);
//ig     bool               x11EventFilter (XEvent*);

private:
                            KApplication (const KApplication&);
                            KApplication (bool, bool);

};   // KApplication


