#include "systemapi.h" #include <QString> #include <QStringList> #include <QFile> #include <QDir> #include <QProcess> #include <QDesktopServices> #include <QUrl> #include <QVariant> #include <QVariantMap> #include <QVariantList> #include <QCoreApplication> #include <QLocale> #include <QWebPage> #include <QFileDialog> QVariant SystemApi::readFile(const QString& fname) { QVariantList retList; QFile file(fname); if (!file.open(QIODevice::ReadOnly | QIODevice::Text)) { retList.append("Could not read file '" + fname + "'"); return retList; } while (!file.atEnd()) { QByteArray line = file.readLine(); retList.append(line); } QVariant retVar(retList); return retVar; } bool SystemApi::createFile(const QString& filename, const QString& fileContents) { // add security check QString fName = filename; int last = filename.lastIndexOf(QDir::separator()); //check for a directory pre-pended on the file, and create a directory if needed if( last > -1 ) { //separate the directory and create it QString directory = filename.left(last); QDir dir; dir.mkdir(directory); dir.setCurrent(directory); //separate the file name fName = filename.right(filename.length() - (last + 1)); } QFile file(fName); if (file.open(QFile::ReadWrite)) { QByteArray fileArray = fileContents.toAscii(); file.write(fileArray); file.close(); return true; } return false; } QString SystemApi::startProcess(const QString& program, const QStringList& arguments) { QProcess *process = new QProcess(); process->setProcessChannelMode(QProcess::MergedChannels); process->start(program, arguments); if( !process->waitForStarted() ) return "process failed to start"; if(!process->waitForFinished()) return "process failed to finish"; return process->readAll(); } void SystemApi::startDetached(const QString& program, const QStringList& arguments, const QString& workingDirectory) { QProcess::startDetached(program, arguments, workingDirectory); } // This is useful for opening, e.g., a help page (opens in system default browser) bool SystemApi::openUrlInBrowser(QString filepath) { return QDesktopServices::openUrl(QUrl(filepath)); } QVariant SystemApi::getSystemLocale() { QLocale sl = QLocale::system(); QLocale::Language lang = sl.language(); QString langStr = QLocale::languageToString(lang); QString locStr = sl.name(); QVariantMap retMap; retMap.insert("Locale Name", locStr); retMap.insert("Language Name", langStr); retMap.insert("Language id", lang); return QVariant(retMap); } QVariant SystemApi::ls(const QString& dirname) { return ls(dirname, false); } QVariant SystemApi::ls(const QString& dirname, bool fileInfo) { if (fileInfo) { if (dirname.isEmpty()) { QString returnMessage = "Error: Please include a local directory path."; return returnMessage; } else { QDir dir(dirname); QFileInfoList slist = dir.entryInfoList(); QVariantList outputList; for (int i=2; i < slist.count(); i++) { QVariantMap outputMap; if (slist[i].isDir()) outputMap.insert("type","dir"); else if (slist[i].isFile()) outputMap.insert("type","file"); outputMap.insert("path",slist[i].canonicalFilePath()); outputMap.insert("isHidden",slist[i].isHidden()); outputList.append(outputMap); } return outputList; } } else { QStringList slist; if (dirname.isEmpty()) { QFileInfoList drives = QDir::drives(); for (int i = 0; i < drives.size(); ++i) { QString drive = drives.at(i).absoluteFilePath(); slist.append(drive); } } else { QDir dir(dirname); slist = dir.entryList(); } QVariant retVar(slist); return retVar; } } bool SystemApi::setCurrentDir(const QString& directory) { QDir dir; dir.mkdir(directory);//maybe the directory doesn't exist? Let's make one! What could possibly go wrong? dir.setCurrent(directory); return true; } QString SystemApi::selectDirectory() { return QFileDialog::getExistingDirectory(); } QString SystemApi::selectFile(const QString& caption, const QString& dir) { return QFileDialog::getOpenFileName(0, caption, dir); } QStringList SystemApi::selectFiles(const QString& caption, const QString& dir) { return QFileDialog::getOpenFileNames(0, caption, dir); } QString SystemApi::currentDir() { QDir cdir = QDir::current(); return cdir.absolutePath(); } QString SystemApi::applicationPath() { return QCoreApplication::applicationDirPath(); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#3 | 8115 | David George |
a bunch of changes to the GuiApi - probably bound to change, though, so use at your own risk! beginnings of migrating to an "all windows are created equal" model. (as opposed to a MainWindow) removing the unreliable Qt execution of the .js methods - please include in your HTML (<script type="text/javascript" src="qrc:/js/ClientKitMethods.js"></script>) |
||
#2 | 8107 | David George |
a little cleanup / bug squashing. Not much to see here. createP4 method now added directly to p4 object (rather than through proto) removing some methods that were only used for development debugging/testing |
||
#1 | 8101 | David George |
beginning of _massive_ re-factoring your current build settings will fail create a new project from newly added .pro file (but change its p4api paths to match your old one) look for updated README as soon as Dave agrees that changes are _indeed_ for the best (Changes by Jaimen) |