コード例 #1
0
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality);

            try {
                string url = null;
                new PleaseWaitForm().ShowAndWait("Picasa plug-in", Language.GetString("picasa", LangKey.communication_wait),
                                                 delegate() {
                    string filename    = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                    string contentType = "image/" + config.UploadFormat.ToString();
                    url = PicasaUtils.UploadToPicasa(surfaceToUpload, outputSettings, captureDetails.Title, filename);
                }
                                                 );
                uploadUrl = url;

                if (uploadUrl != null && config.AfterUploadLinkToClipBoard)
                {
                    ClipboardHelper.SetClipboardData(uploadUrl);
                }
                return(true);
            } catch (Exception e) {
                MessageBox.Show(Language.GetString("picasa", LangKey.upload_failure) + " " + e.ToString());
            }
            uploadUrl = null;
            return(false);
        }
コード例 #2
0
        public SettingsForm(PicasaConfiguration config)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            InitializeTexts();

            combobox_uploadimageformat.Items.Clear();
            foreach (OutputFormat format in Enum.GetValues(typeof(OutputFormat)))
            {
                combobox_uploadimageformat.Items.Add(format.ToString());
            }

            comboBox_DefaultSize.Items.Clear();
            foreach (PictureDisplaySize displaySize in Enum.GetValues(typeof(PictureDisplaySize)))
            {
                comboBox_DefaultSize.Items.Add(displaySize.ToString());
            }

            PicasaUtils.LoadHistory();

            if (config.runtimePicasaHistory.Count > 0)
            {
                historyButton.Enabled = true;
            }
            else
            {
                historyButton.Enabled = false;
            }
        }
コード例 #3
0
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality);

            try {
                string url = null;
                new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("picasa", LangKey.communication_wait),
                                                 delegate
                {
                    string filename = Path.GetFileName(FilenameHelper.GetFilename(_config.UploadFormat, captureDetails));
                    url             = PicasaUtils.UploadToPicasa(surfaceToUpload, outputSettings, captureDetails.Title, filename);
                }
                                                 );
                uploadUrl = url;

                if (uploadUrl != null && _config.AfterUploadLinkToClipBoard)
                {
                    ClipboardHelper.SetClipboardData(uploadUrl);
                }
                return(true);
            } catch (Exception e) {
                Log.Error("Error uploading.", e);
                MessageBox.Show(Language.GetString("picasa", LangKey.upload_failure) + " " + e.Message);
            }
            uploadUrl = null;
            return(false);
        }
コード例 #4
0
        public bool Upload(ICaptureDetails captureDetails, Image image)
        {
            using (MemoryStream stream = new MemoryStream())
            {
                BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(Attributes.Name, lang.GetString(LangKey.communication_wait));

                host.SaveToStream(image, stream, config.UploadFormat, config.UploadJpegQuality);
                byte[] buffer = stream.GetBuffer();

                try
                {
                    string     filename    = Path.GetFileName(host.GetFilename(config.UploadFormat, captureDetails));
                    string     contentType = "image/" + config.UploadFormat.ToString();
                    PicasaInfo picasaInfo  = PicasaUtils.UploadToPicasa(buffer, captureDetails.DateTime.ToString(), filename, contentType);
                    if (config.PicasaUploadHistory == null)
                    {
                        config.PicasaUploadHistory = new Dictionary <string, string>();
                    }

                    if (picasaInfo.ID != null)
                    {
                        LOG.InfoFormat("Storing Picasa upload for id {0}", picasaInfo.ID);

                        config.PicasaUploadHistory.Add(picasaInfo.ID, picasaInfo.ID);
                        config.runtimePicasaHistory.Add(picasaInfo.ID, picasaInfo);
                    }

                    picasaInfo.Image = PicasaUtils.CreateThumbnail(image, 90, 90);
                    // Make sure the configuration is save, so we don't lose the deleteHash
                    IniConfig.Save();
                    // Make sure the history is loaded, will be done only once
                    PicasaUtils.LoadHistory();

                    // Show
                    if (config.AfterUploadOpenHistory)
                    {
                        PicasaHistory.ShowHistory();
                    }

                    if (config.AfterUploadLinkToClipBoard)
                    {
                        Clipboard.SetText(picasaInfo.LinkUrl(config.PictureDisplaySize));
                    }
                    return(true);
                }
                catch (Google.GData.Client.InvalidCredentialsException eLo)
                {
                    MessageBox.Show(lang.GetString(LangKey.InvalidCredentials));
                }
                catch (Exception e)
                {
                    MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.ToString());
                }
                finally
                {
                    backgroundForm.CloseDialog();
                }
            }
            return(false);
        }
コード例 #5
0
        public static void LoadHistory()
        {
            if (config.runtimePicasaHistory == null)
            {
                return;
            }
            if (config.PicasaUploadHistory == null)
            {
                return;
            }

            if (config.runtimePicasaHistory.Count == config.PicasaUploadHistory.Count)
            {
                return;
            }
            // Load the Picasa history
            List <string> hashes = new List <string>();

            foreach (string hash in config.PicasaUploadHistory.Keys)
            {
                hashes.Add(hash);
            }

            bool saveNeeded = false;

            foreach (string hash in hashes)
            {
                if (config.runtimePicasaHistory.ContainsKey(hash))
                {
                    // Already loaded
                    continue;
                }
                try {
                    PicasaInfo imgurInfo = PicasaUtils.RetrievePicasaInfo(hash);
                    if (imgurInfo != null)
                    {
                        PicasaUtils.RetrievePicasaThumbnail(imgurInfo);
                        config.runtimePicasaHistory.Add(hash, imgurInfo);
                    }
                    else
                    {
                        LOG.DebugFormat("Deleting not found Picasa {0} from config.", hash);
                        config.PicasaUploadHistory.Remove(hash);
                        saveNeeded = true;
                    }
                } catch (Exception e) {
                    LOG.Error("Problem loading Picasa history for hash " + hash, e);
                }
            }
            if (saveNeeded)
            {
                // Save needed changes
                IniConfig.Save();
            }
        }
コード例 #6
0
 public void HistoryMenuClick(object sender, EventArgs eventArgs)
 {
     PicasaUtils.LoadHistory();
     PicasaHistory.ShowHistory();
 }