Ejemplo n.º 1
0
QVariant fSettings::lastItem(QString array, QString key)
{
	int size=beginReadArray(array);
	setArrayIndex(size-1);
	QVariant val=value(key);
	endArray();
	return val;
}
Ejemplo n.º 2
0
QStringList fSettings::toStringList(QString array, QString key)
{
	int size=beginReadArray(array);
	QStringList uList;
	for(int i=0; i<size; i++)
	{
		setArrayIndex(i);
		uList.append(value(key).toString());
	}
	endArray();
	return uList;
}
Ejemplo n.º 3
0
int fSettings::appendValue(QVariant fValue, QString array, QString key, int unique)
{
	if((!unique)||(findValue(fValue,array,key)==-1))
	{
		int size=beginReadArray(array);
		endArray();
		beginWriteArray(array);
		setArrayIndex(size);
		setValue(key, fValue);
		endArray();
		return 1;
	}
	else
		return 0;
}
Ejemplo n.º 4
0
int fSettings::findValue(QVariant fValue, QString array, QString key)
{
	// finds value in current array
	// Why does QSettings not have it?
	int size=beginReadArray(array);
	int ret=-1;
	for(int i=0; i<size; i++)
	{
		setArrayIndex(i);
		if(value(key)==fValue) ret=i;
	}
	endArray();
	return ret;

}
Ejemplo n.º 5
0
void Settings::load()
{
	beginGroup("RecentProjects");

	int size = beginReadArray("Project");
	for (int i = 0; i < size; i++) {
		setArrayIndex(i);
		RecentProject proj;
		proj.path_ = value("Path").toString();
		proj.name_ = value("Name").toString();
		recentProjects_.append(proj);
	}
	endArray();

	endGroup();
}
Ejemplo n.º 6
0
/** get configured values, with reasonable defaults
 */
