source: src-qt4/EasyPBI/backend.cpp @ 0c42827

releng/10.0.1releng/10.0.2
Last change on this file since 0c42827 was 0c42827, checked in by Ken Moore <ken@…>, 5 months ago

Update EasyPBI to 2.3:
Changes Include:
Add ability to build from ports directly again.
Add legacy port-build options to the GUI.
Add item to show current package compile-time options.
Add ability to create a new module from either ports/packages.
Fix a bug in the default wrapper script for 10.x PBI's (container path is /usr/local/ now when running)

  • Property mode set to 100644
File size: 4.4 KB
Line 
1#include "backend.h"
2
3QIcon Backend::icon(QString icon){
4  icon = icon.toLower();
5  //Qt embedded resources (http://www.qtcentre.org/wiki/index.php?title=Embedded_resources)
6  QString iconPath = ":/trolltech/styles/commonstyle/images/";
7  if(icon == "new"){ iconPath.append("newdirectory-128.png"); }
8  else if(icon=="load"){ iconPath.append("diropen-128.png"); }
9  else if(icon=="refresh"){ iconPath.append("refresh-32.png"); }
10  else if(icon=="delete"){ iconPath.append("standardbutton-delete-128.png"); }
11  else if(icon=="left"){ iconPath.append("left-128.png"); }
12  else if(icon=="right"){ iconPath.append("right-128.png"); }
13  else if(icon=="up"){ iconPath.append("up-128.png"); }
14  else if(icon=="down"){ iconPath.append("down-128.png"); }
15  else if(icon=="save"){ iconPath.append("standardbutton-save-32.png"); }
16  else if(icon=="help"){ iconPath.append("standardbutton-help-32.png"); }
17  else if(icon=="open"){ iconPath.append("standardbutton-open-32.png"); }
18  else if(icon=="file"){ iconPath.append("file-32.png"); }
19  else if(icon=="trash"){ iconPath.append("trash-32.png"); }
20  else if(icon=="clear"){ iconPath.append("standardbutton-clear-128.png"); }
21  else if(icon=="start"){ iconPath.append("media-play-32.png"); }
22  else if(icon=="stop"){ iconPath.append("media-stop-32.png"); }
23  //EasyPBI embedded resources (EasyPBI.qrc)
24  else if(icon=="close"){ iconPath = ":/png/icons/window-close.png"; }
25  else if(icon=="easypbi"){ iconPath = ":/png/icons/EasyPBIicon.png"; }
26  else if(icon=="freebsd"){ iconPath = ":/png/icons/freebsd.png"; }
27  else if(icon=="pcbsd"){iconPath = ":/png/icons/pcbsd.png"; }
28  else if(icon=="config"){iconPath = ":/png/icons/config.png"; }
29  //onebit iconset icons (http://www.iconfinder.com/search/?q=iconset%3Aonebit)
30  else if(icon=="plus"){iconPath = ":/png/icons/plus.png"; }
31  else if(icon=="minus"){iconPath = ":/png/icons/minus.png"; }
32  else{ iconPath.clear(); }
33       
34  return QIcon(iconPath);
35}
36
37QStringList Backend::getCmdOutput(QString cmd, QString dir){
38  QProcess *proc = new QProcess;
39  proc->setProcessChannelMode(QProcess::MergedChannels);
40  if( !dir.isEmpty() && QFile::exists(dir) ){ proc->setWorkingDirectory(dir); }
41  proc->start(cmd);
42  while(!proc->waitForFinished(300)){
43    QCoreApplication::processEvents();
44  }
45  QStringList out = QString(proc->readAllStandardOutput()).split("\n"); 
46  delete proc; 
47  return out;
48}
49
50// ====================
51//  PACKAGE DATABASE TOOLS
52// ====================
53QStringList Backend::getPkgList(){
54  //Generate an alphabetized list of all available packages/ports on the repo
55  //format: <category>/<pkgname> (port format)
56  QString cmd = "pkg search -o \"/\"";
57  QStringList result = getCmdOutput(cmd);
58  result.removeAll(""); //get rid of empty items
59  return result;
60}
61
62QStringList Backend::getPkgInfo(QString port){
63  //Function to query the package repository and pull down information about a particular package
64  //Output: <name>, <version>, <website>, <license>
65  QString cmd = "pkg rquery \"%n\\n%v\\n%w\" -e %o "+port; //general info
66  QString cmd2 = "pkg rquery %L -e %o "+port; //License info
67  QStringList info;
68  //Get the general info
69  QStringList out = Backend::getCmdOutput(cmd);
70  for(int i=0; i<3; i++){
71    if(i < out.length()){ info << out[i]; }
72    else{ info << ""; }
73  }
74  //Now get the licence
75  QString lic = Backend::getCmdOutput(cmd2).join(" ");
76  info << lic;
77  return info;
78}
79
80QStringList Backend::getPkgOpts(QString port){
81  //Function to query the package repository and pull down information about a particular package
82  //Output: <option>=<on/off>
83  QString cmd = "pkg rquery \"%Ok=%Ov\" -e %o "+port;
84  QStringList out = Backend::getCmdOutput(cmd);
85  out.removeAll(""); //get rid of empty items
86  return out;
87}
88//================
89//       PORT TOOLS
90// ================
91QStringList Backend::getPortOpts(QString portPath){
92  //output format: <option>:::<on/off>:::<description>
93  QString cmd = "make showconfig";
94  QStringList list = Backend::getCmdOutput(cmd, portPath);
95  //Now parse the output
96  QStringList out;
97    for(int i=0; i<list.length(); i++){
98      if(list[i].startsWith("===>")){ continue; } //comment
99      else if(list[i].simplified().isEmpty()){ continue; }
100      QString opt = list[i].section("=",0,0).simplified();
101      QString val = list[i].section(":",0,0).section("=",1,1).simplified();
102      QString desc = list[i].section(":",1,50).simplified();
103      out << opt+":::"+val+":::"+desc;
104    }
105  return out;
106}
Note: See TracBrowser for help on using the repository browser.