mirror of
https://github.com/greenshot/greenshot
synced 2025-07-16 10:03:44 -07:00
Made it work again
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@710 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
8cc84eaf1b
commit
02bd63be60
7 changed files with 237 additions and 217 deletions
|
@ -28,6 +28,7 @@ using System.Runtime.Serialization.Formatters.Binary;
|
|||
using System.Text;
|
||||
using System.Windows.Forms;
|
||||
|
||||
using FlickrNet;
|
||||
using Greenshot.Capturing;
|
||||
using Greenshot.Forms;
|
||||
using Greenshot.Plugin;
|
||||
|
@ -41,11 +42,14 @@ namespace GreenshotFlickrPlugin {
|
|||
public class FlickrPlugin : IGreenshotPlugin {
|
||||
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(FlickrPlugin));
|
||||
private const string CONFIG_FILENAME = "flickr-config.properties";
|
||||
private const string AUTHENTICATION_TOKEN_PROPERTY = "authentication.token";
|
||||
private const string ApiKey = "f967e5148945cb3c4e149cc5be97796a";
|
||||
private const string SharedSecret = "4180a21a1d2f8666";
|
||||
private ILanguage lang = Language.GetInstance();
|
||||
private IGreenshotPluginHost host;
|
||||
private ICaptureHost captureHost = null;
|
||||
private PluginAttribute myAttributes;
|
||||
private Properties config = new Properties();
|
||||
private Properties config = null;
|
||||
|
||||
public FlickrPlugin() { }
|
||||
|
||||
|
@ -110,7 +114,7 @@ namespace GreenshotFlickrPlugin {
|
|||
string dllPath = Path.GetDirectoryName(myAttributes.DllFile);
|
||||
string dllFilename = args.Name.Substring(0, args.Name.IndexOf(",")) + ".dll";
|
||||
LOG.Debug("Resolving: " + dllFilename);
|
||||
if (dllFilename.StartsWith("Flickr")) {
|
||||
if (dllFilename.ToLower().StartsWith("flickr")) {
|
||||
return Assembly.LoadFile(Path.Combine(dllPath, dllFilename));
|
||||
}
|
||||
return null;
|
||||
|
@ -119,18 +123,13 @@ namespace GreenshotFlickrPlugin {
|
|||
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);
|
||||
} else {
|
||||
LOG.Debug("No flickr configuration found at: " + filename);
|
||||
}
|
||||
bool changed = false;
|
||||
if (config == null) {
|
||||
config = new Properties();
|
||||
changed = true;
|
||||
}
|
||||
if (changed) {
|
||||
SaveConfig();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void SaveConfig() {
|
||||
|
@ -145,14 +144,74 @@ namespace GreenshotFlickrPlugin {
|
|||
public void EditMenuClick(object sender, EventArgs eventArgs) {
|
||||
ToolStripMenuItem item = (ToolStripMenuItem)sender;
|
||||
IImageEditor imageEditor = (IImageEditor)item.Tag;
|
||||
bool authentication = false;
|
||||
|
||||
Flickr flickr = new Flickr(ApiKey, SharedSecret);
|
||||
if(config.GetProperty(AUTHENTICATION_TOKEN_PROPERTY) == null) {
|
||||
string frob = flickr.AuthGetFrob();
|
||||
// Calculate the URL at Flickr to redirect the user to
|
||||
string flickrUrl = flickr.AuthCalcUrl(frob, AuthLevel.Write);
|
||||
FlickrAuthenticationForm authForm = new FlickrAuthenticationForm(flickrUrl);
|
||||
DialogResult authFormResult = authForm.ShowDialog();
|
||||
if (authFormResult == DialogResult.OK) {
|
||||
try {
|
||||
// use the temporary Frob to get the authentication
|
||||
Auth auth = flickr.AuthGetToken(frob);
|
||||
// Store this Token for later usage,
|
||||
// or set your Flickr instance to use it.
|
||||
LOG.Debug("User authenticated successfully");
|
||||
LOG.Debug("Authentication token is " + auth.Token);
|
||||
LOG.Debug("User id is " + auth.User.UserId);
|
||||
LOG.Debug("User name is " + auth.User.UserName);
|
||||
LOG.Debug("User fullname is " + auth.User.FullName);
|
||||
config.AddProperty(AUTHENTICATION_TOKEN_PROPERTY, auth.Token);
|
||||
SaveConfig();
|
||||
authentication = true;
|
||||
} catch (FlickrException ex) {
|
||||
// If user did not authenticat your application
|
||||
// then a FlickrException will be thrown.
|
||||
LOG.Debug("User did not authenticate you", ex);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Token is there
|
||||
authentication = true;
|
||||
}
|
||||
if (!authentication) {
|
||||
MessageBox.Show("No Authentication made!");
|
||||
return;
|
||||
}
|
||||
flickr.AuthToken = config.GetProperty(AUTHENTICATION_TOKEN_PROPERTY);
|
||||
FlickrUploadForm uploader = new FlickrUploadForm();
|
||||
DialogResult result = uploader.ShowDialog();
|
||||
if (result == DialogResult.OK) {
|
||||
DialogResult uploaderResult = uploader.ShowDialog();
|
||||
if (uploaderResult == DialogResult.OK) {
|
||||
using (MemoryStream stream = new MemoryStream()) {
|
||||
imageEditor.SaveToStream(stream, "PNG", 100);
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
try {
|
||||
uploader.upload(stream);
|
||||
string file = "test.png";
|
||||
string title = "Test Photo";
|
||||
string description = "This is the description of the photo";
|
||||
string tags = "greenshot,screenshot";
|
||||
string photoId = flickr.UploadPicture(stream, file, title, description, tags, false, false, false, ContentType.Screenshot, SafetyLevel.Restricted, HiddenFromSearch.Hidden);
|
||||
|
||||
flickr.PhotosSetMeta(photoId, "Greenshot screenshot", "This is a greenshot screenshot!");
|
||||
// // Get list of users sets
|
||||
// PhotosetCollection sets = flickr.PhotosetsGetList();
|
||||
// string photosetId = null;
|
||||
// if (sets.Count == 0) {
|
||||
// LOG.Debug("Not photosets found, creating");
|
||||
// Photoset photoset = flickr.PhotosetsCreate("Greenshot", "Greenshot screenshots", photoId);
|
||||
// LOG.Debug("Created photoset with description: " + photoset.Description);
|
||||
// LOG.Debug("Created photoset with id: " + photoset.PhotosetId);
|
||||
// photosetId = photoset.PhotosetId;
|
||||
// } else {
|
||||
// // Get the first set in the collection
|
||||
// photosetId = sets[0].PhotosetId;
|
||||
// }
|
||||
//
|
||||
// // Add the photo to that set
|
||||
// flickr.PhotosetsAddPhoto(photosetId, photoId);
|
||||
MessageBox.Show(lang.GetString(LangKey.upload_success));
|
||||
} catch(Exception e) {
|
||||
LOG.Error("Problem uploading", e);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue