<commit_before>#include "selectchanneldialog.hpp"

#include "application.hpp"
#include "providers/twitch/twitchserver.hpp"
#include "util/layoutcreator.hpp"

#include <QDialogButtonBox>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <widgets/notebook.hpp>

#define TAB_TWITCH 0

namespace chatterino {
namespace widgets {

SelectChannelDialog::SelectChannelDialog()
    : BaseWindow((QWidget *)nullptr, BaseWindow::EnableCustomFrame)
    , selectedChannel(Channel::getEmpty())
{
    this->setWindowTitle("Select a channel to join");

    this->tabFilter.dialog = this;

    util::LayoutCreator<QWidget> layoutWidget(this->getLayoutContainer());
    auto layout = layoutWidget.setLayoutType<QVBoxLayout>().withoutMargin();
    auto notebook = layout.emplace<Notebook>(this).assign(&this->ui.notebook);

    // twitch
    {
        util::LayoutCreator<QWidget> obj(new QWidget());
        auto vbox = obj.setLayoutType<QVBoxLayout>();

        // channel_btn
        auto channel_btn = vbox.emplace<QRadioButton>("Channel").assign(&this->ui.twitch.channel);
        auto channel_lbl = vbox.emplace<QLabel>("Join a twitch channel by its name.").hidden();
        channel_lbl->setWordWrap(true);
        auto channel_edit = vbox.emplace<QLineEdit>().hidden().assign(&this->ui.twitch.channelName);

        QObject::connect(*channel_btn, &QRadioButton::toggled, [=](bool enabled) mutable {
            if (enabled) {
                channel_edit->setFocus();
                channel_edit->setSelection(0, channel_edit->text().length());
            }

            channel_edit->setVisible(enabled);
            channel_lbl->setVisible(enabled);
        });

        channel_btn->installEventFilter(&this->tabFilter);
        channel_edit->installEventFilter(&this->tabFilter);

        // whispers_btn
        auto whispers_btn =
            vbox.emplace<QRadioButton>("Whispers").assign(&this->ui.twitch.whispers);
        auto whispers_lbl =
            vbox.emplace<QLabel>("Shows the whispers that you receive while chatterino is running.")
                .hidden();

        whispers_lbl->setWordWrap(true);
        whispers_btn->installEventFilter(&this->tabFilter);

        QObject::connect(*whispers_btn, &QRadioButton::toggled,
                         [=](bool enabled) mutable { whispers_lbl->setVisible(enabled); });

        // mentions_btn
        auto mentions_btn =
            vbox.emplace<QRadioButton>("Mentions").assign(&this->ui.twitch.mentions);
        auto mentions_lbl =
            vbox.emplace<QLabel>("Shows all the messages that highlight you from any channel.")
                .hidden();

        mentions_lbl->setWordWrap(true);
        mentions_btn->installEventFilter(&this->tabFilter);

        QObject::connect(*mentions_btn, &QRadioButton::toggled,
                         [=](bool enabled) mutable { mentions_lbl->setVisible(enabled); });

        // watching_btn
        auto watching_btn =
            vbox.emplace<QRadioButton>("Watching").assign(&this->ui.twitch.watching);
        auto watching_lbl =
            vbox.emplace<QLabel>("Requires the chatterino browser extension.").hidden();

        watching_lbl->setWordWrap(true);
        watching_btn->installEventFilter(&this->tabFilter);

        QObject::connect(*watching_btn, &QRadioButton::toggled,
                         [=](bool enabled) mutable { watching_lbl->setVisible(enabled); });

        vbox->addStretch(1);

        // tabbing order
        QWidget::setTabOrder(*watching_btn, *channel_btn);
        QWidget::setTabOrder(*channel_btn, *whispers_btn);
        QWidget::setTabOrder(*whispers_btn, *mentions_btn);
        QWidget::setTabOrder(*mentions_btn, *watching_btn);

        // tab
        NotebookTab *tab = notebook->addPage(obj.getElement());
        tab->setCustomTitle("Twitch");
    }

    // irc
    /*{
        util::LayoutCreator<QWidget> obj(new QWidget());
        auto vbox = obj.setLayoutType<QVBoxLayout>();

        auto edit = vbox.emplace<QLabel>("not implemented");

        NotebookTab2 *tab = notebook->addPage(obj.getElement());
        tab->setTitle("Irc");
    }*/

    layout->setStretchFactor(*notebook, 1);

    auto buttons = layout.emplace<QHBoxLayout>().emplace<QDialogButtonBox>(this);
    {
        auto *button_ok = buttons->addButton(QDialogButtonBox::Ok);
        QObject::connect(button_ok, &QPushButton::clicked, [=](bool) { this->ok(); });
        auto *button_cancel = buttons->addButton(QDialogButtonBox::Cancel);
        QObject::connect(button_cancel, &QAbstractButton::clicked, [=](bool) { this->close(); });
    }

    this->setScaleIndependantSize(300, 210);

    // Shortcuts
    auto *shortcut_ok = new QShortcut(QKeySequence("Return"), this);
    QObject::connect(shortcut_ok, &QShortcut::activated, [=] { this->ok(); });
    auto *shortcut_cancel = new QShortcut(QKeySequence("Esc"), this);
    QObject::connect(shortcut_cancel, &QShortcut::activated, [=] { this->close(); });
}<commit_msg>Default add to channel (#453)<commit_after>#include "selectchanneldialog.hpp"

#include "application.hpp"
#include "providers/twitch/twitchserver.hpp"
#include "util/layoutcreator.hpp"

#include <QDialogButtonBox>
#include <QGroupBox>
#include <QLabel>
#include <QLineEdit>
#include <QVBoxLayout>
#include <widgets/notebook.hpp>

#define TAB_TWITCH 0

namespace chatterino {
namespace widgets {

SelectChannelDialog::SelectChannelDialog()
    : BaseWindow((QWidget *)nullptr, BaseWindow::EnableCustomFrame)
    , selectedChannel(Channel::getEmpty())
{
    this->setWindowTitle("Select a channel to join");

    this->tabFilter.dialog = this;

    util::LayoutCreator<QWidget> layoutWidget(this->getLayoutContainer());
    auto layout = layoutWidget.setLayoutType<QVBoxLayout>().withoutMargin();
    auto notebook = layout.emplace<Notebook>(this).assign(&this->ui.notebook);

    // twitch
    {
        util::LayoutCreator<QWidget> obj(new QWidget());
        auto vbox = obj.setLayoutType<QVBoxLayout>();

        // channel_btn
        auto channel_btn = vbox.emplace<QRadioButton>("Channel").assign(&this->ui.twitch.channel);
        auto channel_lbl = vbox.emplace<QLabel>("Join a twitch channel by its name.").hidden();
        channel_lbl->setWordWrap(true);
        auto channel_edit = vbox.emplace<QLineEdit>().hidden().assign(&this->ui.twitch.channelName);

        QObject::connect(*channel_btn, &QRadioButton::toggled, [=](bool enabled) mutable {
            if (enabled) {
                channel_edit->setFocus();
                channel_edit->setSelection(0, channel_edit->text().length());
            }

            channel_edit->setVisible(enabled);
            channel_lbl->setVisible(enabled);
        });

        channel_btn->installEventFilter(&this->tabFilter);
        channel_edit->installEventFilter(&this->tabFilter);

        // whispers_btn
        auto whispers_btn =
            vbox.emplace<QRadioButton>("Whispers").assign(&this->ui.twitch.whispers);
        auto whispers_lbl =
            vbox.emplace<QLabel>("Shows the whispers that you receive while chatterino is running.")
                .hidden();

        whispers_lbl->setWordWrap(true);
        whispers_btn->installEventFilter(&this->tabFilter);

        QObject::connect(*whispers_btn, &QRadioButton::toggled,
                         [=](bool enabled) mutable { whispers_lbl->setVisible(enabled); });

        // mentions_btn
        auto mentions_btn =
            vbox.emplace<QRadioButton>("Mentions").assign(&this->ui.twitch.mentions);
        auto mentions_lbl =
            vbox.emplace<QLabel>("Shows all the messages that highlight you from any channel.")
                .hidden();

        mentions_lbl->setWordWrap(true);
        mentions_btn->installEventFilter(&this->tabFilter);

        QObject::connect(*mentions_btn, &QRadioButton::toggled,
                         [=](bool enabled) mutable { mentions_lbl->setVisible(enabled); });

        // watching_btn
        auto watching_btn =
            vbox.emplace<QRadioButton>("Watching").assign(&this->ui.twitch.watching);
        auto watching_lbl =
            vbox.emplace<QLabel>("Requires the chatterino browser extension.").hidden();

        watching_lbl->setWordWrap(true);
        watching_btn->installEventFilter(&this->tabFilter);

        QObject::connect(*watching_btn, &QRadioButton::toggled,
                         [=](bool enabled) mutable { watching_lbl->setVisible(enabled); });

        vbox->addStretch(1);

        // tabbing order
        QWidget::setTabOrder(*watching_btn, *channel_btn);
        QWidget::setTabOrder(*channel_btn, *whispers_btn);
        QWidget::setTabOrder(*whispers_btn, *mentions_btn);
        QWidget::setTabOrder(*mentions_btn, *watching_btn);

        // tab
        NotebookTab *tab = notebook->addPage(obj.getElement());
        tab->setCustomTitle("Twitch");
    }

    // irc
    /*{
        util::LayoutCreator<QWidget> obj(new QWidget());
        auto vbox = obj.setLayoutType<QVBoxLayout>();

        auto edit = vbox.emplace<QLabel>("not implemented");

        NotebookTab2 *tab = notebook->addPage(obj.getElement());
        tab->setTitle("Irc");
    }*/

    layout->setStretchFactor(*notebook, 1);

    auto buttons = layout.emplace<QHBoxLayout>().emplace<QDialogButtonBox>(this);
    {
        auto *button_ok = buttons->addButton(QDialogButtonBox::Ok);
        QObject::connect(button_ok, &QPushButton::clicked, [=](bool) { this->ok(); });
        auto *button_cancel = buttons->addButton(QDialogButtonBox::Cancel);
        QObject::connect(button_cancel, &QAbstractButton::clicked, [=](bool) { this->close(); });
    }

    this->setScaleIndependantSize(300, 210);
    this->ui.notebook->selectIndex(TAB_TWITCH);
    this->ui.twitch.channel->setFocus();

    // Shortcuts
    auto *shortcut_ok = new QShortcut(QKeySequence("Return"), this);
    QObject::connect(shortcut_ok, &QShortcut::activated, [=] { this->ok(); });
    auto *shortcut_cancel = new QShortcut(QKeySequence("Esc"), this);
    QObject::connect(shortcut_cancel, &QShortcut::activated, [=] { this->close(); });
}
{'fraction_non_alphanumeric': 0.14405857326605323, 'fraction_numerical': 0.0024735331948154745, 'mean_word_length': 3.3049403747870527, 'pattern_counts': {'":': 0, '<': 53, '<?xml version=': 0, '>': 145, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6870140', 'n_tokens_mistral': 3080, 'n_tokens_neox': 2999, 'n_words': 452}