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: Merge permission/watermark into master #122

Merged
merged 12 commits into from
Jan 23, 2024
10 changes: 10 additions & 0 deletions .tx/config
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
[main]
host = https://www.transifex.com
minimum_perc = 80
mode = developer

[o:linuxdeepin:p:libimage-viewer:r:libimage-viewer]
file_filter = src/libimageviewer/translations/libimageviewer_<lang>.ts
source_file = src/libimageviewer/translations/libimageviewer.ts
source_lang = en
type = QT
1 change: 1 addition & 0 deletions .tx/deepin.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
[transifex]
branch = m20
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ message(STATUS ${CMAKE_CXX_FLAGS})

option(DOTEST "option for test" OFF)

if(DOTEST)
if(DOTEST OR CMAKE_BUILD_TYPE STREQUAL "Debug")
add_subdirectory(tests)
endif()

Expand Down
47 changes: 23 additions & 24 deletions libimageviewer/imageengine.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -15,7 +15,9 @@
#include "service/commonservice.h"
#include "unionimage/imgoperate.h"
#include "unionimage/unionimage.h"
#include "service/permissionconfig.h"
#include "service/imagedataservice.h"

class ImageEnginePrivate
{
public:
Expand All @@ -25,13 +27,17 @@
public:
ImageEngine *const q_ptr;
LibImgOperate *m_worker = nullptr;
// QString m_thumbnailSavePath;//缩略图保存路径

Q_DECLARE_PUBLIC(ImageEngine)

Check warning on line 31 in libimageviewer/imageengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'd_func' is never used.
Q_DISABLE_COPY(ImageEnginePrivate)
};

ImageEnginePrivate::ImageEnginePrivate(ImageEngine *parent): q_ptr(parent)
ImageEnginePrivate::ImageEnginePrivate(ImageEngine *parent)
: q_ptr(parent)
{
Q_Q(ImageEngine);
// 关联授权操作通知信号
QObject::connect(PermissionConfig::instance(), &PermissionConfig::authoriseNotify, q, &ImageEngine::sigAuthoriseNotify);

QThread *workerThread = new QThread(q_ptr);
m_worker = new LibImgOperate(workerThread);
Expand All @@ -41,10 +47,7 @@
workerThread->start();
}

ImageEnginePrivate::~ImageEnginePrivate()
{

}
ImageEnginePrivate::~ImageEnginePrivate() {}

ImageEngine *ImageEngine::m_ImageEngine = nullptr;

Expand All @@ -61,45 +64,40 @@
: QObject(parent)
, d_ptr(new ImageEnginePrivate(this))
{
// Q_D(ImageEngine);
}

ImageEngine::~ImageEngine()
{

}
ImageEngine::~ImageEngine() {}

/**
@brief 构造传入图像 `paths` 的缩略图到路径 `thumbnailSavePath` , `remake` 标识是否重新创建
@note 由于兼容性问题,此处的 `thumbnailSavePath` `paths` 没有调整为引用传递
*/
void ImageEngine::makeImgThumbnail(QString thumbnailSavePath, QStringList paths, int makeCount, bool remake)

Check warning on line 75 in libimageviewer/imageengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'thumbnailSavePath' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.

Check warning on line 75 in libimageviewer/imageengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'paths' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
rb-union marked this conversation as resolved.
Show resolved Hide resolved
{
//执行子线程制作缩略图动作
// QMetaObject::invokeMethod(d->m_worker, "slotMakeImgThumbnail"
// , Q_ARG(QString, thumbnailSavePath)
// , Q_ARG(QStringList, paths)
// , Q_ARG(int, makeCount)
// , Q_ARG(bool, remake)
// );
Q_UNUSED(makeCount);
if (paths.count() > 0) {
LibImageDataService::instance()->readThumbnailByPaths(thumbnailSavePath, paths, remake);
}
}

//判断是否图片格式
bool ImageEngine::isImage(const QString &path)
{
bool bRet = false;
QMimeDatabase db;
QMimeType mt = db.mimeTypeForFile(path, QMimeDatabase::MatchContent);
QMimeType mt1 = db.mimeTypeForFile(path, QMimeDatabase::MatchExtension);
if (mt.name().startsWith("image/") || mt.name().startsWith("video/x-mng") ||
mt1.name().startsWith("image/") || mt1.name().startsWith("video/x-mng")) {
if (mt.name().startsWith("image/") || mt.name().startsWith("video/x-mng") || mt1.name().startsWith("image/") ||
mt1.name().startsWith("video/x-mng")) {
bRet = true;
}
return bRet;
}

bool ImageEngine::isRotatable(const QString &path)
{
//BUG#93143
// BUG#93143
//由于底层代码判断是否可旋转的依据是文件名后缀所代表的图片是否可保存
//因此文件是否存在的判断添加在这一层
QFileInfo info(path);
Expand All @@ -109,15 +107,16 @@
return LibUnionImage_NameSpace::isImageSupportRotate(path);
}
}

