[cheese/shareable-media] Do not use the spinning technique
- From: Patricia Santana Cruz <patriciasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [cheese/shareable-media] Do not use the spinning technique
- Date: Tue, 27 Dec 2011 18:25:59 +0000 (UTC)
commit 84c0e71978bda63508bf30666ef5cae9af4da41a
Author: Patricia Santana Cruz <patriciasantanacruz gmail com>
Date: Tue Dec 27 18:20:27 2011 +0000
Do not use the spinning technique
In order to improve the efficiency of this code, the spinning technique
has been replaced with the g_child_watch_add() function.
src/cheese-shareable-media.vala | 37 ++++++++++++++++------------
src/cheese-window.vala | 51 ---------------------------------------
2 files changed, 21 insertions(+), 67 deletions(-)
---
diff --git a/src/cheese-shareable-media.vala b/src/cheese-shareable-media.vala
index 3bf56bc..33999ae 100644
--- a/src/cheese-shareable-media.vala
+++ b/src/cheese-shareable-media.vala
@@ -3,33 +3,38 @@
*/
namespace ShareableMedia {
private const string SENDTO_EXEC = "nautilus-sendto";
+ private Cheese.MainWindow window;
- public void files_share(Cheese.MainWindow mainWindow, GLib.List<GLib.File> files)
+ void child_finished (Pid pid, int status)
{
- if (mainWindow == null)
- stdout.printf ("Test: NULL mainWindow\n");
+ Process.close_pid(pid);
+ window.get_window().set_cursor(new Gdk.Cursor(Gdk.CursorType.LEFT_PTR));
+ }
+ public void files_share (Cheese.MainWindow mainWindow, GLib.List<GLib.File> files)
+ {
+ window = mainWindow;
string[] argv = {};
argv += SENDTO_EXEC;
-
files.foreach ((file) => argv += file.get_path());
try {
- mainWindow.set_busy_cursor();
Pid child_pid;
- Process.spawn_async(
- "/",
- argv,
- null,
- SpawnFlags.SEARCH_PATH,
- null,
- out child_pid);
+ if (Process.spawn_async("/",
+ argv,
+ null,
+ SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD,
+ null,
+ out child_pid))
+ {
+ ChildWatch.add (child_pid, child_finished);
+ window.get_window().set_cursor(new Gdk.Cursor(Gdk.CursorType.WATCH));
+ }
- mainWindow.set_normal_cursor();
- } catch (Error err) {
- mainWindow.set_normal_cursor();
- stdout.printf ("Unable to launch nautilus-sendto\n");
+ } catch (Error error) {
+ window.get_window().set_cursor(new Gdk.Cursor(Gdk.CursorType.LEFT_PTR));
+ stdout.printf ("Unable to launch nautilus-sendto: %s\n", error.message);
}
}
}
diff --git a/src/cheese-window.vala b/src/cheese-window.vala
index 46bcdb7..34e7efb 100644
--- a/src/cheese-window.vala
+++ b/src/cheese-window.vala
@@ -71,7 +71,6 @@ public class Cheese.MainWindow : Gtk.Window
private Clutter.Box current_effects_grid;
private int current_effects_page = 0;
- private int busy_counter = 0;
private ArrayList<Clutter.Box> effects_grids;
private Gtk.Action take_photo_action;
@@ -499,56 +498,6 @@ public class Cheese.MainWindow : Gtk.Window
}
/**
- * Change cursor form to a watch when Cheese is busy doing a sharing
- * operation.
- */
- public void set_busy_cursor()
- {
- if (busy_counter++ > 0)
- return;
-
- get_window().set_cursor(new Gdk.Cursor(Gdk.CursorType.WATCH));
- spin_event_loop(10);
- }
-
- /**
- * Change cursor form back to normal when Cheese is not any longer busy with a
- * sharing operation.
- */
- public void set_normal_cursor()
- {
- if (busy_counter <= 0) {
- busy_counter = 0;
- return;
- } else if (--busy_counter > 0) {
- return;
- }
-
- get_window().set_cursor(new Gdk.Cursor(Gdk.CursorType.LEFT_PTR));
- spin_event_loop(10);
- }
-
- // Testing
- public bool spin_event_loop(int max = -1)
- {
- if (max == 0)
- return true;
-
- while (Gtk.events_pending())
- {
- if (Gtk.main_iteration())
- return false;
-
- if (max > 0)
- {
- if (--max <= 0)
- break;
- }
- }
- return true;
- }
-
- /**
* Make the media capture mode actions sensitive.
*/
private void enable_mode_change ()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]