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

svn at pcbsd.org svn at pcbsd.org
Thu Oct 4 14:11:14 PDT 2012


Author: kenmoore
Date: 2012-10-04 21:11:14 +0000 (Thu, 04 Oct 2012)
New Revision: 19604

Modified:
   users/ken/EasyPBI2/modBuild.cpp
   users/ken/EasyPBI2/modBuild.h
Log:
Finish up almost all the rest of the revamped module builder class for EasyPBI2. I just need to look over/fix the port detection stuff before it is completely done.



Modified: users/ken/EasyPBI2/modBuild.cpp
===================================================================
--- users/ken/EasyPBI2/modBuild.cpp	2012-10-04 19:01:30 UTC (rev 19603)
+++ users/ken/EasyPBI2/modBuild.cpp	2012-10-04 21:11:14 UTC (rev 19604)
@@ -1,14 +1,5 @@
 #include "modBuild.h"
 
-/*  --- EXAMPLE USAGE ---
-  1) Make/fill structures: makeStructs(), loadPBIconf()
-  2) Make the module directory: makeModuleDir()
-  3) Make pbi.conf: writePBIconf()
-  4) Make desktop/menu entries: makeDesktopEntry(), makeMenuEntry()
-  5) Make external-links file: makeExternalLinks()
-  6) Add resources (icons, etc): addResource()
-*/
-
 ModBuild::ModBuild(QWidget* parent) : QWidget(parent){
   // --Clear the internal variables--
   isPortPBI=FALSE; isLocalPBI=FALSE;
@@ -32,6 +23,82 @@
 ModBuild::~ModBuild(){
 }
 
+bool ModBuild::createNewModule(QString modPath, QString modType, QString modBase){
+  //Set the module path for all the functions
+  modulePath = modPath;	
+  //Create the module directory structure if possible
+  bool ok = createModuleDir(); //this will check for existing dir and overwrite it if possible
+  if(!ok){return FALSE; }	
+  //Get the type of PBI this module creates
+  isPortPBI=FALSE; isLocalPBI=FALSE;
+  if(modType.toLower() == "port"){ isPortPBI=TRUE; }
+  else if(modType.toLower() == "local"){ isLocalPBI=TRUE; }
+  else{
+    qDebug() << "Cannot create module: Invalid module type - "+modType;
+    return FALSE;
+  }
+  //Clear out all the module structures
+  currentBins.clear(); currentIcons.clear(); currentMimeTypes.clear();
+  loadDesktop(""); loadMenu(""); loadMime("");
+  linksStruct.clear();  loadPBIconf();
+  //Try to auto-populate the module structures if possible
+  if(isPortPBI){
+    mkStruct[0] = modBase; //pbi_makeport
+    qDebug() << "Reading port info has not been finished for EasyPBI 2";
+  }
+  if(isLocalPBI){
+    progStruct[0] = modBase.section("/",-1); //pbi_progname
+    progStruct[5] = modBase;  //pbi_packagedir
+  }
+  //Now create the module contents
+  writePBIconf();
+  writeExternalLinks();
+  return TRUE;
+}
+
+bool ModBuild::loadModule(QString modPath){
+  //verify that the module exists
+  QDir dir(modPath);
+  if( !dir.exists() || !dir.exists("pbi.conf") ){
+    qDebug() << "Cannot load module: not a valid module directory - "+modPath;
+    return FALSE;
+  }
+  //Save which module this is
+  modulePath = modPath;
+  //Load pbi.conf
+  loadPBIconf();
+  //Determine the type of module by the pbi.conf entries
+  isPortPBI=FALSE; isLocalPBI=FALSE;
+  if(!progStruct[5].isEmpty()){ isLocalPBI=TRUE; } //check for PBI_PACKAGEDIR
+  if(!mkStruct[0].isEmpty()){ isPortPBI=TRUE; } //check for PBI_MAKEPORT
+  //Reset the current lists
+  currentBins.clear(); currentIcons.clear(); currentMimeTypes.clear();
+  //Reset the XDG file structures	
+  loadDesktop(""); loadMenu(""); //Just clear these structures
+  QStringList tmp = filesAvailable("mime");
+  for(int i=0; i<tmp.length(); i++){
+    loadMime(tmp[i]); //This will fill up the currentMimeTypes structure;
+  }
+  //Get the current resources
+  tmp = filesAvailable("resources");
+  for(int i=0; i<tmp.length(); i++){
+    if(tmp[i].endsWith(".png")){ currentIcons << tmp[i]; }
+    if(tmp[i].startsWith("bin/")){ currentBins << tmp[i]; }
+  }
+  //Get additional port binaries (if applicable)
+  if(isPortPBI){
+    qDebug() << "Reading port info has not been finished for EasyPBI 2";
+  }
+  //Load the external-links file
+  if(!dir.exists("external-links")){
+    linksStruct.clear();
+    writeExternalLinks(); //Create the external-links file if it is missing
+  }else{
+    loadExternalLinks();
+  }
+  return TRUE;
+}
+
 bool ModBuild::loadPBIconf(){
   //Clear the current structures
   progStruct.clear(); mkStruct.clear(); serverStruct.clear();
@@ -39,11 +106,11 @@
   progStruct << "" << "" << "" << "" << "" << "";
   mkStruct << "" << "" << "" << "";
   serverStruct << "NO" << "00" << "00" << "NO";
-
+  if(!QFile::exists(modulePath+"/pbi.conf")){ return FALSE; } //only reset the structures if the file does not exist
   //Read the designated pbi.conf and store the variables
   QFile file(modulePath+"/pbi.conf");
   if( !file.open(QIODevice::ReadOnly | QIODevice::Text)){
-    qDebug() << "Error: Unable to load "+modDir+"pbi.conf";
+    qDebug() << "Error: Unable to load "+modulePath+"/pbi.conf";
     return FALSE;
   }
   QTextStream in(&file);
@@ -101,38 +168,31 @@
   return TRUE;
 }
 
-QString ModBuild::makeModuleDir(QString baseDir, QString modName){
+bool ModBuild::createModuleDir(){
 //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); }
-
+  QString modName = modulePath.section("/",-1);
   //Check the base Directory
-  QDir dir(baseDir);
-  if(!dir.exists()){
-    qDebug() << "Error: Base directory does not exist";
-    return "";
-  }
-  QString modulePath = "";
-  if(dir.exists(modName)){
-    dir.cd(modName);
+  QDir dir(modulePath);
+  if(dir.exists()){ 
     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
+      return FALSE;
     }else{
       qDebug() << "Valid Module directory already exists - overwriting it";
-      bool success = emptyDirectory(baseDir+"/"+modName); //Remove the module
+      bool success = emptyDirectory(modulePath); //Remove the module
       if(!success){
         qDebug() << " - Could not remove all old module contents. Please remove them by hand";
+	return FALSE;
       }else{
-        dir.rmdir(baseDir+"/"+modName);
+        dir.rmdir(modulePath);
       }
     }
   }
-  //Create New module directory
-  dir.cd(baseDir);
+  //Create new module directory
+  dir.cd(modulePath);
+  dir.cdUp();
   if(!dir.mkdir(modName)){
     qDebug() << "Error: Could not create module directory";
     // return empty path
@@ -145,11 +205,11 @@
     dir.mkdir("xdg-mime");
     dir.mkdir("scripts");
     qDebug() << "Module directory successfully created";
-    modulePath = baseDir + "/" + modName; //return the full path
   }
 
-  return modulePath;
+  return TRUE;
 }
+
 bool ModBuild::writePBIconf(){
 //Returns TRUE if successful
 
@@ -251,7 +311,7 @@
       //Check true/false values
       if(menuStruct[4].toLower() != "true"){ menuStruct[4]="false"; }
       if(menuStruct[5].toLower() != "true"){ menuStruct[5]="false"; }
-      status = TRUE
+      status = TRUE;
       file.close();
     }
     return status;
@@ -337,7 +397,7 @@
       //Check for true/false values
       if(desktopStruct[4].toLower() != "true"){ desktopStruct[4]="false"; }
       if(desktopStruct[5].toLower() != "true"){ desktopStruct[5]="false"; }
-      status = TRUE
+      status = TRUE;
       file.close();
     }
     return status;
@@ -404,13 +464,16 @@
           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
+      //Make sure the detected mime type is in the current list
+      currentMimeTypes << mimeStruct[1];
+      currentMimeTypes.removeDuplicates();
+      //Return
+      status = TRUE;
       file.close();
     }
     return status;
