Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
        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);
        }
Ejemplo n.º 3
0
        protected override void SaveToObject(VolumeDB.VolumeItem item)
        {
            // save form
            item.Note     = Note;
            item.Keywords = Keywords.Trim();

            item.UpdateChanges();
        }
Ejemplo n.º 4
0
 public void Write(VolumeItem item)
 {
     EnsureOpen();
     buffer[buffCounter++] = item;
     if (buffCounter >= buffer.Length)
     {
         database.InsertVolumeItems(buffer);
         buffCounter = 0;
     }
 }
Ejemplo n.º 5
0
        public void Flush()
        {
            EnsureOpen();
            if (buffCounter > 0) {
                VolumeItem[] remainder = new VolumeItem[buffCounter];

                Array.Copy(buffer, remainder, buffCounter);
                database.InsertVolumeItems(remainder);
                buffCounter = 0;
            }
        }
Ejemplo n.º 6
0
        public void Flush()
        {
            EnsureOpen();
            if (buffCounter > 0)
            {
                VolumeItem[] remainder = new VolumeItem[buffCounter];

                Array.Copy(buffer, remainder, buffCounter);
                database.InsertVolumeItems(remainder);
                buffCounter = 0;
            }
        }
Ejemplo n.º 7
0
        protected override void LoadFromObject(VolumeDB.VolumeItem item)
        {
            //
            // form
            //
            Note     = item.Note;
            Keywords = item.Keywords;

            //
            // info labels
            //
            UpdateLabel(lblItemType, itemType);
            UpdateLabel(lblName, item.Name);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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;
        }
Ejemplo n.º 12
0
        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;
            }
        }
Ejemplo n.º 13
0
        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;
        }
Ejemplo n.º 14
0
        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);
        }
Ejemplo n.º 15
0
        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();
        }
Ejemplo n.º 16
0
        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();
        }
Ejemplo n.º 17
0
 public void Fill(VolumeItem[] items, VolumeDatabase db, bool clearVolumeCache)
 {
     if (clearVolumeCache)
         volumeCache.Clear();
     Fill(items, db);
 }
Ejemplo n.º 18
0
 internal void InsertVolumeItem(VolumeItem item)
 {
     InsertVolumeItems(new VolumeItem[] { item });
 }
Ejemplo n.º 19
0
 public void UpdateVolumeItem(VolumeItem item)
 {
     UpdateVolumeItems(new VolumeItem[] { item });
 }
Ejemplo n.º 20
0
 public void Write(VolumeItem item)
 {
     EnsureOpen();
     buffer[buffCounter++] = item;
     if (buffCounter >= buffer.Length) {
         database.InsertVolumeItems(buffer);
         buffCounter = 0;
     }
 }
Ejemplo n.º 21
0
        // 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);
            }
        }
Ejemplo n.º 22
0
        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);
        }