#include "Window.hpp" #include "../Client/Client.hpp" #include "../XML/XMLQueueParser.hpp" #include "../XML/XMLOnelinerParser.hpp" #include "../Animation/AnimatedText.hpp" #include "../Utils/Utils.hpp" #include "../global.hpp" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //#ifdef _DEBUG #include //#endif Window :: Window(const QString& windowName, const unsigned int width, const unsigned int height, QWidget* parent):QMainWindow(parent) { // Load the icons logo = new QIcon("data/favicon.png"); favIcon = new QIcon("data/heart_add.png"); redStar = new QIcon("data/star-red.png"); emptyStar = new QIcon("data/star-empty.png"); vote1Icon = new QIcon("data/rating_1.gif"); vote2Icon = new QIcon("data/rating_2.gif"); vote3Icon = new QIcon("data/rating_3.gif"); vote4Icon = new QIcon("data/rating_4.gif"); vote5Icon = new QIcon("data/rating_5.gif"); // Set the title this->setWindowTitle(windowName); this->resize(width, height); this->setWindowIcon(*logo); // Menu /** * - Connect * - Favorite * - Favorite last played * - Reload * ------------ * - Quit **/ QMenu* fileMenu = new QMenu(tr("&File"), this); { connectMenu = this->addAction(fileMenu, tr("&Identification"), tr("Ctrl+I"), tr("Connect to Nectarine"), this, SLOT(connection())); favoriteMenu = this->addAction(fileMenu, tr("&Fav current music"), tr("Ctrl+F"), tr("Add the current song in the favorite"), this, SLOT(favoriteMusic()), false); favoriteMenu->setIcon((*favIcon)); favoriteLastMenu = this->addAction(fileMenu, tr("&Fav last music"), tr("Ctrl+G"), tr("Add the previous song in the favorite"), this, SLOT(favoriteLastMusic()), false); this->addAction(fileMenu, tr("&Reload Queue"), tr("Ctrl+R"), tr("Reload the queue"), this, SLOT(reloadQueue())); fileMenu->addSeparator(); onelinerMenu = this->addAction(fileMenu, tr("R&eload Oneliner"), tr("Ctrl+E"), tr("Reload the oneliner"), this, SLOT(reloadOneliner())); fileMenu->addSeparator(); closeMenu = this->addAction(fileMenu, tr("&Quit"), tr("Ctrl+Q"), tr("Quit the application"), qApp, SLOT(quit())); // Add to the window this->menuBar()->addMenu(fileMenu); } // Vote /** * - Vote -> 1 * - Vote -> 2 * - Vote -> 3 * - Vote -> 4 * - Vote -> 5 **/ QMenu* voteMenu = new QMenu(tr("Vote"), this); { vote1 = this->addAction(voteMenu, tr("&Vote -> 1"), tr("Ctrl+1"), QString(tr("Vote 1 for the current song")), this, SLOT(voteScore1())); vote1->setEnabled(false); vote1->setIcon(*vote1Icon); vote2 = this->addAction(voteMenu, tr("&Vote -> 2"), tr("Ctrl+2"), QString(tr("Vote 2 for the current song")), this, SLOT(voteScore2())); vote2->setEnabled(false); vote2->setIcon(*vote2Icon); vote3 = this->addAction(voteMenu, tr("&Vote -> 3"), tr("Ctrl+3"), QString(tr("Vote 3 for the current song")), this, SLOT(voteScore3())); vote3->setEnabled(false); vote3->setIcon(*vote3Icon); vote4 = this->addAction(voteMenu, tr("&Vote -> 4"), tr("Ctrl+4"), QString(tr("Vote 4 for the current song")), this, SLOT(voteScore4())); vote4->setEnabled(false); vote4->setIcon(*vote4Icon); vote5 = this->addAction(voteMenu, tr("&Vote -> 5"), tr("Ctrl+5"), QString(tr("Vote 5 for the current song")), this, SLOT(voteScore5())); vote5->setEnabled(false); vote5->setIcon(*vote5Icon); // Add to the window this->menuBar()->addMenu(voteMenu); } // View /** * - Colours * ----------- * - Switch Music * - Switch Oneliner * ----------- * - Switch Notification **/ QMenu* viewMenu = new QMenu(tr("View"), this); { coloursMenu = this->addAction(viewMenu, tr("&Colours"), tr("Ctrl+F"), QString(tr("Set / Unset the colours")), this, SLOT(switchColours()), true, true); viewMenu->addSeparator(); musicSwitchMenu = this->addAction(viewMenu, tr("Switch &Music"), tr("Ctrl+M"), QString(tr("Set / Unset the music part")), this, SLOT(switchMusic()), true, true); onelinerSwitchMenu = this->addAction(viewMenu, tr("Switch One&liner"), tr("Ctrl+L"), QString(tr("Set / Unset the oneliner part")), this, SLOT(switchOneliner()), true, true); viewMenu->addSeparator(); notificationSwitchMenu = this->addAction(viewMenu, tr("Switch &Notification"), tr("Ctrl+N"), QString(tr("Set / Unset the notification")), this, SLOT(switchNotification()), true, true); // Add to the window this->menuBar()->addMenu(viewMenu); } // History /** * - Load History * - Save History **/ QMenu* historyMenu = new QMenu(tr("History"), this); { this->addAction(historyMenu, tr("&Open History"), tr("Ctrl+O"), QString(tr("Open the history of the oneliner")), this, SLOT(loadHistoryMenu()), true, false); this->addAction(historyMenu, tr("&Save History"), tr("Ctrl+S"), QString(tr("Save the history of the oneliner")), this, SLOT(saveHistoryMenu()), true, false); // Add to the window this->menuBar()->addMenu(historyMenu); } // Help /** * - About **/ QMenu* helpMenu = new QMenu(tr("?"), this); { this->addAction(helpMenu, tr("&About"), tr("F1"), QString(tr("About this "))+QString(APPLICATION_NAME), this, SLOT(aboutBox())); // Add to the window this->menuBar()->addMenu(helpMenu); } // Set the client that getting the queue xml file client = new Client(this, this->statusBar()); // Connect the done signal with the parser connect(client, SIGNAL(done(bool)), this, SLOT(updateXmlFile(bool))); // Set the xml parser for the queue xmlQueueParser = new XMLQueueParser(); /* Hierarchie: * QWidget -> QGridLayout -> QGroupBox "Playing now" -> QVBoxLayout -> QLabel "Name --- Artist" * -> QSlider "Song position" * -> QLabel "Song position" * -> QTableWidget "Pending" * -> QTableWidget " */ // Set the box to contain all the elements QWidget* centralBox = new QWidget(this); this->setCentralWidget(centralBox); centralBox->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); // Global GridLayout globalHBox = new QHBoxLayout(centralBox); musicFrame = new QFrame(this); musicVBox = new QVBoxLayout(musicFrame); globalHBox->addWidget(musicFrame); // Group box for the now playing information nowGroupBox = new QGroupBox(tr("Now Playing:"),centralBox); musicVBox->addWidget(nowGroupBox); // VBoxLayout for the information nowSongBox = new QVBoxLayout(nowGroupBox); // Label for the name --- artist information songLabel = new QLabel(tr("No song for the moment"),nowGroupBox); songLabel->setAlignment(Qt::AlignHCenter); nowSongBox->addWidget(songLabel); // Position slider songPositionSlider = new QSlider(Qt::Horizontal,nowGroupBox); songPositionSlider->setEnabled(false); // Avoid to be controlled by the user nowSongBox->addWidget(songPositionSlider); // Label for the song position songTimeLabel = new QLabel("",nowGroupBox); songTimeLabel->setAlignment(Qt::AlignHCenter); nowSongBox->addWidget(songTimeLabel); // Construct the rest of the window (two tables) /* QTable construction: * Set the number of columns * Set the number of rows * Set to use the alternating colors * Disable the word wrap * Set the size policy * Add the widget into the QVBoxLayout */ // QTable for the pending list requestQueueTable = new QTableWidget(centralBox); requestQueueTable->setColumnCount(NB_COLUMNS_MUSIC); requestQueueTable->setRowCount(20); requestQueueTable->setAlternatingRowColors(true); requestQueueTable->setWordWrap(false); //requestQueueTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); musicVBox->addWidget(requestQueueTable,1,0); // Set the header for the pending list requestQueueTable->setHorizontalHeaderLabels(QStringList() << tr("Request at") << tr("ID Artist") << tr("Artist") << tr("ID Song") << tr("Length") << tr("Song") << tr("ID Requester") << tr("Requester")); QHeaderView* requestHeaderView = new QHeaderView(Qt::Horizontal, requestQueueTable); //requestHeaderView->setResizeMode(QHeaderView::Stretch); requestQueueTable->setHorizontalHeader(requestHeaderView); // QTable for the history list historyQueueTable = new QTableWidget(centralBox); historyQueueTable->setColumnCount(NB_COLUMNS_MUSIC); historyQueueTable->setRowCount(NB_HISTORY_ROWS); historyQueueTable->setAlternatingRowColors(true); historyQueueTable->setWordWrap(false); //historyQueueTable->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); musicVBox->addWidget(historyQueueTable,2,0); // Set the header for the history list historyQueueTable->setHorizontalHeaderLabels(QStringList() << tr("Request at") << tr("ID Artist") << tr("Artist") << tr("ID Song") << tr("Length") << tr("Song") << tr("ID Requester") << tr("Requester")); QHeaderView* historyHeaderView = new QHeaderView(Qt::Horizontal, historyQueueTable); //historyHeaderView->setResizeMode(QHeaderView::ResizeToContents); historyQueueTable->setHorizontalHeader(historyHeaderView); /* Remove the ID information to the user * 1 -> the ID of the artist * 3 -> the ID of the song * 6 -> the ID of the requester */ requestQueueTable->setColumnHidden(1,true); historyQueueTable->setColumnHidden(1,true); requestQueueTable->setColumnHidden(3,true); historyQueueTable->setColumnHidden(3,true); requestQueueTable->setColumnHidden(6,true); historyQueueTable->setColumnHidden(6,true); /* * Set the oneliner * Hierarchie -> * QGroupBox -> QVboxLayout -> QTableWidget -> Date * -> Author * -> Message * -> QLineEdit */ onelinerBox = new QGroupBox(tr("Oneliner:"),centralBox); globalHBox->addWidget(onelinerBox); onelinerVBox = new QVBoxLayout(onelinerBox); onelinerViewer = new AnimatedText(onelinerBox); //onelinerVBox->addWidget(onelinerViewerTable); onelinerVBox->addWidget(onelinerViewer); onelinerViewer->setReadOnly(true); //onelinerViewerTable->setColumnCount(NB_COLUMNS_ONELINER); //onelinerViewerTable->setRowCount(NB_HISTORY_ROWS); //onelinerViewerTable->setAlternatingRowColors(true); //onelinerViewerTable->setWordWrap(false); // Set the header for the history list //onelinerViewerTable->setHorizontalHeaderLabels(QStringList() << tr("Date") << tr("Author") << tr("Message")); //QHeaderView* onelinerHeaderView = new QHeaderView(Qt::Horizontal, onelinerViewerTable); //onelinerViewerTable->setHorizontalHeader(onelinerHeaderView); onelinerChat = NULL; // Will be set later favoriteButton = NULL; voteBox = NULL; voteButton1 = NULL; voteButton2 = NULL; voteButton3 = NULL; voteButton4 = NULL; voteButton5 = NULL; // Set the xml parser for the oneliner xmlOnelinerParser = new XMLOnelinerParser(onelinerViewer); // Trayicon if ( QSystemTrayIcon::isSystemTrayAvailable() ) { /** * Special menu for the QSystemTrayIcon * * - Connect * - Favorite * ---------------- * - Vote buttons * ---------------- * - Close * **/ QMenu* trayMenu = new QMenu(this); { trayMenu->addAction(connectMenu); trayMenu->addAction(favoriteMenu); trayMenu->addSeparator(); trayMenu->addAction(vote1); trayMenu->addAction(vote2); trayMenu->addAction(vote3); trayMenu->addAction(vote4); trayMenu->addAction(vote5); trayMenu->addSeparator(); trayMenu->addAction(closeMenu); } trayIcon = new QSystemTrayIcon(*logo, this); trayIcon->setContextMenu(trayMenu); trayIcon->show(); } else trayIcon = NULL; // Timers // Set the update timer for the queue updateQueueTimer = new QTimer(this); updateQueueTimer->setInterval(WAITING_TIME_NOCHANGED); connect(updateQueueTimer, SIGNAL(timeout()), this, SLOT(reloadQueue())); std::cout << "Timer Start: " << updateQueueTimer->interval() << std::endl; updateOnelinerTimer = new QTimer(this); connect(updateOnelinerTimer, SIGNAL(timeout()), this, SLOT(reloadOneliner())); // Timer to update the position of the slider (and the label too) updateSliderTimer = new QTimer(nowGroupBox); updateSliderTimer->setInterval(1000); connect(updateSliderTimer, SIGNAL(timeout()), this, SLOT(updateSlider())); // Will be use only for the connection button updateFavoriteButton = new QTimer(this); connect(updateFavoriteButton, SIGNAL(timeout()), this, SLOT(checkIfConnected())); resizeTimer = new QTimer(this); resizeTimer->setInterval(WAIT_RESIZE); connect(resizeTimer, SIGNAL(timeout()), this, SLOT(resizeTables())); // Starting process updateQueueTimer->start(); // Equivalent to client->forceQueueRequest(); updateOnelinerTimer->start(WAITING_TIME_NOCHANGED); updateSliderTimer->start(); updateFavoriteButton->start(WAITING_TIME_IDENTIFIED); resizeTimer->start(); notification = true; } Window :: ~Window(void) { updateQueueTimer->stop(); delete updateQueueTimer; updateQueueTimer = NULL; updateOnelinerTimer->stop(); delete updateOnelinerTimer; updateOnelinerTimer = NULL; updateFavoriteButton->stop(); delete updateFavoriteButton; updateFavoriteButton = NULL; resizeTimer->stop(); delete resizeTimer; resizeTimer = NULL; delete client; delete xmlQueueParser; delete xmlOnelinerParser; delete updateSliderTimer; delete songLabel; delete songTimeLabel; delete songPositionSlider; delete onelinerViewer; delete onelinerChat; delete requestQueueTable; delete historyQueueTable; delete favoriteButton; /*delete voteButton1; delete voteButton2; delete voteButton3; delete voteButton4; delete voteButton5;*/ delete voteBox; // Will suppress the buttons contains in it delete nowSongBox; delete nowGroupBox; //delete globalHBox; delete musicVBox; delete onelinerVBox; delete musicFrame; delete vote1; delete vote2; delete vote3; delete vote4; delete vote5; delete onelinerMenu; delete favoriteMenu; delete connectMenu; delete closeMenu; delete coloursMenu; delete musicSwitchMenu; delete onelinerSwitchMenu; delete notificationSwitchMenu; delete logo; delete favIcon; delete redStar; delete emptyStar; delete vote1Icon; delete vote2Icon; delete vote3Icon; delete vote4Icon; delete vote5Icon; if ( trayIcon ) delete trayIcon; } QAction* Window :: addAction(QMenu* parentMenu,const QString& entryName, const QString& keySequence, const QString& statusTipMessage, const QObject* object, const char* slot, const bool enabled, const bool checkable) { QAction* action = new QAction(0); action = parentMenu->addAction(entryName); action->setShortcut(QKeySequence(keySequence)); action->setStatusTip(statusTipMessage); action->setEnabled(enabled); action->setCheckable(checkable); action->setChecked(checkable); connect(action, SIGNAL(triggered()), object, slot); return action; } void Window :: setFavoriteButton(void) { if ( favoriteButton == NULL ) { favoriteButton = new QPushButton(tr("Favorite it !"), this); favoriteButton->setIcon((*favIcon)); nowSongBox->addWidget(favoriteButton); connect(favoriteButton, SIGNAL(clicked()), this, SLOT(favoriteMusic())); } } void Window :: setVoteButton(void) { if ( voteButton1 == NULL && voteButton2 == NULL && voteButton3 == NULL && voteButton4 == NULL && voteButton5 == NULL ) { QSizePolicy policy(QSizePolicy::Maximum,QSizePolicy::Maximum); voteBox = new QHBoxLayout(); nowSongBox->addLayout(voteBox); voteButton1 = new QPushButton(this); voteBox->addWidget(voteButton1); voteButton1->setIcon((*emptyStar)); voteButton1->setFlat(true); voteButton1->setSizePolicy(policy); connect(voteButton1, SIGNAL(clicked()), this, SLOT(voteScore1())); voteButton2 = new QPushButton(this); voteBox->addWidget(voteButton2); voteButton2->setIcon((*emptyStar)); voteButton2->setFlat(true); voteButton2->setSizePolicy(policy); connect(voteButton2, SIGNAL(clicked()), this, SLOT(voteScore2())); voteButton3 = new QPushButton(this); voteBox->addWidget(voteButton3); voteButton3->setIcon((*emptyStar)); voteButton3->setFlat(true); voteButton3->setSizePolicy(policy); connect(voteButton3, SIGNAL(clicked()), this, SLOT(voteScore3())); voteButton4 = new QPushButton(this); voteBox->addWidget(voteButton4); voteButton4->setIcon((*emptyStar)); voteButton4->setFlat(true); voteButton4->setSizePolicy(policy); connect(voteButton4, SIGNAL(clicked()), this, SLOT(voteScore4())); voteButton5 = new QPushButton(this); voteBox->addWidget(voteButton5); voteButton5->setIcon((*emptyStar)); voteButton5->setFlat(true); voteButton5->setSizePolicy(policy); connect(voteButton5, SIGNAL(clicked()), this, SLOT(voteScore5())); voteBox->setAlignment(Qt::AlignCenter); } } void Window :: setOnelinerChat(void) { onelinerChat = new QLineEdit(onelinerBox); onelinerVBox->addWidget(onelinerChat); connect(onelinerChat, SIGNAL(returnPressed()), this, SLOT(sendMessage())); } void Window :: updateQueue(void) { xmlQueueParser->read(client->getQueueData(), songLabel, requestQueueTable, historyQueueTable); unsigned int songLength = xmlQueueParser->getSongLength(); unsigned int songPosition = songLength - xmlQueueParser->getSecondsLeft(); songLengthMin = songLength / 60; songLengthSec = songLength % 60; songPositionMin = songPosition / 60; songPositionSec = songPosition % 60; songPositionSlider->setMaximum(songLength); songPositionSlider->setValue(songPosition); songTimeLabel->setText(QString("%1:%2 / %3:%4").arg(songPositionMin).arg(songPositionSec,2,10,QLatin1Char('0')).arg(songLengthMin).arg(songLengthSec,2,10,QLatin1Char('0'))); if ( updateQueueTimer ) { if ( xmlQueueParser->getSecondsLeft() == 0 ) { updateQueueTimer->start(WAITING_TIME_NOCHANGED); std::cout << "Timer Sec = 0: " << updateQueueTimer->interval() << " Sec= " << xmlQueueParser->getSecondsLeft() << std::endl; } else { updateQueueTimer->start(xmlQueueParser->getSecondsLeft()*1000); std::cout << "Timer Normal: " << updateQueueTimer->interval() << std::endl; // Set the window name this->setWindowTitle(xmlQueueParser->getCurrentSongName() + QString(TITLE_SEPARATOR) + xmlQueueParser->getCurrentArtistName() + QString(TITLE_SEPARATOR) + QString(APPLICATION_NAME)); if ( notification ) trayIcon->showMessage(APPLICATION_NAME + QString(tr(" - Music: ")), xmlQueueParser->getCurrentSongName() + QString(TITLE_SEPARATOR) + xmlQueueParser->getCurrentArtistName(), QSystemTrayIcon::NoIcon, 4000); } #ifdef _DEBUG std::cout << "Timer Interval: " << updateQueueTimer->interval() << std::endl; #endif } // In case of the user click on the button if ( client->isIdentified() == true ) { if ( favoriteButton ) if ( favoriteButton->isEnabled() == false ) { favoriteButton->setEnabled(true); // We enable the button for the next song favoriteButton->setText(tr("Favorite it!")); } if ( favoriteMenu->isEnabled() == false ) favoriteMenu->setEnabled(true); if ( vote1->isEnabled() == false ) vote1->setEnabled(true); if ( vote2->isEnabled() == false ) vote2->setEnabled(true); if ( vote3->isEnabled() == false ) vote3->setEnabled(true); if ( vote4->isEnabled() == false ) vote4->setEnabled(true); if ( vote5->isEnabled() == false ) vote5->setEnabled(true); } if ( client->isIdentified() && xmlQueueParser->getIdSongLastPlayed() != 0 ) favoriteLastMenu->setEnabled(true); } void Window :: updateOneliner(void) { xmlOnelinerParser->read(client->getOnelinerData()); //xmlOnelinerParser->fillTable(onelinerViewerTable); if ( notification ) if ( xmlOnelinerParser->getIsNewMessage() ) trayIcon->showMessage(APPLICATION_NAME + QString(tr(" - Oneliner: ")), xmlOnelinerParser->getNewMessage().author + QString(": ") + xmlOnelinerParser->getNewMessage().message, QSystemTrayIcon::NoIcon, 5000); if ( updateOnelinerTimer ) { updateOnelinerTimer->start(WAITING_TIME_ONELINER); } } /*********************************************************************** * -> Slots **********************************************************************/ void Window :: aboutBox(void) { QMessageBox::information(this, tr("About"), QString("\t")+QString(APPLICATION_NAME)+QString("\n\n")+tr("Created by ")+QString("Alexandre LAURENT - Copyright 2009\n\tthedograge@hotmail.fr")); } void Window :: connection(void) { client->forceConnection(this); } void Window :: checkIfConnected(void) { if ( client->isIdentified() ) { setFavoriteButton(); setVoteButton(); setOnelinerChat(); // Change the state of the menus connectMenu->setEnabled(false); favoriteMenu->setEnabled(true); onelinerMenu->setEnabled(true); vote1->setEnabled(true); vote2->setEnabled(true); vote3->setEnabled(true); vote4->setEnabled(true); vote5->setEnabled(true); client->forceOnelinerRequest(); disconnect(updateFavoriteButton, SIGNAL(timeout()), this, SLOT(checkIfConnected())); } else { updateFavoriteButton->start(WAITING_TIME_IDENTIFIED); } } void Window :: favoriteMusic(void) { client->sendAddToFavorite(xmlQueueParser->getIdSongNowPlayed()); favoriteMenu->setEnabled(false); favoriteButton->setEnabled(false); favoriteButton->setText(tr("This song is now in your favorite list!")); } void Window :: favoriteLastMusic(void) { client->sendAddToFavorite(xmlQueueParser->getIdSongLastPlayed()); favoriteLastMenu->setEnabled(false); } void Window :: reloadQueue(void) { // In case if the server doesn't respond we reset the timer updateQueueTimer->start(WAITING_TIME_NOCHANGED); client->forceQueueRequest(); } void Window :: reloadOneliner(void) { client->forceOnelinerRequest(); } void Window :: sendMessage(void) { client->sendMessage(onelinerChat->text()); onelinerChat->clear(); } void Window :: voteScore1(void) { client->sendVote(xmlQueueParser->getIdSongNowPlayed(),1); voteButton1->setIcon((*redStar)); voteButton2->setIcon((*emptyStar)); voteButton3->setIcon((*emptyStar)); voteButton4->setIcon((*emptyStar)); voteButton5->setIcon((*emptyStar)); vote1->setEnabled(false); } void Window :: voteScore2(void) { client->sendVote(xmlQueueParser->getIdSongNowPlayed(),2); voteButton1->setIcon((*redStar)); voteButton2->setIcon((*redStar)); voteButton3->setIcon((*emptyStar)); voteButton4->setIcon((*emptyStar)); voteButton5->setIcon((*emptyStar)); vote2->setEnabled(false); } void Window :: voteScore3(void) { client->sendVote(xmlQueueParser->getIdSongNowPlayed(),3); voteButton1->setIcon((*redStar)); voteButton2->setIcon((*redStar)); voteButton3->setIcon((*redStar)); voteButton4->setIcon((*emptyStar)); voteButton5->setIcon((*emptyStar)); vote3->setEnabled(false); } void Window :: voteScore4(void) { client->sendVote(xmlQueueParser->getIdSongNowPlayed(),4); voteButton1->setIcon((*redStar)); voteButton2->setIcon((*redStar)); voteButton3->setIcon((*redStar)); voteButton4->setIcon((*redStar)); voteButton5->setIcon((*emptyStar)); vote4->setEnabled(false); } void Window :: voteScore5(void) { client->sendVote(xmlQueueParser->getIdSongNowPlayed(),5); voteButton1->setIcon((*redStar)); voteButton2->setIcon((*redStar)); voteButton3->setIcon((*redStar)); voteButton4->setIcon((*redStar)); voteButton5->setIcon((*redStar)); vote5->setEnabled(false); } void Window :: loadHistoryMenu(void) { QString fileName = QFileDialog::getOpenFileName(this, tr("Open oneliner history"), QDir::currentPath(), tr("Text (*.txt)")); if ( fileName != "" ) if ( !(xmlOnelinerParser->loadHistory(fileName)) ) QMessageBox::warning(this, APPLICATION_NAME, tr("The application couldn't open the history file that you have mentionned.\nSorry for this annoyance.")); else { //xmlOnelinerParser->fillTable(onelinerViewerTable); } } void Window :: saveHistoryMenu(void) { QString fileName = QFileDialog::getSaveFileName(this, tr("Save oneliner history"), QDir::currentPath(), tr("Text (*.txt)")); if ( fileName != "" ) if ( !(xmlOnelinerParser->saveHistory(fileName)) ) QMessageBox::warning(this, APPLICATION_NAME, tr("The application couldn't open a file to save the history.\nSorry for this annoyance.")); } void Window :: updateXmlFile(bool error) { if ( error == true && client->isQueueReady() == true ) // Check to know if the queue request goes wrong { // Set the timer with a short time if ( updateQueueTimer ) { updateQueueTimer->start(WAITING_TIME_NOCHANGED); std::cout << "Timer Error: " << updateQueueTimer->interval() << std::endl; } songLabel->setText(tr("No song for the moment")); songTimeLabel->setText(tr("")); return; } if ( error == true && client->isOnelinerReady() == true ) // Check to know if the oneliner request goes wrong { // Set the timer with a short time if ( updateOnelinerTimer ) updateOnelinerTimer->start(WAITING_TIME_NOCHANGED); return; } //xmlParser->addData(client->getData()); if ( client->isQueueReady() ) { updateQueue(); } if ( client->isOnelinerReady() ) { updateOneliner(); } } void Window :: updateSlider(void) { songPositionSlider->setValue(songPositionSlider->value()+1); updateSliderTimer->start(); songPositionSec++; if ( songPositionSec == 60u ) { songPositionSec = 0; songPositionMin++; } if ( songPositionMin >= songLengthMin && songPositionSec >= songLengthSec ) { songPositionMin = songLengthMin; songPositionSec = songLengthSec; } songTimeLabel->setText(QString("%1:%2 / %3:%4").arg(songPositionMin).arg(songPositionSec,2,10,QLatin1Char('0')).arg(songLengthMin).arg(songLengthSec,2,10,QLatin1Char('0'))); this->setWindowTitle(xmlQueueParser->getCurrentSongName() + QString(TITLE_SEPARATOR) + xmlQueueParser->getCurrentArtistName() + QString(TITLE_SEPARATOR) + QString("%1:%2 / %3:%4").arg(songPositionMin).arg(songPositionSec,2,10,QLatin1Char('0')).arg(songLengthMin).arg(songLengthSec,2,10,QLatin1Char('0')) + QString(TITLE_SEPARATOR) + QString(APPLICATION_NAME)); if ( notification ) { trayIcon->setToolTip(xmlQueueParser->getCurrentSongName() + QString(TITLE_SEPARATOR) + xmlQueueParser->getCurrentArtistName() + QString(TITLE_SEPARATOR) + QString("%1:%2 / %3:%4").arg(songPositionMin).arg(songPositionSec,2,10,QLatin1Char('0')).arg(songLengthMin).arg(songLengthSec,2,10,QLatin1Char('0')) + QString("\n\t-----\n") + xmlOnelinerParser->getNewMessage().author + QString(": ") + xmlOnelinerParser->getNewMessage().message); } } void Window :: switchColours(void) { xmlQueueParser->useColours(coloursMenu->isChecked()); xmlOnelinerParser->useColours(coloursMenu->isChecked()); if ( !coloursMenu->isChecked() ) { Utils::removeColours(requestQueueTable); Utils::removeColours(historyQueueTable); //Utils::removeColours(onelinerViewerTable); } else { this->reloadQueue(); } } void Window::switchMusic(void) { musicFrame->setVisible(musicSwitchMenu->isChecked()); } void Window::switchOneliner(void) { onelinerBox->setVisible(onelinerSwitchMenu->isChecked()); } void Window::switchNotification(void) { notification = notificationSwitchMenu->isChecked(); trayIcon->setVisible(notificationSwitchMenu->isChecked()); } void Window :: resizeTables(void) { requestQueueTable->resizeColumnsToContents(); historyQueueTable->resizeColumnsToContents(); //onelinerViewerTable->resizeColumnsToContents(); resizeTimer->start(); } /*********************************************************************** * Functions **********************************************************************/