Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add media file information display in property dialog #2532

Merged
merged 4 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/dfm-base/base/configs/settingbackend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,7 @@ void SettingBackend::initWorkspaceSettingConfig()
{ "keys", viewModeKeys } },
1);
ins->addConfig(LV2_GROUP_VIEW ".04_restore_view_mode",
{ { "key", "03_restore_view_mode" },
{ { "key", "04_restore_view_mode" },
{ "desc", tr("Restore default view mode for all directories") },
{ "text", tr("Restore default view mode") },
{ "type", "pushButton" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ enum PropertyFilterType {
kFilePositionFiled = 1 << 6,
kFileCreateTimeFiled = 1 << 7,
kFileAccessedTimeFiled = 1 << 8,
kFileModifiedTimeFiled = 1 << 9
kFileModifiedTimeFiled = 1 << 9,
kFileImageSizeFiled = 1 << 10,
kFileMediaResolutionFiled = 1 << 11,
kFileMediaDurationFiled = 1 << 12
};
Q_ENUM_NS(PropertyFilterType)

Expand All @@ -50,6 +53,9 @@ enum BasicFieldExpandEnum : int {
kFileCreateTime,
kFileAccessedTime,
kFileModifiedTime,
kFileImageSize,
kFileMediaResolution,
kFileMediaDuration,
};
Q_ENUM_NS(BasicFieldExpandEnum)

Expand Down
128 changes: 127 additions & 1 deletion src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,19 @@
#include "utils/propertydialogmanager.h"

#include <dfm-base/dfm_event_defines.h>
#include <dfm-base/base/schemefactory.h>

Check warning on line 10 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/base/schemefactory.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 10 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/base/schemefactory.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/interfaces/fileinfo.h>

Check warning on line 11 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/interfaces/fileinfo.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 11 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/interfaces/fileinfo.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/utils/fileutils.h>

Check warning on line 12 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/utils/fileutils.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 12 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/utils/fileutils.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/utils/fileinfohelper.h>

Check warning on line 13 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/utils/fileinfohelper.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 13 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/utils/fileinfohelper.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/utils/universalutils.h>

Check warning on line 14 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/utils/universalutils.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 14 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/utils/universalutils.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <dfm-base/mimetype/mimetypedisplaymanager.h>

Check warning on line 15 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-base/mimetype/mimetypedisplaymanager.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 15 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-base/mimetype/mimetypedisplaymanager.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <dfm-framework/event/event.h>

Check warning on line 17 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-framework/event/event.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 17 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-framework/event/event.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <dfm-io/dfileinfo.h>

Check warning on line 19 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <dfm-io/dfileinfo.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 19 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <dfm-io/dfileinfo.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#ifdef DTKWIDGET_CLASS_DSizeMode
# include <DSizeMode>

Check warning on line 22 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <DSizeMode> not found. Please note: Cppcheck does not need standard library headers to get proper results.

Check warning on line 22 in src/plugins/common/dfmplugin-propertydialog/views/basicwidget.cpp

View workflow job for this annotation

GitHub Actions / static-check / static-check

Include file: <DSizeMode> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#endif
#include <DGuiApplicationHelper>

Expand All @@ -32,6 +39,7 @@

Q_DECLARE_METATYPE(QList<QUrl> *)

USING_IO_NAMESPACE
DWIDGET_USE_NAMESPACE
DFMBASE_USE_NAMESPACE
using namespace dfmplugin_propertydialog;
Expand Down Expand Up @@ -90,6 +98,10 @@
DFontSizeManager::instance()->bind(hideFile, DFontSizeManager::SizeType::T7, QFont::Normal);
hideFile->setText(tr("Hide this file"));
hideFile->setToolTip(hideFile->text());

fileImgSize = createValueLabel(frameMain, tr("Image size"));
fileMediaResolution = createValueLabel(frameMain, tr("Resolution"));
fileMediaDuration = createValueLabel(frameMain, tr("Duration"));
}

KeyValueLabel *BasicWidget::createValueLabel(QFrame *frame, QString leftValue)
Expand Down Expand Up @@ -214,6 +226,18 @@
fieldMap.remove(BasicFieldExpandEnum::kFileModifiedTime);
fileModified->deleteLater();
fileModified = nullptr;
} else if (fieldFilter & PropertyFilterType::kFileImageSizeFiled) {
fieldMap.remove(BasicFieldExpandEnum::kFileImageSize);
fileImgSize->deleteLater();
fileImgSize = nullptr;
} else if (fieldFilter & PropertyFilterType::kFileMediaResolutionFiled) {
fieldMap.remove(BasicFieldExpandEnum::kFileMediaResolution);
fileMediaResolution->deleteLater();
fileMediaResolution = nullptr;
} else if (fieldFilter & PropertyFilterType::kFileMediaDurationFiled) {
fieldMap.remove(BasicFieldExpandEnum::kFileMediaDuration);
fileMediaDuration->deleteLater();
fileMediaDuration = nullptr;
}
}

Expand Down Expand Up @@ -279,9 +303,15 @@
fCount = 1;
fileSize->setRightValue(FileUtils::formatSize(fSize), Qt::ElideNone, Qt::AlignVCenter, true);
}
if (fileImgSize && fileImgSize->RightValue().isEmpty())
fileImgSize->setVisible(false);
if (fileMediaResolution && fileMediaResolution->RightValue().isEmpty())
fileMediaResolution->setVisible(false);
if (fileMediaDuration && fileMediaDuration->RightValue().isEmpty())
fileMediaDuration->setVisible(false);

