예제 #1
0
void MPDConnection::connectToMPD(const ServerInfo &server) {
	if (d->connected) {
		if (d->server == server) // Trying to reconncet to same server, ignore
			return;
		// Trying to connect to another server. disconnect, then connect to it.
		disconnectFromMPD();
	}

	setCaller("MPDConnection::connectToMPD", "mpd_newConnection");
	d->connection = mpd_newConnection(server.address().toUtf8(), server.port(), Config::instance()->timeoutTime());
	if (!finishCommand()) {
		disconnectFromMPD(tr("Could not connect to server %1:%2").arg(server.address()).arg(server.port()));
		return;
	}

	if (!server.password().isEmpty()) {
		mpd_call(MPDConnection::connectToMPD, Password, server.password().toUtf8());
		if (!finishCommand()) {
			disconnectFromMPD(tr("Authentication failed"));
			return;
		}
	}

	d->connected = true;
	d->server = server;
	emit connected(server);
}
예제 #2
0
QVariant ServerModel::data(const QModelIndex &index, int role) const {
	if ((role != Qt::DisplayRole && role != Qt::EditRole) || !index.isValid())
		return QVariant();

	ServerInfo si = m_servers.at(index.row());
	switch (index.column()) {
		case 0:
			return si.name();
		case 1:
			return si.address();
		case 2:
			return si.port();
		case 3:
			return role == Qt::EditRole ? "" : si.password().isEmpty() ? "" : "********";
	}
	return QVariant();
}