xref: /haiku/src/preferences/time/TimeZoneListView.cpp (revision 529cd177b573aaba391c8adc9c9f5ad76a14bf81)
1 /*
2  * Copyright 2012, Haiku Inc. All rights reserved.
3  * Distributed under the terms of the MIT License.
4  *
5  * Authors:
6  *		Sean Bailey <ziusudra@gmail.com>
7 */
8 
9 
10 #include "TimeZoneListView.h"
11 
12 #include <new>
13 
14 #include <Catalog.h>
15 #include <DateFormat.h>
16 #include <Locale.h>
17 #include <String.h>
18 #include <TimeZone.h>
19 #include <ToolTip.h>
20 
21 #include "TimeZoneListItem.h"
22 
23 
24 #undef B_TRANSLATION_CONTEXT
25 #define B_TRANSLATION_CONTEXT "Time"
26 
27 
28 TimeZoneListView::TimeZoneListView(void)
29 	:
30 	BOutlineListView("cityList", B_SINGLE_SELECTION_LIST)
31 {
32 }
33 
34 
35 TimeZoneListView::~TimeZoneListView()
36 {
37 }
38 
39 
40 bool
41 TimeZoneListView::GetToolTipAt(BPoint point, BToolTip** _tip)
42 {
43 	TimeZoneListItem* item = static_cast<TimeZoneListItem*>(
44 		this->ItemAt(this->IndexOf(point)));
45 	if (item == NULL || !item->HasTimeZone())
46 		return false;
47 
48 	BString nowInTimeZone;
49 	time_t now = time(NULL);
50 	fTimeFormat.Format(nowInTimeZone, now, B_SHORT_TIME_FORMAT,
51 		&item->TimeZone());
52 
53 	BString dateInTimeZone;
54 	fDateFormat.Format(dateInTimeZone, now, B_SHORT_DATE_FORMAT,
55 		&item->TimeZone());
56 
57 	BString toolTip = item->Text();
58 	toolTip << '\n' << item->TimeZone().ShortName() << " / "
59 			<< item->TimeZone().ShortDaylightSavingName()
60 			<< B_TRANSLATE("\nNow: ") << nowInTimeZone
61 			<< " (" << dateInTimeZone << ')';
62 
63 	SetToolTip(toolTip.String());
64 
65 	*_tip = ToolTip();
66 
67 	return true;
68 }
69