Esempio n. 1
0
void
FriendWidget::setDetails()
{
    ui->userDetails->setText( userString( m_user ) );
    ui->username->setText( Label::boldLinkStyle( Label::anchor( m_user.www().toString(), name() ), Qt::black ) );
    ui->lastTrack->setText( m_track.toString() );

    if ( m_listeningNow )
    {
        // show the
        m_movie->start();
        ui->equaliser->show();

        ui->trackFrame->setObjectName( "nowListening" );
        style()->polish( ui->trackFrame );

        if ( !m_track.extra( "playerName" ).isEmpty() )
            ui->timestamp->setText( tr( "Scrobbling now from %1" ).arg( m_track.extra( "playerName" ) ) );
        else
            ui->timestamp->setText( tr( "Scrobbling now" ) );

        if ( m_timestampTimer ) m_timestampTimer->stop();
    }
    else
    {
        m_movie->stop();
        ui->equaliser->hide();

        ui->trackFrame->setObjectName( "groupBox" );
        style()->polish( ui->trackFrame );

        updateTimestamp();
    }
}
Esempio n. 2
0
void ServerDialog::ChatCallBack(char *user, char *message)
{
	QString userString(user);
	ui.plainTextChat->appendPlainText(QString(user) + QString(": ") + QString(message));
	ui.plainTextChat->ensureCursorVisible();
	/* moveToThread kanske?*/
	ui.plainTextChat->update();
}
Esempio n. 3
0
void UI::handleCommand(const std::string &command) {

	std::pair<std::string::size_type, std::string::size_type> pos
		= nextToken(command);
	std::string::size_type len = pos.second - pos.first;

	if (!len) {
		return;
	}

	std::string data(command, pos.first, len);

	if (len == 1 && data == "/" && command.length() > 2) {
		pos.first += 2;
		goto chatmsg;
	}

	if (command[pos.first] != '/') {
	chatmsg:
		if (! chatNetwork.length()) {
			messageW->printf("Message not sent, use /chat or /msg command\n");
			messageW->refresh();
			return;
		}

		if (! userExists(chatUser, chatNetwork)) {
			messageW->printf("Message not sent, user not found\n");
			messageW->refresh();
			return;
		}

		sendSignal("/net/msg/send", chatNetwork,
				   new sig::MessageData(chatUser,
									std::string(command, pos.first), 0));

	}

	if (len == 5 && (data == "/quit" || data == "/exit")) {
		sendSignal("/core/module/exits", Core::coreName);
		return;
	}

	if ((len == 2 && (data == "/n" || data == ":n"))
	|| (len == 6 && data == "/names")) {
		/* /names command */
		if (networkUsers.empty()) {
			messageW->printf("There are no connected networks\n");
		} else {
			NetworkUsers::iterator nuit;
			sig::UsersListData::Users::iterator uit;
			for(nuit=networkUsers.begin(); nuit!=networkUsers.end(); ++nuit) {
				if (nuit->second->users.empty()) {
					messageW->printf("Network %s has no connected users\n",
					                 nuit->first.c_str());
				} else {
					messageW->printf("Connected users in network %s:\n",
					                 nuit->first.c_str());
					for(uit=nuit->second->users.begin();
					    uit!=nuit->second->users.end();
					    ++uit) {
						messageW->printf("%s (%s) (%s)\n",
						          uit->second->name.c_str(),
						          uit->first.toString().c_str(),
						          uit->second->status.toString().c_str()
						);
					}
				}
			}
		}
	}

	if (len == 5 && data == "/chat") {

		/* trim */
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			/* end chat */
			messageW->printf("Chat with %s (network %s) finished\n",
			                chatUser.toString().c_str(),
							chatNetwork.c_str());
			chatNetwork.clear();
			statusW->printf("\n");
			statusW->refresh();
			return;
		}

		std::string userString(command, pos.first, pos.second-pos.first);

		std::multimap< std::string, User* >::iterator it;
		findUsers(userString);

		if(usersFound.size() == 0) {
			messageW->printf("No users match to '%s', try /names command.\n", userString.c_str());
		} else if(usersFound.size() > 1) {
			int iii;
			messageW->printf("Ambiguous user '%s', possible matches:\n",
			                 userString.c_str());
			for(iii=1, it=usersFound.begin(); it!=usersFound.end(); ++iii, ++it) {
				messageW->printf("[#%d] %s\n", iii, it->second->id.toString().c_str());
			}
			completionModeEnter();
		} else {

			it = usersFound.begin();
			chatUser = it->second->id;
			chatNetwork = it->first;
			messageW->printf("Chatting with %s (network %s)\n",
			                 chatUser.toString().c_str(),
							 chatNetwork.c_str());
			statusW->printf("Chatting with %s (network %s)\n",
			                 chatUser.toString().c_str(),
							 chatNetwork.c_str());
			statusW->refresh();
		}
		messageW->refresh();
	}

	if ((len == 4 && data == "/msg") ||
	    (len == 3 && data == "/me")) {
		/* if len == 0 then data == "/" */

		/* trim */
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			/* refuse to send empty line */
			return;
		}

		std::string userString(command, pos.first, pos.second-pos.first);
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			/* no message? */
			return;
		}
		std::string msgString(command, pos.first, pos.second-pos.first);

		std::multimap< std::string, User* >::iterator it;
		findUsers(userString);

		if(usersFound.size() == 0) {
			messageW->printf("No users match to '%s', try /names command.\n", userString.c_str());
		} else if(usersFound.size() > 1) {
			int iii;
			messageW->printf("Ambiguous user '%s', possible matches:\n",
			                 userString.c_str());
			for(iii=1, it=usersFound.begin(); it!=usersFound.end(); ++iii, ++it) {
				messageW->printf("[#%d] %s\n", iii, it->second->id.toString().c_str());
			}
			completionModeEnter();
		} else {

			it = usersFound.begin();
			std::string net = it->first;
			sendSignal("/net/msg/send", net,
			           new sig::MessageData(it->second->id,
		                                std::string(command, pos.first),
		                                len==3?sig::MessageData::ACTION:0));
		}

	} else if (len == 3 && data == "/aw") {
		/* dirty trick */
		pos.second = pos.first + 1;
		goto status;

	} else if (len == 7 && data == "/status") {
	status:
		enum User::State state;
		bool valid;

		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			return;
		}

		data.assign(command, pos.first, pos.second - pos.first);
		state = User::getState(data, valid);
		if (!valid) {
			return;
		}

		/* send to all networks */
		std::string net = "/net/";
		pos = nextToken(command, pos.second);
		if (pos.first == std::string::npos) {
			data.clear();
		} else {
			data.assign(command, pos.first, std::string::npos);
		}

		/*
		 * in UserData we must supply valid data only for these
		 * information which has changed (status and/or displayname)
		 */
		sendSignal("/net/status/change", net,
		           new sig::UserData(User("dummy", Address(),
		                                  User::Status(state, data)),
		                             sig::UserData::STATE |
		                             sig::UserData::MESSAGE));
	} else if((len == 3 && data == "/dn")
	|| (len = 12 && data == "/displayname")) {



	} else if(len == 8 && data == "/history") {
		std::list<std::string>::iterator hi;
		int i;

		messageW->printf("Command history:\n");
		for(hi=history.begin(), ++hi, i=1; hi!=history.end(); ++hi, ++i) {
			messageW->printf("[%2d] %s\n", i, hi->c_str());
		}
		messageW->refresh();


	/* ... and so it may go with other commands */
	} else {
		/* print error message -- unkonw command */
	}
}