Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
1c5a6a0
location-geoclue.c: ‘g_type_init’ is deprecated.
jpds-zz Nov 9, 2013
a86566a
src/redshift.c: Use glib.h instead of redefining MAX and MIN.
jpds-zz Nov 9, 2013
fe857e2
src/redshift.c: Use DBus to determine if an active network connection…
jpds-zz Nov 9, 2013
88b6219
src/redshift.c: Remember to g_value_unset().
jpds-zz Nov 9, 2013
145fc8d
src/redshift.c: Check State property instead of ActiveConnections.
jpds-zz Nov 9, 2013
cff5173
src/redshift.c: Improved no active connection warning string.
jpds-zz Nov 9, 2013
b57c6c1
src/redshift.c: Fixed string to match reality.
jpds-zz Nov 9, 2013
5abd80c
src/redshift.c: Renamed have_active_connections() function to
jpds-zz Nov 9, 2013
819c9e6
configure.ac: Added libnm-glib to GLIB PKG_CHECK_MODULES.
jpds-zz Nov 9, 2013
c0a4839
src/redshift-gtk/statusicon.py: DBus parts to check NetworkManager st…
jpds-zz Nov 9, 2013
f32a0e1
src/redshift-gtk/statusicon.py: Use pynotify to show the user that no
jpds-zz Nov 9, 2013
7b18224
src/redshift-gtk/statusicon.py: Give our pynotify notification variab…
jpds-zz Nov 9, 2013
b69bbbd
src/redshift.c: Refactor the g_value_get_uint() so that we can always do
jpds-zz Nov 9, 2013
f20728a
src/redshift-gtk/statusicon.py: I like my spaces for readability.
jpds-zz Nov 9, 2013
39495b7
src/redshift.c: DBUS_TYPE_G_ARRAY_OF_OBJECT_PATH - no longer necessary.
jpds-zz Nov 9, 2013
4c2be9e
src/redshift.c: Removed unnecessary include on nm-connection.h.
jpds-zz Nov 9, 2013
4ce8c55
src/redshift-gtk/statusicon.py: Improved variable names related to DBus.
jpds-zz Nov 9, 2013
4c21789
src/redshift.c: Made network_manager_connected() function more of a q…
jpds-zz Nov 10, 2013
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ PKG_CHECK_MODULES([XCB], [xcb], [have_xcb=yes], [have_xcb=no])
PKG_CHECK_MODULES([XCB_RANDR], [xcb-randr],
[have_xcb_randr=yes], [have_xcb_randr=no])

PKG_CHECK_MODULES([GLIB], [glib-2.0 gobject-2.0], [have_glib=yes], [have_glib=no])
PKG_CHECK_MODULES([GLIB], [glib-2.0 gobject-2.0 libnm-glib], [have_glib=yes], [have_glib=no])
PKG_CHECK_MODULES([GCONF], [gconf-2.0], [have_gconf=yes], [have_gconf=no])
PKG_CHECK_MODULES([GEOCLUE], [geoclue], [have_geoclue=yes], [have_geoclue=no])

