[PC-BSD Commits] r16234 - pcbsd/current/src-qt4/EasyPBI
svn at pcbsd.org
svn at pcbsd.org
Tue Apr 3 17:24:17 PDT 2012
Author: kenmoore
Date: 2012-04-04 00:24:17 +0000 (Wed, 04 Apr 2012)
New Revision: 16234
Removed:
pcbsd/current/src-qt4/EasyPBI/pbi.cpp
pcbsd/current/src-qt4/EasyPBI/pbi.h
Modified:
pcbsd/current/src-qt4/EasyPBI/EasyPBI.pro
pcbsd/current/src-qt4/EasyPBI/Makefile
pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp
pcbsd/current/src-qt4/EasyPBI/mainwindow.h
pcbsd/current/src-qt4/EasyPBI/modBuild.cpp
pcbsd/current/src-qt4/EasyPBI/modBuild.h
Log:
Finish up the change-over to a new Module-Builder backend for EasyPBI. New port information functionality is now much more efficient and reliable. Also remove the old pbi.* backend files now to remove a bunch of compilation warnings.
Modified: pcbsd/current/src-qt4/EasyPBI/EasyPBI.pro
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/EasyPBI.pro 2012-04-03 23:45:12 UTC (rev 16233)
+++ pcbsd/current/src-qt4/EasyPBI/EasyPBI.pro 2012-04-04 00:24:17 UTC (rev 16234)
@@ -13,11 +13,9 @@
SOURCES += main.cpp\
mainwindow.cpp \
- pbi.cpp \
modBuild.cpp
HEADERS += mainwindow.h \
- pbi.h \
modBuild.h
FORMS += mainwindow.ui
Modified: pcbsd/current/src-qt4/EasyPBI/Makefile
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/Makefile 2012-04-03 23:45:12 UTC (rev 16233)
+++ pcbsd/current/src-qt4/EasyPBI/Makefile 2012-04-04 00:24:17 UTC (rev 16234)
@@ -1,6 +1,6 @@
#############################################################################
# Makefile for building: /usr/local/bin/EasyPBI
-# Generated by qmake (2.01a) (Qt 4.7.4) on: Tue Mar 20 08:56:19 2012
+# Generated by qmake (2.01a) (Qt 4.7.4) on: Tue Apr 3 19:59:26 2012
# Project: EasyPBI.pro
# Template: app
# Command: /usr/local/bin/qmake-qt4 -o Makefile EasyPBI.pro
@@ -45,12 +45,10 @@
SOURCES = main.cpp \
mainwindow.cpp \
- pbi.cpp \
modBuild.cpp moc_mainwindow.cpp \
qrc_EasyPBI.cpp
OBJECTS = main.o \
mainwindow.o \
- pbi.o \
modBuild.o \
moc_mainwindow.o \
qrc_EasyPBI.o
@@ -159,7 +157,7 @@
dist:
@$(CHK_DIR_EXISTS) .tmp/EasyPBI1.0.0 || $(MKDIR) .tmp/EasyPBI1.0.0
- $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents mainwindow.h pbi.h modBuild.h .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents EasyPBI.qrc .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp pbi.cpp modBuild.cpp .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/EasyPBI1.0.0/ && (cd `dirname .tmp/EasyPBI1.0.0` && $(TAR) EasyPBI1.0.0.tar EasyPBI1.0.0 && $(COMPRESS) EasyPBI1.0.0.tar) && $(MOVE) `dirname .tmp/EasyPBI1.0.0`/EasyPBI1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/EasyPBI1.0.0
+ $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents mainwindow.h modBuild.h .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents EasyPBI.qrc .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents main.cpp mainwindow.cpp modBuild.cpp .tmp/EasyPBI1.0.0/ && $(COPY_FILE) --parents mainwindow.ui .tmp/EasyPBI1.0.0/ && (cd `dirname .tmp/EasyPBI1.0.0` && $(TAR) EasyPBI1.0.0.tar EasyPBI1.0.0 && $(COMPRESS) EasyPBI1.0.0.tar) && $(MOVE) `dirname .tmp/EasyPBI1.0.0`/EasyPBI1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/EasyPBI1.0.0
clean:compiler_clean
@@ -183,8 +181,7 @@
compiler_moc_header_make_all: moc_mainwindow.cpp
compiler_moc_header_clean:
-$(DEL_FILE) moc_mainwindow.cpp
-moc_mainwindow.cpp: pbi.h \
- mainwindow.h
+moc_mainwindow.cpp: mainwindow.h
/usr/local/bin/moc-qt4 $(DEFINES) $(INCPATH) mainwindow.h -o moc_mainwindow.cpp
compiler_rcc_make_all: qrc_EasyPBI.cpp
@@ -223,20 +220,14 @@
####### Compile
-main.o: main.cpp mainwindow.h \
- pbi.h \
- ../config.h
+main.o: main.cpp mainwindow.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp
mainwindow.o: mainwindow.cpp mainwindow.h \
- pbi.h \
ui_mainwindow.h \
modBuild.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o mainwindow.o mainwindow.cpp
-pbi.o: pbi.cpp pbi.h
- $(CXX) -c $(CXXFLAGS) $(INCPATH) -o pbi.o pbi.cpp
-
modBuild.o: modBuild.cpp modBuild.h
$(CXX) -c $(CXXFLAGS) $(INCPATH) -o modBuild.o modBuild.cpp
Modified: pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp 2012-04-03 23:45:12 UTC (rev 16233)
+++ pcbsd/current/src-qt4/EasyPBI/mainwindow.cpp 2012-04-04 00:24:17 UTC (rev 16234)
@@ -35,10 +35,10 @@
MainWindow::~MainWindow()
{
- if (pbi_data)
- {
- Clean_Up(pbi_data, TRUE);
- }
+ // if (pbi_data)
+ // {
+ // Clean_Up(pbi_data, TRUE);
+ // }
//delete ui;
}
@@ -54,7 +54,7 @@
}
void MainWindow::SetupDefaults(){
- pbi_data = NULL;
+ //pbi_data = NULL;
PROGVERSION = "1.2";
PROG_DIR = QDir::homePath() + "/EasyPBI";
PBIOUT_DIR= PROG_DIR + "/PBI";
@@ -115,11 +115,11 @@
void MainWindow::Reset_Form()
{
- if (pbi_data)
- {
- Clean_Up(pbi_data, TRUE);
- pbi_data = NULL;
- }
+ //if (pbi_data)
+ //{
+ //Clean_Up(pbi_data, TRUE);
+ //pbi_data = NULL;
+ //}
ui->port_name->setText("");
ui->port_category->setText("");
ui->author->setText("");
@@ -155,59 +155,39 @@
void MainWindow::on_pushNewModule_clicked()
{
- QString module_path;
- int status;
- char *argv[] = {"-9", "-s", ""};
-
- // clear out any existing module
- if (pbi_data)
- {
- Reset_Form();
- }
-
// check to see if the ports tree exists
if (!Check_For_Ports(true)){return;}
// get new port to work on
- module_path = QFileDialog::getExistingDirectory(this, tr("Select Port"), PORTS_DIR);
+ QString 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."));
- return;
+
+ //get the port information
+ QString port_name = ModBuild::getPortInfo(module_path,"portname").join("");
+ if(port_name.isEmpty() ){
+ //Invalid port directory Selected
+ QMessageBox::warning(this, tr("Error: Invalid Port"), tr("Invalid Port. Please select a valid port directory.\nExample: /usr/ports/archivers/unzip is a valid port directory."));
+ return;
}
- // get the name, arguments
- argv[2] = strdup(qPrintable(module_path));
- Get_Options(pbi_data, 3, argv);
- // confirm port exists
- status = Port_Exists(pbi_data);
- 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);
+ QString author_name = ModBuild::getPortInfo(module_path,"maintainer").join("");
+ QString website = ModBuild::getPortInfo(module_path,"website").join("");
+ QString menu_cat = ModBuild::getPortInfo(module_path,"menucategory").join("");
+
// Display the detected info
- ui->author->setText(pbi_data->author_name);
- ui->port_category->setText(pbi_data->category);
+ ui->author->setText(author_name);
+ ui->port_category->setText(menu_cat);
ui->port_selected->setText(PORT_SELECTED);
ui->icon_path->setText(DEFAULTICON_FILE);
- ui->port_name->setText(pbi_data->port_name);
- ui->website->setText(pbi_data->web_site);
+ ui->port_name->setText(port_name);
+ ui->website->setText(website);
ui->status_bar->setText(tr("Please fill out the above fields and click \"Create Module\"."));
//Enable the GUI Buttons
ui->gui_app->setEnabled(TRUE);
ui->create_button->setEnabled(TRUE);
ui->pushFindIcon->setEnabled(TRUE);
- status = Is_GUI(pbi_data);
+ bool status = TRUE; //Is_GUI(pbi_data);
if (status)
ui->gui_app->setChecked(true);
else
@@ -216,7 +196,7 @@
void MainWindow::on_create_button_clicked()
{
- char *home_dir;
+ /*char *home_dir;
char original_dir[PATH_MAX];
if (! pbi_data)
@@ -242,7 +222,8 @@
home_dir = getenv("HOME");
chdir(home_dir);
chdir("EasyPBI/Modules"); //Already exists (checked before now)
-
+ */
+
// Build Module
bool success = FALSE;
ModBuild::makeStructs(ui->port_name->text(),ui->website->text(),ui->author->text(), \
@@ -285,7 +266,7 @@
void MainWindow::on_port_info_button_clicked()
{
//Check if a port is selected
- if(! pbi_data){
+ if(ui->port_selected->text().isEmpty()){
QMessageBox::warning(this, tr("Error: Port Information"), tr("Please select a port first"));
return;
}
@@ -795,8 +776,8 @@
QStringList MainWindow::getPortBinaries(QString port){
//port: category/portname (example: www/firefox)
QStringList bins;
-
- //Run Jesse's pbi.cpp code to find the binaries for a given port
+ bins = ModBuild::getPortInfo(PORTS_DIR+"/"+port, "binaries");
+ /* //Run Jesse's pbi.cpp code to find the binaries for a given port
// -- create the new data structure
PBI_Struct *new_pbi_data;
char *argv[] = {"-9", "-s", ""};
@@ -832,7 +813,7 @@
current_exe = (BIN_FILE *) current_exe->next;
}
}
-
+*/
return bins;
}
@@ -1015,7 +996,7 @@
ui->listCurrentLinks->clear();
//Make sure each line is displayed in the format [(bin) : (types)]
for(int i=0; i<bins.length(); i++){
- qDebug() << bins << types;
+ //qDebug() << bins << types;
if(!bins[i].isEmpty() && !types[i].isEmpty()){
QString entry = bins[i] + " : " + types[i];
ui->listCurrentLinks->addItem(entry);
Modified: pcbsd/current/src-qt4/EasyPBI/mainwindow.h
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/mainwindow.h 2012-04-03 23:45:12 UTC (rev 16233)
+++ pcbsd/current/src-qt4/EasyPBI/mainwindow.h 2012-04-04 00:24:17 UTC (rev 16234)
@@ -14,7 +14,7 @@
#include <QDir>
#include <QProcess>
#include <QTimer>
-#include "pbi.h"
+//#include "pbi.h"
#ifndef TRUE
#define TRUE 1
@@ -98,7 +98,7 @@
QStringList getPortBinaries(QString);
QString PROG_DIR, PORTS_DIR, PORT_SELECTED, PBIOUT_DIR, MODOUT_DIR, PROGVERSION, PBISETTINGS_FILE, DEFAULTICON_FILE;
QProcess *p;
- PBI_Struct *pbi_data;
+ //PBI_Struct *pbi_data;
};
#endif // MAINWINDOW_H
Modified: pcbsd/current/src-qt4/EasyPBI/modBuild.cpp
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/modBuild.cpp 2012-04-03 23:45:12 UTC (rev 16233)
+++ pcbsd/current/src-qt4/EasyPBI/modBuild.cpp 2012-04-04 00:24:17 UTC (rev 16234)
@@ -8,8 +8,8 @@
5) Make external-links file: makeExternalLinks()
6) Add resources (icons, etc): addResource()
*/
-QStringList progStruct, mkStruct, serverStruct, menuStruct, desktopStruct, linksStruct;
-QString saveMenuFile, saveDesktopFile, saveExternalLinksFile;
+QStringList progStruct, mkStruct, serverStruct, menuStruct, desktopStruct, linksStruct, portStruct;
+QString saveMenuFile, saveDesktopFile, saveExternalLinksFile, savePortDir;
bool ModBuild::goodStructs(){
if( progStruct.isEmpty() || mkStruct.isEmpty() || serverStruct.isEmpty() ){
@@ -617,3 +617,205 @@
return QStringList("");
}
}
+
+QStringList ModBuild::getPortInfo(QString portDir, QString value, bool forceRead){
+ QStringList outL;
+ //Check the given port location and fill the port info structures
+ if( !isGoodPort(portDir, forceRead) ){
+ //Bad port directory given
+ qDebug() << "Invalid port directory given";
+ return outL; //is empty list
+ }
+
+ //Now return the desired port info (fill outL list)
+ if(value.toLower() == "portname"){
+ outL = portStruct[0].split("###",QString::SkipEmptyParts);
+ }else if(value.toLower() == "maintainer"){
+ outL = portStruct[1].split("###",QString::SkipEmptyParts);
+ }else if(value.toLower() == "website"){
+ outL = portStruct[2].split("###",QString::SkipEmptyParts);
+ }else if(value.toLower() == "options"){
+ outL = portStruct[3].split("###",QString::SkipEmptyParts);
+ }else if(value.toLower() == "binaries"){
+ outL = portStruct[4].split("###",QString::SkipEmptyParts);
+ }else if(value.toLower() == "menucategory"){
+ outL = portStruct[5].split("###",QString::SkipEmptyParts);
+ }else{
+ qDebug() << "Invalid port info requested\n - Valid Options: portname, maintainer, website, options, binaries, menucategory";
+ }
+
+ return outL;
+}
+
+bool ModBuild::isGoodPort(QString portDir, bool forceRead){
+ //Remove extra "/" at end of the dir path if needed
+ if(portDir.endsWith("/")){portDir.chop(1);}
+ //Check if it is a valid port directory
+ if( !QFile::exists(portDir+"/Makefile") || !QFile::exists(portDir+"/distinfo") ){
+ qDebug() << "Invalid Port Directory";
+ return FALSE;
+ }
+
+ //Check if we need to re-read the Port info
+ if( forceRead || (portDir != savePortDir) ){
+ //Clear the data structure and initialize it
+ portStruct.clear();
+ portStruct << "" << "" << "" << "" << "" << "";
+
+ qDebug() << "Reading port information for:" << portDir;
+ //Read the Port files and save the info to the data structure
+ QStringList actualopts, bins, listopts; //initialize lists
+ bool variableBinFound = FALSE;
+
+ //Load the Makefile
+ QFile mkfile(portDir+"/Makefile");
+ if(!mkfile.open(QIODevice::ReadOnly) ){
+ return FALSE;
+ }
+ QTextStream mkin(&mkfile);
+ while( !mkin.atEnd() ){
+ QString line = mkin.readLine().simplified();
+ if( line.startsWith("PORTNAME=") ){
+ portStruct[0] = line.section(" ",1,1,QString::SectionSkipEmpty);
+ qDebug() << " - Found portname:" << portStruct[0];
+ }else if( line.startsWith("MAINTAINER=") ){
+ portStruct[1] = line.section(" ",1,1,QString::SectionSkipEmpty);
+ qDebug() << " - Found maintainer:"<< portStruct[1];
+ }else if( line.startsWith("OPTIONS=") ){
+ listopts << line.section(" ",1,1,QString::SectionSkipEmpty);
+ while( line.endsWith("\\")){
+ line = mkin.readLine();
+ listopts << line.section(" ",0,0,QString::SectionSkipEmpty).simplified();
+ }
+ }else if( line.startsWith("WWW=") ){
+ portStruct[2] = line.section(" ",1,1,QString::SectionSkipEmpty);
+ qDebug() << " - Found website:"<< portStruct[2];
+ }else if( line.startsWith("PLIST_FILES") ){ //catch PLIST_FILES= and PLIST_FILES+=
+ QStringList tmpL = line.section(" ",1,60).split(" ",QString::SkipEmptyParts);
+ while( line.endsWith("\\") ){
+ line = mkin.readLine();
+ tmpL.append( line.split(" ",QString::SkipEmptyParts) );
+ }
+ for(int i=0; i<tmpL.length(); i++){
+ if(tmpL[i].endsWith("\\")){ tmpL[i].chop(1); }
+ if( tmpL[i].startsWith("bin/") || tmpL[i].startsWith("sbin/") ){
+ bins << tmpL[i];
+ if(tmpL[i].contains("$")){ variableBinFound=TRUE; }
+ }
+ }
+ }else if( line.startsWith(".if defined(") || line.startsWith(".if !defined(") ){
+ //Get the variable used (we need WITH_* or WITHOUT_*)
+ QString var = line.section("(",1,1).section(")",0,0).simplified();
+ //qDebug() << line << var << var.section("_",1,1);
+ if( var.startsWith("WITH") && listopts.contains( var.section("_",1,1) ) ){
+ actualopts << var;
+ }
+ }else{
+ //do nothing - skip this line
+ }
+ }
+ mkfile.close();
+
+ //Load pkg-descr file
+ if(QFile::exists(portDir+"/pkg-descr")){
+ QFile desfile(portDir+"/pkg-descr");
+ if(!desfile.open(QIODevice::ReadOnly) ){
+ return FALSE;
+ }
+ QTextStream desin(&desfile);
+ while( !desin.atEnd() ){
+ QString line = desin.readLine().simplified();
+ if( line.startsWith("WWW:") ){
+ portStruct[2] = line.section(" ",1,1,QString::SectionSkipEmpty);
+ qDebug() << " - Found website:" << portStruct[2];
+ }
+ }
+ desfile.close();
+ }
+
+ //Load the pkg-plist file
+ if(QFile::exists(portDir+"/pkg-plist")){
+ QFile pfile(portDir+"/pkg-plist");
+ if(!pfile.open(QIODevice::ReadOnly) ){
+ return FALSE;
+ }
+ QTextStream pin(&pfile);
+ while( !pin.atEnd() ){
+ QString line = pin.readLine().simplified();
+ if( line.startsWith("bin/") || line.startsWith("sbin/") ){
+ bins << line;
+ if(line.contains("%%")){ variableBinFound=TRUE; }
+ }
+ }
+ pfile.close();
+ }
+ //Replace any common variables that might be in the bin list if any were found
+ if( variableBinFound ){
+ qDebug() << " - Attempting to fix binary names";
+ QStringList tmpbins = bins;
+ //Try to replace common variables (add more later)
+ tmpbins.replaceInStrings("%%PORTNAME%%",portStruct[0]);
+ tmpbins.replaceInStrings("$PORTNAME",portStruct[0]);
+ tmpbins.replaceInStrings("${PORTNAME}",portStruct[0]);
+
+ //If there are any bins that still have a variable in them, remove it from the list
+ bins.clear();
+ for(int i=0; i<tmpbins.length(); i++){
+ if(!tmpbins[i].contains("%%") && !tmpbins[i].contains("$") ){
+ bins << tmpbins[i];
+ }
+ }
+ }
+ //Assign the program a menu category based on the port category
+ portStruct[5] = assignPortMenuCategory(portDir);
+ qDebug() << " - Assigned menu category:"<<portStruct[5];
+
+ //Save the binaries and options as a string
+ actualopts.removeDuplicates();
+ bins.removeDuplicates();
+ portStruct[3] = actualopts.join("###");
+ portStruct[4] = bins.join("###");
+
+ //For debugging display all info
+ qDebug() << " - Make Options:" << portStruct[3].split("###");
+ qDebug() << " - Binaries:" << portStruct[4].split("###");
+ qDebug() << " - Finished Detecting port information";
+ savePortDir = portDir;
+ } // end of reading the port information and saving it to the structure
+
+ return TRUE;
+}
+
+QString ModBuild::assignPortMenuCategory(QString portDir){
+ //Assign a menu category based upon the port category
+
+ //Get the port category
+ QString pc = portDir.section("ports/",1,1).section("/",0,0);
+ QString mc;
+ //qDebug() << portDir << pc;
+ //Create the port -> menu category conversions
+ QStringList avcat, devcat, edcat, gamecat, gracat,netcat,offcat,setcat,syscat;
+ avcat << "audio"<<"multimedia";
+ devcat << "devel" << "lang" << "java";
+ edcat << "astro" << "biology" << "cad" <<"math"<< "science";
+ gamecat << "games";
+ gracat << "graphics";
+ netcat << "ftp"<<"irc"<<"mail"<<"net"<<"net-im"<<"net-p2p"<<"net-mgmt"<<"www";
+ offcat << "editors" << "finance" << "news" << "textproc";
+ setcat << "accessibility"<<"print";
+ syscat << "sysutils" << "benchmarks" << "emulators" << "ports-mgmt";
+
+ //Assign the menu category
+ if( avcat.contains(pc) ){ mc="AudioVideo"; }
+ else if( devcat.contains(pc) ){ mc="Development"; }
+ else if( edcat.contains(pc) ){ mc="Education"; }
+ else if( gamecat.contains(pc) ){ mc="Game"; }
+ else if( gracat.contains(pc) ){ mc="Graphics"; }
+ else if( netcat.contains(pc) ){ mc="Network"; }
+ else if( offcat.contains(pc) ){ mc="Office"; }
+ else if( setcat.contains(pc) ){ mc="Settings"; }
+ else if( syscat.contains(pc) ){ mc="System"; }
+ else{ mc = "Utility"; }
+
+ return mc;
+}
Modified: pcbsd/current/src-qt4/EasyPBI/modBuild.h
===================================================================
--- pcbsd/current/src-qt4/EasyPBI/modBuild.h 2012-04-03 23:45:12 UTC (rev 16233)
+++ pcbsd/current/src-qt4/EasyPBI/modBuild.h 2012-04-04 00:24:17 UTC (rev 16234)
@@ -10,6 +10,8 @@
private:
static bool goodStructs();
+ static bool isGoodPort(QString, bool);
+ static QString assignPortMenuCategory(QString);
public:
static void makeStructs(QString,QString,QString,QString,QString,QString,QString,QString,QString,bool,QString,bool);
@@ -28,6 +30,8 @@
static QString getMenuEntryValue(QString, QString, bool forceRead = FALSE);
static QString getDesktopEntryValue(QString, QString, bool forceRead = FALSE);
static QStringList getExternalLinksValues(QString, QString, bool forceRead = FALSE);
+ static QStringList getPortInfo(QString, QString, bool forceRead = FALSE);
+
};
More information about the Commits
mailing list