private TItem[] QueryItems <TItem>(string sqlQuery, int limit) where TItem : IChildItem // IChildItem is the least common denominator of all volumeitems and related interfaces (e.g. DirectoryVolumeItem, FileVolumeItem, ..., IContainerItem, IChildItem) { List <TItem> list = new List <TItem>(); int n = 0; sql.ExecuteReader(sqlQuery, delegate(IDataReader reader, IRecordData readerRecData) { while (reader.Read()) { if ((limit > -1) && (++n > limit)) { list.Clear(); throw new TooManyResultsException( string.Format("The result limit of {0} items has been reached", limit)); } // TODO : if possible, don't hardcode 'reader["ItemType"]' here, // use something like reader[AnInterface.TypeField]. VolumeDatabase shouldnt include table-/fieldnames if possible. // the classes representing the data should hold the names. // TODO : why do i have to cast to (IChildItem) first? TItem item = (TItem)(IChildItem)VolumeItem.CreateInstance((VolumeItemType)(int)(long)reader["ItemType"], this); IVolumeDBRecord record = (IVolumeDBRecord)item; record.SetRecordData(readerRecData); record.IsNew = false; list.Add(item); } }); return(list.ToArray()); }
internal static VolumeItem CreateInstance(VolumeItemType type, VolumeDatabase database) { VolumeItem item = null; switch (type) { case VolumeItemType.DirectoryVolumeItem: item = new DirectoryVolumeItem(database); break; case VolumeItemType.FileVolumeItem: item = new FileVolumeItem(database); break; case VolumeItemType.AudioCdRootVolumeItem: item = new AudioCdRootVolumeItem(database); break; case VolumeItemType.AudioTrackVolumeItem: item = new AudioTrackVolumeItem(database); break; default: throw new NotImplementedException(string.Format("Instantiation of type {0} is not implemented", type.ToString())); } return(item); }
protected override void SaveToObject(VolumeDB.VolumeItem item) { // save form item.Note = Note; item.Keywords = Keywords.Trim(); item.UpdateChanges(); }
public void Write(VolumeItem item) { EnsureOpen(); buffer[buffCounter++] = item; if (buffCounter >= buffer.Length) { database.InsertVolumeItems(buffer); buffCounter = 0; } }
public void Flush() { EnsureOpen(); if (buffCounter > 0) { VolumeItem[] remainder = new VolumeItem[buffCounter]; Array.Copy(buffer, remainder, buffCounter); database.InsertVolumeItems(remainder); buffCounter = 0; } }
protected override void LoadFromObject(VolumeDB.VolumeItem item) { // // form // Note = item.Note; Keywords = item.Keywords; // // info labels // UpdateLabel(lblItemType, itemType); UpdateLabel(lblName, item.Name); }
protected override void LoadFromObject(VolumeDB.VolumeItem item) { if (!(item is AudioTrackVolumeItem)) { throw new ArgumentException(string.Format("must be of type {0}", typeof(AudioTrackVolumeItem)), "item"); } base.LoadFromObject(item); AudioTrackVolumeItem avi = (AudioTrackVolumeItem)item; UpdateLabel(lblDuration, avi.Duration.ToString()); UpdateLabel(lblMimeType, avi.MimeType); }
protected override void LoadFromObject(VolumeDB.VolumeItem item) { if (!(item is FileVolumeItem)) { throw new ArgumentException(string.Format("must be of type {0}", typeof(FileVolumeItem)), "item"); } base.LoadFromObject(item); FileVolumeItem fvi = (FileVolumeItem)item; UpdateLabel(lblSize, Util.GetSizeStr(fvi.Size)); UpdateLabel(lblHash, string.IsNullOrEmpty(fvi.Hash) ? "-" : fvi.Hash); }
protected override void LoadFromObject(VolumeDB.VolumeItem item) { if (!(item is FileSystemVolumeItem)) { throw new ArgumentException(string.Format("must be of type {0}", typeof(FileSystemVolumeItem)), "item"); } base.LoadFromObject(item); FileSystemVolumeItem fsvi = (FileSystemVolumeItem)item; UpdateLabel(lblLocation, fsvi.Location); UpdateLabel(lblLastWriteTime, fsvi.LastWriteTime.ToString()); UpdateLabel(lblMimeType, string.IsNullOrEmpty(fsvi.MimeType) ? "-" : fsvi.MimeType); }
public Gdk.Pixbuf GetIconForItem(VolumeItem item, Gtk.IconSize iconSize) { Gdk.Pixbuf pb; if ((item is FileSystemVolumeItem) && (((FileSystemVolumeItem)item).IsSymLink)) { return iconCache.GetIcon(Icon.SymLink, iconSize); } string mimeType = item.MimeType; if (string.IsNullOrEmpty(mimeType)) pb = iconCache.GetIcon(DEFAULT_ICON, iconSize); else pb = mimeIconCache.GetIcon(mimeType, iconSize); return pb; }
public static Gdk.Pixbuf GetThumb(VolumeItem item, VolumeDatabase db, int size) { string dbDataPath = PathUtil.GetDbDataPath(db); string volumeDataPath = DbData.GetVolumeDataPath(dbDataPath, item.VolumeID); string thumbsPath = DbData.GetVolumeDataThumbsPath(volumeDataPath); string thumbName = System.IO.Path.Combine( thumbsPath, string.Format("{0}.png", item.ItemID)); if (File.Exists(thumbName)) { if (size > 0) return new Gdk.Pixbuf(thumbName, size, size, false); else return new Gdk.Pixbuf(thumbName); } else { return null; } }
private Gdk.Pixbuf GetImage(VolumeItem item) { Gdk.Pixbuf img = null; if (App.Settings.ShowThumbsInItemLists) { int sz = IconUtils.GetIconSizeVal(ICON_SIZE); img = PathUtil.GetThumb(item, database, sz); } if (img == null) img = itemIcons.GetIconForItem(item, ICON_SIZE); return img; }
private TreeIter AppendDirValues(TreeStore store, TreeIter parent, bool parentIsRoot, Gdk.Pixbuf icon, string name, VolumeItem item) { if ((item != null) && !App.Settings.ShowHiddenItems && item.Name.StartsWith(".")) return TreeIter.Zero; if (parentIsRoot) return store.AppendValues(icon, name, item); else return store.AppendValues(parent, icon, name, item); }
public void Preview(VolumeItem item, VolumeDatabase db) { if (item == null) throw new ArgumentNullException("item"); if (db == null) throw new ArgumentNullException("db"); // free old pixbuf (but not a _cached_ icon!) if (!isIcon && (this.pb != null)) { this.pb.Dispose(); this.pb = null; } Pixbuf tmp = PathUtil.GetThumb(item, db, 0); if (tmp != null) { this.pb = tmp; this.isIcon = false; } else { if (EnableGenericIcons) this.pb = itemIcons.GetIconForItem(item, ICON_SIZE); else this.pb = null; this.isIcon = true; } QueueDraw(); }
public void Fill(VolumeItem[] items, VolumeDatabase db) { if (items == null) throw new ArgumentNullException("items"); if (db == null) throw new ArgumentNullException("db"); ListStore store = new Gtk.ListStore( typeof(Gdk.Pixbuf), typeof(string), typeof(VolumeItem)); /* VolumeItem - not visible */ foreach (VolumeItem item in items) { Volume vol; if (!volumeCache.TryGetValue(item.VolumeID, out vol)) { vol = item.GetOwnerVolume(); volumeCache.Add(vol.VolumeID, vol); } string description; string itemName = Util.Escape(item.Name); string volTitle = Util.Escape(vol.Title.Length > 0 ? vol.Title : STR_UNNAMED); string archiveNo = Util.Escape(vol.ArchiveNo.Length > 0 ? vol.ArchiveNo : "-"); switch (item.GetVolumeItemType()) { case VolumeItemType.FileVolumeItem: case VolumeItemType.DirectoryVolumeItem: description = string.Format("<b>{0}</b>\n<span size=\"smaller\"><i>{1}:</i> {2}\n<i>{3}:</i> {4}, <i>{5}:</i> {6}</span>", itemName, Util.Escape(STR_LOCATION), Util.Escape(((FileSystemVolumeItem)item).Location), Util.Escape(STR_VOLUME), volTitle, Util.Escape(STR_ARCHIVENO), archiveNo); break; case VolumeItemType.AudioTrackVolumeItem: description = string.Format("<b>{0}</b>\n<span size=\"smaller\"><i>{1}</i>\n<i>{2}:</i> {3}, <i>{4}:</i> {5}</span>", itemName, Util.Escape(STR_AUDIOTRACK), Util.Escape(STR_VOLUME), volTitle, Util.Escape(STR_ARCHIVENO), archiveNo); break; default: throw new NotImplementedException("Search result view has not been implemented for this volumetype"); } store.AppendValues(GetImage(item, db), description, item); } this.Model = store; ColumnsAutosize(); }
public void Fill(VolumeItem[] items, VolumeDatabase db, bool clearVolumeCache) { if (clearVolumeCache) volumeCache.Clear(); Fill(items, db); }
internal void InsertVolumeItem(VolumeItem item) { InsertVolumeItems(new VolumeItem[] { item }); }
public void UpdateVolumeItem(VolumeItem item) { UpdateVolumeItems(new VolumeItem[] { item }); }
// finds the specified item: // - select owner volume // - expand the treeview path to the item // and select the item public void FindItem(VolumeItem item) { if (item == null) throw new ArgumentNullException("item"); // get path of volume ids to item Stack<long> path = new Stack<long>(); VolumeItem tmp = item; while (tmp.ItemID != 1) { // skip root item path.Push(tmp.ItemID); tmp = database.GetVolumeItem(tmp.VolumeID, tmp.ParentID); } // find and select volume of specified item TreeModel model = tvVolumes.Model; TreeIter iter; long volumeID = item.VolumeID; bool hasMoreIters = true; model.GetIterFirst(out iter); while (hasMoreIters) { Volume vol = tvVolumes.GetVolume(iter); if (vol.VolumeID == volumeID) { // select owner volume tvVolumes.Selection.SelectIter(iter); tvVolumes.ScrollToCell(model.GetPath(iter), null, false, .0f, .0f); if (path.Count > 0) { // find and select specified item tvItems.Model.GetIterFirst(out iter); FindItemRecursive(iter, path); } // else : specified item is the root item so select nothing break; } hasMoreIters = model.IterNext(ref iter); } }
public void Categorize(VolumeItem[] items) { if (items == null) throw new ArgumentNullException("items"); ListStore store = GetNewStore(); TreeIter iter = TreeIter.Zero; this.allItems = items; ClearCategories(); if (items.Length > 0) { // categorize items foreach(VolumeItem item in items) { CategoryInfo ci; if (MIME_MAPPING.TryGetValue(item.MimeType, out ci)) ci.items.Add(item); } // fill listore iter = store.AppendValues( PIXBUF_ALL_ITEMS, string.Format("{0} ({1})", S._("All items"), items.Length), Category.AllItems); for (int i = 0; i < CATEGORIES.Length; i++) { CategoryInfo ci = CATEGORIES[i]; if (ci.items.Count > 0) { store.AppendValues( ci.pixbuf, string.Format("{0} ({1})", ci.caption, ci.items.Count), (Category)i); } } } Model = store; ColumnsAutosize(); // select "all items" if (iter.Stamp != TreeIter.Zero.Stamp) Selection.SelectIter(iter); }