Skip to content

Commit

Permalink
feat: Merge permission/watermark into master
Browse files Browse the repository at this point in the history
合并权限控制和水印需求到主线.

* 新增权限控制(PermissionConfig), 允许配置功能开闭;
* 新增水印功能, 允许通过配置定制阅读和打印水印;
* 水印接口特殊, DTKWidget主线和定制线的接口不同;
* 调整合入代码以兼容各版本.

Log: 回合看图权限控制和水印需求
Task: https://pms.uniontech.com/story-view-27785.html
Task: https://pms.uniontech.com/story-view-30217.html
Influence: Print Permission
  • Loading branch information
rb-union committed Jan 23, 2024
1 parent 315b3ab commit 70c1371
Show file tree
Hide file tree
Showing 12 changed files with 494 additions and 317 deletions.
39 changes: 15 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 @@ -17,6 +17,7 @@
#include "unionimage/unionimage.h"
#include "service/permissionconfig.h"
#include "service/imagedataservice.h"

class ImageEnginePrivate
{
public:
Expand All @@ -26,11 +27,13 @@ class ImageEnginePrivate
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);
// 关联授权操作通知信号
Expand All @@ -44,10 +47,7 @@ ImageEnginePrivate::ImageEnginePrivate(ImageEngine *parent): q_ptr(parent)
workerThread->start();
}

ImageEnginePrivate::~ImageEnginePrivate()
{

}
ImageEnginePrivate::~ImageEnginePrivate() {}

ImageEngine *ImageEngine::m_ImageEngine = nullptr;

Expand All @@ -64,23 +64,13 @@ ImageEngine::ImageEngine(QWidget *parent)
: QObject(parent)
, d_ptr(new ImageEnginePrivate(this))
{
// Q_D(ImageEngine);
}

ImageEngine::~ImageEngine()
{

}
ImageEngine::~ImageEngine() {}

void ImageEngine::makeImgThumbnail(QString thumbnailSavePath, QStringList paths, int makeCount, bool remake)

