~kubuntu-members/korundum/4.11

« back to all changes in this revision

Viewing changes to plasma/src/plasmahandlers.cpp

  • Committer: Ian Monroe
  • Date: 2010-11-21 15:55:01 UTC
  • Revision ID: git-v1:c37670e4e3c59f5eb2ba112f5341a5e706217f6f
Split up Smoke into Qt and KDE directories. 
Move libsmoke stuff into the generator directory
Split up Ruby into qtruby and korundum directories

svn path=/trunk/KDE/kdebindings/ruby/; revision=1199320

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/***************************************************************************
2
 
                 plasmahandlers.cpp  -  Plasma specific marshallers
3
 
                             -------------------
4
 
    begin                : Sun Sep 28 2003
5
 
    copyright            : (C) 2003 by Richard Dale
6
 
    email                : Richard_Dale@tipitina.demon.co.uk
7
 
 ***************************************************************************/
8
 
 
9
 
/***************************************************************************
10
 
 *                                                                         *
11
 
 *   This program is free software; you can redistribute it and/or modify  *
12
 
 *   it under the terms of the GNU General Public License as published by  *
13
 
 *   the Free Software Foundation; either version 2 of the License, or     *
14
 
 *   (at your option) any later version.                                   *
15
 
 *                                                                         *
16
 
 ***************************************************************************/
17
 
 
18
 
#include <ruby.h>
19
 
 
20
 
#include <qtruby.h>
21
 
#include <smokeruby.h>
22
 
#include <marshall_macros.h>
23
 
#include <smoke/qtcore_smoke.h>
24
 
 
25
 
#include <plasma/packagestructure.h>
26
 
#include <plasma/containment.h>
27
 
#include <plasma/applet.h>
28
 
#include <plasma/datacontainer.h>
29
 
 
30
 
void marshall_PackageStructurePtr(Marshall *m) {
31
 
    switch(m->action()) {
32
 
    case Marshall::FromVALUE: 
33
 
    {
34
 
        break;
35
 
    }
36
 
 
37
 
    case Marshall::ToVALUE: 
38
 
    {
39
 
        KSharedPtr<Plasma::PackageStructure> *ptr = new KSharedPtr<Plasma::PackageStructure>(*(KSharedPtr<Plasma::PackageStructure>*)m->item().s_voidp);
40
 
        if (ptr == 0) {
41
 
            *(m->var()) = Qnil;
42
 
            break;
43
 
        }
44
 
        Plasma::PackageStructure * package = ptr->data();
45
 
 
46
 
        VALUE obj = getPointerObject(package);
47
 
        if (obj == Qnil) {
48
 
            smokeruby_object  * o = ALLOC(smokeruby_object);
49
 
            o->smoke = m->smoke();
50
 
            o->classId = m->smoke()->idClass("Plasma::PackageStructure").index;
51
 
            o->ptr = package;
52
 
            o->allocated = false;
53
 
            obj = set_obj_info("Plasma::PackageStructure", o);
54
 
        }
55
 
 
56
 
        *(m->var()) = obj;              
57
 
 
58
 
        if (m->cleanup()) {
59
 
        }
60
 
        break;
61
 
    }
62
 
 
63
 
    default:
64
 
        m->unsupported();
65
 
        break;
66
 
    }
67
 
}
68
 
 
69
 
