Refactored the Office Destinations, including the Interop & configuration, to the new Office plug-in. Also refactored some code to be more consistent.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2131 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-10-10 14:18:05 +00:00
commit 4d399a60ac
34 changed files with 739 additions and 365 deletions

View file

@ -0,0 +1,192 @@
/*
* 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 <http://www.gnu.org/licenses/>.
*/
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Greenshot.Interop.Office;
using Greenshot.Plugin;
using GreenshotPlugin.Core;
using Greenshot.IniFile;
namespace GreenshotOfficePlugin {
/// <summary>
/// Description of OutlookDestination.
/// </summary>
public class OutlookDestination : AbstractDestination {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(OutlookDestination));
private static OfficeConfiguration conf = IniConfig.GetIniSection<OfficeConfiguration>();
private static string exePath = null;
private static Image applicationIcon = null;
private static Image mailIcon = GreenshotPlugin.Core.GreenshotResources.getImage("Email.Image");
private static Image meetingIcon = null;
private static bool isActiveFlag = false;
private static string mapiClient = "Microsoft Outlook";
public const string DESIGNATION = "Outlook";
private string outlookInspectorCaption;
private OlObjectClass outlookInspectorType;
static OutlookDestination() {
if (EmailConfigHelper.HasOutlook()) {
isActiveFlag = true;
}
exePath = PluginUtils.GetExePath("OUTLOOK.EXE");
if (exePath != null && File.Exists(exePath)) {
applicationIcon = PluginUtils.GetExeIcon(exePath, 0);
WindowDetails.AddProcessToExcludeFromFreeze("outlook");
if (conf.OutlookAllowExportInMeetings) {
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
}
} else {
exePath = null;
}
if (exePath == null) {
isActiveFlag = false;
}
}
public OutlookDestination() {
}
public OutlookDestination(string outlookInspectorCaption, OlObjectClass outlookInspectorType) {
this.outlookInspectorCaption = outlookInspectorCaption;
this.outlookInspectorType = outlookInspectorType;
}
public override string Designation {
get {
return DESIGNATION;
}
}
public override string Description {
get {
if (outlookInspectorCaption == null) {
return mapiClient;
} else {
return outlookInspectorCaption;
}
}
}
public override int Priority {
get {
return 3;
}
}
public override bool isActive {
get {
return base.isActive && isActiveFlag;
}
}
public override bool isDynamic {
get {
return true;
}
}
public override Keys EditorShortcutKeys {
get {
return Keys.Control | Keys.E;
}
}
public override Image DisplayIcon {
get {
if (outlookInspectorCaption != null) {
if (OlObjectClass.olAppointment.Equals(outlookInspectorType)) {
// Make sure we loaded the icon, maybe the configuration has been changed!
if (meetingIcon == null) {
meetingIcon = PluginUtils.GetExeIcon(exePath, 2);
}
return meetingIcon;
} else {
return mailIcon;
}
} else {
return applicationIcon;
}
}
}
public override IEnumerable<IDestination> DynamicDestinations() {
Dictionary<string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings);
if (inspectorCaptions != null) {
foreach (string inspectorCaption in inspectorCaptions.Keys) {
yield return new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption]);
}
}
}
public override ExportInformation ExportCapture(bool manuallyInitiated, ISurface surface, ICaptureDetails captureDetails) {
ExportInformation exportInformation = new ExportInformation(this.Designation, this.Description);
// Outlook logic
string tmpFile = captureDetails.Filename;
if (tmpFile == null || surface.Modified) {
using (Image image = surface.GetImageForExport()) {
tmpFile = ImageOutput.SaveNamedTmpFile(image, captureDetails, new OutputSettings());
}
} else {
LOG.InfoFormat("Using already available file: {0}", tmpFile);
}
// Create a attachment name for the image
string attachmentName = captureDetails.Title;
if (!string.IsNullOrEmpty(attachmentName)) {
attachmentName = attachmentName.Trim();
}
// Set default if non is set
if (string.IsNullOrEmpty(attachmentName)) {
attachmentName = "Greenshot Capture";
}
// Make sure it's "clean" so it doesn't corrupt the header
attachmentName = Regex.Replace(attachmentName, @"[^\x20\d\w]", "");
if (outlookInspectorCaption != null) {
OutlookEmailExporter.ExportToInspector(outlookInspectorCaption, tmpFile, attachmentName);
exportInformation.ExportMade = true;
} else {
if (!manuallyInitiated) {
Dictionary<string, OlObjectClass> inspectorCaptions = OutlookEmailExporter.RetrievePossibleTargets(conf.OutlookAllowExportInMeetings);
if (inspectorCaptions != null && inspectorCaptions.Count > 0) {
List<IDestination> destinations = new List<IDestination>();
destinations.Add(new OutlookDestination());
foreach (string inspectorCaption in inspectorCaptions.Keys) {
destinations.Add(new OutlookDestination(inspectorCaption, inspectorCaptions[inspectorCaption]));
}
// Return the ExportInformation from the picker without processing, as this indirectly comes from us self
return ShowPickerMenu(false, surface, captureDetails, destinations);
}
} else {
OutlookEmailExporter.ExportToOutlook(conf.OutlookEmailFormat, tmpFile, FilenameHelper.FillPattern(conf.EmailSubjectPattern, captureDetails, false), attachmentName, conf.EmailTo, conf.EmailCC, conf.EmailBCC);
exportInformation.ExportMade = true;
}
}
ProcessExport(exportInformation, surface);
return exportInformation;
}
}
}