⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rs_system.cpp

📁 qcad2.05可用于windows和linux的源码
💻 CPP
📖 第 1 页 / 共 3 页
字号:
/****************************************************************************** $Id: rs_system.cpp 2263 2005-03-15 18:48:11Z js $**** Copyright (C) 2001-2003 RibbonSoft. All rights reserved.**** This file is part of the qcadlib Library project.**** This file may be distributed and/or modified under the terms of the** GNU General Public License version 2 as published by the Free Software** Foundation and appearing in the file LICENSE.GPL included in the** packaging of this file.**** Licensees holding valid qcadlib Professional Edition licenses may use ** this file in accordance with the qcadlib Commercial License** Agreement provided with the Software.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.**** See http://www.ribbonsoft.com for further details.**** Contact info@ribbonsoft.com if any conditions of this licensing are** not clear to you.************************************************************************/#include <qapplication.h>#include <qtextcodec.h>#include "rs_settings.h"#include "rs_system.h"#include "rs_regexp.h"#include "rs_translator.h"#include "rs_fileinfo.h"RS_System* RS_System::uniqueInstance = NULL;/** * Initializes the system. * * @param appName Application name (e.g. "QCad II") * @param appVersion Application version (e.g. "1.2.3") * @param appDirName Application directory name used for  *     subdirectories in /usr, /etc ~/. * @param appDir Absolute application directory (e.g. /opt/qcad) *                 defaults to current directory. */void RS_System::init(const RS_String& appName, const RS_String& appVersion,                     const RS_String& appDirName, const RS_String& appDir) {    this->appName = appName;    this->appVersion = appVersion;    this->appDirName = appDirName;    if (appDir=="") {        this->appDir = RS_Dir::currentDirPath();    } else {        this->appDir = appDir;    }    RS_DEBUG->print("RS_System::init: System %s initialized.", appName.latin1());    RS_DEBUG->print("RS_System::init: App dir: %s", appDir.latin1());    initialized = true;    initLanguageList();}/** * Initializes the list of available translations. */void RS_System::initLanguageList() {    RS_DEBUG->print("RS_System::initLanguageList");    RS_StringList lst = getFileList("qm", "qm");    RS_SETTINGS->beginGroup("/Paths");    lst += RS_StringList::split(";",                                RS_SETTINGS->readEntry("/Translations", ""));    RS_SETTINGS->endGroup();    for (RS_StringList::Iterator it = lst.begin();            it!=lst.end();            ++it) {        RS_DEBUG->print("RS_System::initLanguageList: qm file: %s",                        (*it).latin1());        int i1 = (*it).findRev('_');        int i2 = (*it).find('.', i1);        RS_String l = (*it).mid(i1+1, i2-i1-1);        if (languageList.find(l)==languageList.end()) {            RS_DEBUG->print("RS_System::initLanguageList: append language: %s",                            l.latin1());            languageList.append(l);        }    }    RS_DEBUG->print("RS_System::initLanguageList: OK");}/** * Loads a different translation for the application GUI. */void RS_System::loadTranslation(const RS_String& lang, const RS_String& langCmd) {    static RS_Translator* tQt = NULL;    static RS_Translator* tQCad = NULL;    static RS_Translator* tQCadGuiQt = NULL;    static RS_Translator* tQCadActions = NULL;    static RS_Translator* tQCadCmd = NULL;    static RS_Translator* tQCadLib = NULL;    static RS_Translator* tQCadCam = NULL;    static RS_Translator* tQCadProf = NULL;    RS_String langFile;    // search in various directories for translations    RS_StringList lst = getDirectoryList("qm");    RS_SETTINGS->beginGroup("/Paths");    lst += RS_StringList::split(";",                                RS_SETTINGS->readEntry("/Translations", ""));    RS_SETTINGS->endGroup();    for (RS_StringList::Iterator it = lst.begin();            it!=lst.end();            ++it) {        langFile = "qt_" + lang + ".qm";        if (tQt!=NULL) {            qApp->removeTranslator(tQt);            delete tQt;        }        tQt = new QTranslator(0);        if (tQt->load(langFile, (*it))) {            qApp->installTranslator(tQt);        }        langFile = "qcad_" + lang + ".qm";        if (tQCad!=NULL) {            qApp->removeTranslator(tQCad);            delete tQCad;        }        tQCad = new QTranslator(0);        if (tQCad->load(langFile, (*it))) {            qApp->installTranslator(tQCad);        }        langFile = "qcadguiqt_" + lang + ".qm";        if (tQCadGuiQt!=NULL) {            qApp->removeTranslator(tQCadGuiQt);            delete tQCadGuiQt;        }        tQCadGuiQt = new QTranslator(0);        if (tQCadGuiQt->load(langFile, (*it))) {            qApp->installTranslator(tQCadGuiQt);        }        langFile = "qcadactions_" + lang + ".qm";        if (tQCadActions!=NULL) {            qApp->removeTranslator(tQCadActions);            delete tQCadActions;        }        tQCadActions = new QTranslator(0);        if (tQCadActions->load(langFile, (*it))) {            qApp->installTranslator(tQCadActions);        }        langFile = "qcadcmd_" + langCmd + ".qm";        if (tQCadCmd!=NULL) {            qApp->removeTranslator(tQCadCmd);            delete tQCadCmd;        }        tQCadCmd = new QTranslator(0);        if (tQCadCmd->load(langFile, (*it))) {            qApp->installTranslator(tQCadCmd);        }        langFile = "qcadlib_" + lang + ".qm";        if (tQCadLib!=NULL) {            qApp->removeTranslator(tQCadLib);            delete tQCadLib;        }        tQCadLib = new QTranslator(0);        if (tQCadLib->load(langFile, (*it))) {            qApp->installTranslator(tQCadLib);        }		        langFile = "qcadcam_" + lang + ".qm";        if (tQCadLib!=NULL) {            qApp->removeTranslator(tQCadCam);            delete tQCadCam;        }        tQCadCam = new QTranslator(0);        if (tQCadCam->load(langFile, (*it))) {            qApp->installTranslator(tQCadCam);        }        langFile = "qcadprof_" + lang + ".qm";        if (tQCadProf!=NULL) {            qApp->removeTranslator(tQCadProf);            delete tQCadProf;        }        tQCadProf = new QTranslator(0);        if (tQCadProf->load(langFile, (*it))) {            qApp->installTranslator(tQCadProf);        }    }}/** * Checks if the system has been initialized and prints a warning * otherwise to stderr. */bool RS_System::checkInit() {    if (!initialized) {        RS_DEBUG->print(RS_Debug::D_WARNING,			"RS_System::checkInit: System not initialized.\n"            "Use RS_SYSTEM->init(appname, appdirname) to do so.");    }    return initialized;}/** * Creates all given directories in the user's home. */bool RS_System::createHomePath(const QString& p) {    QDir dr;    QStringList dirs = QStringList::split('/', p, false);    QString created = getHomeDir();    for (QStringList::Iterator it=dirs.begin(); it!=dirs.end(); ++it) {        created += QString("/%1").arg(*it);                if (created.isEmpty() || QFileInfo(created).isDir() || dr.mkdir(created, true)) {			RS_DEBUG->print("RS_System::createHomePath: Created directory '%s'", 				created.latin1());    	}        else {			RS_DEBUG->print(RS_Debug::D_ERROR, 				"RS_System::createHomePath: Cannot create directory '%s'", 				created.latin1());            return false;        }    }	return true;}/** * Searches for files in an application shared directory in the given * subdirectory with the given extension. * * @return List of the absolute paths of the files found. */RS_StringList RS_System::getFileList(const RS_String& subDirectory,                                     const RS_String& fileExtension) {    checkInit();    /*RS_StringList dirList;    // Redhat style:    dirList.append("/usr/share/" + appDirName);    // SuSE style:    dirList.append("/usr/X11R6/" + appDirName);    dirList.append("/usr/X11R6/share/" + appDirName);    dirList.append(getHomeDir() + "/." + appDirName);    // Local directory:    dirList.append(".");    //dirList.append(getCurrentDir());    // Debian Doc:    /usr/share/doc/qcad/html/en/    */    RS_StringList dirList = getDirectoryList(subDirectory);    RS_StringList fileList;    RS_String path;    RS_Dir dir;    for (RS_StringList::Iterator it = dirList.begin();            it!=dirList.end();            ++it ) {        //path = RS_String(*it) + "/" + subDirectory;        path = RS_String(*it);        dir = RS_Dir(path);        if (dir.exists() && dir.isReadable()) {            RS_StringList files = dir.entryList("*." + fileExtension);            for (RS_StringList::Iterator it2 = files.begin();                    it2!=files.end();                    it2++) {                fileList += path + "/" + (*it2);            }        }    }    return fileList;}/** * @return List of all directories in subdirectory 'subDirectory' in * all possible QCad directories. */RS_StringList RS_System::getDirectoryList(const RS_String& subDirectory) {    RS_StringList dirList;#ifdef __APPLE__    if (subDirectory!="library") {#endif        //local (application) directory has priority over other dirs:        if (!appDir.isEmpty() && appDir!="/" && appDir!=getHomeDir()) {            dirList.append(appDir + "/" + subDirectory);        }        // Redhat style:        dirList.append("/usr/share/" + appDirName + "/" + subDirectory);        // SuSE style:        dirList.append("/usr/X11R6/" + appDirName + "/" + subDirectory);        dirList.append("/usr/X11R6/share/" + appDirName + "/" + subDirectory);        dirList.append(getHomeDir() + "/." + appDirName + "/" + subDirectory);#ifdef __APPLE__    }#endif#ifdef __APPLE__    // Mac OS X - don't scan for library since this might lead us into the    //  wrong directory tree:    if (!appDir.isEmpty() && appDir!="/" /*&& subDirectory!="library"*/) {        dirList.append(appDir + "/../Resources/" + subDirectory);        dirList.append(appDir + "/../../../" + subDirectory);    }#endif    // Individual directories:    RS_SETTINGS->beginGroup("/Paths");    if (subDirectory=="fonts") {        dirList += RS_StringList::split(RS_RegExp("[;]"),                                        RS_SETTINGS->readEntry("/Fonts", ""));    } else if (subDirectory=="patterns") {        dirList += RS_StringList::split(RS_RegExp("[;]"),                                        RS_SETTINGS->readEntry("/Patterns", ""));    } else if (subDirectory.startsWith("scripts")) {        dirList += RS_StringList::split(RS_RegExp("[;]"),                                        RS_SETTINGS->readEntry("/Scripts", ""));    } else if (subDirectory.startsWith("library")) {        dirList += RS_StringList::split(RS_RegExp("[;]"),                                        RS_SETTINGS->readEntry("/Library", ""));    } else if (subDirectory.startsWith("po")) {        dirList += RS_StringList::split(RS_RegExp("[;]"),                                        RS_SETTINGS->readEntry("/Translations", ""));    }    RS_SETTINGS->endGroup();    RS_StringList ret;    RS_DEBUG->print("RS_System::getDirectoryList: Paths:");    for (RS_StringList::Iterator it = dirList.begin();            it!=dirList.end(); ++it ) {        if (RS_FileInfo(*it).isDir()) {            ret += (*it);            RS_DEBUG->print(*it);        }    }    return ret;}/** * Converts a language string to a symbol (e.g. Deutsch or German to 'de'). *  * Supported languages: http://ftp.ics.uci.edu/pub/ietf/http/related/iso639.txt */RS_String RS_System::languageToSymbol(const RS_String& lang) {    RS_String l = lang.lower();    // don't use else if.. M$ visual wannabe c++ can't handle it    if (l=="afar") {        return "aa";    }    if (l=="abkhazian") {        return "ab";    }    if (l=="afrikaans") {        return "af";    }    if (l=="amharic") {        return "am";    }    if (l=="arabic") {        return "ar";    }    if (l=="assamese") {        return "as";    }    if (l=="aymara") {        return "ay";    }    if (l=="azerbaijani") {        return "az";    }    if (l=="bashkir") {        return "ba";    }    if (l=="byelorussian") {        return "be";    }    if (l=="bulgarian") {        return "bg";    }    if (l=="bihari") {        return "bh";    }    if (l=="bislama") {        return "bi";    }    if (l=="bengali" || l=="bangla") {        return "bn";    }    if (l=="tibetan") {        return "bo";    }    if (l=="breton") {        return "br";    }    if (l=="catalan") {        return "ca";    }    if (l=="corsican") {        return "co";    }    if (l=="czech") {        return "cs";    }    if (l=="welsh") {        return "cy";    }    if (l=="danish") {        return "da";    }    if (l=="german" || l=="deutsch") {        return "de";    }    if (l=="bhutani") {        return "dz";    }    if (l=="greek") {        return "el";    }    if (l=="english") {        return "en";    }    if (l=="esperanto") {        return "eo";    }    if (l=="spanish") {        return "es";    }    if (l=="estonian") {        return "et";    }    if (l=="basque") {        return "eu";    }    if (l=="persian") {        return "fa";    }    if (l=="finnish") {        return "fi";    }    if (l=="fiji") {        return "fj";    }    if (l=="faroese") {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -