Ejemplo n.º 1
0
void YourAccounts::createGui()
{
	QVBoxLayout *mainLayout = new QVBoxLayout(this);

	QHBoxLayout *contentLayout = new QHBoxLayout();
	mainLayout->addItem(contentLayout);

	AccountsView = new QListView(this);
	AccountsView->setMinimumWidth(150);
	contentLayout->addWidget(AccountsView);
	MyAccountsModel = m_injectedFactory->makeInjected<AccountsModel>(m_accountManager, AccountsView);
	auto *chain = new ModelChain{this};
	auto accountProxyModel = new AccountsProxyModel(chain);
	chain->setBaseModel(MyAccountsModel);
	accountProxyModel->addFilter(new HaveProtocolFilter(accountProxyModel));
	chain->addProxyModel(accountProxyModel);

	QAction *separator = new QAction(this);
	separator->setSeparator(true);

	AddExistingAccountAction = new QAction(m_iconsManager->iconByPath(KaduIcon("contact-new")), tr("Add existing account"), this);
	CreateNewAccountAction = new QAction(m_iconsManager->iconByPath(KaduIcon("system-users")), tr("Create new account"), this);

	ActionListModel *actionsModel = new ActionListModel(this);
	actionsModel->appendAction(separator);
	actionsModel->appendAction(AddExistingAccountAction);
	actionsModel->appendAction(CreateNewAccountAction);

	QList<QAbstractItemModel *> models;
	models.append(chain->lastModel());
	models.append(actionsModel);

	ActionFilterProxyModel *proxyModel = new ActionFilterProxyModel(this);
	proxyModel->setSourceModel(MergedProxyModelFactory::createInstance(models, this));
	proxyModel->setModel(chain->lastModel());
	proxyModel->addHideWhenModelEmpty(separator);

	AccountsView->setModel(proxyModel);
	AccountsView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
	AccountsView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
	AccountsView->setIconSize(QSize(32, 32));
	connect(AccountsView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
			this, SLOT(accountSelectionChanged(const QItemSelection &, const QItemSelection &)));

	QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal, this);
	mainLayout->addWidget(buttons);

	QPushButton *cancelButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogCloseButton), tr("Close"), this);

	connect(cancelButton, SIGNAL(clicked(bool)), this, SLOT(close()));
	buttons->addButton(cancelButton, QDialogButtonBox::RejectRole);

	MainStack = new QStackedWidget(this);

	contentLayout->addWidget(MainStack, 100);

	createAccountWidget();
	createEditAccountWidget();
}
Ejemplo n.º 2
0
void ProxyEditWindow::createGui()
{
    QVBoxLayout *mainLayout = new QVBoxLayout(this);

    QHBoxLayout *contentLayout = new QHBoxLayout();
    mainLayout->addItem(contentLayout);

    ProxyView = new QListView(this);
    ProxyView->setMinimumWidth(150);
    contentLayout->addWidget(ProxyView);

    ProxyModel = m_injectedFactory->makeInjected<NetworkProxyModel>(ProxyView);
    ProxyProxyModel = new NetworkProxyProxyModel(ProxyView);
    ProxyProxyModel->setSourceModel(ProxyModel);

    QAction *separator = new QAction(this);
    separator->setSeparator(true);

    AddProxyAction = new QAction(tr("Add new proxy"), this);

    ActionListModel *actionsModel = new ActionListModel(this);
    actionsModel->appendAction(separator);
    actionsModel->appendAction(AddProxyAction);

    QList<QAbstractItemModel *> models;
    models.append(ProxyProxyModel);
    models.append(actionsModel);

    ActionFilterProxyModel *actionProxyModel = new ActionFilterProxyModel(this);
    actionProxyModel->setSourceModel(MergedProxyModelFactory::createInstance(models, this));
    actionProxyModel->setModel(ProxyProxyModel);
    actionProxyModel->addHideWhenModelEmpty(separator);

    ProxyView->setModel(actionProxyModel);
    ProxyView->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Expanding);
    ProxyView->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    ProxyView->setIconSize(QSize(32, 32));
    connect(ProxyView->selectionModel(), SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
            this, SLOT(proxySelectionChanged(const QItemSelection &, const QItemSelection &)));

    QWidget *editPanel = new QWidget(this);
    contentLayout->addWidget(editPanel);

    QFormLayout *editLayout = new QFormLayout(editPanel);

    Type = new QComboBox(editPanel);
    Type->addItem(tr("HTTP CONNECT method"), "http");
    Type->addItem(tr("SOCKS Version 5"), "socks");
    Type->addItem(tr("HTTP Polling"), "poll");
    connect(Type, SIGNAL(currentIndexChanged(int)), this, SLOT(dataChanged()));
    editLayout->addRow(tr("Type (for Jabber)"), Type);

    PollingUrl = new QLineEdit(editPanel);
    connect(PollingUrl, SIGNAL(textChanged(QString)), this, SLOT(dataChanged()));
    editLayout->addRow(tr("Polling URL"), PollingUrl);

    Host = new QLineEdit(editPanel);
    connect(Host, SIGNAL(textChanged(QString)), this, SLOT(dataChanged()));
    editLayout->addRow(tr("Host"), Host);

    Port = new QLineEdit(editPanel);
    connect(Port, SIGNAL(textChanged(QString)), this, SLOT(dataChanged()));
    Port->setValidator(new QIntValidator(1, 65535, Port));
    editLayout->addRow(tr("Port"), Port);

    User = new QLineEdit(editPanel);
    connect(User, SIGNAL(textChanged(QString)), this, SLOT(dataChanged()));
    editLayout->addRow(tr("User"), User);

    Password = new QLineEdit(editPanel);
    connect(Password, SIGNAL(textChanged(QString)), this, SLOT(dataChanged()));
    Password->setEchoMode(QLineEdit::Password);
    editLayout->addRow(tr("Password"), Password);

    QDialogButtonBox *editButtons = new QDialogButtonBox(Qt::Horizontal, editPanel);
    editLayout->addRow(editButtons);

    SaveButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogApplyButton), tr("Add"), editButtons);
    connect(SaveButton, SIGNAL(clicked()), this, SLOT(saveProxyButtonClicked()));
    CancelButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogCancelButton), tr("Cancel"), editButtons);
    connect(CancelButton, SIGNAL(clicked()), this, SLOT(cancelButtonClicked()));
    RemoveButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogCancelButton), tr("Remove"), editButtons);
    connect(RemoveButton, SIGNAL(clicked(bool)), this, SLOT(removeButtonClicked()));

    editButtons->addButton(SaveButton, QDialogButtonBox::ApplyRole);
    editButtons->addButton(CancelButton, QDialogButtonBox::RejectRole);
    editButtons->addButton(RemoveButton, QDialogButtonBox::DestructiveRole);

    QDialogButtonBox *buttons = new QDialogButtonBox(Qt::Horizontal, this);
    mainLayout->addWidget(buttons);

    QPushButton *closeButton = new QPushButton(qApp->style()->standardIcon(QStyle::SP_DialogCancelButton), tr("Close"), buttons);

    connect(closeButton, SIGNAL(clicked(bool)), this, SLOT(close()));
    buttons->addButton(closeButton, QDialogButtonBox::RejectRole);
}