Skip to content

Commit

Permalink
Fixed license showing.
Browse files Browse the repository at this point in the history
  • Loading branch information
mtytel committed May 30, 2016
1 parent c0bf872 commit a689ec7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 13 deletions.
11 changes: 11 additions & 0 deletions src/common/load_save.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,17 @@ String LoadSave::getAuthor(var state) {
return "";
}

String LoadSave::getLicense(var state) {
if (!state.isObject())
return "";

DynamicObject* object_state = state.getDynamicObject();
NamedValueSet properties = object_state->getProperties();
if (properties.contains("license"))
return properties["license"];
return "";
}

File LoadSave::getConfigFile() {
PropertiesFile::Options config_options;
config_options.applicationName = "Helm";
Expand Down
1 change: 1 addition & 0 deletions src/common/load_save.h
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class LoadSave {
var state);

static String getAuthor(var state);
static String getLicense(var state);

static File getConfigFile();
static var getConfigVar();
Expand Down
43 changes: 31 additions & 12 deletions src/editor_sections/patch_browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,19 @@ PatchBrowser::PatchBrowser() : Component("patch_browser") {
selectedFilesChanged(banks_model_);
selectedFilesChanged(folders_model_);

license_link_ = new HyperlinkButton("CC-BY", URL("https://creativecommons.org/licenses/by/4.0/"));
license_link_->setFont(Fonts::getInstance()->monospace().withPointHeight(12.0f),
false, Justification::centredLeft);
license_link_->setColour(HyperlinkButton::textColourId, Colour(0xffffd740));
addAndMakeVisible(license_link_);
cc_license_link_ = new HyperlinkButton("CC-BY",
URL("https://creativecommons.org/licenses/by/4.0/"));
cc_license_link_->setFont(Fonts::getInstance()->monospace().withPointHeight(12.0f),
false, Justification::centredLeft);
cc_license_link_->setColour(HyperlinkButton::textColourId, Colour(0xffffd740));
addAndMakeVisible(cc_license_link_);

gpl_license_link_ = new HyperlinkButton("GPL-3",
URL("http://www.gnu.org/licenses/gpl-3.0.en.html"));
gpl_license_link_->setFont(Fonts::getInstance()->monospace().withPointHeight(12.0f),
false, Justification::centredLeft);
gpl_license_link_->setColour(HyperlinkButton::textColourId, Colour(0xffffd740));
addAndMakeVisible(gpl_license_link_);

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

if (isPatchSelected()) {
float data_x = BROWSE_PADDING + 2.0f * getNarrowWidth() + getWideWidth() + 3.0f * BROWSE_PADDING;
float data_x = BROWSE_PADDING + 2.0f * getNarrowWidth() +
getWideWidth() + 3.0f * BROWSE_PADDING;
float division = 90.0f;
float buffer = 20.0f;

Expand Down Expand Up @@ -217,8 +226,10 @@ void PatchBrowser::resized() {

float data_x = start_x + 2.0f * width1 + width2 + 3.0f * BROWSE_PADDING;
float data_widget_buffer_x = 12.0f;
license_link_->setBounds(data_x + 108.0f, BROWSE_PADDING + 160.0f,
200.0f, 20.0f);
cc_license_link_->setBounds(data_x + 108.0f, BROWSE_PADDING + 160.0f,
200.0f, 20.0f);
gpl_license_link_->setBounds(data_x + 108.0f, BROWSE_PADDING + 160.0f,
200.0f, 20.0f);

float button_width = (width2 - 3.0f * data_widget_buffer_x) / 2.0f;
save_as_button_->setBounds(data_x + data_widget_buffer_x, height - 30.0f,
Expand All @@ -235,7 +246,10 @@ void PatchBrowser::visibilityChanged() {
if (isVisible()) {
search_box_->setText("");
search_box_->grabKeyboardFocus();
license_link_->setVisible(isPatchSelected());

bool is_cc = license_.contains("creativecommons");
cc_license_link_->setVisible(isPatchSelected() && is_cc);
gpl_license_link_->setVisible(isPatchSelected() && !is_cc);
}
}

Expand All @@ -253,8 +267,10 @@ void PatchBrowser::selectedFilesChanged(FileListBoxModel* model) {
if (listener_)
listener_->newPatchSelected(patch);
}
else
license_link_->setVisible(false);
else {
cc_license_link_->setVisible(false);
gpl_license_link_->setVisible(false);
}
repaint();
}
}
Expand Down Expand Up @@ -345,9 +361,12 @@ void PatchBrowser::loadFromFile(File& patch) {
parent->setPatchName(patch.getFileNameWithoutExtension());
parent->setFolderName(patch.getParentDirectory().getFileName());
author_ = LoadSave::getAuthor(parsed_json_state);
license_ = LoadSave::getLicense(parsed_json_state);
parent->setAuthor(author_);

license_link_->setVisible(true);
bool is_cc = license_.contains("creativecommons");
cc_license_link_->setVisible(is_cc);
gpl_license_link_->setVisible(!is_cc);
}
}

Expand Down
4 changes: 3 additions & 1 deletion src/editor_sections/patch_browser.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ class PatchBrowser : public Component,
ScopedPointer<TextEditor> search_box_;

PatchSelectedListener* listener_;
ScopedPointer<HyperlinkButton> license_link_;
ScopedPointer<HyperlinkButton> cc_license_link_;
ScopedPointer<HyperlinkButton> gpl_license_link_;

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

String author_;
String license_;

JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PatchBrowser)
};
Expand Down

0 comments on commit a689ec7

Please sign in to comment.