2
* Copyright © 2011 Patricia Santana Cruz <patriciasantanacruz@gmail.com>
4
* Licensed under the GNU General Public License Version 2
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21
* Class used for sharing images or videos with different technologies through
24
public class Cheese.ShareableMedia : GLib.Object {
25
private uint num_children = 0;
26
Cheese.MainWindow window;
29
* Create a new ShareableMedia instance.
31
* @param main_window the main window of the Cheese application
33
public ShareableMedia (Cheese.MainWindow main_window)
39
* Callback to be called when the child exits.
41
* Cleans up the child process spawned by {@link ShareableMedia.share_files}
42
* and if that child is the last one, it will also set the cursor
45
* @param pid the process id of the child process
46
* @param status the status information about the child process
48
* @see ShareableMedia.share_files
50
void child_finished (Pid pid, int status)
52
/* Method for checking WIFEXITED(status) value, which returns true if the
53
* child terminated normally, that is, by calling exit(3) or _exit(2), or
54
* by returning from main().
56
if (!Process.if_exited(status))
57
warning ("nautilus-sendto exited abnormally");
59
Process.close_pid(pid);
62
if (num_children == 0)
64
window.get_window ().set_cursor (
65
new Gdk.Cursor (Gdk.CursorType.LEFT_PTR));
70
* Used for sharing one or more images and/or one or more videos through
71
* different technologies.
73
* It works asynchronously and will create a new child every time it is
74
* called. When the child exists, the {@link ShareableMedia.child_finished}
77
* It will also set the cursor to busy to indicate to the user that
78
* there is some task that is being done.
80
* @param files a list of the files (videos and/or images that are going to
83
* @see ShareableMedia.child_finished.
85
public void share_files (GLib.List<GLib.File> files)
88
// Defined in cheese-window.vala.
91
files.foreach ((file) => argv += file.get_path ());
97
if (Process.spawn_async ("/", argv, null,
98
SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, null,
101
ChildWatch.add (child_pid, child_finished);
104
/* Show a busy cursor if there are any children. It just needs
105
* to be done for the first child.
107
if (num_children == 1)
109
window.get_window ().set_cursor (new Gdk.Cursor
110
(Gdk.CursorType.WATCH));
114
catch (SpawnError error)
116
window.get_window ().set_cursor (new Gdk.Cursor
117
(Gdk.CursorType.LEFT_PTR));
118
warning ("Unable to launch nautilus-sendto: %s\n", error.message);