~noskcaj/ubuntu/saucy/xfce4-power-manager/1.2.0-2ubuntu1

« back to all changes in this revision

Viewing changes to settings/xfpm-settings-main.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-09 18:28:34 UTC
  • mfrom: (2.3.5 upstream)
  • Revision ID: james.westby@ubuntu.com-20101209182834-efb7dinmf9ssp3es
Tags: 1.0.1-0ubuntu1
Upload to natty (pkg-xfce svn r4665), no Ubuntu changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <glib.h>
31
31
 
32
32
#include <libxfce4util/libxfce4util.h>
33
 
#include <libxfcegui4/libxfcegui4.h>
 
33
#include <libxfce4ui/libxfce4ui.h>
34
34
 
35
35
#include <dbus/dbus-glib.h>
36
36
#include <dbus/dbus-glib-lowlevel.h>
37
37
 
38
38
#include <xfconf/xfconf.h>
39
39
 
40
 
#include "libxfpm/xfpm-popups.h"
41
 
#include "libxfpm/xfpm-string.h"
42
 
#include "libxfpm/xfpm-common.h"
43
 
#include "libxfpm/xfpm-dbus.h"
 
40
#include "common/xfpm-common.h"
44
41
 
45
42
#include "xfce-power-manager-dbus-client.h"
46
43
#include "xfpm-settings.h"
47
44
#include "xfpm-config.h"
48
 
 
49
 
int main(int argc, char **argv)
 
45
#include "xfpm-dbus.h"
 
46
 
 
47
#include "xfpm-unique.h"
 
48
 
 
49
int main (int argc, char **argv)
50
50
{
 
51
    
51
52
    GError *error = NULL;
52
53
    DBusGConnection *bus;
53
54
    GHashTable *config_hash;
54
55
    
55
 
    gboolean system_laptop;
56
 
    gboolean user_privilege;
 
56
    gboolean has_battery;
 
57
    gboolean auth_suspend;
 
58
    gboolean auth_hibernate;
57
59
    gboolean can_suspend;
58
60
    gboolean can_hibernate;
 
61
    gboolean can_shutdown;
59
62
    gboolean has_lcd_brightness;
60
63
    gboolean has_sleep_button;
61
64
    gboolean has_hibernate_button;
62
65
    gboolean has_power_button;
 
66
    gboolean has_lid;
 
67
    gboolean can_spin_down;
 
68
    gboolean devkit_disk;
63
69
    gboolean start_xfpm_if_not_running;
64
70
    
65
71
    GdkNativeWindow socket_id = 0;
98
104
        g_error ("%s\n",error->message);
99
105
    }
100
106
 
101
 
    if ( xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager") ) 
 
107
    if ( xfpm_dbus_name_has_owner (dbus_g_connection_get_connection(bus), "org.xfce.PowerManager") ) 
102
108
    {
 
109
        GtkWidget *dialog;
 
110
        XfpmUnique *unique;
103
111
        TRACE("Xfce power manager is running\n");
104
112
        
105
 
        if ( xfpm_dbus_name_has_owner(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config") )
106
 
        {
107
 
            TRACE("Settings dialog already open\n");
108
 
            dbus_g_connection_unref(bus);
109
 
            return EXIT_SUCCESS;
110
 
        }
111
 
        
112
 
        xfpm_dbus_register_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
113
 
        
114
 
        if ( !xfconf_init(&error) )
115
 
        {
116
 
            g_critical("xfconf init failed: %s using default settings\n", error->message);
117
 
            
118
 
            xfpm_popup_message(_("Xfce Power Manager"),_("Failed to load power manager configuration, "\
119
 
                                "using defaults"), GTK_MESSAGE_WARNING);
120
 
            g_error_free(error);
121
 
            error = NULL;
122
 
            return EXIT_FAILURE;
123
 
        }
124
 
        
125
 
        if ( !g_thread_supported () )
126
 
            g_thread_init (NULL);
127
 
            
128
 
        dbus_g_thread_init ();
129
 
        
130
 
        channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
131
 
        
132
 
        proxy = dbus_g_proxy_new_for_name(bus,
133
 
                                           "org.xfce.PowerManager",
134
 
                                           "/org/xfce/PowerManager",
135
 
                                           "org.xfce.Power.Manager");
136
 
        
137
 
        xfpm_manager_dbus_client_get_config (proxy, 
138
 
                                             &config_hash,
139
 
                                             &error);
140
 
                                             
141
 
        if ( error )
142
 
        {
143
 
            g_critical ("Unable to get configuration information from xfce power manager: %s", error->message);
144
 
            xfpm_error (_("Xfce Power Manager Settings"),
145
 
                       _("Unable to connect to Xfce Power Manager") );
146
 
            g_error_free (error);
147
 
            return EXIT_FAILURE;
148
 
        }
149
 
        
150
 
        system_laptop = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "system-laptop"));
151
 
        can_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-suspend"));
152
 
        can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-hibernate"));
153
 
        user_privilege = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "caller-privilege"));
