//
//     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/>.


class KServiceType : KSycocaEntry
{
%TypeHeaderCode
#include <kservicetype.h>
%End


public:
    typedef KSharedPtr<KServiceType> Ptr;

    typedef QList<KServiceType::Ptr> List;

    explicit                KServiceType (KDesktopFile* config);
                            KServiceType (QDataStream& _str, int offset);
    QString                 comment () const;
    QString                 desktopEntryPath () const;
    bool                    isDerived () const;
    QString                 parentServiceType () const;
    bool                    inherits (const QString& servTypeName) const;
    QVariant::Type          propertyDef (const QString& _name) const;
    QStringList             propertyDefNames () const;
    QMap<QString,QVariant::Type>  propertyDefs () const;
    KServiceType::Ptr       parentType ();
    void                    setServiceOffersOffset (int offset);
    int                     serviceOffersOffset () const;
    static KServiceType::Ptr  serviceType (const QString& _name);
    static KServiceType::List  allServiceTypes ();

protected:
//ig                        KServiceType (KServiceTypePrivate& dd);
//ig                        KServiceType (KServiceTypePrivate& dd, const QString& _name, const QString& _comment);
};   // KServiceType



%MappedType QList<KServiceType::Ptr>
{
%TypeHeaderCode
#include <qlist.h>
%End

%ConvertFromTypeCode
    // Create the list.
    PyObject *l;

    if ((l = PyList_New(sipCpp->size())) == NULL)
        return NULL;

    // Set the list elements.
    for (int i = 0; i < sipCpp->size(); ++i)
    {
        KServiceType::Ptr *t = new KServiceType::Ptr (sipCpp->at(i));
        PyObject *tobj;

        if ((tobj = sipConvertFromNewType(t->data(), sipType_KServiceType, sipTransferObj)) == NULL)
        {
            Py_DECREF(l);
            delete t;

            return NULL;
        }

        PyList_SET_ITEM(l, i, tobj);
    }

    return l;
%End

%ConvertToTypeCode
    // Check the type if that is all that is required.
    if (sipIsErr == NULL)
    {
        if (!PyList_Check(sipPy))
            return 0;

        for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
            if (!sipCanConvertToType(PyList_GET_ITEM(sipPy, i), sipType_KServiceType, SIP_NOT_NONE))
                return 0;

        return 1;
    }

    QList<KServiceType::Ptr> *ql = new QList<KServiceType::Ptr>;
 
    for (int i = 0; i < PyList_GET_SIZE(sipPy); ++i)
    {
        int state;
        KServiceType *t = reinterpret_cast<KServiceType *>(sipConvertToType(PyList_GET_ITEM(sipPy, i), sipType_KServiceType, sipTransferObj, SIP_NOT_NONE, &state, sipIsErr));
 
        if (*sipIsErr)
        {
            sipReleaseType(t, sipType_KServiceType, state);

            delete ql;
            return 0;
        }

        KSharedPtr<KServiceType> *tptr = new KSharedPtr<KServiceType> (t);

        ql->append(*tptr);

        sipReleaseType(t, sipType_KServiceType, state);
    }
 
    *sipCppPtr = ql;
 
    return sipGetState(sipTransferObj);
%End
};


%MappedType QMap<QString,QVariant::Type>
{
%TypeHeaderCode
#include <qmap.h>
%End

%ConvertFromTypeCode
    // Create the dictionary.
    PyObject *d = PyDict_New();

    if (!d)
        return NULL;

    // Set the dictionary elements.
    QMap<QString, QVariant::Type>::const_iterator i = sipCpp->constBegin();

    while (i != sipCpp->constEnd())
    {
        QString *t1 = new QString (i.key());
        QVariant::Type t2 =  (QVariant::Type) (i.value());

        PyObject *t1obj = sipConvertFromNewType(t1, sipType_QString, sipTransferObj);
        PyObject *t2obj = PyInt_FromLong ((long) t2);

        if (t1obj == NULL || t2obj == NULL || PyDict_SetItem(d, t1obj, t2obj) < 0)
        {
            Py_DECREF(d);

            if (t1obj)
                Py_DECREF(t1obj);
            else
                delete t1;

            if (t2obj)
                Py_DECREF(t2obj);

            return NULL;
        }

        Py_DECREF(t1obj);
        Py_DECREF(t2obj);

        ++i;
    }

    return d;
%End

%ConvertToTypeCode
    PyObject *t1obj, *t2obj;
    SIP_SSIZE_T i = 0;

    // Check the type if that is all that is required.
    if (sipIsErr == NULL)
    {
        if (!PyDict_Check(sipPy))
            return 0;

        while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
        {
            if (!sipCanConvertToType(t1obj, sipType_QString, SIP_NOT_NONE))
                return 0;

            if (!PyInt_Check (t2obj))
                return 0;
        } 

        return 1;
    }

    QMap<QString, QVariant::Type> *qm = new QMap<QString, QVariant::Type>;
 
    while (PyDict_Next(sipPy, &i, &t1obj, &t2obj))
    {
        int state1;

        QString *t1 = reinterpret_cast<QString *>(sipConvertToType(t1obj, sipType_QString, sipTransferObj, SIP_NOT_NONE, &state1, sipIsErr));
        QVariant::Type t2 = (QVariant::Type)PyInt_AS_LONG (t2obj);
 
        if (*sipIsErr)
        {
            sipReleaseType(t1, sipType_QString, state1);

            delete qm;
            return 0;
        }

        qm->insert(*t1, t2);

        sipReleaseType(t1, sipType_QString, state1);
    }
 
    *sipCppPtr = qm;
 
    return sipGetState(sipTransferObj);
%End
};

