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

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

Status line enhancement to show number of folders, files and size

  • src/kits/tracker/CountView.cpp

    From c6c587934e213811dcdc6076c67d36507fe06529 Mon Sep 17 00:00:00 2001
    From: "Sidhant Sharma [:TigerKid001]" <tigerkid001@gmail.com>
    Date: Wed, 22 Oct 2014 18:32:22 +0000
    Subject: [PATCH] Status line enhancement v1.0
    
    ---
     src/kits/tracker/CountView.cpp | 68 ++++++++++++++++++++++++++++++++++++++----
     src/kits/tracker/CountView.h   |  3 ++
     src/kits/tracker/PoseView.cpp  |  2 +-
     3 files changed, 67 insertions(+), 6 deletions(-)
    
    diff --git a/src/kits/tracker/CountView.cpp b/src/kits/tracker/CountView.cpp
    index a1d3c7c..976ec47 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()  
    207213
    208214
    209215void
     216BCountView::GetCountsAndSizes()
     217{
     218    if(fLastCount != fPoseView->CountItems())
     219        fLastCount = fPoseView->CountItems();
     220
     221    node_ref ref;
     222    Model* model = fPoseView->TargetModel();
     223    if(model->IsDirectory())
     224        ref = *model->NodeRef();
     225
     226    BDirectory dir(&ref);
     227    dir.Rewind();
     228    BEntry entry;
     229    while (dir.GetNextEntry(&entry) == B_OK) {
     230        StatStruct statbuf;
     231        status_t status = entry.GetStat(&statbuf);
     232        if (status != B_OK)
     233            return;
     234
     235        if (S_ISDIR(statbuf.st_mode))
     236            fDirCount++;
     237        else{
     238            fFileCount++;
     239            off_t fileSize = 0;
     240            BFile file(&entry,B_READ_ONLY);
     241            file.GetSize(&fileSize);
     242            fTotalFilesSize += fileSize;
     243        }
     244    }
     245}
     246
     247void
    210248BCountView::Draw(BRect updateRect)
    211249{
    212250    BRect bounds(Bounds());
    BCountView::Draw(BRect updateRect)  
    222260        be_control_look->DrawMenuBarBackground(this, bounds, updateRect,
    223261            ViewColor());
    224262    }
    225 
    226263    BString itemString;
     264    BString fileString, folderString, sizeString;
    227265    if (IsTypingAhead())
    228266        itemString << TypeAhead();
    229267    else if (IsFiltering()) {
    BCountView::Draw(BRect updateRect)  
    232270        if (fLastCount == 0)
    233271            itemString << B_TRANSLATE("no items");
    234272        else {
    235             static BMessageFormat format(B_TRANSLATE_COMMENT(
     273            static BMessageFormat itemFormat(B_TRANSLATE_COMMENT(
    236274                "{0, plural, one{# item} other{# items}}",
    237275                "Number of selected items: \"1 item\" or \"2 items\""));
    238             format.Format(itemString, fLastCount);
     276            itemFormat.Format(itemString, fLastCount);
     277
     278            itemString += " | ";
     279            static BMessageFormat folderFormat(B_TRANSLATE_COMMENT(
     280                "{0, plural, one{# folder} other{# folders}}",
     281                "Number of selected folders: \"1 folder\" or \"2 folders\""));
     282            folderFormat.Format(folderString, fDirCount);
     283            itemString += folderString;
     284            }
     285
     286            itemString += " | ";
     287            static BMessageFormat fileFormat(B_TRANSLATE_COMMENT(
     288                "{0, plural, one{# file} other{# files}}",
     289                "Number of selected folders: \"1 file\" or \"2 files\""));
     290            fileFormat.Format(fileString, fFileCount);
     291            itemString += fileString;
     292            char sizeBuffer[128];
     293            sizeString = string_for_size((double)fTotalFilesSize,
     294                        sizeBuffer, sizeof(sizeBuffer));
     295            itemString += "(";
     296            itemString += sizeString;
     297            itemString += ")";
    239298        }
    240     }
    241 
    242299    BRect textRect(TextInvalRect());
    243300
    244301    TruncateString(&itemString, IsTypingAhead() ? B_TRUNCATE_BEGINNING
    BCountView::AttachedToWindow()  
    346403    SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR));
    347404    SetLowColor(ViewColor());
    348405
     406    GetCountsAndSizes();
    349407    CheckCount();
    350408}
    351409
  • src/kits/tracker/CountView.h

    diff --git a/src/kits/tracker/CountView.h b/src/kits/tracker/CountView.h
    index 52ad97e..2e47885 100644
    a b public:  
    5757    virtual void WindowActivated(bool active);
    5858
    5959    void CheckCount();
     60    void GetCountsAndSizes();
    6061    void StartBarberPole();
    6162    void EndBarberPole();
    6263
    private:  
    8081    void TrySpinningBarberPole();
    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 = 240;
    117117
    118118const uint32 kAddNewPoses = 'Tanp';
    119119const uint32 kAddPosesCompleted = 'Tapc';