Preferences::Preferences(QObject *parent) :
    QSettings("SWI-Prolog", "pqConsole", parent)
{
    console_font = value("console_font", QFont("courier", 12)).value<QFont>();
    wrapMode = static_cast<ConsoleEditBase::LineWrapMode>(value("wrapMode", ConsoleEditBase::WidgetWidth).toInt());

    console_out_fore = value("console_out_fore", 0).toInt();
    console_out_back = value("console_out_back", 7).toInt();
    console_inp_fore = value("console_inp_fore", 0).toInt();
    console_inp_back = value("console_inp_back", 15).toInt();

    // selection from SVG named colors
    // see http://www.w3.org/TR/SVG/types.html#ColorKeywords
    static QColor v[] = {
        "black",
        "red",
        "green",
        "brown",
        "blue",
        "magenta",
        "cyan",
        "white",
        "gray",     // 'highlighted' from here
        "magenta",
        "chartreuse",
        "gold",
        "dodgerblue",
        "magenta",
        "lightblue",
        "beige"
    };

    ANSI_sequences.clear();

    beginReadArray("ANSI_sequences");
    for (int i = 0; i < 16; ++i) {
        setArrayIndex(i);
        QColor c = value("color", v[i]).value<QColor>();
	if ( !c.isValid() )	// Play safe if the color is invalid
	    c = v[i];		// Happens on MacOSX 10.11 (El Captain)
	ANSI_sequences.append(c);
    }
    endArray();
}
Ejemplo n.º 7
0
void SettingsSerializer::readSerialized()
{
    QFile f(path);
    if (!f.open(QIODevice::ReadOnly))
    {
        qWarning() << "Couldn't open file";
        return;
    }
    QByteArray data = f.readAll();
    f.close();

    // Decrypt
    if (tox_is_data_encrypted(reinterpret_cast<uint8_t*>(data.data())))
    {
        if (password.isEmpty())
        {
            qCritical() << "The settings file is encrypted, but we don't have a password!";
            return;
        }

        Core* core = Nexus::getCore();

        uint8_t salt[TOX_PASS_SALT_LENGTH];
        tox_get_salt(reinterpret_cast<uint8_t *>(data.data()), salt);
        auto passkey = core->createPasskey(password, salt);

        data = core->decryptData(data, *passkey);
        if (data.isEmpty())
        {
            qCritical() << "Failed to decrypt the settings file";
            return;
        }
    }
    else
    {
        if (!password.isEmpty())
            qWarning() << "We have a password, but the settings file is not encrypted";
    }

    if (memcmp(data.data(), magic, 4))
    {
        qWarning() << "Bad magic!";
        return;
    }
    data = data.mid(4);

    QDataStream stream(&data, QIODevice::ReadOnly);
    stream.setVersion(QDataStream::Qt_5_0);

    while (!stream.atEnd())
    {
        RecordTag tag;
        readStream(stream, tag);
        if (tag == RecordTag::Value)
        {
            QByteArray key;
            QByteArray value;
            readStream(stream, key);
            readStream(stream, value);
            setValue(QString::fromUtf8(key), QVariant(QString::fromUtf8(value)));
        }
        else if (tag == RecordTag::GroupStart)
        {
            QByteArray prefix;
            readStream(stream, prefix);
            beginGroup(QString::fromUtf8(prefix));
        }
        else if (tag == RecordTag::ArrayStart)
        {
            QByteArray prefix;
            readStream(stream, prefix);
            beginReadArray(QString::fromUtf8(prefix));
            QByteArray sizeData;
            readStream(stream, sizeData);
            if (sizeData.isEmpty())
            {
                qWarning("The personal save file is corrupted!");
                return;
            }
            int size = dataToVInt(sizeData);
            arrays[array].size = qMax(size, arrays[array].size);
        }
        else if (tag == RecordTag::ArrayValue)
        {
            QByteArray indexData;
            readStream(stream, indexData);
            if (indexData.isEmpty())
            {
                qWarning("The personal save file is corrupted!");
                return;
            }
            setArrayIndex(dataToVInt(indexData));
            QByteArray key;
            QByteArray value;
            readStream(stream, key);
            readStream(stream, value);
            setValue(QString::fromUtf8(key), QVariant(QString::fromUtf8(value)));
        }
        else if (tag == RecordTag::ArrayEnd)
        {
            endArray();
        }
    }

    group = array = -1;
}
Ejemplo n.º 8
0
Config::Config(QObject* parent)
    : QSettings(ORGNAME, PROGNAME, parent)
{
    keywordsSorted = keywords.keywords.values();
    keywordsSorted.sort();

    languages.insert("English", "en_EN");
    languages.insert("Russian", "ru_RU");

    maxRecentFiles = 9;
    maxHistory 	   = 10;

    beginGroup("General");
    language    	   = value("language", "English").toString();
    recentFiles 	   = value("recentFiles").toStringList();
    openFiles   	   = value("openFiles").toStringList();
    lastFile  		   = value("lastFile").toString();
    mainWindowGeometry = value("mainWindowGeometry").toByteArray();
    mainWindowState    = value("mainWindowState").toByteArray();
    helpWindowGeometry = value("helpWindowGeometry").toByteArray();
    endGroup();

    beginGroup("Editor");
    fontFamily   = value("fontFamily", "Courier New").toString();
    fontSize     = value("fontSize", 12).toInt();
    tabIndents   = value("tabIndents").toBool();
    autoIndent   = value("autoIndent").toBool();
    backUnindent = value("backUnindent").toBool();
    spaceTabs    = value("spaceTabs", true).toBool();
    indentSize   = value("indentSize", 4).toInt();
    tabSize      = value("tabSize", 4).toInt();
    whitespaces  = value("whitespaces").toBool();

    QTextCharFormat fmt; // формат по умолчанию, не изменяется
    fmt.setBackground(QColor(255, 255, 255, 0)) ; // прозрачный белый

    int size = beginReadArray("ColorScheme");

    for (int i = 0; i < size; i++) {
        setArrayIndex(i);

        QString type = value("type").toString();

        colorScheme.insert(type, fmt);
        colorScheme[type].setFontItalic(value("italic").toBool());
        colorScheme[type].setFontWeight(value("weihgt").toInt());
        colorScheme[type].setForeground(value("foreground").value<QColor>());
        colorScheme[type].setBackground(value("background").value<QColor>());
    }

    endArray();

    QHashIterator<QString, QString> it(keywords.keywords);

    while (it.hasNext()) {
        it.next();

        QString keyword = it.value();

        keyword.replace("*", "\\*").replace("$", "\\$");
        patterns.insert(it.key(), QRegExp(tr("\\b%1\\b").arg(keyword)));

        if (!colorScheme.contains(it.key())) // для всех слов пустая схема при size == 0
            colorScheme.insert(it.key(), fmt);
    }

    // 1. для неключевых слов добавить шаблон
    patterns.insert("Parentheses", 	    QRegExp("[\\(\\)\\[\\]]"));
    patterns.insert("Numbers", 			QRegExp("(^|\\s)[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?"));
    patterns.insert("Local Variables",  QRegExp("\\$?\\?[\\w-]+"));
    patterns.insert("Global Variables", QRegExp("\\?\\*[\\w-]+\\*"));

    // 2. настроить схему по умолчанию
    if (!size) {
        colorScheme.insert("Constructs", fmt);
        colorScheme["Constructs"].setFontWeight(QFont::Bold);
        colorScheme["Constructs"].setForeground(Qt::darkBlue);

        colorScheme.insert("Strings", fmt);
        colorScheme["Strings"].setForeground(Qt::darkRed);

        colorScheme.insert("Comments", fmt);
        colorScheme["Comments"].setFontItalic(true);
        colorScheme["Comments"].setForeground(Qt::darkGreen);

        colorScheme.insert("Parentheses", fmt);
        colorScheme["Parentheses"].setFontWeight(QFont::Bold);

        colorScheme.insert("Numbers", fmt);
        colorScheme["Numbers"].setForeground(Qt::darkYellow);

        colorScheme.insert("Local Variables", fmt);
        colorScheme["Local Variables"].setForeground(Qt::darkYellow);

        colorScheme.insert("Global Variables", fmt);
        colorScheme["Global Variables"].setForeground(Qt::darkYellow);

        colorScheme.insert("Text", fmt);
        colorScheme["Text"].setForeground(Qt::black);
        colorScheme["Text"].setBackground(Qt::white);

        colorScheme.insert("Line Numbers", fmt);
        colorScheme["Line Numbers"].setForeground(Qt::gray);
        colorScheme["Line Numbers"].setBackground(QColor(30, 60, 90));
    }

    endGroup(); // Editor

    beginGroup("Sessions");
    leaveOpen       = value("leaveOpen").toBool();
    sessions 	    = value("sessions").toMap();
    sessionSplitter	= value("sessionSplitter").toByteArray();
    endGroup();

    beginGroup("Snippets");
    snippetPath		= value("snippetPath").toString();
    snippetSplitter = value("snippetSplitter").toByteArray();
    endGroup();

    beginGroup("SearchReplace");
    findHistory     = value("findHistory").toStringList();
    replaceHistory  = value("replaceHistory").toStringList();
    matchCase       = value("matchCase").toBool();
    regExp          = value("regExp").toBool();
    allFiles        = value("allFiles").toBool();
    endGroup();
}