Esempio n. 1
0
QVariant fSettings::lastItem(QString array, QString key)
{
	int size=beginReadArray(array);
	setArrayIndex(size-1);
	QVariant val=value(key);
	endArray();
	return val;
}
Esempio 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;
}
Esempio 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;
}
Esempio 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;

}
Esempio 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();
}
Esempio n. 6
0
void Settings::store()
{
	beginGroup("RecentProjects");

	beginWriteArray("Project");
	QLinkedList<RecentProject>::iterator itr;
	int i;
	for (itr = recentProjects_.begin(), i = 0; itr != recentProjects_.end();
	     ++itr, i++) {
		setArrayIndex(i);
		setValue("Path", (*itr).path_);
		setValue("Name", (*itr).name_);
	}
	endArray();

	endGroup();
}
/** 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();
}
/** save configured values
 */
Preferences::~Preferences() {

    #define SV(s) setValue(#s, s)

    SV(console_font);
    SV(wrapMode);

    SV(console_out_fore);
    SV(console_out_back);

    SV(console_inp_fore);
    SV(console_inp_back);

    #undef SV

    beginWriteArray("ANSI_sequences");
    for (int i = 0; i < ANSI_sequences.size(); ++i) {
        setArrayIndex(i);
        setValue("color", ANSI_sequences[i]);
    }
    endArray();
}
Esempio n. 9
0
void ComponentInfo::parseComponentInfoString(QString value)
{
  if (value.isEmpty()) {
    return;
  }
  QStringList list = StringHandler::unparseStrings(value);
  // read the class name
  if (list.size() > 0) {
    mClassName = list.at(0);
  } else {
    return;
  }
  // read the name
  if (list.size() > 1) {
    mName = list.at(1);
  } else {
    return;
  }
  // read the class comment
  if (list.size() > 2) {
    mComment = list.at(2);
  } else {
    return;
  }
  // read the class access
  if (list.size() > 3) {
    mIsProtected = StringHandler::removeFirstLastQuotes(list.at(3)).contains("protected");
  } else {
    return;
  }
  // read the final attribute
  if (list.size() > 4) {
    mIsFinal = list.at(4).contains("true");
  } else {
    return;
  }
  // read the flow attribute
  if (list.size() > 5) {
    mIsFlow = list.at(5).contains("true");
  } else {
    return;
  }
  // read the stream attribute
  if (list.size() > 6) {
    mIsStream = list.at(6).contains("true");
  } else {
    return;
  }
  // read the replaceable attribute
  if (list.size() > 7) {
    mIsReplaceable = list.at(7).contains("true");
  } else {
    return;
  }
  // read the variability attribute
  if (list.size() > 8) {
    QMap<QString, QString>::iterator variability_it;
    for (variability_it = mVariabilityMap.begin(); variability_it != mVariabilityMap.end(); ++variability_it) {
      if (variability_it.key().compare(StringHandler::removeFirstLastQuotes(list.at(8))) == 0) {
        mVariability = variability_it.value();
        break;
      }
    }
  }
  // read the inner attribute
  if (list.size() > 9) {
    mIsInner = list.at(9).contains("inner");
    mIsOuter = list.at(9).contains("outer");
  } else {
    return;
  }
  // read the casuality attribute
  if (list.size() > 10) {
    QMap<QString, QString>::iterator casuality_it;
    for (casuality_it = mCasualityMap.begin(); casuality_it != mCasualityMap.end(); ++casuality_it) {
      if (casuality_it.key().compare(StringHandler::removeFirstLastQuotes(list.at(10))) == 0) {
        mCasuality = casuality_it.value();
        break;
      }
    }
  }
  // read the array index value
  if (list.size() > 11) {
    setArrayIndex(list.at(11));
  }
}
Esempio n. 10
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;
}
Esempio n. 11
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();
}
Esempio n. 12
0
Config::~Config()
{
    beginGroup("General");
    setValue("language",           language);
    setValue("recentFiles",        recentFiles);
    setValue("openFiles",          openFiles);
    setValue("lastFile",           lastFile);
    setValue("mainWindowGeometry", mainWindowGeometry);
    setValue("mainWindowState",    mainWindowState);
    setValue("helpWindowGeometry", helpWindowGeometry);
    endGroup();

    beginGroup("Editor");
    setValue("fontFamily",   fontFamily);
    setValue("fontSize",     fontSize);
    setValue("tabIndents",   tabIndents);
    setValue("autoIndent",   autoIndent);
    setValue("backUnindent", backUnindent);
    setValue("spaceTabs",    spaceTabs);
    setValue("indentSize",   indentSize);
    setValue("tabSize",      tabSize);
    setValue("whitespaces",  whitespaces);

    QMapIterator<QString, QTextCharFormat> it(colorScheme);

    beginWriteArray("ColorScheme");

    int i = 0;

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

        setArrayIndex(i++);
        setValue("type",       it.key());
        setValue("italic",     it.value().font().italic());
        setValue("weihgt",     it.value().font().weight());
        setValue("foreground", it.value().foreground());
        setValue("background", it.value().background());
    }

    endArray();

    endGroup(); // Editor

    beginGroup("Sessions");
    setValue("leaveOpen", 	    leaveOpen);
    setValue("sessions", 		sessions);
    setValue("sessionSplitter", sessionSplitter);
    endGroup();

    beginGroup("Snippets");
    setValue("snippetPath",     snippetPath);
    setValue("snippetSplitter", snippetSplitter);
    endGroup();

    beginGroup("SearchReplace");
    findHistory.sort();
    replaceHistory.sort();
    setValue("findHistory",     findHistory);
    setValue("replaceHistory",  replaceHistory);
    setValue("matchCase", 	    matchCase);
    setValue("regExp",    	    regExp);
    setValue("allFiles",  	    allFiles);
    endGroup();
}