예제 #1
0
        private void DeleteButtonClick(object sender, EventArgs e)
        {
            if (listview_imgur_uploads.SelectedItems.Count > 0)
            {
                for (int i = 0; i < listview_imgur_uploads.SelectedItems.Count; i++)
                {
                    ImgurInfo    imgurInfo = (ImgurInfo)listview_imgur_uploads.SelectedItems[i].Tag;
                    DialogResult result    = MessageBox.Show(Language.GetFormattedString("imgur", LangKey.delete_question, imgurInfo.Title), Language.GetFormattedString("imgur", LangKey.delete_title, imgurInfo.Hash), MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                    if (result != DialogResult.Yes)
                    {
                        continue;
                    }
                    // Should fix Bug #3378699
                    pictureBox1.Image = pictureBox1.ErrorImage;
                    try {
                        new PleaseWaitForm().ShowAndWait(ImgurPlugin.Attributes.Name, Language.GetString("imgur", LangKey.communication_wait),
                                                         delegate {
                            ImgurUtils.DeleteImgurImage(imgurInfo);
                        }
                                                         );
                    } catch (Exception ex) {
                        Log.Warn("Problem communicating with Imgur: ", ex);
                    }

                    imgurInfo.Dispose();
                }
            }
            Redraw();
        }
예제 #2
0
        /// <summary>
        /// Upload the capture to imgur
        /// </summary>
        /// <param name="captureDetails">ICaptureDetails</param>
        /// <param name="surfaceToUpload">ISurface</param>
        /// <param name="uploadUrl">out string for the url</param>
        /// <returns>true if the upload succeeded</returns>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl)
        {
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(_config.UploadFormat, _config.UploadJpegQuality, _config.UploadReduceColors);

            try {
                string    filename  = Path.GetFileName(FilenameHelper.GetFilenameFromPattern(_config.FilenamePattern, _config.UploadFormat, captureDetails));
                ImgurInfo imgurInfo = null;

                // Run upload in the background
                new PleaseWaitForm().ShowAndWait("Imgur plug-in", Language.GetString("imgur", LangKey.communication_wait),
                                                 delegate
                {
                    imgurInfo = ImgurUtils.UploadToImgur(surfaceToUpload, outputSettings, captureDetails.Title, filename);
                    if (imgurInfo != null && _config.AnonymousAccess)
                    {
                        Log.InfoFormat("Storing imgur upload for hash {0} and delete hash {1}", imgurInfo.Hash, imgurInfo.DeleteHash);
                        _config.ImgurUploadHistory.Add(imgurInfo.Hash, imgurInfo.DeleteHash);
                        _config.runtimeImgurHistory.Add(imgurInfo.Hash, imgurInfo);
                        CheckHistory();
                    }
                }
                                                 );

                if (imgurInfo != null)
                {
                    // TODO: Optimize a second call for export
                    using (Image tmpImage = surfaceToUpload.GetImageForExport()) {
                        imgurInfo.Image = ImageHelper.CreateThumbnail(tmpImage, 90, 90);
                    }
                    IniConfig.Save();

                    if (_config.UsePageLink)
                    {
                        uploadUrl = imgurInfo.Page;
                    }
                    else
                    {
                        uploadUrl = imgurInfo.Original;
                    }
                    if (!string.IsNullOrEmpty(uploadUrl) && _config.CopyLinkToClipboard)
                    {
                        try
                        {
                            ClipboardHelper.SetClipboardData(uploadUrl);
                        }
                        catch (Exception ex)
                        {
                            Log.Error("Can't write to clipboard: ", ex);
                            uploadUrl = null;
                        }
                    }
                    return(true);
                }
            } catch (Exception e) {
                Log.Error("Error uploading.", e);
                MessageBox.Show(Language.GetString("imgur", LangKey.upload_failure) + " " + e.Message);
            }
            uploadUrl = null;
            return(false);
        }
예제 #3
0
        public SettingsForm()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            CancelButton = buttonCancel;
            AcceptButton = buttonOK;

            historyButton.Enabled = ImgurUtils.IsHistoryLoadingNeeded();
        }
