[PC-BSD Commits] r15766 - pcbsd-projects/EasyPBI
svn at pcbsd.org
svn at pcbsd.org
Fri Mar 9 18:48:05 PST 2012
Author: kenmoore
Date: 2012-03-10 02:48:05 +0000 (Sat, 10 Mar 2012)
New Revision: 15766
Modified:
pcbsd-projects/EasyPBI/mainwindow.cpp
pcbsd-projects/EasyPBI/modBuild.cpp
pcbsd-projects/EasyPBI/modBuild.h
pcbsd-projects/EasyPBI/pbi.cpp
Log:
Update EasyPBI to use the new Backend, and fix the menu categories. It is now ready to add the module editing functionality to the GUI.
Modified: pcbsd-projects/EasyPBI/mainwindow.cpp
===================================================================
--- pcbsd-projects/EasyPBI/mainwindow.cpp 2012-03-09 20:08:11 UTC (rev 15765)
+++ pcbsd-projects/EasyPBI/mainwindow.cpp 2012-03-10 02:48:05 UTC (rev 15766)
@@ -3,6 +3,7 @@
#include <dirent.h>
#include "mainwindow.h"
#include "ui_mainwindow.h"
+#include "modBuild.h"
#include <QDebug>
//PBI_Struct *pbi_data = NULL;
@@ -149,10 +150,10 @@
module_path = QFileDialog::getExistingDirectory(this, tr("Select Port"), PORTS_DIR);
if(module_path.isEmpty()){return;} //action cancelled or closed
PORT_SELECTED = module_path.section("ports/",1,1);
+ // Initialize the data structure
pbi_data = Init_Data();
- if (! pbi_data)
- {
- QMessageBox::about(this, tr("Error"), tr("Could not set up memory for this module."));
+ if (! pbi_data){
+ QMessageBox::about(this, tr("Error"), tr("Could not set up memory for this module."));
return;
}
// get the name, arguments
@@ -160,22 +161,23 @@
Get_Options(pbi_data, 3, argv);
// confirm port exists
status = Port_Exists(pbi_data);
- if (! status)
- {
+ if (! status){
QMessageBox::about(this, tr("Error"), tr("This port does not exist."));
Clean_Up(pbi_data, TRUE);
return;
}
+ // Detect port's name, icon, website, author, and category
Get_Name(pbi_data);
Get_Icon(pbi_data);
Get_Category(pbi_data);
Get_Website(pbi_data);
Get_Author(pbi_data);
+ // Display the detected info
ui->author->setText(pbi_data->author_name);
ui->port_category->setText(pbi_data->category);
ui->port_selected->setText(PORT_SELECTED);
- if (pbi_data->icon_name)
- ui->icon_path->setText(pbi_data->icon_name);
+ if (pbi_data->icon_name){ui->icon_path->setText(pbi_data->icon_name);}
+
ui->port_name->setText(pbi_data->port_name);
ui->website->setText(pbi_data->web_site);
ui->status_bar->setText(tr("Please fill out the above fields and click \"Create Module\"."));
@@ -193,10 +195,7 @@
void MainWindow::on_create_button_clicked()
{
char *home_dir;
- char final_output[1024];
BIN_FILE *current_exe;
- //int status;
- FILE *my_file;
char original_dir[PATH_MAX];
if (! pbi_data)
@@ -224,35 +223,43 @@
chdir("EasyPBI/Modules"); //Already exists (checked before now)
//mkdir("Modules", 0777);
- // build module
- Create_Module_Template9(pbi_data);
- Get_Main_Exe_Smart(pbi_data);
- Get_More_Exe(pbi_data);
- Copy_Icon9(pbi_data);
- Write_Conf9(pbi_data);
- Write_Menu(pbi_data, NULL);
- current_exe = pbi_data->more_exe;
- while (current_exe)
- {
- Write_Menu(pbi_data, current_exe->path);
- current_exe = (BIN_FILE *) current_exe->next;
+ // Build Module
+ bool success = FALSE;
+ ModBuild::makeStructs(ui->port_name->text(),ui->website->text(),ui->author->text(), \
+ ui->icon_path->text(),ui->port_selected->text(),"","","","",FALSE,"",FALSE);
+ QString newModulePath = ModBuild::makeModuleDir( MODOUT_DIR,ModBuild::getFilenameFromPath(ui->port_selected->text()) );
+ if(!newModulePath.isEmpty()){
+ qDebug() << "Module Directory:" << newModulePath;
+ if( ModBuild::writePBIconf(newModulePath) ){
+ ModBuild::addResource(newModulePath,ModBuild::readValue("PBI_PROGICON"));
+ QStringList binaries, linkOpts;
+ ModBuild::makeExternalLinks(newModulePath,binaries,linkOpts); //should work since pbi.conf was created successfully
+ //Add desktop/menu entries
+ if(ui->gui_app->isChecked()){
+ Get_Main_Exe_Smart(pbi_data);
+ Get_More_Exe(pbi_data);
+ current_exe = pbi_data->more_exe;
+ while(current_exe){
+ ModBuild::makeMenuEntry( newModulePath, current_exe->path, ModBuild::getFilenameFromPath(current_exe->path) ,ModBuild::readValue("PBI_PROGICON"), ui->port_category->text() );
+ ModBuild::makeDesktopEntry( newModulePath, current_exe->path, ModBuild::getFilenameFromPath(current_exe->path) ,ModBuild::readValue("PBI_PROGICON") );
+ current_exe = (BIN_FILE *) current_exe->next;
+ }
+ }
+ success = TRUE;
+ // create tarball of module
+ ModBuild::compressModule(newModulePath);
+ } // pbi.conf success
+ } //noModulePath check
+ QString result;
+ if(success){
+ result = tr("Done. Your module is located in the EasyPBI folder.\nPlease view the 'AppCafe Integration' page for further instructions");
+ qDebug() << "Finished building Module";
}
-
- // create tarball of module
- sprintf(final_output, "tar czf %s.tar.gz %s", pbi_data->port_name9, pbi_data->port_name9);
- system(final_output);
- sprintf(final_output, "%s.tar.gz", pbi_data->port_name9);
- my_file = fopen(final_output, "r");
- if (my_file)
- {
- sprintf(final_output, "Done. Your module is located at %s/EasyPBI/Modules/\nPlease view the 'AppCafe Integration' page for further instructions", home_dir);
- fclose(my_file);
+ else{
+ result = tr("There was an error creating the module. There may be a permission error creating new directories in your home directory.");
+ qDebug() << "Error building module: see log above";
}
- else
- sprintf(final_output, "Something went wrong creating the module. There may be a permission error creating new directories in your home.");
- ui->status_bar->setText(final_output);
- // we are done, return to original working directory
- chdir(original_dir);
+ ui->status_bar->setText(result);
}
void MainWindow::on_port_info_button_clicked()
Modified: pcbsd-projects/EasyPBI/modBuild.cpp
===================================================================
--- pcbsd-projects/EasyPBI/modBuild.cpp 2012-03-09 20:08:11 UTC (rev 15765)
+++ pcbsd-projects/EasyPBI/modBuild.cpp 2012-03-10 02:48:05 UTC (rev 15766)
@@ -3,7 +3,7 @@
/* --- EXAMPLE USAGE ---
1) Make/fill structures: makeStructs(), loadPBIconf()
2) Make the module directory: makeModuleDir()
- 3) Make pbi.conf: makePBIconf()
+ 3) Make pbi.conf: writePBIconf()
4) Make desktop/menu entries: makeDesktopEntry(), makeMenuEntry()
5) Make external-links file: makeExternalLinks()
*/
@@ -101,24 +101,46 @@
QString ModBuild::makeModuleDir(QString baseDir, QString modName){
//Creates the directory structure for a complete PBI module
+
+ //Remove the "/" on the end of the baseDir if there is one
+ if( baseDir.endsWith("/") ){ baseDir.chop(1); }
+
+ //Check the base Directory
QDir dir(baseDir);
if(!dir.exists()){
qDebug() << "Error: Base directory does not exist";
return "";
}
- if(!dir.mkdir(modName)){
- qDebug() << "Error: Could not create module directory";
- return "";
+ QString modulePath = "";
+ if(dir.exists(modName)){
+ dir.cd(modName);
+ bool validModule = dir.exists("resources") && dir.exists("xdg-desktop") \
+ && dir.exists("xdg-menu") && dir.exists("xdg-mime") && dir.exists("scripts");
+ if( !validModule ){
+ qDebug() << "Error: Directory exists, but is not a valid module";
+ // return empty path
+ }else{
+ qDebug() << "Valid Module directory already exists";
+ modulePath = baseDir + "/" + modName; //return the full path
+ }
+ }else{
+ //New module directory
+ if(!dir.mkdir(modName)){
+ qDebug() << "Error: Could not create module directory";
+ // return empty path
+ }else{
+ //If main directory could be created, should no problem with sub-directories
+ dir.cd(modName);
+ dir.mkdir("resources");
+ dir.mkdir("xdg-desktop");
+ dir.mkdir("xdg-menu");
+ dir.mkdir("xdg-mime");
+ dir.mkdir("scripts");
+ qDebug() << "Module directory successfully created";
+ modulePath = baseDir + "/" + modName; //return the full path
+ }
}
- //If main directory could be created, should no problem with sub-directories
- dir.cd(modName);
- dir.mkdir("resources");
- dir.mkdir("xdg-desktop");
- dir.mkdir("xdg-menu");
- dir.mkdir("xdg-mime");
- dir.mkdir("scripts");
-
- return dir.currentPath();
+ return modulePath;
}
bool ModBuild::writePBIconf(QString modDir){
//Returns TRUE if successful
@@ -150,7 +172,7 @@
contents << "PBI_PROGNAME=\""+progStruct[0]+"\"";
contents << "PBI_PROGWEB=\""+progStruct[1]+"\"";
contents << "PBI_PROGAUTHOR=\""+progStruct[2]+"\"";
- contents << "PBI_PROGICON=\""+progStruct[3]+"\"\n";
+ contents << "PBI_PROGICON=\""+getFilenameFromPath(progStruct[3])+"\"\n";
// -- Port Info
contents << "# -- Port Information --";
contents << "PBI_MAKEPORT=\""+mkStruct[0]+"\"";
@@ -161,8 +183,8 @@
contents << "# -- Require Root Permissions to Install PBI --";
contents << "PBI_REQUIRESROOT=\""+serverStruct[0]+"\"\n";
contents << "# -- Auto-build Configuration Options --";
- contents << "PBI_BUILDKEY=\""+serverStruct[1]+"\"";
- contents << "PBI_AB_PRIORITY=\""+serverStruct[2]+"\"";
+ contents << "PBI_BUILDKEY="+serverStruct[1];
+ contents << "PBI_AB_PRIORITY="+serverStruct[2];
contents << "PBI_AB_NOTMPFS=\""+serverStruct[3]+"\"\n";
// --Export all the variables
contents << "export PBI_PROGNAME PBI_PROGWEB PBI_PROGAUTHOR PBI_PROGICON PBI_MAKEPORT PBI_MKPORTBEFORE PBI_MKPORTAFTER PBI_MAKEOPTS PBI_REQUIRESROOT PBI_BUILDKEY PBI_AB_PRIORITY PBI_AB_NOTMPFS";
@@ -210,7 +232,7 @@
contents << "GenericName="+name.toLower();
contents << "Exec=%%PBI_EXEDIR%%/"+binary;
contents << "Path=%%PBI_APPDIR%%";
- contents << "Icon=%%PBI_APPDIR%%/"+icon;
+ contents << "Icon=%%PBI_APPDIR%%/"+getFilenameFromPath(icon);
contents << "StartupNotify=true";
contents << "Categories="+category+";";
@@ -248,7 +270,7 @@
contents << "GenericName="+name.toLower();
contents << "Exec=%%PBI_EXEDIR%%/"+binary;
contents << "Path=%%PBI_APPDIR%%";
- contents << "Icon=%%PBI_APPDIR%%/"+icon;
+ contents << "Icon=%%PBI_APPDIR%%/"+getFilenameFromPath(icon);
contents << "StartupNotify=true";
//Create the Menu entry
@@ -282,13 +304,47 @@
return status;
}
+bool ModBuild::addResource(QString modDir, QString resourcePath){
+ if(resourcePath.isEmpty()){
+ qDebug() << "Warning: no resource selected";
+ return TRUE; // Do not flag this as an error in the function
+ }
+ //resourcePath *MUST* be an absolute path (start with "/")
+ if( !resourcePath.startsWith("/") ){
+ qDebug() << "Error: Path to desired resource is not an absolute path!";
+ return FALSE;
+ }
+
+ //Check that the desired resource exists
+ if( !QFile::exists(resourcePath) ){
+ qDebug() << "Error: Desired resource does not exist: " << resourcePath;
+ return FALSE;
+ }
+ //Create the full path to the location within the module
+ QString newResourcePath = modDir + "/resources/";
+ QString resource = getFilenameFromPath(resourcePath);
+ newResourcePath.append(resource);
+
+ //Check if the resource already exists in the module
+ if( QFile::exists(newResourcePath) ){
+ qDebug() << "Overwriting existing module resource:" << resource;
+ QFile::remove(newResourcePath);
+ }
+ //Copy the resource into the module
+ if( !QFile::copy(resourcePath,newResourcePath) ){
+ qDebug() << "Error copying resource into the module";
+ return FALSE;
+ }
+ return TRUE;
+}
+
bool ModBuild::createFile(QString fileName, QStringList contents){
//fileName = full path to file (I.E. /home/pcbsd/junk/junk.txt)
//contents = list of lines to be written (one line per entry in the list - no newline needed at the end of an entry)
//Remove any existing file with that name/location
if( QFile::exists(fileName) ){
- if( QFile::remove(fileName) ){
+ if( !QFile::remove(fileName) ){
qDebug() << fileName+": Error -- Could not overwrite existing file";
return FALSE;
}
@@ -308,15 +364,13 @@
//Close the File
file.close();
//Move the temporary file into its final location
- if( QFile::copy(fileName+".tmp", fileName) ){
- qDebug() << fileName+": Failure -- Could not copy "+fileName+".tmp to "+fileName;
+ if( !file.rename(fileName) ){
+ qDebug() << fileName+": Error: Could not rename "+fileName+".tmp as "+fileName;
return FALSE;
}
- if( QFile::remove(fileName+".tmp") ){ //remove the temporary file
- qDebug() << fileName+": Warning -- Could not delete "+fileName+".tmp -- Please remove manually";
- }
//Return success
- qDebug() << fileName+": Success";
+ QString extra = QDir::homePath() + "/EasyPBI/Modules/"; //remove this from the filename display
+ qDebug() << "Created:" << fileName.remove(extra);
return TRUE;
}
@@ -360,3 +414,28 @@
return TRUE;
}
+void ModBuild::compressModule(QString modDir){
+ //Check that modDir is an absolute path
+ if( !modDir.startsWith("/") ){
+ qDebug() << "Error: Module directory is not an absolute path:" << modDir;
+ }
+ //Check that the directory exists
+ QDir testDir(modDir);
+ if(testDir.exists() == FALSE){
+ qDebug() << "Error: Directory does not exist:" << modDir;
+ return;
+ }
+ //Compress the directory
+ QString localDir = getFilenameFromPath(modDir);
+ QString cmd = "cd "+modDir+"/..; tar czf "+localDir+".tar.gz "+localDir;
+ //qDebug() << cmd;
+ system( cmd.toUtf8() );
+ return;
+}
+
+QString ModBuild::getFilenameFromPath(QString fullPath){
+ QStringList entries = fullPath.split("/",QString::SkipEmptyParts);
+ QString name = entries[entries.length() - 1]; //only take the last entry
+ return name;
+}
+
Modified: pcbsd-projects/EasyPBI/modBuild.h
===================================================================
--- pcbsd-projects/EasyPBI/modBuild.h 2012-03-09 20:08:11 UTC (rev 15765)
+++ pcbsd-projects/EasyPBI/modBuild.h 2012-03-10 02:48:05 UTC (rev 15766)
@@ -22,6 +22,9 @@
static bool createFile(QString,QStringList);
static QString readValue(QString);
static bool writeValue(QString,QString);
+ static bool addResource(QString,QString);
+ static void compressModule(QString);
+ static QString getFilenameFromPath(QString);
};
Modified: pcbsd-projects/EasyPBI/pbi.cpp
===================================================================
--- pcbsd-projects/EasyPBI/pbi.cpp 2012-03-09 20:08:11 UTC (rev 15765)
+++ pcbsd-projects/EasyPBI/pbi.cpp 2012-03-10 02:48:05 UTC (rev 15766)
@@ -766,27 +766,31 @@
return FALSE;
if ( strstr(data->port_dir, "games") )
- strcpy(cat, "Games");
+ strcpy(cat, "Game");
else if ( strstr(data->port_dir, "devel") )
strcpy(cat, "Development");
else if ( strstr(data->port_dir, "multimedia"))
- strcpy(cat, "Multimedia");
+ strcpy(cat, "AudioVideo");
else if ( strstr(data->port_dir, "audio") )
- strcpy(cat, "Multimedia");
+ strcpy(cat, "AudioVideo");
else if ( strstr(data->port_dir, "graphics"))
strcpy(cat, "Graphics");
else if ( strstr(data->port_dir, "www") )
- strcpy(cat, "Internet");
+ strcpy(cat, "Network");
else if ( strstr(data->port_dir, "net") )
- strcpy(cat, "Internet");
+ strcpy(cat, "Network");
else if ( strstr(data->port_dir, "ftp") )
- strcpy(cat, "Internet");
+ strcpy(cat, "Network");
else if ( strstr(data->port_dir, "mail") )
- strcpy(cat, "Internet");
+ strcpy(cat, "Network");
else if ( strstr(data->port_dir, "cad") )
strcpy(cat, "Graphics");
+ else if ( strstr(data->port_dir, "editors") )
+ strcpy(cat, "Office");
+ else if ( strstr(data->port_dir, "sysutils") )
+ strcpy(cat, "System");
else
- strcpy(cat, "Utilities");
+ strcpy(cat, "Utility");
if (cat[0])
{
More information about the Commits
mailing list