From 3a818be7ef1530783f101e29f647241888e65b63 Mon Sep 17 00:00:00 2001 From: Johan Wagenheim Date: Fri, 10 Nov 2023 03:08:54 +0000 Subject: [PATCH] Fix tooltip and show condition correctly --- Source/ForecastDeskbarView.cpp | 41 +++++++++++++++++++++------------- Source/ForecastDeskbarView.h | 2 +- Source/ForecastView.cpp | 9 +++++++- Source/ForecastView.h | 1 + Source/MainWindow.cpp | 2 +- locales/en.catkeys | 5 +++-- 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/Source/ForecastDeskbarView.cpp b/Source/ForecastDeskbarView.cpp index bd0e6b2..3afd138 100644 --- a/Source/ForecastDeskbarView.cpp +++ b/Source/ForecastDeskbarView.cpp @@ -17,6 +17,9 @@ #include "ForecastDeskbarView.h" #include "ForecastView.h" +#undef B_TRANSLATION_CONTEXT +#define B_TRANSLATION_CONTEXT "ForecastDeskbarView" + const uint32 kUpdateForecastMessage = 'Updt'; const float kToolTipDelay = 1000000; /*1000000ms = 1s*/ @@ -26,6 +29,7 @@ ForecastDeskbarView::ForecastDeskbarView(BRect viewSize) { // forecastview is only needed to get the weather icon fForecastView = new ForecastView(BRect(0, 0, 0, 0)); + fForecastView->SetDeskbarIconSize(viewSize.IntegerHeight()); AddChild(fForecastView); fMessageRunner = NULL; } @@ -39,8 +43,8 @@ ForecastDeskbarView::ForecastDeskbarView(BMessage* archive) // fForecastView is unarchived and already added to the view hierarchy fForecastView = static_cast(FindView("Weather")); entry_ref appRef; - archive->FindRef("appLocation", &appRef); SetAppLocation(appRef); + archive->FindRef("appLocation", &appRef); } @@ -69,7 +73,7 @@ ForecastDeskbarView::Draw(BRect drawRect) { BView::Draw(drawRect); SetDrawingMode(B_OP_OVER); - // TO-DO: Try with + // TO-DO: Try with // SetBlendingMode(B_PIXEL_ALPHA, B_ALPHA_OVERLAY); BBitmap* icon = fForecastView->GetWeatherIcon(); if (icon != NULL) @@ -84,7 +88,7 @@ ForecastDeskbarView::Archive(BMessage* into, bool deep) const status_t status = BView::Archive(into, deep); if (status != B_OK) return status; - + status = into->AddString("add_on", kSignature); if (status != B_OK) return status; @@ -98,7 +102,6 @@ ForecastDeskbarView::Instantiate(BMessage* archive) { if (!validate_instantiation(archive, "ForecastDeskbarView")) return NULL; - return new ForecastDeskbarView(archive); } @@ -108,14 +111,11 @@ ForecastDeskbarView::MessageReceived(BMessage* message) { if (message->what == kUpdateForecastMessage) { BString weatherDetailsText; - weatherDetailsText << "Temperature: " - << FormatString(fForecastView->Unit(), - fForecastView->Temperature()) - << "\n"; - weatherDetailsText << "Condition: " << fForecastView->GetCondition() - << "\n"; - weatherDetailsText << "Location: " << fForecastView->CityName(); - SetToolTip(weatherDetailsText.String()); + weatherDetailsText.SetToFormat(B_TRANSLATE("Temperature: %s\nCondition: %s\nLocation: %s"), + FormatString(fForecastView->Unit(), fForecastView->Temperature()).String(), + fForecastView->GetStatus().String(), + fForecastView->CityName().String()); + SetToolTip(weatherDetailsText); Invalidate(); } else @@ -138,8 +138,11 @@ ForecastDeskbarView::MouseDown(BPoint point) if (Window()->CurrentMessage() != NULL) mouseButtonStates = Window()->CurrentMessage()->FindInt32("buttons"); - if (mouseButtonStates & B_PRIMARY_MOUSE_BUTTON) // Left click - be_roster->Launch(&fAppRef); + if (mouseButtonStates & B_PRIMARY_MOUSE_BUTTON) + {// Left click + if (be_roster->FindApp(kSignature, &fAppRef) == B_NO_ERROR) + be_roster->Launch(&fAppRef); + } } @@ -155,6 +158,12 @@ extern "C" BView* instantiate_deskbar_item(float maxWidth, float maxHeight); BView* instantiate_deskbar_item(float maxWidth, float maxHeight) -{ - return new ForecastDeskbarView(BRect(0, 0, maxWidth - 1, maxHeight - 1)); +{ + int size = std::min(maxWidth, maxHeight); + ForecastDeskbarView* view = new ForecastDeskbarView(BRect(0, 0, size - 1, size - 1)); + entry_ref appRef; + view->SetAppLocation(appRef); + return view; + + //return new ForecastDeskbarView(BRect(0, 0, size - 1, size - 1)); } diff --git a/Source/ForecastDeskbarView.h b/Source/ForecastDeskbarView.h index 336e689..d38c63d 100644 --- a/Source/ForecastDeskbarView.h +++ b/Source/ForecastDeskbarView.h @@ -17,7 +17,7 @@ class ForecastDeskbarView : public BView { - + public: ForecastDeskbarView(BRect viewSize); ForecastDeskbarView(BMessage* archive); diff --git a/Source/ForecastView.cpp b/Source/ForecastView.cpp index b3fce89..cdd0138 100644 --- a/Source/ForecastView.cpp +++ b/Source/ForecastView.cpp @@ -51,6 +51,7 @@ const double kDefaultLatitude = 37.45383; const int32 kMaxUpdateDelay = 240; const int32 kMaxForecastDay = 5; const int32 kReconnectionDelay = 5; +int32 fSizeDeskBarIcon = 10; #undef B_TRANSLATION_CONTEXT @@ -692,7 +693,7 @@ ForecastView::_LoadIcons(BBitmap* bitmap[3], uint32 type, const char* name) BBitmap* largeBitmap = new BBitmap( BRect(0, 0, kSizeLargeIcon - 1, kSizeLargeIcon - 1), 0, B_RGBA32); BBitmap* deskbarBitmap = new BBitmap( - BRect(0, 0, kSizeDeskBarIcon - 1, kSizeDeskBarIcon - 1), 0, + BRect(0, 0, fSizeDeskBarIcon - 1, fSizeDeskBarIcon - 1), 0, B_RGBA32); status_t status = smallBitmap->InitCheck(); @@ -1288,3 +1289,9 @@ ForecastView::_NetworkConnected() } return false; } + +void +ForecastView::SetDeskbarIconSize(int height) +{ + fSizeDeskBarIcon = height; +} diff --git a/Source/ForecastView.h b/Source/ForecastView.h index e1bb557..7f57b67 100644 --- a/Source/ForecastView.h +++ b/Source/ForecastView.h @@ -164,6 +164,7 @@ status_t SaveState(BMessage* into, bool deep = true) const; int32 GetCondition(); BString GetStatus(); int32 Temperature(); + void SetDeskbarIconSize(int height); private: void _Init(); diff --git a/Source/MainWindow.cpp b/Source/MainWindow.cpp index 2e96c45..803d915 100644 --- a/Source/MainWindow.cpp +++ b/Source/MainWindow.cpp @@ -46,7 +46,7 @@ MainWindow::_PrepareMenuBar(void) B_TRANSLATE("Refresh"), new BMessage(kUpdateMessage), 'R')); menu->AddSeparatorItem(); // Remove menu item until Deskbar replicant is fixed - menu->AddItem(fReplicantMenuItem = new BMenuItem(B_TRANSLATE("Deskbar Replicant"), + menu->AddItem(fReplicantMenuItem = new BMenuItem(B_TRANSLATE("Deskbar replicant"), new BMessage(kToggleDeskbarReplicantMessage), 'T')); menu->AddItem(new BMenuItem(B_TRANSLATE("Change location" B_UTF8_ELLIPSIS), new BMessage(kCitySelectionMessage), 'L')); diff --git a/locales/en.catkeys b/locales/en.catkeys index 0e2ec2c..67013b3 100644 --- a/locales/en.catkeys +++ b/locales/en.catkeys @@ -1,4 +1,4 @@ -1 English x-vnd.przemub.Weather 704655087 +1 English x-vnd.przemub.Weather 3368765232 No network ForecastView No network OK ForecastView OK Slight rain ForecastView Slight rain @@ -14,9 +14,9 @@ Preferences… MainWindow Preferences… Freezing dense drizzle ForecastView Freezing dense drizzle Use Celsius °C PreferencesWindow Use Celsius °C Heavy snow fall ForecastView Heavy snow fall +Deskbar replicant MainWindow Deskbar replicant Weather (The Replicant version) ForecastView Weather (The Replicant version) Weather System name Weather -Loading… MainWindow Loading… Mainly clear ForecastView Mainly clear Partly cloudy ForecastView Partly cloudy OK PreferencesWindow OK @@ -33,6 +33,7 @@ Clear sky ForecastView Clear sky Moderate rain showers ForecastView Moderate rain showers Enter location: city, country, region CitiesListSelectionWindow Enter location: city, country, region Snow grains ForecastView Snow grains +Temperature: %s\nCondition: %s\nLocation: %s ForecastDeskbarView Temperature: %s\nCondition: %s\nLocation: %s Slight rain showers ForecastView Slight rain showers Heavy rain ForecastView Heavy rain Light drizzle ForecastView Light drizzle