2017-11-29 20:59:54 +03:00
|
|
|
|
#include "mainwindow.h"
|
|
|
|
|
#include "ui_mainwindow.h"
|
2017-12-03 23:08:43 +03:00
|
|
|
|
|
2017-11-29 21:36:29 +03:00
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QMessageBox>
|
2017-11-29 20:59:54 +03:00
|
|
|
|
|
2017-12-03 23:08:43 +03:00
|
|
|
|
|
2017-11-29 20:59:54 +03:00
|
|
|
|
MainWindow::MainWindow(QWidget *parent) :
|
|
|
|
|
QMainWindow(parent),
|
|
|
|
|
ui(new Ui::MainWindow)
|
|
|
|
|
{
|
|
|
|
|
ui->setupUi(this);
|
2017-11-29 21:36:29 +03:00
|
|
|
|
source = new syncLib::Sync();
|
|
|
|
|
ui->horizontalSlider_Value->setMaximum(100);
|
2017-12-03 23:08:43 +03:00
|
|
|
|
ui->horizontalSlider_Value->setValue(source->getValume());
|
2017-12-04 19:23:33 +03:00
|
|
|
|
|
2017-12-03 23:08:43 +03:00
|
|
|
|
songModel.setSource(source->getPlayList());
|
2017-12-04 19:23:33 +03:00
|
|
|
|
playList = &(source->getServersList());
|
|
|
|
|
serverModel.setSource(playList);
|
|
|
|
|
|
2017-12-03 23:08:43 +03:00
|
|
|
|
ui->localSongsView->setModel(&songModel);
|
2017-12-04 19:23:33 +03:00
|
|
|
|
ui->ServersView->setModel(&serverModel);
|
|
|
|
|
|
2017-12-03 23:08:43 +03:00
|
|
|
|
ui->localSongsView->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
|
2017-12-05 16:47:45 +03:00
|
|
|
|
ui->ServersView->horizontalHeader()->setSectionResizeMode(1,QHeaderView::Stretch);
|
|
|
|
|
|
2017-12-03 23:08:43 +03:00
|
|
|
|
ui->horizontalSlider_Seek->setMaximum(1000000);
|
|
|
|
|
|
|
|
|
|
connect(source,SIGNAL(seekChanged(qint64)),SLOT(on_seekChanged(qint64)));
|
2017-12-04 19:23:33 +03:00
|
|
|
|
connect(source,SIGNAL(networkStateChange()),SLOT(on_network_state_changed()));
|
2017-12-03 23:08:43 +03:00
|
|
|
|
|
2017-11-29 20:59:54 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
|
{
|
|
|
|
|
delete ui;
|
2017-11-29 21:36:29 +03:00
|
|
|
|
delete source;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_Play_clicked()
|
|
|
|
|
{
|
|
|
|
|
|
2017-12-03 23:08:43 +03:00
|
|
|
|
int curentSong = ui->localSongsView->currentIndex().row();
|
|
|
|
|
if(!source->play(songModel.data(songModel.index(curentSong, 0), Qt::DisplayRole).toInt())){
|
|
|
|
|
QMessageBox::critical(this,tr("Error"),tr("Сould not play the file you selected."));
|
2017-11-29 21:36:29 +03:00
|
|
|
|
}
|
2017-12-03 23:08:43 +03:00
|
|
|
|
|
2017-11-29 21:36:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_Pause_clicked()
|
|
|
|
|
{
|
2017-12-03 23:08:43 +03:00
|
|
|
|
if(ui->Pause->text() == "Play"){
|
|
|
|
|
source->pause(false);
|
|
|
|
|
ui->Pause->setText("Pause");
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
source->pause(true);
|
|
|
|
|
ui->Pause->setText("Play");
|
|
|
|
|
|
|
|
|
|
}
|
2017-11-29 21:36:29 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_Stop_clicked()
|
|
|
|
|
{
|
|
|
|
|
source->stop();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_Search_clicked()
|
|
|
|
|
{
|
|
|
|
|
if(source->getServersList().isEmpty())
|
|
|
|
|
source->scan();
|
|
|
|
|
else{
|
|
|
|
|
ETcpSocket * server = source->getServersList().front();
|
|
|
|
|
if(!source->listen(server)){
|
2018-01-11 23:01:47 +03:00
|
|
|
|
QMessageBox::critical(this,tr("Error"),tr("Сould not listen the finded server - %0").arg(server->peerName()));
|
2017-11-29 21:36:29 +03:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_horizontalSlider_Value_valueChanged(int value)
|
|
|
|
|
{
|
2017-12-03 23:08:43 +03:00
|
|
|
|
source->setValume(value);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_listen_clicked()
|
|
|
|
|
{
|
2017-12-04 19:23:33 +03:00
|
|
|
|
int curentServer = ui->ServersView->currentIndex().row();
|
|
|
|
|
if(!source->listen((*playList)[curentServer])){
|
|
|
|
|
QMessageBox::critical(this,tr("Error"),tr("Сould not play the file you selected."));
|
|
|
|
|
}
|
2017-12-03 23:08:43 +03:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_Select_clicked()
|
|
|
|
|
{
|
|
|
|
|
QStringList songs = QFileDialog::getOpenFileNames(this);
|
|
|
|
|
|
|
|
|
|
for(QString url:songs){
|
|
|
|
|
source->addNewSong(url);
|
|
|
|
|
songModel.refresh();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_horizontalSlider_Seek_sliderReleased(){
|
|
|
|
|
source->jump(ui->horizontalSlider_Seek->value() / 1000000.0 * source->getEndPoint());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void MainWindow::on_seekChanged(qint64 value){
|
|
|
|
|
ui->horizontalSlider_Seek->setValue(value * 1000000 / source->getEndPoint());
|
2017-11-29 20:59:54 +03:00
|
|
|
|
}
|
2017-12-04 19:23:33 +03:00
|
|
|
|
|
|
|
|
|
void MainWindow::on_network_state_changed(){
|
|
|
|
|
serverModel.refresh();
|
|
|
|
|
}
|