Merge lp:~andrewfister/deja-dup/network-manager into lp:~deja-dup-team/deja-dup/trunk

Proposed by Andrew Fister
Status: Merged
Merged at revision: not available
Proposed branch: lp:~andrewfister/deja-dup/network-manager
Merge into: lp:~deja-dup-team/deja-dup/trunk
Diff against target: 180 lines
4 files modified
configure.ac (+1/-0)
deja-dup/Makefile.am (+3/-1)
libdeja-dup/Duplicity.vala (+56/-2)
libdeja-dup/DuplicityInstance.vala (+26/-1)
To merge this branch: bzr merge lp:~andrewfister/deja-dup/network-manager
Reviewer Review Type Date Requested Status
Michael Terry Approve
Review via email: mp+13252@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrew Fister (andrewfister) wrote :

The new code is ready for review and testing.

Revision history for this message
Michael Terry (mterry) wrote :

Just a quick comment that the code looks good in theory from a quick scan. Won't have time to look at it in depth/test it for a couple days. :-/

Revision history for this message
Michael Terry (mterry) wrote :

Oh, and thanks! :)

Revision history for this message
Michael Terry (mterry) wrote :

Pushed in. Looks great! Thanks a bunch. I made a couple changes -- a few checks that 'inst' wasn't null for example. And a bit of logic to set the status to "Paused (no network)" while paused so that the user has some feedback.

