初步实现菜单栏添加,但是好像还有点问题。
This commit is contained in:
parent
12c7a5a2df
commit
180fdbfc14
@ -34,6 +34,9 @@ set(PROJECT_SOURCES
|
|||||||
MainWidget.cpp
|
MainWidget.cpp
|
||||||
MainWidget.h
|
MainWidget.h
|
||||||
MainWidget.ui
|
MainWidget.ui
|
||||||
|
adddesktop.ui
|
||||||
|
adddesktop.h
|
||||||
|
adddesktop.cpp
|
||||||
packqt.qrc
|
packqt.qrc
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -21,6 +21,7 @@ void MainWidget::connect_operator()
|
|||||||
connect(ui->btnAddEnv, &QPushButton::clicked, this, [=]() { add_env_btn(); });
|
connect(ui->btnAddEnv, &QPushButton::clicked, this, [=]() { add_env_btn(); });
|
||||||
connect(ui->btnDelEnv, &QPushButton::clicked, this, [=]() { del_env_btn(); });
|
connect(ui->btnDelEnv, &QPushButton::clicked, this, [=]() { del_env_btn(); });
|
||||||
connect(ui->btnGenerate, &QPushButton::clicked, this, [=]() { generate(); });
|
connect(ui->btnGenerate, &QPushButton::clicked, this, [=]() { generate(); });
|
||||||
|
connect(ui->btnInstall, &QPushButton::clicked, this, [=]() { install_bin2menu(); });
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainWidget::control_init()
|
void MainWidget::control_init()
|
||||||
@ -53,6 +54,17 @@ void MainWidget::simple_log(const QString& info, bool enter)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 将二进制文件安装到菜单栏
|
||||||
|
void MainWidget::install_bin2menu()
|
||||||
|
{
|
||||||
|
// QString bin = SelectFile(this, ui->edBinary, "请选择二进制可执行文件", "所有文件 (*)");
|
||||||
|
// if (bin.isEmpty()) {
|
||||||
|
// return;
|
||||||
|
// }
|
||||||
|
AddDesktop add(this);
|
||||||
|
add.exec();
|
||||||
|
}
|
||||||
|
|
||||||
// 将某个文件夹拷贝到制定目录下
|
// 将某个文件夹拷贝到制定目录下
|
||||||
bool MainWidget::copy_dir(const std::string& source_dir, const std::string& des_dir)
|
bool MainWidget::copy_dir(const std::string& source_dir, const std::string& des_dir)
|
||||||
{
|
{
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include <boost/filesystem.hpp>
|
#include <boost/filesystem.hpp>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "adddesktop.h"
|
||||||
|
|
||||||
namespace fs = boost::filesystem;
|
namespace fs = boost::filesystem;
|
||||||
|
|
||||||
@ -36,12 +37,14 @@ private:
|
|||||||
void simple_log(const QString& info, bool enter = true);
|
void simple_log(const QString& info, bool enter = true);
|
||||||
// 将某个文件夹拷贝到制定目录下
|
// 将某个文件夹拷贝到制定目录下
|
||||||
bool copy_dir(const std::string& source_dir, const std::string& des_dir);
|
bool copy_dir(const std::string& source_dir, const std::string& des_dir);
|
||||||
|
// 将二进制文件安装到菜单栏
|
||||||
|
void install_bin2menu();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::vector<std::string> get_depend_on(const std::string& name, const std::vector<std::string>& env);
|
std::vector<std::string> get_depend_on(const std::string& name, const std::vector<std::string>& env);
|
||||||
std::list<std::string> handle_result(const std::vector<std::string>& vec);
|
std::list<std::string> handle_result(const std::vector<std::string>& vec);
|
||||||
|
|
||||||
private:
|
public:
|
||||||
static QString SelectDirectory(QWidget* parent, QLineEdit* pEdit, const QString& pre_path = "");
|
static QString SelectDirectory(QWidget* parent, QLineEdit* pEdit, const QString& pre_path = "");
|
||||||
static QString SelectFile(QWidget* parent, QLineEdit* pEdit, const QString& info, const QString& filter);
|
static QString SelectFile(QWidget* parent, QLineEdit* pEdit, const QString& info, const QString& filter);
|
||||||
static bool isOk(QWidget* parent, const QString& title, const QString& content);
|
static bool isOk(QWidget* parent, const QString& title, const QString& content);
|
||||||
|
@ -184,6 +184,13 @@
|
|||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
<layout class="QHBoxLayout" name="horizontalLayout_8">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnInstall">
|
||||||
|
<property name="text">
|
||||||
|
<string>给可执行文件添加到菜单</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="horizontalSpacer">
|
<spacer name="horizontalSpacer">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
94
adddesktop.cpp
Normal file
94
adddesktop.cpp
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
#include "adddesktop.h"
|
||||||
|
#include <QTextStream>
|
||||||
|
#include "ui_adddesktop.h"
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
AddDesktop::AddDesktop(QWidget *parent) :
|
||||||
|
QDialog(parent),
|
||||||
|
ui(new Ui::AddDesktop)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
// Audio:音频应用程序,如播放器、编辑器等。
|
||||||
|
// Video:视频应用程序,如播放器、编辑器等。
|
||||||
|
// Development:开发工具,如IDE、编辑器等。
|
||||||
|
// Education:教育类应用程序,如学习工具、教育游戏等。
|
||||||
|
// Game:游戏应用程序。
|
||||||
|
// Graphics:图形设计和编辑工具。
|
||||||
|
// Office:办公软件,如文档编辑器、电子表格、演示文稿等。
|
||||||
|
// Science:科学工具和应用程序,如数学、物理学、化学工具等。
|
||||||
|
// Settings:系统设置工具。
|
||||||
|
// System:系统工具,如文件管理器、终端模拟器等。
|
||||||
|
// Utility:实用工具,如压缩软件、文本编辑器等。
|
||||||
|
|
||||||
|
ui->cbCategories->addItem("Audio");
|
||||||
|
ui->cbCategories->addItem("Video");
|
||||||
|
ui->cbCategories->addItem("Development");
|
||||||
|
ui->cbCategories->addItem("Education");
|
||||||
|
ui->cbCategories->addItem("Game");
|
||||||
|
ui->cbCategories->addItem("Graphics");
|
||||||
|
ui->cbCategories->addItem("Office");
|
||||||
|
ui->cbCategories->addItem("Science");
|
||||||
|
ui->cbCategories->addItem("Settings");
|
||||||
|
ui->cbCategories->addItem("Utility");
|
||||||
|
ui->cbCategories->setCurrentIndex(ui->cbCategories->count() - 1);
|
||||||
|
|
||||||
|
connect(ui->cbIsCustomIco, &QCheckBox::toggled, this, &AddDesktop::checkchange);
|
||||||
|
connect(ui->btnSelectBinary, &QPushButton::clicked, this, [=](){
|
||||||
|
MainWidget::SelectFile(this, ui->edBinary, "请选择Qt二进制文件", "所有文件 (*)");
|
||||||
|
});
|
||||||
|
connect(ui->btnSelectIco, &QPushButton::clicked, this, [=](){
|
||||||
|
MainWidget::SelectFile(this, ui->edIco, "请选择ico图标文件", "图标文件(*.ico);;所有文件 (*)");
|
||||||
|
});
|
||||||
|
connect(ui->btnInstall, &QPushButton::clicked, this, &AddDesktop::install_to_desktop);
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddDesktop::checkchange()
|
||||||
|
{
|
||||||
|
if (ui->cbIsCustomIco->isChecked()) {
|
||||||
|
ui->edIco->setEnabled(false);
|
||||||
|
ui->btnSelectIco->setEnabled(false);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
ui->edIco->setEnabled(true);
|
||||||
|
ui->btnSelectIco->setEnabled(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void AddDesktop::install_to_desktop()
|
||||||
|
{
|
||||||
|
QFile file("://resource/desktop.txt");
|
||||||
|
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
QTextStream stream(&file);
|
||||||
|
QString content = stream.readAll();
|
||||||
|
file.close();
|
||||||
|
std::string ct = content.toStdString();
|
||||||
|
std::string tool_name = fs::path(ui->edBinary->text().trimmed().toStdString()).filename().string();
|
||||||
|
boost::replace_all(ct, "re_name", 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_icon", ui->edIco->text().trimmed().toStdString());
|
||||||
|
boost::replace_all(ct, "re_category", ui->cbCategories->currentText().toStdString());
|
||||||
|
|
||||||
|
fs::path tmp = fs::path(QDir::homePath().toStdString()).append(".config");
|
||||||
|
if (!fs::exists(tmp)) {
|
||||||
|
fs::create_directories(tmp);
|
||||||
|
}
|
||||||
|
tmp.append(tool_name + ".desktop");;
|
||||||
|
std::ofstream out(tmp.string(), std::ios::out);
|
||||||
|
if (!out.is_open()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
out << ct;
|
||||||
|
out.close();
|
||||||
|
MainWidget::message(this, "完成");
|
||||||
|
std::string cp_cmd("pkexec cp " + tmp.string() + " /usr/share/applications");
|
||||||
|
system(cp_cmd.c_str());
|
||||||
|
}
|
||||||
|
|
||||||
|
AddDesktop::~AddDesktop()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
26
adddesktop.h
Normal file
26
adddesktop.h
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
#ifndef ADDDESKTOP_H
|
||||||
|
#define ADDDESKTOP_H
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include "MainWidget.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class AddDesktop;
|
||||||
|
}
|
||||||
|
|
||||||
|
class AddDesktop : public QDialog
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit AddDesktop(QWidget *parent = nullptr);
|
||||||
|
~AddDesktop();
|
||||||
|
|
||||||
|
private:
|
||||||
|
void checkchange();
|
||||||
|
void install_to_desktop();
|
||||||
|
private:
|
||||||
|
Ui::AddDesktop *ui;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // ADDDESKTOP_H
|
155
adddesktop.ui
Normal file
155
adddesktop.ui
Normal file
@ -0,0 +1,155 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>AddDesktop</class>
|
||||||
|
<widget class="QDialog" name="AddDesktop">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>429</width>
|
||||||
|
<height>259</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Dialog</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>二进制文件:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="edBinary"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnSelectBinary">
|
||||||
|
<property name="text">
|
||||||
|
<string>选择</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="cbIsCustomIco">
|
||||||
|
<property name="text">
|
||||||
|
<string>使用默认图标</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>图标文件 (ICO):</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="edIco"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnSelectIco">
|
||||||
|
<property name="text">
|
||||||
|
<string>选择</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>程序类别:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="cbCategories"/>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_4">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btnInstall">
|
||||||
|
<property name="text">
|
||||||
|
<string>安装到菜单</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections/>
|
||||||
|
</ui>
|
@ -1,5 +1,6 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>resource/run.sh</file>
|
<file>resource/run.sh</file>
|
||||||
|
<file>resource/desktop.txt</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
8
resource/desktop.txt
Normal file
8
resource/desktop.txt
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Name=re_name
|
||||||
|
Comment=re_describe
|
||||||
|
Exec=re_path
|
||||||
|
Icon=re_icon
|
||||||
|
Terminal=false
|
||||||
|
Type=Application
|
||||||
|
Categories=re_category;
|
Loading…
x
Reference in New Issue
Block a user