コード例 #1
0
void LinkLocalServiceBrowser::handleServiceResolved(const DNSSDServiceID& service, const boost::optional<DNSSDResolveServiceQuery::Result>& result) {
	if (result) {
		std::pair<ServiceMap::iterator, bool> r = services.insert(std::make_pair(service, *result));
		if (r.second) {
			onServiceAdded(LinkLocalService(r.first->first, r.first->second));
		}
		else {
			r.first->second = *result;
			onServiceChanged(LinkLocalService(r.first->first, r.first->second));
		}
	}
}
    AccountsPreferencesPane::AccountsPreferencesPane(QWidget * parent, Qt::WindowFlags f)
        : Utopia::PreferencesPane(parent, f)
    {
        serviceManager = ServiceManager::instance();
        connect(serviceManager.get(), SIGNAL(serviceAdded(Kend::Service*)), this, SLOT(onServiceAdded(Kend::Service*)));
        connect(serviceManager.get(), SIGNAL(serviceRemoved(Kend::Service*)), this, SLOT(onServiceRemoved(Kend::Service*)));
        serviceManagerModel = new ServiceManagerModel(this);
        QVBoxLayout * dialogLayout = new QVBoxLayout(this);
        dialogLayout->setSpacing(8);
        tableView = new QTableView;
        tableView->setModel(serviceManagerModel);
        tableView->setItemDelegateForColumn(1, new AccountDelegate(this));
        tableView->setFocusPolicy(Qt::NoFocus);
        tableView->horizontalHeader()->hide();
        tableView->horizontalHeader()->setResizeMode(0, QHeaderView::ResizeToContents);
        tableView->horizontalHeader()->setResizeMode(1, QHeaderView::Stretch);
        tableView->horizontalHeader()->setSectionHidden(2, true);
        tableView->horizontalHeader()->setResizeMode(3, QHeaderView::ResizeToContents);
        tableView->horizontalHeader()->setResizeMode(4, QHeaderView::ResizeToContents);
        tableView->horizontalHeader()->resizeSection(3, 100);
        tableView->verticalHeader()->hide();
        tableView->verticalHeader()->setResizeMode(QHeaderView::ResizeToContents);
        tableView->setAlternatingRowColors(true);
        tableView->setSelectionMode(QAbstractItemView::SingleSelection);
        tableView->setSelectionBehavior(QAbstractItemView::SelectRows);
        tableView->setShowGrid(false);
        tableView->setWordWrap(false);
        connect(tableView->selectionModel(), SIGNAL(currentRowChanged(const QModelIndex &, const QModelIndex &)),
                this, SLOT(onCurrentRowChanged(const QModelIndex &, const QModelIndex &)), Qt::QueuedConnection);
        dialogLayout->addWidget(tableView, 1);

        QHBoxLayout * buttonLayout = new QHBoxLayout;
        buttonLayout->setSpacing(0);
        buttonLayout->setContentsMargins(0, 0, 0, 0);
        addServiceButton = new QToolButton;
        addServiceButton->setIcon(QIcon(":/icons/addaccount.png"));
        addServiceButton->setObjectName("addServiceButton");
        connect(addServiceButton, SIGNAL(clicked()), this, SLOT(onAddServiceButtonClicked()));
        removeServiceButton = new QToolButton;
        removeServiceButton->setIcon(QIcon(":/icons/removeaccount.png"));
        removeServiceButton->setObjectName("removeServiceButton");
        removeServiceButton->setEnabled(false);
        connect(removeServiceButton, SIGNAL(clicked()), this, SLOT(onRemoveServiceButtonClicked()));
        buttonLayout->addStretch(1);
        buttonLayout->addWidget(addServiceButton);
        buttonLayout->addWidget(removeServiceButton);
        dialogLayout->addLayout(buttonLayout, 0);

        detailsGroup = new QGroupBox("Account details");
        dialogLayout->addWidget(detailsGroup, 0);
        detailsGroup->hide();
        infoStack = new QStackedLayout(detailsGroup);

        if (serviceManager->count() > 0) {
            tableView->setCurrentIndex(serviceManagerModel->index(0, 0));
        }

        userInfoEditor = new UserInfoEditor(this);
        userInfoEditor->hide();

        // Populate info panels from service manager
        for (int i = 0; i < serviceManager->count(); ++i) {
            Service * service = serviceManager->serviceAt(i);
            onServiceAdded(service);
        }
    }