From 6c3d7e446ea1a0aaf0d04996111a3e92bddedaf5 Mon Sep 17 00:00:00 2001
From: "Sidhant Sharma [:TigerKid001]" <tigerkid001@gmail.com>
Date: Fri, 24 Oct 2014 09:11:33 +0530
Subject: [PATCH] Status line enhancement v1.1
---
src/kits/tracker/CountView.cpp | 70 +++++++++++++++++++++++++++++++++++++++---
src/kits/tracker/CountView.h | 3 ++
src/kits/tracker/PoseView.cpp | 2 +-
3 files changed, 70 insertions(+), 5 deletions(-)
diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp
index a1d3c7c..02ee6c9 100644
a
|
b
|
All rights reserved.
|
47 | 47 | #include "Bitmaps.h" |
48 | 48 | #include "ContainerWindow.h" |
49 | 49 | #include "DirMenu.h" |
| 50 | #include "Entry.h" |
| 51 | #include "Model.h" |
50 | 52 | #include "PoseView.h" |
| 53 | #include "StringForSize.h" |
51 | 54 | #include "Utilities.h" |
52 | 55 | |
53 | 56 | |
… |
… |
BCountView::BCountView(BRect bounds, BPoseView* view)
|
66 | 69 | BView(bounds, "CountVw", B_FOLLOW_LEFT + B_FOLLOW_BOTTOM, |
67 | 70 | B_PULSE_NEEDED | B_WILL_DRAW), |
68 | 71 | fLastCount(-1), |
| 72 | fFileCount(0), |
| 73 | fDirCount(0), |
| 74 | fTotalFilesSize(0), |
69 | 75 | fPoseView(view), |
70 | 76 | fShowingBarberPole(false), |
71 | 77 | fBorderHighlighted(false), |
… |
… |
BCountView::CheckCount()
|
198 | 204 | // invalidate the count text area if necessary |
199 | 205 | if (fLastCount != fPoseView->CountItems()) { |
200 | 206 | fLastCount = fPoseView->CountItems(); |
| 207 | _UpdateCountsAndSizes(); |
201 | 208 | Invalidate(TextInvalRect()); |
202 | 209 | } |
203 | 210 | |
… |
… |
BCountView::CheckCount()
|
207 | 214 | |
208 | 215 | |
209 | 216 | void |
| 217 | BCountView::_UpdateCountsAndSizes() |
| 218 | { |
| 219 | fFileCount = 0; |
| 220 | fDirCount = 0; |
| 221 | fTotalFilesSize = 0; |
| 222 | if(fLastCount != fPoseView->CountItems()) |
| 223 | fLastCount = fPoseView->CountItems(); |
| 224 | |
| 225 | node_ref ref; |
| 226 | Model* model = fPoseView->TargetModel(); |
| 227 | if(model->IsDirectory()) |
| 228 | ref = *model->NodeRef(); |
| 229 | else |
| 230 | // we can't check for files and folders if model is not a directory |
| 231 | return; |
| 232 | |
| 233 | BDirectory dir(&ref); |
| 234 | dir.Rewind(); |
| 235 | BEntry entry; |
| 236 | while (dir.GetNextEntry(&entry) == B_OK) { |
| 237 | StatStruct statbuf; |
| 238 | status_t status = entry.GetStat(&statbuf); |
| 239 | if (status != B_OK) |
| 240 | return; |
| 241 | |
| 242 | if (S_ISDIR(statbuf.st_mode)) |
| 243 | fDirCount++; |
| 244 | else { |
| 245 | fFileCount++; |
| 246 | off_t fileSize = 0; |
| 247 | fileSize = statbuf.st_size; |
| 248 | fTotalFilesSize += fileSize; |
| 249 | } |
| 250 | } |
| 251 | } |
| 252 | |
| 253 | |
| 254 | void |
210 | 255 | BCountView::Draw(BRect updateRect) |
211 | 256 | { |
212 | 257 | BRect bounds(Bounds()); |
… |
… |
BCountView::Draw(BRect updateRect)
|
222 | 267 | be_control_look->DrawMenuBarBackground(this, bounds, updateRect, |
223 | 268 | ViewColor()); |
224 | 269 | } |
225 | | |
226 | 270 | BString itemString; |
| 271 | BString fileString, folderString, sizeString; |
227 | 272 | if (IsTypingAhead()) |
228 | 273 | itemString << TypeAhead(); |
229 | 274 | else if (IsFiltering()) { |
… |
… |
BCountView::Draw(BRect updateRect)
|
232 | 277 | if (fLastCount == 0) |
233 | 278 | itemString << B_TRANSLATE("no items"); |
234 | 279 | else { |
235 | | static BMessageFormat format(B_TRANSLATE_COMMENT( |
| 280 | static BMessageFormat itemFormat(B_TRANSLATE_COMMENT( |
236 | 281 | "{0, plural, one{# item} other{# items}}", |
237 | 282 | "Number of selected items: \"1 item\" or \"2 items\"")); |
238 | | format.Format(itemString, fLastCount); |
| 283 | itemFormat.Format(itemString, fLastCount); |
| 284 | |
| 285 | itemString += " | "; |
| 286 | static BMessageFormat folderFormat(B_TRANSLATE_COMMENT( |
| 287 | "{0, plural, one{# folder} other{# folders}}", |
| 288 | "Number of selected folders: \"1 folder\" or \"2 folders\"")); |
| 289 | folderFormat.Format(folderString, fDirCount); |
| 290 | itemString += folderString; |
| 291 | |
| 292 | itemString += " | "; |
| 293 | static BMessageFormat fileFormat(B_TRANSLATE_COMMENT( |
| 294 | "{0, plural, one{# file} other{# files}} (%size%)", |
| 295 | "Number of selected folders: \"1 file\" or \"2 files\"")); |
| 296 | fileFormat.Format(fileString, fFileCount); |
| 297 | char sizeBuffer[128]; |
| 298 | sizeString = string_for_size((double)fTotalFilesSize, |
| 299 | sizeBuffer, sizeof(sizeBuffer)); |
| 300 | fileString.ReplaceFirst("%size%", sizeString); |
| 301 | itemString += fileString; |
239 | 302 | } |
240 | 303 | } |
241 | | |
242 | 304 | BRect textRect(TextInvalRect()); |
243 | 305 | |
244 | 306 | TruncateString(&itemString, IsTypingAhead() ? B_TRUNCATE_BEGINNING |
diff --git a/src/kits/tracker/CountView.h b/src/kits/tracker/CountView.h
index 52ad97e..2ec5007 100644
a
|
b
|
private:
|
78 | 78 | BRect TextInvalRect() const; |
79 | 79 | BRect TextAndBarberPoleRect() const; |
80 | 80 | void TrySpinningBarberPole(); |
| 81 | void _UpdateCountsAndSizes(); |
81 | 82 | |
82 | 83 | int32 fLastCount; |
| 84 | int32 fFileCount, fDirCount; |
| 85 | off_t fTotalFilesSize; |
83 | 86 | BPoseView* fPoseView; |
84 | 87 | bool fShowingBarberPole : 1; |
85 | 88 | bool fBorderHighlighted : 1; |
diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
index ae04731..a13b00c 100644
a
|
b
|
using std::max;
|
113 | 113 | |
114 | 114 | |
115 | 115 | const float kDoubleClickTresh = 6; |
116 | | const float kCountViewWidth = 76; |
| 116 | const float kCountViewWidth = 250; |
117 | 117 | |
118 | 118 | const uint32 kAddNewPoses = 'Tanp'; |
119 | 119 | const uint32 kAddPosesCompleted = 'Tapc'; |