[PC-BSD Commits] r7686 - pcbsd/current/src-qt4/libpcbsd

svn at pcbsd.org svn at pcbsd.org
Fri Oct 1 08:56:15 PDT 2010


Author: kris
Date: 2010-10-01 08:56:15 -0700 (Fri, 01 Oct 2010)
New Revision: 7686

Modified:
   pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
   pcbsd/current/src-qt4/libpcbsd/utils.cpp
Log:

While here, also add set functions to go along with get* stuff



Modified: pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2010-10-01 15:41:01 UTC (rev 7685)
+++ pcbsd/current/src-qt4/libpcbsd/pcbsd-utils.h	2010-10-01 15:56:15 UTC (rev 7686)
@@ -38,6 +38,13 @@
    static QString getProxyType();
    static QString getProxyPort();
    static QString getMasterMirror();
+   static bool setValPBIConf(QString key, QString val);
+   static bool setProxyURL(QString val);
+   static bool setProxyUser(QString val);
+   static bool setProxyPass(QString val);
+   static bool setProxyType(QString val);
+   static bool setProxyPort(QString val);
+   static bool setMasterMirror(QString val);
 };
 
 #endif

Modified: pcbsd/current/src-qt4/libpcbsd/utils.cpp
===================================================================
--- pcbsd/current/src-qt4/libpcbsd/utils.cpp	2010-10-01 15:41:01 UTC (rev 7685)
+++ pcbsd/current/src-qt4/libpcbsd/utils.cpp	2010-10-01 15:56:15 UTC (rev 7686)
@@ -26,6 +26,7 @@
 #include <sys/sysctl.h>
 
 #include <QString>
+#include <QStringList>
 #include <QFile>
 #include <QTextStream>
 
@@ -127,3 +128,67 @@
 QString Utils::getMasterMirror() {
 	return getValFromPBIConf("PBI_MIRROR");
 }
+
+
+bool Utils::setValPBIConf(QString key, QString val)
+{
+  bool savedLine;
+  QStringList pbiConf;
+
+  // Read PBI_ETCCONF into memory
+  QFile confFile(PBI_ETCCONF);
+  if ( confFile.open( QIODevice::ReadOnly ) ) {
+        QTextStream stream( &confFile );
+        QString line;
+        while ( !stream.atEnd() ) {
+	    savedLine = false;
+            line = stream.readLine();
+
+	    // Check Mirror Tag
+	    if ( line.indexOf(key + ": ") == 0 ) {
+	      pbiConf << key + ": " + val;
+	      savedLine = true;
+	    }
+
+	    if (!savedLine )
+	      pbiConf << line;
+        }
+   confFile.close();
+  } else {
+    return false;
+  }
+
+  if ( confFile.open( QIODevice::WriteOnly ) ) {
+        QTextStream stream( &confFile );
+	for (int i = 0; i < pbiConf.count(); ++i)
+		stream << pbiConf.at(i) << "\n";
+	confFile.close();
+	return true;
+  }
+	
+  return false;
+}
+
+bool Utils::setProxyURL(QString val) {
+	return setValPBIConf("PBI_PROXYURL", val);
+}
+
+bool Utils::setProxyUser(QString val) {
+	return setValPBIConf("PBI_PROXYUSER", val);
+}
+
+bool Utils::setProxyPass(QString val) {
+	return setValPBIConf("PBI_PROXYPASS", val);
+}
+
+bool Utils::setProxyType(QString val) {
+	return setValPBIConf("PBI_PROXYTYPE", val);
+}
+
+bool Utils::setProxyPort(QString val) {
+	return setValPBIConf("PBI_PROXYPORT", val);
+}
+
+bool Utils::setMasterMirror(QString val) {
+	return setValPBIConf("PBI_MIRROR", val);
+}



More information about the Commits mailing list