Exemplo n.º 1
0
 private void RefreshOneThumbnail(Book.BookInfo bookInfo, Image image)
 {
     // The arguments here are not currently used (method signature is legacy),
     // but may be useful if we optimize.
     // optimize: I think this will reload all of them
     _webSocketServer.SendString("bookImage", "reload", bookInfo.Id);
 }
Exemplo n.º 2
0
        private void RefreshOneThumbnail(Book.BookInfo bookInfo, Image image)
        {
            if (IsDisposed)
            {
                return;
            }
            try
            {
                var imageIndex = _bookThumbnails.Images.IndexOfKey(bookInfo.Id);
                if (imageIndex > -1)
                {
                    _bookThumbnails.Images[imageIndex] = image;
                    var button = FindBookButton(bookInfo);
                    button.Image = image;
                }
            }

            catch (Exception e)
            {
                Logger.WriteEvent("Error refreshing thumbnail. " + e.Message);
#if DEBUG
                throw;
#endif
            }
        }
Exemplo n.º 3
0
        private void AddOneBook(Book.BookInfo bookInfo, FlowLayoutPanel flowLayoutPanel)
        {
            var button = new Button()
            {
                Size = new Size(90, 110)
            };

            button.Text = ShortenTitleIfNeeded(bookInfo.QuickTitleUserDisplay);
            button.TextImageRelation         = TextImageRelation.ImageAboveText;
            button.ImageAlign                = ContentAlignment.TopCenter;
            button.TextAlign                 = ContentAlignment.BottomCenter;
            button.FlatStyle                 = FlatStyle.Flat;
            button.ForeColor                 = Palette.TextAgainstDarkBackground;
            button.FlatAppearance.BorderSize = 0;
            button.ContextMenuStrip          = _bookContextMenu;
            button.MouseDown                += OnClickBook; //we need this for right-click menu selection, which needs to 1st select the book
            //doesn't work: item.DoubleClick += (sender,arg)=>_model.DoubleClickedBook();

            button.Font = bookInfo.IsEditable ? _editableBookFont : _collectionBookFont;


            button.Tag = bookInfo;


            Image thumbnail = Resources.PagePlaceHolder;;

            _bookThumbnails.Images.Add(bookInfo.Id, thumbnail);
            button.ImageIndex = _bookThumbnails.Images.Count - 1;
            flowLayoutPanel.Controls.Add(button);

            Image img;

            //review: we could do this at idle time, too:
            if (bookInfo.TryGetPremadeThumbnail(out img))
            {
                RefreshOneThumbnail(bookInfo, img);
            }
            else
            {
                //show this one for now, in the background someone will do the slow work of getting us a better one
                RefreshOneThumbnail(bookInfo, Resources.placeHolderBookThumbnail);
                //hack to signal that we need to make a real one when get a chance
                button.ImageIndex = 999;
            }
            _buttonsNeedingSlowUpdate.Enqueue(button);

//			bookInfo.GetThumbNailOfBookCoverAsync(bookInfo.Type != Book.Book.BookType.Publication,
//				                                  image => RefreshOneThumbnail(bookInfo, image),
//												  error=> RefreshOneThumbnail(bookInfo, Resources.Error70x70));
        }
Exemplo n.º 4
0
        private void HandleThumbnailerErrror(Book.BookInfo bookInfo, Exception error)
        {
            string path = Path.Combine(bookInfo.FolderPath, "thumbnail.png");

            try
            {
                Resources.Error70x70.Save(@path, ImageFormat.Png);
            }
            catch (Exception e)
            {
                Logger.WriteError("Could not save error icon for book", e);
            }

            RefreshOneThumbnail(bookInfo, Resources.Error70x70);
        }
Exemplo n.º 5
0
        public void DeleteBook(Book.BookInfo bookInfo)
        {
            var didDelete = ConfirmRecycleDialog.Recycle(bookInfo.FolderPath);

            if (!didDelete)
            {
                return;
            }

            Logger.WriteEvent("After BookStorage.DeleteBook({0})", bookInfo.FolderPath);
            HandleBookDeletedFromCollection(bookInfo.FolderPath);
            if (_bookSelection != null)
            {
                _bookSelection.SelectBook(null);
            }
        }
Exemplo n.º 6
0
        public void DeleteBook(Book.BookInfo bookInfo)
        {
            var didDelete = ConfirmRecycleDialog.Recycle(bookInfo.FolderPath);

            if (!didDelete)
            {
                return;
            }

            Logger.WriteEvent("After BookStorage.DeleteBook({0})", bookInfo.FolderPath);
            //Debug.Assert(_bookInfos.Contains(bookInfo)); this will occur if we delete a book from the BloomLibrary section
            _bookInfos.Remove(bookInfo);

            if (CollectionChanged != null)
            {
                CollectionChanged.Invoke(this, null);
            }
            if (_bookSelection != null)
            {
                _bookSelection.SelectBook(null);
            }
        }
Exemplo n.º 7
0
        public void DeleteBook(Book.BookInfo bookInfo)
        {
            var didDelete = ConfirmRecycleDialog.Recycle(bookInfo.FolderPath);

            if (!didDelete)
            {
                return;
            }

            Logger.WriteEvent("After BookStorage.DeleteBook({0})", bookInfo.FolderPath);
            //ListOfBooksIsOutOfDate();
            Debug.Assert(_bookInfos.Contains(bookInfo));
            _bookInfos.Remove(bookInfo);

            if (CollectionChanged != null)
            {
                CollectionChanged.Invoke(this, null);
            }
            if (_bookSelection != null)
            {
                _bookSelection.SelectBook(null);
            }
        }
Exemplo n.º 8
0
 private void HandleThumbnailerErrror(Book.BookInfo bookInfo, Exception error)
 {
     RefreshOneThumbnail(bookInfo, Resources.Error70x70);
 }
Exemplo n.º 9
0
 private Button FindBookButton(Book.BookInfo bookInfo)
 {
     return(AllBookButtons().FirstOrDefault(b => b.Tag == bookInfo));
 }
Exemplo n.º 10
0
        private void AddOneBook(Book.BookInfo bookInfo, FlowLayoutPanel flowLayoutPanel, bool localizeTitle)
        {
            var button = new Button()
            {
                Size = new Size(90, 110)
            };
            string title = bookInfo.QuickTitleUserDisplay;

            if (localizeTitle)
            {
                title = LocalizationManager.GetDynamicString("Bloom", "Template." + title, title);
            }

            button.Text = ShortenTitleIfNeeded(title);
            button.TextImageRelation         = TextImageRelation.ImageAboveText;
            button.ImageAlign                = ContentAlignment.TopCenter;
            button.TextAlign                 = ContentAlignment.BottomCenter;
            button.FlatStyle                 = FlatStyle.Flat;
            button.ForeColor                 = Palette.TextAgainstDarkBackground;
            button.FlatAppearance.BorderSize = 0;
            button.UseMnemonic               = false;       //otherwise, it tries to interpret '&' as a shortcut
            button.ContextMenuStrip          = _bookContextMenu;
            button.MouseDown                += OnClickBook; //we need this for right-click menu selection, which needs to 1st select the book
            //doesn't work: item.DoubleClick += (sender,arg)=>_model.DoubleClickedBook();

            button.Font = bookInfo.IsEditable ? _editableBookFont : _collectionBookFont;

            // Setting the AutoEllipsis property is strange but makes it behave the same on
            // Windows and Linux. Despite its name it won't show an ellipsis but wrap the line
            // at a word boundary if the text is too long (at least if the height is large
            // enough - didn't try what happens if the text doesn't fit in multiple lines)
            button.AutoEllipsis = true;
            button.AutoSize     = false;

            button.Tag = bookInfo;


            Image thumbnail = Resources.PagePlaceHolder;;

            _bookThumbnails.Images.Add(bookInfo.Id, thumbnail);
            button.ImageIndex = _bookThumbnails.Images.Count - 1;
            flowLayoutPanel.Controls.Add(button);

            Image img;

            //review: we could do this at idle time, too:
            if (bookInfo.TryGetPremadeThumbnail(out img))
            {
                RefreshOneThumbnail(bookInfo, img);
            }
            else
            {
                //show this one for now, in the background someone will do the slow work of getting us a better one
                RefreshOneThumbnail(bookInfo, Resources.placeHolderBookThumbnail);
                //hack to signal that we need to make a real one when get a chance
                button.ImageIndex = 999;
            }
            _buttonsNeedingSlowUpdate.Enqueue(button);

//			bookInfo.GetThumbNailOfBookCoverAsync(bookInfo.Type != Book.Book.BookType.Publication,
//				                                  image => RefreshOneThumbnail(bookInfo, image),
//												  error=> RefreshOneThumbnail(bookInfo, Resources.Error70x70));
        }