TransferView.cs :  » Business-Application » DC » DCSharp » GUI » C# / CSharp Open Source

Home
C# / CSharp Open Source
1.2.6.4 mono .net core
2.2.6.4 mono core
3.Aspect Oriented Frameworks
4.Bloggers
5.Build Systems
6.Business Application
7.Charting Reporting Tools
8.Chat Servers
9.Code Coverage Tools
10.Content Management Systems CMS
11.CRM ERP
12.Database
13.Development
14.Email
15.Forum
16.Game
17.GIS
18.GUI
19.IDEs
20.Installers Generators
21.Inversion of Control Dependency Injection
22.Issue Tracking
23.Logging Tools
24.Message
25.Mobile
26.Network Clients
27.Network Servers
28.Office
29.PDF
30.Persistence Frameworks
31.Portals
32.Profilers
33.Project Management
34.RSS RDF
35.Rule Engines
36.Script
37.Search Engines
38.Sound Audio
39.Source Control
40.SQL Clients
41.Template Engines
42.Testing
43.UML
44.Web Frameworks
45.Web Service
46.Web Testing
47.Wiki Engines
48.Windows Presentation Foundation
49.Workflows
50.XML Parsers
C# / C Sharp
C# / C Sharp by API
C# / CSharp Tutorial
C# / CSharp Open Source » Business Application » DC 
DC » DCSharp » GUI » TransferView.cs
/*
 * 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 System.Collections.Generic;

using Gtk;
using Mono.Unix;

using DCSharp.Backend.Objects;

namespace DCSharp.GUI{
  // NOTE: Any model used with this class must contains the following
  // columns.
  public enum TransferStoreColumn
  {
    Object,
    Name,
    Directory,
    SizeText,
    Size,
    Position,
    ProgressText,
    Progress,
    TimeLeft
  };
  
  public class TransferView : ExtendedTreeView
  {
    public TransferView(TreeModel model) : base(model)
    {
      // Columns
      TreeViewColumn column;
      CellRendererPixbuf pixbufRenderer;
      CellRendererText textRenderer;
      CellRendererProgress progressRenderer;
      
      // Name
      column = new TreeViewColumn();
      column.Title = Catalog.GetString("Name");
      column.Expand = true;
      column.Resizable = true;
      column.SortColumnId = (int)TransferStoreColumn.Name;
      AppendColumn(column);
      
      pixbufRenderer = new CellRendererPixbuf();
      column.PackStart(pixbufRenderer, false);
      column.SetCellDataFunc(pixbufRenderer, SetPixbuf);
      
      textRenderer = new CellRendererText();
      textRenderer.Ellipsize = Pango.EllipsizeMode.End;
      column.PackStart(textRenderer, true);
      column.AddAttribute(textRenderer, "text",
        (int)TransferStoreColumn.Name);
      column.SetCellDataFunc(textRenderer, SetTextStyle);
      
      ExpanderColumn = column;
      
      // Size
      textRenderer = new CellRendererText();
      column = AppendColumn(Catalog.GetString("Size"), textRenderer,
        "text", (int)TransferStoreColumn.SizeText);
      column.SortColumnId = (int)TransferStoreColumn.Size;
      column.SetCellDataFunc(textRenderer, SetTextStyle);
      
      // Status
      textRenderer = new CellRendererText();
      //textRenderer.Ellipsize = Pango.EllipsizeMode.End;
      column = AppendColumn(Catalog.GetString("Status"), textRenderer);
      column.Resizable = true;
      column.SetCellDataFunc(textRenderer, SetStatusText);
      
      // Progress
      progressRenderer = new CellRendererProgress();
      column = AppendColumn(Catalog.GetString("Progress"), progressRenderer);
      column.Resizable = true;
      column.AddAttribute(progressRenderer, "text",
        (int)TransferStoreColumn.ProgressText);
      column.AddAttribute(progressRenderer, "value",
        (int)TransferStoreColumn.Progress);
      column.SortColumnId = (int)TransferStoreColumn.Progress;
      
      // Time left
      textRenderer = new CellRendererText();
      column = AppendColumn(Catalog.GetString("Time Left"), textRenderer,
        "text", (int)TransferStoreColumn.TimeLeft);
      column.SortColumnId = (int)TransferStoreColumn.TimeLeft;
      column.SetCellDataFunc(textRenderer, SetTextStyle);
    }
    
    #region Methods
    
    public T[] GetSelectedTransfers<T>(bool recurse) where T : TransferFileInfo
    {
      TreeIter[] selectedIters = GetSelectedIters();
      List<T> transfers = new List<T>();
      
      foreach (TreeIter iter in selectedIters)
      {
        AddTransfersToList(transfers, iter, recurse);
      }
      return transfers.ToArray();
    }
    
    private void AddTransfersToList<T>(List<T> transfers, TreeIter iter,
      bool recurse) where T : TransferFileInfo
    {
      TreeIter childIter;
      
      T transfer = Model.GetValue(iter, (int)TransferStoreColumn.Object) as T;
      if (transfer != null)
      {
        if (!transfers.Contains(transfer))
        {
          transfers.Add(transfer);
        }
      }
      else if (recurse && Model.IterChildren(out childIter, iter))
      {
        do
        {
          AddTransfersToList(transfers, childIter, true);
        }
        while (Model.IterNext(ref childIter));
      }
    }
    
    #region CellDataFuncs
    
    protected virtual void SetPixbuf(TreeViewColumn column,
      CellRendererPixbuf pixbufRenderer, TreeModel model, TreeIter iter,
      object obj)
    {
      TransferFileInfo transfer = obj as TransferFileInfo;
      if (transfer != null)
      {
        if (transfer.Name != null)
        {
          pixbufRenderer.Pixbuf = Util.GetIconFromPath(transfer.Name);
        }
        else
        {
          pixbufRenderer.Pixbuf = null;
        }
      }
    }
    
    protected virtual void SetStatusText(TreeViewColumn column,
      CellRendererText textRenderer, TreeModel model, TreeIter iter,
      object obj)
    {
      TransferFileInfo transfer = obj as TransferFileInfo;
      
      textRenderer.Text = Util.GetStatus(transfer);
      
      SetTextStyle(column, textRenderer, model, iter, obj);
    }
    
    protected virtual void SetTextStyle(TreeViewColumn column,
      CellRendererText textRenderer, TreeModel model, TreeIter iter,
      object obj)
    {
      TransferFileInfo transfer = obj as TransferFileInfo;
      if (transfer != null && !transfer.Active &&
        transfer.Position < transfer.Size)
      {
        textRenderer.Foreground = "dim grey";
      }
      else
      {
        textRenderer.Foreground = "black";
      }
    }
    
    private void SetPixbuf(TreeViewColumn column, CellRenderer renderer,
      TreeModel model, TreeIter iter)
    {
      object obj = model.GetValue(iter, (int)TransferStoreColumn.Object);
      
      SetPixbuf(column, (CellRendererPixbuf)renderer, model, iter, obj);
    }
    
    private void SetStatusText(TreeViewColumn column, CellRenderer renderer,
      TreeModel model, TreeIter iter)
    {
      object obj = model.GetValue(iter, (int)TransferStoreColumn.Object);
      
      SetStatusText(column, (CellRendererText)renderer, model, iter, obj);
    }
    
    private void SetTextStyle(TreeViewColumn column, CellRenderer renderer,
      TreeModel model, TreeIter iter)
    {
      object obj = model.GetValue(iter, (int)TransferStoreColumn.Object);
      
      SetTextStyle(column, (CellRendererText)renderer, model, iter, obj);
    }
    
    #endregion
    
    #endregion
  }
}
www.java2v.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.