Skip to content

Commit

Permalink
#24 complete similar song found module[854003]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed May 4, 2016
1 parent 8e96b84 commit eae13e8
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 143 deletions.
6 changes: 2 additions & 4 deletions TTKCore/musicCore/MusicCore.pri
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ HEADERS += \
$$PWD/musiccoremplayer.h \
$$PWD/musicsong.h \
$$PWD/musiccryptographichash.h \
$$PWD/musicbackgroundmanager.h \
$$PWD/musicsemaphoreeventloop.h
$$PWD/musicbackgroundmanager.h

}

Expand Down Expand Up @@ -95,7 +94,6 @@ SOURCES += \
$$PWD/musiccoremplayer.cpp \
$$PWD/musicsong.cpp \
$$PWD/musiccryptographichash.cpp \
$$PWD/musicbackgroundmanager.cpp \
$$PWD/musicsemaphoreeventloop.cpp
$$PWD/musicbackgroundmanager.cpp

}
7 changes: 4 additions & 3 deletions TTKCore/musicCore/musicconnectionpool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,11 @@ void MusicConnectionPool::poolConnect(const QString &from, const QString &to)
QObject::connect(first, SIGNAL(musicBgDownloadFinished()), second,
SLOT(musicBgThemeDownloadFinished()));
}
else if(from == "MusicSongSearchOnlineTableWidget" && to == "MusicSongsSummarizied" )
else if(from == "MusicSongSearchOnlineTableWidget" && to == "MusicSongsSummarizied" ||
from == "MusicSimilarFoundWidget" && to == "MusicSongsSummarizied" )
{
QObject::connect(first, SIGNAL(muiscSongToPlayListChanged(QString,QString,QString)), second,
SLOT(addNetMusicSongToList(QString,QString,QString)));
QObject::connect(first, SIGNAL(muiscSongToPlayListChanged(QString,QString,QString,bool)), second,
SLOT(addNetMusicSongToList(QString,QString,QString,bool)));
}
else if(from == "MusicSongSearchOnlineTableWidget" && to == "MusicRightAreaWidget" )
{
Expand Down
39 changes: 0 additions & 39 deletions TTKCore/musicCore/musicsemaphoreeventloop.cpp

This file was deleted.

57 changes: 0 additions & 57 deletions TTKCore/musicCore/musicsemaphoreeventloop.h

This file was deleted.

8 changes: 4 additions & 4 deletions TTKCore/musicToolsetswidget/musicvolumegainwidget.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#include "musicvolumegainwidget.h"
#include "ui_musicvolumegainwidget.h"
#include "musicbackgroundmanager.h"
#include "musicsemaphoreeventloop.h"
#include "musicmessagebox.h"
#include "musicuiobject.h"

#include <QProcess>
#include <QEventLoop>
#include <QFileDialog>

#define GAIN_DEFAULT 89
Expand Down Expand Up @@ -173,7 +173,7 @@ void MusicVolumeGainWidget::addFileButtonClicked()
for(int i=orcount; i<m_paths.count(); ++i)
{
m_currentIndex = i;
MusicSemaphoreEventLoop loop;
QEventLoop loop(this);
connect(m_process, SIGNAL(finished(int)), &loop, SLOT(quit()));
m_process->start(MAKE_GAIN_AL, QStringList() << m_paths[i]);
loop.exec();
Expand All @@ -199,7 +199,7 @@ void MusicVolumeGainWidget::addFilesButtonClicked()
m_currentIndex = m_paths.count();
m_paths << info.absoluteFilePath();

MusicSemaphoreEventLoop loop;
QEventLoop loop(this);
connect(m_process, SIGNAL(finished(int)), &loop, SLOT(quit()));
m_process->start(MAKE_GAIN_AL, QStringList() << m_paths.last());
loop.exec();
Expand Down Expand Up @@ -251,7 +251,7 @@ void MusicVolumeGainWidget::applyButtonClicked()
ui->progressBarAll->setRange(0, ui->tableWidget->rowCount());
for(int i=0; i<ui->tableWidget->rowCount(); ++i)
{
MusicSemaphoreEventLoop loop;
QEventLoop loop(this);
connect(m_process, SIGNAL(finished(int)), &loop, SLOT(quit()));
m_process->start(MAKE_GAIN_AL, QStringList() << "-g" <<
ui->tableWidget->item(i, 2)->text() << m_paths[i]);
Expand Down
12 changes: 8 additions & 4 deletions TTKCore/musicToolswidget/musicsongssummarizied.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ void MusicSongsSummarizied::removeMusicSongToLovestListAt(int row)
}

void MusicSongsSummarizied::addNetMusicSongToList(const QString &name, const QString &time,
const QString &format)
const QString &format, bool play)
{
QString musicSong = MusicCryptographicHash().decrypt(name, DOWNLOAD_KEY);
const QString path = QString("%1%2.%3").arg(DATA_CACHED_AL).arg(name).arg(format);
Expand All @@ -301,9 +301,13 @@ void MusicSongsSummarizied::addNetMusicSongToList(const QString &name, const QSt
{
emit updatePlayLists(path);
}
///when download finished just play it at once
QToolBox::setCurrentIndex(MUSIC_NETWORK_LIST);
emit musicPlayIndex(m_musicFileNames[MUSIC_NETWORK_LIST].count() - 1, 0);

if(play)
{
///when download finished just play it at once
QToolBox::setCurrentIndex(MUSIC_NETWORK_LIST);
emit musicPlayIndex(m_musicFileNames[MUSIC_NETWORK_LIST].count() - 1, 0);
}
}

void MusicSongsSummarizied::addSongToPlayList(const QStringList &items)
Expand Down
2 changes: 1 addition & 1 deletion TTKCore/musicToolswidget/musicsongssummarizied.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public Q_SLOTS:
* Remove music song to lovest list by row.
*/
void addNetMusicSongToList(const QString &name, const QString &time,
const QString &format);
const QString &format, bool play);
/*!
* Add current network music to download to local.
*/
Expand Down
52 changes: 29 additions & 23 deletions TTKCore/musicWidget/musicsimilarfoundwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@
#include "musicdatadownloadthread.h"
#include "musiccryptographichash.h"
#include "musicnetworkthread.h"
#include "musicconnectionpool.h"
#include "musicuiobject.h"

#include <QBoxLayout>
#include <QGridLayout>
#include <QPushButton>
#include <QCheckBox>
#include <QEventLoop>

MusicSimilarFoundWidget::MusicSimilarFoundWidget(QWidget *parent)
: QWidget(parent)
Expand All @@ -29,15 +31,19 @@ MusicSimilarFoundWidget::MusicSimilarFoundWidget(QWidget *parent)
m_mainWindow->setLayout(mLayout);

#ifndef USE_MULTIPLE_QUERY
m_downloadThread = new MusicDownLoadQuerySingleThread(this);
m_downloadThread = new MusicDownLoadQuerySingleThread(this);
#else
m_downloadThread = new MusicDownLoadQueryMultipleThread(this);
m_downloadThread = new MusicDownLoadQueryMultipleThread(this);
#endif
connect(m_downloadThread, SIGNAL(resolvedSuccess()), SLOT(queryAllFinished()));

M_CONNECTION->setValue("MusicSimilarFoundWidget", this);
M_CONNECTION->poolConnect("MusicSimilarFoundWidget", "MusicSongsSummarizied");
}