if (fileType && fileType->RightValue().isEmpty()) {
const FileInfo::FileType type = info->fileType();
FileInfo::FileType type = info->fileType();
fileType->setRightValue(info->displayOf(DisPlayInfoType::kMimeTypeDisplayName), Qt::ElideMiddle, Qt::AlignVCenter, true);
if (type == FileInfo::FileType::kDirectory && fileCount && fileCount->RightValue().isEmpty()) {
fileCount->setRightValue(tr("%1 item").arg(0), Qt::ElideNone, Qt::AlignVCenter, true);
Expand All @@ -297,7 +327,38 @@
delete fileCount;
fileCount = nullptr;
}

QUrl localUrl = url;
QList<QUrl> urls {};
bool ok = UniversalUtils::urlsTransformToLocal({ localUrl }, &urls);
if (ok && !urls.isEmpty())
localUrl = urls.first();
FileInfoPointer localinfo = InfoFactory::create<FileInfo>(localUrl);
const QString &mimeName { localinfo->nameOf(NameInfoType::kMimeTypeName) };
type = MimeTypeDisplayManager::instance()->displayNameToEnum(mimeName);
QList<DFileInfo::AttributeExtendID> extenList;
if (type == FileInfo::FileType::kVideos) {
extenList << DFileInfo::AttributeExtendID::kExtendMediaWidth << DFileInfo::AttributeExtendID::kExtendMediaHeight << DFileInfo::AttributeExtendID::kExtendMediaDuration;
connect(&FileInfoHelper::instance(), &FileInfoHelper::mediaDataFinished, this, &BasicWidget::videoExtenInfo);
const QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> &mediaAttributes = localinfo->mediaInfoAttributes(DFileInfo::MediaType::kVideo, extenList);
if (!mediaAttributes.isEmpty())
videoExtenInfo(url, mediaAttributes);
} else if (type == FileInfo::FileType::kImages) {
extenList << DFileInfo::AttributeExtendID::kExtendMediaWidth << DFileInfo::AttributeExtendID::kExtendMediaHeight;
connect(&FileInfoHelper::instance(), &FileInfoHelper::mediaDataFinished, this, &BasicWidget::imageExtenInfo);
const QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> &mediaAttributes = localinfo->mediaInfoAttributes(DFileInfo::MediaType::kImage, extenList);
if (!mediaAttributes.isEmpty())
imageExtenInfo(url, mediaAttributes);
} else if (type == FileInfo::FileType::kAudios) {
extenList << DFileInfo::AttributeExtendID::kExtendMediaDuration;
connect(&FileInfoHelper::instance(), &FileInfoHelper::mediaDataFinished, this, &BasicWidget::audioExtenInfo);
const QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> &mediaAttributes = localinfo->mediaInfoAttributes(DFileInfo::MediaType::kAudio, extenList);
if (!mediaAttributes.isEmpty())
audioExtenInfo(url, mediaAttributes);
}
}


}

void BasicWidget::initFileMap()
Expand All @@ -309,6 +370,9 @@
fieldMap.insert(BasicFieldExpandEnum::kFileCreateTime, fileCreated);
fieldMap.insert(BasicFieldExpandEnum::kFileAccessedTime, fileAccessed);
fieldMap.insert(BasicFieldExpandEnum::kFileModifiedTime, fileModified);
fieldMap.insert(BasicFieldExpandEnum::kFileImageSize, fileImgSize);
fieldMap.insert(BasicFieldExpandEnum::kFileMediaResolution, fileMediaResolution);
fieldMap.insert(BasicFieldExpandEnum::kFileMediaDuration, fileMediaDuration);
}

void BasicWidget::selectFileUrl(const QUrl &url)
Expand Down Expand Up @@ -360,3 +424,65 @@
{
DArrowLineDrawer::closeEvent(event);
}

