Skip to content

Commit

Permalink
Removed the Error property from ThumbnailCachedEventArgs.
Browse files Browse the repository at this point in the history
  • Loading branch information
oozcitak committed Oct 14, 2010
1 parent a49cb71 commit 285f162
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 57 deletions.
8 changes: 1 addition & 7 deletions ImageListView/Events.cs
Original file line number Diff line number Diff line change
Expand Up @@ -473,24 +473,18 @@ public class ThumbnailCachedEventArgs
/// Gets the cached thumbnail image.
/// </summary>
public Image Thumbnail { get; private set; }
/// <summary>
/// Gets whether an error occurred during thumbnail extraction.
/// </summary>
public bool Error { get; private set; }

/// <summary>
/// Initializes a new instance of the ItemEventArgs class.
/// </summary>
/// <param name="item">The item that is the target of this event.</param>
/// <param name="thumbnail">The cached thumbnail image.</param>
/// <param name="size">The size of the thumbnail request.</param>
/// <param name="error">Determines whether an error occurred during thumbnail extraction.</param>
public ThumbnailCachedEventArgs(ImageListViewItem item, Image thumbnail, Size size, bool error)
public ThumbnailCachedEventArgs(ImageListViewItem item, Image thumbnail, Size size)
{
Item = item;
Thumbnail = thumbnail;
Size = size;
Error = error;
}
}
/// <summary>
Expand Down
8 changes: 2 additions & 6 deletions ImageListView/ImageListView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,6 @@ public Size ThumbnailSize
if (mThumbnailSize != value)
{
mThumbnailSize = value;
thumbnailCache.CurrentThumbnailSize = mThumbnailSize;
thumbnailCache.Rebuild();
Refresh();
}
Expand Down Expand Up @@ -873,9 +872,7 @@ public ImageListView()
// Helpers
layoutManager = new ImageListViewLayoutManager(this);
navigationManager = new ImageListViewNavigationManager(this);

thumbnailCache = new ImageListViewCacheThumbnail(this);
thumbnailCache.CurrentThumbnailSize = mThumbnailSize;
shellInfoCache = new ImageListViewCacheShellInfo(this);
itemCacheManager = new ImageListViewCacheMetadata(this);

