-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmainwindow.cpp
More file actions
74 lines (59 loc) · 1.96 KB
/
mainwindow.cpp
File metadata and controls
74 lines (59 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include "mainwindow.h"
#include "./ui_mainwindow.h"
#include <QFileDialog>
#include <QMessageBox>
#include <unistd.h>
#include <fstream>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::on_selectExecutable_clicked()
{
QString location = "/home/" + user;
executable = QFileDialog::getOpenFileName(this, "Select executable", location);
}
void MainWindow::on_selectIcon_clicked()
{
QString location = "/home/" + user;
icon = QFileDialog::getOpenFileName(this, "Select icon", location);
}
void MainWindow::on_lineEdit_editingFinished()
{
programName = ui->lineEdit->text();
}
void MainWindow::on_selectDestination_clicked()
{
QString location = "/home/" + user + "/Desktop";
destination = QFileDialog::getExistingDirectory(this, tr("Open Directory"),
location,
QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks);
}
void MainWindow::on_generateEntry_clicked()
{
if (executable.isEmpty())
{
QMessageBox::information(this,"..", "You need to select an executable!");
return;
}
int result = access(executable.toStdString().c_str(), X_OK);
if(result != 0) {
QMessageBox::information(this, "..", "Warning: The selected executable does not have the required execution permissions.");
}
QString locationAndName = destination + "/" + programName + ".desktop";
std::ofstream shortcut;
shortcut.open(locationAndName.toStdString());
shortcut << "[Desktop Entry]\n";
shortcut << "Exec=" + executable.toStdString()<<"\n";
shortcut << "Icon=" + icon.toStdString()<<"\n";
shortcut << "Name=" + programName.toStdString()<<"\n";
shortcut << "Type=Application";
shortcut.close();
QMessageBox::information(this,"..", "Desktop entry created.");
}