]> git.saurik.com Git - cydia.git/commitdiff
Finished implementing Storage.
authorJay Freeman (saurik) <saurik@saurik.com>
Wed, 10 Dec 2008 12:34:44 +0000 (12:34 +0000)
committerJay Freeman (saurik) <saurik@saurik.com>
Thu, 30 Sep 2010 07:09:14 +0000 (07:09 +0000)
Cydia.app/storage.html
Cydia.app/storage.js
Cydia.mm
UICaboodle/BrowserView.m

index 21a87adc99d87af1e9cb1a6917d30cf96eb8d37f..bd208f9c2090e2bfa3908d20d16e69ad94ad9791 100644 (file)
         }
 
         piechart > div {
+            -webkit-border-radius: 50px;
             height: 100px;
-            padding: 1px;
+            overflow: hidden;
             position: relative;
-            width: 103px;
+            width: 100px;
         }
 
-        piechart > div > div.lslice,
-        piechart > div > div.rslice {
-            background-color: #4d4d70;
+        piechart > div > div:first-child {
             height: 100px;
+            overflow: hidden;
             position: absolute;
+            z-index: 102;
+            width: 51px;
         }
 
-        piechart > div > div.lslice {
-            -webkit-border-bottom-left-radius: 50px;
-            -webkit-border-top-left-radius: 50px;
-            width: 50px;
-            z-index: 2;
+        piechart > div > div:last-child {
+            height: 100px;
+            overflow: hidden;
+            position: absolute;
+            width: 100px;
+            z-index: 0;
         }
 
-        piechart > div > div.rslice {
-            -webkit-border-bottom-right-radius: 50px;
-            -webkit-border-top-right-radius: 50px;
-            left: 49px;
-            width: 53px;
-            z-index: 0;
+        piechart > div div.lslice,
+        piechart > div div.rslice,
+        piechart > div div.tslice,
+        piechart > div div.bslice {
+            background-color: #4d4d70;
         }
 
-        piechart > div > div.xslice {
+        piechart > div div.lslice,
+        piechart > div div.rslice,
+        piechart > div div.tslice,
+        piechart > div div.bslice,
+        piechart > div div.xslice {
+            /* XXX: technically, these aren't needed */
             -webkit-border-bottom-left-radius: 50px;
             -webkit-border-top-left-radius: 50px;
             height: 100px;
-            left: 2px;
             position: absolute;
-            -webkit-transform-origin: 50px 50%;
+            -webkit-transform-origin: 100% 50%;
             width: 50px;
         }
 
-        piechart > div > div.tslice {
+        piechart > div div.lslice {
+            z-index: 100;
+        }
+
+        piechart > div div.rslice,
+        piechart > div div.tslice,
+        piechart > div div.bslice {
+            z-index: 0;
+        }
+
+        piechart > div div.rslice {
+            -webkit-transform: rotate(180deg);
+        }
+
+        piechart > div div.tslice {
+            -webkit-transform: rotate(90deg);
+        }
+
+        piechart > div div.bslice {
+            -webkit-transform: rotate(270deg);
+        }
+
+        piechart > div > div.nslice {
             position: absolute;
             text-align: center;
             top: 42px;
             width: 100px;
-            z-index: 3;
+            z-index: 103;
         }
 
-        piechart > div > div.tslice > div {
+        piechart > div > div.nslice > div {
             background-color: rgba(255, 255, 255, 0.7);
             -webkit-border-radius: 7px;
             display: inline;
 
 <a class="giant-button">
     <div class="contents">
-        <piechart id="system-chart"><div>
-            <div class="lslice"></div>
-            <div class="rslice"></div>
-            <div class="tslice"><div id="system-size"></div></div>
-            <div class="xslice" id="system-slice" style="
-                background-color: #7d7da0; -webkit-transform: rotate(10deg); z-index: 1;
-            "></div>
+        <piechart><div>
+            <div id="system-left"></div>
+            <div id="system-right">
+                <div class="lslice"></div>
+                <div class="rslice"></div>
+                <div class="tslice"></div>
+                <div class="bslice"></div>
+            </div>
+            <div class="nslice"><div id="system-size"></div></div>
         </div></piechart>
 
         <label>System</label>
 
 <a class="giant-button">
     <div class="contents">
-        <piechart id="private-chart"><div>
-            <div class="lslice"></div>
-            <div class="rslice"></div>
-            <div class="tslice"><div id="private-size"></div></div>
-            <div class="xslice" id="private-slice" style="
-                background-color: #9090e0; -webkit-transform: rotate(150deg); z-index: 1;
-            "></div>
-            <div class="xslice" id="private-slice" style="
-                background-color: #7070e0; -webkit-transform: rotate(120deg); z-index: 1;
-            "></div>
-            <div class="xslice" id="private-slice" style="
-                background-color: #d0d0f0; -webkit-transform: rotate(90deg); z-index: 1;
-            "></div>
-            <div class="xslice" id="private-slice" style="
-                background-color: #7da0e0; -webkit-transform: rotate(60deg); z-index: 1;
-            "></div>
-            <div class="xslice" id="private-slice" style="
-                background-color: #7d7da0; -webkit-transform: rotate(30deg); z-index: 1;
-            "></div>
+        <piechart><div>
+            <div id="private-left"></div>
+            <div id="private-right">
+                <div class="lslice"></div>
+                <div class="rslice"></div>
+                <div class="tslice"></div>
+                <div class="bslice"></div>
+            </div>
+            <div class="nslice"><div id="private-size"></div></div>
         </div></piechart>
 
         <label>Private</label>
index 926a61d3b8ca3f43c5de6c3680ab0f7f29839df1..02dc51b7d0859a1208764e118092a1200f47633b 100644 (file)
@@ -9,6 +9,29 @@ var list = function (legend, color, name, value) {
 
 console.log(cydia.statfs("/"));
 
+var cut = function (parent, color, fraction, z) {
+    var deg = Math.round(360 * fraction);
+    if (deg < 2)
+        deg = 2;
+    parent.append('<div class="xslice" style="' +
+        'background-color: ' + color + ';' +
+        '-webkit-transform: rotate(' + deg + 'deg);' +
+        'z-index: ' + z + ';' +
+    '"></div>');
+};
+
+var chart = function (right, left, slices) {
+    var total = 0;
+    for (var i = 0; i != slices.length; ++i) {
+        var slice = slices[i];
+        var z = slices.length - i;
+        if (slice[1] > 0.5)
+            cut(right, slice[0], total + 0.5, z);
+        total += slice[1];
+        cut(total > 0.5 ? left : right, slice[0], total, z);
+    }
+};
+
 var setup = function (name, root, folders) {
     var size = $("#" + name + "-size");
     var statfs = cydia.statfs(root);
@@ -28,16 +51,26 @@ var setup = function (name, root, folders) {
     var legend = $("#" + name + "-legend");
     var used = 0;
 
+    var slices = [];
+
     if (folders != null)
         for (var i = 0; i != folders.length; ++i) {
             var folder = folders[i];
             var usage = cydia.du(folder[1]);
-            list(legend, colors[i + 2], folder[0], usage / kb);
-            total += usage;
+            var color = colors[i + 2];
+            var percent = usage / kb;
+            list(legend, color, folder[0], percent);
+            slices.push([color, percent]);
+            used += usage;
         }
 
     var free = statfs[0] * statfs[2] / 1024;
-    list(legend, colors[0], folders == null ? "Used" : "Other", (kb - free - total) / kb);
+    var other = (kb - free - used) / kb;
+
+    slices.push([colors[0], other]);
+    chart($("#" + name + "-right"), $("#" + name + "-left"), slices);
+
+    list(legend, colors[0], folders == null ? "Used" : "Other", other);
     list(legend, colors[1], "Free", statfs[2] / statfs[1]);
 };
 
index ae230f690c6b0e54a67129d14f666a8e4d4c78c8..bc1c0ccb14a5a20e6bf17b48a8d93859c7689cef 100644 (file)
--- a/Cydia.mm
+++ b/Cydia.mm
@@ -4753,30 +4753,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     return @"About";
 }
 
-@end
-/* }}} */
-/* Storage View {{{ */
-@interface StorageView : BrowserView {
-}
-
-@end
-
-@implementation StorageView
-
-- (NSString *) title {
-    return @"Storage";
-}
-
-#if !AlwaysReload
-- (id) _rightButtonTitle {
-    return nil;
-}
-#endif
-
-- (bool) _loading {
-    return false;
-}
-
 @end
 /* }}} */
 /* Manage View {{{ */
@@ -6759,7 +6735,7 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) {
     if ([href isEqualToString:@"cydia://add-source"])
         return [[[AddSourceView alloc] initWithBook:book_ database:database_] autorelease];
     else if ([href isEqualToString:@"cydia://storage"])
-        return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[StorageView class]];
+        return [self _pageForURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"storage" ofType:@"html"]] withClass:[BrowserView class]];
     else if ([href isEqualToString:@"cydia://sources"])
         return [[[SourceTable alloc] initWithBook:book_ database:database_] autorelease];
     else if ([href isEqualToString:@"cydia://packages"])
index cb16bc8599581cd0ec11c3dc7035ff418cb12f32..93e253b62e7f57891e18a7b8e438f7111ebf3055 100644 (file)
 - (NSNumber *) du:(NSString *)path {
     NSNumber *value(nil);
 
-    /* XXX: omfg this is stupid */
-    if (FILE *du = popen([[@"du -s " stringByAppendingString:path] UTF8String], "r")) {
+    int fds[2];
+    _assert(pipe(fds) != -1);
+
+    pid_t pid(ExecFork());
+    if (pid == 0) {
+        _assert(dup2(fds[1], 1) != -1);
+        _assert(close(fds[0]) != -1);
+        _assert(close(fds[1]) != -1);
+        execlp("du", "du", "-s", [path UTF8String], NULL);
+        exit(1);
+        _assert(false);
+    }
+
+    _assert(close(fds[1]) != -1);
+
+    if (FILE *du = fdopen(fds[0], "r")) {
         char line[1024];
         while (fgets(line, sizeof(line), du) != NULL) {
             size_t length(strlen(line));
             }
         }
 
-        pclose(du);
-    }
+        fclose(du);
+    } else _assert(close(fds[0]));
+
+    int status;
+  wait:
+    if (waitpid(pid, &status, 0) == -1)
+        if (errno == EINTR)
+            goto wait;
+        else _assert(false);
 
     return value;
 }