Expand Down Expand Up @@ -1805,12 +1802,11 @@ internal void OnCacheErrorInternal(Guid guid, Exception error, CacheThread cache
/// <param name="guid">The guid of the item whose thumbnail is cached.</param>
/// <param name="thumbnail">The cached image.</param>
/// <param name="size">Requested thumbnail size.</param>
/// <param name="error">Determines whether an error occurred during thumbnail extraction.</param>
internal void OnThumbnailCachedInternal(Guid guid, Image thumbnail, Size size, bool error)
internal void OnThumbnailCachedInternal(Guid guid, Image thumbnail, Size size)
{
ImageListViewItem item = null;
if (mItems.TryGetValue(guid, out item))
OnThumbnailCached(new ThumbnailCachedEventArgs(item, thumbnail, size, error));
OnThumbnailCached(new ThumbnailCachedEventArgs(item, thumbnail, size));
}
/// <summary>
/// Updates item details.
Expand Down
20 changes: 10 additions & 10 deletions ImageListView/ImageListViewCacheMetadata.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ internal class ImageListViewCacheMetadata : IDisposable

#region CacheRequest Class
/// <summary>
/// Represents an item in the cache.
/// Represents a cache request.
/// </summary>
private class CacheRequest
{
Expand Down Expand Up @@ -108,9 +108,9 @@ public CacheRequest(Guid guid, object virtualItemKey, bool useWIC)
private class CanContinueProcessingEventArgs : EventArgs
{
/// <summary>
/// Gets the guid of the request.
/// Gets the cache request.
/// </summary>
public Guid Guid { get; private set; }
public CacheRequest Request { get; private set; }
/// <summary>
/// Gets whether this item should be processed.
/// </summary>
Expand All @@ -119,10 +119,10 @@ private class CanContinueProcessingEventArgs : EventArgs
/// <summary>
/// Initializes a new instance of the <see cref="CanContinueProcessingEventArgs"/> class.
/// </summary>
/// <param name="guid">The guid of the request.</param>
public CanContinueProcessingEventArgs(Guid guid)
/// <param name="request">The cache request.</param>
public CanContinueProcessingEventArgs(CacheRequest request)
{
Guid = guid;
Request = request;
ContinueProcessing = true;
}
}
Expand Down Expand Up @@ -169,8 +169,7 @@ public ImageListViewCacheMetadata(ImageListView owner)
/// <returns>true if the item should be processed; otherwise false.</returns>
private bool OnCanContinueProcessing(CacheRequest item)
{
CanContinueProcessingEventArgs arg = new CanContinueProcessingEventArgs(
item.Guid);
CanContinueProcessingEventArgs arg = new CanContinueProcessingEventArgs(item);
context.Send(checkProcessingCallback, arg);
return arg.ContinueProcessing;
}
Expand All @@ -182,19 +181,20 @@ private bool OnCanContinueProcessing(CacheRequest item)
private void CanContinueProcessing(object argument)
{
CanContinueProcessingEventArgs arg = argument as CanContinueProcessingEventArgs;
CacheRequest request = arg.Request;
bool canProcess = true;

// Is it in the edit cache?
if (canProcess)
{
if (editCache.ContainsKey(arg.Guid))
if (editCache.ContainsKey(request.Guid))
canProcess = false;
}

// Was the item was updated by the UI thread?
if (canProcess)
{
if (mImageListView != null && !mImageListView.IsItemDirty(arg.Guid))
if (mImageListView != null && !mImageListView.IsItemDirty(request.Guid))
canProcess = false;
}

Expand Down
52 changes: 22 additions & 30 deletions ImageListView/ImageListViewCacheThumbnail.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,13 +259,9 @@ public void Dispose()
private class CanContinueProcessingEventArgs : EventArgs
{
/// <summary>
/// Gets the guid of the request.
/// Gets the request.
/// </summary>
public Guid Guid { get; private set; }
/// <summary>
/// Gets the type of the request.
/// </summary>
public RequestType RequestType { get; private set; }
public CacheRequest Request { get; private set; }
/// <summary>
/// Gets whether this item should be processed.
/// </summary>
Expand All @@ -274,12 +270,10 @@ private class CanContinueProcessingEventArgs : EventArgs
/// <summary>
/// Initializes a new instance of the <see cref="CanContinueProcessingEventArgs"/> class.
/// </summary>
/// <param name="guid">The guid of the request.</param>
/// <param name="requestType">Type of the request.</param>
public CanContinueProcessingEventArgs(Guid guid, RequestType requestType)
/// <param name="request">The cache request.</param>
public CanContinueProcessingEventArgs(CacheRequest request)
{
Guid = guid;
RequestType = requestType;
Request = request;
ContinueProcessing = true;
}
}
Expand Down Expand Up @@ -315,10 +309,6 @@ public CanContinueProcessingEventArgs(Guid guid, RequestType requestType)
/// Returns the count of items in the cache.
/// </summary>
public long CacheSize { get { return thumbCache.Count; } }
/// <summary>
/// Gets or sets the current thumbnail size.
/// </summary>
public Size CurrentThumbnailSize { get; set; }
#endregion

#region Constructor
Expand Down Expand Up @@ -368,8 +358,7 @@ public ImageListViewCacheThumbnail(ImageListView owner)
/// <returns>true if the item should be processed; otherwise false.</returns>
private bool OnCanContinueProcessing(CacheRequest item)
{
CanContinueProcessingEventArgs arg = new CanContinueProcessingEventArgs(
item.Guid, item.RequestType);
CanContinueProcessingEventArgs arg = new CanContinueProcessingEventArgs(item);
context.Send(checkProcessingCallback, arg);
return arg.ContinueProcessing;
}
Expand All @@ -381,28 +370,31 @@ private bool OnCanContinueProcessing(CacheRequest item)
private void CanContinueProcessing(object argument)
{
CanContinueProcessingEventArgs arg = argument as CanContinueProcessingEventArgs;
CacheRequest request = arg.Request;
bool canProcess = true;

// Is it already cached?
if (canProcess && (arg.RequestType == RequestType.Thumbnail))
if (canProcess && (request.RequestType == RequestType.Thumbnail))
{
CacheItem existing = null;
thumbCache.TryGetValue(arg.Guid, out existing);
if (existing != null && existing.Size == CurrentThumbnailSize)
thumbCache.TryGetValue(request.Guid, out existing);
if (existing != null && existing.Size == request.Size &&
existing.UseEmbeddedThumbnails == request.UseEmbeddedThumbnails &&
existing.AutoRotate == request.AutoRotate && existing.UseWIC == request.UseWIC)
canProcess = false;
}

// Is it in the edit cache?
if (canProcess)
{
if (editCache.ContainsKey(arg.Guid))
if (editCache.ContainsKey(request.Guid))
canProcess = false;
}

// Is it outside the visible area?
if (canProcess && (arg.RequestType == RequestType.Thumbnail) && (CacheMode == CacheMode.OnDemand))
if (canProcess && (request.RequestType == RequestType.Thumbnail) && (CacheMode == CacheMode.OnDemand))
{
if (mImageListView != null && !mImageListView.IsItemVisible(arg.Guid))
if (mImageListView != null && !mImageListView.IsItemVisible(request.Guid))
canProcess = false;
}

Expand Down Expand Up @@ -464,10 +456,10 @@ void bw_RunWorkerCompleted(object sender, QueuedWorkerCompletedEventArgs e)
{
// Did the thumbnail size change while we were
// creating the thumbnail?
if (result.Size != CurrentThumbnailSize)
if (result.Size != mImageListView.ThumbnailSize)
result.State = CacheState.Unknown;

// Purge invisible items if we exceeded the cache limit?
// Purge invisible items if we exceeded the cache limit
MemoryUsed += GetImageMemorySize(result.Image);
if (IsCacheLimitExceeded())
PurgeInvisible(true);
Expand All @@ -479,17 +471,17 @@ void bw_RunWorkerCompleted(object sender, QueuedWorkerCompletedEventArgs e)
{
if (request.RequestType != RequestType.Thumbnail)
mImageListView.Refresh(false, true);
else if (mImageListView.IsItemVisible(request.Guid))
else if (mImageListView.IsItemVisible(result.Guid))
mImageListView.Refresh(false, true);
}

// Raise the ThumbnailCached event
if (mImageListView != null)
mImageListView.OnThumbnailCachedInternal(request.Guid, result.Image, request.Size, e.Error != null);
mImageListView.OnThumbnailCachedInternal(result.Guid, result.Image, result.Size);

// Raise the CacheError event
if (e.Error != null && mImageListView != null)
mImageListView.OnCacheErrorInternal(request.Guid, e.Error, CacheThread.Thumbnail);
mImageListView.OnCacheErrorInternal(result.Guid, e.Error, CacheThread.Thumbnail);
}
/// <summary>
/// Handles the DoWork event of the queued background worker.
Expand Down Expand Up @@ -792,7 +784,7 @@ public void Add(Guid guid, string filename, Size thumbSize, Image thumb,

if (mImageListView != null)
{
mImageListView.OnThumbnailCachedInternal(guid, thumb, thumbSize, false);
mImageListView.OnThumbnailCachedInternal(guid, thumb, thumbSize);
mImageListView.Refresh();
}
}
Expand Down Expand Up @@ -849,7 +841,7 @@ public void Add(Guid guid, object key, Size thumbSize, Image thumb,
// Raise the cache events
if (mImageListView != null)
{
mImageListView.OnThumbnailCachedInternal(guid, thumb, thumbSize, false);
mImageListView.OnThumbnailCachedInternal(guid, thumb, thumbSize);
mImageListView.Refresh();
}
}
Expand Down
5 changes: 1 addition & 4 deletions ImageListViewTests/TestForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,7 @@ void imageListView1_ThumbnailCached(object sender, Manina.Windows.Forms.Thumbnai
int index = -1;
if (e.Item != null)
index = e.Item.Index;
if (e.Error)
LogEvent(string.Format("<-- {0} !!!", index));
else
LogEvent(string.Format("<-- {0} ({1})", index, e.Size));
LogEvent(string.Format("<-- {0} ({1})", index, e.Size));
}
}
// Thumbnail caching
Expand Down

0 comments on commit 285f162

Please sign in to comment.