-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: change preview plugin to an app
1.mv preview plugin to apps dir 2.add dde-file-manager-preview exec project 3.change package info Log: add file preview exec
- Loading branch information
Showing
143 changed files
with
10,159 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
.../dde-file-manager-preview-plugins.install → debian/dde-file-manager-preview.install
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
usr/lib/*/dde-file-manager/plugins/previews/*.so | ||
usr/share/mime/packages/dtk-dci.xml | ||
|
||
usr/libexec/dde-file-manager-preview |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
if(NOT DEFINED DFM_PLUGIN_PREVIEW_DIR) | ||
set(DFM_PLUGIN_PREVIEW_DIR ${DFM_PLUGIN_DIR}/previews) | ||
endif() | ||
|
||
add_subdirectory(filepreview) | ||
add_subdirectory(libdfm-preview) | ||
add_subdirectory(pluginpreviews) |
29 changes: 29 additions & 0 deletions
29
src/apps/dde-file-manager-preview/filepreview/CMakeLists.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
cmake_minimum_required(VERSION 3.10) | ||
|
||
set(BIN_NAME "dde-file-manager-preview") | ||
|
||
configure_file( | ||
"../../config.h.in" | ||
"${CMAKE_CURRENT_BINARY_DIR}/config.h" | ||
) | ||
|
||
set(CMAKE_INCLUDE_CURRENT_DIR ON) | ||
find_package(Qt5 COMPONENTS Core REQUIRED) | ||
find_package(Dtk COMPONENTS Widget REQUIRED) | ||
|
||
FILE(GLOB_RECURSE FILEPREVIEW_FILES CONFIGURE_DEPENDS | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*.h" | ||
"${CMAKE_CURRENT_SOURCE_DIR}/*.cpp" | ||
) | ||
|
||
add_executable(${BIN_NAME} | ||
${FILEPREVIEW_FILES} | ||
) | ||
|
||
target_link_libraries(${BIN_NAME} PRIVATE | ||
Qt5::Core | ||
Dtk::Widget | ||
DFM::base | ||
) | ||
|
||
install(TARGETS ${BIN_NAME} DESTINATION ${CMAKE_INSTALL_LIBEXECDIR}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "previewsingleapplication.h" | ||
|
||
#ifdef DFM_ORGANIZATION_NAME | ||
# define ORGANIZATION_NAME DFM_ORGANIZATION_NAME | ||
#else | ||
# define ORGANIZATION_NAME "deepin" | ||
#endif | ||
|
||
int main(int argc, char *argv[]) { | ||
// singlentan process | ||
PreviewSingleApplication app(argc, argv); | ||
|
||
app.setQuitOnLastWindowClosed(false); | ||
app.setOrganizationName(ORGANIZATION_NAME); | ||
Check warning on line 18 in src/apps/dde-file-manager-preview/filepreview/main.cpp GitHub Actions / cppcheck
Check warning on line 18 in src/apps/dde-file-manager-preview/filepreview/main.cpp GitHub Actions / static-check / Call-CppCheck
|
||
app.setApplicationName("Deepin File Preview"); | ||
app.setApplicationVersion("v1.0"); | ||
|
||
QString uniqueKey(app.applicationName()); | ||
bool isSinglentanApp = app.setSingleInstance(uniqueKey); | ||
|
||
if (isSinglentanApp) { | ||
PreviewSingleApplication::processArgs(app.arguments()); | ||
return app.exec(); | ||
} else { | ||
app.handleNewClient(uniqueKey); | ||
return 0; | ||
} | ||
} |
79 changes: 79 additions & 0 deletions
79
src/apps/dde-file-manager-preview/filepreview/previewlibrary.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "previewlibrary.h" | ||
#include "config.h" | ||
|
||
#include <QLibrary> | ||
#include <QDir> | ||
|
||
DFM_LOG_REISGER_CATEGORY(DFMPREVIEW_LOG_CG) | ||
|
||
PreviewLibrary::PreviewLibrary(QObject *parent) | ||
: QObject(parent) | ||
{} | ||
|
||
bool PreviewLibrary::load() | ||
{ | ||
if (previewLib) | ||
return true; | ||
|
||
QString libPath; | ||
{ | ||
//默认路径 | ||
#ifdef QT_DEBUG | ||
char path[PATH_MAX] = {0}; | ||
const char *defaultPath = realpath("../libdfm-preview", path); | ||
#else | ||
auto defaultPath = DFM_PLUGIN_COMMON_EDGE_DIR; | ||
#endif | ||
static_assert(std::is_same<decltype(defaultPath), const char *>::value, "DFM_PLUGIN_COMMON_EDGE_DIR is not a string."); | ||
|
||
QDir dir(defaultPath); | ||
libPath = dir.absoluteFilePath("libdfm-preview.so"); | ||
} | ||
|
||
previewLib = new QLibrary(libPath, this); | ||
if (!previewLib->load()) { | ||
fmCritical() << "Can not load libdfm-preview.so" << previewLib->errorString(); | ||
delete previewLib; | ||
previewLib = nullptr; | ||
return false; | ||
} | ||
|
||
initFunc = (InitializePreview)previewLib->resolve("initFilePreview"); | ||
if (!initFunc) { | ||
fmCritical() << "No such api initFilePreview in libdfm-preview.so"; | ||
delete previewLib; | ||
previewLib = nullptr; | ||
return false; | ||
} | ||
|
||
showFunc = (ShowPreviewDialog)previewLib->resolve("showFilePreviewDialog"); | ||
if (!showFunc) { | ||
fmCritical() << "No such api showFilePreviewDialog in libdfm-preview.so"; | ||
delete previewLib; | ||
previewLib = nullptr; | ||
return false; | ||
} | ||
|
||
initFunc(); | ||
return true; | ||
} | ||
|
||
void PreviewLibrary::unload() | ||
{ | ||
if (previewLib) { | ||
previewLib->unload(); | ||
delete previewLib; | ||
previewLib = nullptr; | ||
showFunc = nullptr; | ||
} | ||
} | ||
|
||
void PreviewLibrary::showPreview(quint64 windowId, const QList<QUrl> &selecturls, const QList<QUrl> dirUrl) | ||
{ | ||
if (showFunc) | ||
showFunc(windowId, selecturls, dirUrl); | ||
} |
36 changes: 36 additions & 0 deletions
36
src/apps/dde-file-manager-preview/filepreview/previewlibrary.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#ifndef PREVIEWLIBRARY_H | ||
#define PREVIEWLIBRARY_H | ||
|
||
#include <dfm-base/dfm_log_defines.h> | ||
|
||
#include <QObject> | ||
#include <QUrl> | ||
|
||
#define DFMPREVIEW_LOG_CG dde_file_manager_preview | ||
DFM_LOG_USE_CATEGORY(DFMPREVIEW_LOG_CG) | ||
Check warning on line 14 in src/apps/dde-file-manager-preview/filepreview/previewlibrary.h GitHub Actions / cppcheck
Check warning on line 14 in src/apps/dde-file-manager-preview/filepreview/previewlibrary.h GitHub Actions / static-check / Call-CppCheck
|
||
|
||
typedef int (*ShowPreviewDialog)(quint64 windowId, const QList<QUrl> &selecturls, const QList<QUrl> dirUrl); | ||
typedef int (*InitializePreview)(); | ||
class QLibrary; | ||
|
||
class PreviewLibrary: public QObject | ||
{ | ||
Q_OBJECT | ||
public: | ||
explicit PreviewLibrary(QObject *parent = nullptr); | ||
|
||
bool load(); | ||
void unload(); | ||
void showPreview(quint64 windowId, const QList<QUrl> &selecturls, const QList<QUrl> dirUrl); | ||
|
||
protected: | ||
ShowPreviewDialog showFunc = nullptr; | ||
InitializePreview initFunc = nullptr; | ||
QLibrary *previewLib = nullptr; | ||
}; | ||
|
||
#endif // PREVIEWLIBRARY_H |
168 changes: 168 additions & 0 deletions
168
src/apps/dde-file-manager-preview/filepreview/previewsingleapplication.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,168 @@ | ||
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd. | ||
// | ||
// SPDX-License-Identifier: GPL-3.0-or-later | ||
|
||
#include "previewsingleapplication.h" | ||
#include "previewlibrary.h" | ||
|
||
#include <dfm-base/utils/windowutils.h> | ||
#include <dfm-base/utils/finallyutil.h> | ||
|
||
#include <QLocalServer> | ||
#include <QLocalSocket> | ||
#include <QStandardPaths> | ||
#include <QTranslator> | ||
#include <QFile> | ||
#include <QDir> | ||
#include <QProcess> | ||
|
||
#include <linux/limits.h> | ||
|
||
DFMBASE_USE_NAMESPACE | ||
// DFM_LOG_REISGER_CATEGORY(DFMPREVIEW_LOG_CG) | ||
|
||
PreviewSingleApplication::PreviewSingleApplication(int &argc, char **argv, int) | ||
: DApplication(argc, argv), localServer(new QLocalServer) | ||
{ | ||
initConnect(); | ||
} | ||
|
||
PreviewSingleApplication::~PreviewSingleApplication() | ||
{ | ||
closeServer(); | ||
} | ||
|
||
void PreviewSingleApplication::handleNewClient(const QString &uniqueKey) | ||
{ | ||
QByteArray data { nullptr }; | ||
|
||
for (const QString &arg : arguments()) { | ||
data.append(arg.toLocal8Bit().toBase64()); | ||
data.append(' '); | ||
} | ||
|
||
if (!data.isEmpty()) | ||
data.chop(1); | ||
|
||
QLocalSocket *socket = getNewClientConnect(uniqueKey, data); | ||
if (socket) { | ||
socket->waitForReadyRead(); | ||
|
||
for (const QByteArray &i : socket->readAll().split(' ')) | ||
fmInfo() << QString::fromLocal8Bit(QByteArray::fromBase64(i)); | ||
|
||
socket->close(); | ||
socket->deleteLater(); | ||
} | ||
} | ||
|
||
void PreviewSingleApplication::processArgs(const QStringList &list) | ||
{ | ||
// parse args | ||
if (list.count() < 4) | ||
return; | ||
|
||
quint64 winId = list[1].toULongLong(); | ||
|
||
QStringList selectUrlsStr = list[2].split(";"); | ||
QStringList dirUrlsStr = list[3].split(";"); | ||
|
||
QList<QUrl> selectUrls(QUrl::fromStringList(selectUrlsStr)); | ||
QList<QUrl> dirUrls(QUrl::fromStringList(dirUrlsStr)); | ||
|
||
PreviewLibrary lib; | ||
if (!lib.load()) | ||
return; | ||
|
||
lib.showPreview(winId, selectUrls, dirUrls); | ||
} | ||
|
||
void PreviewSingleApplication::initConnect() | ||
{ | ||
connect(localServer, &QLocalServer::newConnection, this, &PreviewSingleApplication::handleConnection); | ||
} | ||
|
||
QLocalSocket *PreviewSingleApplication::getNewClientConnect(const QString &key, const QByteArray &message) | ||
{ | ||
QLocalSocket *localSocket = new QLocalSocket; | ||
localSocket->connectToServer(userServerName(key)); | ||
if (localSocket->waitForConnected(1000)) { | ||
if (localSocket->state() == QLocalSocket::ConnectedState) { | ||
if (localSocket->isValid()) { | ||
localSocket->write(message); | ||
localSocket->flush(); | ||
} | ||
} | ||
} else { | ||
fmDebug() << localSocket->errorString(); | ||
} | ||
|
||
return localSocket; | ||
} | ||
|
||
QString PreviewSingleApplication::userServerName(const QString &key) | ||
{ | ||
QString userKey = QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::RuntimeLocation), key); | ||
if (userKey.isEmpty()) { | ||
userKey = QString("%1/%2").arg(QStandardPaths::writableLocation(QStandardPaths::TempLocation), key); | ||
} | ||
return userKey; | ||
} | ||
|
||
bool PreviewSingleApplication::setSingleInstance(const QString &key) | ||
{ | ||
QString userKey = userServerName(key); | ||
|
||
QLocalSocket localSocket; | ||
localSocket.connectToServer(userKey); | ||
|
||
// if connect success, another instance is running. | ||
bool result = localSocket.waitForConnected(1000); | ||
|
||
if (result) | ||
return false; | ||
|
||
localServer->removeServer(userKey); | ||
|
||
bool f = localServer->listen(userKey); | ||
|
||
return f; | ||
} | ||
|
||
void PreviewSingleApplication::handleConnection() | ||
{ | ||
fmDebug() << "New connection is coming"; | ||
QLocalSocket *nextPendingConnection = localServer->nextPendingConnection(); | ||
connect(nextPendingConnection, SIGNAL(readyRead()), this, SLOT(readData())); | ||
} | ||
|
||
void PreviewSingleApplication::closeServer() | ||
{ | ||
if (localServer) { | ||
localServer->removeServer(localServer->serverName()); | ||
localServer->close(); | ||
delete localServer; | ||
localServer = nullptr; | ||
} | ||
} | ||
|
||
void PreviewSingleApplication::readData() | ||
{ | ||
QLocalSocket *socket = qobject_cast<QLocalSocket *>(sender()); | ||
|
||
if (!socket) | ||
return; | ||
|
||
QStringList arguments; | ||
for (const QByteArray &arg_base64 : socket->readAll().split(' ')) { | ||
const QByteArray &arg = QByteArray::fromBase64(arg_base64.simplified()); | ||
|
||
if (arg.isEmpty()) | ||
continue; | ||
|
||
QString argstr = QString::fromLocal8Bit(arg); | ||
arguments << argstr; | ||
} | ||
|
||
processArgs(arguments); | ||
} |
Oops, something went wrong.