Skip to content

Commit

Permalink
Merge pull request #3757 from offhub/add007-3
Browse files Browse the repository at this point in the history
Update NewBoxWizard.cpp
  • Loading branch information
DavidXanatos authored Mar 27, 2024
2 parents cf57f9f + be77fc6 commit d08bfc8
Showing 1 changed file with 34 additions and 12 deletions.
46 changes: 34 additions & 12 deletions SandboxiePlus/SandMan/Wizards/NewBoxWizard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,14 +181,28 @@ SB_STATUS CNewBoxWizard::TryToCreateBox()
QString templateSettings = theAPI->SbieIniGetEx(templateFullName, "");
QString templateComment = tr("Add your settings after this line.");

if (field("sharedTemplate").toBool()) {
if (templateSettings.isNull()) {
QString templateBase = QString("Tmpl.Title=%1\r\nTmpl.Class=Local\r\nTmpl.Comment=%2\r\n").arg(templateName, templateComment);
theAPI->SbieIniSet(templateFullName, "", templateBase);
}
if (templateSettings.isNull()) {
QString templateBase = QString("Tmpl.Title=%1\r\nTmpl.Class=Local\r\nTmpl.Comment=%2\r\n").arg(templateName, templateComment);
theAPI->SbieIniSet(templateFullName, "", templateBase);
}

if (field("sharedTemplate").toInt() == 1) { // insert template
QString insertValue = templateFullName.replace("Template_", "");
pBox->InsertText("Template", insertValue);
}
else if (field("sharedTemplate").toInt() == 2) { // append to config
QStringList templateSettingsLines = templateSettings.split("\r\n", Qt::SkipEmptyParts);
for (const QString& tLine : templateSettingsLines) {
if (!tLine.startsWith("Enabled=") && !tLine.startsWith("ConfigLevel=") && !tLine.startsWith("Tmpl.") && !tLine.startsWith("#")) { // skip lines
QStringList tParts = tLine.split('=');
if (tParts.size() == 2) {
QString tKey = tParts[0].trimmed();
QString tValue = tParts[1].trimmed();
pBox->AppendText(tKey, tValue);
}
}
}
}

if (!Password.isEmpty())
pBox->ImBoxCreate(ImageSize / 1024, Password);
Expand Down Expand Up @@ -692,12 +706,20 @@ CAdvancedPage::CAdvancedPage(QWidget *parent)
layout->addWidget(pImageProtection, row++, 1, 1, 3);
registerField("imagesProtection", pImageProtection);

QCheckBox* pSharedTemplate = new QCheckBox(tr("Use a shared local template"));
pSharedTemplate->setToolTip(tr("This setting adds a local template to the sandbox configuration so that the settings in that template are shared between sandboxes. However, some settings added to the template may not be reflected in the user interface."
"\nTo change the template's settings, simply locate and edit the 'SharedTemplate' template in the App Templates list under Sandbox Options."
"\nTo disable this template for a sandbox, simply uncheck it in the template list."));
pSharedTemplate->setChecked(theConf->GetBool("BoxDefaults/SharedTemplate", false));
layout->addWidget(pSharedTemplate, row++, 1, 1, 3);
QLabel* pSharedTemplateLbl = new QLabel(tr("Shared template mode"), this);
pSharedTemplateLbl->setToolTip(tr("This setting adds a local template or its settings to the sandbox configuration so that the settings in that template are shared between sandboxes."
"\nHowever, if 'use as a template' option is selected as the sharing mode, some settings may not be reflected in the user interface."
"\nTo change the template's settings, simply locate the 'SharedTemplate' template in the App Templates list under Sandbox Options, then double-click on it to edit it."
"\nTo disable this template for a sandbox, simply uncheck it in the template list."));
layout->addWidget(pSharedTemplateLbl, row, 1);

QComboBox* pSharedTemplate = new QComboBox();
pSharedTemplate->addItem(tr("Disabled"));
pSharedTemplate->addItem(tr("Use as a template"));
pSharedTemplate->addItem(tr("Append to the configuration"));
layout->addWidget(pSharedTemplate, row++, 2);
pSharedTemplate->setCurrentIndex(theConf->GetInt("BoxDefaults/SharedTemplate", 0));
layout->addItem(new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum), 0, 3, 1, 1);
registerField("sharedTemplate", pSharedTemplate);

setLayout(layout);
Expand Down Expand Up @@ -831,7 +853,7 @@ bool CSummaryPage::validatePage()

theConf->SetValue("BoxDefaults/BoxToken", field("boxToken").toBool());
theConf->SetValue("BoxDefaults/ImagesProtection", field("imagesProtection").toBool());
theConf->SetValue("BoxDefaults/SharedTemplate", field("sharedTemplate").toBool());
theConf->SetValue("BoxDefaults/SharedTemplate", field("sharedTemplate").toInt());
}

theConf->SetValue("Options/InstantBoxWizard", m_pSetInstant->isChecked());
Expand Down

0 comments on commit d08bfc8

Please sign in to comment.