1
0
Fork 0
mirror of https://github.com/juce-framework/JUCE.git synced 2026-01-14 00:14:18 +00:00

Additions and tweaks to the tracktion_marketplace module to make it more flexible.

This commit is contained in:
jules 2015-04-24 11:28:25 +01:00
parent adf01a6a15
commit 973e530bcf
5 changed files with 51 additions and 22 deletions

View file

@ -68,7 +68,7 @@ public:
if (args.size() != 5)
{
std::cout << "Requires 5 arguments: app-name username user-email machine-numbers private-key" << std::endl
std::cout << "Requires 5 arguments: app-name user-email username machine-numbers private-key" << std::endl
<< " app-name: name of the product being unlocked" << std::endl
<< " user-email: user's email address" << std::endl
<< " username: name of the user. Careful not to allow any spaces!" << std::endl

View file

@ -341,12 +341,8 @@ TracktionMarketplaceStatus::UnlockResult TracktionMarketplaceStatus::handleFaile
return r;
}
TracktionMarketplaceStatus::UnlockResult TracktionMarketplaceStatus::attemptWebserverUnlock (const String& email,
const String& password)
String TracktionMarketplaceStatus::readReplyFromWebserver (const String& email, const String& password)
{
// This method will block while it contacts the server, so you must run it on a background thread!
jassert (! MessageManager::getInstance()->isThisTheMessageThread());
URL url (getServerAuthenticationURL()
.withParameter ("product", getMarketplaceProductID())
.withParameter ("email", email)
@ -356,7 +352,16 @@ TracktionMarketplaceStatus::UnlockResult TracktionMarketplaceStatus::attemptWebs
DBG ("Trying to unlock via URL: " << url.toString (true));
const String reply (url.readEntireTextStream());
return url.readEntireTextStream();
}
TracktionMarketplaceStatus::UnlockResult TracktionMarketplaceStatus::attemptWebserverUnlock (const String& email,
const String& password)
{
// This method will block while it contacts the server, so you must run it on a background thread!
jassert (! MessageManager::getInstance()->isThisTheMessageThread());
String reply (readReplyFromWebserver (email, password));
DBG ("Reply from server: " << reply);

View file

@ -105,6 +105,11 @@ public:
/** Can be overridden if necessary, but by default returns "tracktion.com". */
virtual String getWebsiteName();
/** The default implementation of this method will construct a URL with the default
parameters and read the reply, but for custom webserver set-ups, you may need to
override it to use more exotic methods. */
virtual String readReplyFromWebserver (const String& email, const String& password);
//==============================================================================
// The following methods can be called by your app:

View file

@ -82,15 +82,15 @@ struct TracktionMarketplaceUnlockForm::OverlayComp : public Component,
if (result.errorMessage.isNotEmpty())
{
AlertWindow::showMessageBox (AlertWindow::WarningIcon,
TRANS("Registration Failed"),
result.errorMessage);
AlertWindow::showMessageBoxAsync (AlertWindow::WarningIcon,
TRANS("Registration Failed"),
result.errorMessage);
}
else if (result.informativeMessage.isNotEmpty())
{
AlertWindow::showMessageBox (AlertWindow::InfoIcon,
TRANS("Registration Complete!"),
result.informativeMessage);
AlertWindow::showMessageBoxAsync (AlertWindow::InfoIcon,
TRANS("Registration Complete!"),
result.informativeMessage);
}
else if (result.urlToLaunch.isNotEmpty())
{
@ -99,7 +99,7 @@ struct TracktionMarketplaceUnlockForm::OverlayComp : public Component,
}
if (result.succeeded)
form.cancel();
form.dismiss();
else
delete this;
}
@ -120,7 +120,8 @@ static juce_wchar getDefaultPasswordChar() noexcept
}
TracktionMarketplaceUnlockForm::TracktionMarketplaceUnlockForm (TracktionMarketplaceStatus& s,
const String& userInstructions)
const String& userInstructions,
bool hasCancelButton)
: status (s),
message (String(), userInstructions),
passwordBox (String(), getDefaultPasswordChar()),
@ -139,7 +140,9 @@ TracktionMarketplaceUnlockForm::TracktionMarketplaceUnlockForm (TracktionMarketp
addAndMakeVisible (emailBox);
addAndMakeVisible (passwordBox);
addAndMakeVisible (registerButton);
addAndMakeVisible (cancelButton);
if (hasCancelButton)
addAndMakeVisible (cancelButton);
registerButton.addListener (this);
cancelButton.addListener (this);
@ -174,21 +177,31 @@ void TracktionMarketplaceUnlockForm::resized()
Rectangle<int> buttonArea (r.removeFromBottom (buttonHeight));
registerButton.changeWidthToFitText (buttonHeight);
cancelButton.changeWidthToFitText (buttonHeight);
const int gap = 20;
buttonArea = buttonArea.withSizeKeepingCentre (registerButton.getWidth() + gap + cancelButton.getWidth(), buttonHeight);
buttonArea = buttonArea.withSizeKeepingCentre (registerButton.getWidth()
+ (cancelButton.isVisible() ? gap + cancelButton.getWidth() : 0),
buttonHeight);
registerButton.setBounds (buttonArea.removeFromLeft (registerButton.getWidth()));
buttonArea.removeFromLeft (gap);
cancelButton.setBounds (buttonArea);
r.removeFromBottom (20);
// (force use of a default system font to make sure it has the password blob character)
Font font (Font::getDefaultTypefaceForFont (Font (Font::getDefaultSansSerifFontName(),
Font::getDefaultStyle(),
5.0f)));
const int boxHeight = 24;
passwordBox.setBounds (r.removeFromBottom (boxHeight));
passwordBox.setInputRestrictions (64);
passwordBox.setFont (font);
r.removeFromBottom (30);
emailBox.setBounds (r.removeFromBottom (boxHeight));
passwordBox.setInputRestrictions (256);
emailBox.setInputRestrictions (512);
emailBox.setFont (font);
r.removeFromBottom (30);
@ -225,7 +238,7 @@ void TracktionMarketplaceUnlockForm::buttonClicked (Button* b)
if (b == &registerButton)
attemptRegistration();
else if (b == &cancelButton)
cancel();
dismiss();
}
void TracktionMarketplaceUnlockForm::attemptRegistration()
@ -252,7 +265,7 @@ void TracktionMarketplaceUnlockForm::attemptRegistration()
}
}
void TracktionMarketplaceUnlockForm::cancel()
void TracktionMarketplaceUnlockForm::dismiss()
{
delete this;
}

View file

@ -49,11 +49,18 @@ public:
The userInstructions will be displayed above the email and password boxes.
*/
TracktionMarketplaceUnlockForm (TracktionMarketplaceStatus&,
const String& userInstructions);
const String& userInstructions,
bool hasCancelButton = true);
/** Destructor. */
~TracktionMarketplaceUnlockForm();
/** This is called when the form is dismissed (either cancelled or when registration
succeeds).
By default it will delete this, but you can override it to do other things.
*/
virtual void dismiss();
/** @internal */
void paint (Graphics&) override;
/** @internal */
@ -75,7 +82,6 @@ private:
void buttonClicked (Button*) override;
void attemptRegistration();
void cancel();
void showBubbleMessage (const String&, Component&);
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (TracktionMarketplaceUnlockForm)