Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!
View | Details | Raw Unified | Return to bug 129861
Collapse All | Expand All

(-)Filters/FilterExternal.cs (-16 / +23 lines)
Lines 143-171 namespace Beagle.Filters { Link Here
143
				Error ();
143
				Error ();
144
			}
144
			}
145
145
146
			string args = efi.Arguments.Replace ("%s", String.Format ("\"{0}\"", FileInfo.FullName));
146
			// FIXME: Need to deal with quotation marks in the XML file, probably.
147
147
			string[] tmp_argv = efi.Arguments.Split (' ');
148
			Process pc = new Process ();
148
			string[] argv = new string [tmp_argv.Length + 1];
149
150
			argv [0] = efi.Command;
151
152
			int j = 1;
153
			for (int i = 0; i < tmp_argv.Length; i++) {
154
				if (tmp_argv [i] == String.Empty)
155
					continue;
156
157
				if (tmp_argv [i] == "%s")
158
					argv [j] = FileInfo.FullName;
159
				else
160
					argv [j] = tmp_argv [i];
161
				j++;
162
			}
149
163
150
			pc.StartInfo.FileName = efi.Command;
164
			SafeProcess pc = new SafeProcess ();
151
			pc.StartInfo.Arguments = args;
165
			pc.Arguments = argv;
152
			pc.StartInfo.RedirectStandardInput = false;
166
			pc.RedirectStandardOutput = true;
153
			pc.StartInfo.RedirectStandardOutput = true;
154
			pc.StartInfo.UseShellExecute = false;
155
167
156
			try {
168
			try {
157
				pc.Start ();
169
				pc.Start ();
158
			} catch (System.ComponentModel.Win32Exception ex) {
170
			} catch (SafeProcessException e) {
159
				Logger.Log.Warn ("Unable to execute {0}: {1}",
171
				Log.Warn (e.Message);
160
						 pc.StartInfo.FileName, ex);
161
				Error ();
172
				Error ();
162
				return;
173
				return;
163
			}
174
			}
164
175
165
			// Nice the process so that we don't monopolize the CPU
176
			StreamReader pout = new StreamReader (pc.StandardOutput);
166
			pc.PriorityClass = ProcessPriorityClass.BelowNormal;
167
168
			StreamReader pout = pc.StandardOutput;
169
177
170
			string str;
178
			string str;
171
			while ((str = pout.ReadLine ()) != null) {
179
			while ((str = pout.ReadLine ()) != null) {
Lines 174-180 namespace Beagle.Filters { Link Here
174
			}
182
			}
175
183
176
			pout.Close ();
184
			pout.Close ();
177
			pc.WaitForExit ();
178
			pc.Close ();
185
			pc.Close ();
179
			Finished ();
186
			Finished ();
180
		}
187
		}
