Example #1
0
        public SettingsForm(DropboxConfiguration 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());
            }

            DropboxUtils.LoadHistory();

            if (config.runtimeDropboxHistory.Count > 0)
            {
                historyButton.Enabled = true;
            }
            else
            {
                historyButton.Enabled = false;
            }
        }
Example #2
0
        /// <summary>
        /// This will be called when the menu item in the Editor is clicked
        /// </summary>
        public bool Upload(ICaptureDetails captureDetails, ISurface surfaceToUpload, out string uploadUrl)
        {
            uploadUrl = null;
            SurfaceOutputSettings outputSettings = new SurfaceOutputSettings(config.UploadFormat, config.UploadJpegQuality, false);

            try {
                string dropboxUrl = null;
                new PleaseWaitForm().ShowAndWait(Attributes.Name, Language.GetString("dropbox", LangKey.communication_wait),
                                                 delegate() {
                    string filename = Path.GetFileName(FilenameHelper.GetFilename(config.UploadFormat, captureDetails));
                    dropboxUrl      = DropboxUtils.UploadToDropbox(surfaceToUpload, outputSettings, filename);
                }
                                                 );
                if (dropboxUrl == null)
                {
                    return(false);
                }
                uploadUrl = dropboxUrl;
                return(true);
            } catch (Exception e) {
                LOG.Error(e);
                MessageBox.Show(Language.GetString("dropbox", LangKey.upload_failure) + " " + e.Message);
                return(false);
            }
        }
        /// <summary>
        /// A form for token
        /// </summary>
        /// <returns>bool true if OK was pressed, false if cancel</returns>
        public bool ShowConfigDialog()
        {
            SettingsForm settingsForm;
            ILanguage    lang = Language.GetInstance();

            BackgroundForm backgroundForm = BackgroundForm.ShowAndWait(DropboxPlugin.Attributes.Name, lang.GetString(LangKey.communication_wait));

            try {
                settingsForm = new SettingsForm(this);
            } finally {
                backgroundForm.CloseDialog();
            }
            settingsForm.AuthToken                  = this.DropboxAccessToken;
            settingsForm.UploadFormat               = this.UploadFormat.ToString();
            settingsForm.AfterUploadOpenHistory     = this.AfterUploadOpenHistory;
            settingsForm.AfterUploadLinkToClipBoard = this.AfterUploadLinkToClipBoard;
            DialogResult result = settingsForm.ShowDialog();

            if (result == DialogResult.OK)
            {
                this.DropboxAccessToken = settingsForm.AuthToken;
                this.UploadFormat       = (OutputFormat)Enum.Parse(typeof(OutputFormat), settingsForm.UploadFormat.ToLower());

                this.AfterUploadOpenHistory     = settingsForm.AfterUploadOpenHistory;
                this.AfterUploadLinkToClipBoard = settingsForm.AfterUploadLinkToClipBoard;
                IniConfig.Save();

                // Save DropboxAccessToken from file
                DropboxUtils.SaveAccessToken();

                return(true);
            }
            return(false);
        }
        public static void LoadHistory()
        {
            if (config.runtimeDropboxHistory == null)
            {
                return;
            }
            if (config.DropboxUploadHistory == null)
            {
                return;
            }

            if (config.runtimeDropboxHistory.Count == config.DropboxUploadHistory.Count)
            {
                return;
            }
            // Load the Dropbox history
            List <string> hashes = new List <string>();

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

            bool saveNeeded = false;

            foreach (string hash in hashes)
            {
                if (config.runtimeDropboxHistory.ContainsKey(hash))
                {
                    // Already loaded
                    continue;
                }
                try {
                    DropboxInfo imgurInfo = DropboxUtils.RetrieveDropboxInfo(hash);
                    if (imgurInfo != null)
                    {
                        DropboxUtils.RetrieveDropboxThumbnail(imgurInfo);
                        config.runtimeDropboxHistory.Add(hash, imgurInfo);
                    }
                    else
                    {
                        LOG.DebugFormat("Deleting not found Dropbox {0} from config.", hash);
                        config.DropboxUploadHistory.Remove(hash);
                        saveNeeded = true;
                    }
                } catch (Exception e) {
                    LOG.Error("Problem loading Dropbox history for hash " + hash, e);
                }
            }
            if (saveNeeded)
            {
                // Save needed changes
                IniConfig.Save();
            }
        }
