Exemplo n.º 1
0
            private void Rename()
            {
                var page = _tabPage as ColumnTabPage;

                if (page != null)
                {
                    using (var dialog = new InputDialogForm("change tab title (leave empty for default)"))
                    {
                        dialog.Value = page.CustomTitle ?? "";
                        if (dialog.ShowDialog() == DialogResult.OK)
                        {
                            var title = dialog.Value.Trim();

                            if (title == "")
                            {
                                page.CustomTitle = null;
                            }
                            else
                            {
                                page.CustomTitle = title;
                            }
                        }
                    }
                }
            }
Exemplo n.º 2
0
            protected override void OnDoubleClick(EventArgs e)
            {
                base.OnDoubleClick(e);

                using (var dialog = new InputDialogForm("channel name")
                {
                    Value = _chatControl.ChannelName
                })
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        _chatControl.ChannelName = dialog.Value;
                    }
                }
            }
Exemplo n.º 3
0
        public override void HandleKeys(Keys keys)
        {
            switch (keys)
            {
            // left
            case Keys.Left:
                Input.Logic.MoveCursorLeft(false, false);
                break;

            case Keys.Left | Keys.Control:
                Input.Logic.MoveCursorLeft(true, false);
                break;

            case Keys.Left | Keys.Shift:
                Input.Logic.MoveCursorLeft(false, true);
                break;

            case Keys.Left | Keys.Shift | Keys.Control:
                Input.Logic.MoveCursorLeft(true, true);
                break;

            // right
            case Keys.Right:
                Input.Logic.MoveCursorRight(false, false);
                break;

            case Keys.Right | Keys.Control:
                Input.Logic.MoveCursorRight(true, false);
                break;

            case Keys.Right | Keys.Shift:
                Input.Logic.MoveCursorRight(false, true);
                break;

            case Keys.Right | Keys.Shift | Keys.Control:
                Input.Logic.MoveCursorRight(true, true);
                break;

            // up + down
            case Keys.Up:
                if (_lastMessages.Count != 0)
                {
                    if (_currentLastMessageIndex > 0)
                    {
                        _lastMessages[_currentLastMessageIndex] = Input.Logic.Text;
                        _currentLastMessageIndex--;
                        Input.Logic.SetText(_lastMessages[_currentLastMessageIndex]);
                    }
                }
                break;

            case Keys.Down:
                if (_lastMessages.Count != 0)
                {
                    if (_currentLastMessageIndex < _lastMessages.Count - 1)
                    {
                        _lastMessages[_currentLastMessageIndex] = Input.Logic.Text;
                        _currentLastMessageIndex++;
                        Input.Logic.SetText(_lastMessages[_currentLastMessageIndex]);
                    }
                }
                break;

            // tabbing
            case Keys.Tab:
                HandleTabCompletion(true);
                break;

            case Keys.Shift | Keys.Tab:
                HandleTabCompletion(false);
                break;

            // select all
            case (Keys.Control | Keys.A):
                Input.Logic.SelectAll();
                break;

            // delete
            case Keys.Back:
            case (Keys.Back | Keys.Control):
            case (Keys.Back | Keys.Shift):
            case Keys.Delete:
            case (Keys.Delete | Keys.Control):
            case (Keys.Delete | Keys.Shift):
                Input.Logic.Delete((keys & Keys.Control) == Keys.Control, (keys & ~Keys.Control) == Keys.Delete);
                break;

            // paste
            case Keys.Control | Keys.V:
                PasteText(Clipboard.GetText());
                break;

            // home / end
            case Keys.Home:
                Input.Logic.SetCaretPosition(0);
                break;

            case Keys.Home | Keys.Shift:
                Input.Logic.SetSelectionEnd(0);
                break;

            case Keys.End:
                Input.Logic.SetCaretPosition(Input.Logic.Text.Length);
                break;

            case Keys.End | Keys.Shift:
                Input.Logic.SetSelectionEnd(Input.Logic.Text.Length);
                break;

            // rename split
            case Keys.Control | Keys.R:
                using (var dialog = new InputDialogForm("channel name")
                {
                    Value = ChannelName
                })
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        ChannelName = dialog.Value;
                    }
                }
                break;

            // default
            default:
                base.HandleKeys(keys);
                break;
            }

            base.HandleKeys(keys);
        }
