~santi698/gazette/plug-idea

« back to all changes in this revision

Viewing changes to src/Gazette.vala

  • Committer: Santiago Ocamica
  • Date: 2013-05-09 15:35:01 UTC
  • Revision ID: santi6982@gmail.com-20130509153501-kdxrao04yjnnjw13
Only save states on SIGINT or SIGTERM, one write to settings per session :)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
using Clutter;
2
2
 
 
3
// Global variable for saving on SIGTERM
3
4
 
4
5
public class GlobalSettings : Granite.Services.Settings
5
6
{
23
24
 
24
25
public class Gazette.App : Granite.Application
25
26
{
 
27
    public static PluginManager plugin_manager;
 
28
 
26
29
        construct
27
30
        {
28
31
                program_name = "Gazette";
29
32
                application_id = "org.pantheon.gazette";
30
33
        }
31
34
        const int MARGIN = 50;
32
 
    public PluginManager plugin_manager;
 
35
//    public PluginManager plugin_manager;
33
36
    private GazetteWindow window;
34
37
        ~App () {
35
38
            debug("destructor called");
62
65
                    plugin.service.settings_deserialize(states[plugin.id]);
63
66
                }
64
67
            }
65
 
//            Process.signal(ProcessSignal.TERM, save_states);
 
68
            Process.signal(ProcessSignal.TERM, save_states);
 
69
            Process.signal(ProcessSignal.INT, save_states);
66
70
            return false;
67
71
        });
68
72
        }
69
73
    public void load_plugin (Plugin plugin) {
70
74
        debug ("Loading service");
71
75
        Service service = new Service (plugin);
72
 
        service.state_changed.connect(save_states);
73
76
        plugin.assign_service (service);
74
77
        plugin.load ();
75
78
        window.stage.add_child (service);
76
79
    }
77
 
    public void save_states () {
78
 
        //debug("Saving states before exiting");
 
80
    public static void save_states () {
 
81
        debug("Saving states before exiting");
79
82
        string[] plugin_states = {};
80
 
        var plugins = plugin_manager.get_plugins();
 
83
        var plugins = Gazette.App.plugin_manager.get_plugins();
81
84
            foreach (var p in plugins) {
82
85
                plugin_states += p.id.to_string () + ":" + p.service.settings_serialize();
83
86
        }
84
87
        GlobalSettings.get_default ().service_states = plugin_states;
85
 
        //Process.exit(0);
 
88
        Process.exit(0);
86
89
    }
87
90
}
88
91
 
 
92
 
89
93
int main (string [] args)
90
94
{
91
95
        GtkClutter.init (ref args);