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

File bug#3560-status-line-enhancement-004.patch, 5.8 KB (added by TigerKid001, 9 years ago)
  • src/kits/tracker/CountView.cpp

    From cd75968f9c9f0f1909de23978a81925961e6843b Mon Sep 17 00:00:00 2001
    From: "Sidhant Sharma [:TigerKid001]" <tigerkid001@gmail.com>
    Date: Sat, 25 Oct 2014 11:24:51 +0530
    Subject: [PATCH] Status line enhancement v1.3
    
    ---
     src/kits/tracker/CountView.cpp | 105 ++++++++++++++++++++++++++++++++++-------
     src/kits/tracker/CountView.h   |   5 ++
     src/kits/tracker/PoseView.cpp  |   2 +-
     3 files changed, 93 insertions(+), 19 deletions(-)
    
    diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp
    index a1d3c7c..301d840 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),
     76    fMoreFiles(false),
    7077    fShowingBarberPole(false),
    7178    fBorderHighlighted(false),
    7279    fBarberPoleMap(NULL),
    7380    fLastBarberPoleOffset(5),
    7481    fStartSpinningAfter(0),
     82    fStatusString(""),
    7583    fTypeAheadString(""),
    7684    fFilterString("")
    7785{
    BCountView::CheckCount()  
    198206    // invalidate the count text area if necessary
    199207    if (fLastCount != fPoseView->CountItems()) {
    200208        fLastCount = fPoseView->CountItems();
     209        _UpdateCountsAndSizes();
    201210        Invalidate(TextInvalRect());
    202211    }
    203212
    BCountView::CheckCount()  
    207216
    208217
    209218void
     219BCountView::_UpdateCountsAndSizes()
     220{
     221    fFileCount = 0;
     222    fDirCount = 0;
     223    fTotalFilesSize = 0;
     224    fLastCount = fPoseView->CountItems();
     225    fMoreFiles = false;
     226
     227    node_ref ref;
     228    Model* model = fPoseView->TargetModel();
     229    if (model->IsDirectory())
     230        ref = *model->NodeRef();
     231    else {
     232        // we can't check for files and folders if model is not a directory
     233        return;
     234    }
     235   
     236    BDirectory dir(&ref);
     237    BEntry entry;
     238    while (dir.GetNextEntry(&entry) == B_OK) {
     239        StatStruct statbuf;
     240        status_t status = entry.GetStat(&statbuf);
     241        if (status != B_OK) {
     242            fMoreFiles = true;
     243            continue;
     244        }
     245
     246        if (S_ISDIR(statbuf.st_mode))
     247            fDirCount++;
     248        else {
     249            fFileCount++;
     250            fTotalFilesSize += statbuf.st_size;
     251        }
     252    }
     253   
     254    BString itemString;
     255    BString fileString, folderString, sizeString;
     256    if (IsTypingAhead())
     257        fStatusString << TypeAhead();
     258    else if (IsFiltering()) {
     259        fStatusString << fLastCount << " " << Filter();
     260    } else {
     261        if (fLastCount == 0)
     262            fStatusString << B_TRANSLATE("no items");
     263        else {
     264            fStatusString = "";
     265            static BMessageFormat itemFormat(B_TRANSLATE_COMMENT(
     266                "{0, plural, one{# item} other{# items}}",
     267                "Number of selected items: \"1 item\" or \"2 items\""));
     268            itemFormat.Format(itemString, fLastCount);
     269            fStatusString += itemString;
     270
     271            fStatusString += " | ";
     272            static BMessageFormat folderFormat(B_TRANSLATE_COMMENT(
     273                "{0, plural, one{# folder} other{# folders}}",
     274                "Number of selected folders: \"1 folder\" or \"2 folders\""));
     275            folderFormat.Format(folderString, fDirCount);
     276            fStatusString += folderString;
     277
     278            fStatusString += " | ";
     279            static BMessageFormat fileFormat(B_TRANSLATE_COMMENT(
     280                "{0, plural, one{#%more% file} other{#%more% files}} (%size%)",
     281                "Number of selected files: \"1 file\" or \"2 files\""));
     282            fileFormat.Format(fileString, fFileCount);
     283            fileString.ReplaceFirst("%more%", (fMoreFiles?"+":"") );
     284            char sizeBuffer[128];
     285            sizeString = string_for_size((double)fTotalFilesSize,
     286                        sizeBuffer, sizeof(sizeBuffer));
     287            fileString.ReplaceFirst("%size%", sizeString);
     288            fStatusString += fileString;
     289        }
     290    }
     291}
     292
     293
     294void
    210295BCountView::Draw(BRect updateRect)
    211296{
    212297    BRect bounds(Bounds());
    BCountView::Draw(BRect updateRect)  
    223308            ViewColor());
    224309    }
    225310
    226     BString itemString;
    227     if (IsTypingAhead())
    228         itemString << TypeAhead();
    229     else if (IsFiltering()) {
    230         itemString << fLastCount << " " << Filter();
    231     } else {
    232         if (fLastCount == 0)
    233             itemString << B_TRANSLATE("no items");
    234         else {
    235             static BMessageFormat format(B_TRANSLATE_COMMENT(
    236                 "{0, plural, one{# item} other{# items}}",
    237                 "Number of selected items: \"1 item\" or \"2 items\""));
    238             format.Format(itemString, fLastCount);
    239         }
    240     }
    241 
    242311    BRect textRect(TextInvalRect());
    243312
    244     TruncateString(&itemString, IsTypingAhead() ? B_TRUNCATE_BEGINNING
     313    TruncateString(&fStatusString, IsTypingAhead() ? B_TRUNCATE_BEGINNING
    245314            : IsFiltering() ? B_TRUNCATE_MIDDLE : B_TRUNCATE_END,
    246315        textRect.Width());
    247316
    BCountView::Draw(BRect updateRect)  
    253322        SetHighColor(0, 0, 0);
    254323
    255324    MovePenTo(textRect.LeftBottom());
    256     DrawString(itemString.String());
     325    DrawString(fStatusString.String());
    257326
    258327    bounds.top++;
    259328
  • src/kits/tracker/CountView.h

    diff --git a/src/kits/tracker/CountView.h b/src/kits/tracker/CountView.h
    index 52ad97e..7291e1c 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;
     87    bool fMoreFiles : 1;
    8488    bool fShowingBarberPole : 1;
    8589    bool fBorderHighlighted : 1;
    8690    BBitmap* fBarberPoleMap;
    8791    float fLastBarberPoleOffset;
    8892    bigtime_t fStartSpinningAfter;
     93    BString fStatusString;
    8994    BString fTypeAheadString;
    9095    BString fFilterString;
    9196};
  • 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';