Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Deskbar icon and tooltip #101

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
49 changes: 28 additions & 21 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 float kToolTipDelay = 1000000; /*1000000ms = 1s*/
int fMaxHeight;

extern "C" _EXPORT BView* instantiate_deskbar_item(float maxWidth, float maxHeight);

ForecastDeskbarView::ForecastDeskbarView(BRect viewSize, ForecastView* forecastView)
:
Expand All @@ -28,6 +32,13 @@ ForecastDeskbarView::ForecastDeskbarView(BRect viewSize, ForecastView* forecastV
fMessageRunner = NULL;
}

ForecastDeskbarView::ForecastDeskbarView(BMessage* archive)
:
BView(archive)
{
fMessageRunner = NULL;
}


ForecastDeskbarView::~ForecastDeskbarView()
{
Expand All @@ -48,17 +59,16 @@ ForecastDeskbarView::AttachedToWindow()
AdoptParentColors();
}

extern "C" _EXPORT BView* instantiate_deskbar_item();


BView*
instantiate_deskbar_item()
extern "C" _EXPORT BView*
instantiate_deskbar_item(float maxWidth, float maxHeight)
{
fMaxHeight = maxHeight;
BMessage settings;
LoadSettings(settings);
ForecastDeskbarView* view = new ForecastDeskbarView(
BRect(0, 0, 16, 16),
new ForecastView(BRect(0, 0, 0, 0),
BRect(0, 0, maxHeight, maxHeight),
new ForecastView(BRect(0, 0, 0, 0),
&settings));
entry_ref appRef;
settings.FindRef("appLocation", &appRef);
Expand All @@ -73,11 +83,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 @@ -88,24 +98,21 @@ ForecastDeskbarView::Instantiate(BMessage* archive)
if (!validate_instantiation(archive, "ForecastDeskbarView"))
return NULL;

return reinterpret_cast<BArchivable*>(instantiate_deskbar_item());
return reinterpret_cast<BArchivable*>(instantiate_deskbar_item(fMaxHeight, fMaxHeight));
}


void
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());

BString tooltip;
BString temperature = FormatString(fForecastView->Unit(), fForecastView->Temperature());
tooltip.SetToFormat(B_TRANSLATE("Temperature: %s\nCondition: %s\nLocation: %s"),
temperature.String(),
fForecastView->GetStatus().String(),
fForecastView->CityName().String());
SetToolTip(tooltip);
Invalidate();
} else
BView::MessageReceived(message);
Expand Down
12 changes: 5 additions & 7 deletions Source/ForecastDeskbarView.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,24 @@

#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(BMessage* archive);
~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 All @@ -41,4 +39,4 @@ class ForecastDeskbarView : public BView
};


#endif // FORECASTDESKBARVIEW_H
#endif // FORECASTDESKBARVIEW_H
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
6 changes: 4 additions & 2 deletions locales/en.catkeys
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
1 English x-vnd.przemub.Weather 704655087
1 English x-vnd.przemub.Weather 2992569182
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…
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…
Expand All @@ -33,6 +34,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
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