Exemplo n.º 4
0
        //static Image getImage(string name)
        //{
        //    try
        //    {
        //        return Image.FromResource("Chatterino.Desktop.Assets." + name);
        //    }
        //    catch { }

        //    return null;
        //}

        // CONSTRUCTOR
        public ColumnTabPage()
        {
            AllowDrop = true;

            LayoutPreviewItem = new ColumnLayoutPreviewItem
            {
                Visible = false
            };
            LayoutPreviewItem.SetBounds(25, 25, 100, 100);
            Controls.Add(LayoutPreviewItem);

            // layout on item added/removed/bounds changed
            ColumnAdded += (s, e) =>
            {
                foreach (var w in e.Value.Widgets)
                {
                    Controls.Add(w);

                    //w.MouseUp += W_ButtonReleased;
                }

                layout();

                e.Value.WidgetAdded   += Value_WidgetAdded;
                e.Value.WidgetRemoved += Value_WidgetRemoved;
            };

            ColumnRemoved += (s, e) =>
            {
                foreach (var w in e.Value.Widgets)
                {
                    Controls.Remove(w);

                    //w.MouseUp -= W_ButtonReleased;
                }

                layout();

                e.Value.WidgetAdded   -= Value_WidgetAdded;
                e.Value.WidgetRemoved -= Value_WidgetRemoved;
            };

            SizeChanged += (s, e) =>
            {
                layout();

                Invalidate();
            };

            // Drag drop
            var lastDragPoint = new Point(10000, 10000);

            var dragColumn = -1;
            var dragRow    = -1;

            var MaxColumns = 10;
            var MaxRows    = 10;

            DragEnter += (s, e) =>
            {
                try
                {
                    var control = (ColumnLayoutDragDropContainer)e.Data.GetData(typeof(ColumnLayoutDragDropContainer));

                    if (control != null)
                    {
                        dragging = true;

                        lastDragPoint = new Point(10000, 10000);

                        e.Effect = e.AllowedEffect;
                        LayoutPreviewItem.Visible = true;
                    }
                }
                catch
                {
                }
            };
            DragLeave += (s, e) =>
            {
                if (dragging)
                {
                    dragging = false;
                    LayoutPreviewItem.Visible = false;
                }
            };
            DragDrop += (s, e) =>
            {
                if (dragging)
                {
                    dragging = false;
                    LayoutPreviewItem.Visible = false;

                    var container = (ColumnLayoutDragDropContainer)e.Data.GetData(typeof(ColumnLayoutDragDropContainer));

                    if (container != null /* && dragColumn != -1*/)
                    {
                        var control = container.Control;

                        AddWidget(control, dragColumn, dragRow);

                        //if (dragRow == -1)
                        //{
                        //    InsertColumn(dragColumn, new ChatColumn(control));
                        //}
                        //else
                        //{
                        //    ChatColumn row = Columns.ElementAt(dragColumn);
                        //    row.InsertWidget(dragRow, control);
                        //}
                    }
                }
            };

            DragOver += (s, e) =>
            {
                if (dragging)
                {
                    var mouse = PointToClient(new Point(e.X, e.Y));

                    if (lastDragPoint != mouse)
                    {
                        lastDragPoint = mouse;
                        var totalWidth = Width;

                        if (ColumnCount == 0)
                        {
                            LayoutPreviewItem.Bounds  = new Rectangle(8, 8, Width - 16, Height - 16);
                            LayoutPreviewItem.Visible = true;

                            dragColumn = -1;
                            dragRow    = -1;

                            e.Effect = DragDropEffects.Move;
                            LayoutPreviewItem.IsError = false;
                        }
                        else
                        {
                            var columnWidth = (double)totalWidth / ColumnCount;

                            dragColumn = -1;
                            dragRow    = -1;

                            // insert new column
                            for (var i = (ColumnCount >= MaxColumns ? 1 : 0); i < (ColumnCount >= MaxColumns ? ColumnCount : ColumnCount + 1); i++)
                            {
                                if (mouse.X > i * columnWidth - columnWidth / 4 &&
                                    mouse.X < i * columnWidth + columnWidth / 4)
                                {
                                    dragColumn = i;

                                    var bounds = new Rectangle((int)(i * columnWidth - columnWidth / 4), 0, (int)(columnWidth / 2), Height);

                                    if (LayoutPreviewItem.Bounds != bounds)
                                    {
                                        LayoutPreviewItem.Bounds = bounds;
                                        LayoutPreviewItem.Invalidate();
                                    }
                                    break;
                                }
                            }

                            // insert new row
                            if (dragColumn == -1)
                            {
                                for (var i = 0; i < ColumnCount; i++)
                                {
                                    if (mouse.X < (i + 1) * columnWidth)
                                    {
                                        var rows      = Columns.ElementAt(i);
                                        var rowHeight = (double)Height / rows.WidgetCount;

                                        for (var j = 0; j < rows.WidgetCount + 1; j++)
                                        {
                                            if (mouse.Y > j * rowHeight - rowHeight / 2 &&
                                                mouse.Y < j * rowHeight + rowHeight / 2)
                                            {
                                                if (rows.WidgetCount < MaxRows)
                                                {
                                                    dragColumn = i;
                                                    dragRow    = j;
                                                }

                                                var bounds = new Rectangle((int)(i * columnWidth), (int)(j * rowHeight - rowHeight / 2), (int)columnWidth, (int)(rowHeight));
                                                if (LayoutPreviewItem.Bounds != bounds)
                                                {
                                                    LayoutPreviewItem.Bounds = bounds;
                                                    LayoutPreviewItem.Invalidate();
                                                }
                                            }
                                        }
                                        break;
                                    }
                                }
                            }

                            LayoutPreviewItem.IsError = dragColumn == -1;
                            e.Effect = dragColumn == -1 ? DragDropEffects.None : DragDropEffects.Move;
                        }
                    }
                }
            };

            // Add chat control
            checkAddChatControl();

            addChatControl.Click += (s, e) =>
            {
                var chatControl = new ChatControl();

                using (var dialog = new InputDialogForm("channel name")
                {
                    Value = ""
                })
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        chatControl.ChannelName = dialog.Value;
                    }
                }

                AddColumn(new ChatColumn(chatControl));
            };
        }
