diff --git a/GreenshotOfficeCommunicatorPlugin/Communicator.cs b/GreenshotOfficeCommunicatorPlugin/Communicator.cs new file mode 100644 index 000000000..811742315 --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/Communicator.cs @@ -0,0 +1,187 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; +using CommunicatorAPI; +using System.Runtime.InteropServices; +using System.Collections.Generic; +using GreenshotPlugin.Core; + +namespace GreenshotOfficeCommunicatorPlugin { + + public class Communicator { + private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Communicator)); + private bool connected = false; + + private CommunicatorAPI.Messenger communicator = null; + private Dictionary communicatorConversations = new Dictionary(); + public Communicator() { + } + public bool isConnected { + get { + return connected; + } + } + + public bool hasConversations { + get { + return communicatorConversations.Count > 0; + } + } + + public IEnumerable Conversations { + get { + foreach (CommunicatorConversation conversation in communicatorConversations.Values) { + yield return conversation; + } + } + } + + // A simple implementation of signing in. + public void Signin(string account, string passwd) { + if (connected) + return; + + if (communicator == null) { + // Create a Messenger object, if necessary + communicator = new CommunicatorAPI.Messenger(); + + // Register event handlers for OnSignin and Signout events + communicator.OnSignin += new DMessengerEvents_OnSigninEventHandler(communicator_OnSignin); + communicator.OnSignout += new DMessengerEvents_OnSignoutEventHandler(communicator_OnSignout); + communicator.OnIMWindowCreated += new DMessengerEvents_OnIMWindowCreatedEventHandler(communicator_OnIMWindowCreated); + communicator.OnIMWindowDestroyed += new DMessengerEvents_OnIMWindowDestroyedEventHandler(communicator_OnIMWindowDestroyed); + } + + if (account == null) { + communicator.AutoSignin(); + } else { + communicator.Signin(0, account, passwd); + } + } + + // Event handler for OnSignin event. + void communicator_OnSignin(int hr) { + if (hr != 0) { + Console.WriteLine("Signin failed."); + return; + } + connected = true; + } + + void communicator_OnSignout() { + connected = false; + + // Release the unmanaged resource. + Marshal.ReleaseComObject(communicator); + communicator = null; + } + + // Register for IMWindowCreated event to receive the + // conversation window object. Other window objects can + // received via this event handling as well. + void communicator_OnIMWindowCreated(object pIMWindow) { + try { + IMessengerConversationWndAdvanced imWindow = (IMessengerConversationWndAdvanced)pIMWindow; + CommunicatorConversation conversation = null; + if (communicatorConversations.ContainsKey(imWindow.HWND)) { + conversation = communicatorConversations[imWindow.HWND]; + } else { + conversation = new CommunicatorConversation(imWindow.HWND); + communicatorConversations.Add(imWindow.HWND, conversation); + } + conversation.ImWindow = imWindow; + } catch (Exception exception) { + LOG.Error(exception); + } + } + + void communicator_OnIMWindowDestroyed(object pIMWindow) { + try { + IMessengerConversationWndAdvanced imWindow = (IMessengerConversationWndAdvanced)pIMWindow; + CommunicatorConversation foundConversation = null; + long foundHwnd = 0; + foreach (long hwndKey in communicatorConversations.Keys) { + if (imWindow.Equals(communicatorConversations[hwndKey].ImWindow)) { + foundConversation = communicatorConversations[hwndKey]; + foundConversation.ImWindow = null; + foundHwnd = hwndKey; + break; + } + } + if (foundConversation != null) { + communicatorConversations.Remove(foundHwnd); + } + Marshal.ReleaseComObject(pIMWindow); + } catch (Exception exception) { + LOG.Error(exception); + } + } + + public CommunicatorConversation StartConversation(string account) { + object[] sipUris = { account }; + CommunicatorAPI.IMessengerAdvanced msgrAdv = communicator as CommunicatorAPI.IMessengerAdvanced; + CommunicatorConversation communicatorConversation = null; + if (msgrAdv != null) { + try { + object obj = msgrAdv.StartConversation( + CONVERSATION_TYPE.CONVERSATION_TYPE_IM, // Type of conversation + sipUris, // object array of signin names for having multiple conversations + null, + "Testing", + "1", + null); + long hwnd = long.Parse(obj.ToString()); + if (!communicatorConversations.ContainsKey(hwnd)) { + communicatorConversations.Add(hwnd, new CommunicatorConversation(hwnd)); + } + communicatorConversation = communicatorConversations[hwnd]; + } catch (Exception ex) { + LOG.Error(ex); + } + } + + return communicatorConversation; + } + + + public void ShowContacts() { + // Display contacts to a console window(for illustration only). + foreach (IMessengerContact contact in communicator.MyContacts as IMessengerContacts) { + if (!contact.IsSelf) { + Console.WriteLine("{0} ({1})", contact.SigninName, contact.Status); + } + } + } + + // A simple implementation of signing out. + public void Signout() { + if (!connected) { + return; + } + + if (communicator == null) { + return; + } + + communicator.Signout(); + } + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/CommunicatorConversation.cs b/GreenshotOfficeCommunicatorPlugin/CommunicatorConversation.cs new file mode 100644 index 000000000..7c7c24e97 --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/CommunicatorConversation.cs @@ -0,0 +1,84 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +using System.Text; +using CommunicatorAPI; +using System.Runtime.InteropServices; +using GreenshotPlugin.Core; + +namespace GreenshotOfficeCommunicatorPlugin { + public class CommunicatorConversation { + private IMessengerConversationWndAdvanced imWindow = null; + private long hwnd = 0; + private Queue queuedText = new Queue(); + + public CommunicatorConversation(long hwnd) { + this.hwnd = hwnd; + } + + public bool isActive { + get { + return imWindow != null; + } + } + + public IMessengerConversationWndAdvanced ImWindow { + get { + return imWindow; + } + set { + imWindow = value; + if (imWindow != null) { + while (queuedText.Count > 0 && imWindow != null) { + SendTextMessage(queuedText.Dequeue()); + } + } else { + hwnd = 0; + } + } + } + + // Send text only if the window object matches the desired window handle + public void SendTextMessage(string msg) { + if (imWindow != null) { + imWindow.SendText(msg); + } else { + queuedText.Enqueue(msg); + } + } + + public string History { + get { + return imWindow.History; + } + } + + public string Title { + get { + if (imWindow != null) { + return new WindowDetails(new IntPtr(hwnd)).Text; + } + return null; + } + } + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/DLL/CommunicatorAPI.dll b/GreenshotOfficeCommunicatorPlugin/DLL/CommunicatorAPI.dll new file mode 100644 index 000000000..f7e4f84ce Binary files /dev/null and b/GreenshotOfficeCommunicatorPlugin/DLL/CommunicatorAPI.dll differ diff --git a/GreenshotOfficeCommunicatorPlugin/DLL/CommunicatorPrivate.dll b/GreenshotOfficeCommunicatorPlugin/DLL/CommunicatorPrivate.dll new file mode 100644 index 000000000..0f128dbdf Binary files /dev/null and b/GreenshotOfficeCommunicatorPlugin/DLL/CommunicatorPrivate.dll differ diff --git a/GreenshotOfficeCommunicatorPlugin/Forms/OfficeCommunicatorForm.cs b/GreenshotOfficeCommunicatorPlugin/Forms/OfficeCommunicatorForm.cs new file mode 100644 index 000000000..126f4d2bc --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/Forms/OfficeCommunicatorForm.cs @@ -0,0 +1,31 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; + +namespace GreenshotOfficeCommunicatorPlugin { + /// + /// This class is needed for design-time resolving of the language files + /// + public class OfficeCommunicatorForm : GreenshotPlugin.Controls.GreenshotForm { + public OfficeCommunicatorForm() : base() { + } + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/Forms/SettingsForm.Designer.cs b/GreenshotOfficeCommunicatorPlugin/Forms/SettingsForm.Designer.cs new file mode 100644 index 000000000..64721429f --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/Forms/SettingsForm.Designer.cs @@ -0,0 +1,96 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +namespace GreenshotOfficeCommunicatorPlugin { + partial class SettingsForm { + /// + /// Designer variable used to keep track of non-visual components. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Disposes resources used by the form. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing) { + if (components != null) { + components.Dispose(); + } + } + base.Dispose(disposing); + } + + /// + /// This method is required for Windows Forms designer support. + /// Do not change the method contents inside the source code editor. The Forms designer might + /// not be able to load this method if it was changed manually. + /// + private void InitializeComponent() + { + this.buttonOK = new GreenshotPlugin.Controls.GreenshotButton(); + this.buttonCancel = new GreenshotPlugin.Controls.GreenshotButton(); + this.SuspendLayout(); + // + // buttonOK + // + this.buttonOK.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonOK.LanguageKey = "officecommunicator.OK"; + this.buttonOK.Location = new System.Drawing.Point(222, 11); + this.buttonOK.Name = "buttonOK"; + this.buttonOK.Size = new System.Drawing.Size(75, 23); + this.buttonOK.TabIndex = 2; + this.buttonOK.Text = "OK"; + this.buttonOK.UseVisualStyleBackColor = true; + this.buttonOK.Click += new System.EventHandler(this.ButtonOKClick); + // + // buttonCancel + // + this.buttonCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); + this.buttonCancel.LanguageKey = "officecommunicator.CANCEL"; + this.buttonCancel.Location = new System.Drawing.Point(303, 11); + this.buttonCancel.Name = "buttonCancel"; + this.buttonCancel.Size = new System.Drawing.Size(75, 23); + this.buttonCancel.TabIndex = 3; + this.buttonCancel.Text = "Cancel"; + this.buttonCancel.UseVisualStyleBackColor = true; + this.buttonCancel.Click += new System.EventHandler(this.ButtonCancelClick); + // + // SettingsForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; + this.ClientSize = new System.Drawing.Size(387, 46); + this.Controls.Add(this.buttonCancel); + this.Controls.Add(this.buttonOK); + this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; + this.LanguageKey = "officecommunicator.settings_title"; + this.MaximizeBox = false; + this.MinimizeBox = false; + this.Name = "SettingsForm"; + this.Text = "Office Communicator settings"; + this.ResumeLayout(false); + + } + private GreenshotPlugin.Controls.GreenshotButton buttonCancel; + private GreenshotPlugin.Controls.GreenshotButton buttonOK; + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/Forms/SettingsForm.cs b/GreenshotOfficeCommunicatorPlugin/Forms/SettingsForm.cs new file mode 100644 index 000000000..5cf2826b1 --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/Forms/SettingsForm.cs @@ -0,0 +1,47 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; +using System.Windows.Forms; +using GreenshotPlugin.Core; +using GreenshotPlugin.Controls; + +namespace GreenshotOfficeCommunicatorPlugin { + /// + /// Description of PasswordRequestForm. + /// + public partial class SettingsForm : OfficeCommunicatorForm { + public SettingsForm(OfficeCommunicatorConfiguration config) : base() { + // + // The InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + this.Icon = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon(); + } + + void ButtonOKClick(object sender, EventArgs e) { + this.DialogResult = DialogResult.OK; + } + + void ButtonCancelClick(object sender, System.EventArgs e) { + this.DialogResult = DialogResult.Cancel; + } + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/GreenshotOfficeCommunicatorPlugin.csproj b/GreenshotOfficeCommunicatorPlugin/GreenshotOfficeCommunicatorPlugin.csproj new file mode 100644 index 000000000..3c059d9ba --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/GreenshotOfficeCommunicatorPlugin.csproj @@ -0,0 +1,118 @@ + + + + {C1050323-F237-43E2-90F9-1D620F29252F} + Debug + x86 + Library + GreenshotOfficeCommunicatorPlugin + GreenshotOfficeCommunicatorPlugin + v2.0 + Properties + False + False + 4 + false + OnBuildSuccess + + + + 3.5 + + + + bin\Debug\ + true + Full + False + True + False + Off + 4194304 + x86 + 4096 + DEBUG;TRACE + + + bin\Release\ + false + None + True + False + False + Off + 4194304 + AnyCPU + 4096 + + + + + False + True + DLL\CommunicatorAPI.dll + + + False + True + DLL\CommunicatorPrivate.dll + + + ..\Greenshot\Lib\log4net.dll + + + + + + + + + + + Form + + + Form + + + SettingsForm.cs + + + + + + + + Never + + + + + + {5B924697-4DCD-4F98-85F1-105CB84B7341} + GreenshotPlugin + + + + + SettingsForm.cs + + + + + Always + + + Always + + + + "$(SolutionDir)\tools\TortoiseSVN\SubWCRev.exe" "$(ProjectDir)\" "$(ProjectDir)\Properties\AssemblyInfo.cs.template" "$(ProjectDir)\Properties\AssemblyInfo.cs" + mkdir "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)" +copy "$(ProjectDir)bin\$(Configuration)\$(TargetFileName)" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*.gsp" +copy "$(ProjectDir)\DLL\*.dll" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName) + +mkdir "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)" +copy "$(ProjectDir)\Languages\*.xml" "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" + + \ No newline at end of file diff --git a/GreenshotOfficeCommunicatorPlugin/LanguageKeys.cs b/GreenshotOfficeCommunicatorPlugin/LanguageKeys.cs new file mode 100644 index 000000000..8dc67c329 --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/LanguageKeys.cs @@ -0,0 +1,42 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; + +namespace GreenshotOfficeCommunicatorPlugin { + public enum LangKey { + upload_menu_item, + settings_title, + label_url, + label_upload_format, + label_clear, + OK, + CANCEL, + upload_success, + upload_failure, + communication_wait, + delete_question, + clear_question, + delete_title, + use_page_link, + history, + configure + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/Languages/language_officecommunicatorplugin-en-US.xml b/GreenshotOfficeCommunicatorPlugin/Languages/language_officecommunicatorplugin-en-US.xml new file mode 100644 index 000000000..ca11504c1 --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/Languages/language_officecommunicatorplugin-en-US.xml @@ -0,0 +1,32 @@ + + + + + Upload to Office Communicator + + + Office Communicator settings + + + OK + + + Cancel + + + Successfully uploaded image to Office Communicator! + + + An error occured while uploading to Office Communicator: + + + Image format + + + Communicating with Office Communicator. Please wait... + + + Configure + + + \ No newline at end of file diff --git a/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorConfiguration.cs b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorConfiguration.cs new file mode 100644 index 000000000..d5b33907e --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorConfiguration.cs @@ -0,0 +1,57 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +using System.Windows.Forms; + +using GreenshotPlugin.Controls; +using GreenshotPlugin.Core; +using Greenshot.IniFile; + +namespace GreenshotOfficeCommunicatorPlugin { + /// + /// Description of OfficeCommunicatorConfiguration. + /// + [IniSection("OfficeCommunicator", Description="Greenshot OfficeCommunicator Plugin configuration")] + public class OfficeCommunicatorConfiguration : IniSection { + [IniProperty("Destination", Description = "The designation of the destination which is used to export via, the returned URL is used in the message.", DefaultValue = "FileDialog")] + public string DestinationDesignation; + + /// + /// A form for username/password + /// + /// bool true if OK was pressed, false if cancel + public bool ShowConfigDialog() { + SettingsForm settingsForm = null; + + new PleaseWaitForm().ShowAndWait(OfficeCommunicatorPlugin.Attributes.Name, Language.GetString("officecommunicator", LangKey.communication_wait), + delegate() { + settingsForm = new SettingsForm(this); + } + ); + DialogResult result = settingsForm.ShowDialog(); + if (result == DialogResult.OK) { + return true; + } + return false; + } + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorDestination.cs b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorDestination.cs new file mode 100644 index 000000000..8c9ee8589 --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorDestination.cs @@ -0,0 +1,125 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Diagnostics; +using System.Drawing; +using System.IO; +using System.Windows; + +using Greenshot.Plugin; +using GreenshotPlugin.Core; +using Greenshot.IniFile; + +namespace GreenshotOfficeCommunicatorPlugin { + /// + /// Description of OfficeCommunicatorDestination. + /// + public class OfficeCommunicatorDestination : AbstractDestination { + private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OfficeCommunicatorDestination)); + private static OfficeCommunicatorConfiguration config = IniConfig.GetIniSection(); + private OfficeCommunicatorPlugin plugin = null; + private static string exePath = null; + private static Image applicationIcon = null; + private CommunicatorConversation conversation = null; + + static OfficeCommunicatorDestination() { + exePath = GetExePath("communicator.exe"); + if (exePath != null && File.Exists(exePath)) { + applicationIcon = GetExeIcon(exePath, 0); + } else { + exePath = null; + } + } + public OfficeCommunicatorDestination(OfficeCommunicatorPlugin plugin) { + this.plugin = plugin; + } + + public OfficeCommunicatorDestination(OfficeCommunicatorPlugin plugin, CommunicatorConversation conversation) : this(plugin) { + this.conversation = conversation; + } + + public override string Designation { + get { + return "OfficeCommunicator"; + } + } + + public override string Description { + get { + if (conversation == null) { + return Language.GetString("officecommunicator", LangKey.upload_menu_item); + } else { + return Language.GetString("officecommunicator", LangKey.upload_menu_item) + " - " + conversation.Title; + } + } + } + + public override Image DisplayIcon { + get { + return applicationIcon; + } + } + + public override bool isActive { + get { + return base.isActive && exePath != null && ((conversation == null && plugin.Communicator.hasConversations) || (conversation != null && conversation.isActive)); + } + } + + public override IEnumerable DynamicDestinations() { + foreach (CommunicatorConversation conversation in plugin.Communicator.Conversations) { + if (conversation.isActive) { + yield return new OfficeCommunicatorDestination(plugin, conversation); + } + } + } + + public override bool isDynamic { + get { + return true; + } + } + + public override bool useDynamicsOnly { + get { + return true; + } + } + + public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) { + ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description); + if (conversation != null) { + ExportInformation internalExportInformation = plugin.Host.ExportCapture(false, config.DestinationDesignation, surface, captureDetails); + if (internalExportInformation != null && internalExportInformation.ExportMade) { + exportInformation.ExportMade = true; + if (!string.IsNullOrEmpty(internalExportInformation.Uri)) { + conversation.SendTextMessage("Greenshot sends you: " + internalExportInformation.Uri); + } else if (!string.IsNullOrEmpty(internalExportInformation.Filepath)) { + conversation.SendTextMessage(@"Greenshot sends you: file://" + internalExportInformation.Filepath); + } + } + } + return exportInformation; + } + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorPlugin.cs b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorPlugin.cs new file mode 100644 index 000000000..54747e3da --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/OfficeCommunicatorPlugin.cs @@ -0,0 +1,109 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Drawing; +using System.IO; +using System.Windows.Forms; +using System.Threading; + +using Greenshot.Plugin; +using GreenshotPlugin.Controls; +using GreenshotPlugin.Core; +using Greenshot.IniFile; +using CommunicatorAPI; +using System.Runtime.InteropServices; + +namespace GreenshotOfficeCommunicatorPlugin { + /// + /// This is the OfficeCommunicatorPlugin + /// + public class OfficeCommunicatorPlugin : IGreenshotPlugin { + private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OfficeCommunicatorPlugin)); + public static PluginAttribute Attributes; + private OfficeCommunicatorConfiguration config = IniConfig.GetIniSection(); + private IGreenshotHost host; + private Communicator communicator; + public IGreenshotHost Host { + get { + return host; + } + } + + public Communicator Communicator { + get { + return communicator; + } + set { + communicator = value; + } + } + + public OfficeCommunicatorPlugin() { + } + + public IEnumerable Destinations() { + yield return new OfficeCommunicatorDestination(this); + } + + public IEnumerable Processors() { + yield break; + } + + /// + /// Implementation of the IGreenshotPlugin.Initialize + /// + /// Use the IGreenshotPluginHost interface to register events + /// Use the ICaptureHost interface to register in the MainContextMenu + /// My own attributes + /// true if plugin is initialized, false if not (doesn't show) + public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes) { + this.host = (IGreenshotHost)pluginHost; + Attributes = myAttributes; + + communicator = new Communicator(); + communicator.Signin(null, null); + return true; + } + + public virtual void Shutdown() { + LOG.Debug("OfficeCommunicator Plugin shutdown."); + } + + /// + /// Implementation of the IPlugin.Configure + /// + public virtual void Configure() { + config.ShowConfigDialog(); + } + + /// + /// This will be called when Greenshot is shutting down + /// + /// + /// + public void Closing(object sender, FormClosingEventArgs e) { + LOG.Debug("Application closing, de-registering OfficeCommunicator Plugin!"); + Shutdown(); + } + } +} diff --git a/GreenshotOfficeCommunicatorPlugin/Properties/AssemblyInfo.cs.template b/GreenshotOfficeCommunicatorPlugin/Properties/AssemblyInfo.cs.template new file mode 100644 index 000000000..46558d817 --- /dev/null +++ b/GreenshotOfficeCommunicatorPlugin/Properties/AssemblyInfo.cs.template @@ -0,0 +1,54 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2012 Thomas Braun, Jens Klingen, Robin Krom + * + * For more information see: http://getgreenshot.org/ + * The Greenshot project is hosted on Sourceforge: http://sourceforge.net/projects/greenshot/ + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 1 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +#region Using directives + +using System; +using System.Reflection; +using System.Runtime.InteropServices; +using Greenshot.Plugin; + +#endregion + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("Greenshot-OfficeCommunicator-Plugin")] +[assembly: AssemblyDescription("A plugin to upload images to office communicator")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("Greenshot")] +[assembly: AssemblyProduct("OfficeCommunicator Plugin")] +[assembly: AssemblyCopyright("Copyright (C) 2007-2012")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +// The PluginAttribute describes the "entryType" and if the plugin is configurable +[assembly: PluginAttribute("GreenshotOfficeCommunicatorPlugin.OfficeCommunicatorPlugin", true)] + +// This sets the default COM visibility of types in the assembly to invisible. +// If you need to expose a type to COM, use [ComVisible(true)] on that type. +[assembly: ComVisible(false)] + +// The assembly version has following format : +// +// Major.Minor.Build.Revision +// +// You can specify all the values or you can use the default the Revision and +// Build Numbers by using the '*' as shown below: +[assembly: AssemblyVersion("1.0.2.$WCREV$")]