Check warning on line 71 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 71 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++.
{
//执行子线程制作缩略图动作
// 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);
Expand All @@ -93,16 +83,16 @@ bool ImageEngine::isImage(const QString &path)
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 @@ -112,15 +102,16 @@ bool ImageEngine::isRotatable(const QString &path)
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
2 changes: 1 addition & 1 deletion 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
57 changes: 36 additions & 21 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 Down Expand Up @@ -31,15 +31,24 @@
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)
{
// 在界面前初始化授权配置
Expand All @@ -64,8 +73,7 @@ ImageViewerPrivate::ImageViewerPrivate(imageViewerSpace::ImgViewerType imgViewer

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 Down Expand Up @@ -98,21 +106,27 @@ ImageViewerPrivate::ImageViewerPrivate(imageViewerSpace::ImgViewerType imgViewer
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);
}
});
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)
ImageViewer::ImageViewer(imageViewerSpace::ImgViewerType imgViewerType,
QString savePath,

Check warning on line 127 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 @@ -141,7 +155,8 @@ bool ImageViewer::startdragImage(const QStringList &paths, const QString &firstP
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 @@ -161,7 +176,7 @@ void ImageViewer::startImgView(const QString &currentPath, const QStringList &pa

//启动线程制作缩略图
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
51 changes: 28 additions & 23 deletions libimageviewer/imageviewer.h
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 @@ -14,69 +14,74 @@ class AbstractTopToolbar;

DWIDGET_USE_NAMESPACE


class ImageViewerPrivate;
class IMAGEVIEWERSHARED_EXPORT ImageViewer : public DWidget
{
Q_OBJECT
public:
//ImgViewerType:图片展示类型, savePath:缩略图保存位置,customTopToolbar:自定义标题栏,nullptr的时候使用内置方案
explicit ImageViewer(imageViewerSpace::ImgViewerType imgViewerType, QString savePath, AbstractTopToolbar *customTopToolbar = nullptr, QWidget *parent = nullptr);
// ImgViewerType:图片展示类型, savePath:缩略图保存位置,customTopToolbar:自定义标题栏,nullptr的时候使用内置方案
explicit ImageViewer(imageViewerSpace::ImgViewerType imgViewerType,
QString savePath,
AbstractTopToolbar *customTopToolbar = nullptr,
QWidget *parent = nullptr);
~ImageViewer() override;

//调用文件选择窗口
// 调用文件选择窗口
bool startChooseFileDialog();

//传入路径加载图片 paths:所有照片 firstPath:第一张 isCustom:是否是自定义相册 album:自定义相册名称
bool startdragImage(const QStringList &paths, const QString &firstPath = "", bool isCustom = false, const QString &album = "");
// 传入路径加载图片 paths:所有照片 firstPath:第一张 isCustom:是否是自定义相册 album:自定义相册名称
bool
startdragImage(const QStringList &paths, const QString &firstPath = "", bool isCustom = false, const QString &album = "");

//传入路径加载图片 paths:所有照片 firstPath:第一张 isCustom:是否是自定义相册 album:自定义相册名称 UID:相册的UID
bool startdragImageWithUID(const QStringList &paths, const QString &firstPath = "", bool isCustom = false, const QString &album = "", int UID = -1);
// 传入路径加载图片 paths:所有照片 firstPath:第一张 isCustom:是否是自定义相册 album:自定义相册名称 UID:相册的UID
bool startdragImageWithUID(
const QStringList &paths, const QString &firstPath = "", bool isCustom = false, const QString &album = "", int UID = -1);

//启动图片展示入口
// 启动图片展示入口
void startImgView(const QString &currentPath, const QStringList &paths = QStringList());

//设置topbar的显示和隐藏
// 设置topbar的显示和隐藏
void setTopBarVisible(bool visible);

//设置Bottomtoolbar的显示和隐藏
// 设置Bottomtoolbar的显示和隐藏
void setBottomtoolbarVisible(bool visible);

//获得工具栏按钮
// 获得工具栏按钮
DIconButton *getBottomtoolbarButton(imageViewerSpace::ButtonType type);

//获得当前展示图片路径
// 获得当前展示图片路径
QString getCurrentPath();

//二次开发接口
// 二次开发接口

//设置图片显示panel右键菜单的显示和隐藏,false为永久隐藏,true为跟随原有策略显示或隐藏
// 设置图片显示panel右键菜单的显示和隐藏,false为永久隐藏,true为跟随原有策略显示或隐藏
void setViewPanelContextMenuItemVisible(imageViewerSpace::NormalMenuItemId id, bool visible);

//设置下方工具栏按钮的显示和隐藏,true为永久隐藏,false为跟随原有策略显示或隐藏
// 设置下方工具栏按钮的显示和隐藏,true为永久隐藏,false为跟随原有策略显示或隐藏
void setBottomToolBarButtonAlawysNotVisible(imageViewerSpace::ButtonType id, bool notVisible);

//相册-给右键菜单传输自定义相册名称
// 相册-给右键菜单传输自定义相册名称
void setCustomAlbumName(const QMap<QString, bool> map, bool isFav);

//相册-给右键菜单传输自定义相册名称的UID方案接口,map的参数依次是UID,相册名,是否在此相册
// 相册-给右键菜单传输自定义相册名称的UID方案接口,map的参数依次是UID,相册名,是否在此相册
void setCustomAlbumNameAndUID(const QMap<int, std::pair<QString, bool> > &map, bool isFav);

//设置全屏/退出全屏
// 设置全屏/退出全屏
void switchFullScreen();

//设置启动幻灯片
// 设置启动幻灯片
void startSlideShow(const QStringList &paths, const QString &firstPath);

//设置panel拖拽使能
// 设置panel拖拽使能
void setDropEnabled(bool enable);

protected:
void resizeEvent(QResizeEvent *e) override;
void showEvent(QShowEvent *e) override;

private:
QScopedPointer<ImageViewerPrivate> d_ptr;
Q_DECLARE_PRIVATE_D(qGetPtrHelper(d_ptr), ImageViewer)
};

#endif // IMAGEVIEWER_H
#endif // IMAGEVIEWER_H
Loading

0 comments on commit 70c1371

Please sign in to comment.