// TODO : remove parameter itemType if generic constraints allow internal and parameterized constructors. // Parameter itemType is used as a workaround to instanciate a VolumeItem object, // because the internal VolumeItem constructor with the database parameter can't be used in generic code. // see http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=9a8e58ee-1371-4e99-8385-c3e2a4157fd6 // see http://lab.msdn.microsoft.com/productfeedback/viewfeedback.aspx?feedbackid=80517ec1-2d08-43cc-bc90-9927877061a9 /// <summary> /// Returns a specific VolumeItem object, but preassigns properties of the VolumeItem baseclass only. /// Filling properties of the specific, derived object, is job of the specific VolumeScanner implementation. /// </summary> /// <typeparam name="TVolumeItem">Type of the specific volume item.</typeparam> /// <returns> /// A new specific VolumeItem derived from base class VolumeItem /// with all base class properties preassigned. /// </returns> protected TVolumeItem GetNewVolumeItem <TVolumeItem>(long parentID, string name, string mimeType, MetadataStore metaData, VolumeItemType itemType) where TVolumeItem : VolumeItem { // TODO: check here if TMediaItem applies to TMedia? /* TVolumeItem item = new TVolumeItem(database); */ TVolumeItem item = (TVolumeItem)VolumeItem.CreateInstance(itemType, database); // initialize fields of the VolumeItem base class. // don't initialize via properties. initializing via properties is error-prone // as the compiler won't error if a new field is added to the base class // and forgotten to be initialized here. item.SetVolumeItemFields(volume.VolumeID, itemID, parentID, name, mimeType, metaData, null, null); itemID++; return(item); }
public SoundSettingsScreen(Game i_Game) : base(i_Game, 150f, 15f) { int index = 0; this.m_Background = new Background(this, @"Sprites\BG_Space01_1024x768", 1); this.m_MenuHeader = new MenuHeader(this, @"Screens\Settings\SoundSettingsLogo"); this.m_SoundSettingManager = i_Game.Services.GetService(typeof(ISoundSettingsManager)) as ISoundSettingsManager; ToggleItem toggleGameSound = new ToggleItem(@"Screens\Settings\ToggleSound", @"Screens\Settings\OnOff_53x52", this, index++); VolumeItem bgMusicVolume = new VolumeItem(@"Screens\Settings\BgMusic", this, index++); VolumeItem soundEffectsVolume = new VolumeItem(@"Screens\Settings\SoundEffects", this, index++); ClickItem doneItem = new ClickItem("Done", @"Screens\Settings\Done", this, index++); toggleGameSound.ToggleValueChanched += new EventHandler <EventArgs>(this.m_SoundSettingManager.ToggleGameSound_Click); bgMusicVolume.IncreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.IncreaseBackgroundMusic_Click); bgMusicVolume.DecreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.DecreaseBackgroundMusic_Click); soundEffectsVolume.IncreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.IncreaseSoundEffects_Click); soundEffectsVolume.DecreaseVolumeButtonClicked += new EventHandler <EventArgs>(this.m_SoundSettingManager.DecreaseSoundEffects_Click); doneItem.ItemClicked += this.menuItem_Click; this.AddMenuItem(toggleGameSound); this.AddMenuItem(bgMusicVolume); this.AddMenuItem(soundEffectsVolume); this.AddMenuItem(doneItem); }
public override void Execute(SharedObjects shared) { string pathString = PopValueAssert(shared, true).ToString(); string toAppend = PopValueAssert(shared).ToString(); AssertArgBottomAndConsume(shared); if (shared.VolumeMgr != null) { GlobalPath path = shared.VolumeMgr.GlobalPathFromObject(pathString); Volume volume = shared.VolumeMgr.GetVolumeFromPath(path); VolumeItem volumeItem = volume.Open(path) as VolumeFile; VolumeFile volumeFile = null; if (volumeItem == null) { volumeFile = volume.CreateFile(path); } else if (volumeItem is VolumeDirectory) { throw new KOSFileException("Can't append to file: path points to a directory"); } else { volumeFile = volumeItem as VolumeFile; } if (!volumeFile.WriteLn(toAppend)) { throw new KOSFileException("Can't append to file: not enough space or access forbidden"); } } }
private void OnTvSearchResultSelectionChanged(object o, EventArgs args) { TreeIter iter; if (!tvSearchResult.GetSelectedIter(out iter)) { return; } VolumeItem item = tvSearchResult.GetItem(iter); if (item == null) { return; } if (App.Settings.ShowItemInfo) { itemInfo.ShowInfo(item, database); } else if (itemInfo.Visible) { itemInfo.Hide(); } }
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 void FindItemRecursive(TreeIter iter, Stack <long> path) { TreeModel model = tvItems.Model; bool hasMoreIters = true; long itemID = path.Pop(); while (hasMoreIters) { VolumeItem item = tvItems.GetItem(iter); if (item.ItemID == itemID) { if (path.Count > 0) { tvItems.ExpandRow(model.GetPath(iter), false); model.IterChildren(out iter, iter); FindItemRecursive(iter, path); } else { tvItems.Selection.SelectIter(iter); tvItems.ScrollToCell(model.GetPath(iter), null, false, .0f, .0f); } break; } hasMoreIters = model.IterNext(ref iter); } }
private void OnTvItemsSelectionChanged(object o, EventArgs args) { // get selected item TreeIter iter; if (!tvItems.GetSelectedIter(out iter)) { return; } VolumeItem item = tvItems.GetItem(iter); // null -> not an item row (e.g. the "loading" row) if (item == null) { return; } if (App.Settings.ShowItemInfo) { itemInfo.ShowInfo(item, database); } else if (itemInfo.Visible) { itemInfo.Hide(); } }
public VolumeItem GetItem(TreeIter iter) { if (item_col < 0) { return(null); } VolumeItem item = (VolumeItem)Model.GetValue(iter, item_col); return(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); } }
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 void CellDataFunc(TreeViewColumn column, CellRenderer cell, TreeModel model, TreeIter iter) { VolumeItem item = GetItem(iter); Gtk.CellRendererText txt = cell as Gtk.CellRendererText; if ((item != null) && ((item.Note.Length > 0) || (item.Keywords.Length > 0))) { txt.Style = Pango.Style.Italic; //txt.Foreground = "darkgreen"; txt.Text = txt.Text + " *"; } else { txt.Style = Pango.Style.Normal; //txt.Foreground = null; } }
public override void Execute(SharedObjects shared) { object pathObject = PopValueAssert(shared, true); AssertArgBottomAndConsume(shared); GlobalPath path = shared.VolumeMgr.GlobalPathFromObject(pathObject); Volume volume = shared.VolumeMgr.GetVolumeFromPath(path); VolumeItem volumeItem = volume.Open(path); if (volumeItem == null) { throw new KOSException("File or directory does not exist: " + path); } ReturnValue = volumeItem; }
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)); } }
private void EditItem() { TreeIter iter = TreeIter.Zero; if (!tvSearchResult.GetSelectedIter(out iter)) { return; } // load item properties VolumeItem item = tvSearchResult.GetItem(iter); if (item == null) { return; } new ItemProperties(item); }
public override void Execute(SafeSharedObjects shared) { object pathObject = PopValueAssert(shared, true); AssertArgBottomAndConsume(shared); GlobalPath path = shared.VolumeMgr.GlobalPathFromObject(pathObject); Volume volume = shared.VolumeMgr.GetVolumeFromPath(path); VolumeItem volumeItem = volume.Open(path); if (volumeItem == null) { ReturnValue = new BooleanValue(false); } else { ReturnValue = volumeItem; } }
private void ShowItemInMainWindow() { TreeIter iter = TreeIter.Zero; if (!tvSearchResult.GetSelectedIter(out iter)) { return; } VolumeItem item = tvSearchResult.GetItem(iter); if (item == null) { return; } Destroy(); mainWindow.FindItem(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(); }
private void CompareDirectories(GlobalPath dir1Path, GlobalPath dir2Path) { Volume dir1Volume = volumeManager.GetVolumeFromPath(dir1Path); Volume dir2Volume = volumeManager.GetVolumeFromPath(dir2Path); VolumeDirectory dir1 = dir1Volume.Open(dir1Path) as VolumeDirectory; VolumeDirectory dir2 = dir2Volume.Open(dir2Path) as VolumeDirectory; Assert.NotNull(dir1); Assert.NotNull(dir2); int dir1Count = dir1.List().Count; int dir2Count = dir2.List().Count; if (dir1Count != dir2Count) { Assert.Fail("Item count not equal: " + dir1Count + " != " + dir2Count); } foreach (KeyValuePair <string, VolumeItem> pair in dir1.List()) { VolumeItem dir2Item = dir2Volume.Open(dir2Path.Combine(pair.Key)); if (pair.Value is VolumeDirectory && dir2Item is VolumeDirectory) { CompareDirectories(dir1Path.Combine(pair.Key), dir2Path.Combine(pair.Key)); } else if (pair.Value is VolumeFile && dir2Item is VolumeFile) { VolumeFile file1 = pair.Value as VolumeFile; VolumeFile file2 = dir2Item as VolumeFile; Assert.AreEqual(file1.ReadAll(), file2.ReadAll()); } else { Assert.Fail("Items are not of the same type: " + dir1Path.Combine(pair.Key) + ", " + dir2Path.Combine(pair.Key)); } } }
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); }
protected static void DelegateLoadContents(KOSTextEditPopup me) { VolumeItem item = me.loadingVolume.Open(me.loadingPath); if (item == null) { me.term.Print("[New File]"); me.contents = ""; } else if (item is VolumeFile) { VolumeFile file = item as VolumeFile; me.loadingPath = GlobalPath.FromVolumePath(item.Path, me.loadingPath.VolumeId); me.contents = file.ReadAll().String; } else { throw new KOSPersistenceException("Path '" + me.loadingPath + "' points to a directory"); } me.volume = me.loadingVolume; me.isDirty = false; }
private void EditItem() { TreeIter iter; if (!tvItems.GetSelectedIter(out iter)) { return; } // load item properties VolumeItem item = tvItems.GetItem(iter); // null -> not an item row (e.g. the "loading" row) if (item == null) { return; } new ItemProperties(item); // ip.Saved += delegate { // tvItems.UpdateItem(iter, item); // }; }
public void ShowInfo(VolumeItem item, VolumeDatabase db) { if (item == null) { throw new ArgumentNullException("item"); } if (db == null) { throw new ArgumentNullException("db"); } // update item preview itemPreview.Preview(item, db); if (!itemPreview.EnableGenericIcons && !Minimized) { if (itemPreview.IsThumbnailPreview) { itemPreview.Show(); } else { itemPreview.Hide(); } } // update item properties FillPropertyBox(item); // HACK : // somehow the cells of the outer hbox // don't match the gradient of this widget // if ShowInfo() is called a second time. outerBox.QueueDraw(); this.Show(); }
private void FillPropertyBox(VolumeItem item) { ItemProperty[] properties; Dictionary <string, string> nameProperty; switch (item.GetVolumeItemType()) { case VolumeItemType.FileVolumeItem: case VolumeItemType.DirectoryVolumeItem: ItemProperty.GetFSItemProperties((FileSystemVolumeItem)item, out properties, out nameProperty); break; case VolumeItemType.AudioTrackVolumeItem: ItemProperty.GetAudioCdItemProperties((AudioTrackVolumeItem)item, out properties, out nameProperty); break; default: throw new NotImplementedException("Iteminfo has not been implemented for this itemtype yet"); } propertyBox.SetProperties(properties); string tmp; if (nameProperty.TryGetValue("title", out tmp)) { // title found (e.g. html or doc file) // may be followed optionally by artist and/or album (audio file) StringBuilder sbName = new StringBuilder(); StringBuilder sbTooltip = new StringBuilder(); sbName.AppendFormat("<b>{0}</b>", Util.Escape(tmp)); sbTooltip.Append(tmp); if (nameProperty.TryGetValue("artist", out tmp)) { sbName.AppendFormat(" <i>{0}</i> {1}", STR_BY, Util.Escape(tmp)); sbTooltip.AppendFormat(" {0} {1}", STR_BY, tmp); } if (nameProperty.TryGetValue("album", out tmp)) { sbName.AppendFormat(" <i>{0}</i> {1}", STR_FROM, Util.Escape(tmp)); sbTooltip.AppendFormat(" {0} {1}", STR_FROM, tmp); } propertyBox.SetNameProperty(sbName.ToString(), sbTooltip.ToString()); } else { // name expected if (!nameProperty.TryGetValue("name", out tmp)) { throw new ArgumentException("Name expected"); } propertyBox.SetNameProperty(string.Format("<b>{0}</b>", Util.Escape(tmp)), tmp); } }
private static void GetCommonItemProperties(VolumeItem item, out List <ItemProperty> properties, out Dictionary <string, string> nameProperty) { List <ItemProperty> tmp = new List <ItemProperty>(); nameProperty = new Dictionary <string, string>(); // // add metadata properties first (higher priority) // if (!item.MetaData.IsEmpty) { Dictionary <MetadataType, string> metadata = item.MetaData.ToDictionary(); // // cherry-pick interesting properties // string val; /* audio properties*/ if (metadata.TryGetValue(MetadataType.GENRE, out val)) { // NOTE: genre keyword is used in e.g. deb packages as well tmp.Add(new ItemProperty(S._("Genre"), RemoveSimilarIDTags(val), 105)); } if (metadata.TryGetValue(MetadataType.ARTIST, out val)) { //tmp2.Add(new ItemProperty(S._("Artist"), val, 101)); nameProperty.Add("artist", RemoveSimilarIDTags(val)); } if (metadata.TryGetValue(MetadataType.TITLE, out val)) { // NOTE: title keyword is used in e.g. html or doc files as well //tmp2.Add(new ItemProperty(S._("Title"), val, 101)); nameProperty.Add("title", RemoveSimilarIDTags(val)); } if (metadata.TryGetValue(MetadataType.ALBUM, out val)) { //tmp2.Add(new ItemProperty(S._("Album"), val, 103)); nameProperty.Add("album", RemoveSimilarIDTags(val)); } if (metadata.TryGetValue(MetadataType.YEAR, out val)) { tmp.Add(new ItemProperty(S._("Year"), RemoveSimilarIDTags(val), 104)); } if (metadata.TryGetValue(MetadataType.DESCRIPTION, out val)) { // NOTE: description keyword is used in e.g. html files as well tmp.Add(new ItemProperty(S._("Description"), RemoveSimilarIDTags(val), 110)); } /* audio / picture / video properties */ if (metadata.TryGetValue(MetadataType.DURATION, out val)) { tmp.Add(new ItemProperty(S._("Duration"), FormatDuration(MetadataUtils.MetadataDurationToTimespan(val)), 106)); } if (metadata.TryGetValue(MetadataType.SIZE, out val)) { // NOTE: size keyword is used in e.g. deb packages as well (unpacked size in kb) if (item.MimeType.StartsWith("image") || item.MimeType.StartsWith("video")) { tmp.Add(new ItemProperty(S._("Dimensions"), val, 107)); } } /* other properties*/ if (metadata.TryGetValue(MetadataType.FORMAT, out val)) { tmp.Add(new ItemProperty(S._("Format"), val, 108)); } if (metadata.TryGetValue(MetadataType.AUTHOR, out val)) { tmp.Add(new ItemProperty(S._("Author"), val, 111)); } if (metadata.TryGetValue(MetadataType.COPYRIGHT, out val)) { tmp.Add(new ItemProperty(S._("Copyright"), val, 112)); } if (metadata.TryGetValue(MetadataType.PRODUCER, out val)) { tmp.Add(new ItemProperty(S._("Producer"), val, 115)); } if (metadata.TryGetValue(MetadataType.CREATOR, out val)) { tmp.Add(new ItemProperty(S._("Creator"), val, 114)); } if (metadata.TryGetValue(MetadataType.SOFTWARE, out val)) { tmp.Add(new ItemProperty(S._("Software"), val, 116)); } if (metadata.TryGetValue(MetadataType.LANGUAGE, out val)) { tmp.Add(new ItemProperty(S._("Language"), val, 113)); } if (metadata.TryGetValue(MetadataType.PAGE_COUNT, out val)) { tmp.Add(new ItemProperty(S._("Page count"), val, 109)); } if (metadata.TryGetValue(MetadataType.FILENAME, out val)) { // count files in archives // (filenames were joined by MetadataStore.ToDictionary()) int filecount = 0; int lastIndex = -1; while ((lastIndex = val.IndexOf(';', lastIndex + 1)) != -1) { // only count files, skip directory names if ((val[lastIndex - 1] != '/') && (val[lastIndex - 1] != '\\')) { filecount++; } } if ((val[val.Length - 1] != '/') && (val[val.Length - 1] != '\\')) { filecount++; } if (filecount > 0) { tmp.Add(new ItemProperty(S._("File count"), filecount.ToString(), 117)); } } if (Global.EnableDebugging) { foreach (KeyValuePair <MetadataType, string> pair in metadata) { Platform.Common.Diagnostics.Debug.WriteLine( String.Format("{0}: {1}", pair.Key, pair.Value)); } } } // // add common item properties (low priority, shown only if there's room left) // if (!nameProperty.ContainsKey("title")) { // no title metadata // or artist and/or album metadata only nameProperty.Clear(); // use name instead nameProperty.Add("name", item.Name); } if (item.Note.Length > 0) { tmp.Add(new ItemProperty(S._("Note"), item.Note, 301)); } if (item.Keywords.Length > 0) { tmp.Add(new ItemProperty(S._("Keywords"), item.Keywords, 302)); } properties = tmp; }
public VolumeItem GetItem(TreeIter iter) { VolumeItem item = (VolumeItem)Model.GetValue(iter, 2); return(item); }