(-)Filters/FilterMPlayerVideo.cs (-13 / +8 lines)
Lines 96-119 namespace Beagle.Filters { Link Here
96
96
97
		protected override void DoPullProperties ()
97
		protected override void DoPullProperties ()
98
		{
98
		{
99
			// create new external process
99
			SafeProcess pc = new SafeProcess ();
100
			Process pc = new Process ();
100
			pc.Arguments = new string [] { "mplayer", "-vo", "null", "-ao", "null", "-frames", "0", "-identify", FileInfo.FullName };
101
			pc.StartInfo.FileName = "mplayer";
101
			pc.RedirectStandardOutput = true;
102
			pc.StartInfo.Arguments = " -vo null -ao null -frames 0 -identify \"" + FileInfo.FullName+"\"";
102
			pc.RedirectStandardError = true;
103
			pc.StartInfo.RedirectStandardInput = false;
103
104
			pc.StartInfo.RedirectStandardOutput = true;
105
			pc.StartInfo.RedirectStandardError = true;
106
			pc.StartInfo.UseShellExecute = false;
107
			
108
			try {
104
			try {
109
				pc.Start ();
105
				pc.Start ();
110
			} catch (System.ComponentModel.Win32Exception) {
106
			} catch (SafeProcessException e) {
111
				Log.Warn ("Error: mplayer not found or unable to run");
107
				Log.Warn (e.Message);
112
				Error ();
108
				Error ();
113
				return;
109
				return;
114
			}
110
			}
115
111
116
			StreamReader pout = pc.StandardOutput;
112
			StreamReader pout = new StreamReader (pc.StandardOutput);
117
			string str;
113
			string str;
118
			string name = "";
114
			string name = "";
119
			
115
			
Lines 197-203 namespace Beagle.Filters { Link Here
197
			}
193
			}
198
			
194
			
199
			pout.Close ();
195
			pout.Close ();
200
			pc.WaitForExit ();
201
			pc.Close ();
196
			pc.Close ();
202
			
197
			
203
			// If an aspect ratio wasn't set in the file then work out the
198
			// If an aspect ratio wasn't set in the file then work out the
(-)Filters/FilterPdf.cs (-28 / +17 lines)
Lines 30-52 namespace Beagle.Filters { Link Here
30
		protected override void DoPullProperties ()
30
		protected override void DoPullProperties ()
31
		{
31
		{
32
			// create new external process
32
			// create new external process
33
			Process pc = new Process ();
33
			SafeProcess pc = new SafeProcess ();
34
			pc.StartInfo.FileName = "pdfinfo";
34
			pc.Arguments = new string [] { "pdfinfo", FileInfo.FullName };
35
			// FIXME: We probably need to quote special chars in the path
35
			pc.RedirectStandardOutput = true;
36
			pc.StartInfo.Arguments = String.Format (" \"{0}\"", FileInfo.FullName);
36
37
			pc.StartInfo.RedirectStandardInput = false;
38
			pc.StartInfo.RedirectStandardOutput = true;
39
			pc.StartInfo.UseShellExecute = false;
40
			try {
37
			try {
41
				pc.Start ();
38
				pc.Start ();
42
			} catch (System.ComponentModel.Win32Exception) {
39
			} catch (SafeProcessException e) {
43
				Logger.Log.Warn ("Unable to find pdfinfo in path; PDF file not indexed.");
40
				Log.Warn (e.Message);
44
				Finished ();
41
				Error ();
45
				return;
42
				return;
46
			}
43
			}
47
			
44
48
			// add pdfinfo's output to pool
45
			// add pdfinfo's output to pool
49
			StreamReader pout = pc.StandardOutput;
46
			StreamReader pout = new StreamReader (pc.StandardOutput);
50
			string str = null;
47
			string str = null;
51
			string[] tokens = null;
48
			string[] tokens = null;
52
			string strMetaTag = null;
49
			string strMetaTag = null;
Lines 87-119 namespace Beagle.Filters { Link Here
87
				}
84
				}
88
			}
85
			}
89
			pout.Close ();
86
			pout.Close ();
90
			pc.WaitForExit ();
91
			pc.Close ();
87
			pc.Close ();
92
		}
88
		}
93
		
89
		
94
		protected override void DoPull ()
90
		protected override void DoPull ()
95
		{
91
		{
96
			// create new external process
92
			// create new external process
97
			Process pc = new Process ();
93
			SafeProcess pc = new SafeProcess ();
98
			pc.StartInfo.FileName = "pdftotext";
94
			pc.Arguments = new string [] { "pdftotext", "-q", "-nopgbrk", "-enc", "UTF-8", FileInfo.FullName, "-" };
99
			// FIXME: We probably need to quote special chars in the path
95
			pc.RedirectStandardOutput = true;
100
			pc.StartInfo.Arguments = String.Format ("-q -nopgbrk -enc UTF-8 \"{0}\" -", FileInfo.FullName);
96
101
			pc.StartInfo.RedirectStandardInput = false;
102
			pc.StartInfo.RedirectStandardOutput = true;
103
			pc.StartInfo.UseShellExecute = false;
104
			try {
97
			try {
105
				pc.Start ();
98
				pc.Start ();
106
			} catch (System.ComponentModel.Win32Exception) {
99
			} catch (SafeProcessException e) {
107
				Logger.Log.Warn ("Unable to find pdftotext in path; PDF file not indexed.");
100
				Log.Warn (e.Message);
108
				Finished ();
101
				Error ();
109
				return;
102
				return;
110
			}
103
			}
111
104
112
			// Nice the process so we don't monopolize the CPU as much; we might want to even set this to idle
113
			pc.PriorityClass = ProcessPriorityClass.BelowNormal;	
114
115
			// add pdftotext's output to pool
105
			// add pdftotext's output to pool
116
			StreamReader pout = pc.StandardOutput;
106
			StreamReader pout = new StreamReader (pc.StandardOutput);
117
107
118
			// FIXME:  I don't think this is really required
108
			// FIXME:  I don't think this is really required
119
			// Line by line parsing, however, we have to make
109
			// Line by line parsing, however, we have to make
Lines 126-132 namespace Beagle.Filters { Link Here
126
					break;
116
					break;
127
			}
117
			}
128
			pout.Close ();
118
			pout.Close ();
129
			pc.WaitForExit ();
130
			pc.Close ();
119
			pc.Close ();
131
			Finished ();
120
			Finished ();
132
		}
