50
QString typesToHtml( const QList<QUrl>& types )
52
QList<Nepomuk::Types::Class> typeClasses;
53
foreach( const QUrl& type, types ) {
54
typeClasses << Nepomuk::Types::Class( type );
57
// remove all types that are supertypes of others in the list
58
QList<Nepomuk::Types::Class> normalizedTypes;
59
for ( int i = 0; i < typeClasses.count(); ++i ) {
60
Nepomuk::Types::Class& type = typeClasses[i];
62
for ( int j = 0; j < typeClasses.count(); ++j ) {
63
if ( type != typeClasses[j] &&
64
typeClasses[j].isSubClassOf( type ) ) {
70
normalizedTypes << type;
75
QStringList typeStrings;
76
for ( int i = 0; i < normalizedTypes.count(); ++i ) {
77
typeStrings << normalizedTypes[i].label();
80
return typeStrings.join( ", " );
83
QString encodeUrl( const QUrl& u ) {
50
const char* s_noFollow = "noFollow";
51
const char* s_showUri = "showUris";
52
const char* s_true = "true";
54
KUrl configureUrl( const KUrl& url, Nepomuk::ResourcePageGenerator::Flags flags ) {
57
newUrl.removeEncodedQueryItem( s_noFollow );
85
58
if ( url.scheme() == QLatin1String( "nepomuk" ) ) {
86
url.setEncodedQuery( "noFollow=true" );
88
return QString::fromAscii( url.toEncoded() );
59
newUrl.addEncodedQueryItem( s_noFollow, s_true );
62
newUrl.removeEncodedQueryItem( s_showUri );
63
if ( flags & Nepomuk::ResourcePageGenerator::ShowUris ) {
64
newUrl.addEncodedQueryItem( s_showUri, s_true );
83
void Nepomuk::ResourcePageGenerator::setFlagsFromUrl( const KUrl& url )
86
if ( url.encodedQueryItemValue( s_showUri ) == s_true )
91
KUrl Nepomuk::ResourcePageGenerator::url() const
93
return configureUrl( m_resource.resourceUri(), m_flags );
104
97
// TODO: create an html template rather than having it hardcoded here
105
98
QByteArray Nepomuk::ResourcePageGenerator::generatePage() const
186
179
" padding: 0 20 0 20; }"
187
180
"</style></head>"
188
<< "<body><div id=\"body_wrapper\"><div id=\"body\"><div class=\"content\"><div id=\"main\"><div class=\"clearer\"> </div>";
182
<< createConfigureBoxHtml()
183
<< "<div id=\"body_wrapper\"><div id=\"body\"><div class=\"content\"><div id=\"main\"><div class=\"clearer\"> </div>";
190
185
os << "<h1>" << label << "</h1>"
191
186
<< "Type: " << ( exists ? typesToHtml( m_resource.types() ) : i18n( "Resource does not exist" ) );
198
193
Soprano::Statement s = it.current();
199
194
if ( s.predicate().uri() != Soprano::Vocabulary::RDF::type() ) {
200
195
Nepomuk::Types::Property p( s.predicate().uri() );
201
os << "<tr><td align=right><i>" << ( p.label().isEmpty() ? p.name() : p.label() ) << "</i></td><td width=16px></td><td>";
196
os << "<tr><td align=right><i>" << entityLabel( p ) << "</i></td><td width=16px></td><td>";
202
197
if ( s.object().isLiteral() ) {
203
198
if ( s.object().literal().isDateTime() )
204
199
os << KGlobal::locale()->formatDateTime( s.object().literal().toDateTime(), KLocale::FancyShortDate );
217
212
Resource resource( uri );
218
213
uri = resource.resourceUri();
219
214
label = QString::fromLatin1( "%1 (%2)" )
220
.arg( resource.genericLabel(),
215
.arg( resourceLabel( resource ),
221
216
typesToHtml( resource.types() ) );
223
218
os << QString( "<a href=\"%1\">%2</a>" )
240
235
os << "<td align=right>"
241
236
<< QString( "<a href=\"%1\">%2</a> (%3)" )
242
237
.arg( encodeUrl( s.subject().uri() ),
243
resource.genericLabel(),
238
resourceLabel( resource ),
244
239
typesToHtml( resource.types() ) )
246
241
<< "<td width=16px></td>"
247
<< "<td><i>" << ( p.label().isEmpty() ? p.name() : p.label() ) << "</i></td></tr>";
242
<< "<td><i>" << entityLabel( p ) << "</i></td></tr>";
250
245
os << "</table></div>";
259
QString Nepomuk::ResourcePageGenerator::resourceLabel( const Resource& res ) const
261
if ( m_flags & ShowUris )
262
return KUrl( res.resourceUri() ).prettyUrl();
264
return res.genericLabel();
268
QString Nepomuk::ResourcePageGenerator::entityLabel( const Nepomuk::Types::Entity& e ) const
270
if ( m_flags & ShowUris )
271
return KUrl( e.uri() ).prettyUrl();
277
QString Nepomuk::ResourcePageGenerator::typesToHtml( const QList<QUrl>& types ) const
279
QList<Nepomuk::Types::Class> typeClasses;
280
foreach( const QUrl& type, types ) {
281
typeClasses << Nepomuk::Types::Class( type );
284
// remove all types that are supertypes of others in the list
285
QList<Nepomuk::Types::Class> normalizedTypes;
286
for ( int i = 0; i < typeClasses.count(); ++i ) {
287
Nepomuk::Types::Class& type = typeClasses[i];
289
for ( int j = 0; j < typeClasses.count(); ++j ) {
290
if ( type != typeClasses[j] &&
291
typeClasses[j].isSubClassOf( type ) ) {
297
normalizedTypes << type;
301
// extract the labels
302
QStringList typeStrings;
303
for ( int i = 0; i < normalizedTypes.count(); ++i ) {
304
typeStrings << entityLabel( normalizedTypes[i] );
307
return typeStrings.join( ", " );
311
QString Nepomuk::ResourcePageGenerator::encodeUrl( const QUrl& url ) const
313
return QString::fromAscii( configureUrl( url, m_flags ).toEncoded() );
317
QString Nepomuk::ResourcePageGenerator::createConfigureBoxHtml() const
320
= QString::fromLatin1( "<div style=\"position:fixed; right:10px; top:10px; text-align:right;\"><a href=\"%1\">%2</a></div>" )
321
.arg( configureUrl( url(), m_flags^ShowUris ).url(),
322
m_flags&ShowUris ? i18n( "Hide URIs" ) : i18n( "Show URIs" ) );