diff --git a/GreenshotFlickrPlugin/FlickrPlugin.cs b/GreenshotFlickrPlugin/FlickrPlugin.cs new file mode 100644 index 000000000..67a357d78 --- /dev/null +++ b/GreenshotFlickrPlugin/FlickrPlugin.cs @@ -0,0 +1,162 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2010 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.Drawing; +using System.Drawing.Imaging; +using System.IO; +using System.Reflection; +using System.Runtime.Serialization.Formatters.Binary; +using System.Text; +using System.Windows.Forms; + +using Greenshot.Plugin; +using GreenshotPlugin.Core; +using Microsoft.Win32; + +namespace GreenshotFlickrPlugin { + /// + /// OCR Plugin Greenshot + /// + public class FlickrPlugin : IGreenshotPlugin { + private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FlickrPlugin)); + private const string CONFIG_FILENAME = "flickr-config.properties"; + private ILanguage lang = Language.GetInstance(); + private IGreenshotPluginHost host; + private ICaptureHost captureHost = null; + private PluginAttribute myAttributes; + private Properties config = new Properties(); + + public FlickrPlugin() { } + + /// + /// Implementation of the IGreenshotPlugin.Initialize + /// + /// Use the IGreenshotPluginHost interface to register events + /// Use the ICaptureHost interface to register in the MainContextMenu + /// My own attributes + public void Initialize(IGreenshotPluginHost host, ICaptureHost captureHost, PluginAttribute myAttributes) { + LOG.Debug("Initialize called of " + myAttributes.Name); + this.host = (IGreenshotPluginHost)host; + this.captureHost = captureHost; + this.myAttributes = myAttributes; + + host.OnImageEditorOpen += new OnImageEditorOpenHandler(ImageEditorOpened); + + // Make sure the MODI-DLLs are found by adding a resolver + AppDomain.CurrentDomain.AssemblyResolve += new ResolveEventHandler(MyAssemblyResolver); + + LoadConfig(); + } + + /// + /// Implementation of the OnImageEditorOpen event + /// Using the ImageEditor interface to register in the plugin menu + /// + private void ImageEditorOpened(object sender, ImageEditorOpenEventArgs eventArgs) { + ToolStripMenuItem toolStripMenuItem = eventArgs.ImageEditor.GetPluginMenuItem(); + ToolStripMenuItem item = new ToolStripMenuItem(); + item.Text = "Upload to Flickr"; + item.Tag = eventArgs.ImageEditor; + item.Click += new System.EventHandler(EditMenuClick); + toolStripMenuItem.DropDownItems.Add(item); + } + + /// + /// Implementation of the IGreenshotPlugin.Shutdown + /// + public void Shutdown() { + LOG.Debug("Shutdown of " + myAttributes.Name); + host.OnImageEditorOpen -= new OnImageEditorOpenHandler(ImageEditorOpened); + } + + /// + /// Implementation of the IPlugin.Configure + /// + public virtual void Configure() { + StringBuilder stringBuilder = new StringBuilder(); + stringBuilder.AppendLine("This plugin doesn't have a configuration screen."); + stringBuilder.AppendLine("Configuration is stored at: " + Path.Combine(host.ConfigurationPath, CONFIG_FILENAME)); + MessageBox.Show(stringBuilder.ToString()); + } + + /// + /// This method helps to resolve the MODI DLL files + /// + /// object which is starting the resolve + /// ResolveEventArgs describing the Assembly that needs to be found + /// + private Assembly MyAssemblyResolver(object sender, ResolveEventArgs args) { + string dllPath = Path.GetDirectoryName(myAttributes.DllFile); + string dllFilename = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll"; + LOG.Debug("Resolving: " + dllFilename); + if (dllFilename.StartsWith("Flickr")) { + return Assembly.LoadFile(Path.Combine(dllPath, dllFilename)); + } + return null; + } + + private void LoadConfig() { + string filename = Path.Combine(host.ConfigurationPath, CONFIG_FILENAME); + if (File.Exists(filename)) { + LOG.Debug("Loading configuration from: " + filename); + config = Properties.read(filename); + } + bool changed = false; + if (config == null) { + config = new Properties(); + changed = true; + } + if (changed) { + SaveConfig(); + } + + } + + private void SaveConfig() { + string filename = Path.Combine(host.ConfigurationPath, CONFIG_FILENAME); + LOG.Debug("Saving configuration to: " + filename); + config.write(filename, "# The configuration file for the Greenshot Flickr Plugin"); + } + + /// + /// This will be called when the menu item in the Editor is clicked + /// + public void EditMenuClick(object sender, EventArgs eventArgs) { + ToolStripMenuItem item = (ToolStripMenuItem)sender; + IImageEditor imageEditor = (IImageEditor)item.Tag; + FlickrUploadForm uploader = new FlickrUploadForm(); + DialogResult result = uploader.ShowDialog(); + if (result == DialogResult.OK) { + using (MemoryStream stream = new MemoryStream()) { + imageEditor.SaveToStream(stream, "PNG", 100); + stream.Seek(0, SeekOrigin.Begin); + try { + uploader.upload(stream); + MessageBox.Show(lang.GetString(LangKey.upload_success)); + } catch(Exception e) { + MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.Message); + } + } + } + } + } +} \ No newline at end of file diff --git a/GreenshotFlickrPlugin/Forms/FlickrUploadForm.Designer.cs b/GreenshotFlickrPlugin/Forms/FlickrUploadForm.Designer.cs new file mode 100644 index 000000000..45188d7aa --- /dev/null +++ b/GreenshotFlickrPlugin/Forms/FlickrUploadForm.Designer.cs @@ -0,0 +1,111 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2010 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 GreenshotFlickrPlugin { + partial class FlickrUploadForm { + /// + /// 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.button1 = new System.Windows.Forms.Button(); + this.button2 = new System.Windows.Forms.Button(); + this.cancelButton = new System.Windows.Forms.Button(); + this.okButton = new System.Windows.Forms.Button(); + this.SuspendLayout(); + // + // button1 + // + this.button1.Location = new System.Drawing.Point(13, 13); + this.button1.Name = "button1"; + this.button1.Size = new System.Drawing.Size(75, 23); + this.button1.TabIndex = 0; + this.button1.Text = "Auth"; + this.button1.UseVisualStyleBackColor = true; + this.button1.Click += new System.EventHandler(this.AuthMeButton_Click); + // + // button2 + // + this.button2.Location = new System.Drawing.Point(13, 43); + this.button2.Name = "button2"; + this.button2.Size = new System.Drawing.Size(75, 23); + this.button2.TabIndex = 1; + this.button2.Text = "Complete Auth"; + this.button2.UseVisualStyleBackColor = true; + this.button2.Click += new System.EventHandler(this.CompleteAuthButton_Click); + // + // cancelButton + // + this.cancelButton.Location = new System.Drawing.Point(197, 229); + this.cancelButton.Name = "cancelButton"; + this.cancelButton.Size = new System.Drawing.Size(75, 23); + this.cancelButton.TabIndex = 2; + this.cancelButton.Text = "Cancel"; + this.cancelButton.UseVisualStyleBackColor = true; + this.cancelButton.Click += new System.EventHandler(this.CancelButtonClick); + // + // okButton + // + this.okButton.Location = new System.Drawing.Point(116, 229); + this.okButton.Name = "okButton"; + this.okButton.Size = new System.Drawing.Size(75, 23); + this.okButton.TabIndex = 3; + this.okButton.Text = "OK"; + this.okButton.UseVisualStyleBackColor = true; + this.okButton.Click += new System.EventHandler(this.OkButtonClick); + // + // FlickrUploadForm + // + this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); + this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + this.ClientSize = new System.Drawing.Size(284, 264); + this.Controls.Add(this.okButton); + this.Controls.Add(this.cancelButton); + this.Controls.Add(this.button2); + this.Controls.Add(this.button1); + this.Name = "FlickrUploadForm"; + this.Text = "FlickrUploadForm"; + this.ResumeLayout(false); + } + private System.Windows.Forms.Button cancelButton; + private System.Windows.Forms.Button okButton; + private System.Windows.Forms.Button button2; + private System.Windows.Forms.Button button1; + } +} diff --git a/GreenshotFlickrPlugin/Forms/FlickrUploadForm.cs b/GreenshotFlickrPlugin/Forms/FlickrUploadForm.cs new file mode 100644 index 000000000..8c631c260 --- /dev/null +++ b/GreenshotFlickrPlugin/Forms/FlickrUploadForm.cs @@ -0,0 +1,99 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2010 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.Drawing; +using System.IO; +using System.Windows.Forms; + +using FlickrNet; + +namespace GreenshotFlickrPlugin { + /// + /// Description of FlickrUploadForm. + /// + public partial class FlickrUploadForm : Form { + // Store the Frob in a private variable + private string tempFrob; + private string ApiKey = "f967e5148945cb3c4e149cc5be97796a"; + private string SharedSecret = "4180a21a1d2f8666"; + private Flickr flickr; + + public FlickrUploadForm() { + // + // The InitializeComponent() call is required for Windows Forms designer support. + // + InitializeComponent(); + // Create Flickr instance + flickr = new Flickr(ApiKey, SharedSecret); + } + + protected void AuthMeButton_Click(object sender, EventArgs e) { + // Get Frob + tempFrob = flickr.AuthGetFrob(); + // Calculate the URL at Flickr to redirect the user to + string flickrUrl = flickr.AuthCalcUrl(tempFrob, AuthLevel.Write); + // The following line will load the URL in the users default browser. + System.Diagnostics.Process.Start(flickrUrl); + } + + protected void CompleteAuthButton_Click(object sender, EventArgs e) { + try { + // use the temporary Frob to get the authentication + Auth auth = flickr.AuthGetToken(tempFrob); + // Store this Token for later usage, + // or set your Flickr instance to use it. + Console.WriteLine("User authenticated successfully"); + Console.WriteLine("Authentication token is " + auth.Token); + flickr.AuthToken = auth.Token; + Console.WriteLine("User id is " + auth.User); + } catch(FlickrException ex) { + // If user did not authenticat your application + // then a FlickrException will be thrown. + Console.WriteLine("User did not authenticate you"); + Console.WriteLine(ex.ToString()); + } + } + + public void upload(Stream buffer) { + string file = "test.png"; + string title = "Test Photo"; + string description = "This is the description of the photo"; + string tags = "tag1,tag2,tag3"; + string photoId = flickr.UploadPicture(buffer, file, title, description, tags, false, false, false, ContentType.Screenshot, SafetyLevel.Restricted, HiddenFromSearch.Hidden); + + flickr.PhotosSetMeta(photoId, "New Title", "New Description"); + // Get list of users sets + PhotosetCollection sets = flickr.PhotosetsGetList(); + // Get the first set in the collection + Photoset set = sets[0]; + // Add the photo to that set + flickr.PhotosetsAddPhoto(set.PhotosetId, photoId); + } + + void OkButtonClick(object sender, EventArgs e) { + DialogResult = DialogResult.OK; + } + + void CancelButtonClick(object sender, EventArgs e) { + DialogResult = DialogResult.Cancel; + } + } +} diff --git a/GreenshotFlickrPlugin/Forms/FlickrUploadForm.resx b/GreenshotFlickrPlugin/Forms/FlickrUploadForm.resx new file mode 100644 index 000000000..5ea0895e3 --- /dev/null +++ b/GreenshotFlickrPlugin/Forms/FlickrUploadForm.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file diff --git a/GreenshotFlickrPlugin/GreenshotFlickrPlugin.csproj b/GreenshotFlickrPlugin/GreenshotFlickrPlugin.csproj new file mode 100644 index 000000000..1056cba5f --- /dev/null +++ b/GreenshotFlickrPlugin/GreenshotFlickrPlugin.csproj @@ -0,0 +1,94 @@ + + + {56828D7F-F227-41EC-8873-CC32A23A1783} + Debug + x86 + Library + GreenshotFlickrPlugin + GreenshotFlickrPlugin + v2.0 + Properties + C:\Users\Robin\AppData\Roaming\ICSharpCode/SharpDevelop3.0\Settings.SourceAnalysis + False + False + 4 + false + OnBuildSuccess + + + x86 + False + Auto + 4194304 + 4096 + + + bin\Debug\ + true + Full + False + True + DEBUG;TRACE + + + bin\Release\ + False + None + True + False + TRACE + + + + + Lib\FlickrNet.dll + + + ..\Greenshot\Lib\log4net.dll + + + + + + + + + + FlickrUploadForm.cs + + + + + + Always + + + Always + + + Always + + + + + FlickrUploadForm.cs + + + + + + + + {5B924697-4DCD-4F98-85F1-105CB84B7341} + GreenshotPlugin + + + + "$(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)bin\$(Configuration)\FlickrNet.dll" "$(SolutionDir)bin\$(Configuration)\Plugins\$(ProjectName)\*" +mkdir "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)" +copy "$(ProjectDir)bin\$(Configuration)\Languages\*.xml" "$(SolutionDir)bin\$(Configuration)\Languages\Plugins\$(ProjectName)\" + + \ No newline at end of file diff --git a/GreenshotFlickrPlugin/Language.cs b/GreenshotFlickrPlugin/Language.cs new file mode 100644 index 000000000..a8810c987 --- /dev/null +++ b/GreenshotFlickrPlugin/Language.cs @@ -0,0 +1,47 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2010 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.Diagnostics; +using System.Globalization; +using System.Resources; +using System.Threading; + +using GreenshotPlugin.Core; + +namespace GreenshotFlickrPlugin { + /// + /// Wrapper for the language container for the Jira plugin. + /// + public class Language : LanguageContainer, ILanguage { + private static ILanguage uniqueInstance; + private const string LANGUAGE_FILENAME_PATTERN = @"language_flickrplugin-*.xml"; + + public static ILanguage GetInstance() { + if(uniqueInstance == null) { + uniqueInstance = new LanguageContainer(); + uniqueInstance.LanguageFilePattern = LANGUAGE_FILENAME_PATTERN; + uniqueInstance.Load(); + uniqueInstance.SetLanguage(Thread.CurrentThread.CurrentUICulture.Name); + } + return uniqueInstance; + } + } +} diff --git a/GreenshotFlickrPlugin/LanguageKeys.cs b/GreenshotFlickrPlugin/LanguageKeys.cs new file mode 100644 index 000000000..fbd5539e2 --- /dev/null +++ b/GreenshotFlickrPlugin/LanguageKeys.cs @@ -0,0 +1,29 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2010 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 GreenshotFlickrPlugin { + public enum LangKey { + login_error, + upload_success, + upload_failure + } +} diff --git a/GreenshotFlickrPlugin/Languages/language_flickrplugin-de-DE.xml b/GreenshotFlickrPlugin/Languages/language_flickrplugin-de-DE.xml new file mode 100644 index 000000000..2b7b29274 --- /dev/null +++ b/GreenshotFlickrPlugin/Languages/language_flickrplugin-de-DE.xml @@ -0,0 +1,14 @@ + + + + + Es gab ein Problem während dem Login: {0} + + + Ein erfolg beim Hochladen zum Flickr! + + + Es gab einen Fehler beim Hochladen zum Flickr: + + + \ No newline at end of file diff --git a/GreenshotFlickrPlugin/Languages/language_flickrplugin-en-US.xml b/GreenshotFlickrPlugin/Languages/language_flickrplugin-en-US.xml new file mode 100644 index 000000000..69e2f8065 --- /dev/null +++ b/GreenshotFlickrPlugin/Languages/language_flickrplugin-en-US.xml @@ -0,0 +1,14 @@ + + + + + There was a problem during the login: {0} + + + Successfully uploaded image to Flickr! + + + An error occured while uploading to Flickr: + + + \ No newline at end of file diff --git a/GreenshotFlickrPlugin/Languages/language_flickrplugin-nl-NL.xml b/GreenshotFlickrPlugin/Languages/language_flickrplugin-nl-NL.xml new file mode 100644 index 000000000..89b355889 --- /dev/null +++ b/GreenshotFlickrPlugin/Languages/language_flickrplugin-nl-NL.xml @@ -0,0 +1,14 @@ + + + + + Tijden de login is een fout opgetreden: {0} + + + Het uploaden naar Flickr is geslaagt! + + + Tijdens het uploaden naar Flickr is een fout opgetreden: + + + \ No newline at end of file diff --git a/GreenshotFlickrPlugin/Properties/AssemblyInfo.cs.template b/GreenshotFlickrPlugin/Properties/AssemblyInfo.cs.template new file mode 100644 index 000000000..23a849942 --- /dev/null +++ b/GreenshotFlickrPlugin/Properties/AssemblyInfo.cs.template @@ -0,0 +1,54 @@ +/* + * Greenshot - a free and open source screenshot tool + * Copyright (C) 2007-2010 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("GreenshotFlickrPlugin")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("GreenshotFlickrPlugin")] +[assembly: AssemblyCopyright("Copyright 2010")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] +// The PluginAttribute describes the "entryType" and if the plugin is configurable +[assembly: PluginAttribute("GreenshotFlickrPlugin.FlickrPlugin", 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.0.$WCREV$")]