Exemplo n.º 5
0
        //private Button btnResetCurrent;
        //private Button btnResetAll;

        //CTOR
        public SettingsDialog()
        {
            InitializeComponent();

            TopMost = AppSettings.WindowTopMost;

            AppSettings.WindowTopMostChanged += (s, e) =>
            {
                TopMost = AppSettings.WindowTopMost;
            };

            Icon = App.Icon;

            try
            {
                //this.Icon = Program.AppIcon;
            }
            catch { }

            tabs.SelectedIndex = 0;
            tabs.PageSelected += tabs_PageSelected;
            tabs_PageSelected(this, EventArgs.Empty);

            // Accounts
            #region Accounts
            var originalAccounts = AccountManager.Accounts.ToArray();

            foreach (var account in originalAccounts)
            {
                dataGridViewAccounts.Rows.Add(account.Username);
            }

            dataGridViewAccounts.Sort(dataGridViewAccounts.Columns[0], ListSortDirection.Descending);

            LoginForm loginForm = null;

            buttonAccountAdd.Click += delegate
            {
                if (loginForm == null)
                {
                    loginForm = new LoginForm();

                    loginForm.FormClosed += (s, e) =>
                    {
                        if (loginForm.Account != null)
                        {
                            AccountManager.AddAccount(loginForm.Account);

                            IrcManager.Account = loginForm.Account;
                            IrcManager.Connect();

                            var username = loginForm.Account.Username.ToLowerInvariant();

                            var addGridViewItem = true;

                            foreach (DataGridViewRow row in dataGridViewAccounts.Rows)
                            {
                                if (((string)row.Cells[0].Value).ToLowerInvariant() == username)
                                {
                                    addGridViewItem = false;
                                    break;
                                }
                            }

                            if (addGridViewItem)
                            {
                                dataGridViewAccounts.Rows.Add(loginForm.Account.Username);
                                dataGridViewAccounts.Sort(dataGridViewAccounts.Columns[0], ListSortDirection.Ascending);
                            }
                        }
                        loginForm = null;
                    };

                    loginForm.Show();
                }
                else
                {
                    loginForm.BringToFront();
                }
            };

            Closed += delegate
            {
                AccountManager.SaveToJson(Path.Combine(Util.GetUserDataPath(), "Login.json"));

                loginForm?.Close();
            };

            buttonAccountRemove.Click += (s, e) =>
            {
                if (dataGridViewAccounts.SelectedCells.Count != 1)
                {
                    return;
                }

                var username = (string)dataGridViewAccounts.SelectedCells[0].Value;

                AccountManager.RemoveAccount(username);

                buttonAccountRemove.Enabled = dataGridViewAccounts.RowCount != 0;
            };

            buttonAccountRemove.Enabled = dataGridViewAccounts.RowCount != 0;
            #endregion

            // Appearance
            #region Appearance

            Action setNightThemeVisibility = () =>
            {
                comboThemeNight.Visible           = labelNightDesc.Visible = comboThemeNight.Visible =
                    labelThemeNight.Visible       = labelThemeNightFrom.Visible = labelNightThemeUntil.Visible =
                        numThemeNightFrom.Visible = numThemeNightUntil.Visible =
                            checkBoxDifferentThemeAtNight.Checked;
            };

            var originalTheme           = comboTheme.Text = AppSettings.Theme;
            var originalThemeNight      = comboThemeNight.Text = AppSettings.NightTheme;
            var originalThemeHue        = AppSettings.ThemeHue;
            var originalThemeNightStart = AppSettings.NightThemeStart;
            var originalThemeNightEnd   = AppSettings.NightThemeEnd;
            var originalQuality         = comboQuality.Text = AppSettings.Quality;
            var originalPath            = AppSettings.StreamlinkPath;

            BindCheckBox(checkBoxDifferentThemeAtNight, "EnableNightTheme");

            checkBoxDifferentThemeAtNight.CheckedChanged += (s, e) =>
            {
                AppSettings.UpdateCurrentTheme();
                setNightThemeVisibility();
            };

            comboTheme.SelectedValueChanged += (s, e) =>
            {
                AppSettings.Theme = comboTheme.Text;
            };

            comboThemeNight.SelectedValueChanged += (s, e) =>
            {
                AppSettings.NightTheme = comboThemeNight.Text;
            };

            comboQuality.SelectedValueChanged += (s, e) =>
            {
                AppSettings.Quality = comboQuality.Text;
            };

            numThemeNightFrom.Value = Math.Max(1, Math.Min(24, AppSettings.NightThemeStart));

            numThemeNightFrom.ValueChanged += (s, e) =>
            {
                AppSettings.NightThemeStart = (int)numThemeNightFrom.Value;
            };

            numThemeNightUntil.Value = Math.Max(1, Math.Min(24, AppSettings.NightThemeEnd));

            numThemeNightUntil.ValueChanged += (s, e) =>
            {
                AppSettings.NightThemeEnd = (int)numThemeNightUntil.Value;
            };

            setNightThemeVisibility();

            onCancel += (s, e) =>
            {
                AppSettings.Theme           = originalTheme;
                AppSettings.NightTheme      = originalThemeNight;
                AppSettings.ThemeHue        = originalThemeHue;
                AppSettings.NightThemeStart = originalThemeNightStart;
                AppSettings.NightThemeEnd   = originalThemeNightEnd;
                AppSettings.Quality         = originalQuality;
                App.MainForm.Refresh();
            };


            trackBar1.Value = Math.Max(Math.Min((int)Math.Round(originalThemeHue * 360), 360), 0);

            trackBar1.ValueChanged += (s, e) =>
            {
                AppSettings.ThemeHue = trackBar1.Value / 360.0;
                App.MainForm.Refresh();
            };

            var defaultScrollSpeed = AppSettings.ScrollMultiplyer;

            trackBar2.Value = Math.Min(400, Math.Max(100, (int)(AppSettings.ScrollMultiplyer * 200)));

            onCancel += (s, e) =>
            {
                AppSettings.ScrollMultiplyer = defaultScrollSpeed;
            };

            lblScrollSpeed.Text = (int)(AppSettings.ScrollMultiplyer * 100) + "%";

            trackBar2.ValueChanged += (s, e) =>
            {
                AppSettings.ScrollMultiplyer = (double)trackBar2.Value / 200;

                lblScrollSpeed.Text = (int)(AppSettings.ScrollMultiplyer * 100) + "%";
            };

            btnSelectFont.Click += (s, e) =>
            {
                using (var dialog = new CustomFontDialog.FontDialog())
                {
                    if (dialog.ShowDialog(this) == DialogResult.OK)
                    {
                        AppSettings.SetFont(dialog.Font.Name, dialog.Font.Size);
                    }
                }

                updateFontName();
            };

            BindCheckBox(chkTimestamps, "ChatShowTimestamps");
            BindCheckBox(chkTimestampSeconds, "ChatShowTimestampSeconds");
            BindCheckBox(chkTimestampAmPm, "TimestampsAmPm");
            BindCheckBox(chkAllowSameMessages, "ChatAllowSameMessage");
            BindCheckBox(chkDoubleClickLinks, "ChatLinksDoubleClickOnly");
            BindCheckBox(chkHideInput, "ChatHideInputIfEmpty");
            BindCheckBox(chkMessageSeperators, "ChatSeperateMessages");
            BindCheckBox(chkRainbow, "Rainbow");
            BindCheckBox(chkStreamlinkPath, "EnableStreamlinkPath");
            BindCheckBox(chkPrefereEmotes, "PrefereEmotesOverUsernames");

            chkMessageSeperators.CheckedChanged += (s, e) =>
            {
                App.MainForm.Refresh();
            };

            BindTextBox(txtMsgLimit, "ChatMessageLimit");

            BindCheckBox(chkHighlight, "ChatEnableHighlight");
            BindCheckBox(chkPings, "ChatEnableHighlightSound");
            BindCheckBox(chkFlashTaskbar, "ChatEnableHighlightTaskbar");
            BindCheckBox(chkCustomPingSound, "ChatCustomHighlightSound");

            BindCheckBox(chkInputShowMessageLength, "ChatInputShowMessageLength");

            BindCheckBox(chkMentionUserWithAt, "ChatMentionUsersWithAt");

            BindCheckBox(chkTabLocalizedNames, "ChatTabLocalizedNames");
            BindCheckBox(chkTopMost, "WindowTopMost");

            BindCheckBox(chkLastReadMessageIndicator, "ChatShowLastReadMessageIndicator");
            chkLastReadMessageIndicator.CheckedChanged += (s, e) =>
            {
                App.MainForm.Refresh();
            };

            txtStreamlinkCustomArguments.Text = AppSettings.CustomStreamlinkArguments;

            txtStreamlinkCustomArguments.TextChanged += (s, e) =>
            {
                AppSettings.CustomStreamlinkArguments = txtStreamlinkCustomArguments.Text;
            };

            var originalCustomStreamlinkArguments = AppSettings.CustomStreamlinkArguments;

            onCancel += (s, e) =>
            {
                AppSettings.CustomStreamlinkArguments = originalCustomStreamlinkArguments;
            };
            #endregion

            // Commands
            #region Commands
            lock (Commands.CustomCommandsLock)
            {
                foreach (var c in Commands.CustomCommands)
                {
                    dgvCommands.Rows.Add(c.Raw);
                }
            }

            //ChatAllowCommandsAtEnd
            var defaultAllowCommandAtEnd = AppSettings.ChatAllowCommandsAtEnd;

            chkAllowCommandAtEnd.Checked = AppSettings.ChatAllowCommandsAtEnd;

            chkAllowCommandAtEnd.CheckedChanged += (s, e) =>
            {
                AppSettings.ChatAllowCommandsAtEnd = chkAllowCommandAtEnd.Checked;
            };

            onCancel += (s, e) =>
            {
                AppSettings.ChatAllowCommandsAtEnd = defaultAllowCommandAtEnd;
            };

            dgvCommands.MultiSelect      = false;
            dgvCommands.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            dgvCommands.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

            dgvCommands.KeyDown += (s, e) =>
            {
                if (e.KeyData == (Keys.Control | Keys.Back))
                {
                    e.Handled = true;
                }
            };

            btnCommandAdd.Click += (s, e) =>
            {
                dgvCommands.Rows.Add();
                dgvCommands.Rows[dgvCommands.Rows.Count - 1].Selected = true;
            };

            Action updateCustomCommands = () =>
            {
                lock (Commands.CustomCommandsLock)
                {
                    Commands.CustomCommands.Clear();

                    foreach (DataGridViewRow row in dgvCommands.Rows)
                    {
                        Commands.CustomCommands.Add(new Command((string)row.Cells[0].Value));
                    }
                }
            };

            btnCommandRemove.Click += (s, e) =>
            {
                if (dgvCommands.SelectedCells.Count != 0)
                {
                    dgvCommands.Rows.RemoveAt(dgvCommands.SelectedCells[0].RowIndex);
                }

                updateCustomCommands();
            };

            var originalCustomCommand = Commands.CustomCommands;

            lock (Commands.CustomCommandsLock)
            {
                Commands.CustomCommands = new List <Command>(Commands.CustomCommands);
            }

            dgvCommands.CellValueChanged += (s, e) =>
            {
                updateCustomCommands();
            };

            onCancel += (s, e) =>
            {
                lock (Commands.CustomCommandsLock)
                {
                    Commands.CustomCommands = originalCustomCommand;
                }
            };
            #endregion

            // Emotes
            #region emotes
            BindCheckBox(chkTwitchEmotes, "ChatEnableTwitchEmotes");
            BindCheckBox(chkBttvEmotes, "ChatEnableBttvEmotes");
            BindCheckBox(chkFFzEmotes, "ChatEnableFfzEmotes");
            BindCheckBox(chkEmojis, "ChatEnableEmojis");
            BindCheckBox(chkGifEmotes, "ChatEnableGifAnimations");

            var originalIgnoredEmotes = rtbIngoredEmotes.Text = string.Join(Environment.NewLine, AppSettings.ChatIgnoredEmotes.Keys);

            rtbIngoredEmotes.LostFocus += (s, e) =>
            {
                AppSettings.ChatIgnoredEmotes.Clear();
                var    reader = new StringReader(rtbIngoredEmotes.Text);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    AppSettings.ChatIgnoredEmotes[line.Trim()] = null;
                }
            };

            onCancel += (s, e) =>
            {
                AppSettings.ChatIgnoredEmotes.Clear();
                var    reader = new StringReader(originalIgnoredEmotes);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    AppSettings.ChatIgnoredEmotes[line.Trim()] = null;
                }
            };

            BindCheckBox(checkBoxEmoteSizeBasedOnTextHeight, "EmoteScaleByLineHeight");

            var originialEmoteScale = AppSettings.EmoteScale;

            onCancel += (s, e) =>
            {
                AppSettings.EmoteScale = originialEmoteScale;
                App.TriggerEmoteLoaded();
            };

            checkBoxEmoteSizeBasedOnTextHeight.CheckedChanged += (s, e) =>
            {
                labelEmoteScale.Text = $"Emote scale: {AppSettings.EmoteScale:0.##}x";

                App.TriggerEmoteLoaded();
            };

            trackBarEmoteScale.Value = Math.Min(trackBarEmoteScale.Maximum,
                                                Math.Max(trackBarEmoteScale.Minimum, (int)Math.Round((AppSettings.EmoteScale - 0.5) * 10)));

            trackBarEmoteScale.ValueChanged += (s, e) =>
            {
                AppSettings.EmoteScale = trackBarEmoteScale.Value / 10.0 + 0.5;
                labelEmoteScale.Text   = $"Emote scale: {AppSettings.EmoteScale:0.##}x";

                App.TriggerEmoteLoaded();
            };

            labelEmoteScale.Text = $"Emote scale: {AppSettings.EmoteScale:0.##}x";
            #endregion

            // Ignored Users
            #region ignored users
            //BindCheckBox(chkTwitchIgnores, "EnableTwitchUserIgnores");

            foreach (var user in IrcManager.IgnoredUsers)
            {
                dgvIgnoredUsers.Rows.Add(user);
            }

            switch (AppSettings.ChatShowIgnoredUsersMessages)
            {
            case 1:
                comboShowIgnoredUsersMessagesIf.Text = "You are moderator";
                break;

            case 2:
                comboShowIgnoredUsersMessagesIf.Text = "You are broadcaster";
                break;

            default:
                comboShowIgnoredUsersMessagesIf.Text = "Never";
                break;
            }

            comboShowIgnoredUsersMessagesIf.SelectedIndexChanged += (s, e) =>
            {
                if (comboShowIgnoredUsersMessagesIf.Text.Contains("moderator"))
                {
                    AppSettings.ChatShowIgnoredUsersMessages = 1;
                }
                else if (comboShowIgnoredUsersMessagesIf.Text.Contains("broadcaster"))
                {
                    AppSettings.ChatShowIgnoredUsersMessages = 2;
                }
                else
                {
                    AppSettings.ChatShowIgnoredUsersMessages = 0;
                }
            };

            dgvIgnoredUsers.MultiSelect      = false;
            dgvIgnoredUsers.ReadOnly         = true;
            dgvIgnoredUsers.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
            dgvIgnoredUsers.Columns[0].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

            btnIgnoredUserAdd.Click += (s, e) =>
            {
                using (var dialog = new InputDialogForm("Input Username"))
                {
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        string message;

                        if (IrcManager.TryAddIgnoredUser(dialog.Value.Trim(), out message))
                        {
                            dgvIgnoredUsers.Rows.Add(dialog.Value.Trim());
                        }
                        else
                        {
                            MessageBox.Show(message, "Error while ignoring user");
                        }
                    }
                }
            };

            btnIgnoredUserRemove.Click += (s, e) =>
            {
                if (dgvIgnoredUsers.SelectedCells.Count != 0)
                {
                    string message;
                    var    username = (string)dgvIgnoredUsers.SelectedCells[0].Value;

                    if (IrcManager.TryRemoveIgnoredUser(username, out message))
                    {
                        dgvIgnoredUsers.Rows.RemoveAt(dgvIgnoredUsers.SelectedCells[0].RowIndex);
                    }
                    else
                    {
                        MessageBox.Show(message, "Error while unignoring user");
                    }
                }
            };
            #endregion

            // Ignored Messages
            #region ignored messages
            var ignoreKeywordsOriginal = rtbIgnoreKeywords.Text = string.Join(Environment.NewLine, AppSettings.ChatIgnoredKeywords);

            rtbIgnoreKeywords.LostFocus += (s, e) =>
            {
                var    list   = new List <string>();
                var    reader = new StringReader(rtbIgnoreKeywords.Text);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    list.Add(line.Trim());
                }
                AppSettings.ChatIgnoredKeywords = list.ToArray();
            };

            onCancel += (s, e) =>
            {
                // highlight keywords
                {
                    var    list   = new List <string>();
                    var    reader = new StringReader(ignoreKeywordsOriginal);
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        list.Add(line.Trim());
                    }
                    AppSettings.ChatIgnoredKeywords = list.ToArray();
                }
            };
            #endregion

            // Links

            //RegistryKey browserKeys;
            ////on 64bit the browsers are in a different location
            //browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\WOW6432Node\Clients\StartMenuInternet");
            //if (browserKeys == null)
            //    browserKeys = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Clients\StartMenuInternet");
            //string[] browserNames = browserKeys.GetSubKeyNames();

            // Proxy
            BindCheckBox(chkProxyEnabled, "ProxyEnable");
            BindTextBox(textBox1, "ProxyHost");
            BindTextBox(textBox4, "ProxyPort");
            BindTextBox(textBox2, "ProxyUsername");
            BindTextBox(textBox3, "ProxyPassword");

            // Highlights
            #region highlights
            var customHighlightsOriginal      = rtbHighlights.Text = string.Join(Environment.NewLine, AppSettings.ChatCustomHighlights);
            var highlightIgnoredUsersOriginal = rtbUserBlacklist.Text = string.Join(Environment.NewLine, AppSettings.HighlightIgnoredUsers.Keys);

            rtbHighlights.LostFocus += (s, e) =>
            {
                var    list   = new List <string>();
                var    reader = new StringReader(rtbHighlights.Text);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    list.Add(line.Trim());
                }
                AppSettings.ChatCustomHighlights = list.ToArray();
            };

            rtbUserBlacklist.LostFocus += (s, e) =>
            {
                AppSettings.HighlightIgnoredUsers.Clear();
                var    reader = new StringReader(rtbUserBlacklist.Text);
                string line;
                while ((line = reader.ReadLine()) != null)
                {
                    AppSettings.HighlightIgnoredUsers[line.Trim().ToLower()] = null;
                }
            };

            onCancel += (s, e) =>
            {
                // highlight keywords
                {
                    var    list   = new List <string>();
                    var    reader = new StringReader(customHighlightsOriginal);
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        list.Add(line.Trim());
                    }
                    AppSettings.ChatCustomHighlights = list.ToArray();
                }

                // user blacklist
                {
                    AppSettings.HighlightIgnoredUsers.Clear();
                    var    reader = new StringReader(highlightIgnoredUsersOriginal);
                    string line;
                    while ((line = reader.ReadLine()) != null)
                    {
                        AppSettings.HighlightIgnoredUsers[line.Trim().ToLower()] = null;
                    }
                }
            };

            updateFontName();

            btnCustomHighlightOpenFile.Click += (s, e) =>
            {
                using (var dialog = new OpenFileDialog())
                {
                    dialog.Filter = "wave sound file|*.wav";

                    if (dialog.ShowDialog(this) == DialogResult.OK)
                    {
                        try
                        {
                            (GuiEngine.Current as WinformsGuiEngine).HighlightSound?.Dispose();

                            if (!Directory.Exists(Path.Combine(Util.GetUserDataPath(), "Custom")))
                            {
                                Directory.CreateDirectory(Path.Combine(Util.GetUserDataPath(), "Custom"));
                            }

                            File.Copy(dialog.FileName, Path.Combine(Util.GetUserDataPath(), "Custom", "Ping.wav"), true);
                        }
                        catch (Exception exc)
                        {
                            MessageBox.Show(exc.Message, "Error copying the highlight sound");
                        }
                    }
                }
            };
            #endregion

            // Moderation
            BindCheckBox(chkBanButton, "EnableBanButton");
            BindCheckBox(chkTimeoutButton, "EnableTimeoutButton");

            var originalTimeoutButtons = new List <int>(AppSettings.TimeoutButtons);

            Action updateTimeoutButtons = () =>
            {
                List <int> values = new List <int>();
                foreach (var control in listView1.Controls)
                {
                    values.Add((control as TimespanSelectControl).GetValue());
                }
                AppSettings.TimeoutButtons = values;
            };

            foreach (var i in AppSettings.TimeoutButtons)
            {
                var c = new TimespanSelectControl(i);
                c.ValueChanged += (s, e) => updateTimeoutButtons();
                listView1.Controls.Add(c);
            }

            onCancel += (s, e) =>
            {
                AppSettings.TimeoutButtons = originalTimeoutButtons;
            };

            listView1.ControlRemoved += (s, e) => updateTimeoutButtons();
            listView1.ControlAdded   += (s, e) => updateTimeoutButtons();

            btnAddTimeout.Click += (s, e) =>
            {
                listView1.Controls.Add(new TimespanSelectControl());
            };

            // Whispers
            BindCheckBox(chkEnableInlineWhispers, "ChatEnableInlineWhispers");

            //Buttons
            var x = 0;

            ///Cancel
            btnCancel           = new Button();
            btnCancel.AutoSize  = true;
            btnCancel.Text      = "Cancel";
            btnCancel.Location  = new Point(tabs.Panel.Width - 12 - btnCancel.Width - x, tabs.Panel.Height - 12 - btnCancel.Height);
            btnCancel.Anchor    = (AnchorStyles.Right | AnchorStyles.Bottom);
            btnCancel.BackColor = Color.FromArgb(0);
            btnCancel.Click    += new EventHandler(btnCancel_Click);
            tabs.Panel.Controls.Add(btnCancel);
            x += 12 + btnCancel.Width;

            ///OK
            BtnOK           = new Button();
            BtnOK.AutoSize  = true;
            BtnOK.Text      = "Apply";
            BtnOK.Location  = new Point(tabs.Panel.Width - 12 - BtnOK.Width - x, tabs.Panel.Height - 12 - btnCancel.Height);
            BtnOK.Anchor    = (AnchorStyles.Right | AnchorStyles.Bottom);
            BtnOK.BackColor = Color.FromArgb(0);
            BtnOK.Click    += new EventHandler(btnOK_Click);
            tabs.Panel.Controls.Add(BtnOK);
            x += 12 + BtnOK.Width;

            /////ResetCurrent
            //btnResetCurrent = new Button();
            //btnResetCurrent.AutoSize = true;
            //btnResetCurrent.Text = "Reset Current Page";
            //btnResetCurrent.Location = new Point(tabs.Panel.Width - 12 - btnResetCurrent.Width - x, tabs.Panel.Height - 12 - btnOK.Height);
            //btnResetCurrent.Anchor = (AnchorStyles.Right | AnchorStyles.Bottom);
            //btnResetCurrent.BackColor = Color.FromArgb(0);
            //btnResetCurrent.Click += new EventHandler(btnResetCurrent_Click);
            //tabs.Panel.Controls.Add(btnResetCurrent);
            //x += 12 + btnResetCurrent.Width;

            /////ResetAll
            //btnResetAll = new Button();
            //btnResetAll.AutoSize = true;
            //btnResetAll.Text = "Reset All";
            //btnResetAll.Location = new Point(tabs.Panel.Width - 12 - btnResetAll.Width - x, tabs.Panel.Height - 12 - btnOK.Height);
            //btnResetAll.Anchor = (AnchorStyles.Right | AnchorStyles.Bottom);
            //btnResetAll.BackColor = Color.FromArgb(0);
            //btnResetAll.Click += new EventHandler(btnResetAll_Click);
            //tabs.Panel.Controls.Add(btnResetAll);
            //x += 12 + btnResetAll.Width;

            Closed += (s, e) =>
            {
                AppSettings.Save();
            };
        }
