This class implements the panel that appears in the Publish tab when the ePUB button is selected. See PublishView.SetupEpubControl for initialization. In addition to the controls created in InitializeComponent, this control normally has a browser displaying the book preview which occupies the remaining space. Since this is not a standard control it is easier to create it and insert it when needed, especially since the PublishView needs to manipulate it.
Inheritance: System.Windows.Forms.UserControl
        public EpubView SetupEpubControl(EpubView view, NavigationIsolator _isolator, Action updateSaveButton)
        {
            if (view == null)
            {
                view = new EpubView();
                _epubPreviewBrowser          = new Browser();
                _epubPreviewBrowser.Isolator = _isolator;
                _epubPreviewBrowser.Dock     = DockStyle.Fill;
                view.Controls.Add(_epubPreviewBrowser);
                // Has to be in front of the panel docked top for Fill to work.
                _epubPreviewBrowser.BringToFront();
            }
            _model.PrepareToStageEpub();
            Action setupElectronicPublicationControlMethod = SetupEpubControlContent;

            HandleAudioSituation(setupElectronicPublicationControlMethod, _epubPreviewBrowser, updateSaveButton);
            updateSaveButton();
            return(view);
        }
Beispiel #2
0
        private void SetupEpubControl()
        {
            Cursor =Cursors.WaitCursor;
            if (_epubPreviewControl == null)
            {
                _epubPreviewControl = new EpubView();
                _epubPreviewBrowser = new Browser();
                _epubPreviewBrowser.Isolator = _isolator;
                _epubPreviewBrowser.Dock = DockStyle.Fill;
                _epubPreviewControl.Controls.Add(_epubPreviewBrowser);
                // Has to be in front of the panel docked top for Fill to work.
                _epubPreviewBrowser.BringToFront();
            }
            _epubPreviewControl.SetBounds(_pdfViewer.Left, _pdfViewer.Top,
                _pdfViewer.Width, _pdfViewer.Height);
            _epubPreviewControl.Dock = _pdfViewer.Dock;
            _epubPreviewControl.Anchor = _pdfViewer.Anchor;
            var saveBackGround = _epubPreviewControl.BackColor; // changed to match parent during next statement
            Controls.Add(_epubPreviewControl);
            _epubPreviewControl.BackColor = saveBackGround; // keep own color.
            // Typically this control is dock.fill. It has to be in front of tableLayoutPanel1 (which is Left) for Fill to work.
            _epubPreviewControl.BringToFront();

            _model.PrepareToStageEpub();
            if (!_publishWithoutAudio && !LameEncoder.IsAvailable() && _model.IsCompressedAudioMissing)
            {
                var fileLocator = _model.BookSelection.CurrentSelection.GetFileLocator();
                var englishMissingLameModulePath = fileLocator.LocateFileWithThrow("ePUB" + Path.DirectorySeparatorChar + "MissingLameModule-en.html");
                // I hesitate to change the definition of BloomFileLocator.BrowserRoot to return absolute paths.  But apparently we need to feed
                // _epubPreviewBrowser an absolute path or it mysteriously tries to open the relative path in an actual browser window, not itself.
                // (See http://issues.bloomlibrary.org/youtrack/issue/BL-3906 if you don't believe this, which I don't except I see it happening.)
                // So ensure that our file path is an absolute filepath.
                var baseFolder = FileLocator.DirectoryOfApplicationOrSolution;
                if (!englishMissingLameModulePath.StartsWith(baseFolder))
                    englishMissingLameModulePath = Path.Combine(baseFolder, englishMissingLameModulePath);
                var localizedMissingLameModulePath = BloomFileLocator.GetBestLocalizedFile(englishMissingLameModulePath);
                _epubPreviewBrowser.Navigate(localizedMissingLameModulePath, false);
                _epubPreviewBrowser.OnBrowserClick += (sender, e) =>
                {
                    var element = (GeckoHtmlElement)(e as DomEventArgs).Target.CastToGeckoElement();
                    if (element.GetAttribute("id") == "proceedWithoutAudio")
                    {
                        _publishWithoutAudio = true;
                        SetupEpubControlContent();
                    }
                };
            }
            else
            {
                SetupEpubControlContent();
            }
            Cursor = Cursors.Default;
        }
        public void SetDisplayMode(PublishModel.DisplayModes displayMode)
        {
            // This is only supposed to be active in one mode of PublishView.
            Browser.SuppressJavaScriptErrors = false;

            if (displayMode != PublishModel.DisplayModes.Upload && _publishControl != null)
            {
                Controls.Remove(_publishControl);
                _publishControl = null;
            }
            if (displayMode != PublishModel.DisplayModes.EPUB && _epubPreviewControl != null && Controls.Contains(_epubPreviewControl))
            {
                Controls.Remove(_epubPreviewControl);
            }
            if (displayMode != PublishModel.DisplayModes.Android && _androidControl != null && Controls.Contains(_androidControl))
            {
                Controls.Remove(_androidControl);

                // disposal of the browser is good but it hides a multitude of sins that we'd rather catch and fix during development. E.g. BL-4901
                if (!ApplicationUpdateSupport.IsDevOrAlpha)
                {
                    _androidControl.Dispose();
                    _androidControl = null;
                }
            }
            if (displayMode != PublishModel.DisplayModes.Upload && displayMode != PublishModel.DisplayModes.EPUB && displayMode != PublishModel.DisplayModes.Android)
            {
                _pdfViewer.Visible = true;
            }
            switch (displayMode)
            {
            case PublishModel.DisplayModes.WaitForUserToChooseSomething:
                _printButton.Enabled = _saveButton.Enabled = false;
                Cursor = Cursors.Default;
                _workingIndicator.Visible = false;
                _pdfViewer.Visible        = false;
                break;

            case PublishModel.DisplayModes.Working:
                _printButton.Enabled     = _saveButton.Enabled = false;
                _workingIndicator.Cursor = Cursors.WaitCursor;
                Cursor = Cursors.WaitCursor;
                _workingIndicator.Visible = true;
                _pdfViewer.Visible        = false;
                break;

            case PublishModel.DisplayModes.ShowPdf:
                Logger.WriteEvent("Entering Publish PDF Screen");
                if (RobustFile.Exists(_model.PdfFilePath))
                {
                    _pdfViewer.Visible        = true;
                    _workingIndicator.Visible = false;
                    Cursor = Cursors.Default;
                    _saveButton.Enabled  = true;
                    _printButton.Enabled = _pdfViewer.ShowPdf(_model.PdfFilePath);
                }
                break;

            case PublishModel.DisplayModes.Printing:
                _simpleAllPagesRadio.Enabled = false;
                _bookletCoverRadio.Enabled   = false;
                _bookletBodyRadio.Enabled    = false;
                _printButton.Enabled         = _saveButton.Enabled = false;
                _workingIndicator.Cursor     = Cursors.WaitCursor;
                Cursor = Cursors.WaitCursor;
                _workingIndicator.Visible = true;
                break;

            case PublishModel.DisplayModes.ResumeAfterPrint:
                _simpleAllPagesRadio.Enabled = true;
                _pdfViewer.Visible           = true;
                _workingIndicator.Visible    = false;
                Cursor = Cursors.Default;
                _saveButton.Enabled  = true;
                _printButton.Enabled = true;
                break;

            case PublishModel.DisplayModes.Upload:
            {
                Logger.WriteEvent("Entering Publish Upload Screen");
                _workingIndicator.Visible = false;                         // If we haven't finished creating the PDF, we will indicate that in the progress window.
                _saveButton.Enabled       = _printButton.Enabled = false;  // Can't print or save in this mode...wouldn't be obvious what would be saved.
                _pdfViewer.Visible        = false;
                Cursor = Cursors.Default;

                if (_publishControl == null)
                {
                    SetupPublishControl();
                }

                break;
            }

            case PublishModel.DisplayModes.EPUB:
            {
                Logger.WriteEvent("Entering Publish Epub Screen");
                // We may reuse this for the process of generating the ePUB staging files. For now, skip it.
                _workingIndicator.Visible = false;
                _printButton.Enabled      = false;                    // don't know how to print an ePUB
                _pdfViewer.Visible        = false;
                Cursor = Cursors.WaitCursor;
                _epubPreviewControl = ElectronicPublishView.SetupEpubControl(_epubPreviewControl, _isolator, () => _saveButton.Enabled = _model.EpubMaker.ReadyToSave());
                _epubPreviewControl.SetBounds(_pdfViewer.Left, _pdfViewer.Top,
                                              _pdfViewer.Width, _pdfViewer.Height);
                _epubPreviewControl.Dock   = _pdfViewer.Dock;
                _epubPreviewControl.Anchor = _pdfViewer.Anchor;
                var saveBackGround = _epubPreviewControl.BackColor;                     // changed to match parent during next statement
                Controls.Add(_epubPreviewControl);
                _epubPreviewControl.BackColor = saveBackGround;                         // keep own color.
                // Typically this control is dock.fill. It has to be in front of tableLayoutPanel1 (which is Left) for Fill to work.
                _epubPreviewControl.BringToFront();
                Cursor = Cursors.Default;

                // We rather mangled the Readium code in the process of cutting away its own navigation
                // and other controls. It produces all kinds of JavaScript errors, but it seems to do
                // what we want. So just suppress the toasts for all of them.
                Browser.SuppressJavaScriptErrors = true;
                break;
            }

            case PublishModel.DisplayModes.Android:
            {
                Logger.WriteEvent("Entering Publish Android Screen");
                _workingIndicator.Visible = false;
                _printButton.Enabled      = false;
                _pdfViewer.Visible        = false;
                Cursor          = Cursors.WaitCursor;
                _androidControl = new AndroidView(_isolator);
                _androidControl.SetBounds(_pdfViewer.Left, _pdfViewer.Top,
                                          _pdfViewer.Width, _pdfViewer.Height);
                _androidControl.Dock   = _pdfViewer.Dock;
                _androidControl.Anchor = _pdfViewer.Anchor;
                var saveBackGround = _androidControl.BackColor;                     // changed to match parent during next statement
                Controls.Add(_androidControl);
                _androidControl.BackColor = saveBackGround;                         // keep own color.
                // Typically this control is dock.fill. It has to be in front of tableLayoutPanel1 (which is Left) for Fill to work.
                _androidControl.BringToFront();
                Cursor = Cursors.Default;

                break;
            }
            }
            UpdateSaveButton();
        }
        public void SetDisplayMode(PublishModel.DisplayModes displayMode)
        {
            if (displayMode != PublishModel.DisplayModes.Upload && _publishControl != null)
            {
                Controls.Remove(_publishControl);
                _publishControl = null;
            }
            if (displayMode != PublishModel.DisplayModes.EPUB && _epubPreviewControl != null && Controls.Contains(_epubPreviewControl))
            {
                Controls.Remove(_epubPreviewControl);
            }
            if (displayMode != PublishModel.DisplayModes.Upload && displayMode != PublishModel.DisplayModes.EPUB)
            {
                _pdfViewer.Visible = true;
            }
            switch (displayMode)
            {
            case PublishModel.DisplayModes.WaitForUserToChooseSomething:
                _printButton.Enabled = _saveButton.Enabled = false;
                Cursor = Cursors.Default;
                _workingIndicator.Visible = false;
                _pdfViewer.Visible        = false;
                break;

            case PublishModel.DisplayModes.Working:
                _printButton.Enabled     = _saveButton.Enabled = false;
                _workingIndicator.Cursor = Cursors.WaitCursor;
                Cursor = Cursors.WaitCursor;
                _workingIndicator.Visible = true;
                _pdfViewer.Visible        = false;
                break;

            case PublishModel.DisplayModes.ShowPdf:
                if (RobustFile.Exists(_model.PdfFilePath))
                {
                    _pdfViewer.Visible        = true;
                    _workingIndicator.Visible = false;
                    Cursor = Cursors.Default;
                    _saveButton.Enabled  = true;
                    _printButton.Enabled = _pdfViewer.ShowPdf(_model.PdfFilePath);
                }
                break;

            case PublishModel.DisplayModes.Printing:
                _simpleAllPagesRadio.Enabled = false;
                _bookletCoverRadio.Enabled   = false;
                _bookletBodyRadio.Enabled    = false;
                _printButton.Enabled         = _saveButton.Enabled = false;
                _workingIndicator.Cursor     = Cursors.WaitCursor;
                Cursor = Cursors.WaitCursor;
                _workingIndicator.Visible = true;
                break;

            case PublishModel.DisplayModes.ResumeAfterPrint:
                _simpleAllPagesRadio.Enabled = true;
                _pdfViewer.Visible           = true;
                _workingIndicator.Visible    = false;
                Cursor = Cursors.Default;
                _saveButton.Enabled  = true;
                _printButton.Enabled = true;
                break;

            case PublishModel.DisplayModes.Upload:
            {
                _workingIndicator.Visible = false;                         // If we haven't finished creating the PDF, we will indicate that in the progress window.
                _saveButton.Enabled       = _printButton.Enabled = false;  // Can't print or save in this mode...wouldn't be obvious what would be saved.
                _pdfViewer.Visible        = false;
                Cursor = Cursors.Default;

                if (_publishControl == null)
                {
                    SetupPublishControl();
                }

                break;
            }

            case PublishModel.DisplayModes.EPUB:
            {
                // We may reuse this for the process of generating the ePUB staging files. For now, skip it.
                _workingIndicator.Visible = false;
                _printButton.Enabled      = false;                    // don't know how to print an ePUB
                _pdfViewer.Visible        = false;
                Cursor = Cursors.WaitCursor;
                _epubPreviewControl = ElectronicPublishView.SetupEpubControl(_epubPreviewControl, _isolator, () => _saveButton.Enabled = _model.EpubMaker.ReadyToSave());
                _saveButton.Enabled = _model.EpubMaker.ReadyToSave();
                _epubPreviewControl.SetBounds(_pdfViewer.Left, _pdfViewer.Top,
                                              _pdfViewer.Width, _pdfViewer.Height);
                _epubPreviewControl.Dock   = _pdfViewer.Dock;
                _epubPreviewControl.Anchor = _pdfViewer.Anchor;
                var saveBackGround = _epubPreviewControl.BackColor;                     // changed to match parent during next statement
                Controls.Add(_epubPreviewControl);
                _epubPreviewControl.BackColor = saveBackGround;                         // keep own color.
                // Typically this control is dock.fill. It has to be in front of tableLayoutPanel1 (which is Left) for Fill to work.
                _epubPreviewControl.BringToFront();
                Cursor = Cursors.Default;

                break;
            }
            }
            UpdateSaveButton();
        }