[haiku-commits] haiku: hrev45330 - src/preferences/time

  • From: mattmadia@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sat, 2 Mar 2013 22:46:48 +0100 (CET)

hrev45330 adds 1 changeset to branch 'master'
old head: be7b42ea9971f750ebe8483e614a0f40c025ec35
new head: f0e995c8d48978ed5a78b7db6fe3ea6e73f3d17c
overview: http://cgit.haiku-os.org/haiku/log/?qt=range&q=f0e995c+%5Ebe7b42e

----------------------------------------------------------------------------

f0e995c: Create TimeZoneListView class and move GetToolTipAt into it, fixes 
#7726
  
  Signed-off-by: Matt Madia <mattmadia@xxxxxxxxx>

                                           [ Ziusudra <ziusudra@xxxxxxxxx> ]

----------------------------------------------------------------------------

Revision:    hrev45330
Commit:      f0e995c8d48978ed5a78b7db6fe3ea6e73f3d17c
URL:         http://cgit.haiku-os.org/haiku/commit/?id=f0e995c
Author:      Ziusudra <ziusudra@xxxxxxxxx>
Date:        Mon Nov 26 04:05:16 2012 UTC
Committer:   Matt Madia <mattmadia@xxxxxxxxx>
Commit-Date: Sat Mar  2 21:45:20 2013 UTC

Ticket:      https://dev.haiku-os.org/ticket/7726

----------------------------------------------------------------------------

5 files changed, 113 insertions(+), 47 deletions(-)
src/preferences/time/Jamfile              |  2 +
src/preferences/time/TimeZoneListView.cpp | 74 +++++++++++++++++++++++++++
src/preferences/time/TimeZoneListView.h   | 31 +++++++++++
src/preferences/time/ZoneView.cpp         | 44 ++--------------
src/preferences/time/ZoneView.h           |  9 ++--

----------------------------------------------------------------------------

diff --git a/src/preferences/time/Jamfile b/src/preferences/time/Jamfile
index c0579a7..bd1295a 100644
--- a/src/preferences/time/Jamfile
+++ b/src/preferences/time/Jamfile
@@ -19,6 +19,7 @@ local sources =
        TimeSettings.cpp
        TimeWindow.cpp
        TimeZoneListItem.cpp
+       TimeZoneListView.cpp
        TZDisplay.cpp
        ZoneView.cpp
        ;
@@ -44,5 +45,6 @@ DoCatalogs Time :
        ntp.cpp
        Time.cpp
        TimeWindow.cpp
+       TimeZoneListView.cpp
        ZoneView.cpp
        ;
diff --git a/src/preferences/time/TimeZoneListView.cpp 
b/src/preferences/time/TimeZoneListView.cpp
new file mode 100644
index 0000000..87a8519
--- /dev/null
+++ b/src/preferences/time/TimeZoneListView.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2012, Haiku Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Sean Bailey <ziusudra@xxxxxxxxx>
+*/
+
+
+#include "TimeZoneListView.h"
+
+#include <new>
+
+#include <Catalog.h>
+#include <Locale.h>
+#include <String.h>
+#include <TimeZone.h>
+#include <ToolTip.h>
+
+#include "TimeZoneListItem.h"
+
+
+#undef B_TRANSLATION_CONTEXT
+#define B_TRANSLATION_CONTEXT "Time"
+
+
+TimeZoneListView::TimeZoneListView(void)
+       :
+       BOutlineListView("cityList", B_SINGLE_SELECTION_LIST),
+       fToolTip(NULL)
+{
+}
+
+
+TimeZoneListView::~TimeZoneListView()
+{
+       if (fToolTip != NULL)
+               fToolTip->ReleaseReference();
+}
+
+
+bool
+TimeZoneListView::GetToolTipAt(BPoint point, BToolTip** _tip)
+{
+       TimeZoneListItem* item = static_cast<TimeZoneListItem*>(
+               this->ItemAt(this->IndexOf(point)));
+       if (item == NULL || !item->HasTimeZone())
+               return false;
+
+       BString nowInTimeZone;
+       time_t now = time(NULL);
+       BLocale::Default()->FormatTime(&nowInTimeZone, now, B_SHORT_TIME_FORMAT,
+               &item->TimeZone());
+
+       BString dateInTimeZone;
+       BLocale::Default()->FormatDate(&dateInTimeZone, now, 
B_SHORT_DATE_FORMAT,
+               &item->TimeZone());
+
+       BString toolTip = item->Text();
+       toolTip << '\n' << item->TimeZone().ShortName() << " / "
+                       << item->TimeZone().ShortDaylightSavingName()
+                       << B_TRANSLATE("\nNow: ") << nowInTimeZone
+                       << " (" << dateInTimeZone << ')';
+
+       if (fToolTip != NULL)
+               fToolTip->ReleaseReference();
+       fToolTip = new (std::nothrow) BTextToolTip(toolTip.String());
+       if (fToolTip == NULL)
+               return false;
+
+       *_tip = fToolTip;
+
+       return true;
+}
diff --git a/src/preferences/time/TimeZoneListView.h 
b/src/preferences/time/TimeZoneListView.h
new file mode 100644
index 0000000..0b9fd48
--- /dev/null
+++ b/src/preferences/time/TimeZoneListView.h
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2012, Haiku Inc. All rights reserved.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ *             Sean Bailey <ziusudra@xxxxxxxxx>
+ */
+#ifndef _TIME_ZONE_LIST_VIEW_H
+#define _TIME_ZONE_LIST_VIEW_H
+
+
+#include <OutlineListView.h>
+
+
+class BTextToolTip;
+
+
+class TimeZoneListView : public BOutlineListView {
+public:
+                                                               
TimeZoneListView(void);
+                                                               
~TimeZoneListView();
+
+protected:
+       virtual bool                            GetToolTipAt(BPoint point, 
BToolTip** _tip);
+
+private:
+                       BTextToolTip*           fToolTip;
+};
+
+
+#endif // _TIME_ZONE_LIST_VIEW_H
diff --git a/src/preferences/time/ZoneView.cpp 
b/src/preferences/time/ZoneView.cpp
index c773de5..08f5332 100644
--- a/src/preferences/time/ZoneView.cpp
+++ b/src/preferences/time/ZoneView.cpp
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2010, Haiku, Inc. All Rights Reserved.
+ * Copyright 2004-2012, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -42,7 +42,6 @@
 #include <String.h>
 #include <StringView.h>
 #include <TimeZone.h>
