Click here to Skip to main content
11,479,170 members (64,777 online)
Click here to Skip to main content
Add your own
alternative version

WPF Book Reader

, 10 May 2012 GPL3 67.5K 2.8K 119
A WPF book reader for cbz/cbr files
BookReaderv1.zip
BookReader.exe.manifest
ICSharpCode.SharpZipLib.dll
SevenZipSharp.dll
WPFToolkit.dll
Dependencies
7z.dll
BookReader.application
BookReader.exe
BookReaderv1_source.zip
BookReader
ClassDiagram.cd
Dependencies
7-zip.dll
7z.dll
ICSharpCode.SharpZipLib.dll
SevenZipSharp.dll
WPFToolkit.dll
Properties
app.manifest
Settings.settings
Reader
Catalog
Common
Images
RAR
ZIP
Resources
TheRedPushPin.png
XAML
BookReaderv2.zip
BookReader.application
BookReader.exe
BookReader.exe.manifest
7z.dll
SevenZipSharp.dll
WPFToolkit.dll
BookReaderv2_8.zip
Release
BookReader.application
BookReader.exe
BookReader.exe.manifest
Dependencies
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
BookReaderv2_8_source.zip
BookReader.csproj.user
BookReader.csproj.vspscc
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
app.manifest
Settings.settings
acroread.png
document.png
ecran.png
exit.png
FitHeight.png
FitWidth.png
info.png
open_folder.png
refresh.png
Search.png
Theme
TheRedPushPin.png
tools.png
BookReaderv2_source.zip
BookReader.csproj.user
ClassDiagram.cd
7-zip.dll
7z.dll
ICSharpCode.SharpZipLib.dll
SevenZipSharp.dll
WPFToolkit.dll
app.manifest
Settings.settings
TheRedPushPin.png
BookReaderv3_0.zip
BookReader.application
BookReader.exe
BookReader.exe.manifest
BookReader.vshost.exe
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
BookReaderv3_0_source.zip
BookReader.csproj.user
BookReader.csproj.vspscc
7z.dll
pdftohtml.exe
SevenZipSharp.dll
WPFToolkit.dll
app.manifest
Settings.settings
acroread.png
book.ico
document.png
ecran.png
exit.png
FitHeight.png
FitWidth.png
info.png
open_folder.png
refresh.png
Search.png
TheRedPushPin.png
tools.png
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Windows.Media.Imaging;

namespace BookReader
{
	internal class BaseBook : IBook
	{
		#region -----------------constructors-----------------

		public BaseBook()
		{
		}

		public BaseBook(string filePath)
		{
			_filePath = filePath;
			RaisePropetyChanged("FilePath");
			RaisePropetyChanged("FileName");
		}
		#endregion

		#region -----------------properties-----------------
		private ImageCache _Cache = new ImageCache();
		public ImageCache Cache
		{
			get { if (_Cache == null) _Cache = new ImageCache();  return _Cache; }
			set { _Cache = value; }
		}

		private string _filePath = string.Empty;
		public string FilePath
		{
			get { return _filePath; }
			set { _filePath = value; }
		}

		[NonSerialized()]
		private IBookItem _CurrentPage = null;
		public IBookItem CurrentPage
		{
			get { return _CurrentPage; }
			set { _CurrentPage = value; }
		}

		private List<IBookItem> _Pages = new List<IBookItem>();
		public List<IBookItem> Pages
		{
			get { if (_Pages == null) _Pages = new List<IBookItem>(); return _Pages; }
			set { _Pages = value; }
		}
		
		private string _Bookmark = string.Empty;
		public string Bookmark
		{
			get { return _Bookmark; }
			set { _Bookmark = value; RaisePropetyChanged("Bookmark"); }
		}

        private bool _IsRead= false;
        public bool IsRead
        {
            get { return _IsRead; }
            set { _IsRead = value; RaisePropetyChanged("IsRead"); }
        }


		private BitmapImage _Cover = null;
		public BitmapImage Cover
		{
			get { return _Cover; }
			set { _Cover = value; RaisePropetyChanged("Cover"); }
		}

		public string FileName
		{
			get
			{
				return Path.GetFileName(this._filePath);
			}
		}

		private int _NbPages;
		public int NbPages
		{
			get { return _NbPages; }
			set { _NbPages = value; }
		}

		private long _Size;
		public long Size
		{
			get { return _Size; }
			set { _Size = value; }
		}


		#endregion

		#region -----------------loading/unloading-----------------

		virtual public void Load()
		{
			_CurrentPage = Pages[0];
		}

		virtual public void UnLoad()
		{
			Pages.Clear();
			Cache.Clear();
		}
		#endregion

		#region -----------------virtual's-----------------

		virtual public BitmapImage GetCurrentPageImage()
		{
			throw new NotSupportedException();
		}

		#endregion

		#region -----------------bookmark-----------------

		public void SetMark()
		{
			Bookmark = _CurrentPage.FilePath;
		}

		public void GotoMark()
		{
			if (!string.IsNullOrEmpty(_Bookmark))
			{
				foreach (IBookItem pg in Pages)
				{
					if( pg.FilePath == _Bookmark )
						_CurrentPage = pg;
				}
			}
		}
		#endregion

		#region -----------------page navigation management-----------------

		public bool GotoPage( IBookItem page )
		{
			foreach (IBookItem pg in Pages)
			{
				if (pg == page)
				{
					_CurrentPage = pg;
					return true;
				}
			}
			return false;
		}

		public bool GotoNextPage()
		{
			int next = Pages.IndexOf(_CurrentPage);
			if (next >= Pages.Count-1)
				return false;
			else
			{
				next = next + 1;
				_CurrentPage = Pages[next];
				return true;
			}
		}

		public bool GotoPreviousPage()
		{
			int next = Pages.IndexOf(_CurrentPage);
			if (next == 0)
				return false;
			else
			{
				next = next - 1;
				_CurrentPage = Pages[next];
				return true;
			}
		}
		#endregion

		#region -----------------cache management-----------------

		internal IBookItem GetNextPage(IBookItem fromPage )
		{
			int next = Pages.IndexOf(fromPage);
			if (next >= Pages.Count-1)
				return null;
			else
			{
				next = next + 1;
				return Pages[next];
			}
		}

		virtual public void ManageCache()
		{
			Cache.ManageCache();
		}

		#endregion

		#region -----------------INotifyPropertyChanged-----------------

		private void RaisePropetyChanged(string propertyName)
		{
			if (PropertyChanged != null)
			{
				PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
			}
		}

		public event PropertyChangedEventHandler PropertyChanged;

		#endregion
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Guillaume Waser
Architect A.C.S.
France France
No Biography provided

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 10 May 2012
Article Copyright 2009 by Guillaume Waser
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid