~ubuntu-branches/ubuntu/wily/alarm-clock-applet/wily

« back to all changes in this revision

Viewing changes to src/prefs.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-05-19 00:26:36 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20100519002636-7ejwhmytu863rmqt
Tags: 0.3.1-1
* New upstraem release
* debian/alarm-clock-applet.links:
  + Link alarm-clock-applet.desktop into /etc/xdg/autostart to make it
    start up automatically (Closes: #577276)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
#include <glib.h>
25
25
#include <gio/gio.h>
26
26
 
 
27
#include <config.h>
27
28
#include "prefs.h"
28
29
 
29
30
 
223
224
        if (state) {
224
225
                // Enable
225
226
                g_debug ("Preferences: Autostart ENABLE!");
226
 
                if (file == autostart_user_file) {
227
 
                        // Unset Hidden and X-GNOME-Autostart-enabled
228
 
                        kf = g_key_file_new ();
229
 
 
230
 
                        filename = g_file_get_path (file);
231
 
 
232
 
                        if (g_key_file_load_from_file(kf, filename, G_KEY_FILE_NONE, &err)) {
233
 
                                g_key_file_remove_key (kf, "Desktop Entry", "Hidden", NULL);
234
 
                                g_key_file_remove_key (kf, "Desktop Entry", "X-GNOME-Autostart-enabled", NULL);
235
 
 
236
 
                                // Write out results
237
 
                                fstream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &err);
238
 
                                if (fstream) {
239
 
                                        str = g_key_file_to_data (kf, &length, NULL);
240
 
 
241
 
                                        g_print ("Writing str: %s", str);
242
 
                                        g_output_stream_write_all (G_OUTPUT_STREAM (fstream), str, length, NULL, NULL, &err);
243
 
                                        g_output_stream_close (G_OUTPUT_STREAM (fstream), NULL, &err);
244
 
 
245
 
                                        g_free (str);
246
 
                                }
247
 
                        }
248
 
 
249
 
                        g_key_file_free (kf);
250
 
 
251
 
                        if (err) {
252
 
                                g_warning ("Preferences: Error when enabling autostart-file '%s': %s", filename, err->message);
253
 
                                g_error_free (err);
254
 
                        }
255
 
 
256
 
                        g_free(filename);
257
 
 
258
 
                } else {
 
227
 
 
228
                if (file != autostart_user_file) {
259
229
                        // Copy .desktop to autostart_user_file
260
230
                        filename = g_build_filename (ALARM_CLOCK_DATADIR, "applications", PACKAGE ".desktop", NULL);
261
231
                        f = g_file_new_for_path (filename);
268
238
                        g_free (filename);
269
239
                }
270
240
 
 
241
                // Unset Hidden and X-GNOME-Autostart-enabled
 
242
                kf = g_key_file_new ();
 
243
 
 
244
                filename = g_file_get_path (autostart_user_file);
 
245
 
 
246
                if (g_key_file_load_from_file(kf, filename, G_KEY_FILE_NONE, &err)) {
 
247
                        g_key_file_remove_key (kf, "Desktop Entry", "Hidden", NULL);
 
248
                        g_key_file_remove_key (kf, "Desktop Entry", "X-GNOME-Autostart-enabled", NULL);
 
249
 
 
250
                        // Start hidden on autostart
 
251
                        g_key_file_set_string (kf, "Desktop Entry", "Exec", PACKAGE " --hidden");
 
252
 
 
253
                        // Write out results
 
254
                        fstream = g_file_replace (autostart_user_file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &err);
 
255
                        if (fstream) {
 
256
                                str = g_key_file_to_data (kf, &length, NULL);
 
257
 
 
258
                                g_print ("Writing str: %s", str);
 
259
                                g_output_stream_write_all (G_OUTPUT_STREAM (fstream), str, length, NULL, NULL, &err);
 
260
                                g_output_stream_close (G_OUTPUT_STREAM (fstream), NULL, &err);
 
261
 
 
262
                                g_free (str);
 
263
                        }
 
264
                }
 
265
 
 
266
                g_key_file_free (kf);
 
267
 
 
268
                if (err) {
 
269
                        g_warning ("Preferences: Error when enabling autostart-file '%s': %s", filename, err->message);
 
270
                        g_error_free (err);
 
271
                }
 
272
 
 
273
                g_free(filename);
 
274
 
271
275
        } else {
272
276
                // Disable
273
277
                g_debug ("Preferences: Autostart DISABLE!");
284
288
                                }
285
289
 
286
290
                                g_free(filename);
287
 
 
288
 
                                file = autostart_user_file;
289
291
                        }
290
292
 
291
293
                        // Set Hidden=true
292
294
                        kf = g_key_file_new ();
293
295
 
294
 
                        filename = g_file_get_path (file);
 
296
                        filename = g_file_get_path (autostart_user_file);
295
297
 
296
298
                        if (g_key_file_load_from_file(kf, filename, G_KEY_FILE_NONE, &err)) {
297
299
                                g_key_file_set_boolean(kf, "Desktop Entry", "Hidden", TRUE);
298
300
 
299
301
                                // Write out results
300
 
                                fstream = g_file_replace (file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &err);
 
302
                                fstream = g_file_replace (autostart_user_file, NULL, FALSE, G_FILE_CREATE_NONE, NULL, &err);
301
303
                                if (fstream) {
302
304
                                        str = g_key_file_to_data (kf, &length, NULL);
303
305