diff options
author | Manish Sinha <manishsinha@ubuntu.com> | 2011-10-24 06:35:48 +0530 |
---|---|---|
committer | Manish Sinha <manishsinha@ubuntu.com> | 2011-10-24 06:35:48 +0530 |
commit | 12fda1cf112a679f8e159a2aebf9c69f659fc488 (patch) | |
tree | 54a5b4164038914efd8cf862fd5b7a9656f4f96a | |
parent | 2ecc5b389b26fb5ef88901e1774c18db7cc5ff28 (diff) |
Add the necessary files needed for Monodevelop
-rw-r--r-- | monodevelop/AssemblyInfo.cs | 53 | ||||
-rw-r--r-- | monodevelop/MonoDevelop.Zeitgeist.addin.xml | 19 | ||||
-rw-r--r-- | monodevelop/StartupHandler.cs | 134 | ||||
-rw-r--r-- | monodevelop/TrackedDocument.cs | 78 | ||||
-rw-r--r-- | monodevelop/ZeitgeistClient.cs | 153 |
5 files changed, 437 insertions, 0 deletions
diff --git a/monodevelop/AssemblyInfo.cs b/monodevelop/AssemblyInfo.cs new file mode 100644 index 0000000..264a129 --- /dev/null +++ b/monodevelop/AssemblyInfo.cs @@ -0,0 +1,53 @@ +// +// AssemblyInfo.cs +// +// Author: +// Patrick McEvoy <patrick@qmtech.net> +// +// Copyright (c) 2011 QMTech. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, +// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +using System.Reflection; +using System.Runtime.CompilerServices; + +// Information about this assembly is defined by the following attributes. +// Change them to the values specific to your project. + +[assembly: AssemblyTitle("MonoDevelop.Zeitgeist")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("QMTech")] +[assembly: AssemblyProduct("")] +[assembly: AssemblyCopyright("Copyright QMTech 2011. All rights reserved")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}". +// The form "{Major}.{Minor}.*" will automatically update the build and revision, +// and "{Major}.{Minor}.{Build}.*" will update just the revision. + +[assembly: AssemblyVersion("1.0.*")] + +// The following attributes are used to specify the signing key for the assembly, +// if desired. See the Mono documentation for more information about signing. + +//[assembly: AssemblyDelaySign(false)] +//[assembly: AssemblyKeyFile("")] + diff --git a/monodevelop/MonoDevelop.Zeitgeist.addin.xml b/monodevelop/MonoDevelop.Zeitgeist.addin.xml new file mode 100644 index 0000000..35c33c2 --- /dev/null +++ b/monodevelop/MonoDevelop.Zeitgeist.addin.xml @@ -0,0 +1,19 @@ +<Addin id = "Zeitgeist" + namespace = "MonoDevelop" + name = "Zeitgeist Support" + author = "Patrick McEvoy and Manish Sinha" + copyright = "MIT X11" + url = "http://github.com/firegrass/" + description = "Log activity to Zeitgeist." + category = "Logging" + version = "0.1"> + + <Runtime> + <Import assembly="MonoDevelop.Zeitgeist.dll"/> + </Runtime> + + <Dependencies> + <Addin id="Ide" version="2.6.0"/> + </Dependencies> + +</Addin>
\ No newline at end of file diff --git a/monodevelop/StartupHandler.cs b/monodevelop/StartupHandler.cs new file mode 100644 index 0000000..cba2106 --- /dev/null +++ b/monodevelop/StartupHandler.cs @@ -0,0 +1,134 @@ +// +// StartupHandler.cs +// +// Author: +// Patrick McEvoy <patrick@qmtech.net> +// Manish Sinha <manishsinha@ubuntu.com> +// +// Copyright (c) 2011 QMTech. +// Copyright (c) 2011 Manish Sinha <manishsinha@ubuntu.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, +// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +using System; +using Mono.Addins; +using MonoDevelop.Components.Commands; +using MonoDevelop.Ide.Extensions; +using MonoDevelop.Projects; +using MonoDevelop.Ide.Gui; +using System.Collections.Generic; +using MonoDevelop.Core; +using System.Linq; + +namespace MonoDevelop.Zeitgeist +{ + [Extension ("/MonoDevelop/Ide/StartupHandlers", NodeName="Class")] + public class StartupHandler: CommandHandler + { + ZeitgeistClient client; + IList<TrackedDocument> documents = new List<TrackedDocument> (); + + public StartupHandler () + { + client = new ZeitgeistClient (); + } + + protected override void Run () + { + // TODO Don't log files as opened until they before active through usage when opening a project/solu + // IDEA: Auto-close tabs that aren't being used + Ide.IdeApp.Workbench.DocumentOpened += HandleDocumentOpened; + + MonoDevelop.Core.FileService.FileCreated += HandleMonoDevelopCoreFileServiceFileCreated; + MonoDevelop.Core.FileService.FileRenamed += HandleMonoDevelopCoreFileServiceFileRenamed; + MonoDevelop.Core.FileService.FileRemoved += HandleMonoDevelopCoreFileServiceFileRemoved; + + Ide.IdeApp.Workspace.SolutionLoaded += HandleIdeIdeAppWorkspaceSolutionLoaded; + Ide.IdeApp.Workspace.SolutionUnloaded += HandleIdeIdeAppWorkspaceSolutionUnloaded; + } + + void HandleMonoDevelopCoreFileServiceFileCreated (object sender, FileEventArgs e) + { + foreach(var fileInfo in e.ToList()) + { + if(!fileInfo.IsDirectory) + { + MonoDevelop.Core.LoggingService.LogInfo ("File {0} created", + fileInfo.FileName.FileName); + client.SendFilePath (fileInfo.FileName, EventType.Create); + } + } + } + + void HandleMonoDevelopCoreFileServiceFileRemoved (object sender, FileEventArgs e) + { + foreach(var fileInfo in e.ToList()) + { + if(!fileInfo.IsDirectory) + { + MonoDevelop.Core.LoggingService.LogInfo ("File {0} deleted", + fileInfo.FileName.FileName); + client.SendFilePath (fileInfo.FileName, EventType.Delete); + } + } + } + + void HandleMonoDevelopCoreFileServiceFileRenamed (object sender, FileCopyEventArgs e) + { + foreach(FileCopyEventInfo evInfo in e.ToList()) + { + if(!evInfo.IsDirectory) + { + MonoDevelop.Core.LoggingService.LogInfo ("Renamed {0} to {1}", + evInfo.SourceFile.FileName, evInfo.TargetFile.FileName); + client.SendFilePath (evInfo.SourceFile, evInfo.TargetFile, EventType.Move); + } + } + } + + void HandleIdeIdeAppWorkspaceSolutionUnloaded (object sender, SolutionEventArgs e) + { + MonoDevelop.Core.LoggingService.LogInfo ("Solution Unloaded: {0}", e.Solution.FileName.FileName); + client.SendFilePath (e.Solution.FileName, EventType.Leave); + } + + void HandleIdeIdeAppWorkspaceSolutionLoaded (object sender, SolutionEventArgs e) + { + MonoDevelop.Core.LoggingService.LogInfo ("Solution Loaded: {0}", e.Solution.FileName.FileName); + client.SendFilePath (e.Solution.FileName, EventType.Access); + } + + void HandleDocumentOpened (object sender, DocumentEventArgs e) + { + if (!e.Document.IsFile) + return; + + MonoDevelop.Core.LoggingService.LogInfo ("Logging access of {0} to Zeitgeist", e.Document.FileName.FileName); + var tracked = new TrackedDocument (client, e.Document); + tracked.Destroyed += delegate { + foreach (var t in documents) + if (!t.IsCurrent ()) + documents.Remove (t); + }; + documents.Add (tracked); + client.SendFilePath (e.Document.FileName, EventType.Access); + } + } +} + diff --git a/monodevelop/TrackedDocument.cs b/monodevelop/TrackedDocument.cs new file mode 100644 index 0000000..3cbe31d --- /dev/null +++ b/monodevelop/TrackedDocument.cs @@ -0,0 +1,78 @@ +// +// TrackedDocument.cs +// +// Author: +// Patrick McEvoy <patrick@qmtech.net> +// +// Copyright (c) 2011 QMTech. +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, +// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +using System; +using MonoDevelop.Ide.Gui; +using MonoDevelop.Core; + +namespace MonoDevelop.Zeitgeist +{ + internal class TrackedDocument + { + public Document Document { get; set; } + public FilePath FilePath { get; set; } + + ZeitgeistClient client; + + public TrackedDocument (ZeitgeistClient _client, Document doc) + { + client = _client; + + doc.Closed += HandleDocClosed; + doc.Saved += HandleDocSaved; + Document = doc; + FilePath = new FilePath (doc.FileName); + } + + void HandleDocSaved (object sender, EventArgs e) + { + MonoDevelop.Core.LoggingService.LogInfo ("Logging modify of {0} to Zeitgeist", Document.FileName.FileName); + client.SendFilePath (FilePath, EventType.Modify); + } + + void HandleDocClosed (object sender, EventArgs e) + { + MonoDevelop.Core.LoggingService.LogInfo ("Logging leave of {0} to Zeitgeist", FilePath.FileName); + client.SendFilePath (FilePath, EventType.Leave); + } + + public virtual void Dispose () + { + if (Destroyed != null) + Destroyed (this, EventArgs.Empty); + } + + public event EventHandler Destroyed; + + public bool IsCurrent () + { + if (Document == null) + return false; + return true; + } + } +} + diff --git a/monodevelop/ZeitgeistClient.cs b/monodevelop/ZeitgeistClient.cs new file mode 100644 index 0000000..af96314 --- /dev/null +++ b/monodevelop/ZeitgeistClient.cs @@ -0,0 +1,153 @@ +// +// ZeitgeistClient.cs +// +// Author: +// Patrick McEvoy <patrick@qmtech.net> +// Manish Sinha <manishsinha@ubuntu.com> +// +// Copyright (c) 2011 QMTech. +// Copyright (c) 2011 Manish Sinha <manishsinha@ubuntu.com> +// +// Permission is hereby granted, free of charge, to any person obtaining a copy of this +// software and associated documentation files (the "Software"), to deal in the Software +// without restriction, including without limitation the rights to use, copy, modify, +// merge, publish, distribute, sublicense, and/or sell copies of the Software, and to +// permit persons to whom the Software is furnished to do so, subject to the following +// conditions: +// +// The above copyright notice and this permission notice shall be included in all copies or +// substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS +// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. +// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY +// CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, +// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE +// SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + +using System; + +using MonoDevelop.Ide.Gui; + +using Zeitgeist.Datamodel; +using Zeitgeist; +using System.Collections.Generic; +using MonoDevelop.Ide; +using MonoDevelop.Projects; +using MonoDevelop.Core; + +namespace MonoDevelop.Zeitgeist +{ + internal enum EventType { + Access, + Modify, + Leave, + Move, + Create, + Delete, + } + + internal class ZeitgeistClient + { + public const string MonoDevelopUri = "application://monodevelop.desktop"; + public const string Mimetype = "text/plain"; + + const string monodevelopDataSourceId = "org.gnome.MonoDevelop,dataprovider"; + const string monodevelopDataSourceName = "MonoDevelop Datasource"; + const string monodevelopDataSourceDesc = "This datasource pushes the file open, delete, modify events for files and directories edited in MonoDevelop"; + + DataSourceClient dsReg; + LogClient client; + + public ZeitgeistClient () + { + dsReg = new DataSourceClient (); + + MonoDevelop.Core.LoggingService.LogInfo ("Zg#: init new"); + + Event ev = new Event (); + ev.Actor = MonoDevelopUri; + Subject sub = new Subject (); + sub.Interpretation = Interpretation.Instance.Document.Document; + sub.Manifestation = Manifestation.Instance.FileDataObject.FileDataObject; + ev.Subjects.Add (sub); + + try { + dsReg.RegisterDataSources (monodevelopDataSourceId, + monodevelopDataSourceName, + monodevelopDataSourceDesc, + new List<Event> (){ev}); + client = new LogClient (); + } catch (Exception ex) { + MonoDevelop.Core.LoggingService.LogError ("Error init", ex); + } + } + + public void SendFilePath (FilePath oldPath, FilePath newPath, EventType type) + { + var eventManifestation = Manifestation.Instance.EventManifestation.UserActivity; + var subjectInterpretation = Interpretation.Instance.Document.TextDocument.PlainTextDocument.SourceCode; + var subjectManifestation = Manifestation.Instance.FileDataObject.FileDataObject; + + var interpretation = Interpretation.Instance.EventInterpretation.ModifyEvent; + switch (type) { + case EventType.Access: + interpretation = Interpretation.Instance.EventInterpretation.AccessEvent; + break; + case EventType.Leave: + interpretation = Interpretation.Instance.EventInterpretation.LeaveEvent; + break; + case EventType.Modify: + interpretation = Interpretation.Instance.EventInterpretation.ModifyEvent; + break; + case EventType.Move: + interpretation = Interpretation.Instance.EventInterpretation.MoveEvent; + break; + case EventType.Create: + interpretation = Interpretation.Instance.EventInterpretation.CreateEvent; + break; + case EventType.Delete: + interpretation = Interpretation.Instance.EventInterpretation.DeleteEvent; + break; + } + + Event ev = new Event (); + + ev.Id = 0; + ev.Timestamp = DateTime.Now; + ev.Interpretation = interpretation; + ev.Manifestation = eventManifestation; + ev.Actor = MonoDevelopUri; + + Subject sub = new Subject (); + + sub.Uri = "file://" + oldPath.FullPath; + if(newPath != null) + sub.CurrentUri = "file://" + newPath.FullPath; + + sub.Interpretation = subjectInterpretation; + sub.Manifestation = subjectManifestation; + + FilePath path = newPath != null? newPath : oldPath; + MonoDevelop.Core.LoggingService.LogInfo ("File Opened: {0}", path.FullPath); + sub.Origin = path.FullPath.ParentDirectory; + sub.MimeType = DesktopService.GetMimeTypeForUri (path.FullPath); + sub.Text = path.FileName; + sub.Storage = string.Empty; + + ev.Subjects.Add (sub); + + List<Event> listOfEvents = new List<Event> (); + listOfEvents.Add (ev); + + client.InsertEvents (listOfEvents); + } + + public void SendFilePath (FilePath filePath, EventType type) + { + SendFilePath(filePath, null, type); + } + } +} + |