2 * Copyright (c) 2008 Stephan Aßmus <superstippi@gmx.de>. All rights reserved.
3 * Distributed under the terms of the MIT/X11 license.
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.
11 #include "InfoWindow.h"
20 #include <MessageFormat.h>
21 #include <StringForSize.h>
22 #include <StringView.h>
26 #include "DiskUsage.h"
33 #undef B_TRANSLATION_CONTEXT
34 #define B_TRANSLATION_CONTEXT "Info Window"
36 LeftView::LeftView(BRect frame
, BBitmap
* icon
)
38 BView(frame
, NULL
, B_FOLLOW_NONE
, B_WILL_DRAW
),
41 SetViewColor(tint_color(kWindowColor
, B_LIGHTEN_1_TINT
));
52 LeftView::Draw(BRect updateRect
)
54 float right
= Bounds().Width() - kSmallHMargin
;
55 BRect
iconRect(right
- 31.0, kSmallVMargin
, right
, kSmallVMargin
+ 31.0);
56 if (updateRect
.Intersects(iconRect
)) {
57 SetDrawingMode(B_OP_OVER
);
58 DrawBitmap(fIcon
, iconRect
);
63 InfoWin::InfoWin(BPoint p
, FileInfo
*f
, BWindow
* parent
)
64 : BWindow(BRect(p
, p
), kEmptyStr
, B_FLOATING_WINDOW_LOOK
,
65 B_FLOATING_SUBSET_WINDOW_FEEL
,
66 B_NOT_RESIZABLE
| B_NOT_ZOOMABLE
| B_NOT_MINIMIZABLE
)
70 typedef pair
<string
, string
> Item
;
71 typedef vector
<Item
> InfoList
;
73 BString
stringTitle("%refName% info");
74 stringTitle
.ReplaceFirst("%refName%", f
->ref
.name
);
75 SetTitle(stringTitle
.String());
83 // This is a directory, include file count information
84 static BMessageFormat
format(B_TRANSLATE(
85 "%size% in {0, plural, one{# file} other{# files}}"));
87 format
.Format(name
, f
->count
);
91 char tmp
[B_PATH_NAME_LENGTH
] = { 0 };
92 string_for_size(f
->size
, tmp
, sizeof(tmp
));
93 name
.ReplaceFirst("%size%", tmp
);
95 info
.push_back(Item(B_TRANSLATE_MARK("Size"), name
.String()));
97 // Created & modified dates
98 BEntry
entry(&f
->ref
);
100 entry
.GetCreationTime(&t
);
101 strftime(tmp
, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t
));
102 info
.push_back(Item(B_TRANSLATE("Created"), tmp
));
103 entry
.GetModificationTime(&t
);
104 strftime(tmp
, 64, B_TRANSLATE("%a, %d %b %Y, %r"), localtime(&t
));
105 info
.push_back(Item(B_TRANSLATE("Modified"), tmp
));
108 BMimeType
* type
= f
->Type();
109 type
->GetShortDescription(tmp
);
110 info
.push_back(Item(B_TRANSLATE("Kind"), tmp
));
116 info
.push_back(Item(B_TRANSLATE("Path"), path
));
119 BBitmap
*icon
= new BBitmap(BRect(0.0, 0.0, 31.0, 31.0), B_RGBA32
);
122 BNodeInfo::GetTrackerIcon(&ref
, icon
, B_LARGE_ICON
);
124 // Compute the window size and add the views.
125 BFont
smallFont(be_plain_font
);
126 smallFont
.SetSize(floorf(smallFont
.Size() * 0.95));
128 struct font_height fh
;
129 smallFont
.GetHeight(&fh
);
130 float fontHeight
= fh
.ascent
+ fh
.descent
+ fh
.leading
;
132 float leftWidth
= 32.0;
133 float rightWidth
= 0.0;
134 InfoList::iterator i
= info
.begin();
135 while (i
!= info
.end()) {
136 float w
= smallFont
.StringWidth((*i
).first
.c_str())
137 + 2.0 * kSmallHMargin
;
138 leftWidth
= max_c(leftWidth
, w
);
139 w
= smallFont
.StringWidth((*i
).second
.c_str()) + 2.0 * kSmallHMargin
;
140 rightWidth
= max_c(rightWidth
, w
);
144 float winHeight
= 32.0 + 4.0 * kSmallVMargin
+ 5.0 * (fontHeight
146 float winWidth
= leftWidth
+ rightWidth
;
147 ResizeTo(winWidth
, winHeight
);
149 LeftView
*leftView
= new LeftView(BRect(0.0, 0.0, leftWidth
, winHeight
),
151 BView
*rightView
= new BView(
152 BRect(leftWidth
+ 1.0, 0.0, winWidth
, winHeight
), NULL
,
153 B_FOLLOW_NONE
, B_WILL_DRAW
);
158 BStringView
*sv
= new BStringView(
159 BRect(kSmallHMargin
, kSmallVMargin
, rightView
->Bounds().Width(),
160 kSmallVMargin
+ 30.0), NULL
, f
->ref
.name
, B_FOLLOW_ALL
);
162 BFont
largeFont(be_plain_font
);
163 largeFont
.SetSize(ceilf(largeFont
.Size() * 1.1));
164 sv
->SetFont(&largeFont
);
165 rightView
->AddChild(sv
);
167 float y
= 32.0 + 4.0 * kSmallVMargin
;
169 while (i
!= info
.end()) {
170 sv
= new BStringView(
171 BRect(kSmallHMargin
, y
, leftView
->Bounds().Width(),
172 y
+ fontHeight
), NULL
, (*i
).first
.c_str());
173 sv
->SetFont(&smallFont
);
174 sv
->SetAlignment(B_ALIGN_RIGHT
);
175 sv
->SetHighColor(kBasePieColor
[1]); // arbitrary
176 leftView
->AddChild(sv
);
178 sv
= new BStringView(
179 BRect(kSmallHMargin
, y
, rightView
->Bounds().Width(),
180 y
+ fontHeight
), NULL
, (*i
).second
.c_str());
181 sv
->SetFont(&smallFont
);
182 rightView
->AddChild(sv
);
184 y
+= fontHeight
+ kSmallVMargin
;