/** Get a message node element, extrapolate its type (public msg, private msg, channelEnter, etc.) and emit the specific signal */ void AJAXChat::emitChatData(const QDomElement &message) { QString messageText = message.firstChildElement("text").text(); // decode html entities from the message text and simplify it QTextEdit t; t.setHtml(messageText); messageText = t.toPlainText().simplified(); if (messageText.startsWith("/")) { QStringList messageParts = messageText.split(" "); if (messageText.startsWith("/privmsg")) { const int userID = message.attribute("userID").toInt(); emit newPrivateMessage(messageParts.at(1), getUser(userID).text()); } else if (messageText.startsWith("/login")) { emit userLoggedIn(messageParts.at(1)); } else if (messageText.startsWith("/logout")) { emit userLoggedOut(messageParts.at(1)); qDebug("Logged out: " + getUser(messageParts.at(1)).text().toUtf8()); } else if (messageText.startsWith("/channelEnter")) { emit userJoinChannel(messageParts.at(1)); } else if (messageText.startsWith("/channelLeave")) { emit userLeaveChannel(messageParts.at(1)); } else if (messageText.startsWith("/kick")) { emit userKicked(messageParts.at(1)); } else if (messageText.startsWith("/nick")) { emit userChangeNick(messageParts.at(1), messageParts.at(2)); } } else { const int userID = message.attribute("userID").toInt(); emit newPublicMessage(messageText, getUser(userID).text()); } }
Botanna::Botanna(QObject *parent) : QObject(parent) { // Fetch stuff from memory memory = new Memory(this); name = memory->name(); if (name.isEmpty()) { // stop // TODO } chatLocation = memory->chatLocation(); if (chatLocation.isEmpty()) { // stop // TODO } chatUsername = memory->chatUsername(); if (chatUsername.isEmpty()) { // stop // TODO } chatPassword = memory->chatPassword(); if (chatPassword.isEmpty()) { // stop // TODO } forumLoginUrl = memory->forumLoginUrl(); if (forumLoginUrl.isEmpty()) { // nothing to do, can be empty } // setup the chat client chat = new AJAXChat(this); connect(chat, SIGNAL(newPublicMessage(QString&,QString)), this, SLOT(processPublicMessage(QString&,QString))); connect(chat, SIGNAL(userChangeNick(QString,QString)), this, SLOT(updateGDFUser(QString,QString))); connect(chat, SIGNAL(userLoggedOut(QString)), this, SLOT(gdfUserLeave(QString))); connect(chat, SIGNAL(userKicked(QString)), this, SLOT(gdfUserLeave(QString))); connect(chat, SIGNAL(userLeaveChannel(QString)), this, SLOT(gdfUserLeave(QString))); // Here we go, Anna puts his hands on the computer connectToChat(); gdfStarted = false; currentGdfUser = 0; }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { setCentralWidget(new QWidget); QVBoxLayout* layout = new QVBoxLayout( centralWidget() ); layout->setContentsMargins(0,0,0,0); layout->setSpacing(0); layout->addWidget( ui.header = new Header( this ) ); connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), ui.header, SLOT(onUserConnected(QString)) ); connect( &Socket::sock(), SIGNAL(userLoggedOut()), ui.header, SLOT(onUserDisconnected()) ); connect( ui.header, SIGNAL(disconnectClicked()), &Socket::sock(), SLOT(logout()) ); // mettre obligatoirement ici pour corriger un petit bug d'affichage // /*temp refresh button*/ // QPushButton *refreshBtn = new QPushButton( "Refresh" ); // refreshBtn->setObjectName( "refreshBtn" ); // mainLayout->addWidget( refreshBtn ); // connect(refreshBtn, SIGNAL(clicked()), ui.header, SLOT( onRefreshClicked() ) ); QHBoxLayout* centralLayout = new QHBoxLayout( ); centralLayout->addWidget( ui.sideBar = new SideBar( this ) ); centralLayout->addWidget( ui.stackedWidget = new StackedWidget( this ) ); layout->addLayout( centralLayout ); connect(ui.sideBar, SIGNAL( currentChanged( int ) ), ui.stackedWidget, SLOT( setCurrentIndex( int ) ) ); connect(ui.sideBar, SIGNAL( currentChanged( int ) ), SLOT( loadViewData( int ) ) ); // LOG connect( &Socket::sock(), SIGNAL(clientEvent(int)), &Socket::sock(), SLOT(log(int)) ); // LIGHT BOX lightBox = new QLightBoxWidget(this); QHBoxLayout *mainLayout = new QHBoxLayout( lightBox ); QWidget *fm = new QWidget(); fm->setObjectName("connexionFrame"); mainLayout->addWidget( fm ); QGridLayout *lightBoxLayout = new QGridLayout( fm ); lightBoxLayout->setRowStretch(1, 1); settings = new QSettings("smoky.ini",QSettings::IniFormat); lightBoxLayout->addWidget( new QLabel( "IP du serveur" ), 0, 0); lightBoxLayout->addWidget( serverIpEdt = new QLineEdit(), 0, 1 ); serverIpEdt->setInputMask( "000.000.000.000; " ); serverIpEdt->setText( settings->value("serverIp").toString() ); serverIpEdt->setObjectName( "serverIpEdt" ); lightBoxLayout->addWidget( localhostCbx = new QCheckBox("localhost"), 1,1); localhostCbx->setObjectName( "localhostCbx" ); connect( localhostCbx, SIGNAL( stateChanged(int)), SLOT(onLocalhostCbx(int)) ); lightBoxLayout->addWidget( loginIndication = new QLabel(), 1, 0); loginIndication->setObjectName( "loginIndication" ); loginIndication->setText("<center><small>Placez votre visage<br>face à la caméra</small></center>"); lightBoxLayout->addWidget( loginAvatarLbl = new QLabel(""), 2, 0, 2, 1); loginAvatarLbl->setObjectName( "loginAvatarLbl" ); lightBoxLayout->addWidget( loginUserEdt = new QLineEdit(), 2, 1); loginUserEdt->setPlaceholderText("Nom d'utilisateur"); loginUserEdt->setObjectName( "loginUserEdt" ); lightBoxLayout->addWidget( loginPasswordEdt = new QLineEdit(), 3, 1); loginPasswordEdt->setObjectName( "loginPasswordEdt" ); loginPasswordEdt->setEchoMode( QLineEdit::Password ); loginPasswordEdt->setPlaceholderText("Mot de passe"); lightBoxLayout->addWidget( loginSubmitBtn = new QPushButton("Connexion"), 4, 1); loginSubmitBtn->setObjectName( "loginSubmitBtn" ); lightBoxLayout->addWidget( statLbl = new QLabel( "" ), 5,0, 1, 2 ); statLbl->setObjectName( "statLbl" ); lightBox->show(); Camera *cam = new Camera(); t = new QThread(); mTimer = new QTimer(); mTimer->setInterval(1000/24); connect(mTimer, SIGNAL(timeout()), cam, SLOT(queryFrame()) ); connect( this, SIGNAL(startWork()), cam, SLOT(openCamera()) ); connect( this, SIGNAL(startWork()), mTimer, SLOT(start()) ); connect( cam, SIGNAL(stopCamera()), mTimer, SLOT(stop()) ); connect( this, SIGNAL(stopWork()), cam, SLOT(closeCamera()) ); /*destruction*/ // connect( qApp, SIGNAL(aboutToQuit()),mTimer, SLOT(stop()) ); // connect( qApp, SIGNAL(aboutToQuit()),mTimer, SLOT(deleteLater()) ); // connect( qApp, SIGNAL(aboutToQuit()), cam, SLOT(closeCamera()) ); // connect( qApp, SIGNAL(aboutToQuit()), cam, SLOT(deleteLater()) ); connect(t, SIGNAL(finished()), cam, SLOT(deleteLater())); // connect(this, &Controller::operate, worker, &Worker::doWork); //connect( qApp, SIGNAL(aboutToQuit()), t, SLOT(quit()) ); // connect( t, SIGNAL(finished()), t, SLOT(deleteLater()) ); // user logged out connect( &Socket::sock(), SIGNAL(userLoggedOut()), SLOT(startCamera()) ); // user logged in connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), SLOT(stopCamera()) ); cam->moveToThread( t ); mTimer->moveToThread( t ); t->start( QThread::IdlePriority ); emit startWork(); connect(cam, SIGNAL(sendShot(QImage, QRect)), SLOT(onShotSent(QImage)) ); // receive shots connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), loginPasswordEdt, SLOT(clear()) ); connect( &Socket::sock(), SIGNAL(userLoggedIn(QString)), lightBox, SLOT(hide()) ); // rendre la page d'accueil connect( &Socket::sock(), SIGNAL(userLoggedOut()), SLOT(resetThings()) ); connect( &Socket::sock(), SIGNAL(invalidCred()), SLOT(onInvalidCred()) ); connect( loginSubmitBtn, SIGNAL(clicked()), SLOT(connectUser()) ); connect( &Socket::sock(), SIGNAL(connexionError(int)), SLOT(onConnexionError(int)) ); // move(QApplication::desktop()->screen()->rect().center() - this->rect().center()); /* QDesktopWidget desktop; QRect desktop_geometry = desktop.screenGeometry(); */ // resize( 780, 650 ); /*int x = desktop_geometry.width()/2 - width()/2; int y = desktop_geometry.height()/2 - height()/2; move( x, y );*/ // showMaximized(); }