-
Notifications
You must be signed in to change notification settings - Fork 0
/
mainwindow.cpp
199 lines (178 loc) · 6.08 KB
/
mainwindow.cpp
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QPixmap>
#include <QIcon>
#include <QFileDialog>
#include <QMessageBox>
#include <QTextStream>
extern QString path;
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
QPixmap pixmap(":/res/1.png");
QIcon ButtonIcon(pixmap);
ui->pushButton->setIcon(ButtonIcon);
ui->pushButton->setIconSize(ui->pushButton->size()*0.9);
connect(ui->pushButton,SIGNAL(hoverStarted()),this,SLOT(IconPickBtnHoverStart()));
connect(ui->pushButton,SIGNAL(hoverEnded()),this,SLOT(HoverEnd()));
connect(ui->pushButton,SIGNAL(clicked()),this,SLOT(IconPickBtnClick()));
connect(ui->pushButton_2,SIGNAL(hoverStarted()),this,SLOT(CreateBtnHoverStart()));
connect(ui->pushButton_2,SIGNAL(hoverEnded()),this,SLOT(HoverEnd()));
connect(ui->pushButton_2,SIGNAL(clicked()),this,SLOT(CreateBtnClick()));
connect(ui->pushButton_3,SIGNAL(hoverStarted()),this,SLOT(CancelBtnHoverStart()));
connect(ui->pushButton_3,SIGNAL(hoverEnded()),this,SLOT(HoverEnd()));
connect(ui->pushButton_3,SIGNAL(clicked()),this,SLOT(CancelBtnClick()));
connect(ui->toolButton,SIGNAL(hoverStarted()),this,SLOT(ToolBtnHoverStart()));
connect(ui->toolButton,SIGNAL(hoverEnded()),this,SLOT(HoverEnd()));
connect(ui->toolButton,SIGNAL(clicked()),this,SLOT(ToolBtnClick()));
connect(ui->lineEdit,SIGNAL(GotFocus()),this,SLOT(TitleEditFocus()));
connect(ui->lineEdit,SIGNAL(LostFocus()),this,SLOT(HoverEnd()));
connect(ui->lineEdit_2,SIGNAL(GotFocus()),this,SLOT(ExecEditFocus()));
connect(ui->lineEdit_2,SIGNAL(LostFocus()),this,SLOT(HoverEnd()));
connect(ui->lineEdit_3,SIGNAL(GotFocus()),this,SLOT(CommEditFocus()));
connect(ui->lineEdit_3,SIGNAL(LostFocus()),this,SLOT(HoverEnd()));
connect(ui->lineEdit_4,SIGNAL(GotFocus()),this,SLOT(CatEditFocus()));
connect(ui->lineEdit_4,SIGNAL(LostFocus()),this,SLOT(HoverEnd()));
if (path!="") ui->lineEdit_2->setText(path);
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::IconPickBtnHoverStart()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Click to pick an icon.", 0);
}
void MainWindow::HoverEnd()
{
ui->statusBar->clearMessage();
}
void MainWindow::IconPickBtnClick()
{
QFileDialog fd;
IconFile = fd.getOpenFileName(this,"Select Icon...","~/",tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
if(IconFile != "")
{
QPixmap pixmap(IconFile);
QIcon ButtonIcon(pixmap);
ui->pushButton->setIcon(ButtonIcon);
ui->pushButton->setIconSize(ui->pushButton->size()*0.9);
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Icon picked successfully.", 0);
}
}
void MainWindow::CancelBtnHoverStart()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Click to exit.", 0);
}
void MainWindow::CancelBtnClick()
{
QApplication::quit();
}
void MainWindow::CreateBtnHoverStart()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Click to create launcher.", 0);
}
void MainWindow::CreateBtnClick()
{
Title = ui->lineEdit->text();
ExecFile = ui->lineEdit_2->text();
Comment = ui->lineEdit_3->text();
Categories = ui->lineEdit_4->text();
QString filename = Title.simplified();
filename = filename.toLower();
filename.replace(" ","");
filename.append(".desktop");
// QString fil1 = filename;
//filename.prepend("~/");
QFile file(filename);
QString comm = "touch ";
comm.append(filename);
system(comm.toStdString().c_str());
if (!file.open(QIODevice::WriteOnly))
{
QMessageBox msgBox;
QString errmess = "Error creating file. Filename: ";
errmess.append(filename);
msgBox.setText(errmess);
msgBox.exec();
return;
}
QTextStream out(&file);
out << "[Desktop Entry]\n";
out << "Name=";
if (Title=="")
{
QMessageBox msgBox;
msgBox.setText("The \"Title\" field is required.");
msgBox.exec();
return;
}
out << Title << "\n";
if (Comment!="") out << "Comment=" << Comment << "\n";
out << "Exec=";
if (ExecFile=="")
{
QMessageBox msgBox;
msgBox.setText("The \"Executable\" field is required.");
msgBox.exec();
return;
}
out << ExecFile << "\n";
if (IconFile!="") out << "Icon=" << IconFile << "\n";
out << "Terminal=false\nType=Application\n";
if (Categories!="") out << "Categories=" << Categories << "\n";
file.close();
QString command = "pkexec cp ";
command.append(QDir::currentPath());
command.append("/");
command.append(filename);
command.append(" /usr/share/applications/");
system(command.toStdString().c_str());
ui->statusBar->clearMessage();
ui->statusBar->showMessage("The launcher has been created successfully.", 0);
QMessageBox msgBox;
msgBox.setText("The launcher has been created successfully.");
msgBox.exec();
}
void MainWindow::ToolBtnHoverStart()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Click to pick the executable.", 0);
}
void MainWindow::ToolBtnClick()
{
QFileDialog fd;
ExecFile = fd.getOpenFileName(this,"Select Executable...","~/",tr("Executable Files (*)"));
if(ExecFile != "")
{
ui->lineEdit_2->setText(ExecFile);
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Executable picked successfully.", 0);
}
}
void MainWindow::TitleEditFocus()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Input the launcher title here.", 0);
}
void MainWindow::ExecEditFocus()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Input the executable file path here. If it's a script, add \"sh \" before the path.", 0);
}
void MainWindow::CommEditFocus()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Input the description here - optional.", 0);
}
void MainWindow::CatEditFocus()
{
ui->statusBar->clearMessage();
ui->statusBar->showMessage("Input categories (put a semicolon after each tag) - optional.", 0);
}