Exemplo n.º 1
0
void DefaultProxyAction::populateMenu(QMenu *menu, QActionGroup *actionGroup, NetworkProxy defaultProxy)
{
	auto proxyModel = injectedFactory()->makeInjected<NetworkProxyModel>();
	auto proxyProxyModel = new NetworkProxyProxyModel();
	proxyProxyModel->setSourceModel(proxyModel);

	int proxCount = proxyProxyModel->rowCount();

	for (int i = 0; i < proxCount; i++)
	{
		NetworkProxy networkProxy = proxyProxyModel->data(proxyProxyModel->index(i, 0), NetworkProxyRole).value<NetworkProxy>();
		if (networkProxy)
		{
			QAction *proxyAction = menu->addAction(networkProxy.displayName());
			actionGroup->addAction(proxyAction);
			proxyAction->setData(QVariant::fromValue(networkProxy));
			proxyAction->setCheckable(true);
			if (defaultProxy == networkProxy)
				proxyAction->setChecked(true);
		}
	}

	delete proxyProxyModel;
	delete proxyModel;
}
Exemplo n.º 2
0
void ProxyEditWindow::updateProxyView()
{
    QModelIndexList selection = ProxyView->selectionModel()->selectedIndexes();
    if (1 != selection.size())
        return;

    Host->clear();
    Port->clear();
    User->clear();
    Password->clear();

    NetworkProxy proxy = selection.at(0).data(NetworkProxyRole).value<NetworkProxy>();
    if (proxy)
    {
        int type = Type->findData(proxy.type());
        Type->setCurrentIndex(type == -1 ? 0 : type);
        Host->setText(proxy.address());
        Port->setText(QString::number(proxy.port()));
        User->setText(proxy.user());
        Password->setText(proxy.password());
        PollingUrl->setText(proxy.pollingUrl());

        SaveButton->setText(tr("Save"));
        RemoveButton->show();
    }
    else
    {
        SaveButton->setText(tr("Add"));
        RemoveButton->hide();
    }

    dataChanged();
}
Exemplo n.º 3
0
QVariant NetworkProxyModel::data(const QModelIndex &index, int role) const
{
	NetworkProxy proxy = networkProxy(index);
	if (proxy.isNull())
		return QVariant();

	switch (role)
	{
		case Qt::DisplayRole:
			return proxy.displayName();

		case NetworkProxyRole:
			return QVariant::fromValue<NetworkProxy>(proxy);

		case ItemTypeRole:
			return NetworkProxyRole;

		default:
			return QVariant();
	}
}
void NetworkAccessManagerWrapper::configurationUpdated()
{
	NetworkProxy networkProxy;

	if (Application::instance()->configuration()->deprecatedApi()->readBoolEntry("SMS", "DefaultProxy", true))
		networkProxy = NetworkProxyManager::instance()->defaultProxy();
	else
		networkProxy = NetworkProxyManager::instance()->byUuid(Application::instance()->configuration()->deprecatedApi()->readEntry("SMS", "Proxy"));

	QNetworkProxy proxy;

	if (networkProxy)
	{
		proxy.setType(QNetworkProxy::HttpProxy);
		proxy.setHostName(networkProxy.address());
		proxy.setPort(networkProxy.port());
		proxy.setUser(networkProxy.user());
		proxy.setPassword(networkProxy.password());
	}
	else
		proxy.setType(QNetworkProxy::NoProxy);

	setProxy(proxy);
}
Exemplo n.º 5
0
bool NetworkProxyProxyModel::lessThan(const QModelIndex &left, const QModelIndex &right) const
{
	NetworkProxy leftNetworkProxy = left.data(NetworkProxyRole).value<NetworkProxy>();
	NetworkProxy rightNetworkProxy = right.data(NetworkProxyRole).value<NetworkProxy>();

	if (leftNetworkProxy.isNull())
		return false;
	if (rightNetworkProxy.isNull())
		return true;

	int displayCompare = compareNames(leftNetworkProxy.address(), rightNetworkProxy.address());
	return displayCompare < 0;
}
Exemplo n.º 6
0
ConfigurationValueState ProxyEditWindow::state(NetworkProxy proxy)
{
    bool valid = !Host->text().isEmpty()
                 && !Port->text().isEmpty();
    bool changed = proxy.type() != Type->itemData(Type->currentIndex()).toString()
                   || proxy.address() != Host->text()
                   || ((QString::number(proxy.port()) != Port->text()) && (proxy.port() != 0 || !Port->text().isEmpty()))
                   || proxy.user() != User->text()
                   || proxy.password() !=  Password->text()
                   || proxy.pollingUrl() !=  PollingUrl->text();

    if (!changed)
        return StateNotChanged;

    return valid
           ? StateChangedDataValid
           : StateChangedDataInvalid;
}
Exemplo n.º 7
0
void ProxyEditWindow::saveProxy(NetworkProxy proxy)
{
    if (proxy)
    {
        proxy.setType(Type->itemData(Type->currentIndex()).toString());
        proxy.setAddress(Host->text());
        proxy.setPort(Port->text().toInt());
        proxy.setUser(User->text());
        proxy.setPassword(Password->text());
        proxy.setPollingUrl(PollingUrl->text());
    }
    else
        proxy = m_networkProxyManager->byConfiguration(Host->text(), Port->text().toInt(), User->text(), Password->text(),
                ActionCreateAndAdd);

    ForceProxyChange = true;
    selectProxy(proxy);
    ForceProxyChange = false;
}