Merge lp:~u78qir8a9-deactivatedaccount/do-plugins/screen into lp:do-plugins

Proposed by Alex Launi
Status: Rejected
Rejected by: Alex Launi
Proposed branch: lp:~u78qir8a9-deactivatedaccount/do-plugins/screen
Merge into: lp:do-plugins
Diff against target: None lines
To merge this branch: bzr merge lp:~u78qir8a9-deactivatedaccount/do-plugins/screen
Reviewer Review Type Date Requested Status
Alex Launi (community) ball-buster style Needs Fixing
Review via email: mp+5680@code.launchpad.net

This proposal supersedes a proposal from 2009-02-08.

To post a comment you must log in.
Revision history for this message
X (u78qir8a9-deactivatedaccount) wrote : Posted in a previous version of this proposal

  New Plugin: GNU Screen

  This is a plugin for Gnome Do to work with GNU Screen sessions. GNU Screen
  (command 'screen') is a command line application for managing multi-windowed
  shell sessions that can be detached and reattached for persistency, and offers
  much configurability.

  This adds the Plugin directory ./GNUScreen, and adds the plugin to monodevelop
  as well as to the autotools setup.

  This is the Plugin code as provided in gitorious revision 2fd1c03b at
  screen-plugin-gnome-do/mainline

  http://gitorious.org/projects/screen-plugin-gnome-do

Revision history for this message
Alex Launi (alexlauni) wrote : Posted in a previous version of this proposal

When I enabled this plugin it blocked my console and made me pick 1, 2, or 3. I had never launched screen on my laptop before and I guess this is why, but that's a case that needs considered.

Revision history for this message
Alex Launi (alexlauni) wrote : Posted in a previous version of this proposal

You know what would make this one of the best Do plugins ever written? The ability to find ssh sessions, and index screen sessions running on remote hosts. How beautiful would that be?

Revision history for this message
X (u78qir8a9-deactivatedaccount) wrote : Posted in a previous version of this proposal

"When I enabled this plugin it blocked my console and made me pick 1, 2, or 3. I had never launched screen on my laptop before and I guess this is why, but that's a case that needs considered."

Whoa ok that sounds bad. What does "pick 1,2, or 3" mean?

I know a plugin as this has many open issues, like

1. default location of the binary (now "screen")
2. configurable permanent arguments(?)
3. how to find the user's terminal app of choice (this hardcoded to "gnome-terminal", I was just looking at other plugins). Perhaps that's one that is simple to sove using Unix.Process..

Revision history for this message
Alex Launi (alexlauni) wrote : Posted in a previous version of this proposal

On Mon, Feb 9, 2009 at 5:02 AM, Ulrik Sverdrup <email address hidden>wrote:

> Whoa ok that sounds bad. What does "pick 1,2, or 3" mean?
>

I have no idea what it meant! I just chose 1 to get it to unblock...

--
--Alex Launi

Revision history for this message
Matthew Frizelle (gleebtorin) wrote : Posted in a previous version of this proposal

"You know what would make this one of the best Do plugins ever written? The ability to find ssh sessions, and index screen sessions running on remote hosts. How beautiful would that be?"

That would actually be a pretty awesome idea. As a heavy user of screen, that would be very useful to me :)

Revision history for this message
X (u78qir8a9-deactivatedaccount) wrote : Posted in a previous version of this proposal

2009/2/17 Matthew Frizelle <email address hidden>:
> "You know what would make this one of the best Do plugins ever written? The ability to find ssh sessions, and index screen sessions running on remote hosts. How beautiful would that be?"
>
> That would actually be a pretty awesome idea. As a heavy user of screen, that would be very useful to me :)
> --
> https://code.launchpad.net/~ulrik-sverdrup/do-plugins/screen/+merge/3476
> You are subscribed to branch lp:~ulrik-sverdrup/do-plugins/screen.
>

Something to hack on when I have time! That would require finding out
which ssh hosts have key authentication, and then "simply" send "ssh
host 'screen -list'" over the network.. I wouldn't do it without the
user's explicit consent (plugin preferences) though. Anyway, that's
for a later time.

