Skip to content
This repository was archived by the owner on Feb 8, 2025. It is now read-only.

Commit a689ec7

Browse files
committed
Fixed license showing.
1 parent c0bf872 commit a689ec7

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

src/common/load_save.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,17 @@ String LoadSave::getAuthor(var state) {
205205
return "";
206206
}
207207

208+
String LoadSave::getLicense(var state) {
209+
if (!state.isObject())
210+
return "";
211+
212+
DynamicObject* object_state = state.getDynamicObject();
213+
NamedValueSet properties = object_state->getProperties();
214+
if (properties.contains("license"))
215+
return properties["license"];
216+
return "";
217+
}
218+
208219
File LoadSave::getConfigFile() {
209220
PropertiesFile::Options config_options;
210221
config_options.applicationName = "Helm";

src/common/load_save.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ class LoadSave {
6060
var state);
6161

6262
static String getAuthor(var state);
63+
static String getLicense(var state);
6364

6465
static File getConfigFile();
6566
static var getConfigVar();

src/editor_sections/patch_browser.cpp

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,19 @@ PatchBrowser::PatchBrowser() : Component("patch_browser") {
122122
selectedFilesChanged(banks_model_);
123123
selectedFilesChanged(folders_model_);
124124

125-
license_link_ = new HyperlinkButton("CC-BY", URL("https://creativecommons.org/licenses/by/4.0/"));
126-
license_link_->setFont(Fonts::getInstance()->monospace().withPointHeight(12.0f),
127-
false, Justification::centredLeft);
128-
license_link_->setColour(HyperlinkButton::textColourId, Colour(0xffffd740));
129-
addAndMakeVisible(license_link_);
125+
cc_license_link_ = new HyperlinkButton("CC-BY",
126+
URL("https://creativecommons.org/licenses/by/4.0/"));
127+
cc_license_link_->setFont(Fonts::getInstance()->monospace().withPointHeight(12.0f),
128+
false, Justification::centredLeft);
129+
cc_license_link_->setColour(HyperlinkButton::textColourId, Colour(0xffffd740));
130+
addAndMakeVisible(cc_license_link_);
131+
132+
gpl_license_link_ = new HyperlinkButton("GPL-3",
133+
URL("http://www.gnu.org/licenses/gpl-3.0.en.html"));
134+
gpl_license_link_->setFont(Fonts::getInstance()->monospace().withPointHeight(12.0f),
135+
false, Justification::centredLeft);
136+
gpl_license_link_->setColour(HyperlinkButton::textColourId, Colour(0xffffd740));
137+
addAndMakeVisible(gpl_license_link_);
130138

131139
save_as_button_ = new TextButton(TRANS("Save As"));
132140
save_as_button_->addListener(this);
@@ -158,7 +166,8 @@ void PatchBrowser::paint(Graphics& g) {
158166
g.fillRect(data_rect);
159167

160168
if (isPatchSelected()) {
161-
float data_x = BROWSE_PADDING + 2.0f * getNarrowWidth() + getWideWidth() + 3.0f * BROWSE_PADDING;
169+
float data_x = BROWSE_PADDING + 2.0f * getNarrowWidth() +
170+
getWideWidth() + 3.0f * BROWSE_PADDING;
162171
float division = 90.0f;
163172
float buffer = 20.0f;
164173

@@ -217,8 +226,10 @@ void PatchBrowser::resized() {
217226

218227
float data_x = start_x + 2.0f * width1 + width2 + 3.0f * BROWSE_PADDING;
219228
float data_widget_buffer_x = 12.0f;
220-
license_link_->setBounds(data_x + 108.0f, BROWSE_PADDING + 160.0f,
221-
200.0f, 20.0f);
229+
cc_license_link_->setBounds(data_x + 108.0f, BROWSE_PADDING + 160.0f,
230+
200.0f, 20.0f);
231+
gpl_license_link_->setBounds(data_x + 108.0f, BROWSE_PADDING + 160.0f,
232+
200.0f, 20.0f);
222233

223234
float button_width = (width2 - 3.0f * data_widget_buffer_x) / 2.0f;
224235
save_as_button_->setBounds(data_x + data_widget_buffer_x, height - 30.0f,
@@ -235,7 +246,10 @@ void PatchBrowser::visibilityChanged() {
235246
if (isVisible()) {
236247
search_box_->setText("");
237248
search_box_->grabKeyboardFocus();
238-
license_link_->setVisible(isPatchSelected());
249+
250+
bool is_cc = license_.contains("creativecommons");
251+
cc_license_link_->setVisible(isPatchSelected() && is_cc);
252+
gpl_license_link_->setVisible(isPatchSelected() && !is_cc);
239253
}
240254
}
241255

@@ -253,8 +267,10 @@ void PatchBrowser::selectedFilesChanged(FileListBoxModel* model) {
253267
if (listener_)
254268
listener_->newPatchSelected(patch);
255269
}
256-
else
257-
license_link_->setVisible(false);
270+
else {
271+
cc_license_link_->setVisible(false);
272+
gpl_license_link_->setVisible(false);
273+
}
258274
repaint();
259275
}
260276
}
@@ -345,9 +361,12 @@ void PatchBrowser::loadFromFile(File& patch) {
345361
parent->setPatchName(patch.getFileNameWithoutExtension());
346362
parent->setFolderName(patch.getParentDirectory().getFileName());
347363
author_ = LoadSave::getAuthor(parsed_json_state);
364+
license_ = LoadSave::getLicense(parsed_json_state);
348365
parent->setAuthor(author_);
349366

350-
license_link_->setVisible(true);
367+
bool is_cc = license_.contains("creativecommons");
368+
cc_license_link_->setVisible(is_cc);
369+
gpl_license_link_->setVisible(!is_cc);
351370
}
352371
}
353372

src/editor_sections/patch_browser.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ class PatchBrowser : public Component,
8484
ScopedPointer<TextEditor> search_box_;
8585

8686
PatchSelectedListener* listener_;
87-
ScopedPointer<HyperlinkButton> license_link_;
87+
ScopedPointer<HyperlinkButton> cc_license_link_;
88+
ScopedPointer<HyperlinkButton> gpl_license_link_;
8889

8990
SaveSection* save_section_;
9091
DeleteSection* delete_section_;
@@ -94,6 +95,7 @@ class PatchBrowser : public Component,
9495
ScopedPointer<TextButton> hide_button_;
9596

9697
String author_;
98+
String license_;
9799

98100
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PatchBrowser)
99101
};

0 commit comments

Comments
 (0)