예제 #1
0
        private void OnShowBookMetadataEditor()
        {
            try
            {
                if(!_model.CanEditCopyrightAndLicense)
                {
                    MessageBox.Show(LocalizationManager.GetString("EditTab.CannotChangeCopyright",
                        "Sorry, the copyright and license for this book cannot be changed."));
                    return;
                }

                _model.SaveNow();
                //in case we were in this dialog already and made changes, which haven't found their way out to the Book yet

                var metadata = _model.CurrentBook.GetLicenseMetadata();

                Logger.WriteEvent("Showing Metadata Editor Dialog");
                using(var dlg = new SIL.Windows.Forms.ClearShare.WinFormsUI.MetadataEditorDialog(metadata))
                {
                    dlg.ShowCreator = false;
                    if(DialogResult.OK == dlg.ShowDialog())
                    {
                        Logger.WriteEvent("For BL-3166 Investigation");
                        if(metadata.License == null)
                        {
                            Logger.WriteEvent("old LicenseUrl was null ");
                        }
                        else
                        {
                            Logger.WriteEvent("old LicenseUrl was " + metadata.License.Url);
                        }
                        if(dlg.Metadata.License == null)
                        {
                            Logger.WriteEvent("new LicenseUrl was null ");
                        }
                        else
                        {
                            Logger.WriteEvent("new LicenseUrl: " + dlg.Metadata.License.Url);
                        }

                        _model.ChangeBookLicenseMetaData(dlg.Metadata);
                    }
                }
                Logger.WriteMinorEvent("Emerged from Metadata Editor Dialog");
            }
            catch(Exception error)
            {
                // Throwing this exception is causing it to be swallowed.  It results in the web browser just showing a blank white page, but no
                // message is displayed and no exception is caught by the debugger.
                //#if DEBUG
                //				throw;
                //#endif
                SIL.Reporting.ErrorReport.NotifyUserOfProblem(error,
                    "There was a problem recording your changes to the copyright and license.");
            }
        }
예제 #2
0
        private void OnEditImageMetdata(DomEventArgs ge)
        {
            var imageElement = GetImageNode(ge);
            if(imageElement == null)
                return;
            string fileName = HtmlDom.GetImageElementUrl(imageElement).NotEncoded;

            //enhance: this all could be done without loading the image into memory
            //could just deal with the metadata
            //e.g., var metadata = Metadata.FromFile(path)
            var path = Path.Combine(_model.CurrentBook.FolderPath, fileName);
            PalasoImage imageInfo = null;
            try
            {
                imageInfo = PalasoImage.FromFileRobustly(path);
            }
            catch(TagLib.CorruptFileException e)
            {
                ErrorReport.NotifyUserOfProblem(e,
                    "Bloom ran into a problem while trying to read the metadata portion of this image, " + path);
                return;
            }

            using(imageInfo)
            {
                var hasMetadata = !(imageInfo.Metadata == null || imageInfo.Metadata.IsEmpty);
                if(hasMetadata)
                {
                    // If we have metadata with an official collectionUri or we are translating a shell
                    // just give a summary of the metadata
                    var looksOfficial = !string.IsNullOrEmpty(imageInfo.Metadata.CollectionUri);
                    if(looksOfficial || !_model.CanEditCopyrightAndLicense)
                    {
                        MessageBox.Show(imageInfo.Metadata.GetSummaryParagraph("en"));
                        return;
                    }
                }
                else
                {
                    // If we don't have metadata, but we are translating a shell
                    // don't allow the metadata to be edited
                    if(!_model.CanEditCopyrightAndLicense)
                    {
                        MessageBox.Show(LocalizationManager.GetString("EditTab.CannotChangeCopyright",
                            "Sorry, the copyright and license for this book cannot be changed."));
                        return;
                    }
                }
                // Otherwise, bring up the dialog to edit the metadata
                Logger.WriteEvent("Showing Metadata Editor For Image");
                using(var dlg = new SIL.Windows.Forms.ClearShare.WinFormsUI.MetadataEditorDialog(imageInfo.Metadata))
                {
                    if(DialogResult.OK == dlg.ShowDialog())
                    {
                        imageInfo.Metadata = dlg.Metadata;
                        imageInfo.Metadata.StoreAsExemplar(Metadata.FileCategory.Image);
                        //update so any overlays on the image are brought up to data
                        PageEditingModel.UpdateMetadataAttributesOnImage(new ElementProxy(imageElement), imageInfo);
                        imageElement.Click(); //wake up javascript to update overlays
                        SaveChangedImage(imageElement, imageInfo, "Bloom had a problem updating the image metadata");

                        var answer =
                            MessageBox.Show(
                                LocalizationManager.GetString("EditTab.CopyImageIPMetadataQuestion",
                                    "Copy this information to all other pictures in this book?", "get this after you edit the metadata of an image"),
                                LocalizationManager.GetString("EditTab.TitleOfCopyIPToWholeBooksDialog",
                                    "Picture Intellectual Property Information"), MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                MessageBoxDefaultButton.Button2);
                        if(answer == DialogResult.Yes)
                        {
                            Cursor = Cursors.WaitCursor;
                            try
                            {
                                _model.CopyImageMetadataToWholeBook(dlg.Metadata);
                                // There might be more than one image on this page. Update overlays.
                                _model.RefreshDisplayOfCurrentPage();
                            }
                            catch(Exception e)
                            {
                                ErrorReport.NotifyUserOfProblem(e, "There was a problem copying the metadata to all the images.");
                            }
                            Cursor = Cursors.Default;
                        }
                    }
                }
            }

            //_model.SaveNow();
            //doesn't work: _browser1.WebBrowser.Reload();
        }