@@ -470,7 +533,7 @@
     //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;
+      qDebug() << "Error: Could not open external-links file:"<<modulePath+"/external-links";
       return FALSE;
     }
     QTextStream in(&file);
@@ -489,6 +552,7 @@
       }
     }
     file.close();
+    return TRUE;
 }
 
 bool ModBuild::writeExternalLinks(){
@@ -504,7 +568,7 @@
   contents << "# TARGET             LINK IN LOCALBASE         ACTION";
   //add the desired binaries
   for(int i=0; i<linksStruct.length(); i++){
-    QStringList link = linksStruct[i].split("::")
+    QStringList link = linksStruct[i].split("::");
     contents << link[0] +"     "+link[1]+"     "+link[2];
   }
   //Create the external-links file
@@ -536,7 +600,7 @@
   }	
 }
 
-bool ModBuild::addResource(QString modDir, QString resourcePath){
+bool ModBuild::addResource(QString resourceType, QString resourcePath){
   if(resourcePath.isEmpty()){
     qDebug() << "Warning: no resource selected";
     return TRUE;  // Do not flag this as an error in the function
@@ -546,30 +610,67 @@
     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/";
+  //Determine the type of file that is being added
+  bool isWrapper=FALSE;
+  bool isIcon=FALSE;
+  if(resourceType.toLower()=="wrapper"){ isWrapper = TRUE;  }
+  else if(resourceType.toLower()=="icon"){ isIcon = TRUE; }
+  //Create the full path to the location within the module  
+  QString newResourcePath = modulePath + "/resources/";
+  if(isWrapper){ 
+    newResourcePath.append("bin/"); 
+    //Make sure the "bin" directory exists
+    QDir dir(newResourcePath);
+    if(!dir.exists()){ dir.cdUp(); dir.mkdir("bin"); }  
+  }
   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
+  bool status=FALSE;
   if( !QFile::copy(resourcePath,newResourcePath) ){
     qDebug() << "Error copying resource into the module";
-    return FALSE;
+  }else{
+    status=TRUE;
   }
-  return TRUE;
+  //Add the item to the appropriate lists
+  if(status && isIcon){ currentIcons << resource;  currentIcons.removeDuplicates();}
+  else if(status && isWrapper){ currentBins << "bin/"+resource; currentBins.removeDuplicates();}
+  
+  return status;
 }
 
+bool ModBuild::removeResource(QString filePath){
+  //filePath is relative to the module's resource directory
+	
+  //Determine if it is a wrapper script, icon, or other
+  bool isWrapper=FALSE; bool isIcon=FALSE;
+  if(filePath.startsWith("bin/")){ isWrapper=TRUE; }
+  else if(filePath.endsWith(".png")){ isIcon=TRUE; }
+  //Check if the file exists
+  bool status=FALSE;
+  QDir dir(modulePath+"/resources");
+  if(dir.exists(filePath)){
+    status = dir.remove(filePath);
+  }else{
+    qDebug() << "Error removing non-existant resource:"+filePath;
+  }
+  //Remove the item from the appropriate lists
+  if(status && isIcon){ currentIcons.removeAll(filePath); }
+  else if(status && isWrapper){ currentBins.removeAll(filePath); }
+  
+  return status;
+}
+
 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)
@@ -615,48 +716,76 @@
   if(group=="resources"){
     dir.cd(group);
     //Get all the files in the main directory
-    fileList = dir.entryList(QDir::Files || QDir::NoDotAndDotDot || QDir::Hidden);
+    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);
+    QStringList subdirs = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot);
+    for(int i=0; i<subdirs.length(); i++){
+      dir.cd(subdirs[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);
+    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);	  
+    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);	  
+    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);	  
+    fileList = dir.entryList(QStringList("*.sh"), QDir::Files | QDir::NoDotAndDotDot | QDir::Hidden);	  
   }
   return fileList; //This will return nothing if an invalid group is given
 }
 
 QString ModBuild::readValue(QString variable){
+//progStruct=[ name, website, author, icon, version, packageDir]
+//mkStruct=[ makeport, portbefore, portafter, makeoptions]
+//serverStruct=[ needroot, buildkey, priority, noTMPFS]
+//menuStruct=[ name, genericname, exec, icon, nodisplay, terminal, categories, mimetype]
+//desktopStruct=[ name, genericname, exec, icon, nodisplay, terminal, mimetype]
+//mimeStruct=[ info, type, patterns] (patterns is a " "-delimited list)
+	
   QString val;
-  if(variable=="PBI_PROGNAME"){ val = progStruct[0]; }
-  else if(variable=="PBI_PROGWEB"){ val = progStruct[1]; }
-  else if(variable=="PBI_PROGAUTHOR"){ val = progStruct[2]; }
-  else if(variable=="PBI_PROGICON"){ val = progStruct[3]; }
-  else if(variable=="PBI_MAKEPORT"){ val = mkStruct[0]; }
-  else if(variable=="PBI_MKPORTBEFORE"){ val = mkStruct[1]; }
-  else if(variable=="PBI_MKPORTAFTER"){ val = mkStruct[2]; }
-  else if(variable=="PBI_MAKEOPTS"){ val = mkStruct[3]; }
-  else if(variable=="PBI_REQUIRESROOT"){ val = serverStruct[0]; }
-  else if(variable=="PBI_BUILDKEY"){ val = serverStruct[1]; }
-  else if(variable=="PBI_AB_PRIORITY"){ val = serverStruct[2]; }
-  else if(variable=="PBI_AB_NOTMPFS"){ val = serverStruct[3]; }
+  QString var = variable.toLower();
+  if(var=="progname"){ val = progStruct[0] ;}
+  else if(variable=="progweb"){ val = progStruct[1]; }
+  else if(variable=="progauthor"){ val = progStruct[2]; }
+  else if(variable=="progicon"){ val = progStruct[3]; }
+  else if(variable=="progversion"){ val = progStruct[4]; }
+  else if(variable=="packagedir"){ val = progStruct[5]; }
+  else if(variable=="makeport"){ val = mkStruct[0]; }
+  else if(variable=="makeportbefore"){ val = mkStruct[1]; }
+  else if(variable=="makeportafter"){ val = mkStruct[2]; }
+  else if(variable=="makeoptions"){ val = mkStruct[3]; }
+  else if(variable=="requiresroot"){ val = serverStruct[0]; }
+  else if(variable=="buildkey"){ val = serverStruct[1]; }
+  else if(variable=="priority"){ val = serverStruct[2]; }
+  else if(variable=="notmpfs"){ val = serverStruct[3]; }
+  else if(variable=="menuname"){ val = menuStruct[0]; }
+  else if(variable=="menugenericname"){ val = menuStruct[1]; }
+  else if(variable=="menuexec"){ val = menuStruct[2]; }
+  else if(variable=="menuicon"){ val = menuStruct[3]; }
+  else if(variable=="menunodisplay"){ val = menuStruct[4] ;}
+  else if(variable=="menuterminal"){ val = menuStruct[5]; }
+  else if(variable=="menucategories"){ val = menuStruct[6]; }
+  else if(variable=="menumimetype"){ val = menuStruct[7]; }
+  else if(variable=="desktopname"){ val = desktopStruct[0]; }
+  else if(variable=="desktopgenericname"){ val = desktopStruct[1]; }
+  else if(variable=="desktopexec"){ val = desktopStruct[2]; }
+  else if(variable=="desktopicon"){ val = desktopStruct[3]; }
+  else if(variable=="desktopnodisplay"){ val = desktopStruct[4]; }
+  else if(variable=="desktopterminal"){ val = desktopStruct[5]; }
+  else if(variable=="desktopmimetype"){ val = desktopStruct[6]; }
+  else if(variable=="mimeinfo"){ val = mimeStruct[0]; }
+  else if(variable=="mimetype"){ val = mimeStruct[1]; }
+  else if(variable=="mimepatterns"){ val = mimeStruct[2]; }
   else{
     qDebug() << "Error: Invalid variable name to read";
   }
@@ -664,18 +793,45 @@
 }
 
 bool ModBuild::writeValue(QString variable, QString value){
-  if(variable=="PBI_PROGNAME"){ progStruct[0] = value; }
-  else if(variable=="PBI_PROGWEB"){ progStruct[1] = value; }
-  else if(variable=="PBI_PROGAUTHOR"){ progStruct[2] = value; }
-  else if(variable=="PBI_PROGICON"){ progStruct[3] = value; }
-  else if(variable=="PBI_MAKEPORT"){ mkStruct[0] = value; }
-  else if(variable=="PBI_MKPORTBEFORE"){ mkStruct[1] = value; }
-  else if(variable=="PBI_MKPORTAFTER"){ mkStruct[2] = value; }
-  else if(variable=="PBI_MAKEOPTS"){ mkStruct[3] = value; }
-  else if(variable=="PBI_REQUIRESROOT"){ serverStruct[0] = value; }
-  else if(variable=="PBI_BUILDKEY"){ serverStruct[1] = value; }
-  else if(variable=="PBI_AB_PRIORITY"){ serverStruct[2] = value; }
-  else if(variable=="PBI_AB_NOTMPFS"){ serverStruct[3] = value; }
+//progStruct=[ name, website, author, icon, version, packageDir]
+//mkStruct=[ makeport, portbefore, portafter, makeoptions]
+//serverStruct=[ needroot, buildkey, priority, noTMPFS]
+//menuStruct=[ name, genericname, exec, icon, nodisplay, terminal, categories, mimetype]
+//desktopStruct=[ name, genericname, exec, icon, nodisplay, terminal, mimetype]
+//mimeStruct=[ info, type, patterns] (patterns is a " "-delimited list)
+  QString var = variable.toLower();
+  if(var=="progname"){ progStruct[0] = value; }
+  else if(variable=="progweb"){ progStruct[1] = value; }
+  else if(variable=="progauthor"){ progStruct[2] = value; }
+  else if(variable=="progicon"){ progStruct[3] = value; }
+  else if(variable=="progversion"){ progStruct[4] = value; }
+  else if(variable=="packagedir"){ progStruct[5] = value; }
+  else if(variable=="makeport"){ mkStruct[0] = value; }
+  else if(variable=="makeportbefore"){ mkStruct[1] = value; }
+  else if(variable=="makeportafter"){ mkStruct[2] = value; }
+  else if(variable=="makeoptions"){ mkStruct[3] = value; }
+  else if(variable=="requiresroot"){ serverStruct[0] = value; }
+  else if(variable=="buildkey"){ serverStruct[1] = value; }
+  else if(variable=="priority"){ serverStruct[2] = value; }
+  else if(variable=="notmpfs"){ serverStruct[3] = value; }
+  else if(variable=="menuname"){ menuStruct[0] = value; }
+  else if(variable=="menugenericname"){ menuStruct[1] = value; }
+  else if(variable=="menuexec"){ menuStruct[2] = value; }
+  else if(variable=="menuicon"){ menuStruct[3] = value; }
+  else if(variable=="menunodisplay"){ menuStruct[4] = value; }
+  else if(variable=="menuterminal"){ menuStruct[5] = value; }
+  else if(variable=="menucategories"){ menuStruct[6] = value; }
+  else if(variable=="menumimetype"){ menuStruct[7] = value; }
+  else if(variable=="desktopname"){ desktopStruct[0] = value; }
+  else if(variable=="desktopgenericname"){ desktopStruct[1] = value; }
+  else if(variable=="desktopexec"){ desktopStruct[2] = value; }
+  else if(variable=="desktopicon"){ desktopStruct[3] = value; }
+  else if(variable=="desktopnodisplay"){ desktopStruct[4] = value; }
+  else if(variable=="desktopterminal"){ desktopStruct[5] = value; }
+  else if(variable=="desktopmimetype"){ desktopStruct[6] = value; }
+  else if(variable=="mimeinfo"){ mimeStruct[0] = value; }
+  else if(variable=="mimetype"){ mimeStruct[1] = value; }
+  else if(variable=="mimepatterns"){ mimeStruct[2] = value; }
   else{
     qDebug() << "Error: Invalid variable name to read";
     return FALSE;
@@ -683,20 +839,10 @@
   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: Module directory does not exist:" << modDir;
-    return;
-  }
-  //Compress the directory
-  QString localDir = getFilenameFromPath(modDir);
-  QString cmd = "cd "+modDir+"/..; tar czf "+localDir+".tar.gz "+localDir;
+void ModBuild::compressModule(){
+  //Compress the module directory
+  QString localDir = getFilenameFromPath(modulePath);
+  QString cmd = "cd "+modulePath+"/..; tar czf "+localDir+".tar.gz "+localDir;
   //qDebug() << cmd;
   system( cmd.toUtf8() );
   return;
@@ -707,184 +853,6 @@
   return fullPath.section("/",-1);
 }
 
-QString ModBuild::getMenuEntryValue(QString filePath, QString value, bool forceRead){
-  if(!filePath.endsWith(".desktop")){
-    qDebug() << "Error: Desired file is not a menu entry:" << filePath;
-    return "";
-  }
-  if(filePath != saveMenuFile || forceRead){
-    //Read the new file
-    QFile file(filePath);
-    if(!file.exists()){
-      qDebug() << "Error: Menu entry file does not exist:"<<filePath;
-      return "";
-    }
-    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
-      qDebug() << "Error: Could not open menu entry file:"<<filePath;
-      return "";
-    }
-    QTextStream in(&file);
-    QString name, genericname, exec, icon, categories;
-    while(!in.atEnd()){
-      QString line = in.readLine();
-      if(line.startsWith("Name=")){
-        name = line.section("=",1,3,QString::SectionSkipEmpty);
-      }else if(line.startsWith("GenericName=")){
-        genericname = line.section("=",1,3,QString::SectionSkipEmpty);
-      }else if(line.startsWith("Exec=")){
-        exec = line.section("=",1,3,QString::SectionSkipEmpty);
-        exec = getFilenameFromPath(exec);
-      }else if(line.startsWith("Icon=")){
-        icon = line.section("=",1,3,QString::SectionSkipEmpty);
-        icon = getFilenameFromPath(icon);
-      }else if(line.startsWith("Categories=")){
-        categories = line.section("=",1,3,QString::SectionSkipEmpty);
-      }else{
-        //Do nothing - ignore this line
-      }
-    }
-    file.close();
-
-    //Update the data structure from the new file
-    menuStruct.clear();
-    menuStruct << name << genericname << exec << icon << categories;
-    
-    //Save the filename to label the currently saved structure
-    saveMenuFile = filePath;
-  }
-
-  //Return the values saved in the menu structure
-  if(value.toLower()=="name"){
-    return menuStruct[0];
-  }else if(value.toLower()=="genericname"){
-    return menuStruct[1];
-  }else if(value.toLower()=="exec"){
-    return menuStruct[2];
-  }else if(value.toLower()=="icon"){
-    return menuStruct[3];
-  }else if(value.toLower()=="category"){
-    return menuStruct[4];
-  }else{
-    qDebug() << "Error: Invalid menu entry variable";
-    return "";
-  }
-}
-
-QString ModBuild::getDesktopEntryValue(QString filePath, QString value, bool forceRead){
-  if(!filePath.endsWith(".desktop")){
-    qDebug() << "Error: Desired file is not a desktop entry:" << filePath;
-    return "";
-  }
-  if(filePath != saveDesktopFile || forceRead){
-    //Read the new file
-    QFile file(filePath);
-    if(!file.exists()){
-      qDebug() << "Error: Desktop entry file does not exist:"<<filePath;
-      return "";
-    }
-    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
-      qDebug() << "Error: Could not open desktop entry file:"<<filePath;
-      return "";
-    }
-    QTextStream in(&file);
-    QString name, genericname, exec, icon;
-    while(!in.atEnd()){
-      QString line = in.readLine();
-      if(line.startsWith("Name=")){
-        name = line.section("=",1,3,QString::SectionSkipEmpty);
-      }else if(line.startsWith("GenericName=")){
-        genericname = line.section("=",1,3,QString::SectionSkipEmpty);
-      }else if(line.startsWith("Exec=")){
-        exec = line.section("=",1,3,QString::SectionSkipEmpty);
-        exec = getFilenameFromPath(exec);
-      }else if(line.startsWith("Icon=")){
-        icon = line.section("=",1,3,QString::SectionSkipEmpty);
-        icon = getFilenameFromPath(icon);
-      }else{
-        //Do nothing - ignore this line
-      }
-    }
-    file.close();
-
-    //Update the data structure from the new file
-    desktopStruct.clear();
-    desktopStruct << name << genericname << exec << icon;
-    
-    //Save the filename to label the currently saved structure
-    saveDesktopFile = filePath;
-  }
-
-  //Return the values saved in the menu structure
-  if(value.toLower()=="name"){
-    return desktopStruct[0];
-  }else if(value.toLower()=="genericname"){
-    return desktopStruct[1];
-  }else if(value.toLower()=="exec"){
-    return desktopStruct[2];
-  }else if(value.toLower()=="icon"){
-    return desktopStruct[3];
-  }else{
-    qDebug() << "Error: Invalid desktop entry variable";
-    return "";
-  }
-}
-
-QStringList ModBuild::getExternalLinksValues(QString filePath, QString value, bool forceRead){
-  if(!filePath.endsWith("external-links")){
-    qDebug() << "Error: Desired file is not an external-links file:" << filePath;
-    return QStringList("");
-  }
-  if(filePath != saveExternalLinksFile || forceRead){
-    //Read the new file
-    QFile file(filePath);
-    if(!file.exists()){
-      qDebug() << "Error: external-links file does not exist:"<<filePath;
-      return QStringList("");
-    }
-    if(!file.open(QIODevice::ReadOnly | QIODevice::Text)){
-      qDebug() << "Error: Could not open external-links file:"<<filePath;
-      return QStringList("");
-    }
-    QTextStream in(&file);
-    QString original, linkto, types;
-    linksStruct.clear();
-    linksStruct << "" << "" << "";
-    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);
-        if(linksStruct[0].isEmpty()){linksStruct[0] = original; }
-        else{ linksStruct[0].append(":"+original); }
-        if(linksStruct[1].isEmpty()){linksStruct[1] = linkto; }
-        else{ linksStruct[1].append(":"+linkto); }
-        if(linksStruct[2].isEmpty()){linksStruct[2] = types; }
-        else{ linksStruct[2].append(":"+types); }
-      }else{
-        //Do nothing - ignore this line
-      }
-    }
-    file.close();
-
-    //Save the filename to label the currently saved structure
-    saveExternalLinksFile = filePath;
-  }
-
-  //Return the values saved in the menu structure
-  if(value.toLower()=="target"){
-    return linksStruct[0].split(":");
-  }else if(value.toLower()=="linkto"){
-    return linksStruct[1].split(":");
-  }else if(value.toLower()=="action"){
-    return linksStruct[2].split(":");
-  }else{
-    qDebug() << "Error: Invalid external-links variable";
-    return QStringList("");
-  }
-}
-
 QStringList ModBuild::getPortInfo(QString portDir, QString value, bool forceRead){
   QStringList outL;
   //Check the given port location and fill the port info structures

Modified: users/ken/EasyPBI2/modBuild.h
===================================================================
--- users/ken/EasyPBI2/modBuild.h	2012-10-04 19:01:30 UTC (rev 19603)
+++ users/ken/EasyPBI2/modBuild.h	2012-10-04 21:11:14 UTC (rev 19604)
@@ -14,52 +14,58 @@
 	
 private:
   //Internal variables
-  QStringList progStruct, mkStruct, serverStruct, menuStruct, desktopStruct, linksStruct, portStruct;
-  QString modulePath, saveMenuFile, saveDesktopFile, saveMimeFile;
+  QStringList progStruct, mkStruct, serverStruct, menuStruct, desktopStruct, mimeStruct, linksStruct, portStruct;
+  QString modulePath, saveMenuFile, saveDesktopFile, saveMimeFile, savePortDir;
   QStringList currentBins, currentMimeTypes, currentIcons;
   bool isPortPBI, isLocalPBI;
   //Internal functions
   bool isGoodPort(QString, bool);
   QString assignPortMenuCategory(QString);
   int readMakeFile(QString);
-  bool emptyDirectory(QString);
+  static bool emptyDirectory(QString);
+  QString getFilenameFromPath(QString);
 
 public:
   ModBuild(QWidget* parent =0);
   ~ModBuild();
-  //Regular functions
+  // --Regular functions--
+    //Module startup functions
+  bool createNewModule(QString, QString, QString);
+  bool loadModule(QString);
+    //pbi.conf functions
   bool loadPBIconf();
   bool writePBIconf();
-  
+    //desktop entry functions
   bool loadDesktop(QString);
   bool writeDesktop();
   bool removeDesktop();
-
+    //menu entry functions
   bool loadMenu(QString);
   bool writeMenu();
   bool removeMenu();
-
+    //mime type functions
   bool loadMime(QString);
   bool writeMime();
   bool removeMime();
-
+    //external-links functions
   bool loadExternalLinks();
   bool writeExternalLinks();
-  void addExternalLink(QString, QString, QString);
-  void removeExternalLink(QString, QString, QString);
+  void addExternalLink(QString, QString, QStringList);
+  void removeExternalLink(QString, QString);
+    //resources functions
+  bool addResource(QString, QString);
+  bool removeResource(QString);
+   //General purpose functions
+  QString readValue(QString); //get a variable from the module
+  bool writeValue(QString,QString); //set a variable in the module
+  QStringList filesAvailable(QString); //get the available files per category
+  void compressModule();  //package the module for distribution
+  bool createModuleDir();  //Create/overwrite module directory structure
   
-  //Static functions
-  static QString makeModuleDir(QString,QString);
+  // --Static functions--
   static bool createFile(QString,QStringList);
-  static QStringList filesAvailable(QString);
 
-  QString readValue(QString);
-  bool writeValue(QString,QString);
-  bool addResource(QString,QString);
-  void compressModule(QString);
-  QString getFilenameFromPath(QString);
-  QString getMenuEntryValue(QString, QString, bool forceRead = FALSE);
-  QString getDesktopEntryValue(QString, QString, bool forceRead = FALSE);
+
   QStringList getPortInfo(QString, QString, bool forceRead = FALSE);
   
 



More information about the Commits mailing list