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