Expand Down
2 changes: 0 additions & 2 deletions src/location-geoclue.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,6 @@
int
location_geoclue_init(location_geoclue_state_t *state)
{
g_type_init();

state->position = NULL;
state->provider = NULL;
state->provider_path = NULL;
Expand Down
23 changes: 23 additions & 0 deletions src/redshift-gtk/statusicon.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@
appindicator module isn't present it will fall back to a GTK status icon.
'''

import dbus
import sys, os
import subprocess, signal
import gettext

import pynotify
import pygtk
pygtk.require("2.0")

Expand Down Expand Up @@ -54,6 +56,10 @@ def run():
args.insert(0, os.path.join(defs.BINDIR, 'redshift'))
process = subprocess.Popen(args)

system_bus = dbus.SystemBus()
system_bus_proxy = system_bus.get_object("org.freedesktop.NetworkManager",
"/org/freedesktop/NetworkManager")

try:
if appindicator:
# Create indicator
Expand All @@ -67,6 +73,16 @@ def run():
status_icon.set_from_icon_name('redshift-status-on')
status_icon.set_tooltip('Redshift')

def is_connected():
# Get latest state from NetworkManager.
nm_state = system_bus_proxy.Get("org.freedesktop.NetworkManager",
"State")

if nm_state == 70:
return True

return False

def is_enabled():
if appindicator:
return indicator.get_icon() == 'redshift-status-on'
Expand Down Expand Up @@ -174,6 +190,13 @@ def popup_menu_cb(widget, button, time, data=None):
def child_cb(pid, cond, data=None):
sys.exit(-1)

if not is_connected():
pynotify.init ("Redshift")
connectivity_notification = pynotify.Notification("Redshift",
_("No active network connection available to retrieve location "
"information."), "redshift")
connectivity_notification.show()

# Add watch on child process
glib.child_watch_add(process.pid, child_cb)

Expand Down
63 changes: 58 additions & 5 deletions src/redshift.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# include "config.h"
#endif

#include <glib.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
Expand All @@ -30,6 +31,9 @@
#include <locale.h>
#include <errno.h>

#include <dbus/dbus-glib.h>
#include <NetworkManager.h>

#if defined(HAVE_SIGNAL_H) && !defined(__WIN32__)
# include <signal.h>
#endif
Expand All @@ -46,11 +50,6 @@
#include "solar.h"
#include "systemtime.h"


#define MIN(x,y) ((x) < (y) ? (x) : (y))
#define MAX(x,y) ((x) > (y) ? (x) : (y))


#if !(defined(ENABLE_RANDR) || \
defined(ENABLE_VIDMODE) || \
defined(ENABLE_WINGDI))
Expand Down Expand Up @@ -622,6 +621,39 @@ find_location_provider(const char *name)
return provider;
}

static int
is_network_manager_connected (DBusGConnection *bus, DBusGProxy *proxy)
{
GError *error = NULL;
GValue value = G_VALUE_INIT;
unsigned int state_reported;

/* Get the State property from the NM Manager object */
if (!dbus_g_proxy_call (proxy, "Get", &error,
G_TYPE_STRING, NM_DBUS_INTERFACE,
G_TYPE_STRING, "State",
G_TYPE_INVALID,
G_TYPE_VALUE, &value,
G_TYPE_INVALID)) {
g_warning ("Failed to get State property: %s", error->message);
g_error_free (error);
}

/* Make sure the State property is the type we expect it to be. */
if (!G_VALUE_HOLDS (&value, G_TYPE_UINT)) {
g_warning ("Unexpected type returned getting State: %s",
G_VALUE_TYPE_NAME (&value));
}

state_reported = g_value_get_uint(&value);
g_value_reset (&value);

if (state_reported == NM_STATE_CONNECTED_GLOBAL) {
return 1;
}

return 0;
}

int
main(int argc, char *argv[])
Expand All @@ -638,6 +670,19 @@ main(int argc, char *argv[])
textdomain(PACKAGE);
#endif

DBusGConnection *bus;
DBusGProxy *props_proxy;

bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, NULL);

props_proxy = dbus_g_proxy_new_for_name (bus,
NM_DBUS_SERVICE,
NM_DBUS_PATH,
DBUS_INTERFACE_PROPERTIES);

g_assert (props_proxy);


/* Initialize settings to NULL values. */
char *config_filepath = NULL;

Expand Down Expand Up @@ -929,6 +974,14 @@ main(int argc, char *argv[])
&config_state, provider_args);
if (r < 0) exit(EXIT_FAILURE);
} else {
if(!is_network_manager_connected(bus, props_proxy)) {
g_warning("NetworkManager reports no network connection "
"activated.");
exit(EXIT_FAILURE);
} else {
printf(_("NetworkManager reports active network connection "
"exists.\n"));
}
/* Try all providers, use the first that works. */
for (int i = 0;
location_providers[i].name != NULL; i++) {
Expand Down