[f-spot] Port the main FSpot source to the new generics DbStore.
- From: Ruben Vermeersch <rubenv src gnome org>
- To: svn-commits-list gnome org
- Subject: [f-spot] Port the main FSpot source to the new generics DbStore.
- Date: Mon, 25 May 2009 08:10:02 -0400 (EDT)
commit ad567aa453ddd0979231eb7bf638741440fb049b
Author: Ruben Vermeersch <ruben savanne be>
Date: Thu May 21 04:15:01 2009 +0200
Port the main FSpot source to the new generics DbStore.
---
src/ExportStore.cs | 10 ++++------
src/JobStore.cs | 14 ++++++--------
src/MainWindow.cs | 7 +++----
src/MetaStore.cs | 10 ++++------
src/PhotoEventArgs.cs | 2 +-
src/PhotoQuery.cs | 2 +-
src/PhotoStore.cs | 18 +++++++++---------
src/RollStore.cs | 8 ++++----
src/TagQueryWidget.cs | 16 ++++++++--------
src/TagSelectionWidget.cs | 18 ++++++------------
src/TagStore.cs | 33 ++++++++++++++++-----------------
src/XmpTagsImporter.cs | 7 ++++---
12 files changed, 66 insertions(+), 79 deletions(-)
diff --git a/src/ExportStore.cs b/src/ExportStore.cs
index fae8679..c2b56db 100644
--- a/src/ExportStore.cs
+++ b/src/ExportStore.cs
@@ -42,7 +42,7 @@ public class ExportItem : DbItem {
}
}
-public class ExportStore : DbStore {
+public class ExportStore : DbStore<ExportItem> {
public const string FlickrExportType = "fspot:Flickr";
public const string OldFolderExportType = "fspot:Folder"; //This is obsolete and meant to be remove once db reach rev4
@@ -96,17 +96,15 @@ public class ExportStore : DbStore {
return item;
}
- public override void Commit (DbItem dbitem)
+ public override void Commit (ExportItem item)
{
- ExportItem item = dbitem as ExportItem;
-
Database.ExecuteNonQuery(new DbCommand("UPDATE exports SET image_id = :image_id, image_version_id = :image_version_id, export_type = :export_type SET export_token = :export_token WHERE id = :item_id",
"item_id", item.Id, "image_id", item.ImageId, "image_version_id", item.ImageVersionId, "export_type", item.ExportType, "export_token", item.ExportToken));
EmitChanged (item);
}
- public override DbItem Get (uint id)
+ public override ExportItem Get (uint id)
{
// we never use this
return null;
@@ -126,7 +124,7 @@ public class ExportStore : DbStore {
return list;
}
- public override void Remove (DbItem item)
+ public override void Remove (ExportItem item)
{
RemoveFromCache (item);
diff --git a/src/JobStore.cs b/src/JobStore.cs
index 12d9e3d..868ff9b 100644
--- a/src/JobStore.cs
+++ b/src/JobStore.cs
@@ -84,7 +84,7 @@ public abstract class Job : DbItem, IJob
protected abstract bool Execute ();
}
-public class JobStore : DbStore {
+public class JobStore : DbStore<Job> {
internal static void CreateTable (QueuedSqliteDatabase database)
{
@@ -160,10 +160,8 @@ public class JobStore : DbStore {
return job;
}
- public override void Commit (DbItem dbitem)
+ public override void Commit (Job item)
{
- Job item = dbitem as Job;
-
if (item.Persistent)
Database.ExecuteNonQuery(new DbCommand("UPDATE jobs " +
"SET job_type = :job_type " +
@@ -179,13 +177,13 @@ public class JobStore : DbStore {
EmitChanged (item);
}
- public override DbItem Get (uint id)
+ public override Job Get (uint id)
{
// we never use this
return null;
}
- public override void Remove (DbItem item)
+ public override void Remove (Job item)
{
RemoveFromCache (item);
@@ -195,9 +193,9 @@ public class JobStore : DbStore {
EmitRemoved (item);
}
- public void HandleRemoveJob (object o, EventArgs e)
+ public void HandleRemoveJob (Object o, EventArgs e)
{
- Remove (o as DbItem);
+ Remove (o as Job);
}
public JobStore (QueuedSqliteDatabase database, bool is_new) : base (database, true)
diff --git a/src/MainWindow.cs b/src/MainWindow.cs
index eee15ba..b96f599 100644
--- a/src/MainWindow.cs
+++ b/src/MainWindow.cs
@@ -673,10 +673,9 @@ public class MainWindow {
FSpot.Extensions.ExportMenuItemNode.SelectedImages = delegate () {return new FSpot.PhotoArray (SelectedPhotos ()); };
}
- private void HandleDbItemsChanged (object sender, DbItemEventArgs args)
+ private void HandleDbItemsChanged (object sender, DbItemEventArgs<Photo> args)
{
- foreach (DbItem item in args.Items) {
- Photo p = item as Photo;
+ foreach (Photo p in args.Items) {
if (p == null)
continue;
if (write_metadata)
@@ -687,7 +686,7 @@ public class MainWindow {
query.RequestReload ();
}
- private void HandleTagsChanged (object sender, DbItemEventArgs args)
+ private void HandleTagsChanged (object sender, DbItemEventArgs<Tag> args)
{
icon_view.QueueDraw ();
UpdateTagEntryFromSelection ();
diff --git a/src/MetaStore.cs b/src/MetaStore.cs
index e617284..13cc99c 100644
--- a/src/MetaStore.cs
+++ b/src/MetaStore.cs
@@ -32,7 +32,7 @@ public class MetaItem : DbItem {
}
}
-public class MetaStore : DbStore {
+public class MetaStore : DbStore<MetaItem> {
private const string version = "F-Spot Version";
private const string db_version = "F-Spot Database Version";
private const string hidden = "Hidden Tag Id";
@@ -126,21 +126,19 @@ public class MetaStore : DbStore {
return item;
}
- public override void Commit (DbItem dbitem)
+ public override void Commit (MetaItem item)
{
- MetaItem item = dbitem as MetaItem;
-
Database.ExecuteNonQuery(new DbCommand("UPDATE meta SET data = :data WHERE name = :name", "name", item.Name, "data", item.Value));
EmitChanged (item);
}
- public override DbItem Get (uint id)
+ public override MetaItem Get (uint id)
{
return LookupInCache (id);
}
- public override void Remove (DbItem item)
+ public override void Remove (MetaItem item)
{
RemoveFromCache (item);
diff --git a/src/PhotoEventArgs.cs b/src/PhotoEventArgs.cs
index 3eec52e..5b0b6e8 100644
--- a/src/PhotoEventArgs.cs
+++ b/src/PhotoEventArgs.cs
@@ -10,7 +10,7 @@
namespace FSpot
{
- public class PhotoEventArgs : DbItemEventArgs {
+ public class PhotoEventArgs : DbItemEventArgs<Photo> {
PhotosChanges changes;
public PhotosChanges Changes {
get { return changes; }
diff --git a/src/PhotoQuery.cs b/src/PhotoQuery.cs
index 97b3c9c..e977f3b 100644
--- a/src/PhotoQuery.cs
+++ b/src/PhotoQuery.cs
@@ -337,7 +337,7 @@ namespace FSpot {
store.Commit (to_commit.ToArray ());
}
- private void MarkChanged (object sender, DbItemEventArgs args)
+ private void MarkChanged (object sender, DbItemEventArgs<Photo> args)
{
int [] indexes = IndicesOf (args.Items);
diff --git a/src/PhotoStore.cs b/src/PhotoStore.cs
index 56d85d2..5a96c9a 100644
--- a/src/PhotoStore.cs
+++ b/src/PhotoStore.cs
@@ -29,7 +29,7 @@ using FSpot.Platform;
using Banshee.Database;
-public class PhotoStore : DbStore {
+public class PhotoStore : DbStore<Photo> {
public int TotalPhotos {
get {
SqliteDataReader reader = Database.Query("SELECT COUNT(*) AS photo_count FROM photos");
@@ -312,9 +312,9 @@ public class PhotoStore : DbStore {
reader.Close();
}
- public override DbItem Get (uint id)
+ public override Photo Get (uint id)
{
- Photo photo = LookupInCache (id) as Photo;
+ Photo photo = LookupInCache (id);
if (photo != null)
return photo;
@@ -479,12 +479,12 @@ public class PhotoStore : DbStore {
}
- public override void Remove (DbItem item)
+ public override void Remove (Photo item)
{
Remove (new Photo [] { (Photo)item });
}
- public override void Commit (DbItem item)
+ public override void Commit (Photo item)
{
Commit (new Photo [] {item as Photo});
}
@@ -621,8 +621,8 @@ public class PhotoStore : DbStore {
}
// Dbus
- public event EventHandler<DbItemEventArgs> ItemsAddedOverDBus;
- public event EventHandler<DbItemEventArgs> ItemsRemovedOverDBus;
+ public event EventHandler<DbItemEventArgs<Photo>> ItemsAddedOverDBus;
+ public event EventHandler<DbItemEventArgs<Photo>> ItemsRemovedOverDBus;
public Photo CreateOverDBus (string new_path, string orig_path, uint roll_id, out Gdk.Pixbuf pixbuf) {
Photo photo = Create (new_path, orig_path, roll_id, out pixbuf);
@@ -643,7 +643,7 @@ public class PhotoStore : DbStore {
protected void EmitAddedOverDBus (Photo [] photos) {
if (ItemsAddedOverDBus != null)
- ItemsAddedOverDBus (this, new DbItemEventArgs (photos));
+ ItemsAddedOverDBus (this, new DbItemEventArgs<Photo> (photos));
}
protected void EmitRemovedOverDBus (Photo photo) {
@@ -652,7 +652,7 @@ public class PhotoStore : DbStore {
protected void EmitRemovedOverDBus (Photo [] photos) {
if (ItemsRemovedOverDBus != null)
- ItemsRemovedOverDBus (this, new DbItemEventArgs (photos));
+ ItemsRemovedOverDBus (this, new DbItemEventArgs<Photo> (photos));
}
public int Count (string table_name, params IQueryCondition [] conditions)
diff --git a/src/RollStore.cs b/src/RollStore.cs
index 063671a..b417285 100644
--- a/src/RollStore.cs
+++ b/src/RollStore.cs
@@ -17,7 +17,7 @@ using Banshee.Database;
using FSpot.Utils;
using FSpot;
-public class RollStore : DbStore
+public class RollStore : DbStore<Roll>
{
public RollStore (QueuedSqliteDatabase database, bool is_new) : base (database, false)
{
@@ -47,7 +47,7 @@ public class RollStore : DbStore
return Create (System.DateTime.UtcNow);
}
- public override DbItem Get (uint id)
+ public override Roll Get (uint id)
{
Roll roll = LookupInCache (id) as Roll;
if (roll != null)
@@ -63,13 +63,13 @@ public class RollStore : DbStore
return roll;
}
- public override void Remove (DbItem item)
+ public override void Remove (Roll item)
{
RemoveFromCache (item);
Database.ExecuteNonQuery (new DbCommand ("DELETE FROM rolls WHERE id = :id", "id", item.Id));
}
- public override void Commit (DbItem item)
+ public override void Commit (Roll item)
{
// Nothing to do here, since all the properties of a roll are immutable.
}
diff --git a/src/TagQueryWidget.cs b/src/TagQueryWidget.cs
index 58dc359..d26e08c 100644
--- a/src/TagQueryWidget.cs
+++ b/src/TagQueryWidget.cs
@@ -313,19 +313,19 @@ namespace FSpot
// When the user edits a tag (it's icon, name, etc) we get called
// and update the images/text in the query as needed to reflect the changes.
- private void HandleTagChanged (object sender, DbItemEventArgs args)
+ private void HandleTagChanged (object sender, DbItemEventArgs<Tag> args)
{
- foreach (DbItem item in args.Items)
- foreach (Literal term in rootTerm.FindByTag (item as Tag))
- term.Update ();
+ foreach (Tag t in args.Items)
+ foreach (Literal term in rootTerm.FindByTag (t))
+ term.Update ();
}
// If the user deletes a tag that is in use in the query, remove it from the query too.
- private void HandleTagDeleted (object sender, DbItemEventArgs args)
+ private void HandleTagDeleted (object sender, DbItemEventArgs<Tag> args)
{
- foreach (DbItem item in args.Items)
- foreach (Literal term in rootTerm.FindByTag (item as Tag))
- term.RemoveSelf ();
+ foreach (Tag t in args.Items)
+ foreach (Literal term in rootTerm.FindByTag (t))
+ term.RemoveSelf ();
}
private void HandleDragMotion (object o, DragMotionArgs args)
diff --git a/src/TagSelectionWidget.cs b/src/TagSelectionWidget.cs
index deace40..aab4617 100644
--- a/src/TagSelectionWidget.cs
+++ b/src/TagSelectionWidget.cs
@@ -332,25 +332,21 @@ public class TagSelectionWidget : FSpot.Widgets.SaneTreeView {
return iter;
}
- private void HandleTagsRemoved (object sender, DbItemEventArgs args)
+ private void HandleTagsRemoved (object sender, DbItemEventArgs<Tag> args)
{
TreeIter iter;
- foreach (DbItem item in args.Items) {
- Tag tag = (Tag)item;
-
+ foreach (Tag tag in args.Items) {
if (TreeIterForTag (tag, out iter))
(Model as TreeStore).Remove (ref iter);
}
}
- private void HandleTagsAdded (object sender, DbItemEventArgs args)
+ private void HandleTagsAdded (object sender, DbItemEventArgs<Tag> args)
{
TreeIter iter = TreeIter.Zero;
- foreach (DbItem item in args.Items) {
- Tag tag = (Tag)item;
-
+ foreach (Tag tag in args.Items) {
if (tag.Category != tag_store.RootCategory)
TreeIterForTag (tag.Category, out iter);
@@ -360,14 +356,12 @@ public class TagSelectionWidget : FSpot.Widgets.SaneTreeView {
}
}
- private void HandleTagsChanged (object sender, DbItemEventArgs args)
+ private void HandleTagsChanged (object sender, DbItemEventArgs<Tag> args)
{
TreeStore store = Model as TreeStore;
TreeIter iter, category_iter, parent_iter;
- foreach (DbItem item in args.Items) {
- Tag tag = (Tag) item;
-
+ foreach (Tag tag in args.Items) {
TreeIterForTag (tag, out iter);
bool category_valid = TreeIterForTag(tag.Category, out category_iter);
diff --git a/src/TagStore.cs b/src/TagStore.cs
index 5f87fb9..e1b1f56 100644
--- a/src/TagStore.cs
+++ b/src/TagStore.cs
@@ -50,7 +50,7 @@ public class TagRemoveComparer : IComparer {
}
}
-public class TagStore : DbStore {
+public class TagStore : DbStore<Tag> {
Category root_category;
public Category RootCategory {
get {
@@ -286,30 +286,29 @@ public class TagStore : DbStore {
return new_category;
}
- public override DbItem Get (uint id)
+ public override Tag Get (uint id)
{
if (id == 0)
return RootCategory;
else
- return LookupInCache (id) as Tag;
+ return LookupInCache (id);
}
- public override void Remove (DbItem item)
+ public override void Remove (Tag tag)
{
- Category category = item as Category;
+ Category category = tag as Category;
if (category != null &&
category.Children != null &&
category.Children.Count > 0)
throw new InvalidTagOperationException (category, "Cannot remove category that contains children");
- RemoveFromCache (item);
-
- ((Tag)item).Category = null;
+ RemoveFromCache (tag);
+ tag.Category = null;
- Database.ExecuteNonQuery (new DbCommand ("DELETE FROM tags WHERE id = :id", "id", item.Id));
+ Database.ExecuteNonQuery (new DbCommand ("DELETE FROM tags WHERE id = :id", "id", tag.Id));
- EmitRemoved (item);
+ EmitRemoved (tag);
}
@@ -324,17 +323,17 @@ public class TagStore : DbStore {
return Convert.ToBase64String (data);
}
- public override void Commit (DbItem item)
+ public override void Commit (Tag tag)
{
- Commit (item, false);
+ Commit (tag, false);
}
- public void Commit (DbItem item, bool update_xmp)
+ public void Commit (Tag tag, bool update_xmp)
{
- Commit (new DbItem[] {item}, update_xmp);
+ Commit (new Tag[] {tag}, update_xmp);
}
- public void Commit (DbItem [] items, bool update_xmp)
+ public void Commit (Tag [] tags, bool update_xmp)
{
bool use_transactions = !Database.InTransaction && update_xmp;
@@ -342,7 +341,7 @@ public class TagStore : DbStore {
if (use_transactions)
Database.BeginTransaction ();
- foreach (Tag tag in items) {
+ foreach (Tag tag in tags) {
Database.ExecuteNonQuery (new DbCommand ("UPDATE tags SET name = :name, category_id = :category_id, "
+ "is_category = :is_category, sort_priority = :sort_priority, icon = :icon WHERE id = :id",
"name", tag.Name,
@@ -363,6 +362,6 @@ public class TagStore : DbStore {
if (use_transactions)
Database.CommitTransaction ();
- EmitChanged (items);
+ EmitChanged (tags);
}
}
diff --git a/src/XmpTagsImporter.cs b/src/XmpTagsImporter.cs
index e0c0f18..31d2d32 100644
--- a/src/XmpTagsImporter.cs
+++ b/src/XmpTagsImporter.cs
@@ -11,6 +11,7 @@
using Gtk;
using System;
using System.Collections;
+using System.Collections.Generic;
using System.IO;
using System.Xml;
using FSpot.Xmp;
@@ -22,7 +23,7 @@ using FSpot.Utils;
namespace FSpot.Xmp {
internal class XmpTagsImporter {
private TagStore tag_store;
- private Stack tags_created;
+ private Stack<Tag> tags_created;
static private string LastImportIcon = "f-spot-imported-xmp-tags.png";
static private string PlacesIcon = "emblem-places";
@@ -83,7 +84,7 @@ namespace FSpot.Xmp {
public XmpTagsImporter (PhotoStore photo_store, TagStore tag_store)
{
this.tag_store = tag_store;
- tags_created = new Stack ();
+ tags_created = new Stack<Tag> ();
li_root_tag = new TagInfo (Catalog.GetString ("Import Tags"), LastImportIcon);
taginfo_table [(Entity)Location] = new TagInfo (Catalog.GetString ("Location"), PlacesIcon);
@@ -313,7 +314,7 @@ namespace FSpot.Xmp {
// User have cancelled the import.
// Remove all created tags
while (tags_created.Count > 0)
- tag_store.Remove ((DbItem) tags_created.Pop());
+ tag_store.Remove (tags_created.Pop());
// Clear the tags_created array
tags_created.Clear();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]