So, this thing that happened first time you used the plugin, do we
have to resolve that to merge this? I don't understand at all what
could have happened, but I can try reproducing it somehow.

ulrik

Revision history for this message
Alex Launi (alexlauni) wrote :

Organize using statements by length, or lexicographically, and separate them logically, all of the System namespaces together, etc.

Make sure you're following mono guidelines for method calls, I see a lot of MethodName(params) when I should be seeing only MethodName (params)

whitespace issues. separate your methods by newlines. Description and LastUpdateTime in NewScreenAction.cs are touching.

There are some weird tabbing issues too, I'm going to blame monodevelop, but it still needs fixed. Make sure oyu're using all tabs, not spaces.

In SupportsModifierItemForItems, you assign a bool, and then return it. You can save yourself a stack variable. It may not be necessary, but you may also want to check if that 'as' statement failed and left you with a null value-
return file == null ? false : Directory.Exists (fitem.Path);

I see you're hardcoding GNOME terminal, there is a GConf key for the users' preferred terminal. This should be respected, and you should launch that.

perform could use breaking up, if not into methods than just use whitespace. Perform is pretty dense, hard to read. One suggestion I've got for this is to declare your variables at the beginning, then assign them later, vs. having declarations littered throughout the method. Obviously this isn't true for small scoped variables.

These comments pretty much hold for the rest of the merge.

review: Needs Fixing (ball-buster style)
Revision history for this message
Alex Launi (alexlauni) wrote :

ping? This is a cool plugin, if you just fix these couple of issues we can merge!

Revision history for this message
Alex Launi (alexlauni) wrote :

Rejecting due to abandonment

Unmerged revisions

523. By X

New Plugin: GNU Screen

This is a plugin for Gnome Do to work with GNU Screen sessions. GNU Screen
(command 'screen') is a command line application for managing multi-windowed
shell sessions that can be detached and reattached for persistency, and offers
much configurability.

This adds the Plugin directory ./GNUScreen, and adds the plugin to monodevelop
as well as to the autotools setup.

This is the Plugin code as provided in gitorious revision 2fd1c03b at
screen-plugin-gnome-do/mainline

