diff options
author | Jay Freeman (saurik) <saurik@saurik.com> | 2008-12-10 12:34:44 +0000 |
---|---|---|
committer | Jay Freeman (saurik) <saurik@saurik.com> | 2010-09-30 07:09:14 +0000 |
commit | 0adc554ba6925144bab4bcd29fd2371a032cb458 (patch) | |
tree | aeecf3ac4832e7dbecc8a5f69f8990ffb7ea1074 | |
parent | 59c011d87e67a2b7a44bf70576c7fa10e85698bc (diff) |
Finished implementing Storage.
-rw-r--r-- | Cydia.app/storage.html | 116 | ||||
-rw-r--r-- | Cydia.app/storage.js | 39 | ||||
-rw-r--r-- | Cydia.mm | 26 | ||||
-rw-r--r-- | UICaboodle/BrowserView.m | 29 |
4 files changed, 130 insertions, 80 deletions
diff --git a/Cydia.app/storage.html b/Cydia.app/storage.html index 21a87ad..bd208f9 100644 --- a/Cydia.app/storage.html +++ b/Cydia.app/storage.html @@ -96,53 +96,81 @@ } 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; @@ -181,13 +209,15 @@ <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> @@ -201,25 +231,15 @@ <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> diff --git a/Cydia.app/storage.js b/Cydia.app/storage.js index 926a61d..02dc51b 100644 --- a/Cydia.app/storage.js +++ b/Cydia.app/storage.js @@ -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]); }; @@ -4755,30 +4755,6 @@ bool DepSubstrate(const pkgCache::VerIterator &iterator) { @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 {{{ */ @interface ManageView : BrowserView { } @@ -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"]) diff --git a/UICaboodle/BrowserView.m b/UICaboodle/BrowserView.m index cb16bc8..93e253b 100644 --- a/UICaboodle/BrowserView.m +++ b/UICaboodle/BrowserView.m @@ -240,8 +240,22 @@ - (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)); @@ -253,8 +267,15 @@ } } - 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; } |