[PC-BSD Commits] r19593 - users/ken/EasyPBI2

svn at pcbsd.org svn at pcbsd.org
Wed Oct 3 20:54:49 PDT 2012


Author: kenmoore
Date: 2012-10-04 03:54:48 +0000 (Thu, 04 Oct 2012)
New Revision: 19593

Modified:
   users/ken/EasyPBI2/mainGUI.cpp
   users/ken/EasyPBI2/mainGUI.ui
   users/ken/EasyPBI2/modBuild.cpp
   users/ken/EasyPBI2/modBuild.h
Log:
Checkpoint for EasyPBI2, this includes a ton of updates and improvements to the module builder backend, including a redesign so it is an active class rather than a static library (almost finished with the changes).



Modified: users/ken/EasyPBI2/mainGUI.cpp
===================================================================
--- users/ken/EasyPBI2/mainGUI.cpp	2012-10-03 20:26:27 UTC (rev 19592)
+++ users/ken/EasyPBI2/mainGUI.cpp	2012-10-04 03:54:48 UTC (rev 19593)
@@ -42,6 +42,8 @@
 	// -- XDG entries tab --
 	ui->push_xdg_refresh->setIcon(Backend::icon("refresh"));
 	ui->push_xdg_savechanges->setIcon(Backend::icon("save"));
+	ui->push_xdg_addmime->setIcon(Backend::icon("left"));
+	ui->push_xdg_addmimenew->setIcon(Backend::icon("left"));
 	// -- Scripts tab --
 	ui->push_scripts_save->setIcon(Backend::icon("save"));
 	ui->list_scripts_file->addItems(QStringList() << "Installation Scripts" << "pre-portmake.sh" << "post-portmake.sh" << "pre-install.sh" << "post-install.sh" << "pre-remove.sh" );
@@ -202,16 +204,18 @@
 	ui->label_xdg_exec->setVisible(TRUE); ui->line_xdg_exec->setVisible(TRUE);
 	ui->label_xdg_icon->setVisible(TRUE); ui->list_xdg_icon->setVisible(TRUE);
 	ui->label_xdg_menu->setVisible(FALSE); ui->list_xdg_menu->setVisible(FALSE);
+	ui->check_xdg_nodisplay->setVisible(TRUE);
 	ui->check_xdg_terminal->setVisible(TRUE);
-	ui->label_xdg_mimetype->setVisible(FALSE); ui->line_xdg_mimetype->setVisible(FALSE);
+	ui->push_xdg_addmime->setVisible(TRUE);
 	ui->label_xdg_mimepatterns->setVisible(FALSE); ui->line_xdg_mimepatterns->setVisible(FALSE);
 	//New file
 	ui->label_xdg_namenew->setVisible(TRUE); ui->line_xdg_namenew->setVisible(TRUE);
 	ui->label_xdg_execnew->setVisible(TRUE); ui->line_xdg_execnew->setVisible(TRUE);
 	ui->label_xdg_iconnew->setVisible(TRUE); ui->list_xdg_iconnew->setVisible(TRUE);
 	ui->label_xdg_menunew->setVisible(FALSE); ui->list_xdg_menunew->setVisible(FALSE);
+	ui->check_xdg_nodisplaynew->setVisible(TRUE);
 	ui->check_xdg_terminalnew->setVisible(TRUE);
