Use the LED pattern helper to overwrite mce.ini and restart MCE
[led-pattern-ed] / src / led-pattern-editor.vala
1 /* This file is part of LED Pattern Editor.
2  *
3  * Copyright (C) 2010 Philipp Zabel
4  *
5  * LED Pattern Editor is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * LED Pattern Editor is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with LED Pattern Editor. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 public static Osso.Status execute (Osso.Context osso, void* data, bool user_activated) {
20         var window = data as Gtk.Window;
21
22         var list = mce_ini_parse ();
23
24         var dialog = new LedPatternDialog (list);
25         dialog.set_transient_for (window);
26
27         int response = dialog.run ();
28         dialog.destroy ();
29         if (response == Gtk.ResponseType.OK) {
30                 mce_ini_store (list);
31                 var note = new Hildon.Note.confirmation (window, "WARNING! Apply changes without further inspection? Let's hope there is no bug in this program. Writing a broken /etc/mce/mce.ini can brick the device. If unsure, select No and apply the changes manually after inspection.");
32                 response = note.run ();
33                 note.destroy ();
34                 if (response == Gtk.ResponseType.OK) {
35                         Hildon.Banner.show_information (window, null, "Applying changes and restarting MCE ...");
36                         try {
37                                 int exit_status;
38                                 string error;
39                                 var command = "sudo /usr/bin/led-pattern-helper save /tmp/mce.ini";
40                                 Process.spawn_command_line_sync (command, null, out error, out exit_status);
41                                 if (exit_status != 0) {
42                                         var information = "Exit status: %d\n%s".printf (exit_status, error);
43                                         note = new Hildon.Note.information (window, information);
44                                         note.run ();
45                                 }
46                         } catch (SpawnError e) {
47                                 Hildon.Banner.show_information (null, null, e.message);
48                         }
49                 } else {
50                         note = new Hildon.Note.information (window, "The modified LED patterns are stored in /tmp/mce.ini. You have to manually copy this file to /etc/mce/mce.ini and restart MCE for the changes to take effect:\n\nmv /tmp/mce.ini /etc/mce/mce.ini\ninitctl stop mce; sleep 2; initctl start mce");
51                         note.run ();
52                 }
53         }
54
55         return Osso.Status.OK;
56 }
57
58 public static Osso.Status save_state (Osso.Context osso, void* data) {
59         return Osso.Status.OK;
60 }