MusicSimilarFoundWidget::~MusicSimilarFoundWidget()
{
M_CONNECTION->poolDisConnect("MusicSimilarFoundWidget");
while(!m_checkBoxs.isEmpty())
{
delete m_checkBoxs.takeLast();
Expand Down Expand Up @@ -87,7 +93,7 @@ void MusicSimilarFoundWidget::queryAllFinished()
data->m_songUrl = atrr.m_url;
data->m_format = atrr.m_format;
}
m_likeDownloadDatas <<data;
m_likeDownloadDatas << data;
}

createLabels();
Expand Down Expand Up @@ -228,10 +234,7 @@ void MusicSimilarFoundWidget::selectAllItems(bool all)

void MusicSimilarFoundWidget::playButtonClicked()
{
foreach(int index, foundCheckedItem())
{
downloadDataFrom(index);
}
downloadDataFrom(true);
}

void MusicSimilarFoundWidget::downloadButtonClicked()
Expand All @@ -246,26 +249,29 @@ void MusicSimilarFoundWidget::downloadButtonClicked()

void MusicSimilarFoundWidget::addButtonClicked()
{
playButtonClicked();
downloadDataFrom(false);
}

void MusicSimilarFoundWidget::downloadDataFrom(int row)
void MusicSimilarFoundWidget::downloadDataFrom(bool play)
{
if(!M_NETWORK->isOnline() || row < 0)
MIntList list = foundCheckedItem();
for(int i=0; i<list.count(); ++i)
{
return;
}

DownloadData *data = m_likeDownloadDatas[row];
QString musicEnSong = MusicCryptographicHash().encrypt(data->m_songArtist + " - " + data->m_songName, DOWNLOAD_KEY);
QString downloadName = QString("%1%2.%3").arg(DATA_CACHED_AL).arg(musicEnSong).arg(data->m_format);
MusicDataDownloadThread *downSong = new MusicDataDownloadThread( data->m_songUrl, downloadName,
MusicDownLoadThreadAbstract::Download_Music, this);
connect(downSong, SIGNAL(musicDownLoadFinished(QString)), SLOT(downloadDataFinished()));
downSong->startToDownload();
}
if(!M_NETWORK->isOnline())
{
continue;
}
DownloadData *data = m_likeDownloadDatas[ list[i] ];
QString musicEnSong = MusicCryptographicHash().encrypt(data->m_songArtist + " - " + data->m_songName, DOWNLOAD_KEY);
QString downloadName = QString("%1%2.%3").arg(DATA_CACHED_AL).arg(musicEnSong).arg(data->m_format);

