Skip to content

Commit

Permalink
Fix Deskbar icon and tooltip
Browse files Browse the repository at this point in the history
  • Loading branch information
dospuntos committed Oct 22, 2023
1 parent cb695af commit 007d4d1
Show file tree
Hide file tree
Showing 7 changed files with 100 additions and 32 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,14 @@ OPTIMIZE :=
# will recreate only the "locales/en.catkeys" file. Use it as a template
# for creating catkeys for other languages. All localization files must be
# placed in the "locales" subdirectory.
LOCALES = ca de en_AU en_GB en eo es fr fur it nl pt ru sv tr uk
LOCALES = ca de en_AU en_GB en eo es fr fur it nb nl pt ru sv tr uk

# Specify all the preprocessor symbols to be defined. The symbols will not
# have their values set automatically; you must supply the value (if any) to
# use. For example, setting DEFINES to "DEBUG=1" will cause the compiler
# option "-DDEBUG=1" to be used. Setting DEFINES to "DEBUG" would pass
# "-DDEBUG" on the compiler's command line.
DEFINES :=
DEFINES :=

# Specify the warning level. Either NONE (suppress all warnings),
# ALL (enable all warnings), or leave blank (enable default warnings).
Expand All @@ -110,7 +110,7 @@ SYMBOLS :=

# Includes debug information, which allows the binary to be debugged easily.
# If set to "TRUE", debug info will be created.
DEBUGGER :=
DEBUGGER :=

# Specify any additional compiler flags to be used.
COMPILER_FLAGS =
Expand Down
31 changes: 19 additions & 12 deletions Source/ForecastDeskbarView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,26 @@
* All rights reserved. Distributed under the terms of the MIT license.
*/

#include <Alert.h>
#include <Bitmap.h>
#include <Catalog.h>
#include <Looper.h>
#include <MessageRunner.h>
#include <Roster.h>
#include <String.h>
#include <StringView.h>

#include "App.h"
#include "ForecastDeskbarView.h"
#include "ForecastView.h"
#include "Util.h"

#undef B_TRANSLATION_CONTEXT
#define B_TRANSLATION_CONTEXT "ForecastDeskbarView"

const uint32 kUpdateForecastMessage = 'Updt';
//const uint32 kOpenWeatherApp = 'Owea';
const float kToolTipDelay = 1000000; /*1000000ms = 1s*/

extern "C" _EXPORT BView* instantiate_deskbar_item();

ForecastDeskbarView::ForecastDeskbarView(BRect viewSize, ForecastView* forecastView)
:
Expand Down Expand Up @@ -48,17 +52,15 @@ ForecastDeskbarView::AttachedToWindow()
AdoptParentColors();
}

extern "C" _EXPORT BView* instantiate_deskbar_item();