-	ui->label_xdg_mimetypenew->setVisible(FALSE); ui->line_xdg_mimetypenew->setVisible(FALSE);
+	ui->push_xdg_addmimenew->setVisible(TRUE);
 	ui->label_xdg_mimepatternsnew->setVisible(FALSE); ui->line_xdg_mimepatternsnew->setVisible(FALSE);
     }else if(isMenu){
 	//xdg-menu entry
@@ -220,16 +224,18 @@
 	ui->label_xdg_exec->setVisible(TRUE); ui->line_xdg_exec->setVisible(TRUE);
 	ui->label_xdg_icon->setVisible(TRUE); ui->list_xdg_icon->setVisible(TRUE);
 	ui->label_xdg_menu->setVisible(TRUE); ui->list_xdg_menu->setVisible(TRUE);
+	ui->check_xdg_nodisplay->setVisible(TRUE);
 	ui->check_xdg_terminal->setVisible(TRUE);
-	ui->label_xdg_mimetype->setVisible(FALSE); ui->line_xdg_mimetype->setVisible(FALSE);
+	ui->push_xdg_addmime->setVisible(TRUE);
 	ui->label_xdg_mimepatterns->setVisible(FALSE); ui->line_xdg_mimepatterns->setVisible(FALSE);
 	//New file
 	ui->label_xdg_namenew->setVisible(TRUE); ui->line_xdg_namenew->setVisible(TRUE);
 	ui->label_xdg_execnew->setVisible(TRUE); ui->line_xdg_execnew->setVisible(TRUE);
 	ui->label_xdg_iconnew->setVisible(TRUE); ui->list_xdg_iconnew->setVisible(TRUE);
 	ui->label_xdg_menunew->setVisible(TRUE); ui->list_xdg_menunew->setVisible(TRUE);
+	ui->check_xdg_nodisplaynew->setVisible(TRUE);
 	ui->check_xdg_terminalnew->setVisible(TRUE);
-	ui->label_xdg_mimetypenew->setVisible(FALSE); ui->line_xdg_mimetypenew->setVisible(FALSE);
+	ui->push_xdg_addmimenew->setVisible(TRUE);
 	ui->label_xdg_mimepatternsnew->setVisible(FALSE); ui->line_xdg_mimepatternsnew->setVisible(FALSE);
     }else{
 	//xdg-mime entry
@@ -238,16 +244,18 @@
 	ui->label_xdg_exec->setVisible(FALSE); ui->line_xdg_exec->setVisible(FALSE);
 	ui->label_xdg_icon->setVisible(FALSE); ui->list_xdg_icon->setVisible(FALSE);
 	ui->label_xdg_menu->setVisible(FALSE); ui->list_xdg_menu->setVisible(FALSE);
+	ui->check_xdg_nodisplay->setVisible(FALSE);
 	ui->check_xdg_terminal->setVisible(FALSE);
-	ui->label_xdg_mimetype->setVisible(TRUE); ui->line_xdg_mimetype->setVisible(TRUE);
+	ui->push_xdg_addmime->setVisible(FALSE);
 	ui->label_xdg_mimepatterns->setVisible(TRUE); ui->line_xdg_mimepatterns->setVisible(TRUE);
 	//New file
 	ui->label_xdg_namenew->setVisible(FALSE); ui->line_xdg_namenew->setVisible(FALSE);
 	ui->label_xdg_execnew->setVisible(FALSE); ui->line_xdg_execnew->setVisible(FALSE);
 	ui->label_xdg_iconnew->setVisible(FALSE); ui->list_xdg_iconnew->setVisible(FALSE);
 	ui->label_xdg_menunew->setVisible(FALSE); ui->list_xdg_menunew->setVisible(FALSE);
+	ui->check_xdg_nodisplaynew->setVisible(FALSE);
 	ui->check_xdg_terminalnew->setVisible(FALSE);
-	ui->label_xdg_mimetypenew->setVisible(TRUE); ui->line_xdg_mimetypenew->setVisible(TRUE);
+	ui->push_xdg_addmimenew->setVisible(FALSE);
 	ui->label_xdg_mimepatternsnew->setVisible(TRUE); ui->line_xdg_mimepatternsnew->setVisible(TRUE);
     }
   }

Modified: users/ken/EasyPBI2/mainGUI.ui
===================================================================
(Binary files differ)

Modified: users/ken/EasyPBI2/modBuild.cpp
===================================================================
--- users/ken/EasyPBI2/modBuild.cpp	2012-10-03 20:26:27 UTC (rev 19592)
+++ users/ken/EasyPBI2/modBuild.cpp	2012-10-04 03:54:48 UTC (rev 19593)
@@ -10,59 +10,38 @@
 */
 
 ModBuild::ModBuild(QWidget* parent) : QWidget(parent){
-	
+  // --Clear the internal variables--
+  isPortPBI=FALSE; isLocalPBI=FALSE;
+  progStruct.clear(); mkStruct.clear(); serverStruct.clear();
+  menuStruct.clear(); desktopStruct.clear(); mimeStruct.clear(); linksStruct.clear();
+  // --Setup the structures with the proper sizes--
+  progStruct <<""<<""<<""<<""<<""<<"";
+    //progStruct=[ name, website, author, icon, version, packageDir]
+  mkStruct <<""<<""<<""<<"";
+    //mkStruct=[ makeport, portbefore, portafter, makeoptions]
+  serverStruct <<"NO"<<"00"<<"00"<<"NO";
+    //serverStruct=[ needroot, buildkey, priority, noTMPFS]
+  menuStruct << ""<<""<<""<<""<<""<<""<<""<<"";
+    //menuStruct=[ name, genericname, exec, icon, nodisplay, terminal, categories, mimetype]
+  desktopStruct << ""<<""<<""<<""<<""<<""<<"";
+    //desktopStruct=[ name, genericname, exec, icon, nodisplay, terminal, mimetype]
+  mimeStruct << "" << "" << "";
+    //mimeStruct=[ info, type, patterns] (patterns is a " "-delimited list)
 }
 
