Ticket #1247: volumebar.diff
File volumebar.diff, 7.8 KB (added by , 17 years ago) |
---|
-
src/kits/tracker/PoseList.h
64 64 BPose *DeepFindPose(const node_ref *node, int32 *index = NULL) const; 65 65 // same as FindPose, node can be a target of the actual 66 66 // pose if the pose is a symlink 67 BPose *Find VolumePose(const dev_t device, int32 *index = NULL) const;67 BPose *FindNextVolumePose(int32 *currentIndex) const; 68 68 }; 69 69 70 70 // iteration glue, add permutations as needed -
src/kits/tracker/PoseView.cpp
2338 2338 TrackerSettings().SetShowVolumeSpaceBar(enabled); 2339 2339 // supposed to fall through 2340 2340 case kSpaceBarColorChanged: 2341 UpdateVolumeIcons( );2341 UpdateVolumeIcons(true); 2342 2342 break; 2343 2343 case kUpdateVolumeSpaceBar: 2344 dev_t device; 2345 message->FindInt32("device", (int32 *)&device); 2346 UpdateVolumeIcon(device); 2344 UpdateVolumeIcons(false); 2347 2345 break; 2348 2346 } 2349 2347 } … … 5214 5212 5215 5213 5216 5214 void 5217 BPoseView::UpdateVolumeIcon (dev_t device,bool forceUpdate)5215 BPoseView::UpdateVolumeIcons(bool forceUpdate) 5218 5216 { 5219 int32 index ;5220 BPose *pose = fPoseList->Find VolumePose(device,&index);5217 int32 index = -1; 5218 BPose *pose = fPoseList->FindNextVolumePose(&index); 5221 5219 if (pose == NULL) 5222 5220 return; 5223 5221 5224 if (pose->UpdateVolumeSpaceBar(TrackerSettings().ShowVolumeSpaceBar()) || forceUpdate) { 5225 BPoint loc(0, index * fListElemHeight); 5226 pose->UpdateIcon(loc, this); 5227 } 5228 } 5222 bool showSpaceBars = TrackerSettings().ShowVolumeSpaceBar(); 5223 while (pose != NULL) { 5224 if (pose->UpdateVolumeSpaceBar(showSpaceBars) || forceUpdate) { 5225 BPoint loc(0, index * fListElemHeight); 5226 pose->UpdateIcon(loc, this); 5227 } 5229 5228 5230 5231 void 5232 BPoseView::UpdateVolumeIcons() 5233 { 5234 BVolumeRoster roster; 5235 5236 BVolume volume; 5237 while(roster.GetNextVolume(&volume) == B_NO_ERROR) { 5238 BDirectory dir; 5239 volume.GetRootDirectory(&dir); 5240 node_ref nodeRef; 5241 dir.GetNodeRef(&nodeRef); 5242 5243 UpdateVolumeIcon(nodeRef.device, true); 5229 pose = fPoseList->FindNextVolumePose(&index); 5244 5230 } 5245 5231 } 5246 5232 -
src/kits/tracker/Tracker.cpp
497 497 return; 498 498 499 499 // update the volume icon's free space bars 500 BVolumeRoster roster; 501 502 BVolume volume; 503 while (roster.GetNextVolume(&volume) == B_OK) { 504 BDirectory dir; 505 volume.GetRootDirectory(&dir); 506 node_ref nodeRef; 507 dir.GetNodeRef(&nodeRef); 508 509 BMessage notificationMessage; 510 notificationMessage.AddInt32("device", *(int32 *)&nodeRef.device); 511 512 SendNotices(kUpdateVolumeSpaceBar, ¬ificationMessage); 513 } 500 SendNotices(kUpdateVolumeSpaceBar, NULL); 514 501 } 515 502 516 503 -
src/kits/tracker/Pose.cpp
49 49 50 50 51 51 int32 52 CalcFreeSpace( dev_t device)52 CalcFreeSpace(BVolume *volume) 53 53 { 54 BVolume volume(device); 55 fs_info info; 56 if (volume.InitCheck() == B_OK && fs_stat_dev(device,&info) == B_OK) { 57 // Philosophy here: 58 // Bars go on all drives with read/write capabilities 59 // Exceptions: Not on CDDA, but on NTFS/Ext2 60 // Also note that some volumes may return 0 when 61 // BVolume::Capacity() is called (believe-me... That *DOES* 62 // happen) so we also check for that. 63 off_t capacity = volume.Capacity(); 64 if (((!volume.IsReadOnly() && strcmp(info.fsh_name,"cdda")) 65 || !strcmp(info.fsh_name,"ntfs") 66 || !strcmp(info.fsh_name,"ext2")) 67 && (capacity > 0)) { 68 int32 percent = static_cast<int32>(volume.FreeBytes() / (capacity / 100)); 54 off_t capacity = volume->Capacity(); 55 int32 percent = static_cast<int32>(volume->FreeBytes() / (capacity / 100)); 69 56 70 // warn below 20 MB of free space (if this is less than 10% of free space) 71 if (volume.FreeBytes() < 20 * 1024 * 1024 && percent < 10) 72 return -2 - percent; 73 74 return percent; 75 } 76 } 77 return -1; 57 // warn below 20 MB of free space (if this is less than 10% of free space) 58 if (volume->FreeBytes() < 20 * 1024 * 1024 && percent < 10) 59 return -2 - percent; 60 return percent; 78 61 } 79 62 80 63 … … 86 69 BPose::BPose(Model *model, BPoseView *view, bool selected) 87 70 : fModel(model), 88 71 fWidgetList(4, true), 72 fVolume(NULL), 89 73 fPercent(-1), 90 74 fIsSelected(selected), 91 75 fDelayedEdit(true), … … 98 82 { 99 83 CreateWidgets(view); 100 84 101 if (model->IsVolume() && TrackerSettings().ShowVolumeSpaceBar()) { 85 if (model->IsVolume()) { 86 fs_info info; 102 87 dev_t device = model->NodeRef()->device; 103 fPercent = CalcFreeSpace(device); 88 BVolume *volume = new BVolume(device); 89 if (volume->InitCheck() == B_OK 90 && fs_stat_dev(device, &info) == B_OK) { 91 // Philosophy here: 92 // Bars go on all drives with read/write capabilities 93 // Exceptions: Not on CDDA, but on NTFS/Ext2 94 // Also note that some volumes may return 0 when 95 // BVolume::Capacity() is called (believe-me... That *DOES* 96 // happen) so we also check for that. 97 off_t capacity = volume->Capacity(); 98 if (((!volume->IsReadOnly() && strcmp(info.fsh_name,"cdda")) 99 || !strcmp(info.fsh_name,"ntfs") 100 || !strcmp(info.fsh_name,"ext2")) 101 && capacity > 0) { 102 // The volume is ok and we want space bars on it 103 fVolume = volume; 104 } else 105 delete volume; 106 } else 107 delete volume; 108 109 if (fVolume && TrackerSettings().ShowVolumeSpaceBar()) 110 fPercent = CalcFreeSpace(fVolume); 104 111 } 105 112 106 113 if ((fClipboardMode = FSClipboardFindNodeMode(model,true)) != 0 … … 113 120 BPose::~BPose() 114 121 { 115 122 delete fModel; 123 delete fVolume; 116 124 } 117 125 118 126 … … 295 303 return true; 296 304 } 297 305 298 dev_t device = TargetModel()->NodeRef()->device; 299 int32 percent = CalcFreeSpace(device); 306 if (fVolume == NULL) { 307 // we don't want or cannot get the 308 // available space from this volume 309 return false; 310 } 300 311 312 int32 percent = CalcFreeSpace(fVolume); 301 313 if (fPercent != percent) { 302 314 if (percent > 100) 303 315 fPercent = 100; -
src/kits/tracker/PoseView.h
159 159 void SetAutoScroll(bool); 160 160 void SetPoseEditing(bool); 161 161 162 void UpdateVolumeIcon(dev_t device, bool forceUpdate = false); 163 void UpdateVolumeIcons(); 162 void UpdateVolumeIcons(bool forceUpdate = false); 164 163 165 164 // file change notification handler 166 165 virtual bool FSNotification(const BMessage *); -
src/kits/tracker/Pose.h
135 135 BPoint fLocation; 136 136 137 137 uint32 fClipboardMode; 138 BVolume *fVolume; 138 139 int32 fPercent; 139 140 140 141 bool fIsSelected : 1; -
src/kits/tracker/PoseList.cpp
107 107 } 108 108 109 109 BPose * 110 PoseList::Find VolumePose(const dev_t device, int32 *resultingIndex) const110 PoseList::FindNextVolumePose(int32 *currentIndex) const 111 111 { 112 112 int32 count = CountItems(); 113 for (int32 index = 0; index < count; index++) {113 for (int32 index = *currentIndex + 1; index < count; index++) { 114 114 BPose *pose = ItemAt(index); 115 115 Model *model = pose->TargetModel(); 116 116 ASSERT(model); 117 if (model->IsVolume() && model->NodeRef()->device == device) { 118 if (resultingIndex) 119 *resultingIndex = index; 117 if (model->IsVolume()) { 118 *currentIndex = index; 120 119 return pose; 121 120 } 122 121 }