~ubuntu-branches/debian/stretch/cheese/stretch

« back to all changes in this revision

Viewing changes to src/cheese-shareable-media.vala

  • Committer: Package Import Robot
  • Author(s): Andreas Henriksson, Jeremy Bicha, Andreas Henriksson
  • Date: 2013-10-17 16:29:42 UTC
  • mfrom: (1.3.10)
  • Revision ID: package-import@ubuntu.com-20131017162942-w8vdlrr3uo529i4c
Tags: 3.10.1-1
[ Jeremy Bicha ]
* debian/patches/fix-help-license.patch:
  - Backport clarification that the help files are licensed CC-BY-SA 3.0
* debian/patches/fix-um-crop-license.patch:
  - Backport relicensing of this file as GPL-2+ instead of GPL-3+
* debian/copyright:
  - Updated and converted to the 1.0 copyright format
* debian/control.in:
  - Suggest gnome-video-effects-frei0r

[ Andreas Henriksson ]
* New upstream release.
* Bump build-dependencies according to configure.ac:
  - libglib2.0-dev to >= 2.32.0
  - libclutter-1.0-dev to >= 1.13.2
* Drop debian/patches: now included in upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright © 2011 Patricia Santana Cruz <patriciasantanacruz@gmail.com>
3
 
 *
4
 
 * Licensed under the GNU General Public License Version 2
5
 
 *
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.
10
 
 *
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.
15
 
 *
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/>.
18
 
 */
19
 
 
20
 
/**
21
 
 * Class used for sharing images or videos with different technologies through
22
 
 * nautilus-sendto.
23
 
 */
24
 
public class Cheese.ShareableMedia : GLib.Object {
25
 
    private uint num_children = 0;
26
 
    Cheese.MainWindow window;
27
 
 
28
 
    /**
29
 
     * Create a new ShareableMedia instance.
30
 
     *
31
 
     * @param main_window the main window of the Cheese application
32
 
     */
33
 
    public ShareableMedia (Cheese.MainWindow main_window)
34
 
    {
35
 
        window = main_window;
36
 
    }
37
 
 
38
 
    /**
39
 
     * Callback to be called when the child exits.
40
 
     *
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
43
 
     * back to normal.
44
 
     *
45
 
     * @param pid the process id of the child process
46
 
     * @param status the status information about the child process
47
 
     *
48
 
     * @see ShareableMedia.share_files
49
 
     */
50
 
    void child_finished (Pid pid, int status)
51
 
    {
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().
55
 
         */
56
 
        if (!Process.if_exited(status))
57
 
            warning ("nautilus-sendto exited abnormally");
58
 
 
59
 
        Process.close_pid(pid);
60
 
 
61
 
        --num_children;
62
 
        if (num_children == 0)
63
 
        {
64
 
            window.get_window ().set_cursor (
65
 
                new Gdk.Cursor (Gdk.CursorType.LEFT_PTR));
66
 
        }
67
 
    }
68
 
 
69
 
    /**
70
 
     * Used for sharing one or more images and/or one or more videos through
71
 
     * different technologies.
72
 
     *
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}
75
 
     * callback is called.
76
 
     *
77
 
     * It will also set the cursor to busy to indicate to the user that
78
 
     * there is some task that is being done.
79
 
     *
80
 
     * @param files a list of the files (videos and/or images that are going to
81
 
     * be shared.
82
 
     *
83
 
     * @see ShareableMedia.child_finished.
84
 
     */
85
 
    public void share_files (GLib.List<GLib.File> files)
86
 
    {
87
 
        string[] argv = {};
88
 
        // Defined in cheese-window.vala.
89
 
        argv += SENDTO_EXEC;
90
 
 
91
 
        files.foreach ((file) => argv += file.get_path ());
92
 
 
93
 
        try
94
 
        {
95
 
            Pid child_pid;
96
 
 
97
 
            if (Process.spawn_async ("/", argv, null,
98
 
                SpawnFlags.SEARCH_PATH | SpawnFlags.DO_NOT_REAP_CHILD, null,
99
 
                out child_pid))
100
 
            {
101
 
                ChildWatch.add (child_pid, child_finished);
102
 
 
103
 
                ++num_children;
104
 
                /* Show a busy cursor if there are any children. It just needs
105
 
                 * to be done for the first child.
106
 
                 */
107
 
                if (num_children == 1)
108
 
                {
109
 
                    window.get_window ().set_cursor (new Gdk.Cursor
110
 
                        (Gdk.CursorType.WATCH));
111
 
                }
112
 
            }
113
 
        }
114
 
        catch (SpawnError error)
115
 
        {
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);
119
 
        }
120
 
    }
121
 
}