~ubuntu-branches/ubuntu/lucid/kdebase/lucid

« back to all changes in this revision

Viewing changes to apps/dolphin/src/panels/information/kmetadatawidget.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Alessandro Ghersi
  • Date: 2009-12-19 18:29:39 UTC
  • mfrom: (1.1.36 upstream)
  • Revision ID: james.westby@ubuntu.com-20091219182939-i4q5c16348k7vxuk
Tags: 4:4.3.85-0ubuntu1
* New upstream release
  - Bump build-deps

Show diffs side-by-side

added added

removed removed

Lines of Context:
97
97
    void slotMetaDataUpdateDone();
98
98
    void slotLinkActivated(const QString& link);
99
99
 
 
100
    void slotTagActivated(const Nepomuk::Tag& tag);
 
101
 
100
102
#ifdef HAVE_NEPOMUK
101
103
    /**
102
104
     * Disables the metadata widget and starts the job that
183
185
    if (m_nepomukActivated) {
184
186
        m_ratingWidget = new KRatingWidget(parent);
185
187
        m_ratingWidget->setFixedHeight(fontMetrics.height());
 
188
        const Qt::Alignment align = (parent->layoutDirection() == Qt::LeftToRight) ?
 
189
                                    Qt::AlignLeft : Qt::AlignRight;
 
190
        m_ratingWidget->setAlignment(align);
186
191
        connect(m_ratingWidget, SIGNAL(ratingChanged(unsigned int)),
187
192
                q, SLOT(slotRatingChanged(unsigned int)));
188
193
 
189
194
        m_taggingWidget = new KTaggingWidget(parent);
190
195
        connect(m_taggingWidget, SIGNAL(tagsChanged(const QList<Nepomuk::Tag>&)),
191
196
                q, SLOT(slotTagsChanged(const QList<Nepomuk::Tag>&)));
 
197
        connect(m_taggingWidget, SIGNAL(tagActivated(const Nepomuk::Tag&)),
 
198
                q, SLOT(slotTagActivated(const Nepomuk::Tag&)));
192
199
 
193
200
        m_commentWidget = new KCommentWidget(parent);
194
201
        connect(m_commentWidget, SIGNAL(commentChanged(const QString&)),
260
267
 
261
268
void KMetaDataWidget::Private::initMetaInfoSettings()
262
269
{
 
270
    const int currentVersion = 1; // increase version, if the blacklist of disabled
 
271
                                  // properties should be updated
 
272
 
263
273
    KConfig config("kmetainformationrc", KConfig::NoGlobals);
264
 
    KConfigGroup settings = config.group("Show");
265
 
    if (!settings.readEntry("initialized", false)) {
 
274
    if (config.group("Misc").readEntry("version", 0) < currentVersion) {
266
275
        // The resource file is read the first time. Assure
267
276
        // that some meta information is disabled per default.
268
277
 
 
278
        // clear old info
 
279
        config.deleteGroup( "Show" );
 
280
        KConfigGroup settings = config.group("Show");
 
281
 
 
282
        // trueg: KDE 4.5: use a blacklist of actual rdf properties
 
283
 
269
284
        static const char* disabledProperties[] = {
270
285
            "asText", "contentSize", "created", "depth", "description", "fileExtension",
271
286
            "fileName", "fileSize", "hasTag", "isPartOf", "lastModified", "mimeType", "name",
274
289
            0 // mandatory last entry
275
290
        };
276
291
 
277
 
        int i = 0;
278
 
        while (disabledProperties[i] != 0) {
 
292
        for (int i = 0; disabledProperties[i] != 0; ++i) {
279
293
            settings.writeEntry(disabledProperties[i], false);
280
 
            ++i;
281
294
        }
282
295
 
283
296
        // mark the group as initialized
284
 
        settings.writeEntry("initialized", true);
 
297
        config.group("Misc").writeEntry("version", currentVersion);
285
298
    }
286
299
}
287
300
 
333
346
void KMetaDataWidget::Private::slotLoadingFinished()
334
347
{
335
348
#ifdef HAVE_NEPOMUK
336
 
    Q_ASSERT(m_loadMetaDataThread != 0);
 
349
    if (m_loadMetaDataThread == 0) {
 
350
        // The signal finished() has been emitted, but the thread has been marked
 
351
        // as invalid in the meantime. Just ignore the signal in this case.
 
352
        return;
 
353
    }
 
354
 
337
355
    Q_ASSERT(m_ratingWidget != 0);
338
356
    Q_ASSERT(m_commentWidget != 0);
339
357
    Q_ASSERT(m_taggingWidget != 0);
350
368
 
351
369
    const QList<KLoadMetaDataThread::Item> items = mergedItems(m_loadMetaDataThread->items());
352
370
    foreach (const KLoadMetaDataThread::Item& item, items) {
 
371
        const QString itemLabel = item.label;
 
372
        QString itemValue = item.value;
 
373
        if (item.value.startsWith("<a href=")) {
 
374
           // use the text color for the value-links, to create a visual difference
 
375
           // to the semantically different links like "Change..."
 
376
           const QColor linkColor = q->palette().text().color();
 
377
           QString decoration;
 
378
           if (m_readOnly) {
 
379
               decoration = QString::fromLatin1("text-decoration:none;");
 
380
           }
 
381
           const QString styleText = QString::fromLatin1("style=\"color:%1;%2\" ")
 
382
                                                         .arg(linkColor.name())
 
383
                                                         .arg(decoration);
 
384
           itemValue.insert(3 /* after "<a "*/, styleText);
 
385
        }
353
386
        if (index < rowCount) {
354
387
            // adjust texts of the current row
355
 
            m_rows[index].label->setText(item.label);
 
388
            m_rows[index].label->setText(itemLabel);
356
389
            QLabel* infoValueLabel = qobject_cast<QLabel*>(m_rows[index].infoWidget);
357
390
            Q_ASSERT(infoValueLabel != 0);
358
 
            infoValueLabel->setText(item.value);
 
391
            infoValueLabel->setText(itemValue);
359
392
        } else {
360
393
            // create new row
361
 
            QLabel* infoLabel = new QLabel(item.label, q);
362
 
            QLabel* infoValue = new QLabel(item.value, q);
 
394
            QLabel* infoLabel = new QLabel(itemLabel, q);
 
395
            QLabel* infoValue = new QLabel(itemValue, q);
363
396
            connect(infoValue, SIGNAL(linkActivated(QString)),
364
397
                    q, SLOT(slotLinkActivated(QString)));
365
398
            addRow(infoLabel, infoValue);
421
454
#endif
422
455
}
423
456
 
 
457
void KMetaDataWidget::Private::slotTagActivated(const Nepomuk::Tag& tag)
 
458
{
 
459
#ifdef HAVE_NEPOMUK
 
460
    emit q->urlActivated(tag.resourceUri());
 
461
#else
 
462
    Q_UNUSED(tag);
 
463
#endif
 
464
}
 
465
 
424
466
void KMetaDataWidget::Private::slotMetaDataUpdateDone()
425
467
{
426
468
#ifdef HAVE_NEPOMUK