Works well.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'configure.ac'
2--- configure.ac 2009-09-24 05:05:42 +0000
3+++ configure.ac 2009-10-12 22:45:21 +0000
4@@ -71,6 +71,7 @@
5 gtk+-2.0 >= $GTK_REQ_VER
6 gio-2.0 >= $GIO_REQ_VER
7 gconf-2.0
8+ dbus-glib-1
9 gnome-keyring-1)
10 AC_SUBST(DUP_CFLAGS)
11 AC_SUBST(DUP_LIBS)
12
13=== modified file 'deja-dup/Makefile.am'
14--- deja-dup/Makefile.am 2009-09-02 01:06:00 +0000
15+++ deja-dup/Makefile.am 2009-10-12 22:45:21 +0000
16@@ -1,7 +1,8 @@
17 # -*- Mode: Makefile; indent-tabs-mode: t; tab-width: 2 -*-
18 #
19 # This file is part of Déjà Dup.
20-# © 2008,2009 Michael Terry <mike@mterry.name>
21+# © 2008,2009 Michael Terry <mike@mterry.name>,
22+# © 2009 Andrew Fister <temposs@gmail.com>
23 #
24 # Déjà Dup is free software; you can redistribute it and/or modify
25 # it under the terms of the GNU General Public License as published by
26@@ -25,6 +26,7 @@
27 --pkg gio-2.0 \
28 --pkg gconf-2.0 \
29 --pkg gnome-keyring-1 \
30+ --pkg dbus-glib-1 \
31 --pkg libdeja-dup \
32 --pkg PassphraseSchema \
33 --pkg unix \
34
35=== modified file 'libdeja-dup/Duplicity.vala'
36--- libdeja-dup/Duplicity.vala 2009-09-24 00:24:16 +0000
37+++ libdeja-dup/Duplicity.vala 2009-10-12 22:45:21 +0000
38@@ -1,7 +1,8 @@
39 /* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
40 /*
41 This file is part of Déjà Dup.
42- © 2008,2009 Michael Terry <mike@mterry.name>
43+ © 2008,2009 Michael Terry <mike@mterry.name>,
44+ © 2009 Andrew Fister <temposs@gmail.com>
45
46 Déjà Dup is free software: you can redistribute it and/or modify
47 it under the terms of the GNU General Public License as published by
48@@ -90,9 +91,48 @@
49
50 File last_touched_file = null;
51
52+ protected dynamic DBus.Object network_manager;
53+ protected bool connected = true;
54+ protected const uint32 NM_STATE_CONNECTED = 3;
55+
56+ protected void init_dbus_to_network_manager() throws DBus.Error, GLib.Error
57+ {
58+ //Set up the DBus connection to network manager
59+ DBus.Connection conn = DBus.Bus.get(DBus.BusType.SYSTEM);
60+ network_manager = conn.get_object(
61+ "org.freedesktop.NetworkManager",
62+ "/org/freedesktop/NetworkManager",
63+ "org.freedesktop.NetworkManager");
64+
65+ //Retrieve the network manager connection state.
66+ uint32 network_manager_state = network_manager.State;
67+ connected = network_manager_state == NM_STATE_CONNECTED;
68+
69+ //Dbus signal when the state of the connection is changed.
70+ network_manager.StateChanged += network_manager_state_changed;
71+ }
72+
73+ protected void network_manager_state_changed(DBus.Object obj, uint32 new_state)
74+ {
75+ bool was_connected = connected;
76+ connected = new_state == NM_STATE_CONNECTED;
77+
78+ if (connected)
79+ resume();
80+ else if (was_connected)
81+ pause();
82+ }
83+
84 public Duplicity(Operation.Mode mode, Gtk.Window? win) {
85 this.original_mode = mode;
86 toplevel = win;
87+
88+ try {
89+ init_dbus_to_network_manager();
90+ }
91+ catch (Error e) {
92+ warning("%s\n\n%s", e.message, "Failed to initialize DBus\n");
93+ }
94 }
95
96 public virtual void start(Backend backend, bool encrypted,
97@@ -122,9 +162,15 @@
98 delete_age = client.get_int(DELETE_AFTER_KEY);
99 }
100 catch (Error e) {warning("%s\n", e.message);}
101-
102+
103 if (!restart())
104 done(false, false);
105+
106+ if (!backend.is_native() && !connected) {
107+ debug("No connection found. Postponing the backup.");
108+ pause();
109+ return;
110+ }
111 }
112
113 public void cancel() {
114@@ -149,6 +195,14 @@
115 }
116 }
117
118+ public void pause() {
119+ inst.pause();
120+ }
121+
122+ public void resume() {
123+ inst.resume();
124+ }
125+
126 void cancel_inst()
127 {
128 if (inst == null)
129
130=== modified file 'libdeja-dup/DuplicityInstance.vala'
131--- libdeja-dup/DuplicityInstance.vala 2009-09-21 00:18:22 +0000
132+++ libdeja-dup/DuplicityInstance.vala 2009-10-12 22:45:21 +0000
133@@ -1,7 +1,8 @@
134 /* -*- Mode: Vala; indent-tabs-mode: nil; tab-width: 2 -*- */
135 /*
136 This file is part of Déjà Dup.
137- © 2008,2009 Michael Terry <mike@mterry.name>
138+ © 2008,2009 Michael Terry <mike@mterry.name>,
139+ © 2009 Andrew Fister <temposs@gmail.com>
140
141 Déjà Dup is free software: you can redistribute it and/or modify
142 it under the terms of the GNU General Public License as published by
143@@ -140,6 +141,22 @@
144 else
145 done(false, true);
146 }
147+
148+ public void pause()
149+ {
150+ if (is_started())
151+ stop_child();
152+ else
153+ done(false, true);
154+ }
155+
156+ public void resume()
157+ {
158+ if (is_started())
159+ cont_child();
160+ else
161+ done(false, true);
162+ }
163
164 uint stanza_id;
165 uint watch_id;
166@@ -169,6 +186,14 @@
167 void kill_child() {
168 Posix.kill((Posix.pid_t)child_pid, Posix.SIGKILL);
169 }
170+
171+ void stop_child() {
172+ Posix.kill((Posix.pid_t)child_pid, Posix.SIGSTOP);
173+ }
174+
175+ void cont_child() {
176+ Posix.kill((Posix.pid_t)child_pid, Posix.SIGCONT);
177+ }
178
179 bool read_stanza(IOChannel channel, IOCondition cond)
180 {

Subscribers

People subscribed via source and target branches