~ubuntu-branches/ubuntu/saucy/f-spot/saucy

« back to all changes in this revision

Viewing changes to lib/Hyena/src/Hyena/Hyena.Query/FileSizeQueryValue.cs

  • Committer: Bazaar Package Importer
  • Author(s): Iain Lane
  • Date: 2010-05-24 10:35:57 UTC
  • mfrom: (2.4.7 experimental)
  • Revision ID: james.westby@ubuntu.com-20100524103557-1j0i8f66caybci2n
Tags: 0.7.0-1
* New upstream release 0.7.0
 + First release of the unstable 0.7 development series. Massive changes.
 + Reparenting and detaching support (Anton Keks) (Closes: #559745)
 + A new Mallard-based documentation (Harold Schreckengost)
 + No longer embeds flickrnet, uses distribution copy (Iain Lane)
 + Adoption of a large amount of Hyena functionality (Paul Lange, Peter
   Goetz)
 + No longer embeds gnome-keyring-sharp
 + Completely rewritten import, much faster and less memory hungry (Ruben
   Vermeersch) (Closes: #559080, #492658, #341790, #357811, #426017) (LP:
   #412091)
 + No longer use gphoto2-sharp, now uses gvfs which is less crash-pron
   (Ruben Vermeersch)
 + Fix Facebook support (Ruben Vermeersch)
 + Modernized unit tests
 + Revamped build (Mike Gemünde)
 + Much improved duplicate detection (much faster too) (Ruben Vermeersch)
 + Mouse selection in Iconview (Vincent Pomey)
 + Image panning support using middle mouse button (Wojciech Dzierżanowski)
 + Timeline slider now restricted to the size of the window (Iain Churcher)
 + Over 100 bugs closed (http://bit.ly/cyVjnD)
   - No more warnings about schema defaults (Closes: #584215) (LP: #586132)
* debian/control: Clean up build deps to match configure checks
* debian/rules: Don't run dh_makeshilbs as we don't ship any shared
  libraries. There are some private ones though, which get picked up and
  result in a useless postinst/postrm call to ldconfig. Thanks, lintian.
* debian/patches/debian_fix-distclean.patch,
  debian/patches/debian_fix_f-spot.exe.config.patch,
  debian/patches/debian_link-system-flickrnet.patch,
  debian/patches/debian_link-system-gnome-keyring.patch,
  debian/patches/debian_disable-unit-tests,
  debian/patches/git_transition_duration.patch,
  debian/patches/ubuntu_fix_folder_export_hang.patch:
  Clean up obsolete patches which are no longer necessary 
* debian/patches/*: Temporarily disable patches which originated from Ubuntu
  and no longer apply cleanly. We will get these back in a future upstream
  development release.
* debian/patches/*: Refresh to apply cleanly 
* debian/rules: Add new include dir to autoreconf call to pick up f-spot
  macros 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// FileSizeQueryValue.cs
 
3
//
 
4
// Authors:
 
5
//   Gabriel Burt <gburt@novell.com>
 
6
//   Aaron Bockover <abockover@novell.com>
 
7
//
 
8
// Copyright (C) 2007-2008 Novell, Inc.
 
9
//
 
10
// Permission is hereby granted, free of charge, to any person obtaining
 
11
// a copy of this software and associated documentation files (the
 
12
// "Software"), to deal in the Software without restriction, including
 
13
// without limitation the rights to use, copy, modify, merge, publish,
 
14
// distribute, sublicense, and/or sell copies of the Software, and to
 
15
// permit persons to whom the Software is furnished to do so, subject to
 
16
// the following conditions:
 
17
//
 
18
// The above copyright notice and this permission notice shall be
 
19
// included in all copies or substantial portions of the Software.
 
20
//
 
21
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
22
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
23
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
24
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
25
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
26
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
27
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
28
//
 
29
 
 
30
using System;
 
31
using System.Xml;
 
32
using System.Text;
 
33
 
 
34
using Hyena;
 
35
 
 
36
namespace Hyena.Query
 
37
{
 
38
    public enum FileSizeFactor : long {
 
39
        None = 1,
 
40
        KB = 1024,
 
41
        MB = 1048576,
 
42
        GB = 1073741824,
 
43
        TB = 1099511627776,
 
44
        PB = 1125899906842624
 
45
    }
 
46
 
 
47
    public class FileSizeQueryValue : IntegerQueryValue
 
48
    {
 
49
        private FileSizeFactor factor = FileSizeFactor.None;
 
50
        public FileSizeFactor Factor {
 
51
            get { return factor; }
 
52
        }
 
53
 
 
54
        public FileSizeQueryValue ()
 
55
        {
 
56
        }
 
57
 
 
58
        public FileSizeQueryValue (long bytes)
 
59
        {
 
60
            value = bytes;
 
61
            IsEmpty = false;
 
62
            DetermineFactor ();
 
63
        }
 
64
 
 
65
        public double FactoredValue {
 
66
            get { return (double)value / (double)factor; }
 
67
        }
 
68
 
 
69
        public override void ParseUserQuery (string input)
 
70
        {
 
71
            if (input.Length > 1 && (input[input.Length - 1] == 'b' || input[input.Length - 1] == 'B')) {
 
72
                input = input.Substring (0, input.Length - 1);
 
73
            }
 
74
 
 
75
            double double_value;
 
76
            IsEmpty = !Double.TryParse (input, out double_value);
 
77
 
 
78
            if (IsEmpty && input.Length > 1) {
 
79
                IsEmpty = !Double.TryParse (input.Substring (0, input.Length - 1), out double_value);
 
80
            }
 
81
 
 
82
            if (!IsEmpty) {
 
83
                switch (input[input.Length - 1]) {
 
84
                    case 'k': case 'K': factor = FileSizeFactor.KB; break;
 
85
                    case 'm': case 'M': factor = FileSizeFactor.MB; break;
 
86
                    case 'g': case 'G': factor = FileSizeFactor.GB; break;
 
87
                    case 't': case 'T': factor = FileSizeFactor.TB; break;
 
88
                    case 'p': case 'P': factor = FileSizeFactor.PB; break;
 
89
                    default : factor = FileSizeFactor.None; break;
 
90
                }
 
91
                value = (long)((double)factor * double_value);
 
92
            }
 
93
        }
 
94
 
 
95
        public override void ParseXml (XmlElement node)
 
96
        {
 
97
            base.ParseUserQuery (node.InnerText);
 
98
            if (node.HasAttribute ("factor")) {
 
99
                this.factor = (FileSizeFactor) Enum.Parse (typeof(FileSizeFactor), node.GetAttribute ("factor"));
 
100
            } else {
 
101
                DetermineFactor ();
 
102
            }
 
103
        }
 
104
 
 
105
        public override void AppendXml (XmlElement node)
 
106
        {
 
107
            base.AppendXml (node);
 
108
            node.SetAttribute ("factor", factor.ToString ());
 
109
        }
 
110
 
 
111
        public void SetValue (double value, FileSizeFactor factor)
 
112
        {
 
113
            this.value = (long)(value * (double)factor);
 
114
            this.factor = factor;
 
115
            IsEmpty = false;
 
116
        }
 
117
 
 
118
        protected void DetermineFactor ()
 
119
        {
 
120
            if (!IsEmpty && value != 0) {
 
121
                foreach (FileSizeFactor factor in Enum.GetValues (typeof(FileSizeFactor))) {
 
122
                    if (value >= (double)factor) {
 
123
                        this.factor = factor;
 
124
                    }
 
125
                }
 
126
            }
 
127
        }
 
128
 
 
129
        public override string ToUserQuery ()
 
130
        {
 
131
            return ToUserQuery (false);
 
132
        }
 
133
 
 
134
        public string ToUserQuery (bool always_decimal)
 
135
        {
 
136
            if (factor != FileSizeFactor.None) {
 
137
                return String.Format ("{0} {1}",
 
138
                    IntValue == 0
 
139
                        ? "0"
 
140
                        : StringUtil.DoubleToTenthsPrecision (((double)IntValue / (double)factor), always_decimal),
 
141
                    factor.ToString ()
 
142
                );
 
143
            } else {
 
144
                return base.ToUserQuery ();
 
145
            }
 
146
        }
 
147
    }
 
148
}