]>
cloud.milkyroute.net Git - dolphin.git/blob - src/panels/information/metadatawidget.cpp
1 /***************************************************************************
2 * Copyright (C) 2009 by Peter Penz <peter.penz@gmx.at> *
4 * This program is free software; you can redistribute it and/or modify *
5 * it under the terms of the GNU General Public License as published by *
6 * the Free Software Foundation; either version 2 of the License, or *
7 * (at your option) any later version. *
9 * This program is distributed in the hope that it will be useful, *
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
12 * GNU General Public License for more details. *
14 * You should have received a copy of the GNU General Public License *
15 * along with this program; if not, write to the *
16 * Free Software Foundation, Inc., *
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
18 ***************************************************************************/
20 #include "metadatawidget.h"
22 #include <kfileitem.h>
25 #include <config-nepomuk.h>
27 #include "commentwidget_p.h"
28 #include "nepomukmassupdatejob_p.h"
29 #include "taggingwidget_p.h"
32 #include <nepomuk/kratingwidget.h>
34 #include <QGridLayout>
39 class MetaDataWidget::Private
48 Private(MetaDataWidget
* parent
);
51 void addRow(QLabel
* label
, QWidget
* infoWidget
);
52 void setRowVisible(QWidget
* infoWidget
, bool visible
);
56 QGridLayout
* m_gridLayout
;
61 QLabel
* m_modifiedInfo
;
63 QLabel
* m_permissionsInfo
;
65 KRatingWidget
* m_ratingWidget
;
66 TaggingWidget
* m_taggingWidget
;
67 CommentWidget
* m_commentWidget
;
71 MetaDataWidget
* const q
;
74 MetaDataWidget::Private::Private(MetaDataWidget
* parent
) :
90 m_gridLayout
= new QGridLayout(parent
);
92 m_typeInfo
= new QLabel(parent
);
93 m_sizeLabel
= new QLabel(parent
);
94 m_sizeInfo
= new QLabel(parent
);
95 m_modifiedInfo
= new QLabel(parent
);
96 m_ownerInfo
= new QLabel(parent
);
97 m_permissionsInfo
= new QLabel(parent
);
99 m_ratingWidget
= new KRatingWidget(parent
);
100 m_taggingWidget
= new TaggingWidget(parent
);
101 m_commentWidget
= new CommentWidget(parent
);
104 addRow(new QLabel(i18nc("@label", "Type:"), parent
), m_typeInfo
);
105 addRow(m_sizeLabel
, m_sizeInfo
);
106 addRow(new QLabel(i18nc("@label", "Modified:"), parent
), m_modifiedInfo
);
107 addRow(new QLabel(i18nc("@label", "Owner:"), parent
), m_ownerInfo
);
108 addRow(new QLabel(i18nc("@label", "Permissions:"), parent
), m_permissionsInfo
);
110 addRow(new QLabel(i18nc("@label", "Rating:"), parent
), m_ratingWidget
);
111 addRow(new QLabel(i18nc("@label", "Tags:"), parent
), m_taggingWidget
);
112 addRow(new QLabel(i18nc("@label", "Comment:"), parent
), m_commentWidget
);
116 MetaDataWidget::Private::~Private()
120 void MetaDataWidget::Private::addRow(QLabel
* label
, QWidget
* infoWidget
)
124 row
.infoWidget
= infoWidget
;
127 QPalette palette
= label
->palette();
128 QColor textColor
= palette
.color(QPalette::Text
);
129 textColor
.setAlpha(128);
130 palette
.setColor(QPalette::WindowText
, textColor
);
131 label
->setPalette(palette
);
133 const int rowIndex
= m_rows
.count();
134 m_gridLayout
->addWidget(label
, rowIndex
, 0, Qt::AlignLeft
);
135 m_gridLayout
->addWidget(infoWidget
, rowIndex
, 1, Qt::AlignRight
);
138 void MetaDataWidget::Private::setRowVisible(QWidget
* infoWidget
, bool visible
)
140 foreach (const Row
& row
, m_rows
) {
141 if (row
.infoWidget
== infoWidget
) {
142 row
.label
->setVisible(visible
);
143 row
.infoWidget
->setVisible(visible
);
150 MetaDataWidget::MetaDataWidget(QWidget
* parent
) :
156 MetaDataWidget::~MetaDataWidget()
161 void MetaDataWidget::setItem(const KFileItem
& item
)
163 // update values for "type", "size", "modified",
164 // "owner" and "permissions" synchronously
165 d
->m_sizeLabel
->setText(i18nc("@label", "Size:"));
167 d
->m_typeInfo
->setText(i18nc("@label", "Folder"));
168 d
->setRowVisible(d
->m_sizeInfo
, false);
170 d
->m_typeInfo
->setText(item
.mimeComment());
171 d
->m_sizeInfo
->setText(KIO::convertSize(item
.size()));
172 d
->setRowVisible(d
->m_sizeInfo
, true);
174 d
->m_modifiedInfo
->setText(item
.timeString());
175 d
->m_ownerInfo
->setText(item
.user());
176 d
->m_permissionsInfo
->setText(item
.permissionsString());
178 setItems(KFileItemList() << item
);
181 void MetaDataWidget::setItems(const KFileItemList
& items
)
183 if (items
.count() > 1) {
184 // calculate the size of all items and show this
185 // information to the user
186 d
->m_sizeLabel
->setText(i18nc("@label", "Total Size:"));
187 d
->setRowVisible(d
->m_sizeInfo
, true);
189 quint64 totalSize
= 0;
190 foreach (const KFileItem
& item
, items
) {
191 if (!item
.isDir() && !item
.isLink()) {
192 totalSize
+= item
.size();
195 d
->m_sizeInfo
->setText(KIO::convertSize(totalSize
));
199 #include "metadatawidget.moc"