1 /* 2 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved. 3 * Distributed under the terms of the MIT/X11 license. 4 * 5 * Copyright (c) 1999 Mike Steed. You are free to use and distribute this software 6 * as long as it is accompanied by it's documentation and this copyright notice. 7 * The software comes with no warranty, etc. 8 */ 9 #include "InfoWindow.h" 10 11 #include <pair.h> 12 #include <stdio.h> 13 #include <time.h> 14 #include <vector> 15 16 #include <StringView.h> 17 #include <Bitmap.h> 18 #include <NodeInfo.h> 19 20 #include "Common.h" 21 #include "Snapshot.h" 22 23 using std::string; 24 using std::vector; 25 26 LeftView::LeftView(BRect frame, BBitmap* icon) 27 : BView(frame, NULL, B_FOLLOW_NONE, B_WILL_DRAW), 28 fIcon(icon) 29 { 30 SetViewColor(tint_color(kWindowColor, B_LIGHTEN_1_TINT)); 31 } 32 33 34 LeftView::~LeftView() 35 { 36 delete fIcon; 37 } 38 39 40 void 41 LeftView::Draw(BRect updateRect) 42 { 43 float right = Bounds().Width() - kSmallHMargin; 44 BRect iconRect(right - 31.0, kSmallVMargin, right, kSmallVMargin + 31.0); 45 if (updateRect.Intersects(iconRect)) { 46 SetDrawingMode(B_OP_OVER); 47 DrawBitmap(fIcon, iconRect); 48 } 49 } 50 51 52 InfoWin::InfoWin(BPoint p, FileInfo *f, BWindow* parent) 53 : BWindow(BRect(p, p), kEmptyStr, B_FLOATING_WINDOW_LOOK, 54 B_FLOATING_SUBSET_WINDOW_FEEL, 55 B_NOT_RESIZABLE | B_NOT_ZOOMABLE | B_NOT_MINIMIZABLE) 56 { 57 AddToSubset(parent); 58 59 typedef pair<string, string> Item; 60 typedef vector<Item> InfoList; 61 62 char name[B_PATH_NAME_LENGTH]; 63 strcpy(name, f->ref.name); 64 strcat(name, " info"); 65 SetTitle(name); 66 67 InfoList info; 68 Item item; 69 70 // Size 71 size_to_string(f->size, name); 72 if (f->count > 0) { 73 // This is a directory. 74 char str[64]; 75 sprintf(str, kInfoInFiles, f->count); 76 strcat(name, str); 77 } 78 info.push_back(Item(kInfoSize, name)); 79 80 // Created & modified dates 81 BEntry entry(&f->ref); 82 time_t t; 83 entry.GetCreationTime(&t); 84 strftime(name, 64, kInfoTimeFmt, localtime(&t)); 85 info.push_back(Item(kInfoCreated, name)); 86 entry.GetModificationTime(&t); 87 strftime(name, 64, kInfoTimeFmt, localtime(&t)); 88 info.push_back(Item(kInfoModified, name)); 89 90 // Kind 91 BMimeType* type = f->Type(); 92 type->GetShortDescription(name); 93 info.push_back(Item(kInfoKind, name)); 94 delete type; 95 96 // Path 97 string path; 98 f->GetPath(path); 99 info.push_back(Item(kInfoPath, path)); 100 101 // Icon 102 BBitmap *icon = new BBitmap(BRect(0.0, 0.0, 31.0, 31.0), B_RGBA32); 103 entry_ref ref; 104 entry.GetRef(&ref); 105 BNodeInfo::GetTrackerIcon(&ref, icon, B_LARGE_ICON); 106 107 // Compute the window size and add the views. 108 BFont smallFont(be_plain_font); 109 smallFont.SetSize(floorf(smallFont.Size() * 0.95)); 110 111 struct font_height fh; 112 smallFont.GetHeight(&fh); 113 float fontHeight = fh.ascent + fh.descent + fh.leading; 114 115 float leftWidth = 32.0; 116 float rightWidth = 0.0; 117 InfoList::iterator i = info.begin(); 118 while (i != info.end()) { 119 float w = smallFont.StringWidth((*i).first.c_str()) + 2.0 * kSmallHMargin; 120 leftWidth = max_c(leftWidth, w); 121 w = smallFont.StringWidth((*i).second.c_str()) + 2.0 * kSmallHMargin; 122 rightWidth = max_c(rightWidth, w); 123 i++; 124 } 125 126 float winHeight = 32.0 + 4.0 * kSmallVMargin + 5.0 * (fontHeight + kSmallVMargin); 127 float winWidth = leftWidth + rightWidth; 128 ResizeTo(winWidth, winHeight); 129 130 LeftView *leftView = new LeftView(BRect(0.0, 0.0, leftWidth, winHeight), icon); 131 BView *rightView = new BView( 132 BRect(leftWidth + 1.0, 0.0, winWidth, winHeight), NULL, 133 B_FOLLOW_NONE, B_WILL_DRAW); 134 135 AddChild(leftView); 136 AddChild(rightView); 137 138 BStringView *sv = new BStringView( 139 BRect(kSmallHMargin, kSmallVMargin, rightView->Bounds().Width(), kSmallVMargin + 30.0), 140 NULL, f->ref.name, B_FOLLOW_ALL); 141 142 BFont largeFont(be_plain_font); 143 largeFont.SetSize(ceilf(largeFont.Size() * 1.1)); 144 sv->SetFont(&largeFont); 145 rightView->AddChild(sv); 146 147 float y = 32.0 + 4.0 * kSmallVMargin; 148 i = info.begin(); 149 while (i != info.end()) { 150 sv = new BStringView( 151 BRect(kSmallHMargin, y, leftView->Bounds().Width(), y + fontHeight), 152 NULL, (*i).first.c_str()); 153 sv->SetFont(&smallFont); 154 sv->SetAlignment(B_ALIGN_RIGHT); 155 sv->SetHighColor(kBasePieColor[1]); // arbitrary 156 leftView->AddChild(sv); 157 158 sv = new BStringView( 159 BRect(kSmallHMargin, y, rightView->Bounds().Width(), y + fontHeight), 160 NULL, (*i).second.c_str()); 161 sv->SetFont(&smallFont); 162 rightView->AddChild(sv); 163 164 y += fontHeight + kSmallVMargin; 165 i++; 166 } 167 168 Show(); 169 } 170 171 172 InfoWin::~InfoWin() 173 { 174 } 175 176 177