Magellan Linux

Annotation of /trunk/kdelibs4/patches/kdelibs4-4.6.5-newer-desktop-ontologies.patch

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1439 - (hide annotations) (download)
Mon Jul 25 15:09:23 2011 UTC (12 years, 9 months ago) by niro
File size: 11947 byte(s)
-added patch to fix build of kdepim4-runtime with >=desktop-ontologies-0.7
1 niro 1439 commit 1f796983aa8385da77f30813041b40e208c17391
2     Author: Vishesh Handa <handa.vish@gmail.com>
3     Date: Thu May 19 20:52:30 2011 +0530
4    
5     Make KDEPIM 4.6 compile with master
6    
7     This makes the rcgen produce add/setProperty( QList<T> ) functions for
8     properties with nrl:maxCardinality and nrl:cardinality = 1. This was
9     required because with SDO 0.7 the cardinalities of many properties
10     have been set.
11    
12     BUG: 268595
13    
14     diff --git a/nepomuk/rcgen/codegenerator.cpp b/nepomuk/rcgen/codegenerator.cpp
15     index bc670e6..1bb2736 100644
16     --- a/nepomuk/rcgen/codegenerator.cpp
17     +++ b/nepomuk/rcgen/codegenerator.cpp
18     @@ -194,33 +194,28 @@ bool CodeGenerator::writeHeader( const ResourceClass *resourceClass, QTextStream
19     while( it.hasNext() ) {
20     const Property* p = it.next();
21    
22     - if( p->literalRange().isEmpty() &&
23     - !p->range() ) {
24     - if ( !quiet )
25     - qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
26     - continue;
27     - }
28     -
29     - if ( m_mode == SafeMode ) {
30     - ms << writeComment( QString("Get property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
31     - ms << " " << m_code->propertyGetterDeclaration( p, resourceClass ) << ";" << endl;
32     - ms << endl;
33     + if( p->maxCardinality() == 1 || p->cardinality() == 1 ) {
34     + Property * prop = const_cast<Property *>(p);
35     + bool isList = prop->isList();
36     +
37     + prop->setIsList( true );
38     + if( !writePropertyHeader( prop, resourceClass, ms ) )
39     + continue;
40     +
41     + prop->setIsList( false );
42     + if( !writePropertyHeader( prop, resourceClass, ms ) )
43     + continue;
44     +
45     + writePropertyUriHeader( prop, ms );
46     +
47     + prop->setIsList( isList );
48     }
49     -
50     - ms << writeComment( QString("Set property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
51     - ms << " " << m_code->propertySetterDeclaration( p, resourceClass ) << ";" << endl;
52     - ms << endl;
53     -
54     - if( p->isList() ) {
55     - ms << writeComment( QString("Add a value to property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
56     - ms << " " << m_code->propertyAdderDeclaration( p, resourceClass ) << ";" << endl;
57     - ms << endl;
58     + else {
59     + if( !writePropertyHeader( p, resourceClass, ms ) )
60     + continue;
61     + writePropertyUriHeader( p, ms );
62     }
63     -
64     - ms << writeComment( QString( "\\return The URI of the property '%1'." ).arg( p->name() ), 2*4 ) << endl;
65     - ms << " " << "static QUrl " << p->name()[0].toLower() << p->name().mid(1) << "Uri();" << endl;
66     - ms << endl;
67     -
68     +
69     if( !p->hasSimpleType() )
70     includes.insert( p->typeString( true ) );
71     }
72     @@ -299,6 +294,42 @@ bool CodeGenerator::writeHeader( const ResourceClass *resourceClass, QTextStream
73     return true;
74     }
75    
76     +bool CodeGenerator::writePropertyHeader(const Property* p, const ResourceClass* resourceClass, QTextStream& ms) const
77     +{
78     + if( p->literalRange().isEmpty() &&
79     + !p->range() ) {
80     + if ( !quiet )
81     + qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
82     + return false;
83     + }
84     +
85     + if ( m_mode == SafeMode ) {
86     + ms << writeComment( QString("Get property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
87     + ms << " " << m_code->propertyGetterDeclaration( p, resourceClass ) << ";" << endl;
88     + ms << endl;
89     + }
90     +
91     + ms << writeComment( QString("Set property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
92     + ms << " " << m_code->propertySetterDeclaration( p, resourceClass ) << ";" << endl;
93     + ms << endl;
94     +
95     + if( p->isList() ) {
96     + ms << writeComment( QString("Add a value to property '%1'. ").arg(p->name()) + p->comment(), 2*4 ) << endl;
97     + ms << " " << m_code->propertyAdderDeclaration( p, resourceClass ) << ";" << endl;
98     + ms << endl;
99     + }
100     +
101     + return true;
102     +}
103     +
104     +void CodeGenerator::writePropertyUriHeader(const Property* p, QTextStream& ts) const
105     +{
106     + ts << writeComment( QString( "\\return The URI of the property '%1'." ).arg( p->name() ), 2*4 ) << endl;
107     + ts << " " << "static QUrl " << p->name()[0].toLower() << p->name().mid(1) << "Uri();" << endl;
108     + ts << endl;
109     +}
110     +
111     +
112     bool CodeGenerator::writeSource( const ResourceClass* resourceClass, QTextStream& stream ) const
113     {
114     QString s = sourceTemplate( m_mode );
115     @@ -318,29 +349,31 @@ bool CodeGenerator::writeSource( const ResourceClass* resourceClass, QTextStream
116     while( it.hasNext() ) {
117     const Property* p = it.next();
118    
119     - if( p->literalRange().isEmpty() &&
120     - !p->range() ) {
121     - if ( !quiet )
122     - qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
123     - continue;
124     + if( p->maxCardinality() == 1 || p->cardinality() == 1 ) {
125     + Property * prop = const_cast<Property *>(p);
126     + bool isList = prop->isList();
127     +
128     + prop->setIsList( true );
129     + if( !writePropertySource( prop, resourceClass, ms ) )
130     + continue;
131     +
132     + prop->setIsList( false );
133     + if( !writePropertySource( prop, resourceClass, ms ) )
134     + continue;
135     +
136     + writePropertyUriSource( prop, resourceClass, ms );
137     +
138     + prop->setIsList( isList );
139     }
140     -
141     + else {
142     + if( !writePropertySource( p, resourceClass, ms ) )
143     + continue;
144     + writePropertyUriSource( p, resourceClass, ms );
145     + }
146     +
147     if ( !p->hasSimpleType() ) {
148     includes.append( QString( "#include \"%1.h\"" ).arg( p->typeString( true ).toLower() ) );
149     }
150     -
151     - if ( m_mode == SafeMode )
152     - ms << m_code->propertyGetterDefinition( p, resourceClass ) << endl;
153     -
154     - ms << m_code->propertySetterDefinition( p, resourceClass ) << endl;
155     - if( p->isList() )
156     - ms << m_code->propertyAdderDefinition( p, resourceClass ) << endl;
157     -
158     - // write the static method that returns the property's Uri
159     - ms << "QUrl " << resourceClass->name( m_nameSpace ) << "::" << p->name()[0].toLower() << p->name().mid(1) << "Uri()" << endl
160     - << "{" << endl
161     - << " return QUrl::fromEncoded(\"" << p->uri().toString() << "\");" << endl
162     - << "}" << endl << endl;
163     }
164    
165     it = resourceClass->allReverseProperties();
166     @@ -395,6 +428,32 @@ bool CodeGenerator::writeSource( const ResourceClass* resourceClass, QTextStream
167     return true;
168     }
169    
170     +bool CodeGenerator::writePropertySource(const Property* p, const ResourceClass* resourceClass, QTextStream& ms) const
171     +{
172     + if( p->literalRange().isEmpty() && !p->range() ) {
173     + if ( !quiet )
174     + qDebug() << "(CodeGenerator::writeSource) type not defined for property: " << p->name() << endl;
175     + return false;
176     + }
177     +
178     + if ( m_mode == SafeMode )
179     + ms << m_code->propertyGetterDefinition( p, resourceClass ) << endl;
180     +
181     + ms << m_code->propertySetterDefinition( p, resourceClass ) << endl;
182     + if( p->isList() )
183     + ms << m_code->propertyAdderDefinition( p, resourceClass ) << endl;
184     +
185     + return true;
186     +}
187     +
188     +void CodeGenerator::writePropertyUriSource(const Property* p, const ResourceClass* resourceClass, QTextStream& ts) const
189     +{
190     + // write the static method that returns the property's Uri
191     + ts << "QUrl " << resourceClass->name( m_nameSpace ) << "::" << p->name()[0].toLower() << p->name().mid(1) << "Uri()" << endl
192     + << "{" << endl
193     + << " return QUrl::fromEncoded(\"" << p->uri().toString() << "\");" << endl
194     + << "}" << endl << endl;
195     +}
196    
197     bool CodeGenerator::writeSources( const QString& dir )
198     {
199     diff --git a/nepomuk/rcgen/codegenerator.h b/nepomuk/rcgen/codegenerator.h
200     index dc786a4..f26a875 100644
201     --- a/nepomuk/rcgen/codegenerator.h
202     +++ b/nepomuk/rcgen/codegenerator.h
203     @@ -22,6 +22,7 @@ class AbstractCode;
204     class ResourceClass;
205     class QString;
206     class QTextStream;
207     +class Property;
208    
209     class CodeGenerator
210     {
211     @@ -47,7 +48,13 @@ private:
212     bool writeHeader( const ResourceClass* resourceClass, QTextStream& ) const;
213     bool writeSource( const ResourceClass* resourceClass, QTextStream& ) const;
214     bool writeDummyClasses( const QString &folder ) const;
215     +
216     + bool writePropertyHeader( const Property* p, const ResourceClass* resourceClass, QTextStream& ms ) const;
217     + bool writePropertySource( const Property* p, const ResourceClass* resourceClass, QTextStream& ms ) const;
218    
219     + void writePropertyUriHeader( const Property* p, QTextStream& ts ) const;
220     + void writePropertyUriSource( const Property* p, const ResourceClass* resourceClass, QTextStream& ts ) const;
221     +
222     QString visibilityHeader() const;
223     QString visibilityExportMacro() const;
224    
225     diff --git a/nepomuk/rcgen/ontologyparser.cpp b/nepomuk/rcgen/ontologyparser.cpp
226     index 50e3397..f9f8673 100644
227     --- a/nepomuk/rcgen/ontologyparser.cpp
228     +++ b/nepomuk/rcgen/ontologyparser.cpp
229     @@ -164,7 +164,14 @@ bool OntologyParser::parse( const QString& filename, const QString& serializatio
230     }
231     else if( s.predicate().uri() == Soprano::Vocabulary::NRL::maxCardinality() ||
232     s.predicate().uri() == Soprano::Vocabulary::NRL::cardinality() ) {
233     - d->getProperty(s.subject().uri())->setIsList( s.object().literal().toInt() > 1 );
234     + Property * p = d->getProperty(s.subject().uri());
235     + int cValue = s.object().literal().toInt();
236     +
237     + p->setIsList( cValue > 1 );
238     + if( s.predicate().uri() == Soprano::Vocabulary::NRL::maxCardinality() )
239     + p->setMaxCardinality( cValue );
240     + else
241     + p->setCardinality( cValue );
242     }
243     else if( s.predicate().uri() == Soprano::Vocabulary::RDFS::comment() ) {
244     d->comments[s.subject().uri()] = s.object().literal().toString();
245     diff --git a/nepomuk/rcgen/property.cpp b/nepomuk/rcgen/property.cpp
246     index 1baa04c..51d9c07 100644
247     --- a/nepomuk/rcgen/property.cpp
248     +++ b/nepomuk/rcgen/property.cpp
249     @@ -27,7 +27,9 @@ Property::Property()
250     : m_range( 0 ),
251     m_isList( true ),
252     m_domain( 0 ),
253     - m_inverseProperty( 0 )
254     + m_inverseProperty( 0 ),
255     + m_maxCardinality( -1 ),
256     + m_cardinality( -1 )
257     {
258     }
259    
260     @@ -204,3 +206,24 @@ QString Property::literalTypeConversionMethod() const
261    
262     return QString();
263     }
264     +
265     +void Property::setMaxCardinality(int value)
266     +{
267     + m_maxCardinality = value;
268     +}
269     +
270     +int Property::maxCardinality() const
271     +{
272     + return m_maxCardinality;
273     +}
274     +
275     +int Property::cardinality() const
276     +{
277     + return m_cardinality;
278     +}
279     +
280     +void Property::setCardinality(int value)
281     +{
282     + m_cardinality = value;
283     +}
284     +
285     diff --git a/nepomuk/rcgen/property.h b/nepomuk/rcgen/property.h
286     index a72ab5d..a09006d 100644
287     --- a/nepomuk/rcgen/property.h
288     +++ b/nepomuk/rcgen/property.h
289     @@ -139,6 +139,25 @@ public:
290     */
291     bool hasSimpleType() const;
292    
293     + /**
294     + * Sets the max cardinality of the property
295     + */
296     + void setMaxCardinality( int value );
297     +
298     + /**
299     + * Returns the max cardinality of the property
300     + */
301     + int maxCardinality() const;
302     +
303     + /**
304     + * Sets the cardinality of the property
305     + */
306     + void setCardinality( int value );
307     +
308     + /**
309     + * Returns the cardinality of the property
310     + */
311     + int cardinality() const;
312     private:
313     QUrl m_uri;
314     ResourceClass* m_range;
315     @@ -147,6 +166,8 @@ private:
316     bool m_isList;
317     ResourceClass* m_domain;
318     Property* m_inverseProperty;
319     + int m_maxCardinality;
320     + int m_cardinality;
321     };
322    
323     #endif