//根据文件路径制作md5
QString ImageEngine::makeMD5(const QString &path)
{
QFile file(path);
QString stHashValue;
if (file.open(QIODevice::ReadOnly)) { //只读方式打开
QString stHashValue;
if (file.open(QIODevice::ReadOnly)) { //只读方式打开
QCryptographicHash hash(QCryptographicHash::Md5);

QByteArray buf = file.read(10 * 1024 * 1024); // 每次读取10M
QByteArray buf = file.read(10 * 1024 * 1024); // 每次读取10M
buf = buf.append(path.toUtf8());
hash.addData(buf); // 将数据添加到Hash中
stHashValue.append(hash.result().toHex());
Expand Down
13 changes: 7 additions & 6 deletions libimageviewer/imageengine.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand Down Expand Up @@ -30,7 +30,6 @@ class IMAGEVIEWERSHARED_EXPORT ImageEngine : public QObject
//是否是可选转的图片
bool isRotatable(const QString &path);


//根据文件路径制作md5
QString makeMD5(const QString &path);

Expand All @@ -53,27 +52,29 @@ class IMAGEVIEWERSHARED_EXPORT ImageEngine : public QObject
void sigGetAlbumName(const QString &path);
//添加到已有相册/新建相册
void sigAddToAlbum(bool isNew, const QString &album, const QString &path);
void sigAddToAlbumWithUID(bool isNew, int UID, const QString &path); //采用UID方案的添加至相册
void sigAddToAlbumWithUID(bool isNew, int UID, const QString &path); //采用UID方案的添加至相册
//收藏/取消收藏
void sigAddOrRemoveToFav(const QString &path, bool isAdd);
//导出
void sigExport(const QString &path);
//从自定义相册中移除
void sigRemoveFromCustom(const QString &path, const QString &album);
void sigRemoveFromCustomWithUID(const QString &path, int UID); //采用UID方案的从相册中删除
void sigRemoveFromCustomWithUID(const QString &path, int UID); //采用UID方案的从相册中删除
//退出幻灯片
void exitSlideShow();
//按下ESC键
void escShortcutActivated(bool isSwitchFullScreen);
//通知旋转
void sigRotatePic(const QString &path);

private:
// 授权操作通知信号
void sigAuthoriseNotify(const QJsonObject &data);

private:
static ImageEngine *m_ImageEngine;

QScopedPointer<ImageEnginePrivate> d_ptr;
Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), ImageEngine)
};

#endif // IMAGEENGINE_H
#endif // IMAGEENGINE_H
78 changes: 65 additions & 13 deletions libimageviewer/imageviewer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// SPDX-FileCopyrightText: 2022 - 2023 UnionTech Software Technology Co., Ltd.
// SPDX-FileCopyrightText: 2022 - 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

Expand All @@ -13,31 +13,52 @@
#include <QDirIterator>
#include <QTranslator>
#include <DFileDialog>
#include <dtkwidget_config.h>

#include "imageengine.h"
#include "viewpanel/viewpanel.h"
#include "service/permissionconfig.h"
#include "service/commonservice.h"
#include "service/mtpfileproxy.h"
#include "unionimage/imageutils.h"
#include "unionimage/baseutils.h"

#ifdef DTKWIDGET_CLASS_DWaterMarkHelper
#include <DWaterMarkHelper>
#endif

#define PLUGINTRANSPATH "/usr/share/libimageviewer/translations"
class ImageViewerPrivate
{
public:
ImageViewerPrivate(imageViewerSpace::ImgViewerType imgViewerType, QString savePath, AbstractTopToolbar *customTopToolbar, ImageViewer *parent);
ImageViewerPrivate(imageViewerSpace::ImgViewerType imgViewerType,
const QString &savePath,
AbstractTopToolbar *customTopToolbar,
ImageViewer *parent);

private:
ImageViewer *q_ptr;
LibViewPanel *m_panel = nullptr;
imageViewerSpace::ImgViewerType m_imgViewerType;
ImageViewer *q_ptr;
LibViewPanel *m_panel = nullptr;
imageViewerSpace::ImgViewerType m_imgViewerType;

Q_DECLARE_PUBLIC(ImageViewer)
Q_DISABLE_COPY(ImageViewerPrivate)
};