Exemplo n.º 6
0
        public UserInfoPopup(Common.UserInfoData data)
        {
            InitializeComponent();

            TopMost = Common.AppSettings.WindowTopMost;

            Common.AppSettings.WindowTopMostChanged += (s, e) =>
            {
                TopMost = Common.AppSettings.WindowTopMost;
            };

            lblCreatedAt.Text = "";
            lblViews.Text     = "";
            lblNotes.Text     = "Notes: ";

            string notes = AppSettings.GetNotes(data.UserId);

            setControlFont(this);

            Task.Run(() =>
            {
                try
                {
                    var request = WebRequest.Create($"https://api.twitch.tv/helix/users?id={data.UserId}");
                    if (AppSettings.IgnoreSystemProxy)
                    {
                        request.Proxy = null;
                    }
                    request.Headers["Authorization"] = $"Bearer {IrcManager.Account.OauthToken}";
                    request.Headers["Client-ID"]     = $"{Common.IrcManager.DefaultClientID}";
                    using (var response = request.GetResponse()) {
                        using (var stream = response.GetResponseStream())
                        {
                            var parser = new JsonParser();

                            dynamic json     = parser.Parse(stream);
                            dynamic jsondata = json["data"];
                            if (jsondata != null && jsondata.Count > 0)
                            {
                                dynamic channel        = jsondata[0];
                                string logo            = channel["profile_image_url"];
                                string createdAt       = channel["created_at"];
                                string viewCount       = channel["view_count"];
                                string broadCasterType = channel["broadcaster_type"];

                                lblViews.Invoke(() => lblViews.Text = $"Channel Views: {viewCount}\n" + $"Streamer type: {broadCasterType}"
                                #if DEBUG
                                                                      + $"\nid: {data.UserId}"
                                #endif
                                                );

                                if (!String.IsNullOrEmpty(notes))
                                {
                                    lblNotes.Invoke(() => lblNotes.Text = $"Notes: {notes}");
                                }

                                DateTime createAtTime;

                                if (DateTime.TryParse(createdAt, out createAtTime))
                                {
                                    lblCreatedAt.Invoke(() => lblCreatedAt.Text = $"Created at: {createAtTime.ToString()}");
                                }

                                Task.Run(() =>
                                {
                                    try
                                    {
                                        var req = WebRequest.Create(logo);
                                        if (AppSettings.IgnoreSystemProxy)
                                        {
                                            request.Proxy = null;
                                        }

                                        using (var res = req.GetResponse()) {
                                            using (var s = res.GetResponseStream())
                                            {
                                                var image = Image.FromStream(s);

                                                picAvatar.Invoke(() => picAvatar.Image = image);
                                                updateLocation();
                                            }
                                            res.Close();
                                        }
                                    }
                                    catch { }
                                });

                                //query follow count
                                Task.Run(() =>
                                {
                                    try
                                    {
                                        var req = WebRequest.Create($"https://api.twitch.tv/helix/users/follows?to_id={data.UserId}");
                                        if (AppSettings.IgnoreSystemProxy)
                                        {
                                            request.Proxy = null;
                                        }
                                        req.Headers["Authorization"] = $"Bearer {IrcManager.Account.OauthToken}";
                                        req.Headers["Client-ID"]     = $"{Common.IrcManager.DefaultClientID}";
                                        using (var res = req.GetResponse()) {
                                            using (var s = res.GetResponseStream())
                                            {
                                                dynamic followjson   = parser.Parse(s);
                                                string followercount = followjson["total"];
                                                if (!String.IsNullOrEmpty(followercount))
                                                {
                                                    lblViews.Invoke(() => lblViews.Text = lblViews.Text + $"\nFollowers: {followercount}");
                                                    updateLocation();
                                                }
                                            }
                                        }
                                    }
                                    catch { }
                                });
                            }
                        }
                    }
                }
                catch { }
                updateLocation();
            });

            string displayName;

            if (!data.Channel.Users.TryGetValue(data.UserName, out displayName))
            {
                displayName = data.UserName;
            }

            lblUsername.Text = data.UserName;

            btnCopyUsername.Font   = Fonts.GdiSmall;
            btnCopyUsername.Click += (s, e) =>
            {
                try
                {
                    Clipboard.SetText(displayName);
                }
                catch { }
            };

            btnCopyUsername.SetTooltip("Copy Username");
            btnBan.SetTooltip("Ban User");
            btnFollow.SetTooltip("Follow User");
            btnIgnore.SetTooltip("Ignore User");
            btnMessage.SetTooltip("Send Private Message");
            btnNotes.SetTooltip("Set User Notes");
            btnProfile.SetTooltip("Show Profile");
            btnUnban.SetTooltip("Unban User");
            btnWhisper.SetTooltip("Whisper User");
            btnPurge.SetTooltip("Timeout User for 1 Second");

            btnTimeout2Hours.SetTooltip("Timeout User for 2 Hours");
            btnTimeout30Mins.SetTooltip("Timeout User for 30 Minutes");
            btnTimeout5Min.SetTooltip("Timeout User for 5 Minutes");
            btnTimeout1Day.SetTooltip("Timeout User for 1 Day");
            btnTimeout3Days.SetTooltip("Timeout User for 3 Days");
            btnTimeout7Days.SetTooltip("Timeout User for 7 Days");
            btnTimeout1Month.SetTooltip("Timeout User for 1 Month");

            btnPurge.Click         += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 1");
            btnTimeout5Min.Click   += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 300");
            btnTimeout30Mins.Click += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 1800");
            btnTimeout2Hours.Click += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 7200");
            btnTimeout1Day.Click   += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 86400");
            btnTimeout3Days.Click  += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 259200");
            btnTimeout7Days.Click  += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 604800");
            btnTimeout1Month.Click += (s, e) => data.Channel.SendMessage($"/timeout {data.UserName} 2592000");

            // show profile
            btnProfile.Click += (s, e) =>
            {
                Common.GuiEngine.Current.HandleLink(new Common.Link(Common.LinkType.Url, "https://www.twitch.tv/" + data.UserName));
            };

            if (Common.IrcManager.Account.IsAnon || string.Equals(data.UserName, Common.IrcManager.Account.Username, StringComparison.OrdinalIgnoreCase))
            {
                btnBan.Visible     = false;
                btnUnban.Visible   = false;
                btnMessage.Visible = false;
                btnNotes.Visible   = false;
                btnWhisper.Visible = false;
                btnIgnore.Visible  = false;
                btnFollow.Visible  = false;
                btnPurge.Visible   = false;

                btnMod.Visible              = false;
                btnUnmod.Visible            = false;
                btnIgnoreHighlights.Visible = false;

                btnTimeout1Day.Visible   = false;
                btnTimeout1Month.Visible = false;
                btnTimeout2Hours.Visible = false;
                btnTimeout30Mins.Visible = false;
                btnTimeout3Days.Visible  = false;
                btnTimeout5Min.Visible   = false;
                btnTimeout7Days.Visible  = false;
                btnPurge.Visible         = false;
            }
            else
            {
                if (data.Channel.IsModOrBroadcaster && !string.Equals(data.UserName, data.Channel.Name, StringComparison.OrdinalIgnoreCase))
                {
                }
                else
                {
                    btnBan.Visible   = false;
                    btnUnban.Visible = false;

                    btnTimeout1Day.Visible   = false;
                    btnTimeout1Month.Visible = false;
                    btnTimeout2Hours.Visible = false;
                    btnTimeout30Mins.Visible = false;
                    btnTimeout3Days.Visible  = false;
                    btnTimeout5Min.Visible   = false;
                    btnTimeout7Days.Visible  = false;
                    btnPurge.Visible         = false;
                }

                if (data.Channel.IsBroadcaster && !string.Equals(data.UserName, data.Channel.Name, StringComparison.OrdinalIgnoreCase))
                {
                    btnMod.Click += (s, e) =>
                    {
                        data.Channel.SendMessage("/mod " + data.UserName);
                    };
                    btnUnmod.Click += (s, e) =>
                    {
                        data.Channel.SendMessage("/unmod " + data.UserName);
                    };
                }
                else
                {
                    btnMod.Visible   = false;
                    btnUnmod.Visible = false;
                }

                // ban
                btnBan.Click += (s, e) =>
                {
                    data.Channel.SendMessage("/ban " + data.UserName);
                };

                btnUnban.Click += (s, e) =>
                {
                    data.Channel.SendMessage("/unban " + data.UserName);
                };

                // purge user
                btnPurge.Click += (s, e) =>
                {
                    data.Channel.SendMessage("/timeout " + data.UserName + " 1");
                };

                // ignore user
                btnIgnore.Text = Common.IrcManager.IsIgnoredUser(data.UserName) ? "Unignore" : "Ignore";

                btnIgnore.Click += (s, e) =>
                {
                    if (Common.IrcManager.IsIgnoredUser(data.UserName))
                    {
                        string message;

                        if (!Common.IrcManager.TryRemoveIgnoredUser(data.UserName, data.UserId, out message))
                        {
                            MessageBox.Show(message, "Error while ignoring user.");
                        }
                    }
                    else
                    {
                        string message;

                        if (!Common.IrcManager.TryAddIgnoredUser(data.UserName, data.UserId, out message))
                        {
                            MessageBox.Show(message, "Error while unignoring user.");
                        }
                    }

                    btnIgnore.Text = Common.IrcManager.IsIgnoredUser(data.UserName) ? "Unignore" : "Ignore";
                };

                // message user
                btnMessage.Click += (s, e) =>
                {
                    (App.MainForm.Selected as ChatControl)?.Input.Logic.SetText($"/w " + data.UserName + " ");
                };

                // notes
                btnNotes.Click += (s, e) =>
                {
                    using (InputDialogForm dialog = new InputDialogForm("User Notes")
                    {
                        Value = notes
                    }) {
                        notedialog = true;
                        DialogResult res = dialog.ShowDialog();
                        notedialog = false;
                        this.Focus();
                        if (res == DialogResult.OK)
                        {
                            notes = dialog.Value;
                            AppSettings.SetNotes(data.UserId, notes);
                            lblNotes.Invoke(() => lblNotes.Text = $"Notes: {notes}");
                        }
                    }
                };

                // highlight ignore
                btnIgnoreHighlights.Click += (s, e) =>
                {
                    if (AppSettings.HighlightIgnoredUsers.ContainsKey(data.UserName))
                    {
                        object tmp;

                        AppSettings.HighlightIgnoredUsers.TryRemove(data.UserName, out tmp);

                        btnIgnoreHighlights.Text = "Disable Highlights";
                    }
                    else
                    {
                        AppSettings.HighlightIgnoredUsers[data.UserName] = null;

                        btnIgnoreHighlights.Text = "Enable Highlights";
                    }
                };

                btnIgnoreHighlights.Text = AppSettings.HighlightIgnoredUsers.ContainsKey(data.UserName) ? "Enable Highlights" : "Disable Highlights";

                // follow user
                var isFollowing = false;

                Task.Run(() =>
                {
                    bool result;
                    string message;

                    Common.IrcManager.TryCheckIfFollowing(data.UserName, data.UserId, out result, out message);

                    isFollowing = result;

                    btnFollow.Invoke(() => btnFollow.Text = isFollowing ? "Unfollow" : "Follow");
                });

                btnFollow.Click += (s, e) =>
                {
                    Common.GuiEngine.Current.HandleLink(new Common.Link(Common.LinkType.Url, "https://www.twitch.tv/" + data.UserName));
                };
            }
        }