Skip to content
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
12 changes: 12 additions & 0 deletions data/css/default.css
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,18 @@
padding-left: 0px;
}

.wf-panel .weather image {
-gtk-icon-size: 25px;
padding-left: 4px;
padding-right: 4px;
padding-bottom: 4px;
}

.wf-panel .weather label {
font-weight: bold;
font-size: 20px;
}

.wf-panel .network label {
padding-left: 6px;
}
Expand Down
7 changes: 7 additions & 0 deletions metadata/panel.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@
</option>
</group>
<group>
<_short>Weather</_short>
<option name="weather_font" type="string">
<_short>Weather Font</_short>
<default>default</default>
</option>
</group>
<group>
<_short>Battery</_short>
<option name="battery_status" type="string">
<_short>Battery Status</_short>
Expand Down
1 change: 1 addition & 0 deletions src/panel/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ widget_sources = [
'widgets/battery.cpp',
'widgets/menu.cpp',
'widgets/clock.cpp',
'widgets/weather.cpp',
'widgets/command-output.cpp',
'widgets/language.cpp',
'widgets/launchers.cpp',
Expand Down
7 changes: 7 additions & 0 deletions src/panel/panel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "widgets/language.hpp"
#include "widgets/menu.hpp"
#include "widgets/clock.hpp"
#include "widgets/weather.hpp"
#include "widgets/launchers.hpp"
#include "widgets/network.hpp"
#include "widgets/spacing.hpp"
Expand Down Expand Up @@ -148,6 +149,11 @@ class WayfirePanel::impl
return Widget(new WayfireClock());
}

if (name == "weather")
{
return Widget(new WayfireWeather());
}

if (name == "network")
{
return Widget(new WayfireNetworkInfo());
Expand Down Expand Up @@ -384,6 +390,7 @@ void WayfirePanelApp::on_activate()

new CssFromConfigFont("panel/battery_font", ".battery {", "}");
new CssFromConfigFont("panel/clock_font", ".clock {", "}");
new CssFromConfigFont("panel/weather_font", ".weather {", "}");
}

void WayfirePanelApp::handle_new_output(WayfireOutput *output)
Expand Down
75 changes: 75 additions & 0 deletions src/panel/widgets/weather.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include <iostream>
#include <fstream>
#include <glibmm.h>
#include "weather.hpp"
#include "wayfire/nonstd/json.hpp"

void WayfireWeather::init(Gtk::Box *container)
{
label.set_justify(Gtk::Justification::CENTER);
box.get_style_context()->add_class("weather");
box.prepend(label);
box.append(icon);
container->append(box);

update_weather();

timeout = Glib::signal_timeout().connect_seconds(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not using file watching? :D

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably not a bad idea..

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work for symlinks though if the symlinks doesn't change but the file pointed to does?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just looked it up, apparently it follows the symlink to the actual file unless IN_DONT_FOLLOW is passed to inotify_add_watch().

sigc::mem_fun(*this, &WayfireWeather::update_weather), 600);
}

bool WayfireWeather::update_weather()
{
std::string weather_data_dir;

weather_data_dir = std::string(getenv("HOME")) + "/.local/share/owf/data";

std::string file_path = weather_data_dir + "/data.json";

std::ifstream input_file(file_path);

if (!input_file)
{
std::cerr << "Error reading json file " << file_path << std::endl;
return false;
}

std::stringstream buf;
buf << input_file.rdbuf();

wf::json_t json_data;

auto err = wf::json_t::parse_string(buf.str(), json_data);

if (err.has_value())
{
std::cerr << "Error parsing json data " << file_path << ": " << *err << std::endl;
return false;
}

if (!json_data.has_member("temp") || !json_data.has_member("icon"))
{
std::cerr << "Unexpected weather json data in " << file_path << std::endl;
return false;
}

update_label(json_data["temp"]);
update_icon(json_data["icon"]);

return true;
}

void WayfireWeather::update_label(std::string temperature)
{
label.set_text(temperature);
}

void WayfireWeather::update_icon(std::string path)
{
icon.set(path);
}

WayfireWeather::~WayfireWeather()
{
timeout.disconnect();
}
22 changes: 22 additions & 0 deletions src/panel/widgets/weather.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include "../widget.hpp"
#include "wf-popover.hpp"
#include <gtkmm/label.h>
#include <gtkmm/image.h>

class WayfireWeather : public WayfireWidget
{
Gtk::Label label;
Gtk::Image icon;
Gtk::Box box;

sigc::connection timeout;

public:
void init(Gtk::Box *container) override;
bool update_weather();
void update_label(std::string);
void update_icon(std::string);
~WayfireWeather();
};
Loading