void BasicWidget::imageExtenInfo(const QUrl &url, QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> properties)
{
if (url != currentUrl) {
return;
}

if (properties.isEmpty()) {
return;
}
int width = properties[DFileInfo::AttributeExtendID::kExtendMediaWidth].toInt();
int height = properties[DFileInfo::AttributeExtendID::kExtendMediaHeight].toInt();
const QString &imgSizeStr = QString::number(width) + "x" + QString::number(height);

fileImgSize->setRightValue(imgSizeStr, Qt::ElideNone, Qt::AlignVCenter, true);
fileImgSize->setVisible(true);
}

void BasicWidget::videoExtenInfo(const QUrl &url, QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> properties)
{
if (url != currentUrl) {
return;
}
if (properties.isEmpty()) {
return;
}

int width = properties[DFileInfo::AttributeExtendID::kExtendMediaWidth].toInt();
int height = properties[DFileInfo::AttributeExtendID::kExtendMediaHeight].toInt();
const QString &videoResolutionStr = QString::number(width) + "x" + QString::number(height);

QVariant duration = properties[DFileInfo::AttributeExtendID::kExtendMediaDuration];

QTime t(0, 0, 0);
t = t.addMSecs(duration.toInt());

const QString &durationStr = t.toString("hh:mm:ss");

fileMediaResolution->setRightValue(videoResolutionStr, Qt::ElideNone, Qt::AlignVCenter, true);
fileMediaResolution->setVisible(true);
fileMediaDuration->setRightValue(durationStr, Qt::ElideNone, Qt::AlignVCenter, true);
fileMediaDuration->setVisible(true);
}

void BasicWidget::audioExtenInfo(const QUrl &url, QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> properties)
{
if (url != currentUrl) {
return;
}
if (properties.isEmpty()) {
return;
}

QVariant duration = properties[DFileInfo::AttributeExtendID::kExtendMediaDuration];
QTime t(0, 0, 0);
t = t.addMSecs(duration.toInt());

const QString &durationStr = t.toString("hh:mm:ss");

fileMediaDuration->setRightValue(durationStr, Qt::ElideNone, Qt::AlignVCenter, true);
fileMediaDuration->setVisible(true);
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public slots:

void slotFileHide(int state);

void imageExtenInfo(const QUrl &url, QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> properties);
void videoExtenInfo(const QUrl &url, QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> properties);
void audioExtenInfo(const QUrl &url, QMap<DFMIO::DFileInfo::AttributeExtendID, QVariant> properties);

protected:
virtual void closeEvent(QCloseEvent *event) override;

Expand All @@ -59,6 +63,9 @@ public slots:
DFMBASE_NAMESPACE::KeyValueLabel *fileModified { nullptr };
DFMBASE_NAMESPACE::KeyValueLabel *fileAccessed { nullptr };
QCheckBox *hideFile { nullptr };
DFMBASE_NAMESPACE::KeyValueLabel *fileImgSize { nullptr };
DFMBASE_NAMESPACE::KeyValueLabel *fileMediaResolution { nullptr };
DFMBASE_NAMESPACE::KeyValueLabel *fileMediaDuration { nullptr };
bool hideCheckBox { false };
DFMBASE_NAMESPACE::FileStatisticsJob *fileCalculationUtils { nullptr };
qint64 fSize { 0 };
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,15 @@ void IconItemDelegate::paintItemFileName(QPainter *painter, QRectF iconRect, QPa
layout->setAttribute(ElideTextLayout::kBackgroundRadius, kIconModeRectRadius);
}

// If the filename is very long, sizeHint() will set the height of the last item to maximum
// to make the scrollbar appear on the right side.
// However, when the last item is not a single selection target,
// we don't need to draw the filename at maximum height
if (!isSelected || !singleSelected) {
qreal normalHeight = lineHeight * 2;
labelRect.setHeight(labelRect.height() > normalHeight ? normalHeight : labelRect.height());
}

layout->layout(labelRect, opt.textElideMode, painter, background);
}

Expand All @@ -671,7 +680,8 @@ QSize IconItemDelegate::sizeHint(const QStyleOptionViewItem &, const QModelIndex
int lineHeight = UniversalUtils::getTextLineHeight(index, parent()->parent()->fontMetrics());
size.setHeight(size.height() + 2 * lineHeight);

// 如果有一个选中,名称显示很长时,最后一个index时设置item的高度为最多,右边才会出现滑动块
// If there is one selection and the name is very long,
// set the item height to maximum for the last index to make the scrollbar appear on the right side
if (index.isValid() && parent()->isLastIndex(index) && d->expandedItem
&& d->expandedIndex.isValid() && d->expandedItem->isVisible()) {
d->expandedItem->setIconHeight(parent()->parent()->iconSize().height());
Expand Down
Loading
Loading