[PC-BSD Commits] r15827 - pcbsd-projects/EasyPBI
svn at pcbsd.org
svn at pcbsd.org
Thu Mar 15 20:07:34 PDT 2012
Author: kenmoore
Date: 2012-03-16 03:07:34 +0000 (Fri, 16 Mar 2012)
New Revision: 15827
Modified:
pcbsd-projects/EasyPBI/modBuild.cpp
pcbsd-projects/EasyPBI/modBuild.h
Log:
Add ability for backend to read/return values from desktop/menu entries and external-links files
Modified: pcbsd-projects/EasyPBI/modBuild.cpp
===================================================================
--- pcbsd-projects/EasyPBI/modBuild.cpp 2012-03-15 22:34:18 UTC (rev 15826)
+++ pcbsd-projects/EasyPBI/modBuild.cpp 2012-03-16 03:07:34 UTC (rev 15827)
@@ -8,7 +8,8 @@
5) Make external-links file: makeExternalLinks()
6) Add resources (icons, etc): addResource()
*/
-QStringList progStruct, mkStruct, serverStruct;
+QStringList progStruct, mkStruct, serverStruct, menuStruct, desktopStruct, linksStruct;
+QString saveMenuFile, saveDesktopFile, saveExternalLinksFile;
bool ModBuild::goodStructs(){
if( progStruct.isEmpty() || mkStruct.isEmpty() || serverStruct.isEmpty() ){
@@ -440,3 +441,179 @@
return name;
}
+QString ModBuild::getMenuEntryValue(QString filePath, QString value){
+ if(!filePath.endsWith(".desktop")){
+ qDebug() << "Error: Desired file is not a menu entry:" << filePath;
+ return "";
+ }
+ if(filePath != saveMenuFile){
+ //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){
+ if(!filePath.endsWith(".desktop")){
+ qDebug() << "Error: Desired file is not a desktop entry:" << filePath;
+ return "";
+ }
+ if(filePath != saveDesktopFile){
+ //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 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{
+ qDebug() << "Error: Invalid desktop entry variable";
+ return "";
+ }
+}
+
+QStringList ModBuild::getExternalLinksValues(QString filePath, QString value){
+ if(!filePath.endsWith("external-links")){
+ qDebug() << "Error: Desired file is not an external-links file:" << filePath;
+ return QStringList("");
+ }
+ if(filePath != saveExternalLinksFile){
+ //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();
+ 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("");
+ }
+}
Modified: pcbsd-projects/EasyPBI/modBuild.h
===================================================================
--- pcbsd-projects/EasyPBI/modBuild.h 2012-03-15 22:34:18 UTC (rev 15826)
+++ pcbsd-projects/EasyPBI/modBuild.h 2012-03-16 03:07:34 UTC (rev 15827)
@@ -25,6 +25,9 @@
static bool addResource(QString,QString);
static void compressModule(QString);
static QString getFilenameFromPath(QString);
+ static QString getMenuEntryValue(QString, QString);
+ static QString getDesktopEntryValue(QString, QString);
+ static QStringList getExternalLinksValues(QString, QString);
};
More information about the Commits
mailing list