void marshall_QHashQStringQVariant(Marshall *m) {
70
 
        switch(m->action()) {
71
 
        case Marshall::FromVALUE:
72
 
        {
73
 
                VALUE hash = *(m->var());
74
 
                if (TYPE(hash) != T_HASH) {
75
 
                        m->item().s_voidp = 0;
76
 
                        break;
77
 
            }
78
 
                
79
 
                QHash<QString,QVariant> * map = new QHash<QString,QVariant>;
80
 
                
81
 
                // Convert the ruby hash to an array of key/value arrays
82
 
                VALUE temp = rb_funcall(hash, rb_intern("to_a"), 0);
83
 
 
84
 
                for (long i = 0; i < RARRAY_LEN(temp); i++) {
85
 
                        VALUE key = rb_ary_entry(rb_ary_entry(temp, i), 0);
86
 
                        VALUE value = rb_ary_entry(rb_ary_entry(temp, i), 1);
87
 
                        
88
 
                        smokeruby_object *o = value_obj_info(value);
89
 
                        if (o == 0 || o->ptr == 0) {
90
 
                                continue;
91
 
                        }
92
 
                        
93
 
                        (*map)[QString(StringValuePtr(key))] = (QVariant)*(QVariant*)o->ptr;
94
 
                }
95
 
            
96
 
                m->item().s_voidp = map;
97
 
                m->next();
98
 
                
99
 
            if(m->cleanup())
100
 
                delete map;
101
 
        }
102
 
        break;
103
 
        case Marshall::ToVALUE:
104
 
        {
105
 
                QHash<QString,QVariant> *map = (QHash<QString,QVariant>*)m->item().s_voidp;
106
 
                if (!map) {
107
 
                        *(m->var()) = Qnil;
108
 
                        break;
109
 
                }
110
 
                
111
 
            VALUE hv = rb_hash_new();
112
 
                        
113
 
                QHash<QString,QVariant>::Iterator it;
114
 
                for (it = map->begin(); it != map->end(); ++it) {
115
 
                        void *p = new QVariant(it.value());
116
 
                        VALUE obj = getPointerObject(p);
117
 
                                
118
 
                        if (obj == Qnil) {
119
 
                                smokeruby_object  * o = alloc_smokeruby_object( true, 
120
 
                                                                                                                                qtcore_Smoke, 
121
 
                                                                                                                                qtcore_Smoke->idClass("QVariant").index, 
122
 
                                                                                                                                p );
123
 
                                obj = set_obj_info("Qt::Variant", o);
124
 
                        }
125
 
 
126
 
                        rb_hash_aset(hv, rb_str_new2(((QString*)&(it.key()))->toLatin1()), obj);
127
 
        }
128
 
                
129
 
                *(m->var()) = hv;
130
 
                m->next();
131
 
                
132
 
//              if(m->cleanup())
133
 
//                      delete map;
134
 
        }
135
 
        break;
136
 
      default:
137
 
        m->unsupported();
138
 
        break;
139
 
    }
140
 
}
141
 
 
142
 
DEF_LIST_MARSHALLER( PlasmaContainmentList, QList<Plasma::Containment*>, Plasma::Containment )
143
 
DEF_LIST_MARSHALLER( PlasmaAppletList, QList<Plasma::Applet*>, Plasma::Applet )
144
 
 
145
 
DEF_HASH_MARSHALLER( QHashQStringApplet, Plasma::Applet )
146
 
DEF_HASH_MARSHALLER( QHashQStringDataContainer, Plasma::DataContainer )
147
 
DEF_HASH_MARSHALLER( QHashQStringDataEngine, Plasma::DataEngine )
148
 
 
149
 
TypeHandler Plasma_handlers[] = {
150
 
    { "Plasma::PackageStructure::Ptr", marshall_PackageStructurePtr },
151
 
    { "QHash<QString,QVariant>", marshall_QHashQStringQVariant },
152
 
    { "QHash<QString,QVariant>&", marshall_QHashQStringQVariant },
153
 
    { "Plasma::DataEngine::Data", marshall_QHashQStringQVariant },
154
 
    { "Plasma::DataEngine::Data&", marshall_QHashQStringQVariant },
155
 
    { "Plasma::DataEngine::SourceDict", marshall_QHashQStringDataContainer },
156
 
    { "Plasma::DataEngine::Dict", marshall_QHashQStringDataEngine },
157
 
    { "QList<Plasma::Containment*>", marshall_PlasmaContainmentList },
158
 
    { "QList<Plasma::Containment*>&", marshall_PlasmaContainmentList },
159
 
    { "Plasma::Applet::List", marshall_PlasmaAppletList },
160
 
    { 0, 0 }
161
 
};