BView*
extern "C" _EXPORT BView*
instantiate_deskbar_item()
{
BMessage settings;
LoadSettings(settings);
ForecastDeskbarView* view = new ForecastDeskbarView(
BRect(0, 0, 16, 16),
new ForecastView(BRect(0, 0, 0, 0),
BRect(0, 0, 16, 16),
new ForecastView(BRect(0, 0, 0, 0),
&settings));
entry_ref appRef;
settings.FindRef("appLocation", &appRef);
Expand All @@ -73,11 +75,11 @@ 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* bitmap = fForecastView->GetWeatherIcon(static_cast<weatherIconSize>(1));
if (bitmap)
DrawBitmapAsync(bitmap, BPoint(0, 0));
DrawBitmapAsync(bitmap, drawRect);
SetDrawingMode(B_OP_COPY);
}

Expand All @@ -96,14 +98,19 @@ void
ForecastDeskbarView::MessageReceived(BMessage* message)
{
if (message->what == kUpdateForecastMessage) {

// Todo: Reload after X minutes
//if (fForecastView->IsConnected())
//fForecastView->Reload();

BString weatherDetailsText;
weatherDetailsText << "Temperature: "
weatherDetailsText << B_TRANSLATE("Temperature: ")
<< FormatString(fForecastView->Unit(),
fForecastView->Temperature())
<< "\n";
weatherDetailsText << "Condition: " << fForecastView->GetCondition()
weatherDetailsText << B_TRANSLATE("Condition: ") << fForecastView->GetStatus()
<< "\n";
weatherDetailsText << "Location: " << fForecastView->CityName();
weatherDetailsText << B_TRANSLATE("Location: ") << fForecastView->CityName();
SetToolTip(weatherDetailsText.String());

Invalidate();
Expand Down
9 changes: 3 additions & 6 deletions Source/ForecastDeskbarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,23 @@

#include <Bitmap.h>
#include <Entry.h>
#include <Looper.h>
#include <MessageRunner.h>
#include <SupportDefs.h>
#include <View.h>

#include "ForecastView.h"


class ForecastDeskbarView : public BView
{

public:
ForecastDeskbarView(BRect viewSize, ForecastView* forecastView);
~ForecastDeskbarView();

virtual void AttachedToWindow();
virtual void MouseDown(BPoint point);
virtual void MouseMoved(
BPoint point,
uint32 message,
BPoint point,
uint32 message,
const BMessage* dragMessage);
virtual void Draw(BRect drawRect);
virtual void MessageReceived(BMessage* message);
Expand Down
8 changes: 4 additions & 4 deletions Source/ForecastView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
* Copyright 2015 Przemysław Buczkowski <[email protected]>
* Copyright 2014 George White
* All rights reserved. Distributed under the terms of the MIT license.
*/
*/

#include <Alert.h>
#include <AppKit.h>
#include <Bitmap.h>
Expand Down Expand Up @@ -56,7 +56,7 @@ extern const char* kSignature;
class TransparentButton : public BButton
{
public:
TransparentButton(const char* name, const char* label,
TransparentButton(const char* name, const char* label,
BMessage* message);
virtual void Draw(BRect updateRect);
};
Expand Down Expand Up @@ -1246,4 +1246,4 @@ ForecastView::_NetworkConnected()
}
}
return false;
}
}
10 changes: 5 additions & 5 deletions Source/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ 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"), new BMessage(kToggleDeskbarReplicantMessage), 'T'));
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'));
menu->AddItem(new BMenuItem(B_TRANSLATE("Preferences" B_UTF8_ELLIPSIS),
Expand Down Expand Up @@ -90,7 +90,7 @@ MainWindow::MainWindow()
fForecastView = new ForecastView(BRect(0, 0, 100, 100), &settings);
AddChild(fForecastView);
// Enable when works
// fShowForecastMenuItem->SetMarked(fForecastView->ShowForecast());
//fShowForecastMenuItem->SetMarked(fForecastView->ShowForecast());
}


Expand Down Expand Up @@ -253,8 +253,8 @@ void
MainWindow::MenusBeginning()
{
// Menu item removed until Deskbar replicant is fixed
// BDeskbar deskbar;
// fReplicantMenuItem->SetMarked(deskbar.HasItem("ForecastDeskbarView"));
BDeskbar deskbar;
fReplicantMenuItem->SetMarked(deskbar.HasItem("ForecastDeskbarView"));
}


Expand Down
8 changes: 6 additions & 2 deletions locales/en.catkeys
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
1 English x-vnd.przemub.Weather 704655087
1 English x-vnd.przemub.Weather 878890540
Location: ForecastDeskbarView Location:
No network ForecastView No network
OK ForecastView OK
Slight rain ForecastView Slight rain
Slight snow showers ForecastView Slight snow showers
Loading… ForecastView Loading…
OK MainWindow OK
Quit MainWindow Quit
Dense drizzle ForecastView Dense drizzle
Heavy snow showers ForecastView Heavy snow showers
Dense drizzle ForecastView Dense drizzle
City: CitiesListSelectionWindow City:
Background ForecastView Background
Preferences… MainWindow Preferences…
Expand All @@ -26,6 +27,7 @@ Connecting… ForecastView Connecting…
Unable to create a deskbar replicant. The error is: \" MainWindow Unable to create a deskbar replicant. The error is: \"
Overcast ForecastView Overcast
Moderate rain ForecastView Moderate rain
Temperature: ForecastDeskbarView Temperature:
Depositing rime fog ForecastView Depositing rime fog
About Weather MainWindow About Weather
Moderate drizzle ForecastView Moderate drizzle
Expand Down Expand Up @@ -58,3 +60,5 @@ Slight snow fall ForecastView Slight snow fall
Cancel CitiesListSelectionWindow Cancel
About Weather ForecastView About Weather
Moderate snow fall ForecastView Moderate snow fall
Condition: ForecastDeskbarView Condition:
Deskbar Replicant MainWindow Deskbar Replicant
60 changes: 60 additions & 0 deletions locales/nb.catkeys
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
1 Norwegian x-vnd.przemub.Weather 704655087
About Weather ForecastView Om Weather
Background ForecastView Bakgrunn
Clear sky ForecastView Klar himmel
Connecting… ForecastView Kobler til...
Connection error ForecastView Tilkoblingsfeil
Default ForecastView Standard
Dense drizzle ForecastView Tett duskregn
Depositing rime fog ForecastView Rimtåke
Fog ForecastView Tåke
Freezing dense drizzle ForecastView Underkjølt tett duskregn
Freezing light drizzle ForecastView Underkjølt lett duskregn
Heavy freezing rain ForecastView Kraftig underkjølt regn
Heavy rain ForecastView Kraftig regn
Heavy rain showers ForecastView Kraftige regnbyger
Heavy snow fall ForecastView Kraftig snøfall
Heavy snow showers ForecastView Kraftige regnbyger
Light drizzle ForecastView Lett duskregn
Light freezing rain ForecastView Lett underkjølt regn
Loading… ForecastView Laster...
Mainly clear ForecastView Hovedsakelig klart
Moderate drizzle ForecastView Moderat duskregn
Moderate rain ForecastView Moderat regn
Moderate rain showers ForecastView Moderate regnbyger
Moderate snow fall ForecastView Moderat snøfall
No network ForecastView Ingen nettverk
Not available ForecastView Ikke tilgjengelig
OK ForecastView OK
Overcast ForecastView Overskyet
Partly cloudy ForecastView Delvis skyet
Slight rain ForecastView Lett regn
Slight rain showers ForecastView Lette regnbyger
Slight snow fall ForecastView Lett snøfall
Slight snow showers ForecastView Lette snøbyger
Snow grains ForecastView Snøkorn
Text ForecastView Tekst
Thunderstorm ForecastView Tordenvær
Thunderstorm with heavy hail ForecastView Tordenvær med kraftig hagl
Thunderstorm with slight hail ForecastView Tordenvær med lett hagl
Transparent ForecastView Gjennomsiktig
Weather (The Replicant version) ForecastView Weather (replikantversjonen)
About Weather MainWindow Om Weather
An open source weather app showing a forecast for the next 5 days. MainWindow En åpen kildekode vær-app som viser et værvarsel for de neste 5 dagene.
Change location… MainWindow Bytt sted...
Loading… MainWindow Laster...
OK MainWindow OK
Preferences… MainWindow Innstillinger...
Quit MainWindow Avslutt
Refresh MainWindow Oppdater
Unable to create a deskbar replicant. The error is: \" MainWindow Kan ikke lage en skrivebordsreplikant. Feilen er: \"
Cancel CitiesListSelectionWindow Avbryt
Choose location CitiesListSelectionWindow Velg sted
City: CitiesListSelectionWindow By:
Enter location: city, country, region CitiesListSelectionWindow Velg sted: by, land, område
OK CitiesListSelectionWindow OK
OK PreferencesWindow OK
Preferences PreferencesWindow Innstillinger
Use Celsius °C PreferencesWindow Bruk Celsius °C
Use Fahrenheit °F PreferencesWindow Bruk Fahrenheit °F
Weather System name Weather

0 comments on commit 007d4d1

Please sign in to comment.