~ubuntu-branches/ubuntu/precise/gwenview/precise-proposed

« back to all changes in this revision

Viewing changes to app/infocontextmanageritem.cpp

  • Committer: Package Import Robot
  • Author(s): Jonathan Riddell
  • Date: 2011-12-15 14:17:54 UTC
  • mto: This revision was merged to the branch mainline in revision 12.
  • Revision ID: package-import@ubuntu.com-20111215141754-z043hyx69dulbggf
Tags: upstream-4.7.90
ImportĀ upstreamĀ versionĀ 4.7.90

Show diffs side-by-side

added added

removed removed

Lines of Context:
46
46
#include <lib/document/document.h>
47
47
#include <lib/document/documentfactory.h>
48
48
 
49
 
namespace Gwenview {
 
49
namespace Gwenview
 
50
{
50
51
 
51
52
#undef ENABLE_LOG
52
53
#undef LOG
61
62
 * A label which fades out if its content does not fit. If the content is
62
63
 * cropped, a tooltip is shown when the mouse hovers the widget.
63
64
 */
64
 
class FadingLabel : public QLabel {
 
65
class FadingLabel : public QLabel
 
66
{
65
67
public:
66
 
        explicit FadingLabel(QWidget* parent = 0)
67
 
        : QLabel(parent)
68
 
        {
69
 
                setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
70
 
                setTextInteractionFlags(Qt::TextBrowserInteraction);
71
 
        }
 
68
    explicit FadingLabel(QWidget* parent = 0)
 
69
        : QLabel(parent) {
 
70
        setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Fixed);
 
71
        setTextInteractionFlags(Qt::TextBrowserInteraction);
 
72
    }
72
73
 
73
 
        QSize minimumSizeHint() const {
74
 
                return QSize();
75
 
        }
 
74
    QSize minimumSizeHint() const {
 
75
        return QSize();
 
76
    }
76
77
 
77
78
protected:
78
 
        void paintEvent(QPaintEvent* event) {
79
 
                QLabel::paintEvent(event);
80
 
                if (!isCropped()) {
81
 
                        return;
82
 
                }
83
 
 
84
 
                QLinearGradient gradient;
85
 
                int gradientWidth = fontMetrics().averageCharWidth() * 4;
86
 
                if (alignment() & Qt::AlignLeft) {
87
 
                        gradient.setStart(width() - gradientWidth, 0);
88
 
                        gradient.setFinalStop(width(), 0);
89
 
                        gradient.setColorAt(0, Qt::transparent);
90
 
                        gradient.setColorAt(1, palette().color(backgroundRole()));
91
 
                } else {
92
 
                        gradient.setStart(0, 0);
93
 
                        gradient.setFinalStop(gradientWidth, 0);
94
 
                        gradient.setColorAt(0, palette().color(backgroundRole()));
95
 
                        gradient.setColorAt(1, Qt::transparent);
96
 
                }
97
 
                QPainter painter(this);
98
 
                painter.fillRect(rect(), gradient);
99
 
        }
100
 
 
101
 
        bool event(QEvent* event) {
102
 
                if (event->type() == QEvent::ToolTip) {
103
 
                        // Show tooltip if cropped
104
 
                        QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
105
 
                        if (isCropped()) {
106
 
                                QToolTip::showText(helpEvent->globalPos(), text());
107
 
                        } else {
108
 
                                QToolTip::hideText();
109
 
                                event->ignore();
110
 
                        }
111
 
                        return true;
112
 
                }
113
 
                return QLabel::event(event);
114
 
        }
115
 
 
116
 
        inline bool isCropped() const {
117
 
                return sizeHint().width() > width();
118
 
        }
 
79
    void paintEvent(QPaintEvent* event)
 
80
    {
 
81
        QLabel::paintEvent(event);
 
82
        if (!isCropped()) {
 
83
            return;
 
84
        }
 
85
 
 
86
        QLinearGradient gradient;
 
87
        int gradientWidth = fontMetrics().averageCharWidth() * 4;
 
88
        if (alignment() & Qt::AlignLeft) {
 
89
            gradient.setStart(width() - gradientWidth, 0);
 
90
            gradient.setFinalStop(width(), 0);
 
91
            gradient.setColorAt(0, Qt::transparent);
 
92
            gradient.setColorAt(1, palette().color(backgroundRole()));
 
93
        } else {
 
94
            gradient.setStart(0, 0);
 
95
            gradient.setFinalStop(gradientWidth, 0);
 
96
            gradient.setColorAt(0, palette().color(backgroundRole()));
 
97
            gradient.setColorAt(1, Qt::transparent);
 
98
        }
 
99
        QPainter painter(this);
 
100
        painter.fillRect(rect(), gradient);
 
101
    }
 
102
 
 
103
    bool event(QEvent* event)
 
104
    {
 
105
        if (event->type() == QEvent::ToolTip) {
 
106
            // Show tooltip if cropped
 
107
            QHelpEvent* helpEvent = static_cast<QHelpEvent*>(event);
 
108
            if (isCropped()) {
 
109
                QToolTip::showText(helpEvent->globalPos(), text());
 
110
            } else {
 
111
                QToolTip::hideText();
 
112
                event->ignore();
 
113
            }
 
114
            return true;
 
115
        }
 
116
        return QLabel::event(event);
 
117
    }
 
118
 
 
119
    inline bool isCropped() const {
 
120
        return sizeHint().width() > width();
 
121
    }
119
122
};
120
123
 
121
124
/**
122
125
 * This widget is capable of showing multiple lines of key/value pairs.
123
126
 */
124
 
class KeyValueWidget : public QWidget {
125
 
        struct Row {
126
 
                Row()
127
 
                : keyLabel(new FadingLabel)
128
 
                , valueLabel(new FadingLabel)
129
 
                {
130
 
                        if (QApplication::isLeftToRight()) {
131
 
                                keyLabel->setAlignment(Qt::AlignRight);
132
 
                        } else {
133
 
                                valueLabel->setAlignment(Qt::AlignRight);
134
 
                        }
135
 
                }
136
 
 
137
 
                ~Row() {
138
 
                        delete keyLabel;
139
 
                        delete valueLabel;
140
 
                }
141
 
 
142
 
                FadingLabel* keyLabel;
143
 
                FadingLabel* valueLabel;
144
 
        };
 
127
class KeyValueWidget : public QWidget
 
128
{
 
129
    struct Row {
 
130
        Row()
 
131
            : keyLabel(new FadingLabel)
 
132
            , valueLabel(new FadingLabel) {
 
133
            if (QApplication::isLeftToRight()) {
 
134
                keyLabel->setAlignment(Qt::AlignRight);
 
135
            } else {
 
136
                valueLabel->setAlignment(Qt::AlignRight);
 
137
            }
 
138
        }
 
139
 
 
140
        ~Row() {
 
141
            delete keyLabel;
 
142
            delete valueLabel;
 
143
        }
 
144
 
 
145
        FadingLabel* keyLabel;
 
146
        FadingLabel* valueLabel;
 
147
    };
145
148
public:
146
 
        KeyValueWidget(QWidget* parent)
147
 
        : QWidget(parent)
148
 
        , mLayout(new QGridLayout(this))
149
 
        {
150
 
                mLayout->setMargin(0);
151
 
                mLayout->setVerticalSpacing(0);
152
 
                mLayout->setHorizontalSpacing(4);
153
 
                setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
154
 
        }
155
 
 
156
 
        QSize sizeHint() const {
157
 
                int height = fontMetrics().height() * mRows.count();
158
 
                return QSize(150, height);
159
 
        }
160
 
 
161
 
        void addRow(const QString& key, const QString& value) {
162
 
                Row* row = new Row;
163
 
                row->keyLabel->setText(i18nc(
164
 
                        "@item:intext %1 is a key, we append a colon to it. A value is displayed after",
165
 
                        "%1:", key));
166
 
                row->valueLabel->setText(value);
167
 
                mRows.append(row);
168
 
 
169
 
                int rowCount = mLayout->rowCount();
170
 
                mLayout->addWidget(row->keyLabel, rowCount, 0);
171
 
                mLayout->addWidget(row->valueLabel, rowCount, 1);
172
 
                updateKeyColumnWidth();
173
 
                updateGeometry();
174
 
        }
175
 
 
176
 
        void clear() {
177
 
                qDeleteAll(mRows);
178
 
                mRows.clear();
179
 
                updateGeometry();
180
 
        }
 
149
    KeyValueWidget(QWidget* parent)
 
150
        : QWidget(parent)
 
151
        , mLayout(new QGridLayout(this)) {
 
152
        mLayout->setMargin(0);
 
153
        mLayout->setVerticalSpacing(0);
 
154
        mLayout->setHorizontalSpacing(4);
 
155
        setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Fixed);
 
156
    }
 
157
 
 
158
    QSize sizeHint() const {
 
159
        int height = fontMetrics().height() * mRows.count();
 
160
        return QSize(150, height);
 
161
    }
 
162
 
 
163
    void addRow(const QString& key, const QString& value)
 
164
    {
 
165
        Row* row = new Row;
 
166
        row->keyLabel->setText(i18nc(
 
167
                                   "@item:intext %1 is a key, we append a colon to it. A value is displayed after",
 
168
                                   "%1:", key));
 
169
        row->valueLabel->setText(value);
 
170
        mRows.append(row);
 
171
 
 
172
        int rowCount = mLayout->rowCount();
 
173
        mLayout->addWidget(row->keyLabel, rowCount, 0);
 
174
        mLayout->addWidget(row->valueLabel, rowCount, 1);
 
175
        updateKeyColumnWidth();
 
176
        updateGeometry();
 
177
    }
 
178
 
 
179
    void clear()
 
180
    {
 
181
        qDeleteAll(mRows);
 
182
        mRows.clear();
 
183
        updateGeometry();
 
184
    }
181
185
 
182
186
protected:
183
 
        void resizeEvent(QResizeEvent* event) {
184
 
                QWidget::resizeEvent(event);
185
 
                updateKeyColumnWidth();
186
 
                updateGeometry();
187
 
        }
 
187
    void resizeEvent(QResizeEvent* event)
 
188
    {
 
189
        QWidget::resizeEvent(event);
 
190
        updateKeyColumnWidth();
 
191
        updateGeometry();
 
192
    }
188
193
 
189
194
private:
190
 
        QList<Row*> mRows;
191
 
        QGridLayout* mLayout;
 
195
    QList<Row*> mRows;
 
196
    QGridLayout* mLayout;
192
197
 
193
 
        void updateKeyColumnWidth() {
194
 
                const int maxWidth = width() / 2;
195
 
                int keyWidth = 0;
196
 
                Q_FOREACH(Row* row, mRows) {
197
 
                        int wantedWidth = row->keyLabel->sizeHint().width();
198
 
                        if (wantedWidth > keyWidth) {
199
 
                                keyWidth = qMin(wantedWidth, maxWidth);
200
 
                        }
201
 
                }
202
 
                Q_FOREACH(Row* row, mRows) {
203
 
                        row->keyLabel->setFixedWidth(keyWidth);
204
 
                }
205
 
        }
 
198
    void updateKeyColumnWidth()
 
199
    {
 
200
        const int maxWidth = width() / 2;
 
201
        int keyWidth = 0;
 
202
        Q_FOREACH(Row * row, mRows) {
 
203
            int wantedWidth = row->keyLabel->sizeHint().width();
 
204
            if (wantedWidth > keyWidth) {
 
205
                keyWidth = qMin(wantedWidth, maxWidth);
 
206
            }
 
207
        }
 
208
        Q_FOREACH(Row * row, mRows) {
 
209
            row->keyLabel->setFixedWidth(keyWidth);
 
210
        }
 
211
    }
206
212
};
207
213
 
208
214
struct InfoContextManagerItemPrivate {
209
 
        InfoContextManagerItem* q;
210
 
        SideBarGroup* mGroup;
211
 
 
212
 
        // One selection fields
213
 
        QWidget* mOneFileWidget;
214
 
        KeyValueWidget* mKeyValueWidget;
215
 
        Document::Ptr mDocument;
216
 
 
217
 
        // Multiple selection fields
218
 
        QLabel* mMultipleFilesLabel;
219
 
 
220
 
        QPointer<ImageMetaInfoDialog> mImageMetaInfoDialog;
221
 
 
222
 
        void updateMetaInfoDialog() {
223
 
                if (!mImageMetaInfoDialog) {
224
 
                        return;
225
 
                }
226
 
                ImageMetaInfoModel* model = mDocument ? mDocument->metaInfo() : 0;
227
 
                mImageMetaInfoDialog->setMetaInfo(model, GwenviewConfig::preferredMetaInfoKeyList());
228
 
        }
229
 
 
230
 
 
231
 
        void setupGroup() {
232
 
                mOneFileWidget = new QWidget();
233
 
 
234
 
                mKeyValueWidget = new KeyValueWidget(mOneFileWidget);
235
 
 
236
 
                QLabel* moreLabel = new QLabel(mOneFileWidget);
237
 
                moreLabel->setText(QString("<a href='#'>%1</a>").arg(i18nc("@action show more image meta info", "More...")));
238
 
                moreLabel->setAlignment(Qt::AlignRight);
239
 
 
240
 
                QVBoxLayout* layout = new QVBoxLayout(mOneFileWidget);
241
 
                layout->setMargin(2);
242
 
                layout->setSpacing(2);
243
 
                layout->addWidget(mKeyValueWidget);
244
 
                layout->addWidget(moreLabel);
245
 
 
246
 
                mMultipleFilesLabel = new QLabel();
247
 
 
248
 
                mGroup = new SideBarGroup(i18nc("@title:group", "Meta Information"));
249
 
                q->setWidget(mGroup);
250
 
                mGroup->addWidget(mOneFileWidget);
251
 
                mGroup->addWidget(mMultipleFilesLabel);
252
 
 
253
 
                EventWatcher::install(mGroup, QEvent::Show, q, SLOT(updateSideBarContent()));
254
 
 
255
 
                QObject::connect(moreLabel, SIGNAL(linkActivated(const QString&)),
256
 
                        q, SLOT(showMetaInfoDialog()) );
257
 
        }
258
 
 
259
 
        void forgetCurrentDocument() {
260
 
                if (mDocument) {
261
 
                        QObject::disconnect(mDocument.data(), 0, q, 0);
262
 
                        // "Garbage collect" document
263
 
                        mDocument = 0;
264
 
                }
265
 
        }
 
215
    InfoContextManagerItem* q;
 
216
    SideBarGroup* mGroup;
 
217
 
 
218
    // One selection fields
 
219
    QWidget* mOneFileWidget;
 
220
    KeyValueWidget* mKeyValueWidget;
 
221
    Document::Ptr mDocument;
 
222
 
 
223
    // Multiple selection fields
 
224
    QLabel* mMultipleFilesLabel;
 
225
 
 
226
    QPointer<ImageMetaInfoDialog> mImageMetaInfoDialog;
 
227
 
 
228
    void updateMetaInfoDialog()
 
229
    {
 
230
        if (!mImageMetaInfoDialog) {
 
231
            return;
 
232
        }
 
233
        ImageMetaInfoModel* model = mDocument ? mDocument->metaInfo() : 0;
 
234
        mImageMetaInfoDialog->setMetaInfo(model, GwenviewConfig::preferredMetaInfoKeyList());
 
235
    }
 
236
 
 
237
    void setupGroup()
 
238
    {
 
239
        mOneFileWidget = new QWidget();
 
240
 
 
241
        mKeyValueWidget = new KeyValueWidget(mOneFileWidget);
 
242
 
 
243
        QLabel* moreLabel = new QLabel(mOneFileWidget);
 
244
        moreLabel->setText(QString("<a href='#'>%1</a>").arg(i18nc("@action show more image meta info", "More...")));
 
245
        moreLabel->setAlignment(Qt::AlignRight);
 
246
 
 
247
        QVBoxLayout* layout = new QVBoxLayout(mOneFileWidget);
 
248
        layout->setMargin(2);
 
249
        layout->setSpacing(2);
 
250
        layout->addWidget(mKeyValueWidget);
 
251
        layout->addWidget(moreLabel);
 
252
 
 
253
        mMultipleFilesLabel = new QLabel();
 
254
 
 
255
        mGroup = new SideBarGroup(i18nc("@title:group", "Meta Information"));
 
256
        q->setWidget(mGroup);
 
257
        mGroup->addWidget(mOneFileWidget);
 
258
        mGroup->addWidget(mMultipleFilesLabel);
 
259
 
 
260
        EventWatcher::install(mGroup, QEvent::Show, q, SLOT(updateSideBarContent()));
 
261
 
 
262
        QObject::connect(moreLabel, SIGNAL(linkActivated(QString)),
 
263
                         q, SLOT(showMetaInfoDialog()));
 
264
    }
 
265
 
 
266
    void forgetCurrentDocument()
 
267
    {
 
268
        if (mDocument) {
 
269
            QObject::disconnect(mDocument.data(), 0, q, 0);
 
270
            // "Garbage collect" document
 
271
            mDocument = 0;
 
272
        }
 
273
    }
266
274
};
267
275
 
268
 
 
269
276
InfoContextManagerItem::InfoContextManagerItem(ContextManager* manager)
270
277
: AbstractContextManagerItem(manager)
271
 
, d(new InfoContextManagerItemPrivate) {
272
 
        d->q = this;
273
 
        d->setupGroup();
274
 
        connect(contextManager(), SIGNAL(selectionChanged()),
275
 
                SLOT(updateSideBarContent()) );
276
 
        connect(contextManager(), SIGNAL(selectionDataChanged()),
277
 
                SLOT(updateSideBarContent()) );
278
 
}
279
 
 
280
 
InfoContextManagerItem::~InfoContextManagerItem() {
281
 
        delete d;
282
 
}
283
 
 
284
 
 
285
 
void InfoContextManagerItem::updateSideBarContent() {
286
 
        LOG("updateSideBarContent");
287
 
        if (!d->mGroup->isVisible()) {
288
 
                LOG("updateSideBarContent: not visible, not updating");
289
 
                return;
290
 
        }
291
 
        LOG("updateSideBarContent: really updating");
292
 
 
293
 
        KFileItemList itemList = contextManager()->selectedFileItemList();
294
 
        if (itemList.count() == 0) {
295
 
                d->forgetCurrentDocument();
296
 
                d->mOneFileWidget->hide();
297
 
                d->mMultipleFilesLabel->hide();
298
 
                d->updateMetaInfoDialog();
299
 
                return;
300
 
        }
301
 
 
302
 
        KFileItem item = itemList.first();
303
 
        if (itemList.count() == 1 && !ArchiveUtils::fileItemIsDirOrArchive(item)) {
304
 
                fillOneFileGroup(item);
305
 
        } else {
306
 
                fillMultipleItemsGroup(itemList);
307
 
        }
308
 
        d->updateMetaInfoDialog();
309
 
}
310
 
 
311
 
void InfoContextManagerItem::fillOneFileGroup(const KFileItem& item) {
312
 
        d->mOneFileWidget->show();
313
 
        d->mMultipleFilesLabel->hide();
314
 
 
315
 
        d->forgetCurrentDocument();
316
 
        d->mDocument = DocumentFactory::instance()->load(item.url());
317
 
        connect(d->mDocument.data(), SIGNAL(metaInfoUpdated()),
318
 
                SLOT(updateOneFileInfo()) );
319
 
 
320
 
        d->updateMetaInfoDialog();
321
 
        updateOneFileInfo();
322
 
}
323
 
 
324
 
void InfoContextManagerItem::fillMultipleItemsGroup(const KFileItemList& itemList) {
325
 
        d->forgetCurrentDocument();
326
 
 
327
 
        int folderCount = 0, fileCount = 0;
328
 
        Q_FOREACH(const KFileItem& item, itemList) {
329
 
                if (item.isDir()) {
330
 
                        folderCount++;
331
 
                } else {
332
 
                        fileCount++;
333
 
                }
334
 
        }
335
 
 
336
 
        if (folderCount == 0) {
337
 
                d->mMultipleFilesLabel->setText(i18ncp("@label", "%1 file selected", "%1 files selected", fileCount));
338
 
        } else if (fileCount == 0) {
339
 
                d->mMultipleFilesLabel->setText(i18ncp("@label", "%1 folder selected", "%1 folders selected", folderCount));
340
 
        } else {
341
 
                d->mMultipleFilesLabel->setText(i18nc("@label. The two parameters are strings like '2 folders' and '1 file'.",
342
 
                        "%1 and %2 selected", i18np("%1 folder", "%1 folders", folderCount), i18np("%1 file", "%1 files", fileCount)));
343
 
        }
344
 
        d->mOneFileWidget->hide();
345
 
        d->mMultipleFilesLabel->show();
346
 
}
347
 
 
348
 
 
349
 
void InfoContextManagerItem::updateOneFileInfo() {
350
 
        if (!d->mDocument) {
351
 
                return;
352
 
        }
353
 
 
354
 
        QStringList list;
355
 
        d->mKeyValueWidget->clear();
356
 
        ImageMetaInfoModel* metaInfoModel = d->mDocument->metaInfo();
357
 
        Q_FOREACH(const QString& key, GwenviewConfig::preferredMetaInfoKeyList()) {
358
 
                QString label;
359
 
                QString value;
360
 
                metaInfoModel->getInfoForKey(key, &label, &value);
361
 
 
362
 
                if (!label.isEmpty() && !value.isEmpty()) {
363
 
                        d->mKeyValueWidget->addRow(label, value);
364
 
                }
365
 
        }
366
 
 
367
 
        d->mKeyValueWidget->show();
368
 
}
369
 
 
370
 
 
371
 
void InfoContextManagerItem::showMetaInfoDialog() {
372
 
        if (!d->mImageMetaInfoDialog) {
373
 
                d->mImageMetaInfoDialog = new ImageMetaInfoDialog(d->mOneFileWidget);
374
 
                d->mImageMetaInfoDialog->setAttribute(Qt::WA_DeleteOnClose, true);
375
 
                connect(d->mImageMetaInfoDialog, SIGNAL(preferredMetaInfoKeyListChanged(const QStringList&)),
376
 
                        SLOT(slotPreferredMetaInfoKeyListChanged(const QStringList&)) );
377
 
        }
378
 
        d->mImageMetaInfoDialog->setMetaInfo(d->mDocument ? d->mDocument->metaInfo() : 0, GwenviewConfig::preferredMetaInfoKeyList());
379
 
        d->mImageMetaInfoDialog->show();
380
 
}
381
 
 
382
 
 
383
 
void InfoContextManagerItem::slotPreferredMetaInfoKeyListChanged(const QStringList& list) {
384
 
        GwenviewConfig::setPreferredMetaInfoKeyList(list);
385
 
        GwenviewConfig::self()->writeConfig();
386
 
        updateOneFileInfo();
387
 
}
388
 
 
 
278
, d(new InfoContextManagerItemPrivate)
 
279
{
 
280
    d->q = this;
 
281
    d->setupGroup();
 
282
    connect(contextManager(), SIGNAL(selectionChanged()),
 
283
            SLOT(updateSideBarContent()));
 
284
    connect(contextManager(), SIGNAL(selectionDataChanged()),
 
285
            SLOT(updateSideBarContent()));
 
286
}
 
287
 
 
288
InfoContextManagerItem::~InfoContextManagerItem()
 
289
{
 
290
    delete d;
 
291
}
 
292
 
 
293
void InfoContextManagerItem::updateSideBarContent()
 
294
{
 
295
    LOG("updateSideBarContent");
 
296
    if (!d->mGroup->isVisible()) {
 
297
        LOG("updateSideBarContent: not visible, not updating");
 
298
        return;
 
299
    }
 
300
    LOG("updateSideBarContent: really updating");
 
301
 
 
302
    KFileItemList itemList = contextManager()->selectedFileItemList();
 
303
    if (itemList.count() == 0) {
 
304
        d->forgetCurrentDocument();
 
305
        d->mOneFileWidget->hide();
 
306
        d->mMultipleFilesLabel->hide();
 
307
        d->updateMetaInfoDialog();
 
308
        return;
 
309
    }
 
310
 
 
311
    KFileItem item = itemList.first();
 
312
    if (itemList.count() == 1 && !ArchiveUtils::fileItemIsDirOrArchive(item)) {
 
313
        fillOneFileGroup(item);
 
314
    } else {
 
315
        fillMultipleItemsGroup(itemList);
 
316
    }
 
317
    d->updateMetaInfoDialog();
 
318
}
 
319
 
 
320
void InfoContextManagerItem::fillOneFileGroup(const KFileItem& item)
 
321
{
 
322
    d->mOneFileWidget->show();
 
323
    d->mMultipleFilesLabel->hide();
 
324
 
 
325
    d->forgetCurrentDocument();
 
326
    d->mDocument = DocumentFactory::instance()->load(item.url());
 
327
    connect(d->mDocument.data(), SIGNAL(metaInfoUpdated()),
 
328
            SLOT(updateOneFileInfo()));
 
329
 
 
330
    d->updateMetaInfoDialog();
 
331
    updateOneFileInfo();
 
332
}
 
333
 
 
334
void InfoContextManagerItem::fillMultipleItemsGroup(const KFileItemList& itemList)
 
335
{
 
336
    d->forgetCurrentDocument();
 
337
 
 
338
    int folderCount = 0, fileCount = 0;
 
339
    Q_FOREACH(const KFileItem & item, itemList) {
 
340
        if (item.isDir()) {
 
341
            folderCount++;
 
342
        } else {
 
343
            fileCount++;
 
344
        }
 
345
    }
 
346
 
 
347
    if (folderCount == 0) {
 
348
        d->mMultipleFilesLabel->setText(i18ncp("@label", "%1 file selected", "%1 files selected", fileCount));
 
349
    } else if (fileCount == 0) {
 
350
        d->mMultipleFilesLabel->setText(i18ncp("@label", "%1 folder selected", "%1 folders selected", folderCount));
 
351
    } else {
 
352
        d->mMultipleFilesLabel->setText(i18nc("@label. The two parameters are strings like '2 folders' and '1 file'.",
 
353
                                              "%1 and %2 selected", i18np("%1 folder", "%1 folders", folderCount), i18np("%1 file", "%1 files", fileCount)));
 
354
    }
 
355
    d->mOneFileWidget->hide();
 
356
    d->mMultipleFilesLabel->show();
 
357
}
 
358
 
 
359
void InfoContextManagerItem::updateOneFileInfo()
 
360
{
 
361
    if (!d->mDocument) {
 
362
        return;
 
363
    }
 
364
 
 
365
    QStringList list;
 
366
    d->mKeyValueWidget->clear();
 
367
    ImageMetaInfoModel* metaInfoModel = d->mDocument->metaInfo();
 
368
    Q_FOREACH(const QString & key, GwenviewConfig::preferredMetaInfoKeyList()) {
 
369
        QString label;
 
370
        QString value;
 
371
        metaInfoModel->getInfoForKey(key, &label, &value);
 
372
 
 
373
        if (!label.isEmpty() && !value.isEmpty()) {
 
374
            d->mKeyValueWidget->addRow(label, value);
 
375
        }
 
376
    }
 
377
 
 
378
    d->mKeyValueWidget->show();
 
379
}
 
380
 
 
381
void InfoContextManagerItem::showMetaInfoDialog()
 
382
{
 
383
    if (!d->mImageMetaInfoDialog) {
 
384
        d->mImageMetaInfoDialog = new ImageMetaInfoDialog(d->mOneFileWidget);
 
385
        d->mImageMetaInfoDialog->setAttribute(Qt::WA_DeleteOnClose, true);
 
386
        connect(d->mImageMetaInfoDialog, SIGNAL(preferredMetaInfoKeyListChanged(QStringList)),
 
387
                SLOT(slotPreferredMetaInfoKeyListChanged(QStringList)));
 
388
    }
 
389
    d->mImageMetaInfoDialog->setMetaInfo(d->mDocument ? d->mDocument->metaInfo() : 0, GwenviewConfig::preferredMetaInfoKeyList());
 
390
    d->mImageMetaInfoDialog->show();
 
391
}
 
392
 
 
393
void InfoContextManagerItem::slotPreferredMetaInfoKeyListChanged(const QStringList& list)
 
394
{
 
395
    GwenviewConfig::setPreferredMetaInfoKeyList(list);
 
396
    GwenviewConfig::self()->writeConfig();
 
397
    updateOneFileInfo();
 
398
}
389
399
 
390
400
} // namespace