/*
* Copyright (C) 2006-2007 Eskil Bylund
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
using System;
using Gtk;
using Mono.Unix;
using DCSharp.Xml.FileList;
namespace DCSharp.GUI{
public class FileListingStore : TreeStore
{
public enum Column {
Object,
Name,
Bytes,
Size,
TTH,
Loaded
};
public FileListingStore(FileListing fileListing) : base(typeof(object),
typeof(string), typeof(long), typeof(string), typeof(string),
typeof(bool))
{
FileListing = fileListing;
}
#region Properties
private FileListing fileListing;
public FileListing FileListing
{
get
{
return fileListing;
}
set
{
if (fileListing != null)
{
Clear();
}
fileListing = value;
if (fileListing != null)
{
foreach (Directory directory in fileListing.Directories)
{
int children = directory.Directories.Count +
directory.Files.Count;
string size = String.Format(
Catalog.GetPluralString("{0} object", "{0} objects",
children), children);
TreeIter iter = AppendValues(directory, directory.Name,
(long)children, size);
if (children > 0)
{
// Add placeholder
AppendNode(iter);
}
}
}
}
}
#endregion
#region Methods
public void Load(TreeIter iter)
{
bool loaded = (bool)GetValue(iter, (int)Column.Loaded);
if (!loaded)
{
PopulateIter(iter);
TreeIter placeholder;
if (IterChildren(out placeholder, iter))
{
Remove(ref placeholder);
}
SetValue(iter, (int)Column.Loaded, true);
}
}
private void PopulateIter(TreeIter parent)
{
Directory directory = GetValue(parent, (int)Column.Object)
as Directory;
if (directory != null)
{
string size;
foreach (Directory childDir in directory.Directories)
{
int children = childDir.Directories.Count +
childDir.Files.Count;
size = String.Format(Catalog.GetPluralString("{0} object", "{0} objects",
children), children);
TreeIter iter = AppendValues(parent, childDir, childDir.Name,
(long)children, size);
if (children > 0)
{
// Add placeholder
AppendNode(iter);
}
}
foreach (File file in directory.Files)
{
size = Util.FormatFileSize(file.Size);
AppendValues(parent, file, file.Name, file.Size, size,
file.TTH);
}
}
}
#endregion
}
}
|