~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to Rhythmbox/src/Rhythmbox.cs

  • Committer: djsiegel at gmail
  • Date: 2007-11-07 17:13:21 UTC
  • Revision ID: djsiegel@gmail.com-20071107171321-zgu46ukqlpdx1ypa
Initial files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//  Rhythmbox.cs
 
2
//
 
3
//  GNOME Do is the legal property of its developers, whose names are too numerous
 
4
//  to list here.  Please refer to the COPYRIGHT file distributed with this
 
5
//  source distribution.
 
6
//
 
7
//  This program is free software: you can redistribute it and/or modify
 
8
//  it under the terms of the GNU General Public License as published by
 
9
//  the Free Software Foundation, either version 3 of the License, or
 
10
//  (at your option) any later version.
 
11
//
 
12
//  This program is distributed in the hope that it will be useful,
 
13
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
14
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
15
//  GNU General Public License for more details.
 
16
//
 
17
//  You should have received a copy of the GNU General Public License
 
18
//  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
 
 
20
using System;
 
21
using System.Diagnostics;
 
22
 
 
23
namespace RhythmboxAddin
 
24
{
 
25
        
 
26
        
 
27
        public class Rhythmbox
 
28
        {
 
29
                
 
30
                public static void StartIfNeccessary ()
 
31
                {
 
32
                        if (!InstanceIsRunning)
 
33
                        {
 
34
                                Process.Start ("rhythmbox-client", "--no-present");
 
35
                                System.Threading.Thread.Sleep (2 * 1000);
 
36
                        }
 
37
                }
 
38
                
 
39
                public static bool InstanceIsRunning
 
40
                {
 
41
                        get {
 
42
                                Process pidof;
 
43
                                
 
44
                                try {
 
45
                                        // Use pidof command to look for Rhythmbox process. Exit
 
46
                                        // status is 0 if at least one matching process is found.
 
47
                                        // If there's any error, just assume some it's running.
 
48
                                        pidof = Process.Start ("pidof", "rhythmbox");
 
49
                                        pidof.WaitForExit ();
 
50
                                        return pidof.ExitCode == 0;
 
51
                                } catch {
 
52
                                        return true;
 
53
                                }
 
54
                        }
 
55
                }
 
56
                
 
57
                public static void Client (string command)
 
58
                {
 
59
                        Client (command, false);
 
60
                }
 
61
                
 
62
                public static void Client (string command, bool wait)
 
63
                {
 
64
                        Process client;
 
65
                        try {
 
66
                                client = Process.Start ("rhythmbox-client", command);
 
67
                                if (wait)
 
68
                                        client.WaitForExit ();
 
69
                        } catch {
 
70
                        }
 
71
                }
 
72
        }
 
73
}