Skip to content

Commit

Permalink
Fix tooltip and show condition correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
dospuntos authored and pulkomandy committed Jan 4, 2025
1 parent cba9191 commit 3a818be
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 21 deletions.
41 changes: 25 additions & 16 deletions Source/ForecastDeskbarView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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*/

Expand All @@ -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;
}
Expand All @@ -39,8 +43,8 @@ ForecastDeskbarView::ForecastDeskbarView(BMessage* archive)
// fForecastView is unarchived and already added to the view hierarchy
fForecastView = static_cast<ForecastView*>(FindView("Weather"));
entry_ref appRef;
archive->FindRef("appLocation", &appRef);
SetAppLocation(appRef);
archive->FindRef("appLocation", &appRef);
}


Expand Down Expand Up @@ -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)
Expand All @@ -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;
Expand All @@ -98,7 +102,6 @@ ForecastDeskbarView::Instantiate(BMessage* archive)
{
if (!validate_instantiation(archive, "ForecastDeskbarView"))
return NULL;

return new ForecastDeskbarView(archive);
}

Expand All @@ -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
Expand All @@ -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);
}
}


Expand All @@ -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));
}
2 changes: 1 addition & 1 deletion Source/ForecastDeskbarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

class ForecastDeskbarView : public BView
{

public:
ForecastDeskbarView(BRect viewSize);
ForecastDeskbarView(BMessage* archive);
Expand Down
9 changes: 8 additions & 1 deletion Source/ForecastView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -1288,3 +1289,9 @@ ForecastView::_NetworkConnected()
}
return false;
}

void
ForecastView::SetDeskbarIconSize(int height)
{
fSizeDeskBarIcon = height;
}
1 change: 1 addition & 0 deletions Source/ForecastView.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down
5 changes: 3 additions & 2 deletions locales/en.catkeys
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 3a818be

Please sign in to comment.