154
 
        has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-brightness"));
155
 
        has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "sleep-button"));
156
 
        has_power_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "power-button"));
157
 
        has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "hibernate-button"));
158
 
        
159
 
        xfpm_settings_dialog_new (channel, system_laptop, user_privilege,
160
 
                                  can_suspend, can_hibernate, has_lcd_brightness,
161
 
                                  system_laptop, has_sleep_button, has_hibernate_button, has_power_button,
162
 
                                  socket_id);
163
 
                                           
164
 
        gtk_main();
165
 
        
166
 
        xfpm_dbus_release_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
167
 
        dbus_g_connection_unref(bus);
 
113
        unique = xfpm_unique_new ("org.xfce.PowerManager.Config");
 
114
        
 
115
        if ( !xfpm_unique_app_is_running (unique) )
 
116
        {
 
117
            if ( !xfconf_init(&error) )
 
118
            {
 
119
                g_critical("xfconf init failed: %s using default settings\n", error->message);
 
120
                xfce_dialog_show_warning (NULL, 
 
121
                                          _("Xfce Power Manager"), 
 
122
                                          "%s",
 
123
                                          _("Failed to load power manager configuration, using defaults"));
 
124
                g_error_free (error);
 
125
                error = NULL;
 
126
                return EXIT_FAILURE;
 
127
            }
 
128
            
 
129
            if ( !g_thread_supported () )
 
130
                g_thread_init (NULL);
 
131
                
 
132
            dbus_g_thread_init ();
 
133
            
 
134
            channel = xfconf_channel_new(XFPM_CHANNEL_CFG);
 
135
            
 
136
            proxy = dbus_g_proxy_new_for_name(bus,
 
137
                                               "org.xfce.PowerManager",
 
138
                                               "/org/xfce/PowerManager",
 
139
                                               "org.xfce.Power.Manager");
 
140
            
 
141
            xfpm_manager_dbus_client_get_config (proxy, 
 
142
                                                 &config_hash,
 
143
                                                 &error);
 
144
                                                 
 
145
            if ( error )
 
146
            {
 
147
                g_critical ("Unable to get configuration information from xfce power manager: %s", error->message);
 
148
                xfce_dialog_show_error (NULL, error, "%s", _("Unable to connect to Xfce Power Manager"));
 
149
                g_error_free (error);
 
150
                return EXIT_FAILURE;
 
151
            }
 
152
            
 
153
            has_battery = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-battery"));
 
154
            has_lid = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-lid"));
 
155
            can_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-suspend"));
 
156
            can_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-hibernate"));
 
157
            auth_suspend = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-suspend"));
 
158
            auth_hibernate = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "auth-hibernate"));
 
159
            has_lcd_brightness = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "has-brightness"));
 
160
            has_sleep_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "sleep-button"));
 
161
            has_power_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "power-button"));
 
162
            has_hibernate_button = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "hibernate-button"));
 
163
            can_shutdown = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-shutdown"));
 
164
            can_spin_down = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "can-spin"));
 
165
            devkit_disk = xfpm_string_to_bool (g_hash_table_lookup (config_hash, "devkit-disk"));
 
166
            
 
167
            g_hash_table_destroy (config_hash);
 
168
            
 
169
            dialog = xfpm_settings_dialog_new (channel, has_battery, auth_hibernate, auth_suspend,
 
170
                                               can_shutdown, can_suspend, can_hibernate, has_lcd_brightness,
 
171
                                               has_lid, has_sleep_button, has_hibernate_button, has_power_button,
 
172
                                               devkit_disk, can_spin_down, socket_id);
 
173
            
 
174
            g_signal_connect_swapped (unique, "ping-received",
 
175
                                      G_CALLBACK (gtk_window_present), dialog);
 
176
                                               
 
177
            gtk_main();
 
178
            
 
179
            xfpm_dbus_release_name(dbus_g_connection_get_connection(bus), "org.xfce.PowerManager.Config");
 
180
            dbus_g_connection_unref (bus);
 
181
            g_object_unref (proxy);
 
182
        }
 
183
        
 
184
        g_object_unref (unique);
168
185
        
169
186
        return EXIT_SUCCESS;
170
187
    }
173
190
        g_print(_("Xfce power manager is not running"));
174
191
        g_print("\n");
175
192
        start_xfpm_if_not_running =
176
 
            xfce_confirm(_("Xfce4 Power Manager is not running, do you want to launch it now?"),
177
 
                        GTK_STOCK_YES,
178
 
                        _("Run"));
 
193
            xfce_dialog_confirm (NULL, 
 
194
                                 GTK_STOCK_YES, 
 
195
                                 _("Run"), 
 
196
                                 _("Xfce4 Power Manager is not running, do you want to launch it now?"),
 
197
                                 NULL);
 
198
        
179
199
        if ( start_xfpm_if_not_running ) 
180
200
        {
181
201
            g_spawn_command_line_async("xfce4-power-manager",NULL);