Exemplo n.º 1
0
QVariant UserConfiguration::SetOption(QString key_, QString config_, QVariant default_)
{
    if (this->UserOptions.contains(key_))
    {
        // we must not add 2 same
        throw new Huggle::Exception("This option is already in a list you can't have multiple same keys in it", BOOST_CURRENT_FUNCTION);
    }
    QString d_ = default_.toString();
    QString value = ConfigurationParse(key_, config_, d_);
    HuggleOption *h;
    switch (default_.type())
    {
        case QVariant::Int:
            h = new HuggleOption(key_, value.toInt(), value == d_);
            break;
        case QVariant::Bool:
            h = new HuggleOption(key_, Generic::SafeBool(value), value == d_);
            break;
        default:
            h = new HuggleOption(key_, value, value == d_);
            break;
    }
    this->UserOptions.insert(key_, h);
    return h->GetVariant();
}
QString Configuration::GetSafeUserString(QString key_, QString default_value)
{
    HuggleOption *option = this->GetOption(key_);
    if (option != nullptr)
        return option->GetVariant().toString();
    return default_value;
}
QString Configuration::MakeLocalUserConfig()
{
    /// \todo rewrite to save all SharedConfig only if different from project
    QString configuration_ = "<nowiki>\n";
    configuration_ += "enable:true\n";
    configuration_ += "version:" + HuggleConfiguration->HuggleVersion + "\n\n";
    configuration_ += "speedy-message-title:Speedy deleted\n";
    configuration_ += "report-summary:" + HuggleConfiguration->ProjectConfig_ReportSummary + "\n";
    configuration_ += "prod-message-summary:Notification: Proposed deletion of [[$1]]\n";
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    // huggle 2 options
    configuration_ += "auto-advance:false\n";
    configuration_ += "auto-whitelist:true\n";
    configuration_ += "username-listed:true\n";
    configuration_ += "admin:true\n";
    configuration_ += "patrol-speedy:true\n";
    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    configuration_ += "confirm-multiple:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmMultipleEdits) + "\n";
    configuration_ += "confirm-page:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmPage) + "\n";
    configuration_ += "confirm-same:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmSame) + "\n";
    configuration_ += "confirm-self-revert:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmOnSelfRevs) + "\n";
    configuration_ += "confirm-warned:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmWarned) + "\n";
    configuration_ += "confirm-range:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmRange) + "\n";
    configuration_ += "default-summary:" + HuggleConfiguration->ProjectConfig_DefaultSummary + "\n";
    configuration_ += "// this option will change the behaviour of automatic resolution, be carefull\n";
    configuration_ += "revert-auto-multiple-edits:" + Bool2String(HuggleConfiguration->RevertOnMultipleEdits) + "\n";
    configuration_ += "automatically-resolve-conflicts:" + Bool2String(HuggleConfiguration->UserConfig_AutomaticallyResolveConflicts) + "\n";
    configuration_ += "confirm-page:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmPage) + "\n";
    configuration_ += "confirm-same:" + Bool2String(HuggleConfiguration->ProjectConfig_ConfirmSame) + "\n";
    configuration_ += "software-rollback:" + Bool2String(HuggleConfiguration->EnforceManualSoftwareRollback) + "\n";
    configuration_ += "diff-font-size:" + QString::number(HuggleConfiguration->SystemConfig_FontSize) + "\n";
    configuration_ += "RevertOnMultipleEdits:" + Bool2String(HuggleConfiguration->RevertOnMultipleEdits) + "\n";
    configuration_ += "HistoryLoad:" + Bool2String(HuggleConfiguration->UserConfig_HistoryLoad) + "\n";
    configuration_ += "OnNext:" + QString::number(static_cast<int>(HuggleConfiguration->UserConfig_GoNext)) + "\n";
    configuration_ += "DeleteEditsAfterRevert:" + Bool2String(HuggleConfiguration->UserConfig_DeleteEditsAfterRevert) + "\n";
    configuration_ += "SkipToLastEdit:" + Bool2String(HuggleConfiguration->UserConfig_LastEdit) + "\n";
    configuration_ += "RemoveOldestQueueEdits:" + Bool2String(HuggleConfiguration->UserConfig_RemoveOldQueueEdits) + "\n";
    configuration_ += "TruncateEdits:" + Bool2String(HuggleConfiguration->UserConfig_TruncateEdits) + "\n";
    configuration_ += "TalkpageFreshness:" + QString::number(HuggleConfiguration->UserConfig_TalkPageFreshness) + "\n";
    configuration_ += "DisplayTitle:" + Bool2String(HuggleConfiguration->UserConfig_DisplayTitle) + "\n";
    configuration_ += "// Periodically check if you received new messages and display a notification box if you get them\n";
    configuration_ += "CheckTP:" + Bool2String(HuggleConfiguration->UserConfig_CheckTP) + "\n";
    configuration_ += "ManualWarning:" + Bool2String(HuggleConfiguration->UserConfig_ManualWarning) + "\n";
    configuration_ += "// HAN\n";
    configuration_ += "HAN_DisplayUserTalk:" + Bool2String(HuggleConfiguration->UserConfig_HAN_DisplayUserTalk) + "\n";
    configuration_ += "HAN_DisplayBots:" + Bool2String(HuggleConfiguration->UserConfig_HAN_DisplayBots) + "\n";
    configuration_ += "HAN_DisplayUser:"******"\n";
    configuration_ += "QueueID:" + HuggleConfiguration->UserConfig_QueueID + "\n";
    QStringList kl = HuggleConfiguration->UserOptions.keys();
    foreach (QString item, kl)
    {
        HuggleOption *option = HuggleConfiguration->GetOption(item);
        if (option == nullptr)
        {
            // this must never happen
            throw new Huggle::Exception("Option key was nullptr during store", "QString Configuration::MakeLocalUserConfig()");
        }
        if (!option->IsDefault())
        {
            if (option->GetVariant().type() != QVariant::StringList)
            {
                // in case we modified this item we store it
                configuration_ += item + ":" + option->GetVariant().toString() + "\n";
            } else
            {
                QStringList list = option->GetVariant().toStringList();
                configuration_ += item + ":\n";
                int x = 0;
                while (x < list.count())
                {
                    if (x+1 < list.count())
                    {
                        configuration_ += "    " + list.at(x) + ",\n";
                    } else
                    {
                        configuration_ += "    " + list.at(x) + "\n\n";
                    }
                    x++;
                }
            }
        }
    }