Exemplo n.º 1
0
 public Form1()
 {
     InitializeComponent();
     configurationManager = new ConfigurationManager();
     destinationValidator = new DestinationValidator();
     hotkeyMonitor        = new HotkeyMonitor();
     clipboardMonitor     = new ClipboardMonitor();
     // load config
     try
     {
         configurationManager.Load();
     }
     catch (Exception exc)
     {
         SimpleLogger.Log("ERROR: can't read configuration, exc=" + exc);
         MessageBox.Show(exc.ToString(), "Can't load configuration", MessageBoxButtons.OK, MessageBoxIcon.Error);
         Application.Exit();
     }
     // regexp
     try
     {
         destinationValidator.Configure(configurationManager.Configuration());
     }
     catch (Exception exc)
     {
         destinationValidator.Configure(null);
         Log("WARN: can't initialize validator: " + exc);
     }
     // hotkeys
     hotkeyMonitor.KeyPressed += new EventHandler <HTDialer.Utils.HotkeyMonitor.KeyPressedEventArgs>(hook_hotkey_pressed);
     try
     {
         hotkeyMonitor.SetKey(configurationManager.Configuration().Hotkey);
     }
     catch (Exception exc)
     {
         Log("WARN: can't install hotkey, exc=" + exc);
     }
     // clipboard
     clipboardMonitor.ClipboardEvent += new EventHandler <HTDialer.Utils.ClipboardMonitor.ClipboardEventArgs>(hook_clipboard_event);
     // update UI
     string[] s = String.IsNullOrEmpty(configurationManager.Configuration().Credentials) ? null : configurationManager.Configuration().Credentials.Split(':');
     this.fieldHotkey.Text           = configurationManager.Configuration().Hotkey;
     this.fieldHttpUsername.Text     = (s != null ? s[0] : null);
     this.fieldHttpPassword.Text     = (s != null ? s[1] : null);
     this.fieldUrl.Text              = configurationManager.Configuration().Url;
     this.fieldRegex.Text            = configurationManager.Configuration().Regex;
     this.fieldCutchars.Text         = configurationManager.Configuration().CutChars;
     this.fieldShowInTaskbar.Checked = configurationManager.Configuration().ShowInTaskbar;
     // do hide
     this.ShowInTaskbar = configurationManager.Configuration().ShowInTaskbar;
     this.WindowState   = FormWindowState.Minimized;
 }
Exemplo n.º 2
0
        private void buttonApply_Click(object sender, EventArgs e)
        {
            string hkey = fieldHotkey.Text;
            string url  = fieldUrl.Text;

            //
            if (!hotkeyMonitor.IsValid(hkey))
            {
                MessageBox.Show("Invalid hotkey, please redefine it", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (String.IsNullOrEmpty(url))
            {
                MessageBox.Show("You must define URL", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            //
            configurationManager.Configuration().Regex         = fieldRegex.Text;
            configurationManager.Configuration().CutChars      = fieldCutchars.Text;
            configurationManager.Configuration().Hotkey        = hkey;
            configurationManager.Configuration().Url           = url;
            configurationManager.Configuration().Credentials   = (String.IsNullOrEmpty(fieldHttpUsername.Text) ? "" : fieldHttpUsername.Text + ":" + fieldHttpPassword.Text);
            configurationManager.Configuration().ShowInTaskbar = fieldShowInTaskbar.Checked;
            //
            try
            {
                hotkeyMonitor.SetKey(hkey);
                destinationValidator.Configure(configurationManager.Configuration());
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.ToString(), "Can't applying new settings", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            // update UI
            this.ShowInTaskbar = configurationManager.Configuration().ShowInTaskbar;
            //
            configurationManager.Save();
        }