Example #5
0
        /// <summary>
        /// Implementation of the IGreenshotPlugin.Initialize
        /// </summary>
        /// <param name="host">Use the IGreenshotPluginHost interface to register events</param>
        /// <param name="pluginAttribute">My own attributes</param>
        public virtual bool Initialize(IGreenshotHost pluginHost, PluginAttribute myAttributes)
        {
            this.host  = (IGreenshotHost)pluginHost;
            Attributes = myAttributes;

            // Register configuration (don't need the configuration itself)
            config    = IniConfig.GetIniSection <DropboxConfiguration>();
            resources = new ComponentResourceManager(typeof(DropboxPlugin));

            // load DropboxAccessToken from file
            DropboxUtils.LoadAccessToken();

            ToolStripMenuItem itemPlugInRoot = new ToolStripMenuItem();

            itemPlugInRoot.Text  = "Dropbox";
            itemPlugInRoot.Tag   = host;
            itemPlugInRoot.Image = (Image)resources.GetObject("Dropbox");

            ToolStripMenuItem itemPlugInHistory = new ToolStripMenuItem();

            itemPlugInHistory.Text   = lang.GetString(LangKey.History);
            itemPlugInHistory.Tag    = host;
            itemPlugInHistory.Click += new System.EventHandler(HistoryMenuClick);
            itemPlugInRoot.DropDownItems.Add(itemPlugInHistory);

            ToolStripMenuItem itemPlugInConfig = new ToolStripMenuItem();

            itemPlugInConfig.Text   = lang.GetString(LangKey.Configure);
            itemPlugInConfig.Tag    = host;
            itemPlugInConfig.Click += new System.EventHandler(ConfigMenuClick);
            itemPlugInRoot.DropDownItems.Add(itemPlugInConfig);

            PluginUtils.AddToContextMenu(host, itemPlugInRoot);

            return(true);
        }
Example #6
0
        /// <summary>
        /// This will be called when the menu item in the Editor is clicked
        /// </summary>
        public bool Upload(ICaptureDetails captureDetails, Image image)
        {
            if (config.DropboxAccessToken == null)
            {
                MessageBox.Show(lang.GetString(LangKey.TokenNotSet), string.Empty, MessageBoxButtons.OK, MessageBoxIcon.Information);
                return(false);
            }
            else
            {
                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));
                        DropboxInfo DropboxInfo = DropboxUtils.UploadToDropbox(buffer, captureDetails.Title, filename);

                        if (config.DropboxUploadHistory == null)
                        {
                            config.DropboxUploadHistory = new Dictionary <string, string>();
                        }

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

                            config.DropboxUploadHistory.Add(DropboxInfo.ID, DropboxInfo.ID);
                            config.runtimeDropboxHistory.Add(DropboxInfo.ID, DropboxInfo);
                        }

                        DropboxInfo.Image = DropboxUtils.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
                        DropboxUtils.LoadHistory();

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

                        if (config.AfterUploadLinkToClipBoard)
                        {
                            Clipboard.SetText(DropboxInfo.WebUrl);
                        }
                        return(true);
                    }
                    catch (Exception e)
                    {
                        MessageBox.Show(lang.GetString(LangKey.upload_failure) + " " + e.ToString());
                        return(false);
                    }
                    finally
                    {
                        backgroundForm.CloseDialog();
                    }
                }
            }
        }
Example #7
0
 public void HistoryMenuClick(object sender, EventArgs eventArgs)
 {
     DropboxUtils.LoadHistory();
     DropboxHistory.ShowHistory();
 }