-
Notifications
You must be signed in to change notification settings - Fork 43
panel: Add weather widget #329
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
Draft
soreau
wants to merge
2
commits into
master
Choose a base branch
from
wf-panel-weather-widget
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−0
Draft
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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( | ||
| 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(); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| }; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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..
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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_FOLLOWis passed toinotify_add_watch().