Ticket #3560: bug#3560-status-line-enhancement-002.patch

File bug#3560-status-line-enhancement-002.patch, 4.7 KB (added by TigerKid001, 10 years ago)

Updated patch, fixed issues

  • src/kits/tracker/CountView.cpp

    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.  
    4747#include "Bitmaps.h"
    4848#include "ContainerWindow.h"
    4949#include "DirMenu.h"
     50#include "Entry.h"
     51#include "Model.h"
    5052#include "PoseView.h"
     53#include "StringForSize.h"
    5154#include "Utilities.h"
    5255
    5356
    BCountView::BCountView(BRect bounds, BPoseView* view)  
    6669    BView(bounds, "CountVw", B_FOLLOW_LEFT + B_FOLLOW_BOTTOM,
    6770        B_PULSE_NEEDED | B_WILL_DRAW),
    6871    fLastCount(-1),
     72    fFileCount(0),
     73    fDirCount(0),
     74    fTotalFilesSize(0),
    6975    fPoseView(view),
    7076    fShowingBarberPole(false),
    7177    fBorderHighlighted(false),
    BCountView::CheckCount()  
    198204    // invalidate the count text area if necessary
    199205    if (fLastCount != fPoseView->CountItems()) {
    200206        fLastCount = fPoseView->CountItems();
     207        _UpdateCountsAndSizes();
    201208        Invalidate(TextInvalRect());
    202209    }
    203210
    BCountView::CheckCount()  
    207214
    208215
    209216void
     217BCountView::_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
     254void
    210255BCountView::Draw(BRect updateRect)
    211256{
    212257    BRect bounds(Bounds());
    BCountView::Draw(BRect updateRect)  
    222267        be_control_look->DrawMenuBarBackground(this, bounds, updateRect,
    223268            ViewColor());
    224269    }
    225 
    226270    BString itemString;
     271    BString fileString, folderString, sizeString;
    227272    if (IsTypingAhead())
    228273        itemString << TypeAhead();
    229274    else if (IsFiltering()) {
    BCountView::Draw(BRect updateRect)  
    232277        if (fLastCount == 0)
    233278            itemString << B_TRANSLATE("no items");
    234279        else {
    235             static BMessageFormat format(B_TRANSLATE_COMMENT(
     280            static BMessageFormat itemFormat(B_TRANSLATE_COMMENT(
    236281                "{0, plural, one{# item} other{# items}}",
    237282                "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;
    239302        }
    240303    }
    241 
    242304    BRect textRect(TextInvalRect());
    243305
    244306    TruncateString(&itemString, IsTypingAhead() ? B_TRUNCATE_BEGINNING
  • src/kits/tracker/CountView.h

    diff --git a/src/kits/tracker/CountView.h b/src/kits/tracker/CountView.h
    index 52ad97e..2ec5007 100644
    a b private:  
    7878    BRect TextInvalRect() const;
    7979    BRect TextAndBarberPoleRect() const;
    8080    void TrySpinningBarberPole();
     81    void _UpdateCountsAndSizes();
    8182
    8283    int32 fLastCount;
     84    int32 fFileCount, fDirCount;
     85    off_t fTotalFilesSize;
    8386    BPoseView* fPoseView;
    8487    bool fShowingBarberPole : 1;
    8588    bool fBorderHighlighted : 1;
  • src/kits/tracker/PoseView.cpp

    diff --git a/src/kits/tracker/PoseView.cpp b/src/kits/tracker/PoseView.cpp
    index ae04731..a13b00c 100644
    a b using std::max;  
    113113
    114114
    115115const float kDoubleClickTresh = 6;
    116 const float kCountViewWidth = 76;
     116const float kCountViewWidth = 250;
    117117
    118118const uint32 kAddNewPoses = 'Tanp';
    119119const uint32 kAddPosesCompleted = 'Tapc';