22#include " ui_mainwindow.h"
33#include < QFile>
44#include < QFileDialog>
5+ #include < QStandardPaths>
56
67#include < iostream>
78#include < unistd.h>
1213#include < string>
1314#include < algorithm>
1415#include < cctype>
15- #include < filesystem>
1616
1717char *homedir;
1818
@@ -40,6 +40,7 @@ std::string getFilePath(std::string path) {
4040// Writes data to the .desktop file
4141void writeData (std::string data, std::string path) {
4242 std::ofstream file (path);
43+
4344 file << data;
4445
4546 file.close ();
@@ -78,39 +79,6 @@ void MainWindow::on_createButton_clicked() {
7879 if (terminalSelected == true )
7980 terminal = " true" ;
8081
81- // Copy the image file to the /home/jason/.icons folder
82- std::string imageCopyLocation = homedir;
83- std::string copyFileName = (std::string)name.toUtf8 ().constData () + " .png" ;
84-
85- imageCopyLocation += " /.icons/" + copyFileName;
86-
87- std::string copyFromLocation = iconLocation.toUtf8 ().constData ();
88-
89- std::ifstream imageSource (copyFromLocation, std::ios::binary);
90- std::ofstream imageDestination (imageCopyLocation, std::ios::binary);
91-
92- imageDestination << imageSource.rdbuf ();
93-
94- // Create the applications folder if it doesn't already exist
95- // /home/jason/Applications
96- std::string appsFolder = homedir;
97- appsFolder += " /Applications" ;
98-
99- // If the folder doesn't exist, create it.
100- if (!std::filesystem::is_directory (appsFolder)
101- && !std::filesystem::exists (appsFolder)) {
102- std::filesystem::create_directory (appsFolder);
103- }
104-
105- // Copy the application file to the Application folder
106- copyFromLocation = appLocation.toUtf8 ().constData ();
107- std::string copyToLocation = appsFolder + " /" + getFilePath (appLocation.toUtf8 ().constData ());
108-
109- std::ifstream appSource (copyFromLocation, std::ios::binary);
110- std::ofstream appDestination (copyToLocation, std::ios::binary);
111-
112- appDestination << appSource.rdbuf ();
113-
11482 /*
11583 * This is the correct form for a .desktop file:
11684 *
@@ -128,20 +96,22 @@ void MainWindow::on_createButton_clicked() {
12896 std::string fileContents = " " ;
12997
13098 fileContents += " [Desktop Entry]\n " ;
99+ fileContents += " Type=Application\n " ;
100+ fileContents += " Encoding=UTF-8\n " ;
131101 fileContents += " Name=" + (std::string)name.toUtf8 ().constData () + " \n " ; // Name=AppAdder
132- fileContents += " Exec=" + copyToLocation + " \n " ; // Exec=/home/jason/Applications/app.AppImage
102+ fileContents += " Comment=A simple program\n " ;
103+ fileContents += " Exec=" + (std::string)appLocation.toUtf8 ().constData () + " \n " ;
104+ fileContents += " Icon=" + (std::string)iconLocation.toUtf8 ().constData () + " \n " ;
133105 fileContents += " Terminal=" + terminal + " \n " ; // Terminal=false
134- fileContents += " Type=Application\n " ;
135- fileContents += " Icon=" + copyFileName + " \n " ; // Icon=/home/jason/.icons/app.png
136- fileContents += " \n TryExec=" + copyToLocation + " \n " ; // TryExec=/home/jason/Applications/app.AppImage
137106 fileContents += " Actions=Remove;\n " ;
138107
139108 fileContents += " \n [Desktop Action Remove]\n " ;
140109 fileContents += " Name=Uninstall app from system\n " ;
141110
142111 std::string desktopFilePath = homedir;
143112 desktopFilePath += " /.local/share/applications/" + (std::string) name.toUtf8 ().constData () + " .desktop" ;
144- fileContents += " Exec=rm " + copyToLocation + " " + imageCopyLocation + " " + desktopFilePath + " \n " ;
113+
114+ fileContents += " Exec=rm " + desktopFilePath + " \n " ;
145115
146116 writeData (fileContents, desktopFilePath);
147117}
0 commit comments