aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/snap.cpp18
-rw-r--r--src/timezone-file.cpp69
2 files changed, 57 insertions, 30 deletions
diff --git a/src/snap.cpp b/src/snap.cpp
index 9b0abee..a087a75 100644
--- a/src/snap.cpp
+++ b/src/snap.cpp
@@ -30,7 +30,7 @@
#include <set>
#include <string>
-#define ALARM_SOUND_FILENAME "/usr/share/sounds/ubuntu/stereo/phone-incoming-call.ogg"
+#define ALARM_SOUND_FILENAME "/usr/share/sounds/ubuntu/ringtones/Suru arpeggio.ogg"
namespace unity {
namespace indicator {
@@ -50,7 +50,6 @@ namespace
// arbitrary number, but we need a consistent id for play/cancel
const int32_t alarm_ca_id = 1;
-gboolean media_cached = FALSE;
ca_context *c_context = nullptr;
guint timeout_tag = 0;
@@ -65,18 +64,6 @@ ca_context* get_ca_context()
g_warning("Failed to create canberra context: %s\n", ca_strerror(rv));
c_context = nullptr;
}
- else
- {
- const char* filename = ALARM_SOUND_FILENAME;
- rv = ca_context_cache(c_context,
- CA_PROP_EVENT_ID, "alarm",
- CA_PROP_MEDIA_FILENAME, filename,
- CA_PROP_CANBERRA_CACHE_CONTROL, "permanent",
- NULL);
- media_cached = rv == CA_SUCCESS;
- if (rv != CA_SUCCESS)
- g_warning("Couldn't add '%s' to canberra cache: %s", filename, ca_strerror(rv));
- }
}
return c_context;
@@ -106,8 +93,6 @@ void play_alarm_sound()
ca_proplist* props = nullptr;
ca_proplist_create(&props);
- if (media_cached)
- ca_proplist_sets(props, CA_PROP_EVENT_ID, "alarm");
ca_proplist_sets(props, CA_PROP_MEDIA_FILENAME, filename);
const auto rv = ca_context_play_full(context, alarm_ca_id, props, on_alarm_play_done, nullptr);
@@ -307,7 +292,6 @@ Snap::Snap()
Snap::~Snap()
{
- media_cached = false;
g_clear_pointer(&c_context, ca_context_destroy);
}
diff --git a/src/timezone-file.cpp b/src/timezone-file.cpp
index c99897a..bbe48f7 100644
--- a/src/timezone-file.cpp
+++ b/src/timezone-file.cpp
@@ -22,6 +22,59 @@
#include <cerrno>
#include <cstdlib>
+namespace
+{
+ std::string get_timezone_from_file(const std::string& filename)
+ {
+ GError * error;
+ GIOChannel * io_channel;
+ std::string ret;
+
+ // read through filename line-by-line until we fine a nonempty non-comment line
+ error = nullptr;
+ io_channel = g_io_channel_new_file(filename.c_str(), "r", &error);
+ if (error == nullptr)
+ {
+ auto line = g_string_new(nullptr);
+
+ while(ret.empty())
+ {
+ const auto io_status = g_io_channel_read_line_string(io_channel, line, nullptr, &error);
+ if ((io_status == G_IO_STATUS_EOF) || (io_status == G_IO_STATUS_ERROR))
+ break;
+ if (error != nullptr)
+ break;
+
+ g_strstrip(line->str);
+
+ if (!line->len) // skip empty lines
+ continue;
+
+ if (*line->str=='#') // skip comments
+ continue;
+
+ ret = line->str;
+ }
+
+ g_string_free(line, true);
+ }
+
+ if (io_channel != nullptr)
+ {
+ g_io_channel_shutdown(io_channel, false, nullptr);
+ g_io_channel_unref(io_channel);
+ }
+
+ if (error != nullptr)
+ {
+ g_warning("%s Unable to read timezone file '%s': %s", G_STRLOC, filename.c_str(), error->message);
+ g_error_free(error);
+ }
+
+ return ret;
+ }
+}
+
namespace unity {
namespace indicator {
namespace datetime {
@@ -95,20 +148,10 @@ FileTimezone::on_file_changed(gpointer gself)
void
FileTimezone::reload()
{
- GError * err = nullptr;
- gchar * str = nullptr;
+ const auto new_timezone = get_timezone_from_file(m_filename);
- if (!g_file_get_contents(m_filename.c_str(), &str, nullptr, &err))
- {
- g_warning("%s Unable to read timezone file '%s': %s", G_STRLOC, m_filename.c_str(), err->message);
- g_error_free(err);
- }
- else
- {
- g_strstrip(str);
- timezone.set(str);
- g_free(str);
- }
+ if (!new_timezone.empty())
+ timezone.set(new_timezone);
}
} // namespace datetime