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 <Locale.h> 16 #include <String.h> 17 #include <TimeZone.h> 18 #include <ToolTip.h> 19 20 #include "TimeZoneListItem.h" 21 22 23 #undef B_TRANSLATION_CONTEXT 24 #define B_TRANSLATION_CONTEXT "Time" 25 26 27 TimeZoneListView::TimeZoneListView(void) 28 : 29 BOutlineListView("cityList", B_SINGLE_SELECTION_LIST) 30 { 31 } 32 33 34 TimeZoneListView::~TimeZoneListView() 35 { 36 } 37 38 39 bool 40 TimeZoneListView::GetToolTipAt(BPoint point, BToolTip** _tip) 41 { 42 TimeZoneListItem* item = static_cast<TimeZoneListItem*>( 43 this->ItemAt(this->IndexOf(point))); 44 if (item == NULL || !item->HasTimeZone()) 45 return false; 46 47 BString nowInTimeZone; 48 time_t now = time(NULL); 49 BLocale::Default()->FormatTime(&nowInTimeZone, now, B_SHORT_TIME_FORMAT, 50 &item->TimeZone()); 51 52 BString dateInTimeZone; 53 BLocale::Default()->FormatDate(&dateInTimeZone, now, B_SHORT_DATE_FORMAT, 54 &item->TimeZone()); 55 56 BString toolTip = item->Text(); 57 toolTip << '\n' << item->TimeZone().ShortName() << " / " 58 << item->TimeZone().ShortDaylightSavingName() 59 << B_TRANSLATE("\nNow: ") << nowInTimeZone 60 << " (" << dateInTimeZone << ')'; 61 62 SetToolTip(toolTip.String()); 63 64 *_tip = ToolTip(); 65 66 return true; 67 } 68