http://gitorious.org/projects/screen-plugin-gnome-do

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'DoPlugins.mds'
--- DoPlugins.mds 2009-02-01 04:00:44 +0000
+++ DoPlugins.mds 2009-02-08 17:28:11 +0000
@@ -68,6 +68,7 @@
68 <Entry build="True" name="xmms2" configuration="Debug" />68 <Entry build="True" name="xmms2" configuration="Debug" />
69 <Entry build="True" name="TinyUrl" configuration="Debug" />69 <Entry build="True" name="TinyUrl" configuration="Debug" />
70 <Entry build="True" name="Tracker" configuration="Debug" />70 <Entry build="True" name="Tracker" configuration="Debug" />
71 <Entry build="True" name="GNUScreen" configuration="Debug" />
71 </Configuration>72 </Configuration>
72 <Configuration name="Release" ctype="CombineConfiguration">73 <Configuration name="Release" ctype="CombineConfiguration">
73 <Entry build="True" name="Rhythmbox" configuration="Release" />74 <Entry build="True" name="Rhythmbox" configuration="Release" />
@@ -137,6 +138,7 @@
137 <Entry build="True" name="xmms2" configuration="Release" />138 <Entry build="True" name="xmms2" configuration="Release" />
138 <Entry build="True" name="TinyUrl" configuration="Release" />139 <Entry build="True" name="TinyUrl" configuration="Release" />
139 <Entry build="True" name="Tracker" configuration="Release" />140 <Entry build="True" name="Tracker" configuration="Release" />
141 <Entry build="True" name="GNUScreen" configuration="Release" />
140 </Configuration>142 </Configuration>
141 </Configurations>143 </Configurations>
142 <StartMode startupentry="Rhythmbox" single="True">144 <StartMode startupentry="Rhythmbox" single="True">
@@ -207,6 +209,7 @@
207 <Execute type="None" entry="xmms2" />209 <Execute type="None" entry="xmms2" />
208 <Execute type="None" entry="TinyUrl" />210 <Execute type="None" entry="TinyUrl" />
209 <Execute type="None" entry="Tracker" />211 <Execute type="None" entry="Tracker" />
212 <Execute type="None" entry="GNUScreen" />
210 </StartMode>213 </StartMode>
211 <MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />214 <MonoDevelop.ChangeLogAddIn.ChangeLogInfo policy="UpdateNearestChangeLog" />
212 <Entries>215 <Entries>
@@ -277,5 +280,6 @@
277 <Entry filename="Xmms2/xmms2.mdp" />280 <Entry filename="Xmms2/xmms2.mdp" />
278 <Entry filename="TinyUrl/TinyUrl.mdp" />281 <Entry filename="TinyUrl/TinyUrl.mdp" />
279 <Entry filename="Tracker/Tracker.mdp" />282 <Entry filename="Tracker/Tracker.mdp" />
283 <Entry filename="GNUScreen/GNUScreen.mdp" />
280 </Entries>284 </Entries>
281</Combine>285</Combine>
282\ No newline at end of file286\ No newline at end of file
283287
=== added directory 'GNUScreen'
=== added file 'GNUScreen/GNUScreen.mdp'
--- GNUScreen/GNUScreen.mdp 1970-01-01 00:00:00 +0000
+++ GNUScreen/GNUScreen.mdp 2009-02-08 17:28:11 +0000
@@ -0,0 +1,30 @@
1<Project name="GNUScreen" fileversion="2.0" language="C#" clr-version="Net_2_0" ctype="DotNetProject">
2 <Configurations active="Debug">
3 <Configuration name="Debug" ctype="DotNetProjectConfiguration">
4 <Output directory="bin/Debug" assembly="GNUScreen" />
5 <Build debugmode="True" target="Library" />
6 <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
7 <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" definesymbols="DEBUG" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
8 </Configuration>
9 <Configuration name="Release" ctype="DotNetProjectConfiguration">
10 <Output directory="bin/Release" assembly="GNUScreen" />
11 <Build debugmode="False" target="Library" />
12 <Execution runwithwarnings="True" consolepause="False" runtime="MsNet" clr-version="Net_2_0" />
13 <CodeGeneration compiler="Mcs" warninglevel="4" optimize="True" unsafecodeallowed="False" generateoverflowchecks="True" generatexmldocumentation="False" ctype="CSharpCompilerParameters" />
14 </Configuration>
15 </Configurations>
16 <Contents>
17 <File name="." subtype="Directory" buildaction="Compile" />
18 <File name="Resources/GNUScreen.addin.xml" subtype="Code" buildaction="EmbedAsResource" />
19 <File name="src/NewScreenAction.cs" subtype="Code" buildaction="Compile" />
20 <File name="src/ScreenAction.cs" subtype="Code" buildaction="Compile" />
21 <File name="src/ScreenSessions.cs" subtype="Code" buildaction="Compile" />
22 </Contents>
23 <References>
24 <ProjectReference type="Gac" localcopy="True" refto="System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
25 <ProjectReference type="Gac" localcopy="True" refto="Do.Universe, Version=0.8.0.0, Culture=neutral, PublicKeyToken=null" />
26 <ProjectReference type="Gac" localcopy="True" refto="Do.Platform, Version=0.8.0.0, Culture=neutral, PublicKeyToken=null" />
27 <ProjectReference type="Gac" localcopy="True" refto="Mono.Posix, Version=2.0.0.0, Culture=neutral, PublicKeyToken=0738eb9f132ed756" />
28 <ProjectReference type="Gac" localcopy="True" refto="System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
29 </References>
30</Project>
0\ No newline at end of file31\ No newline at end of file
132
=== added file 'GNUScreen/Makefile.am'
--- GNUScreen/Makefile.am 1970-01-01 00:00:00 +0000
+++ GNUScreen/Makefile.am 2009-02-08 17:28:11 +0000
@@ -0,0 +1,18 @@
1include $(top_srcdir)/build.rules.mk
2
3ASSEMBLY=GNUScreen
4
5FILES = \
6 src/NewScreenAction.cs \
7 src/ScreenAction.cs \
8 src/ScreenSessions.cs
9
10RESOURCES = \
11 Resources/GNUScreen.addin.xml
12
13REFERENCES = \
14 Mono.Posix \
15 System \
16 System.Core \
17 $(DO_PLATFORM_LIBS) \
18 $(DO_UNIVERSE_LIBS)
019
=== added directory 'GNUScreen/Resources'
=== added file 'GNUScreen/Resources/GNUScreen.addin.xml'
--- GNUScreen/Resources/GNUScreen.addin.xml 1970-01-01 00:00:00 +0000
+++ GNUScreen/Resources/GNUScreen.addin.xml 2009-02-08 17:28:11 +0000
@@ -0,0 +1,27 @@
1<Addin
2 id="GNUScreen"
3 namespace="Do"
4 version="1.0"
5 name="GNU Screen"
6 description="Work with GNU Screen sessions"
7 author="Ulrik Sverdrup"
8 category="Community"
9 >
10
11 <Runtime>
12 <Import assembly="GNUScreen.dll"/>
13 </Runtime>
14
15 <Dependencies>
16 <Addin id="Universe" version="1.0" />
17 </Dependencies>
18
19 <Extension path = "/Do/ItemSource">
20 <ItemSource type="GnomeDoScreen.ScreenSessionItemSource" />
21 </Extension>
22 <Extension path = "/Do/Action">
23 <Action type="GnomeDoScreen.AttachScreenAction" />
24 <Action type="GnomeDoScreen.NewScreenAction" />
25 <Action type="GnomeDoScreen.ScreenCommandAction" />
26 </Extension>
27</Addin>
028
=== added directory 'GNUScreen/src'
=== added file 'GNUScreen/src/NewScreenAction.cs'
--- GNUScreen/src/NewScreenAction.cs 1970-01-01 00:00:00 +0000
+++ GNUScreen/src/NewScreenAction.cs 2009-02-08 17:28:11 +0000
@@ -0,0 +1,110 @@
1/* NewScreenAction.cs
2 *
3 * GNOME Do is the legal property of its developers. Please refer to the
4 * 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
21using System;
22using System.Collections.Generic;
23using System.Linq;
24using System.IO;
25using Do.Universe;
26using Do.Platform;
27using System.Diagnostics;
28
29using Mono.Unix;
30
31namespace GnomeDoScreen {
32 public class NewScreenAction : Act {
33
34 public override string Name {
35 get {
36 return Catalog.GetString("New Screen session");
37 }
38 }
39
40 public override string Description {
41 get {
42 return Catalog.GetString("Create a new GNU Screen session");
43 }
44 }
45 public DateTime LastUpdateTime { get; private set;}
46
47 public override string Icon {
48 get {
49 return "terminal";
50 }
51 }
52
53 public override IEnumerable<Type> SupportedItemTypes {
54 get {
55 yield return typeof(ITextItem);
56 }
57 }
58
59 public override bool SupportsItem (Item item) {
60 return true;
61 }
62
63 /* Support directory as optional
64 */
65 public override IEnumerable<Type> SupportedModifierItemTypes {
66 get { yield return typeof(IFileItem); }
67 }
68
69 public override bool ModifierItemsOptional {
70 get { return true; }
71 }
72 public override bool SupportsModifierItemForItems (IEnumerable<Item> items, Item modItem)
73 {
74 IFileItem fitem = modItem as IFileItem;
75 bool exists = Directory.Exists(fitem.Path);
76 return exists;
77 }
78
79 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems) {
80 string exec = "gnome-terminal";
81
82 string sessionname = "";
83 if (items.First () is ITextItem) {
84 ITextItem textitem = items.First () as ITextItem;
85 sessionname = textitem.Text.Trim();
86 }
87 string workdir = null;
88 if (modItems.Count() > 0 && modItems.First() is IFileItem) {
89 string path = (modItems.First() as IFileItem).Path;
90 /* Check if it is an existing directory
91 */
92 if (Directory.Exists(path))
93 workdir = path;
94 }
95 Process term = new Process ();
96 term.StartInfo.FileName = exec;
97 string sessionarg = "", titlearg = "";
98 if (sessionname != "")
99 sessionarg = "-S '" + sessionname + "'";
100 if (sessionname != "")
101 titlearg = String.Format("--title='{0}'", sessionname);
102 term.StartInfo.Arguments = String.Format("{0} -x screen {1}", titlearg, sessionarg);
103 if (workdir != null)
104 term.StartInfo.WorkingDirectory = workdir;
105 Log<NewScreenAction>.Debug(term.StartInfo.Arguments);
106 term.Start ();
107 return null;
108 }
109 }
110}
0111
=== added file 'GNUScreen/src/ScreenAction.cs'
--- GNUScreen/src/ScreenAction.cs 1970-01-01 00:00:00 +0000
+++ GNUScreen/src/ScreenAction.cs 2009-02-08 17:28:11 +0000
@@ -0,0 +1,209 @@
1/* ScreenAction.cs
2 *
3 * GNOME Do is the legal property of its developers. Please refer to the
4 * 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
21using System;
22using System.Collections.Generic;
23using System.Linq;
24using Do.Universe;
25using Do.Platform;
26using System.Diagnostics;
27
28using Mono.Unix;
29
30namespace GnomeDoScreen {
31 public class AbstractScreenAction : Act {
32 static ScreenSessionItemSource source_cache = null;
33 public override string Name {
34 get { return "AbstractScreenAction"; }
35 }
36
37 public override string Description {
38 get { return "Base class"; }
39 }
40
41 public override string Icon {
42 get {
43 return "terminal";
44 }
45 }
46
47 public override IEnumerable<Type> SupportedItemTypes {
48 get {
49 return new Type[] {
50 typeof(ITextItem),
51 typeof(ScreenSessionItem),
52 };
53 }
54 }
55
56 public static DateTime LastUpdateTime { get; private set;}
57
58 private static void UpdateCacheIfOld(int wait) {
59 /* Wait before update */
60 TimeSpan update_interval = new TimeSpan(0,0,wait);
61 if ((DateTime.UtcNow - LastUpdateTime) > update_interval ) {
62 source_cache.UpdateItems();
63 LastUpdateTime = DateTime.UtcNow;
64 }
65 }
66
67 private static bool TextMatchesItem(string text, ScreenSessionItem item) {
68 if (item == null)
69 return false;
70 string pid = item.Pid;
71 string name = item.SessionName;
72 if (name.StartsWith(text) || pid.StartsWith(text))
73 return true;
74 return false;;
75 }
76
77 public override bool SupportsItem (Item item) {
78 if (item is ScreenSessionItem) {
79 /* If it's a SSI, it should be updated from
80 * the source side
81 */
82 return true;
83 } else if (item is ITextItem) {
84 ITextItem titem = item as ITextItem;
85 /* Check if the given text
86 * matches the beginning of the
87 * _pid_ or _tty name_ of any running
88 * session
89 */
90 /* Wait shorter time for text items */
91 if (source_cache == null)
92 source_cache = new ScreenSessionItemSource();
93 UpdateCacheIfOld(15);
94 foreach (Item it in source_cache.Items) {
95 ScreenSessionItem ssitem = it as ScreenSessionItem;
96 if (this.TextMatchesItem(titem.Text, ssitem)) {
97 return true;
98 }
99 }
100 }
101 return false;
102 }
103 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems) {
104 return null;
105 }
106
107 public static void SpawnScreenSession(string name, string arguments) {
108 string term = "gnome-terminal";
109 ProcessStartInfo ps = new ProcessStartInfo (term);
110 string term_arguments = "";
111 if (name != "")
112 term_arguments += "--title='" + name + "' ";
113 term_arguments += "-x screen ";
114 if (arguments != "")
115 term_arguments += arguments;
116 ps.Arguments = term_arguments;
117 using (Process p = Process.Start (ps)) {
118 Log<AbstractScreenAction>.Debug(ps.Arguments);
119 }
120 }
121
122 public static void RunScreen(string arguments) {
123 string term = "screen";
124 ProcessStartInfo ps = new ProcessStartInfo (term);
125 ps.UseShellExecute = false;
126 ps.Arguments = arguments;
127 using (Process p = Process.Start (ps)) {
128 Log<ScreenCommandAction>.Debug(ps.Arguments);
129 }
130 }
131 }
132
133 public class AttachScreenAction : AbstractScreenAction {
134
135 public override string Name {
136 get {
137 return Catalog.GetString("Attach");
138 }
139 }
140
141 public override string Description {
142 get {
143 return Catalog.GetString("Attach or reattach a running GNU Screen session");
144 }
145 }
146
147 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems) {
148 string screenname = null;
149 string termname = "";
150 if (items.First () is ITextItem) {
151 ITextItem textitem = items.First () as ITextItem;
152 screenname = textitem.Text;
153 } else if (items.First () is ScreenSessionItem) {
154 ScreenSessionItem sitem = items.First () as ScreenSessionItem;
155 /* Attach with Pid, because it is always correct,
156 * the session name can change! */
157 screenname = sitem.Pid;
158 termname = sitem.Name;
159 }
160 if (screenname != null) {
161 SpawnScreenSession(termname, "-x -R " + screenname);
162 }
163 return null;
164 }
165
166 }
167
168 public class ScreenCommandAction : AbstractScreenAction {
169 public override string Name {
170 get {
171 return Catalog.GetString("Send command");
172 }
173 }
174
175 public override string Description {
176 get {
177 return Catalog.GetString("Send a command to a running GNU Screen session");
178 }
179 }
180 public override string Icon {
181 get { return "gtk-execute"; }
182 }
183
184 public override IEnumerable<Type> SupportedModifierItemTypes {
185 get { yield return typeof(ITextItem); }
186 }
187
188 public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modItems) {
189 string screenname = null;
190 string command = null;
191 if (items.First () is ITextItem) {
192 ITextItem textitem = items.First () as ITextItem;
193 screenname = textitem.Text.Trim();
194 } else if (items.First () is ScreenSessionItem) {
195 ScreenSessionItem sitem = items.First () as ScreenSessionItem;
196 /* Use with Pid, because it is always correct,
197 * the session name can change! */
198 screenname = sitem.Pid;
199 }
200 if (modItems.First() is ITextItem) {
201 command = (modItems.First() as ITextItem).Text;
202 }
203 if (screenname != null && command != null) {
204 RunScreen("-S " + screenname + " -X " + command);
205 }
206 return null;
207 }
208 }
209}
0210
=== added file 'GNUScreen/src/ScreenSessions.cs'
--- GNUScreen/src/ScreenSessions.cs 1970-01-01 00:00:00 +0000
+++ GNUScreen/src/ScreenSessions.cs 2009-02-08 17:28:11 +0000
@@ -0,0 +1,152 @@
1/* ScreenSessions.cs
2 *
3 * GNOME Do is the legal property of its developers. Please refer to the
4 * 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
21using System;
22using System.IO;
23using System.Collections.Generic;
24using System.Text.RegularExpressions;
25using System.Diagnostics;
26
27using Do.Platform;
28using Do.Universe;
29
30using Mono.Unix;
31
32
33namespace GnomeDoScreen {
34
35 public class ScreenSessionItem : Item {
36 string pid, sessionname, name, status, date;
37
38 public ScreenSessionItem (string ipid, string iname, string istatus, string idate)
39 {
40 sessionname = iname;
41 status = istatus;
42 date = idate;
43
44 /* Pid used to identify the session */
45 pid = ipid;
46 /* Display name */
47 name = String.Format("{0} ({1})", sessionname, pid);
48 }
49
50 public override string Name { get { return name; } }
51 public override string Description {
52 get {
53 return status + " GNU Screen session, created " + date;
54 }
55 }
56 public override string Icon { get { return "gnome-window-manager"; } }
57
58 public string Pid { get { return pid; } }
59 public string SessionName { get { return sessionname; } }
60 }
61
62 public class ScreenSessionItemSource : ItemSource {
63 List<Item> items;
64
65 public ScreenSessionItemSource ()
66 {
67 items = new List<Item> ();
68 UpdateItems ();
69 }
70
71 public override string Name { get { return Catalog.GetString("Screen sessions"); } }
72 public override string Description { get { return Catalog.GetString("Lists running GNU Screen sessions"); } }
73 public override string Icon { get { return "terminal"; } }
74
75 public override IEnumerable<Type> SupportedItemTypes {
76 get {
77 yield return typeof (ScreenSessionItem);
78 }
79 }
80
81 public override IEnumerable<Item> Items {
82 get {
83 return items;
84 }
85 }
86
87 public override IEnumerable<Item> ChildrenOfItem (Item parent)
88 {
89 yield break;
90 }
91
92 public override void UpdateItems ()
93 {
94 items.Clear ();
95 Log<ScreenSessionItemSource>.Debug(" updating items..");
96
97 try {
98 // sets up our process, the first argument is the command
99 // and the second holds the arguments passed to the command
100 ProcessStartInfo ps = new ProcessStartInfo ("screen", "-list");
101 ps.UseShellExecute = false;
102 // we need to redirect the standard output so we read it
103 // internally in out program
104 ps.RedirectStandardOutput = true;
105
106 // starts the process
107 string output = null;
108 using (Process p = Process.Start (ps)) {
109 // we read the output to a string
110 output = p.StandardOutput.ReadToEnd ();
111 // waits for the process to exit
112 p.WaitForExit ();
113 }
114 if (output == null)
115 return;
116
117 StringReader reader = new StringReader (output);
118
119 Regex r = new Regex ("^\\t([^\\t]+)\\t\\((.*)\\)\\t\\((.*)\\)$");
120 Regex pidtty= new Regex ("^([0-9]+)\\.(.*)");
121
122 string s;
123 /* Group matches:
124 * Groups[0] is the whole string that matched
125 * and [1] and so on are the () groups one by one
126 */
127 while ((s = reader.ReadLine ()) != null) {
128 Match m = r.Match (s);
129 if (m.Groups.Count == 4) {
130 string fullname, status, date;
131 fullname = m.Groups[1].ToString();
132 date = m.Groups[2].ToString();
133 status = m.Groups[3].ToString();
134 /* Part the pid.tty.host into pid and tty
135 */
136 Match ptm = pidtty.Match(fullname);
137 string pid, name;
138 if (ptm.Groups.Count == 3) {
139 pid = ptm.Groups[1].ToString();
140 name = ptm.Groups[2].ToString();
141 items.Add (new ScreenSessionItem (pid, name, status, date));
142 } else {
143 /* Best to report matching error */
144 Log<ScreenSessionItemSource>.Debug("Unable to parse " + s);
145 }
146 }
147 }
148 } catch { }
149 }
150 }
151}
152
0153
=== modified file 'Makefile.am'
--- Makefile.am 2009-01-30 00:17:43 +0000
+++ Makefile.am 2009-02-08 17:28:11 +0000
@@ -30,6 +30,7 @@
30 GoogleDocs \30 GoogleDocs \
31 GoogleMaps \31 GoogleMaps \
32 GoogleSearch \32 GoogleSearch \
33 GNUScreen \
33 ImageShack \34 ImageShack \
34 JIRA \35 JIRA \
35 Launchpad \36 Launchpad \
3637
=== modified file 'configure.ac'
--- configure.ac 2009-01-29 20:26:24 +0000
+++ configure.ac 2009-02-08 17:28:11 +0000
@@ -135,6 +135,7 @@
135GoogleDocs/Makefile135GoogleDocs/Makefile
136GoogleMaps/Makefile136GoogleMaps/Makefile
137GoogleSearch/Makefile137GoogleSearch/Makefile
138GNUScreen/Makefile
138ImageShack/Makefile139ImageShack/Makefile
139JIRA/Makefile140JIRA/Makefile
140Launchpad/Makefile141Launchpad/Makefile

Subscribers

People subscribed via source and target branches