添加使用自定义图标时将图标复制到配置文件夹中。
This commit is contained in:
parent
ee51c70880
commit
d52af47719
@ -1,11 +1,9 @@
|
||||
#include "adddesktop.h"
|
||||
#include <QTextStream>
|
||||
#include "ui_adddesktop.h"
|
||||
#include <QTextStream>
|
||||
#include <fstream>
|
||||
|
||||
AddDesktop::AddDesktop(QWidget *parent) :
|
||||
QDialog(parent),
|
||||
ui(new Ui::AddDesktop)
|
||||
AddDesktop::AddDesktop(QWidget* parent) : QDialog(parent), ui(new Ui::AddDesktop)
|
||||
{
|
||||
ui->setupUi(this);
|
||||
|
||||
@ -36,12 +34,10 @@ AddDesktop::AddDesktop(QWidget *parent) :
|
||||
ui->cbCategories->setCurrentIndex(ui->cbCategories->count() - 1);
|
||||
|
||||
connect(ui->ckUseDefault, &QCheckBox::toggled, this, &AddDesktop::checkchange);
|
||||
connect(ui->btnSelectBinary, &QPushButton::clicked, this, [=](){
|
||||
MainWidget::SelectFile(this, ui->edBinary, "请选择二进制文件", "所有文件 (*)");
|
||||
});
|
||||
connect(ui->btnSelectIco, &QPushButton::clicked, this, [=](){
|
||||
MainWidget::SelectFile(this, ui->edIco, "请选择ico图标文件", "图标文件(*.ico);;所有文件 (*)");
|
||||
});
|
||||
connect(ui->btnSelectBinary, &QPushButton::clicked, this,
|
||||
[=]() { MainWidget::SelectFile(this, ui->edBinary, "请选择二进制文件", "所有文件 (*)"); });
|
||||
connect(ui->btnSelectIco, &QPushButton::clicked, this,
|
||||
[=]() { MainWidget::SelectFile(this, ui->edIco, "请选择ico图标文件", "图标文件(*.ico);;所有文件 (*)"); });
|
||||
connect(ui->btnInstall, &QPushButton::clicked, this, &AddDesktop::install_to_desktop);
|
||||
}
|
||||
|
||||
@ -50,8 +46,7 @@ void AddDesktop::checkchange()
|
||||
if (ui->ckUseDefault->isChecked()) {
|
||||
ui->edIco->setEnabled(false);
|
||||
ui->btnSelectIco->setEnabled(false);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
ui->edIco->setEnabled(true);
|
||||
ui->btnSelectIco->setEnabled(true);
|
||||
}
|
||||
@ -70,7 +65,7 @@ void AddDesktop::install_to_desktop()
|
||||
}
|
||||
|
||||
QTextStream stream(&file);
|
||||
QString content = stream.readAll();
|
||||
QString content = stream.readAll();
|
||||
file.close();
|
||||
std::string ct = content.toStdString();
|
||||
std::string tool_name = fs::path(ui->edBinary->text().trimmed().toStdString()).filename().string();
|
||||
@ -78,21 +73,25 @@ void AddDesktop::install_to_desktop()
|
||||
boost::replace_all(ct, "re_describe", tool_name);
|
||||
boost::replace_all(ct, "re_path", ui->edBinary->text().trimmed().toStdString());
|
||||
|
||||
if (!ui->ckUseDefault->isChecked()) {
|
||||
boost::replace_all(ct, "re_icon", ui->edIco->text().trimmed().toStdString());
|
||||
fs::path default_ico_path = fs::path(tmp).append("packqt");
|
||||
if (!fs::exists(default_ico_path)) {
|
||||
fs::create_directories(default_ico_path);
|
||||
}
|
||||
else {
|
||||
fs::path default_ico_path = fs::path(tmp).append("packqt");
|
||||
if (!fs::exists(default_ico_path)) {
|
||||
fs::create_directories(default_ico_path);
|
||||
}
|
||||
if (ui->ckUseDefault->isChecked()) {
|
||||
default_ico_path.append("Tools.svg");
|
||||
QFile::copy("://resource/Tools.svg", QString::fromStdString(default_ico_path.string()));
|
||||
boost::replace_all(ct, "re_icon", default_ico_path.string());
|
||||
|
||||
} else {
|
||||
std::string icn = ui->edIco->text().trimmed().toStdString();
|
||||
boost::replace_all(ct, "re_icon", icn);
|
||||
default_ico_path.append(fs::path(icn).filename());
|
||||
fs::copy_file(icn, default_ico_path, fs::copy_options::overwrite_existing);
|
||||
}
|
||||
|
||||
boost::replace_all(ct, "re_category", ui->cbCategories->currentText().toStdString());
|
||||
tmp.append(tool_name + ".desktop");;
|
||||
tmp.append(tool_name + ".desktop");
|
||||
;
|
||||
std::ofstream out(tmp.string(), std::ios::out);
|
||||
if (!out.is_open()) {
|
||||
return;
|
||||
@ -105,7 +104,4 @@ void AddDesktop::install_to_desktop()
|
||||
MainWidget::message(this, "完成");
|
||||
}
|
||||
|
||||
AddDesktop::~AddDesktop()
|
||||
{
|
||||
delete ui;
|
||||
}
|
||||
AddDesktop::~AddDesktop() { delete ui; }
|
||||
|
Loading…
x
Reference in New Issue
Block a user