Ticket #1247: volumebar.diff

File volumebar.diff, 7.8 KB (added by mmlr, 17 years ago)

Fixed patch that does not leak a BVolume and doesn't crash on volumes with no space bar

  • src/kits/tracker/PoseList.h

     
    6464    BPose *DeepFindPose(const node_ref *node, int32 *index = NULL) const;
    6565        // same as FindPose, node can be a target of the actual
    6666        // pose if the pose is a symlink
    67     BPose *FindVolumePose(const dev_t device, int32 *index = NULL) const;
     67    BPose *FindNextVolumePose(int32 *currentIndex) const;
    6868};
    6969
    7070// iteration glue, add permutations as needed
  • src/kits/tracker/PoseView.cpp

     
    23382338                            TrackerSettings().SetShowVolumeSpaceBar(enabled);
    23392339                        // supposed to fall through
    23402340                    case kSpaceBarColorChanged:
    2341                         UpdateVolumeIcons();
     2341                        UpdateVolumeIcons(true);
    23422342                        break;
    23432343                    case kUpdateVolumeSpaceBar:
    2344                         dev_t device;
    2345                         message->FindInt32("device", (int32 *)&device);
    2346                         UpdateVolumeIcon(device);   
     2344                        UpdateVolumeIcons(false);
    23472345                        break;
    23482346                }
    23492347            }
     
    52145212
    52155213
    52165214void
    5217 BPoseView::UpdateVolumeIcon(dev_t device, bool forceUpdate)
     5215BPoseView::UpdateVolumeIcons(bool forceUpdate)
    52185216{
    5219     int32 index;
    5220     BPose *pose = fPoseList->FindVolumePose(device,&index);
     5217    int32 index = -1;
     5218    BPose *pose = fPoseList->FindNextVolumePose(&index);
    52215219    if (pose == NULL)
    52225220        return;
    52235221
    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        }
    52295228
    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);
    52445230    }
    52455231}
    52465232
  • src/kits/tracker/Tracker.cpp

     
    497497        return;
    498498
    499499    // 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, &notificationMessage);
    513     }
     500    SendNotices(kUpdateVolumeSpaceBar, NULL);
    514501}
    515502
    516503
  • src/kits/tracker/Pose.cpp

     
    4949
    5050
    5151int32
    52 CalcFreeSpace(dev_t device)
     52CalcFreeSpace(BVolume *volume)
    5353{
    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));
    6956
    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;
    7861}
    7962
    8063
     
    8669BPose::BPose(Model *model, BPoseView *view, bool selected)
    8770    :   fModel(model),
    8871        fWidgetList(4, true),
     72        fVolume(NULL),
    8973        fPercent(-1),
    9074        fIsSelected(selected),
    9175        fDelayedEdit(true),
     
    9882{
    9983    CreateWidgets(view);
    10084
    101     if (model->IsVolume() && TrackerSettings().ShowVolumeSpaceBar()) {
     85    if (model->IsVolume()) {
     86        fs_info info;
    10287        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);
    104111    }
    105112
    106113    if ((fClipboardMode = FSClipboardFindNodeMode(model,true)) != 0
     
    113120BPose::~BPose()
    114121{
    115122    delete fModel;
     123    delete fVolume;
    116124}
    117125
    118126
     
    295303        return true;
    296304    }
    297305
    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    }
    300311
     312    int32 percent = CalcFreeSpace(fVolume);
    301313    if (fPercent != percent) {
    302314        if (percent > 100)
    303315            fPercent = 100;
  • src/kits/tracker/PoseView.h

     
    159159        void SetAutoScroll(bool);
    160160        void SetPoseEditing(bool);
    161161
    162         void UpdateVolumeIcon(dev_t device, bool forceUpdate = false);
    163         void UpdateVolumeIcons();
     162        void UpdateVolumeIcons(bool forceUpdate = false);
    164163
    165164        // file change notification handler
    166165        virtual bool FSNotification(const BMessage *);
  • src/kits/tracker/Pose.h

     
    135135        BPoint fLocation;
    136136
    137137        uint32 fClipboardMode;
     138        BVolume *fVolume;
    138139        int32 fPercent;
    139140
    140141        bool fIsSelected : 1;
  • src/kits/tracker/PoseList.cpp

     
    107107}
    108108
    109109BPose *
    110 PoseList::FindVolumePose(const dev_t device, int32 *resultingIndex) const
     110PoseList::FindNextVolumePose(int32 *currentIndex) const
    111111{
    112112    int32 count = CountItems();
    113     for (int32 index = 0; index < count; index++) {
     113    for (int32 index = *currentIndex + 1; index < count; index++) {
    114114        BPose *pose = ItemAt(index);
    115115        Model *model = pose->TargetModel();
    116116        ASSERT(model);
    117         if (model->IsVolume() && model->NodeRef()->device == device) {
    118             if (resultingIndex)
    119                 *resultingIndex = index;
     117        if (model->IsVolume()) {
     118            *currentIndex = index;
    120119            return pose;
    121120        }
    122121    }