source: src-qt4/EasyPBI/backend.cpp @ 8eaa615

releng/10.0.1releng/10.0.2releng/10.0.3
Last change on this file since 8eaa615 was 8eaa615, checked in by JoshDW19 <joshms@…>, 7 months ago

changed EasyPBI to adhere to new UI template for PC-BSD utilities. Changed menu text & built in icons.

  • Property mode set to 100644
File size: 3.6 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){
38  QProcess *proc = new QProcess;
39  proc->setProcessChannelMode(QProcess::MergedChannels);
40  proc->start(cmd);
41  while(!proc->waitForFinished(300)){
42    QCoreApplication::processEvents();
43  }
44  QStringList out = QString(proc->readAllStandardOutput()).split("\n"); 
45  delete proc; 
46  return out;
47}
48
49// ====================
50//  PACKAGE DATABASE TOOLS
51// ====================
52QStringList Backend::getPkgList(){
53  //Generate an alphabetized list of all available packages/ports on the repo
54  //format: <category>/<pkgname> (port format)
55  QString cmd = "pkg search -o \"/\"";
56  QStringList result = getCmdOutput(cmd);
57  result.removeAll(""); //get rid of empty items
58  return result;
59}
60
61QStringList Backend::getPkgInfo(QString port){
62  //Function to query the package repository and pull down information about a particular package
63  //Output: <name>, <version>, <website>, <license>
64  QString cmd = "pkg rquery \"%n\\n%v\\n%w\" -e %o "+port; //general info
65  QString cmd2 = "pkg rquery %L -e %o "+port; //License info
66  QStringList info;
67  //Get the general info
68  QStringList out = Backend::getCmdOutput(cmd);
69  for(int i=0; i<3; i++){
70    if(i < out.length()){ info << out[i]; }
71    else{ info << ""; }
72  }
73  //Now get the licence
74  QString lic = Backend::getCmdOutput(cmd2).join(" ");
75  info << lic;
76  return info;
77}
78
79QStringList Backend::getPkgOpts(QString port){
80  //Function to query the package repository and pull down information about a particular package
81  //Output: <option>=<on/off>
82  QString cmd = "pkg rquery \"%Ok=%Ov\" -e %o "+port;
83  QStringList out = Backend::getCmdOutput(cmd);
84  out.removeAll(""); //get rid of empty items
85  return out;
86}
Note: See TracBrowser for help on using the repository browser.