public BloomLibraryPublishControl(PublishView parentView, BookTransfer bookTransferrer, LoginDialog login, Book.Book book)
{
_parentView = parentView;
_bookTransferrer = bookTransferrer;
_loginDialog = login;
_book = book;
InitializeComponent();
_originalLoginText = _loginLink.Text; // Before anything might modify it (but after InitializeComponent creates it).
_titleLabel.Text = book.BookInfo.Title;
_progressBox.ShowDetailsMenuItem = true;
_progressBox.ShowCopyToClipboardMenuItem = true;
_progressBox.LinkClicked += _progressBox_LinkClicked;
var metadata = book.GetLicenseMetadata();
// This is usually redundant, but might not be on old books where the license was set before the new
// editing code was written.
book.SetMetadata(metadata);
var license = metadata.License;
if (license == null || (license is NullLicense && string.IsNullOrWhiteSpace(metadata.CopyrightNotice)))
{
// A null license and no copyright indicates they never even opened the ClearShare dialog to choose a license.
_usingCcControls = false;
_usingNotesLabel = false;
_licenseSuggestion.Text = _pleaseSetThis;
_okToUpload = false;
}
else if (license is CreativeCommonsLicense)
{
_creativeCommonsLink.Text = license.Token.ToUpperInvariant();
_usingNotesSuggestion = false;
if (string.IsNullOrWhiteSpace(license.RightsStatement))
{
_licenseNotesLabel.Hide();
}
else
{
_licenseNotesLabel.Text = LocalizationManager.GetString("PublishTab.Upload.AdditionalRequests", "Additional Requests: ") + license.RightsStatement;
}
}
else if (license is NullLicense)
{
_usingCcControls = false;
_licenseNotesLabel.Text = LocalizationManager.GetString("PublishTab.Upload.AllReserved", "All rights reserved (Contact the Copyright holder for any permissions.)");
if (!string.IsNullOrWhiteSpace(license.RightsStatement))
{
_licenseNotesLabel.Text += Environment.NewLine + license.RightsStatement;
}
_licenseSuggestion.Text = LocalizationManager.GetString("PublishTab.Upload.SuggestAssignCC", "Suggestion: Assigning a Creative Commons License makes it easy for you to clearly grant certain permissions to everyone.");
}
else
{
// So far, this means it must be custom license (with non-blank rights...actually, currently, the palaso dialog will not allow a custom license with no rights statement).
_usingCcControls = false;
_licenseNotesLabel.Text = license.RightsStatement;
_licenseSuggestion.Text = LocalizationManager.GetString("PublishTab.Upload.SuggestChangeCC", "Suggestion: Creative Commons Licenses make it much easier for others to use your book, even if they aren't fluent in the language of your custom license.");
}
_copyrightLabel.Text = book.BookInfo.Copyright;
var allLanguages = book.AllLanguages;
foreach (var lang in allLanguages.Keys)
{
var checkBox = new CheckBox();
checkBox.Text = _book.PrettyPrintLanguage(lang);
if (allLanguages[lang])
checkBox.Checked = true;
else
{
checkBox.Text += @" " + LocalizationManager.GetString("PublishTab.Upload.Partial", "(partial)");
}
checkBox.Size = new Size(TextRenderer.MeasureText(checkBox.Text, checkBox.Font).Width + 50, checkBox.Height);
checkBox.Tag = lang;
checkBox.CheckStateChanged += delegate(object sender, EventArgs args)
{
bool someLangChecked = _languagesFlow.Controls.Cast<CheckBox>().Any(b => b.Checked);
_langsLabel.ForeColor = someLangChecked ? Color.Black : Color.Red;
if (_okToUploadDependsOnLangsChecked)
{
_okToUpload = someLangChecked;
UpdateDisplay();
}
};
_languagesFlow.Controls.Add(checkBox);
}
_creditsLabel.Text = book.BookInfo.Credits;
_summaryBox.Text = book.BookInfo.Summary;
try
{
_loginDialog.LogIn(); // See if saved credentials work.
}
catch (Exception e)
{
SIL.Reporting.ErrorReport.NotifyUserOfProblem(e,
LocalizationManager.GetString("PublishTab.Upload.LoginFailure",
"Bloom could not log in to BloomLibrary.org using your saved credentials. Please check your network connection."));
}
_optional1.Left = _summaryBox.Right - _optional1.Width; // right-align these (even if localization changes their width)
RequireValue(_copyrightLabel);
RequireValue(_titleLabel);
if (BookTransfer.UseSandbox)
{
var oldTextWidth = TextRenderer.MeasureText(_uploadButton.Text, _uploadButton.Font).Width;
_uploadButton.Text = LocalizationManager.GetString("PublishTab.Upload.UploadSandbox","Upload Book (to Sandbox)");
var neededWidth = TextRenderer.MeasureText(_uploadButton.Text, _uploadButton.Font).Width;
_uploadButton.Width += neededWidth - oldTextWidth;
}
// After considering all the factors except whether any languages are selected,
// if we can upload at this point, whether we can from here on depends on whether one is checked.
// This test needs to come after evaluating everything else uploading depends on (except login)
_okToUploadDependsOnLangsChecked = _okToUpload;
if (!allLanguages.Keys.Any())
{
_langsLabel.Text += " " + LocalizationManager.GetString("PublishTab.Upload.NoLangsFound", "(None found)");
_langsLabel.ForeColor = Color.Red;
_okToUpload = false;
}
}