mirror of
https://github.com/ModOrganizer2/modorganizer-preview_base.git
synced 2026-07-27 14:01:41 -07:00
Compare commits
18
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
390022e9d6 | ||
|
|
1bfa64842e | ||
|
|
bdd4397c8f | ||
|
|
69fa4b8a3d | ||
|
|
8fe992ed7f | ||
|
|
5597a8eff9 | ||
|
|
02b74362d5 | ||
|
|
d7c6137f29 | ||
|
|
9fc4e63e2d | ||
|
|
247f890396 | ||
|
|
f5318afbdf | ||
|
|
0bdfcb7ae5 | ||
|
|
15f34d3fbd | ||
|
|
9eb356a24b | ||
|
|
1e2c008cab | ||
|
|
886bd07410 | ||
|
|
aaa57ae734 | ||
|
|
c232536d14 |
+8
-12
@@ -1,14 +1,10 @@
|
||||
CMAKE_MINIMUM_REQUIRED(VERSION 2.8.12)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
ADD_COMPILE_OPTIONS($<$<CXX_COMPILER_ID:MSVC>:/MP> $<$<CXX_COMPILER_ID:MSVC>:$<$<CONFIG:RELEASE>:/O2>> $<$<CXX_COMPILER_ID:MSVC>:$<$<CONFIG:RELWITHDEBINFO>:/O2>>)
|
||||
if(DEFINED DEPENDENCIES_DIR)
|
||||
include(${DEPENDENCIES_DIR}/modorganizer_super/cmake_common/mo2.cmake)
|
||||
else()
|
||||
include(${CMAKE_CURRENT_LIST_DIR}/../cmake_common/mo2.cmake)
|
||||
endif()
|
||||
|
||||
SET(PROJ_NAME preview_base)
|
||||
|
||||
PROJECT(${PROJ_NAME})
|
||||
|
||||
SET(DEPENDENCIES_DIR CACHE PATH "")
|
||||
|
||||
# hint to find qt in dependencies path
|
||||
LIST(APPEND CMAKE_PREFIX_PATH ${QT_ROOT}/lib/cmake)
|
||||
|
||||
ADD_SUBDIRECTORY(src)
|
||||
project(preview_base)
|
||||
add_subdirectory(src)
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
version: 1.0.{build}
|
||||
skip_branch_with_pr: true
|
||||
image: Visual Studio 2019
|
||||
environment:
|
||||
WEBHOOK_URL:
|
||||
secure: gOKbXaZM9ImtMD5XrYITvdyZUW/az082G9OIN1EC1Vbg57wBaeLhi49uGjxPw5GVujHku6kxN6ab89zhbS5GVeluR76GM83IbKV4Sh7udXzoYZZdg6YudtYHzdhCgUeiedpswbuczTq9ceIkkfSEWZuh/lMAAVVwvcGsJAnoPFw=
|
||||
build:
|
||||
parallel: true
|
||||
build_script:
|
||||
- pwsh: >-
|
||||
$ErrorActionPreference = 'Stop'
|
||||
|
||||
git clone --depth=1 --no-single-branch https://github.com/ModOrganizer2/modorganizer-umbrella.git c:\projects\modorganizer-umbrella
|
||||
|
||||
New-Item -ItemType Directory -Path c:\projects\modorganizer-build
|
||||
|
||||
cd c:\projects\modorganizer-umbrella
|
||||
|
||||
($env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH -eq $null) ? ($branch = $env:APPVEYOR_REPO_BRANCH) : ($branch = $env:APPVEYOR_PULL_REQUEST_HEAD_REPO_BRANCH)
|
||||
|
||||
git checkout $(git show-ref --verify --quiet refs/remotes/origin/${branch} || echo '-b') ${branch}
|
||||
|
||||
C:\Python37-x64\python.exe unimake.py -d c:\projects\modorganizer-build -s Appveyor_Build=True ${env:APPVEYOR_PROJECT_NAME}
|
||||
|
||||
if($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode ) }
|
||||
artifacts:
|
||||
- path: vsbuild\src\RelWithDebInfo\preview_base.dll
|
||||
name: preview_base_dll
|
||||
- path: vsbuild\src\RelWithDebInfo\preview_base.pdb
|
||||
name: preview_base_pdb
|
||||
- path: vsbuild\src\RelWithDebInfo\preview_base.lib
|
||||
name: preview_base_lib
|
||||
on_success:
|
||||
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
|
||||
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
|
||||
- ps: ./send.ps1 success $env:WEBHOOK_URL
|
||||
on_failure:
|
||||
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
|
||||
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stdout.log
|
||||
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stderr.log
|
||||
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
|
||||
- ps: ./send.ps1 failure $env:WEBHOOK_URL
|
||||
+4
-53
@@ -1,54 +1,5 @@
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.11)
|
||||
cmake_minimum_required(VERSION 3.16)
|
||||
|
||||
CMAKE_POLICY(SET CMP0020 NEW)
|
||||
CMAKE_POLICY(SET CMP0043 NEW)
|
||||
|
||||
FILE(GLOB ${PROJ_NAME}_SRCS *.cpp)
|
||||
FILE(GLOB ${PROJ_NAME}_HDRS *.h)
|
||||
FILE(GLOB ${PROJ_NAME}_FORMS *.ui)
|
||||
|
||||
|
||||
SET(CMAKE_INCLUDE_CURRENT_DIR ON)
|
||||
SET(CMAKE_AUTOMOC ON)
|
||||
SET(CMAKE_AUTOUIC ON)
|
||||
FIND_PACKAGE(Qt5Widgets REQUIRED)
|
||||
QT5_WRAP_UI(${PROJ_NAME}_UIHDRS ${${PROJ_NAME}_FORMS})
|
||||
FIND_PACKAGE(Qt5LinguistTools)
|
||||
QT5_CREATE_TRANSLATION(${PROJ_NAME}_translations_qm ${CMAKE_SOURCE_DIR}/src ${CMAKE_SOURCE_DIR}/src/${PROJ_NAME}_en.ts)
|
||||
|
||||
SET(Boost_USE_STATIC_LIBS ON)
|
||||
SET(Boost_USE_MULTITHREADED ON)
|
||||
SET(Boost_USE_STATIC_RUNTIME OFF)
|
||||
FIND_PACKAGE(Boost)
|
||||
|
||||
IF (Boost_FOUND)
|
||||
INCLUDE_DIRECTORIES(${Boost_INCLUDE_DIRS})
|
||||
ENDIF (Boost_FOUND)
|
||||
|
||||
SET(default_project_path "${CMAKE_SOURCE_DIR}/..")
|
||||
GET_FILENAME_COMPONENT(${default_project_path} ${default_project_path} REALPATH)
|
||||
|
||||
SET(project_path "${default_project_path}" CACHE PATH "path to the other mo projects")
|
||||
SET(lib_path "${project_path}/../../install/libs")
|
||||
|
||||
|
||||
INCLUDE_DIRECTORIES(${project_path}/uibase/src)
|
||||
LINK_DIRECTORIES(${lib_path})
|
||||
|
||||
|
||||
ADD_LIBRARY(${PROJ_NAME} SHARED ${${PROJ_NAME}_HDRS} ${${PROJ_NAME}_SRCS} ${${PROJ_NAME}_UIHDRS} ${${PROJ_NAME}_translations_qm})
|
||||
TARGET_LINK_LIBRARIES(${PROJ_NAME}
|
||||
Qt5::Widgets
|
||||
${Boost_LIBRARIES}
|
||||
uibase)
|
||||
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES COMPILE_FLAGS /GL)
|
||||
SET_TARGET_PROPERTIES(${PROJ_NAME} PROPERTIES LINK_FLAGS_RELWITHDEBINFO "/LTCG /LARGEADDRESSAWARE /OPT:REF /OPT:ICF")
|
||||
|
||||
###############
|
||||
## Installation
|
||||
|
||||
INSTALL(TARGETS ${PROJ_NAME}
|
||||
RUNTIME DESTINATION bin/plugins)
|
||||
INSTALL(FILES $<TARGET_PDB_FILE:${PROJ_NAME}>
|
||||
DESTINATION pdb)
|
||||
add_library(preview_base SHARED)
|
||||
mo2_configure_plugin(preview_base WARNINGS OFF)
|
||||
mo2_install_target(preview_base)
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
Import('qt_env')
|
||||
|
||||
env = qt_env.Clone()
|
||||
|
||||
env.AppendUnique(CPPDEFINES = [ 'PREVIEWBASE_LIBRARY' ])
|
||||
|
||||
lib = env.SharedLibrary('previewBase', env.Glob('*.cpp'))
|
||||
env.InstallModule(lib)
|
||||
|
||||
res = env['QT_USED_MODULES']
|
||||
Return('res')
|
||||
@@ -1,26 +0,0 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-01-14T19:50:56
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
TARGET = previewBase
|
||||
TEMPLATE = lib
|
||||
|
||||
CONFIG += plugins
|
||||
CONFIG += dll
|
||||
|
||||
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets gui
|
||||
|
||||
DEFINES += PREVIEWBASE_LIBRARY
|
||||
|
||||
SOURCES += previewbase.cpp
|
||||
|
||||
HEADERS += previewbase.h
|
||||
|
||||
|
||||
include(../plugin_template.pri)
|
||||
|
||||
OTHER_FILES += \
|
||||
previewbase.json\
|
||||
SConscript
|
||||
+16
-1
@@ -4,9 +4,24 @@
|
||||
<context>
|
||||
<name>PreviewBase</name>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="77"/>
|
||||
<location filename="previewbase.cpp" line="82"/>
|
||||
<source>Preview Base</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="92"/>
|
||||
<source>Supports previewing various types of data files</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="103"/>
|
||||
<source>Enable previewing of basic file types, such as images and text files.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<location filename="previewbase.cpp" line="104"/>
|
||||
<source>Specify a list of comma separated extensions (without ".") that should not be previewed by this plugin.</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
</context>
|
||||
</TS>
|
||||
|
||||
+56
-27
@@ -26,39 +26,49 @@ along with Base Preview plugin. If not, see <http://www.gnu.org/licenses/>.
|
||||
#include <QTextEdit>
|
||||
#include <QtPlugin>
|
||||
#include <QApplication>
|
||||
#include <QDesktopWidget>
|
||||
#include <QScreen>
|
||||
|
||||
|
||||
using namespace MOBase;
|
||||
|
||||
|
||||
PreviewBase::PreviewBase()
|
||||
: m_MOInfo(nullptr)
|
||||
{
|
||||
// set up image reader to be used for all image types qt (the current installation) supports
|
||||
auto imageReader = std::bind(&PreviewBase::genImagePreview, this, std::placeholders::_1, std::placeholders::_2);
|
||||
}
|
||||
|
||||
foreach (const QByteArray &fileType, QImageReader::supportedImageFormats()) {
|
||||
bool PreviewBase::init(IOrganizer *moInfo)
|
||||
{
|
||||
m_MOInfo = moInfo;
|
||||
|
||||
const QStringList& blacklist = m_MOInfo->pluginSetting(name(), "blacklisted_extensions").toString().toLower().split(',');
|
||||
|
||||
// set up image reader to be used for all image types qt (the current installation) supports
|
||||
auto imageReader = std::bind(&PreviewBase::genImagePreview, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
|
||||
foreach(const QByteArray & fileType, QImageReader::supportedImageFormats()) {
|
||||
auto strFileType = QString(fileType).toLower();
|
||||
|
||||
// skip dds as that one is handled by the dds preview plugin.
|
||||
if (strFileType == "dds")
|
||||
if (strFileType == "dds" || blacklist.contains(strFileType))
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[strFileType] = imageReader;
|
||||
}
|
||||
|
||||
auto textReader = std::bind(&PreviewBase::genTxtPreview, this, std::placeholders::_1, std::placeholders::_2);
|
||||
m_PreviewGenerators["txt"] = textReader;
|
||||
m_PreviewGenerators["ini"] = textReader;
|
||||
m_PreviewGenerators["json"] = textReader;
|
||||
m_PreviewGenerators["log"] = textReader;
|
||||
m_PreviewGenerators["cfg"] = textReader;
|
||||
const QStringList supportedTextFormats = { "txt", "ini", "json", "log", "cfg", "psc" };
|
||||
|
||||
auto textReader = std::bind(&PreviewBase::genTxtPreview, this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3);
|
||||
|
||||
}
|
||||
foreach(const QString fileType, supportedTextFormats) {
|
||||
|
||||
// skip blacklisted ones
|
||||
if (blacklist.contains(fileType))
|
||||
continue;
|
||||
|
||||
m_PreviewGenerators[fileType] = textReader;
|
||||
}
|
||||
|
||||
bool PreviewBase::init(MOBase::IOrganizer*)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -67,6 +77,11 @@ QString PreviewBase::name() const
|
||||
return "Preview Base";
|
||||
}
|
||||
|
||||
QString PreviewBase::localizedName() const
|
||||
{
|
||||
return tr("Preview Base");
|
||||
}
|
||||
|
||||
QString PreviewBase::author() const
|
||||
{
|
||||
return "Tannin";
|
||||
@@ -82,14 +97,13 @@ MOBase::VersionInfo PreviewBase::version() const
|
||||
return VersionInfo(1, 1, 0, VersionInfo::RELEASE_FINAL);
|
||||
}
|
||||
|
||||
bool PreviewBase::isActive() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QList<MOBase::PluginSetting> PreviewBase::settings() const
|
||||
{
|
||||
return QList<MOBase::PluginSetting>();
|
||||
QList<PluginSetting> result;
|
||||
result.push_back(PluginSetting("enabled", tr("Enable previewing of basic file types, such as images and text files."), QVariant(true)));
|
||||
result.push_back(PluginSetting("blacklisted_extensions", tr("Specify a list of comma separated extensions (without \".\") "
|
||||
"that should not be previewed by this plugin."), QVariant("")));
|
||||
return result;
|
||||
}
|
||||
|
||||
std::set<QString> PreviewBase::supportedExtensions() const
|
||||
@@ -102,21 +116,32 @@ std::set<QString> PreviewBase::supportedExtensions() const
|
||||
return extensions;
|
||||
}
|
||||
|
||||
QWidget *PreviewBase::genFilePreview(const QString &fileName, const QSize &maxSize) const
|
||||
QWidget* PreviewBase::genFilePreview(const QString &fileName, const QSize &maxSize) const
|
||||
{
|
||||
return genDataPreview(nullptr, fileName, maxSize);
|
||||
}
|
||||
|
||||
QWidget* PreviewBase::genDataPreview(const QByteArray& fileData, const QString& fileName,
|
||||
const QSize& maxSize) const
|
||||
{
|
||||
auto iter = m_PreviewGenerators.find(QFileInfo(fileName).suffix().toLower());
|
||||
if (iter != m_PreviewGenerators.end()) {
|
||||
return iter->second(fileName, maxSize);
|
||||
return iter->second(fileName, maxSize, fileData);
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
QWidget *PreviewBase::genImagePreview(const QString &fileName, const QSize&) const
|
||||
QWidget *PreviewBase::genImagePreview(const QString &fileName, const QSize&, const QByteArray& fileData) const
|
||||
{
|
||||
QLabel *label = new QLabel();
|
||||
QPixmap pic = QPixmap(fileName);
|
||||
QSize screenSize = QApplication::desktop()->screenGeometry().size();
|
||||
QPixmap pic;
|
||||
if (fileData == nullptr) {
|
||||
pic = QPixmap(fileName);
|
||||
} else {
|
||||
pic.loadFromData(fileData);
|
||||
}
|
||||
QSize screenSize = QApplication::primaryScreen()->geometry().size();
|
||||
// ensure the output image is no more than 80% of the screen height.
|
||||
// If the aspect ratio is higher than that of the screen this would still allow the image to extend
|
||||
// beyond the screen but it ensures you can drag the window and close it
|
||||
@@ -128,10 +153,14 @@ QWidget *PreviewBase::genImagePreview(const QString &fileName, const QSize&) con
|
||||
return label;
|
||||
}
|
||||
|
||||
QWidget *PreviewBase::genTxtPreview(const QString &fileName, const QSize&) const
|
||||
QWidget *PreviewBase::genTxtPreview(const QString &fileName, const QSize&, const QByteArray& fileData) const
|
||||
{
|
||||
QTextEdit *edit = new QTextEdit();
|
||||
edit->setText(MOBase::readFileText(fileName));
|
||||
if (fileData == nullptr) {
|
||||
edit->setText(MOBase::readFileText(fileName));
|
||||
} else {
|
||||
edit->setText(MOBase::decodeTextData(fileData));
|
||||
}
|
||||
edit->setReadOnly(true);
|
||||
return edit;
|
||||
}
|
||||
|
||||
+16
-12
@@ -37,26 +37,30 @@ public:
|
||||
PreviewBase();
|
||||
|
||||
public:
|
||||
virtual bool init(MOBase::IOrganizer *moInfo);
|
||||
virtual QString name() const;
|
||||
virtual QString author() const;
|
||||
virtual QString description() const;
|
||||
virtual MOBase::VersionInfo version() const;
|
||||
virtual bool isActive() const;
|
||||
virtual QList<MOBase::PluginSetting> settings() const;
|
||||
virtual bool init(MOBase::IOrganizer *moInfo) override;
|
||||
virtual QString name() const override;
|
||||
virtual QString localizedName() const override;
|
||||
virtual QString author() const override;
|
||||
virtual QString description() const override;
|
||||
virtual MOBase::VersionInfo version() const override;
|
||||
virtual QList<MOBase::PluginSetting> settings() const override;
|
||||
|
||||
public:
|
||||
virtual std::set<QString> supportedExtensions() const;
|
||||
virtual QWidget *genFilePreview(const QString &fileName, const QSize &maxSize) const;
|
||||
virtual bool supportsArchives() const override { return true; }
|
||||
virtual QWidget* genFilePreview(const QString &fileName, const QSize &maxSize) const;
|
||||
virtual QWidget* genDataPreview(const QByteArray& fileData, const QString& fileName,
|
||||
const QSize& maxSize) const override;
|
||||
|
||||
private:
|
||||
|
||||
QWidget *genImagePreview(const QString &fileName, const QSize &maxSize) const;
|
||||
QWidget *genTxtPreview(const QString &fileName, const QSize &maxSize) const;
|
||||
QWidget *genImagePreview(const QString &fileName, const QSize &maxSize, const QByteArray& fileData) const;
|
||||
QWidget* genTxtPreview(const QString& fileName, const QSize& maxSize, const QByteArray& fileData) const;
|
||||
|
||||
private:
|
||||
std::map<QString, std::function<QWidget*(const QString&, const QSize&)> > m_PreviewGenerators;
|
||||
std::map<QString, std::function<QWidget*(const QString&, const QSize&, const QByteArray&)> > m_PreviewGenerators;
|
||||
|
||||
private:
|
||||
const MOBase::IOrganizer* m_MOInfo;
|
||||
};
|
||||
|
||||
#endif // PREVIEWBASE_H
|
||||
|
||||
Reference in New Issue
Block a user