-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs: #24
- Loading branch information
Showing
18 changed files
with
282 additions
and
41 deletions.
There are no files selected for viewing
This file contains 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
Binary file not shown.
This file contains 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 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,72 @@ | ||
#include "alerts.h" | ||
|
||
#include <iomanip> | ||
#include <sstream> | ||
|
||
#include "events.h" | ||
#include "util.h" | ||
|
||
#define T(x) GetLangText(x) | ||
|
||
#define OK_BUTTON_INDEX 0 | ||
#define NEXT_ALERT_BUTTON_INDEX 1 | ||
|
||
static size_t alert_index{0}; | ||
static size_t alert_count{0}; | ||
|
||
inline bool is_next_alert_button_at(int button_index) { | ||
return (alert_index + 1 < alert_count) ? button_index == 1 : false; | ||
} | ||
|
||
void taranis::alert_dialog_handler(int button_index) { | ||
if (is_next_alert_button_at(button_index)) { | ||
const auto event_handler = GetEventHandler(); | ||
++alert_index; | ||
SendEvent(event_handler, EVT_CUSTOM, CustomEvent::display_alert, 0); | ||
} else { | ||
alert_index = 0; | ||
} | ||
CloseDialog(); | ||
} | ||
|
||
void taranis::AlertsButton::open_dialog_maybe() { | ||
alert_count = this->model->alerts.size(); | ||
|
||
if (alert_count == 0) { | ||
return; | ||
} | ||
if (alert_index >= alert_count) { | ||
return; | ||
} | ||
|
||
const auto &alert = this->model->alerts.at(alert_index); | ||
|
||
const auto dialog_title = not alert.event.empty() ? alert.event : T("Alert"); | ||
// 😕 Looks like dialog title isn't displayed at all! | ||
|
||
std::stringstream alert_text; | ||
if (not alert.event.empty()) { | ||
alert_text << alert.event << std::endl << std::endl; | ||
} | ||
alert_text << alert.description << std::endl << std::endl; | ||
if (alert.start_date) { | ||
alert_text << T("Start") << " " << format_time(alert.start_date, true) | ||
<< std::endl; | ||
if (alert.end_date) { | ||
alert_text << T("Duration") << " " | ||
<< format_duration(alert.start_date, alert.end_date) | ||
<< std::endl; | ||
} | ||
} | ||
if (not alert.sender.empty()) { | ||
alert_text << T("Source") << " " << alert.sender; | ||
} | ||
|
||
const auto first_button_text = | ||
alert_index + 1 < alert_count ? T("Next alert") : T("Ok"); | ||
const auto second_button_text = | ||
alert_index + 1 < alert_count ? T("Ok") : nullptr; | ||
|
||
Dialog(ICON_WARNING, dialog_title.c_str(), alert_text.str().c_str(), | ||
first_button_text, second_button_text, &alert_dialog_handler); | ||
} |
This file contains 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,57 @@ | ||
#pragma once | ||
|
||
#include <experimental/optional> | ||
#include <inkview.h> | ||
#include <memory> | ||
|
||
#include "button.h" | ||
#include "fonts.h" | ||
#include "icons.h" | ||
#include "model.h" | ||
|
||
namespace std { | ||
template <class T> using optional = std::experimental::optional<T>; | ||
} | ||
|
||
namespace taranis { | ||
|
||
void alert_dialog_handler(int button_index); | ||
|
||
class AlertsButton : public Button { | ||
public: | ||
AlertsButton(std::shared_ptr<Model> model, std::shared_ptr<Icons> icons, | ||
std::shared_ptr<Fonts> fonts) | ||
: Button{AlertsButton::icon_size + 2 * AlertsButton::padding, | ||
AlertsButton::icon_size + 2 * AlertsButton::padding, | ||
BitmapStretchProportionally(icons->get("warning"), | ||
AlertsButton::icon_size, | ||
AlertsButton::icon_size)}, | ||
model{model}, font{fonts->get_normal_font()} {} | ||
|
||
void show() override { | ||
if (this->model->alerts.empty()) { | ||
this->fill_bounding_box(); | ||
} else { | ||
Button::show(); | ||
} | ||
} | ||
|
||
void open_dialog_maybe(); | ||
|
||
static const int padding{50}; | ||
static const int icon_size{70}; | ||
|
||
protected: | ||
void on_clicked() override { | ||
if (this->model->alerts.empty()) { | ||
return; | ||
} | ||
|
||
this->open_dialog_maybe(); | ||
} | ||
|
||
private: | ||
std::shared_ptr<Model> model; | ||
std::shared_ptr<ifont> font; | ||
}; | ||
} // namespace taranis |
This file contains 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 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 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 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 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 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 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 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
Oops, something went wrong.