void ClientRunThread::run() { mutex->lock(); // Values that we watch for changes int lastStatus = client->GetStatus(); int lastBpm = -1; int lastBpi = -1; int lastBeat = -1; running = true; while (running) { while (!client->Run()); if (client->HasUserInfoChanged()) { emit userInfoChanged(); } int status = client->GetStatus(); if (status != lastStatus) { emit statusChanged(status); lastStatus = status; // Ensure we emit signals once client connects lastBpm = -1; lastBpi = -1; lastBeat = -1; } if (status == NJClient::NJC_STATUS_OK) { int bpm = client->GetActualBPM(); if (bpm != lastBpm) { emit beatsPerMinuteChanged(bpm); lastBpm = bpm; } int bpi = client->GetBPI(); if (bpi != lastBpi) { emit beatsPerIntervalChanged(bpi); lastBpi = bpi; } int pos, length; // in samples client->GetPosition(&pos, &length); int currentBeat = pos * bpi / length + 1; if (currentBeat != lastBeat) { lastBeat = currentBeat; emit currentBeatChanged(currentBeat); } } cond.wait(mutex, 20 /* milliseconds */); } mutex->unlock(); }
void RemoteClient::loginResponse(ProtocolResponse *response) { if (response->getResponseCode() == RespOk) { Response_Login *resp = qobject_cast<Response_Login *>(response); if (!resp) { disconnectFromServer(); return; } setStatus(StatusLoggedIn); emit userInfoChanged(resp->getUserInfo()); emit buddyListReceived(resp->getBuddyList()); emit ignoreListReceived(resp->getIgnoreList()); } else { emit serverError(response->getResponseCode()); setStatus(StatusDisconnecting); } }
/** * Called when fetching user information is finished */ void UserInfo::finishedFetch(const QTweetUser &userInfo) { QTweetUserShow* userShow = qobject_cast<QTweetUserShow*>(sender()); if (userShow) { m_userinfo = userInfo; emit userInfoChanged(); userShow->deleteLater(); //check if is in friends list bool isInFriendsList = m_friends.contains(m_userinfo.id()); if (isInFriendsList != m_isFriend) { m_isFriend = isInFriendsList; emit isFriendChanged(); } } }
void RemoteClient::loginResponse(const Response &response) { const Response_Login &resp = response.GetExtension(Response_Login::ext); if (response.response_code() == Response::RespOk) { setStatus(StatusLoggedIn); emit userInfoChanged(resp.user_info()); QList<ServerInfo_User> buddyList; for (int i = resp.buddy_list_size() - 1; i >= 0; --i) buddyList.append(resp.buddy_list(i)); emit buddyListReceived(buddyList); QList<ServerInfo_User> ignoreList; for (int i = resp.ignore_list_size() - 1; i >= 0; --i) ignoreList.append(resp.ignore_list(i)); emit ignoreListReceived(ignoreList); } else { emit loginError(response.response_code(), QString::fromStdString(resp.denied_reason_str()), resp.denied_end_time()); setStatus(StatusDisconnecting); } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), audio(NULL) { /* Since the ninjam callbacks do not pass a void* opaque argument we rely on * a global variable. */ if (MainWindow::instance) { fprintf(stderr, "MainWindow can only be instantiated once!\n"); abort(); } MainWindow::instance = this; JNL::open_socketlib(); client.config_savelocalaudio = 0; client.LicenseAgreementCallback = LicenseCallbackTrampoline; client.ChatMessage_Callback = ChatMessageCallbackTrampoline; client.SetLocalChannelInfo(0, "channel0", true, 0, false, 0, true, true); client.SetLocalChannelMonitoring(0, false, 0.0f, false, 0.0f, false, false, false, false); connectAction = new QAction(tr("&Connect..."), this); connect(connectAction, SIGNAL(triggered()), this, SLOT(ShowConnectDialog())); disconnectAction = new QAction(tr("&Disconnect"), this); disconnectAction->setEnabled(false); connect(disconnectAction, SIGNAL(triggered()), this, SLOT(Disconnect())); audioConfigAction = new QAction(tr("Configure &audio..."), this); connect(audioConfigAction, SIGNAL(triggered()), this, SLOT(ShowAudioConfigDialog())); QAction *exitAction = new QAction(tr("E&xit"), this); exitAction->setShortcuts(QKeySequence::Quit); connect(exitAction, SIGNAL(triggered()), this, SLOT(close())); QMenu *fileMenu = menuBar()->addMenu(tr("&File")); fileMenu->addAction(connectAction); fileMenu->addAction(disconnectAction); fileMenu->addAction(audioConfigAction); fileMenu->addAction(exitAction); QAction *aboutAction = new QAction(tr("&About..."), this); connect(aboutAction, SIGNAL(triggered()), this, SLOT(ShowAboutDialog())); QMenu *helpMenu = menuBar()->addMenu(tr("&Help")); helpMenu->addAction(aboutAction); setupStatusBar(); setWindowTitle(tr("Wahjam")); chatOutput = new QTextEdit(this); chatOutput->setReadOnly(true); chatInput = new QLineEdit(this); chatInput->connect(chatInput, SIGNAL(returnPressed()), this, SLOT(ChatInputReturnPressed())); channelTree = new ChannelTreeWidget(this); setupChannelTree(); connect(channelTree, SIGNAL(MetronomeMuteChanged(bool)), this, SLOT(MetronomeMuteChanged(bool))); connect(channelTree, SIGNAL(MetronomeBoostChanged(bool)), this, SLOT(MetronomeBoostChanged(bool))); connect(channelTree, SIGNAL(LocalChannelMuteChanged(int, bool)), this, SLOT(LocalChannelMuteChanged(int, bool))); connect(channelTree, SIGNAL(LocalChannelBoostChanged(int, bool)), this, SLOT(LocalChannelBoostChanged(int, bool))); connect(channelTree, SIGNAL(LocalChannelBroadcastChanged(int, bool)), this, SLOT(LocalChannelBroadcastChanged(int, bool))); connect(channelTree, SIGNAL(RemoteChannelMuteChanged(int, int, bool)), this, SLOT(RemoteChannelMuteChanged(int, int, bool))); metronomeBar = new MetronomeBar(this); connect(this, SIGNAL(Disconnected()), metronomeBar, SLOT(reset())); QSplitter *splitter = new QSplitter(this); QWidget *content = new QWidget; QVBoxLayout *layout = new QVBoxLayout; layout->addWidget(chatOutput); layout->addWidget(chatInput); layout->addWidget(metronomeBar); content->setLayout(layout); content->setTabOrder(chatInput, chatOutput); splitter->addWidget(channelTree); splitter->addWidget(content); splitter->setOrientation(Qt::Vertical); setCentralWidget(splitter); BeatsPerIntervalChanged(0); BeatsPerMinuteChanged(0); runThread = new ClientRunThread(&clientMutex, &client); /* Hook up an inter-thread signal for the license agreement dialog */ connect(runThread, SIGNAL(licenseCallback(const char *, bool *)), this, SLOT(LicenseCallback(const char *, bool *)), Qt::BlockingQueuedConnection); /* Hook up an inter-thread signal for the chat message callback */ connect(runThread, SIGNAL(chatMessageCallback(char **, int)), this, SLOT(ChatMessageCallback(char **, int)), Qt::BlockingQueuedConnection); /* No need to block for the remote user info callback */ connect(runThread, SIGNAL(userInfoChanged()), this, SLOT(UserInfoChanged())); /* Hook up an inter-thread signal for client status changes */ connect(runThread, SIGNAL(statusChanged(int)), this, SLOT(ClientStatusChanged(int))); /* Hook up inter-thread signals for bpm/bpi changes */ connect(runThread, SIGNAL(beatsPerMinuteChanged(int)), this, SLOT(BeatsPerMinuteChanged(int))); connect(runThread, SIGNAL(beatsPerIntervalChanged(int)), this, SLOT(BeatsPerIntervalChanged(int))); /* Hook up inter-thread signals for beat and interval changes */ connect(runThread, SIGNAL(beatsPerIntervalChanged(int)), metronomeBar, SLOT(setBeatsPerInterval(int))); connect(runThread, SIGNAL(currentBeatChanged(int)), metronomeBar, SLOT(setCurrentBeat(int))); runThread->start(); }