Skip to content

Commit

Permalink
Add support for ImagePack tool invocation
Browse files Browse the repository at this point in the history
  • Loading branch information
Shengjie Xu committed Nov 29, 2023
1 parent a2c9193 commit c8a0639
Show file tree
Hide file tree
Showing 9 changed files with 702 additions and 42 deletions.
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ set(PROJECT_SOURCES
outputwidget.ui
ExecutionData.h
resource.qrc

tooldialog/imagepacktooldialog.h
tooldialog/imagepacktooldialog.cpp
tooldialog/imagepacktooldialog.ui

${WINDOWS_SOURCES}
${TS_FILES}
)
Expand Down Expand Up @@ -69,6 +74,8 @@ else()
qt5_create_translation(QM_FILES ${CMAKE_SOURCE_DIR} ${TS_FILES})
endif()

target_include_directories(preppipe_gui AFTER PRIVATE ${CMAKE_SOURCE_DIR})

target_link_libraries(preppipe_gui PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

set_target_properties(preppipe_gui PROPERTIES
Expand Down
2 changes: 1 addition & 1 deletion ExecutionData.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ struct ExecutionInfo {
QString program;
QStringList args;
QHash<QString, QString> envs;
QHash<int, UnspecifiedPathInfo> unspecfiedPaths;
QHash<int, UnspecifiedPathInfo> unspecifiedPaths;
QList<OutputInfo> specifiedOutputs;
};

Expand Down
4 changes: 2 additions & 2 deletions executewindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,15 @@ void ExecuteWindow::init(const ExecutionInfo& info)
isCanClose = false;
static const QString SEPARATOR = QString("=").repeated(20);
QStringList args = info.args;
if (info.unspecfiedPaths.size() > 0) {
if (info.unspecifiedPaths.size() > 0) {
if (!tmpdir.isValid()) {
// 无法创建临时目录,无法执行
ui->plainTextEdit->setPlainText(tr(u8"有未指定的输出且无法创建临时目录,无法执行"));
return;
}
}
QDir tmppath(tmpdir.path());
for (auto iter = info.unspecfiedPaths.begin(), iterEnd = info.unspecfiedPaths.end(); iter != iterEnd; ++iter) {
for (auto iter = info.unspecifiedPaths.begin(), iterEnd = info.unspecifiedPaths.end(); iter != iterEnd; ++iter) {
int argindex = iter.key();
const auto& info = iter.value();
QString fullpath = tmppath.filePath(info.defaultName);
Expand Down
83 changes: 52 additions & 31 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include "executewindow.h"
#include "tooldialog/imagepacktooldialog.h"

#include <QDir>
#include <QProcessEnvironment>
Expand Down Expand Up @@ -133,6 +134,7 @@ MainWindow::MainWindow(QWidget *parent)
ui->statusbar->showMessage(tr(u8"请指定主程序路径"));

connect(ui->actionTranslationExport, &QAction::triggered, this, &MainWindow::requestTranslationExport);
connect(ui->actionImagePackTool, &QAction::triggered, this, &MainWindow::requestImagePackTool);

// 初始化时尝试寻找主程序
QMetaObject::invokeMethod(this, &MainWindow::search_exe, Qt::QueuedConnection);
Expand Down Expand Up @@ -245,23 +247,44 @@ InputFlagBuilder ifb({

} // end anonymous namespace

bool MainWindow::populateInitialExecutionInfo(ExecutionInfo& info)
{
bool isAllGood = true;
// 主程序
QString prog = ui->mainExecutableSelectionWidget->getCurrentPath();
if (prog.isEmpty()) {
prog = tr(u8"<未指定:%1>").arg(ui->mainExecutableSelectionWidget->getFieldName());
isAllGood = false;
}
info.program = prog;

//环境变量
QString pluginpath = ui->pluginSelectionWidget->getCurrentPath();
if (pluginpath.length() > 0) {
info.envs.insert("PREPPIPE_PLUGINS", pluginpath);
}

// 设置部分
if (ui->languageCheckBox->isChecked()) {
info.args.append("--language");
auto data = ui->languageComboBox->currentData();
info.args.append(data.toString());
}

return isAllGood;
}

void MainWindow::settingsChanged()
{
ExecutionInfo newInfo;

QStringList args;
QHash<QString, QString> envs;
QHash<int, UnspecifiedPathInfo> unspecifiedPaths;
QList<OutputInfo> specifiedOutputs;
bool isExecutableSpecified = populateInitialExecutionInfo(newInfo);
QStringList& args = newInfo.args;
QHash<int, UnspecifiedPathInfo>& unspecifiedPaths = newInfo.unspecifiedPaths;
QList<OutputInfo>& specifiedOutputs = newInfo.specifiedOutputs;
QStringList errors;

QString unspecified = tr(u8"<未指定:%1>");
bool isExecutableSpecified = false;

// 从环境变量开始
QString pluginpath = ui->pluginSelectionWidget->getCurrentPath();
if (pluginpath.length() > 0) {
envs.insert("PREPPIPE_PLUGINS", pluginpath);
}
auto populatePath = [&](FileSelectionWidget* w) -> void {
if (w->getIsOutputInsteadofInput()) {
OutputInfo outInfo;
Expand All @@ -283,23 +306,10 @@ void MainWindow::settingsChanged()
}
};

// 主程序
QString prog = ui->mainExecutableSelectionWidget->getCurrentPath();
if (prog.length() == 0) {
prog = unspecified.arg(ui->mainExecutableSelectionWidget->getFieldName());
} else {
isExecutableSpecified = true;
}

// 设置部分
if (ui->verboseCheckBox->isChecked()) {
args.append("-v");
}
if (ui->languageCheckBox->isChecked()) {
args.append("--language");
auto data = ui->languageComboBox->currentData();
args.append(data.toString());
}

// 搜索路径
auto searchpaths = ui->searchPathInputWidget->getCurrentList();
Expand Down Expand Up @@ -401,11 +411,7 @@ void MainWindow::settingsChanged()
}
}

curInfo.program = prog;
curInfo.args = args;
curInfo.envs = envs;
curInfo.unspecfiedPaths = unspecifiedPaths;
curInfo.specifiedOutputs = specifiedOutputs;
curInfo = newInfo;
ui->executePushButton->setEnabled(errors.size() == 0);

if (errors.size() > 0) {
Expand All @@ -416,7 +422,7 @@ void MainWindow::settingsChanged()
ui->statusbar->clearMessage();
}

ui->commandTextEdit->setPlainText(getMergedCommand(prog, args));
ui->commandTextEdit->setPlainText(getMergedCommand(curInfo.program, curInfo.args));
}

void MainWindow::requestLaunch()
Expand All @@ -429,7 +435,7 @@ void MainWindow::requestLaunch()
for (auto iter = curInfo.specifiedOutputs.begin(), iterEnd = curInfo.specifiedOutputs.end(); iter != iterEnd; ++iter) {
qDebug() << "output: " << iter->argindex << ": " << iter->fieldName;
}
for (auto iter = curInfo.unspecfiedPaths.begin(), iterEnd = curInfo.unspecfiedPaths.end(); iter != iterEnd; ++iter) {
for (auto iter = curInfo.unspecifiedPaths.begin(), iterEnd = curInfo.unspecifiedPaths.end(); iter != iterEnd; ++iter) {
qDebug() << "unspecified: " << iter.key() << ": " << iter.value().defaultName;
}
ExecuteWindow* w = new ExecuteWindow();
Expand Down Expand Up @@ -484,3 +490,18 @@ void MainWindow::requestTranslationExportImpl(const QString& path)
w->show();
}

void MainWindow::requestImagePackTool()
{
// 首先,执行该操作需要已经选好主程序
ExecutionInfo initInfo;
bool programProvided = populateInitialExecutionInfo(initInfo);
if (!programProvided) {
QMessageBox::critical(this, tr(u8"主程序未选择"), tr(u8"使用工具前需要先选择主程序,请在选好主程序后再尝试该操作。"));
return;
}
// 然后显示对话框,不用等待完成
ImagePackToolDialog* dialog = new ImagePackToolDialog(this);
dialog->setInitialExecutionInfo(initInfo);
dialog->show();
}

13 changes: 5 additions & 8 deletions mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ QT_BEGIN_NAMESPACE
namespace Ui { class MainWindow; }
QT_END_NAMESPACE

struct ExecuteInfo
{
QStringList args;
QHash<QString, QString> envs;
QHash<int, UnspecifiedPathInfo> unspecfiedPaths;
QStringList errors;
};

class MainWindow : public QMainWindow
{
Q_OBJECT
Expand All @@ -27,13 +19,18 @@ class MainWindow : public QMainWindow
static constexpr int LONGSAYSPLITTING_MIN_START_LENGTH = 180;
static constexpr int LONGSAYSPLITTING_TARGET_LENGTH = 60;

// 构建适用于任何流程(包括正常的编译流程和使用工具的部分)的初始命令信息
// 如果关键项有问题(比如没有指定主程序)就返回 false
bool populateInitialExecutionInfo(ExecutionInfo& info);

private slots:
void search_exe();
void settingsChanged();
void inputListChanged();
void requestLaunch();
void requestTranslationExport();
void requestTranslationExportImpl(const QString& path);
void requestImagePackTool();

private:
Ui::MainWindow *ui;
Expand Down
12 changes: 12 additions & 0 deletions mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -525,14 +525,26 @@
</property>
<addaction name="actionTranslationExport"/>
</widget>
<widget class="QMenu" name="toolMenu">
<property name="title">
<string>工具</string>
</property>
<addaction name="actionImagePackTool"/>
</widget>
<addaction name="operationMenu"/>
<addaction name="toolMenu"/>
</widget>
<widget class="QStatusBar" name="statusbar"/>
<action name="actionTranslationExport">
<property name="text">
<string>导出翻译、别名文件</string>
</property>
</action>
<action name="actionImagePackTool">
<property name="text">
<string>图片包</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
Loading

0 comments on commit c8a0639

Please sign in to comment.