-#include <ToolTip.h>
 #include <View.h>
 #include <Window.h>
 
@@ -52,6 +51,7 @@
 
 #include "TimeMessages.h"
 #include "TimeZoneListItem.h"
+#include "TimeZoneListView.h"
 #include "TZDisplay.h"
 
 
@@ -84,7 +84,6 @@ TimeZoneView::TimeZoneView(const char* name)
        :
        BGroupView(name, B_HORIZONTAL, B_USE_DEFAULT_SPACING),
        fGmtTime(NULL),
-       fToolTip(NULL),
        fUseGmtTime(false),
        fCurrentZoneItem(NULL),
        fOldZoneItem(NULL),
@@ -107,8 +106,6 @@ TimeZoneView::CheckCanRevert()
 
 TimeZoneView::~TimeZoneView()
 {
-       if (fToolTip != NULL)
-               fToolTip->ReleaseReference();
        _WriteRTCSettings();
 }
 
@@ -189,41 +186,6 @@ TimeZoneView::MessageReceived(BMessage* message)
 }
 
 
-bool
-TimeZoneView::GetToolTipAt(BPoint point, BToolTip** _tip)
-{
-       TimeZoneListItem* item = static_cast<TimeZoneListItem*>(
-               fZoneList->ItemAt(fZoneList->IndexOf(point)));
-       if (item == NULL || !item->HasTimeZone())
-               return false;
-
-       BString nowInTimeZone;
-       time_t now = time(NULL);
-       BLocale::Default()->FormatTime(&nowInTimeZone, now, B_SHORT_TIME_FORMAT,
-               &item->TimeZone());
-
-       BString dateInTimeZone;
-       BLocale::Default()->FormatDate(&dateInTimeZone, now, 
B_SHORT_DATE_FORMAT,
-               &item->TimeZone());
-
-       BString toolTip = item->Text();
-       toolTip << '\n' << item->TimeZone().ShortName() << " / "
-                       << item->TimeZone().ShortDaylightSavingName()
-                       << B_TRANSLATE("\nNow: ") << nowInTimeZone
-                       << " (" << dateInTimeZone << ')';
-
-       if (fToolTip != NULL)
-               fToolTip->ReleaseReference();
-       fToolTip = new (std::nothrow) BTextToolTip(toolTip.String());
-       if (fToolTip == NULL)
-               return false;
-
-       *_tip = fToolTip;
-
-       return true;
-}
-
-
 void
 TimeZoneView::_UpdateDateTime(BMessage* message)
 {
@@ -243,7 +205,7 @@ TimeZoneView::_UpdateDateTime(BMessage* message)
 void
 TimeZoneView::_InitView()
 {
-       fZoneList = new BOutlineListView("cityList", B_SINGLE_SELECTION_LIST);
+       fZoneList = new TimeZoneListView();
        fZoneList->SetSelectionMessage(new BMessage(H_CITY_CHANGED));
        fZoneList->SetInvocationMessage(new BMessage(H_SET_TIME_ZONE));
        _BuildZoneMenu();
diff --git a/src/preferences/time/ZoneView.h b/src/preferences/time/ZoneView.h
index b0ac9b4..9766263 100644
--- a/src/preferences/time/ZoneView.h
+++ b/src/preferences/time/ZoneView.h
@@ -1,5 +1,5 @@
 /*
- * Copyright 2004-2011, Haiku, Inc. All Rights Reserved.
+ * Copyright 2004-2012, Haiku, Inc. All Rights Reserved.
  * Distributed under the terms of the MIT License.
  *
  * Authors:
@@ -20,9 +20,9 @@ class BMessage;
 class BOutlineListView;
 class BPopUpMenu;
 class BRadioButton;
-class BTextToolTip;
 class BTimeZone;
 class TimeZoneListItem;
+class TimeZoneListView;
 class TTZDisplay;
 
 
@@ -36,7 +36,6 @@ public:
                        bool                            CheckCanRevert();
 
 protected:
-       virtual bool                            GetToolTipAt(BPoint point, 
BToolTip** _tip);
        virtual void                            DoLayout();
 
 private:
@@ -58,15 +57,13 @@ private:
 
                        void                            _Revert();
 
-                       BOutlineListView*       fZoneList;
+                       TimeZoneListView*       fZoneList;
                        BButton*                        fSetZone;
                        TTZDisplay*                     fCurrent;
                        TTZDisplay*                     fPreview;
                        BRadioButton*           fLocalTime;
                        BRadioButton*           fGmtTime;
 
-                       BTextToolTip*           fToolTip;
-
                        int32                           fLastUpdateMinute;
                        bool                            fUseGmtTime;
                        bool                            fOldUseGmtTime;


Other related posts: