config.cpp

来自「奇趣公司比较新的qt/emd版本」· C++ 代码 · 共 431 行 · 第 1/2 页

CPP
431
字号
/******************************************************************************** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved.**** This file is part of the Qt Assistant of the Qt Toolkit.**** This file may be used under the terms of the GNU General Public** License version 2.0 as published by the Free Software Foundation** and appearing in the file LICENSE.GPL included in the packaging of** this file.  Please review the following information to ensure GNU** General Public Licensing requirements will be met:** http://trolltech.com/products/qt/licenses/licensing/opensource/**** If you are unsure which license is appropriate for your use, please** review the following information:** http://trolltech.com/products/qt/licenses/licensing/licensingoverview** or contact the sales department at sales@trolltech.com.**** In addition, as a special exception, Trolltech gives you certain** additional rights. These rights are described in the Trolltech GPL** Exception version 1.0, which can be found at** http://www.trolltech.com/products/qt/gplexception/ and in the file** GPL_EXCEPTION.txt in this package.**** In addition, as a special exception, Trolltech, as the sole copyright** holder for Qt Designer, grants users of the Qt/Eclipse Integration** plug-in the right for the Qt/Eclipse Integration to link to** functionality provided by Qt Designer and its related libraries.**** Trolltech reserves all rights not expressly granted herein.**** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.******************************************************************************/#include "config.h"#include "profile.h"#include "docuparser.h"#include <QApplication>#include <QDesktopWidget>#include <QLibraryInfo>#include <QFont>#include <QFontInfo>#include <QDir>#include <QFile>#include <QFileInfo>#include <QSettings>#include <QtXml>#include <QList>static Config *static_configuration = 0;inline QString getVersionString(){    return QString::number( (QT_VERSION >> 16) & 0xff )        + QLatin1String(".") + QString::number( (QT_VERSION >> 8) & 0xff );}Config::Config()    : profil( 0 ), hideSidebar( false ), rebuildDocs(true){    if( !static_configuration ) {        static_configuration = this;    } else {        qWarning( "Multiple configurations not allowed!" );    }}Config *Config::loadConfig(const QString &profileFileName){    Config *config = new Config();    if (profileFileName.isEmpty()) { // no profile        if (!config->defaultProfileExists()) {            config->profil = Profile::createDefaultProfile();            config->saveProfile(config->profil);        } else {            config->profil = new Profile();        }        config->loadDefaultProfile();        config->load();        return config;    }    QFile file(profileFileName);    if (!file.exists()) {        qWarning( "File does not exist: %s", qPrintable(profileFileName) );        return 0;    }    DocuParser *parser = DocuParser::createParser( profileFileName );    if (!parser) {        qWarning( "Failed to create parser for file: %s", qPrintable(profileFileName) );        return 0;    }    if (parser->parserVersion() < DocuParser::Qt320) {        qWarning( "File does not contain profile information" );        return 0;    }    DocuParser320 *profileParser = static_cast<DocuParser320*>(parser);    parser->parse(&file);    config->profil = profileParser->profile();    if (!config->profil) {        qWarning( "Config::loadConfig(), no profile in: %s", qPrintable(profileFileName) );        return 0;    }    config->profil->setProfileType(Profile::UserProfile);    config->profil->setDocuParser(profileParser);    config->load();    return config;}Config *Config::configuration(){    Q_ASSERT( static_configuration );    return static_configuration;}void Config::load(){    const QString key = getVersionString() + QLatin1String("/");    bool isDefaultProfile = profil->props[QLatin1String("name")] == QLatin1String("default");    const QString pKey = isDefaultProfile ? QString::fromLatin1(QT_VERSION_STR)        : getVersionString();    const QString profkey = pKey + QLatin1String("/Profile/") + profil->props[QLatin1String("name")] + QLatin1String("/");    QSettings settings;    home = profil->props[QLatin1String("startpage")];;    if (home.isEmpty() && isDefaultProfile)        home = QLibraryInfo::location(QLibraryInfo::DocumentationPath) + QLatin1String("/html/index.html");    src = settings.value( profkey + QLatin1String("Source") ).toStringList();    sideBar = settings.value( key + QLatin1String("SideBarPage") ).toInt();    if (qApp->type() != QApplication::Tty)        winGeometry = settings.value(key + QLatin1String("windowGeometry")).toByteArray();    mainWinState = settings.value(key + QLatin1String("MainWindowState")).toByteArray();    pointFntSize = settings.value(key + QLatin1String("FontSize"), qApp->font().pointSizeF()).toDouble();    rebuildDocs = settings.value( key + QLatin1String("RebuildDocDB"), true ).toBool();    profileNames = settings.value( key + QLatin1String("Profile") ).toStringList();        m_fontSettings.windowFont = qVariantValue<QFont>(settings.value(key + QLatin1String("windowfont"), qApp->font()));    m_fontSettings.browserFont = qVariantValue<QFont>(settings.value(key + QLatin1String("browserfont"), qApp->font()));    m_fontSettings.useWindowFont = settings.value(key + QLatin1String("usewindowfont"), false).toBool();    m_fontSettings.useBrowserFont = settings.value(key + QLatin1String("usebrowserfont"), false).toBool();    m_fontSettings.windowWritingSystem = static_cast<QFontDatabase::WritingSystem>(        settings.value(key + QLatin1String("windowwritingsystem"), QFontDatabase::Latin).toInt());    m_fontSettings.browserWritingSystem = static_cast<QFontDatabase::WritingSystem>(        settings.value(key + QLatin1String("browserwritingsystem"), QFontDatabase::Latin).toInt());    m_fontSettings.browserFont.setPointSizeF(pointFntSize);}void Config::save(){    saveSettings();    saveProfile( profil );}void Config::saveSettings(){    const QString key = getVersionString() + QLatin1String("/");    const QString pKey = (profil->props[QLatin1String("name")] == QLatin1String("default"))        ? QString::fromLatin1(QT_VERSION_STR)        : getVersionString();    const QString profkey = pKey + QLatin1String("/Profile/") + profil->props[QLatin1String("name")] + QLatin1String("/");    QSettings settings;    settings.setValue( profkey + QLatin1String("Source"), src );    settings.setValue( key + QLatin1String("SideBarPage"), sideBarPage() );    if (qApp->type() != QApplication::Tty)        settings.setValue(key + QLatin1String("windowGeometry"), winGeometry);    settings.setValue( key + QLatin1String("MainWindowState"), mainWinState );    settings.setValue( key + QLatin1String("FontSize"), pointFntSize);    settings.setValue( key + QLatin1String("RebuildDocDB"), rebuildDocs );    settings.setValue(key + QLatin1String("windowfont"), m_fontSettings.windowFont);    settings.setValue(key + QLatin1String("browserfont"), m_fontSettings.browserFont);    settings.setValue(key + QLatin1String("usewindowfont"), m_fontSettings.useWindowFont);    settings.setValue(key + QLatin1String("usebrowserfont"), m_fontSettings.useBrowserFont);    settings.setValue(key + QLatin1String("windowwritingsystem"), m_fontSettings.windowWritingSystem);    settings.setValue(key + QLatin1String("browserwritingsystem"), m_fontSettings.browserWritingSystem);}#ifdef ASSISTANT_DEBUGstatic void dumpmap( const QMap<QString,QString> &m, const QString &header ){    qDebug( header );    QMap<QString,QString>::ConstIterator it = m.begin();    while (it != m.end()) {        qDebug( "  " + it.key() + ":\t\t" + *it );        ++it;    }}#endifbool Config::defaultProfileExists(){    QSettings settings;    const QString profKey = QLatin1String(QT_VERSION_STR) + QLatin1String("/Profile/default/");    if (settings.contains(profKey + QLatin1String("DocFiles"))        && settings.contains(profKey + QLatin1String("Titles"))        && settings.contains(profKey + QLatin1String("ImageDirs"))) {        QStringList dcfs = settings.value(profKey + QLatin1String("DocFiles") ).toStringList();        foreach (QString file, dcfs) {            if (file == Profile::storableFilePath(file))                return true;

⌨️ 快捷键说明

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