aboutsummaryrefslogtreecommitdiff
path: root/src/timezone-file.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/timezone-file.cpp')
-rw-r--r--src/timezone-file.cpp27
1 files changed, 20 insertions, 7 deletions
diff --git a/src/timezone-file.cpp b/src/timezone-file.cpp
index 76737b4..c99897a 100644
--- a/src/timezone-file.cpp
+++ b/src/timezone-file.cpp
@@ -19,6 +19,9 @@
#include <datetime/timezone-file.h>
+#include <cerrno>
+#include <cstdlib>
+
namespace unity {
namespace indicator {
namespace datetime {
@@ -29,7 +32,7 @@ FileTimezone::FileTimezone()
FileTimezone::FileTimezone(const std::string& filename)
{
- setFilename(filename);
+ set_filename(filename);
}
FileTimezone::~FileTimezone()
@@ -49,13 +52,23 @@ FileTimezone::clear()
}
void
-FileTimezone::setFilename(const std::string& filename)
+FileTimezone::set_filename(const std::string& filename)
{
clear();
- m_filename = filename;
+ auto tmp = realpath(filename.c_str(), nullptr);
+ if(tmp != nullptr)
+ {
+ m_filename = tmp;
+ free(tmp);
+ }
+ else
+ {
+ g_warning("Unable to resolve path '%s': %s", filename.c_str(), g_strerror(errno));
+ m_filename = filename; // better than nothing?
+ }
- auto file = g_file_new_for_path(filename.c_str());
+ auto file = g_file_new_for_path(m_filename.c_str());
GError * err = nullptr;
m_monitor = g_file_monitor_file(file, G_FILE_MONITOR_NONE, nullptr, &err);
g_object_unref(file);
@@ -66,15 +79,15 @@ FileTimezone::setFilename(const std::string& filename)
}
else
{
- m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(onFileChanged), this);
- g_debug("%s Monitoring timezone file '%s'", G_STRLOC, filename.c_str());
+ m_monitor_handler_id = g_signal_connect_swapped(m_monitor, "changed", G_CALLBACK(on_file_changed), this);
+ g_debug("%s Monitoring timezone file '%s'", G_STRLOC, m_filename.c_str());
}
reload();
}
void
-FileTimezone::onFileChanged(gpointer gself)
+FileTimezone::on_file_changed(gpointer gself)
{
static_cast<FileTimezone*>(gself)->reload();
}