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 #116

Merged
merged 12 commits into from
Jan 15, 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
3 changes: 3 additions & 0 deletions libimageviewer/imageengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "service/commonservice.h"
#include "unionimage/imgoperate.h"
#include "unionimage/unionimage.h"
#include "service/permissionconfig.h"
#include "service/imagedataservice.h"
class ImageEnginePrivate
{
Expand All @@ -32,9 +33,11 @@
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);

Check warning on line 40 in libimageviewer/imageengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'ImageEnginePrivate' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).

Check warning on line 40 in libimageviewer/imageengine.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'ImageEnginePrivate' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).
m_worker->moveToThread(workerThread);
//一张缩略图制作完成,发送到主线程
q->connect(m_worker, &LibImgOperate::sigOneImgReady, LibCommonService::instance(), &LibCommonService::slotSetImgInfoByPath);
Expand Down
11 changes: 6 additions & 5 deletions libimageviewer/imageengine.h
Original file line number Diff line number Diff line change
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
37 changes: 35 additions & 2 deletions libimageviewer/imageviewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,20 @@
#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
{
Expand All @@ -33,11 +39,17 @@
Q_DECLARE_PUBLIC(ImageViewer)
};

ImageViewerPrivate::ImageViewerPrivate(imageViewerSpace::ImgViewerType imgViewerType, QString savePath, AbstractTopToolbar *customTopToolbar, ImageViewer *parent)

Check warning on line 42 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++.
: 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 @@ -64,7 +76,7 @@
}
}
}
// }

Q_Q(ImageViewer);
m_imgViewerType = imgViewerType;
//记录当前展示模式
Expand All @@ -75,11 +87,32 @@
QVBoxLayout *layout = new QVBoxLayout(q);
layout->setContentsMargins(0, 0, 0, 0);
q->setLayout(layout);
m_panel = new LibViewPanel(customTopToolbar, q);

Check warning on line 90 in libimageviewer/imageviewer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'ImageViewerPrivate' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).

Check warning on line 90 in libimageviewer/imageviewer.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'ImageViewerPrivate' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).
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)

Check warning on line 115 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++.
: DWidget(parent)
, d_ptr(new ImageViewerPrivate(imgViewerType, savePath, customTopToolbar, this))
{
Expand Down
Loading