void MusicSimilarFoundWidget::downloadDataFinished()
{
QEventLoop loop(this);
MusicDataDownloadThread *downSong = new MusicDataDownloadThread( data->m_songUrl, downloadName,
MusicDownLoadThreadAbstract::Download_Music, this);
connect(downSong, SIGNAL(musicDownLoadFinished(QString)), &loop, SLOT(quit()));
downSong->startToDownload();
loop.exec();

emit muiscSongToPlayListChanged(musicEnSong, data->m_time, data->m_format, play && (i == list.count() - 1));
}
}
15 changes: 9 additions & 6 deletions TTKCore/musicWidget/musicsimilarfoundwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ class MUSIC_WIDGET_EXPORT MusicSimilarFoundWidget : public QWidget
* Set current name to search founds.
*/

Q_SIGNALS:
void muiscSongToPlayListChanged(const QString &name, const QString &time,
const QString &format, bool play);
/*!
* Add current network music to download to local.
*/

public Q_SLOTS:
void queryAllFinished();
/*!
Expand All @@ -61,10 +68,6 @@ public Q_SLOTS:
/*!
* Add button clicked now.
*/
void downloadDataFinished();
/*!
* Download data finished.
*/

protected:
virtual void contextMenuEvent(QContextMenuEvent *event) override;
Expand All @@ -79,9 +82,9 @@ public Q_SLOTS:
/*!
* Found which items is checked.
*/
void downloadDataFrom(int row);
void downloadDataFrom(bool play);
/*!
* Download data from net by index.
* Download data from net and just play or not.
*/

QString m_songNameFull;
Expand Down
3 changes: 2 additions & 1 deletion TTKCore/musicWidget/musicsongsearchonlinewidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,8 @@ void MusicSongSearchOnlineTableWidget::searchDataDwonloadFinished()
{
if(m_downloadData.isValid())
{
emit muiscSongToPlayListChanged(m_downloadData.m_songName, m_downloadData.m_time, m_downloadData.m_format);
emit muiscSongToPlayListChanged(m_downloadData.m_songName, m_downloadData.m_time,
m_downloadData.m_format, true);
}
m_downloadData.clear();
}
Expand Down
2 changes: 1 addition & 1 deletion TTKCore/musicWidget/musicsongsearchonlinewidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class MUSIC_WIDGET_EXPORT MusicSongSearchOnlineTableWidget : public MusicQueryTa

Q_SIGNALS:
void muiscSongToPlayListChanged(const QString &name, const QString &time,
const QString &format);
const QString &format, bool play);
/*!
* Add current network music to download to local.
*/
Expand Down

0 comments on commit eae13e8

Please sign in to comment.