121
		}
(-)Filters/FilterRPM.cs (-13 / +13 lines)
Lines 74-105 namespace Beagle.Filters { Link Here
74
74
75
		protected override void DoPullProperties ()
75
		protected override void DoPullProperties ()
76
		{
76
		{
77
			Process pc = new Process ();
77
			SafeProcess pc = new SafeProcess ();
78
			pc.StartInfo.FileName = "rpm";
78
			pc.Arguments = new string [] { "rpm", "-qp", "--queryformat", "[%{*:xml}\n]", FileInfo.FullName };
79
			pc.StartInfo.Arguments = " -qp --queryformat '[%{*:xml}\n]' \"" + FileInfo.FullName+"\"";
79
			pc.RedirectStandardOutput = true;
80
			pc.StartInfo.RedirectStandardInput = false;
80
			pc.RedirectStandardError = true;
81
			pc.StartInfo.RedirectStandardOutput = true;
82
			pc.StartInfo.RedirectStandardError = true;
83
			pc.StartInfo.UseShellExecute = false;
84
			
81
			
85
			try {
82
			try {
86
				pc.Start ();
83
				pc.Start ();
87
			} catch (System.ComponentModel.Win32Exception) {
84
			} catch (SafeProcessException e) {
88
				Log.Warn ("Error: 'rpm' command not found or unable to run");
85
				Log.Warn (e.Message);
89
				Error ();
86
				Error ();
90
				return;
87
				return;
91
			}
88
			}
92
89
93
			StreamReader pout = pc.StandardOutput;
90
			XmlTextReader reader = new XmlTextReader (new StreamReader (pc.StandardOutput));
94
			XmlTextReader reader = new XmlTextReader (pout);
95
			reader.WhitespaceHandling = WhitespaceHandling.None;
91
			reader.WhitespaceHandling = WhitespaceHandling.None;
96
92
97
			try {
93
			try {
98
				ParseRpmTags (reader);
94
				ParseRpmTags (reader);
99
			} catch (XmlException) {
95
			} catch (XmlException e) {
100
				Logger.Log.Debug ("FilterRPM: Error parsing output of rpmquery!");
96
				Logger.Log.Warn ("FilterRPM: Error parsing output of rpmquery: {0}", e.Message);
101
				Error ();
97
				Error ();
98
			} finally {
99
				reader.Close ();
100
				pc.Close ();
102
			}
101
			}
102
103
			Finished ();
103
			Finished ();
104
		}
104
		}
105
105
(-)Filters/FilterSpreadsheet.cs (-12 / +10 lines)
Lines 75-113 namespace Beagle.Filters { Link Here
75
		override protected void DoPull ()
75
		override protected void DoPull ()
76
		{
76
		{
77
			// create new external process
77
			// create new external process
78
			Process pc = new Process ();
78
			SafeProcess pc = new SafeProcess ();
79
			pc.StartInfo.FileName = "ssindex";
79
			pc.Arguments = new string [] { "ssindex", "-i", FileInfo.FullName };
80
			pc.RedirectStandardOutput = true;
80
81
81
			pc.StartInfo.Arguments = String.Format ("-i \"{0}\"", FileInfo.FullName);
82
			pc.StartInfo.RedirectStandardInput = false;
83
			pc.StartInfo.RedirectStandardOutput = true;
84
			pc.StartInfo.UseShellExecute = false;
85
			try {
82
			try {
86
				pc.Start ();
83
				pc.Start ();
87
			} catch (System.ComponentModel.Win32Exception) {
84
			} catch (SafeProcessException e) {
88
				Logger.Log.Warn ("Unable to find ssindex in path; {0} file not indexed.",
85
				Log.Warn (e.Message);
89
						 FileInfo.FullName);
86
				Error ();
90
				Finished ();
91
				return;
87
				return;
92
			}
88
			}
93
89
94
			// process ssindex output
90
			// process ssindex output
95
			StreamReader pout = pc.StandardOutput;
91
			StreamReader pout = new StreamReader (pc.StandardOutput);
96
			if (!ignoredFirst2lines) {
92
			if (!ignoredFirst2lines) {
97
				pout.ReadLine ();
93
				pout.ReadLine ();
98
				pout.ReadLine ();
94
				pout.ReadLine ();
99
				xmlReader = new XmlTextReader (pout);
95
				xmlReader = new XmlTextReader (pout);
100
				ignoredFirst2lines = true;
96
				ignoredFirst2lines = true;
101
			}
97
			}
98
102
			try {
99
			try {
103
				WalkContentNodes (xmlReader);
100
				WalkContentNodes (xmlReader);
104
			} catch (Exception e) {
101
			} catch (Exception e) {
105
				Logger.Log.Debug ("Exception occurred while indexing {0}.", FileInfo.FullName);
102
				Logger.Log.Debug ("Exception occurred while indexing {0}.", FileInfo.FullName);
106
				Logger.Log.Debug (e);
103
				Logger.Log.Debug (e);
107
			}
104
			}
105
108
			pout.Close ();
106
			pout.Close ();
109
			pc.WaitForExit ();
110
			pc.Close ();
107
			pc.Close ();
108
111
			Finished ();
109
			Finished ();
112
		}
110
		}
113
		
111
		
(-)Util/Makefile.am (+1 lines)
Lines 73-78 UTIL_CSFILES = \ Link Here
73
	$(srcdir)/PngHeader.cs			\
73
	$(srcdir)/PngHeader.cs			\
74
	$(srcdir)/PullingReader.cs      	\
74
	$(srcdir)/PullingReader.cs      	\
75
	$(srcdir)/ReflectionFu.cs		\
75
	$(srcdir)/ReflectionFu.cs		\
76
	$(srcdir)/SafeProcess.cs		\
76
	$(srcdir)/Scheduler.cs			\
77
	$(srcdir)/Scheduler.cs			\
77
	$(srcdir)/SmallIntArray.cs		\
78
	$(srcdir)/SmallIntArray.cs		\
78
	$(srcdir)/Stopwatch.cs			\
79
	$(srcdir)/Stopwatch.cs			\
(-)Util/SafeProcess.cs (+143 lines)
Added Link Here
1
//
2
// SafeProcess.cs
3
//
4
// Copyright (C) 2006 Novell, Inc.
5
//
6
7
//
8
// Permission is hereby granted, free of charge, to any person obtaining a copy
9
// of this software and associated documentation files (the "Software"), to deal
10
// in the Software without restriction, including without limitation the rights
11
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12
// copies of the Software, and to permit persons to whom the Software is
13
// furnished to do so, subject to the following conditions:
14
//
15
// The above copyright notice and this permission notice shall be included in all
16
// copies or substantial portions of the Software.
17
//
18
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
24
// SOFTWARE.
25
//
26
27
using System;
28
using System.IO;
29
using System.Runtime.InteropServices;
30
using Mono.Unix;
31
using GLib;
32
33
namespace Beagle.Util {
34
35
	public class SafeProcess {
36
37
		private bool redirect_stdin, redirect_stdout, redirect_stderr;
38
		private int stdin, stdout, stderr;
39
		private string[] args;
40
		private UnixStream stdin_stream, stdout_stream, stderr_stream;
41
42
		public string[] Arguments {
43
			get { return args; }
44
			set { args = value; }
45
		}
46
47
		public bool RedirectStandardInput {
48
			get { return redirect_stdin; }
49
			set { redirect_stdin = value; }
50
		}
51
52
		public bool RedirectStandardOutput {
53
			get { return redirect_stdout; }
54
			set { redirect_stdout = value; }
55
		}
56
57
		public bool RedirectStandardError {
58
			get { return redirect_stderr; }
59
			set { redirect_stderr = value; }
60
		}
61
62
		public Stream StandardInput {
63
			get { return stdin_stream; }
64
		}
65
66
		public Stream StandardOutput {
67
			get { return stdout_stream; }
68
		}
69
70
		public Stream StandardError {
71
			get { return stderr_stream; }
72
		}
73
74
		[DllImport ("libglib-2.0.so.0")]
75
		static extern bool g_spawn_async_with_pipes (string working_directory,
76
							     string[] argv,
77
							     string[] envp,
78
							     int flags,
79
							     IntPtr child_setup,
80
							     IntPtr child_data,
81
							     IntPtr pid,
82
							     ref int standard_input,
83
							     ref int standard_output,
84
							     ref int standard_error,
85
							     out IntPtr error);
86
87
		public void Start ()
88
		{
89
			if (args == null)
90
				throw new ArgumentException ("Arguments cannot be empty");
91
92
			IntPtr error;
93
94
			if (args [args.Length - 1] != null) {
95
				// Need to null-terminate the array.
96
				string[] tmp_args = new string [args.Length + 1];
97
				Array.Copy (args, tmp_args, args.Length);
98
				args = tmp_args;
99
			}
100
101
			g_spawn_async_with_pipes (null, args, null,
102
						  1 << 2, // G_SPAWN_SEARCH_PATH
103
						  IntPtr.Zero, IntPtr.Zero, IntPtr.Zero,
104
						  ref stdin, ref stdout, ref stderr, out error);
105
106
			if (error != IntPtr.Zero)
107
				throw new SafeProcessException (new GException (error));
108
109
			if (! RedirectStandardInput)
110
				Mono.Unix.Native.Syscall.close (stdin);
111
			else
112
				stdin_stream = new UnixStream (stdin);
113
114
			if (! RedirectStandardOutput)
115
				Mono.Unix.Native.Syscall.close (stdout);
116
			else
117
				stdout_stream = new UnixStream (stdout);
118
119
			if (! RedirectStandardError)
120
				Mono.Unix.Native.Syscall.close (stderr);
121
			else
122
				stderr_stream = new UnixStream (stderr);
123
		}
124
125
		public void Close ()
126
		{
127
			if (stdin_stream != null)
128
				stdin_stream.Close ();
129
130
			if (stdout_stream != null)
131
				stdout_stream.Close ();
132
133
			if (stderr_stream != null)
134
				stderr_stream.Close ();
135
		}
136
	}
137
138
	public class SafeProcessException : Exception {
139
140
		internal SafeProcessException (GException gexception) : base (gexception.Message) { }
141
	}
142
			
143
}
(-)search/Tiles/File.cs (-14 / +7 lines)
Lines 2-7 using System; Link Here
2
using System.Diagnostics;
2
using System.Diagnostics;
3
using System.Runtime.InteropServices;
3
using System.Runtime.InteropServices;
4
using Mono.Unix;
4
using Mono.Unix;
5
using Beagle.Util;
5
6
6
namespace Search.Tiles {
7
namespace Search.Tiles {
7
8
Lines 68-88 namespace Search.Tiles { Link Here
68
		{
69
		{
69
			string path = Hit.FileInfo.DirectoryName;
70
			string path = Hit.FileInfo.DirectoryName;
70
71
71
			Process p = new Process ();
72
			p.StartInfo.UseShellExecute = false;
73
74
			if ((! path.StartsWith ("\"")) && (! path.EndsWith ("\"")))
75
				path = "\"" + path + "\"";
76
77
			// FIXME: When nautilus implements this, then we should
72
			// FIXME: When nautilus implements this, then we should
78
			// also select the file in the folder.
73
			// also select the file in the folder.
79
74
75
			SafeProcess p = new SafeProcess ();
76
80
#if ENABLE_DESKTOP_LAUNCH
77
#if ENABLE_DESKTOP_LAUNCH
81
			p.StartInfo.FileName = "desktop-launch";
78
			p.Arguments = new string [] { "desktop-launch", path };
82
			p.StartInfo.Arguments = path;
83
#else
79
#else
84
			p.StartInfo.FileName = "nautilus";
80
			p.Arguments = new string [] { "nautilus", "--no-desktop", path };
85
			p.StartInfo.Arguments = "--no-desktop " + path;
86
#endif
81
#endif
87
			try {
82
			try {
88
				p.Start ();
83
				p.Start ();
Lines 93-102 namespace Search.Tiles { Link Here
93
88
94
		public void Email ()
89
		public void Email ()
95
		{
90
		{
96
			Process p = new Process ();
91
			SafeProcess p = new SafeProcess ();
97
			p.StartInfo.UseShellExecute = false;
92
			p.Arguments = new string [] { "evolution", String.Format ("mailto:?attach={0}", Hit.FileInfo.FullName) };
98
			p.StartInfo.FileName = "evolution";
99
			p.StartInfo.Arguments = String.Format ("\"mailto:?attach={0}\"", Hit.FileInfo.FullName);
100
93
101
			try {
94
			try {
102
				p.Start () ;
95
				p.Start () ;
(-)search/Tiles/IMLog.cs (-6 / +7 lines)
Lines 2-7 using System; Link Here
2
using System.Diagnostics;
2
using System.Diagnostics;
3
using System.Collections;
3
using System.Collections;
4
using Mono.Unix;
4
using Mono.Unix;
5
using Beagle.Util;
5
6
6
namespace Search.Tiles {
7
namespace Search.Tiles {
7
8
Lines 102-117 namespace Search.Tiles { Link Here
102
103
103
		public override void Open ()
104
		public override void Open ()
104
		{
105
		{
105
			Process p = new Process ();
106
			SafeProcess p = new SafeProcess ();
106
			p.StartInfo.UseShellExecute = true;
107
			p.Arguments = new string [] { "beagle-imlogviewer",
107
			p.StartInfo.FileName = "beagle-imlogviewer";
108
						      "--client", Hit ["fixme:client"],
108
			p.StartInfo.Arguments = String.Format ("--client \"{0}\" --highlight-search \"{1}\" {2}",
109
						      "--highlight-search", Query.QuotedText,
109
							       Hit ["fixme:client"], Query.QuotedText, Hit.Uri.LocalPath);
110
						      Hit.Uri.LocalPath };
110
111
111
			try {
112
			try {
112
				p.Start ();
113
				p.Start ();
113
			} catch (Exception e) {
114
			} catch (Exception e) {
114
				Console.WriteLine ("Unable to run {0}: {1}", p.StartInfo.FileName, e.Message);
115
				Console.WriteLine ("Unable to run {0}: {1}", p.Arguments [0], e.Message);
115
			}
116
			}
116
		}
117
		}
117
	}
118
	}
(-)search/Tiles/Image.cs (-3 / +8 lines)
Lines 100-108 namespace Search.Tiles { Link Here
100
			if (Hit ["fspot:IsIndexed"] == "true")
100
			if (Hit ["fspot:IsIndexed"] == "true")
101
				return;
101
				return;
102
102
103
			ProcessStartInfo pi = new ProcessStartInfo ("f-spot");
103
			SafeProcess p = new SafeProcess ();
104
			pi.Arguments = String.Format ("--import {0}", Hit.FileInfo.FullName);
104
			p.Arguments = new string[] { "f-spot", "--import", Hit.FileInfo.FullName };
105
			Process.Start (pi);
105
106
			try {
107
				p.Start ();
108
			} catch (Exception e) {
109
				Console.WriteLine ("Error launching F-Spot: " + e);
110
			}
106
		}
111
		}
107
#endif
112
#endif
108
		
113
		
(-)search/Tiles/MailAttachment.cs (-11 / +8 lines)
Lines 1-6 Link Here
1
using System;
1
using System;
2
using System.Diagnostics;
2
using System.Diagnostics;
3
using Mono.Unix;
3
using Mono.Unix;
4
using Beagle.Util;
4
5
5
namespace Search.Tiles {
6
namespace Search.Tiles {
6
7
Lines 67-94 namespace Search.Tiles { Link Here
67
68
68
		public override void Open ()
69
		public override void Open ()
69
		{
70
		{
70
			string uri_str;
71
72
			if (GetHitProperty (Hit, "fixme:client") != "evolution") {
71
			if (GetHitProperty (Hit, "fixme:client") != "evolution") {
73
				OpenFromMime (Hit);
72
				OpenFromMime (Hit);
74
				return;
73
				return;
75
			}
74
			}
76
75
77
			Process p = new Process ();
76
			SafeProcess p = new SafeProcess ();
78
			p.StartInfo.UseShellExecute = false;
77
			p.Arguments = new string [2];
79
			p.StartInfo.FileName = "evolution";
78
			p.Arguments [0] = "evolution";
80
79
81
			if (Hit.ParentUriAsString != null)
80
			if (Hit.ParentUriAsString != null)
82
				uri_str = Hit.ParentUriAsString;
81
				p.Arguments [1] = Hit.ParentUriAsString;
83
			else
82
			else
84
				uri_str = Hit.UriAsString;
83
				p.Arguments [1] = Hit.UriAsString;
85
86
			p.StartInfo.Arguments  = "'" + uri_str + "'";
87
84
88
			try {
85
			try {
89
				p.Start ();
86
				p.Start ();
90
			} catch (System.ComponentModel.Win32Exception e) {
87
			} catch (SafeProcessException e) {
91
				Console.WriteLine ("Unable to run {0}: {1}", p.StartInfo.FileName, e.Message);
88
				Console.WriteLine ("Unable to run {0}: {1}", p.Arguments [0], e.Message);
92
			}
89
			}
93
		}	
90
		}	
94
	}
91
	}
(-)search/Tiles/MailMessage.cs (-16 / +11 lines)
Lines 1-6 Link Here
1
using System;
1
using System;
2
using System.Diagnostics;
2
using System.Diagnostics;
3
using Mono.Unix;
3
using Mono.Unix;
4
using Beagle.Util;
4
5
5
namespace Search.Tiles {
6
namespace Search.Tiles {
6
7
Lines 97-124 namespace Search.Tiles { Link Here
97
98
98
		public override void Open ()
99
		public override void Open ()
99
		{
100
		{
100
			string uri_str;
101
102
			if (Hit.GetFirstProperty ("fixme:client") != "evolution") {
101
			if (Hit.GetFirstProperty ("fixme:client") != "evolution") {
103
				OpenFromMime (Hit);
102
				OpenFromMime (Hit);
104
				return;
103
				return;
105
			}
104
			}
106
105
107
			Process p = new Process ();
106
			SafeProcess p = new SafeProcess ();
108
			p.StartInfo.UseShellExecute = false;
107
			p.Arguments = new string [2];
109
			p.StartInfo.FileName = "evolution";
108
			p.Arguments [0] = "evolution";
110
109
111
			if (Hit.ParentUriAsString != null)
110
			if (Hit.ParentUriAsString != null)
112
				uri_str = Hit.ParentUriAsString;
111
				p.Arguments [1] = Hit.ParentUriAsString;
113
			else
112
			else
114
				uri_str = Hit.UriAsString;
113
				p.Arguments [1] = Hit.UriAsString;
115
116
			p.StartInfo.Arguments  = "'" + uri_str + "'";
117
114
118
			try {
115
			try {
119
				p.Start ();
116
				p.Start ();
120
			} catch (System.ComponentModel.Win32Exception e) {
117
			} catch (SafeProcessException e) {
121
				Console.WriteLine ("Unable to run {0}: {1}", p.StartInfo.FileName, e.Message);
118
				Console.WriteLine ("Unable to run {0}: {1}", p.Arguments [0], e.Message);
122
			}
119
			}
123
		}
120
		}
124
121
Lines 127-141 namespace Search.Tiles { Link Here
127
			if (Hit.GetFirstProperty ("fixme:client") != "evolution")
124
			if (Hit.GetFirstProperty ("fixme:client") != "evolution")
128
				return;
125
				return;
129
			
126
			
130
			Process p = new Process ();
127
			SafeProcess p = new SafeProcess ();
131
			p.StartInfo.UseShellExecute = false;
128
			p.Arguments = new string [] { "evolution", String.Format ("{0};forward=attached", Hit.Uri) };
132
			p.StartInfo.FileName = "evolution";
133
			p.StartInfo.Arguments = String.Format ("\"{0};forward=attached\"", Hit.Uri);
134
129
135
			try {
130
			try {
136
				p.Start () ;
131
				p.Start () ;
137
			} catch (Exception e) {
132
			} catch (Exception e) {
138
				Console.WriteLine ("Error launching Evolution composer: " + e);
133
				Console.WriteLine ("Error launching Evolution composer: " + e.Message);
139
			}
134
			}
140
		}
135
		}
141
	}
136
	}
(-)search/Tiles/Note.cs (-7 / +6 lines)
Lines 2-7 using System; Link Here
2
using System.Diagnostics;
2
using System.Diagnostics;
3
using System.Runtime.InteropServices;
3
using System.Runtime.InteropServices;
4
using Mono.Unix;
4
using Mono.Unix;
5
using Beagle.Util;
5
6
6
namespace Search.Tiles {
7
namespace Search.Tiles {
7
8
Lines 32-47 namespace Search.Tiles { Link Here
32
33
33
		public override void Open ()
34
		public override void Open ()
34
		{
35
		{
36
			SafeProcess p = new SafeProcess ();
37
35
			// This doesn't work very well if you have multiple
38
			// This doesn't work very well if you have multiple
36
			// terms that match.  Tomboy doesn't seem to have a way
39
			// terms that match.  Tomboy doesn't seem to have a way
37
			// to specify more than one thing to highlight.
40
			// to specify more than one thing to highlight.
38
			string args = String.Format ("--open-note {0} --highlight-search \"{1}\"",
41
			p.Arguments = new string [] { "tomboy",
39
						     Hit.Uri, Query.QuotedText);
42
						      "--open-note", Hit.UriAsString,
40
			
43
						      "--highlight-search", Query.QuotedText };
41
			Process p = new Process ();
42
			p.StartInfo.UseShellExecute = false;
43
			p.StartInfo.FileName = "tomboy";
44
			p.StartInfo.Arguments = args;
45
44
46
			try {
45
			try {
47
				p.Start ();
46
				p.Start ();
(-)search/Tiles/Tile.cs (-32 / +32 lines)
Lines 326-345 namespace Search.Tiles { Link Here
326
326
327
		protected void OpenFromMime (Hit hit)
327
		protected void OpenFromMime (Hit hit)
328
		{
328
		{
329
			OpenFromMime (hit, null, null, false);
329
			string command = null, item;
330
		}
330
			bool expects_uris = false;
331
332
		protected void OpenFromMime (Hit hit, string command_fallback,
333
					     string args_fallback, bool expects_uris_fallback)
334
		{
335
			string argument;
336
			string command = command_fallback;
337
			bool expects_uris = expects_uris_fallback;
338
331
339
			// FIXME: This is evil.  Nautilus should be handling
332
			// FIXME: This is evil.  Nautilus should be handling
340
			// inode/directory, not just x-directory/normal
333
			// inode/directory, not just x-directory/normal
341
			if (hit.MimeType == "inode/directory")
334
			if (hit.MimeType == "inode/directory")
342
				hit.MimeType = "x-directory/normal";
335
				hit.MimeType = "x-directory/normal";
336
343
#if ENABLE_DESKTOP_LAUNCH
337
#if ENABLE_DESKTOP_LAUNCH
344
			command = "desktop-launch";
338
			command = "desktop-launch";
345
			expects_uris = true;
339
			expects_uris = true;
Lines 356-394 namespace Search.Tiles { Link Here
356
				return;
350
				return;
357
			}
351
			}
358
352
359
			if (args_fallback != null)
353
			if (expects_uris)
360
				argument = args_fallback;
354
				item = UriFu.UriToSerializableString (hit.Uri);
361
			else 
355
			else
362
				argument = "";			
356
				item = hit.Path;
363
364
			if (expects_uris) {
365
				argument = String.Format ("{0} '{1}'", argument,
366
						UriFu.UriToSerializableString(hit.Uri));
367
			} else {
368
				argument = String.Format ("{0} {1}", argument, hit.PathQuoted);
369
			}
370
357
371
			// Sometimes the command is 'quoted'
358
			// Sometimes the command is 'quoted'
372
			if (command.IndexOf ('\'') == 0 && command.LastIndexOf ('\'') == command.Length - 1)
359
			if (command.IndexOf ('\'') == 0 && command.LastIndexOf ('\'') == command.Length - 1)
373
				command = command.Trim ('\'');
360
				command = command.Trim ('\'');
374
361
375
			// This won't work if a program really has a space in
362
			// This won't work if a program really has a space in
376
			// the filename, but I think other things would break
363
			// the command filename, but I think other things would
377
			// with that too, and in practice it doesn't seem to
364
			// break with that too, and in practice it doesn't seem to
378
			// happen.
365
			// happen.
366
			//
367
			// A bigger issue is that the arguments are split up by
368
			// spaces, so quotation marks used to indicate a single
369
			// entry in the argv won't work.  This probably should
370
			// be fixed.
371
			string[] arguments = null;
379
			int idx = command.IndexOf (' ');
372
			int idx = command.IndexOf (' ');
380
			if (idx != -1) {
373
			if (idx != -1) {
381
				argument = String.Format ("{0} {1}", command.Substring (idx + 1), argument);
374
				arguments = command.Substring (idx + 1).Split (' ');
382
				command = command.Substring (0, idx);
375
				command = command.Substring (0, idx);
383
			}
376
			}
384
377
378
			string[] argv;
379
			if (arguments == null)
380
				argv = new string [] { command, item };
381
			else {
382
				argv = new string [arguments.Length + 2];
383
				argv [0] = command;
384
				argv [argv.Length - 1] = item;
385
				Array.Copy (arguments, 0, argv, 1, arguments.Length);
386
			}
387
385
			Console.WriteLine ("Cmd: {0}", command);
388
			Console.WriteLine ("Cmd: {0}", command);
386
			Console.WriteLine ("Arg: {0}", argument);
389
			Console.WriteLine ("Arg: {0}", String.Join (" ", argv, 1, argv.Length - 2));
390
			Console.WriteLine ("Itm: {0}", item);
387
391
388
			Process p = new Process ();
392
			SafeProcess p = new SafeProcess ();
389
			p.StartInfo.UseShellExecute = false;
393
			p.Arguments = argv;
390
			p.StartInfo.FileName = command;
391
			p.StartInfo.Arguments = argument;
392
394
393
			try {
395
			try {
394
				p.Start ();
396
				p.Start ();
Lines 405-414 namespace Search.Tiles { Link Here
405
		public void OpenFromUri (string uri)
407
		public void OpenFromUri (string uri)
406
                {
408
                {
407
#if ENABLE_DESKTOP_LAUNCH
409
#if ENABLE_DESKTOP_LAUNCH
408
			Process p = new Process ();
410
			SafeProcess p = new SafeProcess ();
409
			p.StartInfo.UseShellExecute = false;
411
			p.Arguments = new string[] { "desktop-launch", uri };
410
			p.StartInfo.FileName = "desktop-launch";
411
			p.StartInfo.Arguments = uri;
412
412
413
			try {
413
			try {
414
				p.Start ();
414
				p.Start ();

Return to bug 129861