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
|
//===========================================
// Copyright (c) 2017, q5sys (JT)
// Available under the MIT license
// See the LICENSE file for full details
//===========================================
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "QDir"
#include "QFile"
#include "QTextStream"
#include "QImageReader"
#include "QFileDialog"
#include "QMessageBox"
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->pushButton_executable, SIGNAL(clicked()), this, SLOT(setExec()) );
connect(ui->pushButton_icon, SIGNAL(clicked()), this, SLOT(setIcon()) );
connect(ui->pushButton_save, SIGNAL(clicked()), this, SLOT(save()) );
connect(ui->actionSave, SIGNAL(triggered()), this, SLOT(save()) );
connect(ui->actionClose, SIGNAL(triggered()), this, SLOT(close()) );
}
MainWindow::~MainWindow()
{
delete ui;
}
void MainWindow::setIcon(){
//Prompt for a new image file
QStringList imgformats;
QList<QByteArray> fmts = QImageReader::supportedImageFormats();
for(int i=0; i<fmts.length(); i++){
imgformats << "*."+QString(fmts[i]);
}
QString iconpath = QFileDialog::getOpenFileName(this, tr("Select an image"), QDir::homePath(), \
tr("Images")+" ("+imgformats.join(" ")+")");
ui->lineEdit_icon->setText(iconpath);
icon = ui->lineEdit_icon->text();
}
void MainWindow::setExec(){
//Prompt for a new executable file
QString execpath = QFileDialog::getOpenFileName(this, tr("Select File"), QDir::homePath(), tr("All Files (*)") );
ui->lineEdit_executable->setText(execpath);
executable = ui->lineEdit_executable->text();
}
void MainWindow::setCategories(){
if(ui->checkBox_audio->isChecked()){
catList = catList + "Audio;";}
if(ui->checkBox_video->isChecked()){
catList = catList + "Video;";}
if(ui->checkBox_development->isChecked()){
catList = catList + "Development;";}
if(ui->checkBox_education->isChecked()){
catList = catList + "Education;";}
if(ui->checkBox_game->isChecked()){
catList = catList + "Game;";}
if(ui->checkBox_graphics->isChecked()){
catList = catList + "Graphics;";}
if(ui->checkBox_network->isChecked()){
catList = catList + "Network;";}
if(ui->checkBox_office->isChecked()){
catList = catList + "Office;";}
if(ui->checkBox_science->isChecked()){
catList = catList + "Science;";}
if(ui->checkBox_settings->isChecked()){
catList = catList + "Settings;";}
if(ui->checkBox_system->isChecked()){
catList = catList + "System;";}
if(ui->checkBox_utility->isChecked()){
catList = catList + "Utility;";}
categories = catList;
}
void MainWindow::setOtherValues(){
name = ui->lineEdit_name->text();
genericname = ui->lineEdit_genericname->text();
keywords = ui->lineEdit_keywords->text();
comment = ui->lineEdit_comment->text();
if(ui->checkBox_terminal->isChecked()){
terminal = "true";} else{terminal = "false";};
}
void MainWindow::setDesktopFields(){
setCategories();
setOtherValues();
namefield = "Name=" + name;
genericnamefield = "GenericName=" + genericname;
commentfield = "Comment=" + comment;
iconfield = "Icon=" + icon;
terminalfield = "Terminal=" + terminal;
execfield = "Exec=" + executable;
categoriesfield = "Categories=" + categories;
keywordfield = "Keywords=" + keywords;
}
void MainWindow::save(){
setDesktopFields();
QString path = QDir::homePath();
QString filename;
filename = path + "/" + name + ".desktop";
QFile file(filename);
file.open(QIODevice::WriteOnly | QIODevice::Text);
QTextStream stream(&file);
stream << "{Desktop Entry]" << endl;
stream << "Type=Application" << endl;
stream << "Version=1.0" << endl;
stream << namefield << endl;
stream << genericnamefield << endl;
stream << commentfield << endl;
stream << iconfield << endl;
stream << terminalfield << endl;
stream << execfield << endl;
stream << categoriesfield << endl;
stream << keywordfield << endl;
if(file.isOpen()){
QMessageBox *messageBox = new QMessageBox;
messageBox->setText(tr("File Saved"));
QPushButton *pushButtonOk = messageBox->addButton(tr("Ok"), QMessageBox::YesRole);
messageBox->QDialog::setWindowTitle(tr("Successful"));
messageBox->show();}
else{ QMessageBox *messageBox = new QMessageBox;
messageBox->setText(tr("File Not Saved"));
QPushButton *pushButtonOk = messageBox->addButton(tr("Ok"), QMessageBox::YesRole);
messageBox->QDialog::setWindowTitle(tr("Unsuccessful"));
messageBox->show();}
file.close();
}
|