ImageViewerPrivate::ImageViewerPrivate(imageViewerSpace::ImgViewerType imgViewerType, QString savePath, AbstractTopToolbar *customTopToolbar, ImageViewer *parent)
ImageViewerPrivate::ImageViewerPrivate(imageViewerSpace::ImgViewerType imgViewerType,
const QString &savePath,
AbstractTopToolbar *customTopToolbar,
ImageViewer *parent)
: q_ptr(parent)
{
QDir dir(PLUGINTRANSPATH);
// 在界面前初始化授权配置
if (!qApp) {
qWarning() << qPrintable("Must init authorise config after QApplication initialized!");
} else {
PermissionConfig::instance()->initFromArguments(qApp->arguments());
}

QDir dir(PLUGINTRANSPATH);
if (dir.exists()) {
QDirIterator qmIt(PLUGINTRANSPATH, QStringList() << QString("*%1.qm").arg(QLocale::system().name()), QDir::Files);

Expand All @@ -52,8 +73,7 @@

QStringList parseLocalNameList = QLocale::system().name().split("_", QString::SkipEmptyParts);
if (parseLocalNameList.length() > 0) {
QString translateFilename = QString("/libimageviewer_%2.qm")
.arg(parseLocalNameList.at(0));
QString translateFilename = QString("/libimageviewer_%2.qm").arg(parseLocalNameList.at(0));

QString translatePath = PLUGINTRANSPATH + translateFilename;
if (QFile::exists(translatePath)) {
Expand All @@ -64,7 +84,7 @@
}
}
}
// }

Q_Q(ImageViewer);
m_imgViewerType = imgViewerType;
//记录当前展示模式
Expand All @@ -77,9 +97,40 @@
q->setLayout(layout);
m_panel = new LibViewPanel(customTopToolbar, q);
layout->addWidget(m_panel);

#ifdef DTKWIDGET_CLASS_DWaterMarkHelper
// 设置看图水印,目前仅在主要展示区域显示
if (PermissionConfig::instance()->hasReadWaterMark()) {
auto data = PermissionConfig::instance()->readWaterMarkData();
DWaterMarkHelper::instance()->setData(data);
DWaterMarkHelper::instance()->registerWidget(m_panel);

// 仅权限控制图片单独展示
QObject::connect(PermissionConfig::instance(),
&PermissionConfig::currentImagePathChanged,
q_ptr,
[this](const QString &, bool isTargetImage) {
if (!PermissionConfig::instance()->isValid()) {
return;
}

DWaterMarkWidget *mark = m_panel->findChild<DWaterMarkWidget *>();
if (mark) {
mark->setVisible(isTargetImage);
}
});
}
#endif
}

ImageViewer::ImageViewer(imageViewerSpace::ImgViewerType imgViewerType, QString savePath, AbstractTopToolbar *customTopToolbar, QWidget *parent)
/**
@brief 构造视图展示控件
@note 由于兼容性问题,此处的 `savePath` 没有调整为引用传递
*/
ImageViewer::ImageViewer(imageViewerSpace::ImgViewerType imgViewerType,
QString savePath,

Check warning on line 131 in libimageviewer/imageviewer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Parameter 'savePath' is passed by value. It could be passed as a const reference which is usually faster and recommended in C++.
AbstractTopToolbar *customTopToolbar,
QWidget *parent)
: DWidget(parent)
, d_ptr(new ImageViewerPrivate(imgViewerType, savePath, customTopToolbar, this))
{
Expand Down Expand Up @@ -108,7 +159,8 @@
return d->m_panel->startdragImage(paths, firstPath);
}

bool ImageViewer::startdragImageWithUID(const QStringList &paths, const QString &firstPath, bool isCustom, const QString &album, int UID)
bool ImageViewer::startdragImageWithUID(
const QStringList &paths, const QString &firstPath, bool isCustom, const QString &album, int UID)
{
Q_D(ImageViewer);
d->m_panel->setIsCustomAlbumWithUID(isCustom, album, UID);
Expand All @@ -128,7 +180,7 @@

//启动线程制作缩略图
if (LibCommonService::instance()->getImgViewerType() == imageViewerSpace::ImgViewerTypeLocal ||
LibCommonService::instance()->getImgViewerType() == imageViewerSpace::ImgViewerTypeNull) {
LibCommonService::instance()->getImgViewerType() == imageViewerSpace::ImgViewerTypeNull) {
//首先生成当前图片的缓存
ImageEngine::instance()->makeImgThumbnail(LibCommonService::instance()->getImgSavePath(), QStringList(realPath), 1);
//看图制作全部缩略图
Expand Down
Loading