예제 #4
0
 public static void ShowHistory()
 {
     // Make sure the history is loaded, will be done only once
     ImgurUtils.LoadHistory();
     if (instance == null)
     {
         instance = new ImgurHistory();
     }
     instance.Show();
     instance.redraw();
 }
예제 #5
0
        public SettingsForm(ImgurConfiguration config)
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            CancelButton = buttonCancel;
            AcceptButton = buttonOK;

            ImgurUtils.LoadHistory();

            historyButton.Enabled = config.runtimeImgurHistory.Count > 0;
        }
예제 #6
0
 private void CheckHistory()
 {
     try {
         ImgurUtils.LoadHistory();
         _host.GreenshotForm.BeginInvoke((MethodInvoker) delegate {
             if (_config.ImgurUploadHistory.Count > 0)
             {
                 _historyMenuItem.Enabled = true;
             }
             else
             {
                 _historyMenuItem.Enabled = false;
             }
         });
     } catch (Exception ex) {
         Log.Error("Error loading history", ex);
     }
 }
예제 #7
0
        public SettingsForm(ImgurConfiguration config) : base()
        {
            //
            // The InitializeComponent() call is required for Windows Forms designer support.
            //
            InitializeComponent();
            CancelButton = buttonCancel;
            AcceptButton = buttonOK;
            this.Icon    = GreenshotPlugin.Core.GreenshotResources.getGreenshotIcon();

            ImgurUtils.LoadHistory();

            if (config.runtimeImgurHistory.Count > 0)
            {
                historyButton.Enabled = true;
            }
            else
            {
                historyButton.Enabled = false;
            }
        }
예제 #8
0
        public static void ShowHistory()
        {
            lock (Lock)
            {
                if (ImgurUtils.IsHistoryLoadingNeeded())
                {
                    // Run upload in the background
                    new PleaseWaitForm().ShowAndWait("Imgur " + Language.GetString("imgur", LangKey.history), Language.GetString("imgur", LangKey.communication_wait),
                                                     ImgurUtils.LoadHistory
                                                     );
                }

                // Make sure the history is loaded, will be done only once
                if (_instance == null)
                {
                    _instance = new ImgurHistory();
                }
                if (!_instance.Visible)
                {
                    _instance.Show();
                }
                _instance.Redraw();
            }
        }
예제 #9
0
        public static void LoadHistory()
        {
            if (config.runtimeImgurHistory.Count == config.ImgurUploadHistory.Count)
            {
                return;
            }
            // Load the ImUr history
            List <string> hashes = new List <string>();

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

            bool saveNeeded = false;

            foreach (string hash in hashes)
            {
                if (config.runtimeImgurHistory.ContainsKey(hash))
                {
                    // Already loaded
                    continue;
                }
                try {
                    ImgurInfo imgurInfo = ImgurUtils.RetrieveImgurInfo(hash, config.ImgurUploadHistory[hash]);
                    if (imgurInfo != null)
                    {
                        ImgurUtils.RetrieveImgurThumbnail(imgurInfo);
                        config.runtimeImgurHistory.Add(hash, imgurInfo);
                    }
                    else
                    {
                        LOG.DebugFormat("Deleting not found ImgUr {0} from config.", hash);
                        config.ImgurUploadHistory.Remove(hash);
                        saveNeeded = true;
                    }
                } catch (WebException wE) {
                    bool redirected = false;
                    if (wE.Status == WebExceptionStatus.ProtocolError)
                    {
                        HttpWebResponse response = ((HttpWebResponse)wE.Response);
                        // Image no longer available
                        if (response.StatusCode == HttpStatusCode.Redirect)
                        {
                            LOG.InfoFormat("ImgUr image for hash {0} is no longer available", hash);
                            config.ImgurUploadHistory.Remove(hash);
                            redirected = true;
                        }
                    }
                    if (!redirected)
                    {
                        LOG.Error("Problem loading ImgUr history for hash " + hash, wE);
                    }
                } catch (Exception e) {
                    LOG.Error("Problem loading ImgUr history for hash " + hash, e);
                }
            }
            if (saveNeeded)
            {
                // Save needed changes
                IniConfig.Save();
            }
        }