~ubuntu-branches/ubuntu/precise/xfce4-power-manager/precise

« back to all changes in this revision

Viewing changes to common/xfpm-common.c

  • Committer: Bazaar Package Importer
  • Author(s): Lionel Le Folgoc
  • Date: 2010-12-09 18:28:34 UTC
  • mto: This revision was merged to the branch mainline in revision 19.
  • Revision ID: james.westby@ubuntu.com-20101209182834-tjz13qcewqlq19eu
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * * Copyright (C) 2008-2009 Ali <aliov@xfce.org>
 
3
 *
 
4
 * Licensed under the GNU General Public License Version 2
 
5
 *
 
6
 * This program is free software; you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation; either version 2 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program; if not, write to the Free Software
 
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
19
 */
 
20
 
 
21
#include <glib.h>
 
22
 
 
23
#include <libxfce4util/libxfce4util.h>
 
24
 
 
25
#include "xfpm-common.h"
 
26
 
 
27
const gchar *xfpm_bool_to_string (gboolean value)
 
28
{
 
29
    if ( value == TRUE ) return "TRUE";
 
30
    else                 return "FALSE";
 
31
}
 
32
 
 
33
gboolean xfpm_string_to_bool (const gchar *string)
 
34
{
 
35
    if ( !g_strcmp0 (string, "TRUE") ) return TRUE;
 
36
    else if ( !g_strcmp0 (string, "FALSE") ) return FALSE;
 
37
    
 
38
    return FALSE;
 
39
}
 
40
 
 
41
GtkBuilder *xfpm_builder_new_from_string (const gchar *ui, GError **error)
 
42
{
 
43
    GtkBuilder *builder;
 
44
 
 
45
    builder = gtk_builder_new ();
 
46
    
 
47
    gtk_builder_add_from_string (GTK_BUILDER (builder),
 
48
                                 ui,
 
49
                                 -1,
 
50
                                 error);
 
51
    
 
52
    return builder;
 
53
}
 
54
 
 
55
static void
 
56
xfpm_link_browser (GtkAboutDialog *about, const gchar *link, gpointer data)
 
57
{
 
58
    gchar *cmd;
 
59
    
 
60
    cmd = g_strdup_printf ("%s %s","xdg-open", link);
 
61
    
 
62
    if ( !g_spawn_command_line_async (cmd, NULL) )
 
63
    {
 
64
        g_free (cmd);
 
65
        cmd = g_strdup_printf ("%s %s","xfbrowser4", link);
 
66
        g_spawn_command_line_async (cmd, NULL);
 
67
    }
 
68
    g_free (cmd);
 
69
        
 
70
}
 
71
 
 
72
static void
 
73
xfpm_link_mailto (GtkAboutDialog *about, const gchar *link, gpointer data)
 
74
{
 
75
    gchar *cmd = g_strdup_printf( "%s %s", "xdg-email", link);
 
76
 
 
77
    g_spawn_command_line_async (cmd, NULL);
 
78
    
 
79
    g_free (cmd);
 
80
}
 
81
        
 
82
void       
 
83
xfpm_lock_screen (void)
 
84
{
 
85
    gboolean ret = g_spawn_command_line_async ("xflock4", NULL);
 
86
    
 
87
    if ( !ret )
 
88
    {
 
89
        g_spawn_command_line_async ("gnome-screensaver-command -l", NULL);
 
90
    }
 
91
    
 
92
    if ( !ret )
 
93
    {
 
94
        /* this should be the default*/
 
95
        ret = g_spawn_command_line_async ("xdg-screensaver lock", NULL);
 
96
    }
 
97
    
 
98
    if ( !ret )
 
99
    {
 
100
        ret = g_spawn_command_line_async ("xscreensaver-command -lock", NULL);
 
101
    }
 
102
    
 
103
    if ( !ret )
 
104
    {
 
105
        g_critical ("Connot lock screen\n");
 
106
    }
 
107
}
 
