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

chore: update cmake make ocr optional #128

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
11 changes: 10 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,24 @@ set(CMAKE_AUTORCC ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(ENABLEOCR "Enable OCR" OFF)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

应该在 debian/rules 中加参数设置为 ON

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

修正文件权限等修改后面可以 rebase


include_directories(${PROJECT_BINARY_DIR})
configure_file(${PROJECT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h @ONLY)

find_package(Qt5 REQUIRED COMPONENTS
Core Gui Quick QuickCompiler
DBus Concurrent Svg PrintSupport LinguistTools)
find_package(Qt5Gui)
find_package(DtkDeclarative REQUIRED)
find_package(DtkWidget REQUIRED)
find_package(DtkGui REQUIRED)
find_package(PkgConfig REQUIRED)

# Application
add_subdirectory(src)

add_subdirectory(qimage-plugins)
#add_subdirectory(qimage-plugins)

# Unit Tests
#add_subdirectory(tests)
111 changes: 67 additions & 44 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,48 +1,60 @@
cmake_minimum_required(VERSION 3.1)

#玲珑构建依赖目录
include_directories(${CMAKE_INSTALL_PREFIX}/include)
include_directories(${CMAKE_INSTALL_PREFIX}/include/deepin-ocr-plugin-manager)

set(APP_BIN_INSTALL_DIR ${CMAKE_INSTALL_PREFIX}/bin/)
set(BIN_NAME ${CMAKE_PROJECT_NAME})
list (APPEND RESOURCES)

# Set sources
set(SRC
main.cpp
)

# 源文件
file(GLOB_RECURSE SRCS
./src/*.h
./src/*.cpp
)
main.cpp
)

file(GLOB OCR
./src/ocr/*.h
./src/ocr/*.cpp
)

file(GLOB UIONIMAGE
./src/unionimage/*.h
./src/unionimage/*.cpp
)

file(GLOB DBUS
./src/dbus/*.h
./src/dbus/*.cpp
)

file(GLOB PRINTDIALOG
./src/printdialog/*.h
./src/printdialog/*.cpp
)

file(GLOB UTILS
./src/utils/*.h
./src/utils/*.cpp
)

file(GLOB TOP
./src/*.h
./src/*.cpp
)

set(SRCS
${PRINTDIALOG}
${DBUS}
${UIONIMAGE}
${UTILS}
${TOP}
)

if(ENABLEOCR)
list(APPEND SRCS
${OCR}
)
endif()

file(GLOB_RECURSE QMLSRC
./*.qml
)

# Find the Qt5Quick library
find_package(Qt5Quick CONFIG REQUIRED)
find_package(Qt5QuickCompiler REQUIRED)
find_package(Qt5DBus CONFIG REQUIRED)
find_package(Qt5Concurrent CONFIG REQUIRED)
find_package(Qt5Svg CONFIG REQUIRED)
find_package(Qt5PrintSupport CONFIG REQUIRED)
find_package(Qt5LinguistTools CONFIG REQUIRED)
./*.qml
)

pkg_search_module(LIBRAW REQUIRED IMPORTED_TARGET libraw)
qtquick_compiler_add_resources(RCC_SOURCES ${RESOURCES})

find_package(PkgConfig REQUIRED)
pkg_check_modules(3rd_lib REQUIRED
dtkwidget
)

# OCR
pkg_search_module(OCR_PLUGIN REQUIRED deepin-ocr-plugin-manager)
include_directories(${OCR_PLUGIN_INCLUDE_DIRS})

# 保证 src 目录下头文件全局可见
include_directories(src)

Expand All @@ -65,17 +77,28 @@ add_executable(${BIN_NAME}
${QM}
deepin-image-viewer.qrc
res.qrc
)
)

target_include_directories(${BIN_NAME} PUBLIC ${3rd_lib_INCLUDE_DIRS})
target_link_libraries(${BIN_NAME}
${DtkDeclarative_LIBRARIES}
Qt5::Quick Qt5::PrintSupport Qt5::Gui Qt5::Qml Qt5::Core Qt5::DBus Qt5::Concurrent Qt5::Svg
Qt5::Quick
Qt5::PrintSupport
Qt5::Gui
Qt5::Qml
Qt5::Core
Qt5::DBus
Qt5::Concurrent
Qt5::Svg
GL pthread freeimage
${3rd_lib_LIBRARIES}
${OCR_PLUGIN_LIBRARIES}
)

${DtkWidget_LIBRARIES}
PkgConfig::LIBRAW
)
if(ENABLEOCR)
target_link_libraries(${BIN_NAME}
PkgConfig::OCR_PLUGIN
)

endif()
if (${CMAKE_BUILD_TYPE} MATCHES "Debug")
TARGET_COMPILE_DEFINITIONS(${BIN_NAME} PRIVATE $<$<OR:$<CONFIG:Debug>,$<CONFIG:RelWithDebInfo>>:QT_QML_DEBUG>)
endif ()
Expand Down
5 changes: 4 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
#include "src/filecontrol.h"
#include "src/thumbnailload.h"
#include "src/cursortool.h"
#ifdef ENABLEOCR
#include "src/ocr/livetextanalyzer.h"
#endif
#include "src/dbus/applicationadpator.h"
#include "config.h"

Expand Down Expand Up @@ -67,14 +69,15 @@ int main(int argc, char *argv[])
CursorTool *cursorTool = new CursorTool();
engine.rootContext()->setContextProperty("cursorTool", cursorTool);
// OCR分析工具
#ifdef ENABLEOCR
auto liveTextAnalyzer = new LiveTextAnalyzer;
engine.rootContext()->setContextProperty("liveTextAnalyzer", liveTextAnalyzer);
engine.addImageProvider(QLatin1String("liveTextAnalyzer"), liveTextAnalyzer);

engine.load(QUrl(QStringLiteral("qrc:/qml/main.qml")));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

main.qml 被包括进宏

if (engine.rootObjects().isEmpty())
return -1;

#endif
// 设置DBus接口
ApplicationAdaptor adaptor(fileControl);
QDBusConnection::sessionBus().registerService("com.deepin.imageViewer");
Expand Down
12 changes: 9 additions & 3 deletions src/src/filecontrol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@
#include "unionimage/unionimage_global.h"
#include "unionimage/unionimage.h"
#include "printdialog/printhelper.h"
#include <qmimedata.h>
#ifdef ENABLEOCR
#include "ocr/ocrinterface.h"
#endif

#include <DSysInfo>

#include <QJsonArray>
#include <QJsonDocument>
#include <QFileInfo>
#include <QDir>
#include <QMimeDatabase>
Expand Down Expand Up @@ -82,8 +87,9 @@ QUrl UrlInfo(QString path)

FileControl::FileControl(QObject *parent) : QObject(parent)
{
#ifdef ENABLEOCR
m_ocrInterface = new OcrInterface("com.deepin.Ocr", "/com/deepin/Ocr", QDBusConnection::sessionBus(), this);

#endif
m_shortcutViewProcess = new QProcess(this);

m_config = LibConfigSetter::instance();
Expand Down Expand Up @@ -340,7 +346,6 @@ void FileControl::copyImage(const QString &path)
QString localPath = QUrl(path).toLocalFile();

QClipboard *cb = qApp->clipboard();

// Ownership of the new data is transferred to the clipboard.
QMimeData *newMimeData = new QMimeData();

Expand Down Expand Up @@ -430,6 +435,7 @@ bool FileControl::isFile(const QString &path)
return QFileInfo(localPath).isFile();
}

#ifdef ENABLEOCR
void FileControl::ocrImage(const QString &path, int index)
{
slotRotatePixCurrent();
Expand All @@ -445,7 +451,7 @@ void FileControl::ocrImage(const QString &path, int index)
m_ocrInterface->openFile(tempFileName);
}
}

#endif
QString FileControl::parseCommandlineGetPath(const QString &path)
{
Q_UNUSED(path)
Expand Down
6 changes: 6 additions & 0 deletions src/src/filecontrol.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
#include <QMap>
#include <QFileSystemWatcher>

#ifdef ENABLEOCR
class OcrInterface;
#endif
class QProcess;

class FileControl : public QObject
Expand Down Expand Up @@ -64,8 +66,10 @@ class FileControl : public QObject
//是否是文件
Q_INVOKABLE bool isFile(const QString &path);

#ifdef ENABLEOCR
//进行ocr识别
Q_INVOKABLE void ocrImage(const QString &path, int index);
#endif

// Q_INVOKABLE double fitImage(int imgWidth, int windowWidth);

Expand Down Expand Up @@ -203,7 +207,9 @@ class FileControl : public QObject
QString createShortcutString();

private :
#ifdef ENABLEOCR
OcrInterface *m_ocrInterface;
#endif
QString m_currentPath; // 当前操作的旋转图片路径
QString m_shortcutString; // 快捷键字符串,将采用懒加载模式,需要通过createShortcutString()函数使用
QProcess *m_shortcutViewProcess; // 快捷键面板进程
Expand Down
Empty file modified src/src/printdialog/printhelper.cpp
100755 → 100644
Empty file.
Empty file modified src/src/printdialog/printhelper.h
100755 → 100644
Empty file.
Empty file modified src/src/unionimage/baseutils.cpp
100755 → 100644
Empty file.
Empty file modified src/src/unionimage/baseutils.h
100755 → 100644
Empty file.
Empty file modified src/src/unionimage/imageutils.cpp
100755 → 100644
Empty file.
Empty file modified src/src/unionimage/imageutils.h
100755 → 100644
Empty file.
2 changes: 1 addition & 1 deletion src/translations/deepin-image-viewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
</message>
<message>
<source>day</source>
<translation>day</translation>
<translation type="vanished">day</translation>
</message>
<message>
<source>Image Viewer is an image viewing tool with fashion interface and smooth performance.</source>
Expand Down
8 changes: 4 additions & 4 deletions src/translations/deepin-image-viewer_am_ET.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@
<source>Image Viewer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>day</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Image Viewer is an image viewing tool with fashion interface and smooth performance.</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -396,5 +392,9 @@
<source>%1 is released under %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open image</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
8 changes: 4 additions & 4 deletions src/translations/deepin-image-viewer_ar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@
<source>Image Viewer</source>
<translation type="unfinished">عارض الصور</translation>
</message>
<message>
<source>day</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Image Viewer is an image viewing tool with fashion interface and smooth performance.</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -396,5 +392,9 @@
<source>%1 is released under %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open image</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
10 changes: 6 additions & 4 deletions src/translations/deepin-image-viewer_az.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" ?><!DOCTYPE TS><TS version="2.1" language="az">
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE TS>
<TS version="2.1" language="az">
<context>
<name>FileControl</name>
<message>
Expand Down Expand Up @@ -233,7 +235,7 @@
</message>
<message>
<source>day</source>
<translation>gün</translation>
<translation type="vanished">gün</translation>
</message>
<message>
<source>Image Viewer is an image viewing tool with fashion interface and smooth performance.</source>
Expand Down Expand Up @@ -396,7 +398,7 @@
</message>
<message>
<source>Open image</source>
<translation type="unfinished"/>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
</TS>
8 changes: 4 additions & 4 deletions src/translations/deepin-image-viewer_bg.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,10 +233,6 @@
<source>Image Viewer</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>day</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Image Viewer is an image viewing tool with fashion interface and smooth performance.</source>
<translation type="unfinished"></translation>
Expand Down Expand Up @@ -396,5 +392,9 @@
<source>%1 is released under %2</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Open image</source>
<translation type="unfinished"></translation>
</message>
</context>
</TS>
Loading