From a689ec793de74642fd7b677d64fc4c38212cde91 Mon Sep 17 00:00:00 2001 From: mtytel Date: Mon, 30 May 2016 15:03:43 -0400 Subject: [PATCH] Fixed license showing. --- src/common/load_save.cpp | 11 +++++++ src/common/load_save.h | 1 + src/editor_sections/patch_browser.cpp | 43 +++++++++++++++++++-------- src/editor_sections/patch_browser.h | 4 ++- 4 files changed, 46 insertions(+), 13 deletions(-) diff --git a/src/common/load_save.cpp b/src/common/load_save.cpp index 57b91cbe9a..af5a616a94 100644 --- a/src/common/load_save.cpp +++ b/src/common/load_save.cpp @@ -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"; diff --git a/src/common/load_save.h b/src/common/load_save.h index 372a2c72dc..54a299a50e 100644 --- a/src/common/load_save.h +++ b/src/common/load_save.h @@ -60,6 +60,7 @@ class LoadSave { var state); static String getAuthor(var state); + static String getLicense(var state); static File getConfigFile(); static var getConfigVar(); diff --git a/src/editor_sections/patch_browser.cpp b/src/editor_sections/patch_browser.cpp index 610d5fa3d7..f15a97cfce 100644 --- a/src/editor_sections/patch_browser.cpp +++ b/src/editor_sections/patch_browser.cpp @@ -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); @@ -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; @@ -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, @@ -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); } } @@ -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(); } } @@ -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); } } diff --git a/src/editor_sections/patch_browser.h b/src/editor_sections/patch_browser.h index df4c56dea9..ab542aa88c 100644 --- a/src/editor_sections/patch_browser.h +++ b/src/editor_sections/patch_browser.h @@ -84,7 +84,8 @@ class PatchBrowser : public Component, ScopedPointer search_box_; PatchSelectedListener* listener_; - ScopedPointer license_link_; + ScopedPointer cc_license_link_; + ScopedPointer gpl_license_link_; SaveSection* save_section_; DeleteSection* delete_section_; @@ -94,6 +95,7 @@ class PatchBrowser : public Component, ScopedPointer hide_button_; String author_; + String license_; JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR(PatchBrowser) };