-bool ModBuild::goodStructs(){
-  if( progStruct.isEmpty() || mkStruct.isEmpty() || serverStruct.isEmpty() ){
-    return FALSE;
-  }else{
-    return TRUE;
-  }
+ModBuild::~ModBuild(){
 }
 
-void ModBuild::makeStructs(QString pName, QString pWeb, QString pAuth, QString pIcon, QString mkPort, QString mkBefore, QString mkAfter, QString mkOpts, QString buildKey, bool needRoot, QString priority, bool notmpfs){
-
-//Clear the existing structures
-progStruct.clear(); mkStruct.clear(); serverStruct.clear();
-
-//Fill the structures with the new info in proper format
-//Program info
-progStruct << pName << pWeb << pAuth << pIcon;
-
-//Port info
-mkStruct << mkPort << mkBefore << mkAfter << mkOpts;
-
-//ServerStruct [requiresRoot, buildKey, priority, notmpfs]
-if(needRoot){ serverStruct << "YES"; }
-else{ serverStruct << "NO"; }
-
-if(buildKey.isEmpty()){ buildKey="\"00\"";}
-else{ buildKey = "\"" +buildKey+ "\""; }
-serverStruct << buildKey;
-
-if(priority.isEmpty()){ priority="\"00\"";}
-else{ priority="\"" + priority + "\""; }
-serverStruct << priority;
-
-if(notmpfs){ serverStruct << "YES"; }
-else{ serverStruct << "NO"; }
-
-}
-
-bool ModBuild::loadPBIconf(QString modDir){
-  //Check input
-  if(!modDir.endsWith("/")){modDir.append("/");}
-
+bool ModBuild::loadPBIconf(){
   //Clear the current structures
   progStruct.clear(); mkStruct.clear(); serverStruct.clear();
   //Fill the structures with empty strings (to initialize them)
-  progStruct << "" << "" << "" << "";
+  progStruct << "" << "" << "" << "" << "" << "";
   mkStruct << "" << "" << "" << "";
-  serverStruct << "" << "" << "" << "";
+  serverStruct << "NO" << "00" << "00" << "NO";
 
   //Read the designated pbi.conf and store the variables
-  QFile file(modDir+"pbi.conf");
+  QFile file(modulePath+"/pbi.conf");
   if( !file.open(QIODevice::ReadOnly | QIODevice::Text)){
     qDebug() << "Error: Unable to load "+modDir+"pbi.conf";
     return FALSE;
@@ -81,6 +60,8 @@
       else if(var=="PBI_PROGWEB"){ progStruct[1] = val.remove("\""); }
       else if(var=="PBI_PROGAUTHOR"){ progStruct[2] = val.remove("\""); }
       else if(var=="PBI_PROGICON"){ progStruct[3] = val.remove("\""); }
+      else if(var=="PBI_PROGVERSION"){ progStruct[4] = val.remove("\""); }
+      else if(var=="PBI_PACKAGEDIR"){ progStruct[5] = val.remove("\""); }
       else if(var=="PBI_MAKEPORT"){ mkStruct[0] = val.remove("\""); }
       else if(var=="PBI_MKPORTBEFORE"){ 
 	QStringList tmpL = val.split(" ");
@@ -117,12 +98,6 @@
     }
   }
   file.close();
-  //Check the structures for specific empty slots
-  if(serverStruct[0].isEmpty()){serverStruct[0] = "NO";}
-  if(serverStruct[1].isEmpty()){serverStruct[1] = "00";}
-  if(serverStruct[2].isEmpty()){serverStruct[2] = "00";}
-  if(serverStruct[3].isEmpty()){serverStruct[3] = "NO";}
-  //Other structures can have empty strings
   return TRUE;
 }
 
@@ -162,7 +137,7 @@
     qDebug() << "Error: Could not create module directory";
     // return empty path
   }else{
-    //If main directory could be created, should no problem with sub-directories
+    //If main directory could be created, should be no problem with sub-directories
     dir.cd(modName);
     dir.mkdir("resources");
     dir.mkdir("xdg-desktop");
@@ -175,29 +150,22 @@
 
   return modulePath;
 }
-bool ModBuild::writePBIconf(QString modDir){
+bool ModBuild::writePBIconf(){
 //Returns TRUE if successful
 
-  if(goodStructs() == FALSE){ 
-    qDebug() << "Data Structure has not been loaded yet";
-    return FALSE;
-  }
-
   //Check if the module directory exists
-  QDir testDir(modDir);
+  QDir testDir(modulePath);
   if(testDir.exists() == FALSE){
-    qDebug() << " - pbi.conf creation: Failure -- Invalid module directory";
+    qDebug() << " - pbi.conf creation: Failure -- Module directory does not exist";
     return FALSE;
   }
 
   //Get the path to the module's pbi.conf
-  QString fileName;
-  if(modDir.endsWith("pbi.conf")){ fileName = modDir; }
-  else if(modDir.endsWith("/")){ fileName = modDir+"pbi.conf"; }
-  else{ fileName = modDir+"/pbi.conf"; }
+  QString fileName = modulePath+"/pbi.conf";
 
  //Create the contents of the file to write
   QStringList contents;
+  QString exportLine = "export";
   contents << "#!/bin/sh";
   contents << "# PBI Build Configuration\n";
   // -- Program Info
@@ -205,13 +173,23 @@
   contents << "PBI_PROGNAME=\""+progStruct[0]+"\"";
   contents << "PBI_PROGWEB=\""+progStruct[1]+"\"";
   contents << "PBI_PROGAUTHOR=\""+progStruct[2]+"\"";
-  contents << "PBI_PROGICON=\""+getFilenameFromPath(progStruct[3])+"\"\n";
-  // -- Port Info
-  contents << "# -- Port Information --";
-  contents << "PBI_MAKEPORT=\""+mkStruct[0]+"\"";
-  contents << "PBI_MKPORTBEFORE=\""+mkStruct[1]+"\"";
-  contents << "PBI_MKPORTAFTER=\""+mkStruct[2]+"\"";
-  contents << "PBI_MAKEOPTS=\""+mkStruct[3]+"\"\n";
+  contents << "PBI_PROGICON=\""+getFilenameFromPath(progStruct[3])+"\"";
+  exportLine.append(" PBI_PROGNAME PBI_PROGWEB PBI_PROGAUTHOR PBI_PROGICON");
+  if(isLocalPBI){
+    contents << "PBI_PROGVERSION=\""+progStruct[4]+"\"";
+    contents << "PBI_PACKAGEDIR=\""+progStruct[5]+"\"";
+    exportLine.append(" PBI_PROGVERSION PBI_PACKAGEDIR");
+  }
+  contents << ""; //Add a blank line between sections
+  if(isPortPBI){
+    // -- Port Info (only add this section if the PBI uses FreeBSD ports)
+    contents << "# -- Port Information --";
+    contents << "PBI_MAKEPORT=\""+mkStruct[0]+"\"";
+    contents << "PBI_MKPORTBEFORE=\""+mkStruct[1]+"\"";
+    contents << "PBI_MKPORTAFTER=\""+mkStruct[2]+"\"";
+    contents << "PBI_MAKEOPTS=\""+mkStruct[3]+"\"\n"; //adds a blank line after the section
+    exportLine.append(" PBI_MAKEPORT PBI_MKPORTBEFORE PBI_MKPORTAFTER PBI_MAKEOPTS");
+  }
   // -- Server & Other Info
   contents << "# -- Require Root Permissions to Install PBI --";
   contents << "PBI_REQUIRESROOT=\""+serverStruct[0].remove("\"")+"\"\n";
@@ -219,124 +197,345 @@
   contents << "PBI_BUILDKEY=\""+serverStruct[1].remove("\"")+"\"";
   contents << "PBI_AB_PRIORITY=\""+serverStruct[2].remove("\"")+"\"";
   contents << "PBI_AB_NOTMPFS=\""+serverStruct[3].remove("\"")+"\"\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";
+  exportLine.append(" PBI_REQUIRESROOT PBI_BUILDKEY PBI_AB_PRIORITY PBI_NOTMPFS");
+  // --Export all the variables used
+  contents << exportLine;
 
   //Create the File
   bool status = createFile(fileName, contents);
   return status;
 }
 
-bool ModBuild::makeMenuEntry(QString modDir, QString binary, QString name, QString icon, QString category){
-  //binary = binary name
-  //Will use the current program variables if no name or icon specified
-  if(!goodStructs()){ 
-    qDebug() << "Data Structure has not been loaded yet";
-    return FALSE;
-  }
+bool ModBuild::loadMenu(QString ifile){
+  //Reset the structure
+  menuStruct.clear();
+  menuStruct << ""<<""<<""<<""<<""<<""<<""<<"";  
+  //[ name, genericname, exec, icon, nodisplay, terminal, categories, mimetype]
+	
+  if(ifile.isEmpty()){ return TRUE; } //Also allow this to be a "reset" function for the currently loaded file
+  //Check if the file exists
+  saveMenuFile = ifile; //save the current filename that is loaded
+  QString filePath = modulePath +"/xdg-menu/"+ ifile;
+  if(!QFile::exists(filePath)){ return TRUE; } //Get ready to write a currently non-existant file
+  //Read the file and save the data into the structure
+  bool status = FALSE;
+  QFile file(filePath);
+    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
+      qDebug() << "Error: Could not open xdg-menu entry file:"<<filePath;
+    }else{
+      QTextStream in(&file);
+      while(!in.atEnd()){
+        QString line = in.readLine().simplified();
+        if(line.startsWith("Name=")){
+          menuStruct[0] = line.section("=",1,3,QString::SectionSkipEmpty);
+        }else if(line.startsWith("GenericName=")){
+          menuStruct[1] = line.section("=",1,3,QString::SectionSkipEmpty);
+        }else if(line.startsWith("Exec=")){
+          QString exec = line.section("=",1,3,QString::SectionSkipEmpty);
+          menuStruct[2] = getFilenameFromPath(exec);
+        }else if(line.startsWith("Icon=")){
+          QString icon = line.section("=",1,3,QString::SectionSkipEmpty);
+          menuStruct[3] = getFilenameFromPath(icon);
+	}else if(line.startsWith("NoDisplay=")){
+          menuStruct[4] = line.section("=",1,3,QString::SectionSkipEmpty);
+	}else if(line.startsWith("Terminal=")){
+          menuStruct[5] = line.section("=",1,3,QString::SectionSkipEmpty);
+	}else if(line.startsWith("Categories=")){
+          menuStruct[6] = line.section("=",1,3,QString::SectionSkipEmpty);
+	}else if(line.startsWith("MimeType=")){
+          menuStruct[7] = line.section("=",1,3,QString::SectionSkipEmpty);
+        }else{
+          //Do nothing - ignore this line
+        }
+      }
+      //Check true/false values
+      if(menuStruct[4].toLower() != "true"){ menuStruct[4]="false"; }
+      if(menuStruct[5].toLower() != "true"){ menuStruct[5]="false"; }
+      status = TRUE
+      file.close();
+    }
+    return status;
+}
 
-  //Check inputs
-  QDir testDir(modDir);
-  if(testDir.exists() == FALSE){
-    qDebug() << " - Menu Entry creation: Failure -- Invalid module directory";
-    return FALSE;
-  }
-  if(name.isEmpty()){ name = progStruct[0]; }
-  if(icon.isEmpty()){ icon = progStruct[3]; }
-
-  //Check whether the menu category is valid
-  //Valid menu categories located at: http://standards.freedesktop.org/menu-spec/menu-spec-latest.html#category-registry
-  QStringList validCategories;
-  validCategories <<"AudioVideo"<<"Development"<<"Education"<<"Game"<<"Graphics"<<"Network"<<"Office"<<"Settings"<<"System"<<"Utility";
-  if(!validCategories.contains(category)){
-    qDebug() << "Error: Invalid menu category -- menu entry not created";
-    return FALSE;
-  }
-  binary = getFilenameFromPath(binary);
-  //Create the filename
-  QString fileName = modDir + "/xdg-menu/"+binary+".desktop";
-  //Create the contents for a menu entry
+bool ModBuild::writeMenu(){
+  //Get the path to the file
+  QString fileName = modulePath + "/xdg-menu/" + saveMenuFile;
+  //Create the XDG compliant menu entry
   QStringList contents;
   contents << "#!/usr/bin/env";
   contents << "[Desktop Entry]";
   contents << "Value=1.0";
   contents << "Type=Application";
-  contents << "Name="+name;
-  contents << "GenericName="+name.toLower();
-  contents << "Exec=%%PBI_EXEDIR%%/"+binary;
+  contents << "Name="+menuStruct[0];
+  contents << "GenericName="+menuStruct[1];
+  contents << "Exec=%%PBI_EXEDIR%%/"+getFilenameFromPath(menuStruct[2]);
   contents << "Path=%%PBI_APPDIR%%";
-  contents << "Icon=%%PBI_APPDIR%%/"+getFilenameFromPath(icon);
+  contents << "Icon=%%PBI_APPDIR%%/"+getFilenameFromPath(menuStruct[4]);
   contents << "StartupNotify=true";
-  contents << "Categories="+category+";";
+  if(menuStruct[5].toLower()=="yes" || menuStruct[5].toLower()=="true"){
+    contents << "NoDisplay=true";
+  }
+  if(menuStruct[6].toLower()=="yes" || menuStruct[6].toLower()=="true"){
+    contents << "Terminal=true";
+  }
+  contents << "Categories="+menuStruct[7];
+  if(!menuStruct[8].isEmpty()){
+    contents << "MimeType="+menuStruct[8];
+  }
+  //Save the contents to the file
+  bool status;
+  status = createFile(fileName, contents);
+  return status;
+}
 
-  //Create the Menu entry
-  bool status = createFile(fileName, contents);
+bool ModBuild::removeMenu(){
+  //Delete the currently selected menu file
+  bool status = QFile::remove(modulePath+"/xdg-menu/"+saveMenuFile);
   return status;
 }
 
-bool ModBuild::makeDesktopEntry(QString modDir, QString binary, QString name, QString icon){
-  //binary = binary name
-  //Will use the current program variables if no name or icon specified
-  if(!goodStructs()){ 
-    qDebug() << "Data Structure has not been loaded yet";
-    return FALSE;
-  }
+bool ModBuild::loadDesktop(QString ifile){
+  //Reset the structure
+  desktopStruct.clear();
+  desktopStruct << ""<<""<<""<<""<<""<<""<<"";
+    //[ name, genericname, exec, icon, nodisplay, terminal, mimetypes]
+	
+  if(ifile.isEmpty()){ return TRUE; } //Also allow this to be a "reset" function for the currently loaded file
+  //Check if the file exists
+  saveDesktopFile = ifile; //save the current filename that is loaded
+  QString filePath = modulePath +"/xdg-desktop/"+ ifile;
+  if(!QFile::exists(filePath)){ return TRUE; } //Get ready to write a currently non-existant file
+  //Read the file and save the data into the structure
+  bool status = FALSE;
+  QFile file(filePath);
+    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
+      qDebug() << "Error: Could not open xdg-desktop entry file:"<<filePath;
+    }else{
+      QTextStream in(&file);
+      while(!in.atEnd()){
+        QString line = in.readLine().simplified();
+        if(line.startsWith("Name=")){
+          desktopStruct[0] = line.section("=",1,3,QString::SectionSkipEmpty);
+        }else if(line.startsWith("GenericName=")){
+          desktopStruct[1] = line.section("=",1,3,QString::SectionSkipEmpty);
+        }else if(line.startsWith("Exec=")){
+          QString exec = line.section("=",1,3,QString::SectionSkipEmpty);
+          desktopStruct[2] = getFilenameFromPath(exec);
+        }else if(line.startsWith("Icon=")){
+          QString icon = line.section("=",1,3,QString::SectionSkipEmpty);
+          desktopStruct[3] = getFilenameFromPath(icon);
+	}else if(line.startsWith("NoDisplay=")){
+          desktopStruct[4] = line.section("=",1,3,QString::SectionSkipEmpty);
+	}else if(line.startsWith("Terminal=")){
+          desktopStruct[5] = line.section("=",1,3,QString::SectionSkipEmpty);
+	}else if(line.startsWith("MimeType=")){
+          desktopStruct[6] = line.section("=",1,3,QString::SectionSkipEmpty);
+        }else{
+          //Do nothing - ignore this line
+        }
+      }
+      //Check for true/false values
+      if(desktopStruct[4].toLower() != "true"){ desktopStruct[4]="false"; }
+      if(desktopStruct[5].toLower() != "true"){ desktopStruct[5]="false"; }
+      status = TRUE
+      file.close();
+    }
+    return status;
+}
 
-  //Check inputs
-  QDir testDir(modDir);
-  if(testDir.exists() == FALSE){
-    qDebug() << " - Desktop Entry creation: Failure -- Invalid module directory";
-    return FALSE;
-  }
-  if(name.isEmpty()){ name = progStruct[0]; }
-  if(icon.isEmpty()){ icon = progStruct[3]; }
-  binary = getFilenameFromPath(binary);
-  //Create the filename
-  QString fileName = modDir + "/xdg-desktop/"+binary+".desktop";
-  //Create the contents for a menu entry
+bool ModBuild::writeDesktop(){
+  //Get the path to the file
+  QString fileName = modulePath + "/xdg-desktop/" + saveDesktopFile;
+  //Create the XDG compliant desktop entry
   QStringList contents;
   contents << "#!/usr/bin/env";
   contents << "[Desktop Entry]";
   contents << "Value=1.0";
   contents << "Type=Application";
-  contents << "Name="+name;
-  contents << "GenericName="+name.toLower();
-  contents << "Exec=%%PBI_EXEDIR%%/"+binary;
+  contents << "Name="+desktopStruct[0];
+  contents << "GenericName="+desktopStruct[1];
+  contents << "Exec=%%PBI_EXEDIR%%/"+getFilenameFromPath(desktopStruct[2]);
   contents << "Path=%%PBI_APPDIR%%";
-  contents << "Icon=%%PBI_APPDIR%%/"+getFilenameFromPath(icon);
+  contents << "Icon=%%PBI_APPDIR%%/"+getFilenameFromPath(desktopStruct[3]);
   contents << "StartupNotify=true";
+  if(desktopStruct[4].toLower()=="yes" || desktopStruct[4].toLower()=="true"){
+    contents << "NoDisplay=true";
+  }
+  if(desktopStruct[5].toLower()=="yes" || menuStruct[5].toLower()=="true"){
+    contents << "Terminal=true";
+  }
+  if(!desktopStruct[6].isEmpty()){
+    contents << "MimeType="+desktopStruct[6];
+  }
+  //Save the contents to the file
+  bool status;
+  status = createFile(fileName, contents);
+  return status;
+}
 
-  //Create the Menu entry
-  bool status = createFile(fileName, contents);
+bool ModBuild::removeDesktop(){
+  //Delete the currently selected menu file
+  bool status = QFile::remove(modulePath+"/xdg-desktop/"+saveDesktopFile);
   return status;
 }
 
-bool ModBuild::makeExternalLinks(QString modDir, QStringList binary, QStringList options){
-  //binary list and options list need to be the same size
-  if(binary.length() != options.length()){ 
-    qDebug() << "Error: External Links lists are not the same size";
-    return FALSE;
+bool ModBuild::loadMime(QString ifile){
+  //Reset the structure
+  mimeStruct.clear();
+  mimeStruct << "" << "" << "";  //[ info, type, patterns]
+  if(ifile.isEmpty()){ return TRUE; } //Also allow this to be a "reset" function for the currently loaded file
+  //Check if the file exists
+  saveMimeFile = ifile; //save the current filename that is loaded
+  QString filePath = modulePath +"/xdg-mime/"+ ifile;
+  if(!QFile::exists(filePath)){ return TRUE; } //Get ready to write a currently non-existant file
+  //Read the file and save the data into the structure
+  bool status = FALSE;
+  QFile file(filePath);
+    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
+      qDebug() << "Error: Could not open xdg-mime entry file:"<<filePath;
+    }else{
+      QTextStream in(&file);
+      QStringList patterns;
+      while(!in.atEnd()){
+        QString line = in.readLine().simplified();
+        if(line.startsWith("<mime-info ")){
+          mimeStruct[0] = line.section(" xmlns=",1,1).section("=",0,0).section(">",0,0).remove("\"").remove("\'");
+        }else if(line.startsWith("<mime-type ")){
+          mimeStruct[1] = line.section(" type=",1,1).section("=",0,0).section(">",0,0).remove("\"").remove("\'");
+        }else if(line.startsWith("<glob ") && line.contains("pattern=")){
+          patterns << line.section("pattern=",1,1).section("=",0,0).section("/>",0,0).remove("\"").remove("\'");
+	  mimeStruct[2].append(pattern);
+        }else{
+          //Do nothing - ignore this line
+        }
+      }
+      mimeStruct[2] = patterns.join(" "); //make a space-delimited list
+      status = TRUE
+      file.close();
+    }
+    return status;
+}
+
+bool ModBuild::writeMime(){
+  //Stupid check to make sure there is actually file patterns to be saved
+  if(mimeStruct[2].isEmpty()){ return FALSE; }
+  //Get the path to the file
+  QString fileName = modulePath + "/xdg-menu/" + saveMimeFile;
+  //Set a default mime-info if none given  
+  if(mimeStruct[0].isEmpty()){
+    mimeStruct[0] = "http://www.freedesktop.org/standards/shared-mime-info";
   }
-  //Check module directory and get filename
-  if(!modDir.endsWith("/")){ modDir.append("/"); }
-  QString fileName = modDir+"external-links";
+  //Set a default mime type based upon the filename if none given 
+  if(mimeStruct[1].isEmpty()){
+    mimeStruct[1] = "application/x-"+saveMimeFile.section("-xdg.xml",0,0);
+  }
+  //Make a list of all the patterns to save
+  QStringList patterns = mimeStruct[2].split(" ");
+  //Create the XDG compliant mime type entry
+  QStringList contents;
+  contents << "<?xml version=\"1.0\"?>";
+  contents << "<mime-info xmlns=\'"+mimeStruct[0]+"\'>";
+  contents << "  <mime-type type=\""+mimeStruct[1]+"\">";
+  for(int i=0; i<patterns.length(); i++){
+    contents << "  <glob weight=\"100\" pattern=\""+patterns[i]+"\"/>";
+  }
+  contents << " </mime-type>";
+  contents << "</mime-info>";
+  //Save the contents to the file
+  bool status;
+  status = createFile(fileName, contents);
+  if(status){ 
+    //If successful, add the new mimetype to the current list
+    currentMimeTypes <<mimeStruct[1]; 
+    currentMimeTypes.removeDuplicates(); 
+  }
+  return status;
+}
+
+bool ModBuild::removeMime(){
+  //Delete the currently selected mime file
+  bool status = QFile::remove(modulePath+"/xdg-mime/"+saveMimeFile);
+  //Remove the current Mime entry is successful
+  if(status){
+    int index = currentMimeTypes.indexOf(mimeStruct[1]);
+    if(index >= 0){ currentMimeTypes.removeAt(index); }
+  }
+  return status;
+}
+
+bool ModBuild::loadExternalLinks(){
+    //reset the structure
+    linksStruct.clear();
+    linksStruct << "" << "" << "";    
+    //Read the new file
+    QFile file(modulePath+"/external-links");
+    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
+      qDebug() << "Error: Could not open external-links file:"<<filePath;
+      return FALSE;
+    }
+    QTextStream in(&file);
+    QString original, linkto, types;
+    while(!in.atEnd()){
+      QString line = in.readLine();
+      line.replace("\t"," ");
+      if(!line.startsWith("#")){
+        original = line.section(" ",0,0,QString::SectionSkipEmpty);
+        linkto =  line.section(" ",1,1,QString::SectionSkipEmpty);
+        types =  line.section(" ",2,2,QString::SectionSkipEmpty);
+	//Add the link to the structure
+	linksStruct << original+"::"+linkto+"::"+types;
+      }else{
+        //Do nothing - ignore this line
+      }
+    }
+    file.close();
+}
+
+bool ModBuild::writeExternalLinks(){
+  //File to write
+  QString fileName = modulePath+"/external-links";
   //Get the contents to write to the file
   QStringList contents;
   //Standard Header for file
   contents << "# Files to be Sym-Linked into the default LOCALBASE";
   contents << "# One per-line, relative to %%PBI_APPDIR%% and LOCALBASE";
   contents << "# Defaults to keeping any existing files in LOCALBASE";
-  contents << "# Use action binary for binaries that need wrapper functionality\n";
+  contents << "# Use action \"binary\" for binaries that need wrapper functionality\n";
   contents << "# TARGET             LINK IN LOCALBASE         ACTION";
   //add the desired binaries
-  for(int i=0; i<binary.length(); i++){
-    contents << binary[i]+"     "+binary[i]+"     "+options[i];
+  for(int i=0; i<linksStruct.length(); i++){
+    QStringList link = linksStruct[i].split("::")
+    contents << link[0] +"     "+link[1]+"     "+link[2];
   }
   //Create the external-links file
   bool status = createFile(fileName, contents);
   return status;
 }
 
+void ModBuild::addExternalLink(QString file, QString linkto, QStringList types){
+  QString chk = file+"::"+linkto+"::"; //try to match the file and link, not types
+  for(int i=0; i<linksStruct.length(); i++){
+    if( linksStruct[i].startsWith(chk) ){
+      //This link already exists -> update the types and return
+      linksStruct[i] = chk+types.join(",");
+      return;
+    }
+  }	
+  //This is a new link, add it to the end
+  linksStruct << chk+types.join(",");
+}
+
+void ModBuild::removeExternalLink(QString file, QString linkto){
+  QString chk = file+"::"+linkto+"::"; //try to match the file and link, not types
+  for(int i=0; i<linksStruct.length(); i++){
+    if( linksStruct[i].startsWith(chk) ){
+      //This link already exists -> remove it
+      linksStruct.removeAt(i);
+      return;
+    }
+  }	
+}
+
 bool ModBuild::addResource(QString modDir, QString resourcePath){
   if(resourcePath.isEmpty()){
     qDebug() << "Warning: no resource selected";
@@ -407,6 +606,43 @@
   return TRUE;
 }
 
+QStringList ModBuild::filesAvailable(QString group){
+  QStringList fileList;  
+  //Check to make sure that a module has been selected first
+  if(modulePath.isEmpty()){ return fileList; }
+  QDir dir(modulePath);
+  group = group.toLower();
+  if(group=="resources"){
+    dir.cd(group);
+    //Get all the files in the main directory
+    fileList = dir.entryList(QDir::Files || QDir::NoDotAndDotDot || QDir::Hidden);
+    //Get all the files in any sub-directories
+    QStringList subdirs = dir.entryList(QDir::AllDirs || QDir::NoDotAndDotDot);
+    for(int i=0; i<dirs.length(); i++){
+      dir.cd(dirs[i]);
+      fileList = fileList + dir.entryList(QDir::Files || QDir::NoDotAndDotDot || QDir::Hidden);
+      dir.cdUp();
+    }
+  }else if(group=="xdg-desktop"){
+    dir.cd(group);
+    //Get all the files in the main directory
+    fileList = dir.entryList(QStringList() << ".desktop", QDir::Files || QDir::NoDotAndDotDot || QDir::Hidden);
+  }else if(group=="xdg-menu"){
+    dir.cd(group);
+    //Get all the files in the main directory
+    fileList = dir.entryList(QStringList() << ".desktop", QDir::Files || QDir::NoDotAndDotDot || QDir::Hidden);	  
+  }else if(group=="xdg-mime"){
+    dir.cd(group);
+    //Get all the files in the main directory
+    fileList = dir.entryList(QStringList() << ".xml", QDir::Files || QDir::NoDotAndDotDot || QDir::Hidden);	  
+  }else if(group=="scripts"){
+    dir.cd(group);
+    //Get all the files in the main directory
+    fileList = dir.entryList(QDir::Files || QDir::NoDotAndDotDot || QDir::Hidden);	  
+  }
+  return fileList; //This will return nothing if an invalid group is given
+}
+
 QString ModBuild::readValue(QString variable){
   QString val;
   if(variable=="PBI_PROGNAME"){ val = progStruct[0]; }
@@ -468,9 +704,7 @@
 
 QString ModBuild::getFilenameFromPath(QString fullPath){
   if(fullPath.isEmpty()){return "";}
-  QStringList entries = fullPath.split("/",QString::SkipEmptyParts);
-  QString name = entries[entries.length() - 1]; //only take the last entry
-  return name;
+  return fullPath.section("/",-1);
 }
 
 QString ModBuild::getMenuEntryValue(QString filePath, QString value, bool forceRead){

Modified: users/ken/EasyPBI2/modBuild.h
===================================================================
--- users/ken/EasyPBI2/modBuild.h	2012-10-03 20:26:27 UTC (rev 19592)
+++ users/ken/EasyPBI2/modBuild.h	2012-10-04 03:54:48 UTC (rev 19593)
@@ -6,15 +6,19 @@
 #include <QDir>
 #include <QDebug>
 #include <QWidget>
+#include <QFile>
+#include <QDir>
 
 class ModBuild : public QWidget{
 	Q_OBJECT
 	
 private:
+  //Internal variables
   QStringList progStruct, mkStruct, serverStruct, menuStruct, desktopStruct, linksStruct, portStruct;
-  QString saveMenuFile, saveDesktopFile, saveExternalLinksFile, savePortDir;
-
-  bool goodStructs();
+  QString modulePath, saveMenuFile, saveDesktopFile, saveMimeFile;
+  QStringList currentBins, currentMimeTypes, currentIcons;
+  bool isPortPBI, isLocalPBI;
+  //Internal functions
   bool isGoodPort(QString, bool);
   QString assignPortMenuCategory(QString);
   int readMakeFile(QString);
@@ -22,14 +26,33 @@
 
 public:
   ModBuild(QWidget* parent =0);
-  void makeStructs(QString,QString,QString,QString,QString,QString,QString,QString,QString,bool,QString,bool);
-  bool loadPBIconf(QString);
-  QString makeModuleDir(QString,QString);
-  bool writePBIconf(QString);
-  bool makeMenuEntry(QString,QString,QString,QString,QString);
-  bool makeDesktopEntry(QString,QString,QString,QString);
-  bool makeExternalLinks(QString,QStringList,QStringList);
-  bool createFile(QString,QStringList);
+  ~ModBuild();
+  //Regular functions
+  bool loadPBIconf();
+  bool writePBIconf();
+  
+  bool loadDesktop(QString);
+  bool writeDesktop();
+  bool removeDesktop();
+
+  bool loadMenu(QString);
+  bool writeMenu();
+  bool removeMenu();
+
+  bool loadMime(QString);
+  bool writeMime();
+  bool removeMime();
+
+  bool loadExternalLinks();
+  bool writeExternalLinks();
+  void addExternalLink(QString, QString, QString);
+  void removeExternalLink(QString, QString, QString);
+  
+  //Static functions
+  static QString makeModuleDir(QString,QString);
+  static bool createFile(QString,QStringList);
+  static QStringList filesAvailable(QString);
+
   QString readValue(QString);
   bool writeValue(QString,QString);
   bool addResource(QString,QString);
@@ -37,7 +60,6 @@
   QString getFilenameFromPath(QString);
   QString getMenuEntryValue(QString, QString, bool forceRead = FALSE);
   QString getDesktopEntryValue(QString, QString, bool forceRead = FALSE);
-  QStringList getExternalLinksValues(QString, QString, bool forceRead = FALSE);
   QStringList getPortInfo(QString, QString, bool forceRead = FALSE);
   
 



More information about the Commits mailing list