summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/abaddon.cpp38
-rw-r--r--src/components/chatinputindicator.cpp14
-rw-r--r--src/discord/snowflake.cpp11
-rw-r--r--src/discord/snowflake.hpp2
-rw-r--r--src/util.cpp9
5 files changed, 53 insertions, 21 deletions
diff --git a/src/abaddon.cpp b/src/abaddon.cpp
index 51f8052..bf1c6cf 100644
--- a/src/abaddon.cpp
+++ b/src/abaddon.cpp
@@ -64,18 +64,41 @@ int Abaddon::StartGTK() {
m_css_provider = Gtk::CssProvider::create();
m_css_provider->signal_parsing_error().connect([this](const Glib::RefPtr<const Gtk::CssSection> &section, const Glib::Error &error) {
- Gtk::MessageDialog dlg(*m_main_window, "css failed parsing (" + error.what() + ")", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
+ Gtk::MessageDialog dlg("css failed parsing (" + error.what() + ")", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
dlg.set_position(Gtk::WIN_POS_CENTER);
dlg.run();
});
m_css_low_provider = Gtk::CssProvider::create();
m_css_low_provider->signal_parsing_error().connect([this](const Glib::RefPtr<const Gtk::CssSection> &section, const Glib::Error &error) {
- Gtk::MessageDialog dlg(*m_main_window, "low-priority css failed parsing (" + error.what() + ")", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
+ Gtk::MessageDialog dlg("low-priority css failed parsing (" + error.what() + ")", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
dlg.set_position(Gtk::WIN_POS_CENTER);
dlg.run();
});
+#ifdef _WIN32
+ bool png_found = false;
+ bool gif_found = false;
+ for (const auto &fmt : Gdk::Pixbuf::get_formats()) {
+ if (fmt.get_name() == "png")
+ png_found = true;
+ else if (fmt.get_name() == "gif")
+ gif_found = true;
+ }
+
+ if (!png_found) {
+ Gtk::MessageDialog dlg("The PNG pixbufloader wasn't detected. Abaddon may not work as a result.", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
+ dlg.set_position(Gtk::WIN_POS_CENTER);
+ dlg.run();
+ }
+
+ if (!gif_found) {
+ Gtk::MessageDialog dlg("The GIF pixbufloader wasn't detected. Animations may not display as a result.", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
+ dlg.set_position(Gtk::WIN_POS_CENTER);
+ dlg.run();
+ }
+#endif
+
m_main_window = std::make_unique<MainWindow>();
m_main_window->set_title(APP_TITLE);
m_main_window->set_position(Gtk::WIN_POS_CENTER);
@@ -735,6 +758,17 @@ EmojiResource &Abaddon::GetEmojis() {
int main(int argc, char **argv) {
if (std::getenv("ABADDON_NO_FC") == nullptr)
Platform::SetupFonts();
+
+ char *systemLocale = std::setlocale(LC_ALL, "");
+ try {
+ std::locale::global(std::locale(systemLocale));
+ } catch (...) {
+ try {
+ std::locale::global(std::locale::classic());
+ std::setlocale(LC_ALL, systemLocale);
+ } catch (...) {}
+ }
+
#if defined(_WIN32) && defined(_MSC_VER)
TCHAR buf[2] { 0 };
GetEnvironmentVariableA("GTK_CSD", buf, sizeof(buf));
diff --git a/src/components/chatinputindicator.cpp b/src/components/chatinputindicator.cpp
index 9b063b2..ba794f3 100644
--- a/src/components/chatinputindicator.cpp
+++ b/src/components/chatinputindicator.cpp
@@ -25,16 +25,16 @@ ChatInputIndicator::ChatInputIndicator()
if (!std::filesystem::exists(path)) return;
auto gif_data = ReadWholeFile(path);
auto loader = Gdk::PixbufLoader::create();
- loader->signal_size_prepared().connect([&](int inw, int inh) {
- int w, h;
- GetImageDimensions(inw, inh, w, h, 20, 10);
- loader->set_size(w, h);
- });
- loader->write(gif_data.data(), gif_data.size());
try {
+ loader->signal_size_prepared().connect([&](int inw, int inh) {
+ int w, h;
+ GetImageDimensions(inw, inh, w, h, 20, 10);
+ loader->set_size(w, h);
+ });
+ loader->write(gif_data.data(), gif_data.size());
loader->close();
m_img.property_pixbuf_animation() = loader->get_animation();
- } catch (const std::exception &) {}
+ } catch (...) {}
}
void ChatInputIndicator::AddUser(Snowflake channel_id, const UserData &user, int timeout) {
diff --git a/src/discord/snowflake.cpp b/src/discord/snowflake.cpp
index 8f470a7..efa327d 100644
--- a/src/discord/snowflake.cpp
+++ b/src/discord/snowflake.cpp
@@ -3,6 +3,7 @@
#include <chrono>
#include <ctime>
#include <iomanip>
+#include <glibmm.h>
constexpr static uint64_t DiscordEpochSeconds = 1420070400;
@@ -53,14 +54,12 @@ bool Snowflake::IsValid() const {
return m_num != Invalid;
}
-std::string Snowflake::GetLocalTimestamp() const {
+Glib::ustring Snowflake::GetLocalTimestamp() const {
const time_t secs_since_epoch = (m_num / SecondsInterval) + DiscordEpochSeconds;
const std::tm tm = *localtime(&secs_since_epoch);
- std::stringstream ss;
- const static std::locale locale("");
- ss.imbue(locale);
- ss << std::put_time(&tm, "%X %x");
- return ss.str();
+ std::array<char, 256> tmp;
+ std::strftime(tmp.data(), sizeof(tmp), "%X %x", &tm);
+ return tmp.data();
}
void from_json(const nlohmann::json &j, Snowflake &s) {
diff --git a/src/discord/snowflake.hpp b/src/discord/snowflake.hpp
index f2da5d1..e83317a 100644
--- a/src/discord/snowflake.hpp
+++ b/src/discord/snowflake.hpp
@@ -13,7 +13,7 @@ struct Snowflake {
static Snowflake FromISO8601(std::string_view ts);
bool IsValid() const;
- std::string GetLocalTimestamp() const;
+ Glib::ustring GetLocalTimestamp() const;
bool operator==(const Snowflake &s) const noexcept {
return m_num == s.m_num;
diff --git a/src/util.cpp b/src/util.cpp
index 6796a3f..0ebe73e 100644
--- a/src/util.cpp
+++ b/src/util.cpp
@@ -1,6 +1,7 @@
#include "util.hpp"
#include <array>
#include <filesystem>
+#include <array>
Semaphore::Semaphore(int count)
: m_count(count) {}
@@ -94,11 +95,9 @@ std::string FormatISO8601(const std::string &in, int extra_offset, const std::st
int offset = GetTimezoneOffset();
tm.tm_sec += offset + extra_offset;
mktime(&tm);
- std::stringstream ss;
- const static std::locale locale("");
- ss.imbue(locale);
- ss << std::put_time(&tm, fmt.c_str());
- return ss.str();
+ std::array<char, 512> tmp;
+ std::strftime(tmp.data(), sizeof(tmp), fmt.c_str(), &tm);
+ return tmp.data();
}
void ScrollListBoxToSelected(Gtk::ListBox &list) {