108
 
 
109
void       
 
110
xfpm_preferences (void) 
 
111
{
 
112
    g_spawn_command_line_async ("xfce4-power-manager-settings", NULL);
 
113
}
 
114
 
 
115
void       
 
116
xfpm_help (void)
 
117
{
 
118
    g_spawn_command_line_async ("xfhelp4 xfce4-power-manager.html", NULL);
 
119
}
 
120
 
 
121
void
 
122
xfpm_quit (void)
 
123
{
 
124
    g_spawn_command_line_async ("xfce4-power-manager -q", NULL);
 
125
}
 
126
 
 
127
void       
 
128
xfpm_about (GtkWidget *widget, gpointer data)
 
129
{
 
130
    gchar *package = (gchar *)data;
 
131
    
 
132
    const gchar* authors[3] = 
 
133
    {
 
134
        "Ali Abdallah <aliov@xfce.org>", 
 
135
         NULL
 
136
    };
 
137
                                                            
 
138
    static const gchar *documenters[] =
 
139
    {
 
140
        "Ali Abdallah <aliov@xfce.org>",
 
141
        NULL,
 
142
    };
 
143
    
 
144
 
 
145
    gtk_about_dialog_set_url_hook (xfpm_link_browser, NULL, NULL);
 
146
    gtk_about_dialog_set_email_hook (xfpm_link_mailto, NULL, NULL);
 
147
    
 
148
    gtk_show_about_dialog (NULL,
 
149
                     "authors", authors,
 
150
                     "copyright", "Copyright \302\251 2008-2009 Ali Abdallah",
 
151
                     "destroy-with-parent", TRUE,
 
152
                     "documenters", documenters,
 
153
                     "license", XFCE_LICENSE_GPL,
 
154
                     "name", package,
 
155
                     "translator-credits", _("translator-credits"),
 
156
                     "version", PACKAGE_VERSION,
 
157
                     "website", "http://goodies.xfce.org",
 
158
                     NULL);
 
159
                                                 
 
160
}
 
161
 
 
162
gboolean xfpm_is_multihead_connected (void)
 
163
{
 
164
    GdkDisplay *dpy;
 
165
    GdkScreen *screen;
 
166
    gint nscreen;
 
167
    gint nmonitor;
 
168
    
 
169
    dpy = gdk_display_get_default ();
 
170
    
 
171
    nscreen = gdk_display_get_n_screens (dpy);
 
172
    
 
173
    if ( nscreen == 1 )
 
174
    {
 
175
        screen = gdk_display_get_screen (dpy, 0);
 
176
        if ( screen )
 
177
        {
 
178
            nmonitor = gdk_screen_get_n_monitors (screen);
 
179
            if ( nmonitor > 1 )
 
180
            {
 
181
                g_debug ("Multiple monitor connected");
 
182
                return TRUE; 
 
183
            }
 
184
            else
 
185
                return FALSE;
 
186
        }
 
187
    }
 
188
    else if ( nscreen > 1 )
 
189
    {
 
190
        g_debug ("Multiple screen connected");
 
191
        return TRUE;
 
192
    }
 
193
    
 
194
    return FALSE;
 
195
}
 
196
 
 
197
GdkPixbuf *xfpm_icon_load (const gchar *icon_name, gint size)
 
198
{
 
199
    GdkPixbuf *pix = NULL;
 
200
    GError *error = NULL;
 
201
    
 
202
    pix = gtk_icon_theme_load_icon (gtk_icon_theme_get_default (), 
 
203
                                    icon_name, 
 
204
                                    size,
 
205
                                    GTK_ICON_LOOKUP_USE_BUILTIN,
 
206
                                    &error);
 
207
                                    
 
208
    if ( error )
 
209
    {
 
210
        g_warning ("Unable to load icon : %s : %s", icon_name, error->message);
 
211
        g_error_free (error);
 
212
    }
 
213
    
 
214
    return pix;
 
215
}
 
216