Skip to content

Commit

Permalink
Optimized wifi connection option[152233]
Browse files Browse the repository at this point in the history
  • Loading branch information
Greedysky committed Mar 6, 2017
1 parent aa91fcf commit 007d946
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 25 deletions.
6 changes: 5 additions & 1 deletion TTKCore/musicCoreKits/musicsettingmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class MUSIC_CORE_EXPORT MusicSettingManager : public QObject
LastPlayIndexChoiced, ///*Last Play Index Parameter*/
CloseNetWorkChoiced, ///*Close NetWork Parameter*/
FileAssociationChoiced, ///*File Association Parameter*/
MobileDevicePathChoiced, ///*Set Mobile Device Path Parameter*/
ExtraDevicePathChoiced, ///*Set Extra Device Path Parameter*/

BgThemeChoiced, ///*Bg Theme Parameter*/
BgTransparentChoiced, ///*Bg Transparent Parameter*/
Expand Down Expand Up @@ -105,6 +105,10 @@ class MUSIC_CORE_EXPORT MusicSettingManager : public QObject
DownloadDLoadLimitChoiced, ///*Download DLoad Limit Parameter*/
DownloadULoadLimitChoiced ///*Download ULoad Limit Parameter*/

#ifdef MUSIC_MOBILE
,MobileWifiConnectChoiced ///*Mobile Wifi Connect Parameter*/
#endif

};

static QString getClassName()
Expand Down
4 changes: 2 additions & 2 deletions TTKCore/musicToolsKits/musicconnecttransferwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ void MusicConnectTransferWidget::startToTransferUSBFiles()
}

m_ui->switchButton->setEnabled(false);
QString path = M_SETTING_PTR->value(MusicSettingManager::MobileDevicePathChoiced).toString();
QString path = M_SETTING_PTR->value(MusicSettingManager::ExtraDevicePathChoiced).toString();
if(path.isEmpty())
{
path = getRemovableDrive();
Expand Down Expand Up @@ -263,7 +263,7 @@ void MusicConnectTransferWidget::startToTransferWIFIFiles()

void MusicConnectTransferWidget::reflashRemovableDir()
{
QString path = M_SETTING_PTR->value(MusicSettingManager::MobileDevicePathChoiced).toString();
QString path = M_SETTING_PTR->value(MusicSettingManager::ExtraDevicePathChoiced).toString();
if(path.isEmpty())
{
path = getRemovableDrive();
Expand Down
4 changes: 2 additions & 2 deletions TTKCore/musicapplicationobject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void MusicApplicationObject::winEvent(MSG *msg, long *)
}
QString dev((char)(i + 'A'));
M_LOGGER_INFO(QString("USB_Arrived and The USBDisk is: %1").arg(dev));
M_SETTING_PTR->setValue(MusicSettingManager::MobileDevicePathChoiced, dev + ":/");
M_SETTING_PTR->setValue(MusicSettingManager::ExtraDevicePathChoiced, dev + ":/");
delete m_mobileDevices;
m_mobileDevices = new MusicMobileDevicesWidget;
m_mobileDevices->show();
Expand All @@ -144,7 +144,7 @@ void MusicApplicationObject::winEvent(MSG *msg, long *)
if (lpdbv -> dbcv_flags == 0)
{
M_LOGGER_INFO("USB_remove");
M_SETTING_PTR->setValue(MusicSettingManager::MobileDevicePathChoiced, QString());
M_SETTING_PTR->setValue(MusicSettingManager::ExtraDevicePathChoiced, QString());
delete m_mobileDevices;
m_mobileDevices = nullptr;
}
Expand Down
4 changes: 4 additions & 0 deletions TTKMobile/MobileCore/ttkmusicconfigmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ void TTKMusicConfigManager::writeXMLConfig()
int playModeChoiced = M_SETTING_PTR->value(MusicSettingManager::PlayModeChoiced).toInt();
int volumeChoiced = M_SETTING_PTR->value(MusicSettingManager::VolumeChoiced).toInt();
QStringList lastPlayIndexChoiced = M_SETTING_PTR->value(MusicSettingManager::LastPlayIndexChoiced).toStringList();
int mobileWifiConnectChoiced = M_SETTING_PTR->value(MusicSettingManager::MobileWifiConnectChoiced).toInt();

///////////////////////////////////////////////////////////////////////////
int enhancedMusicChoiced = M_SETTING_PTR->value(MusicSettingManager::EnhancedMusicChoiced).toInt();
Expand Down Expand Up @@ -48,6 +49,7 @@ void TTKMusicConfigManager::writeXMLConfig()
writeDomElement(music, "playVolume", XmlAttribute("value", volumeChoiced));
writeDomElementText(music, "lastPlayIndex", XmlAttribute("value", lastPlayIndexChoiced[0]),
QString("%1,%2").arg(lastPlayIndexChoiced[1]).arg(lastPlayIndexChoiced[2]));
writeDomElement(music, "WifiConnect", XmlAttribute("value", mobileWifiConnectChoiced));

///////////////////////////////////////////////////////////////////////////
writeDomElement(equalizer, "enhancedMusic", XmlAttribute("value", enhancedMusicChoiced));
Expand Down Expand Up @@ -146,6 +148,8 @@ void TTKMusicConfigManager::readOtherLoadConfig() const
{
M_SETTING_PTR->setValue(MusicSettingManager::DownloadServerChoiced,
readXmlAttributeByTagNameValue("downloadServer").toInt());
M_SETTING_PTR->setValue(MusicSettingManager::MobileWifiConnectChoiced,
readXmlAttributeByTagNameValue("WifiConnect").toInt());
}

MusicSongs TTKMusicConfigManager::readMusicFilePath(const QDomNode &node) const
Expand Down
9 changes: 9 additions & 0 deletions TTKMobile/MobileCore/ttkmusicutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "musicsettingmanager.h"
#include "musicsourceupdatethread.h"
#include "musicsemaphoreloop.h"
#include "musicnetworkthread.h"

#include <QDir>
#include <QMessageBox>
Expand Down Expand Up @@ -74,6 +75,14 @@ bool TTKMusicUtils::currentNetIsWifi()
return false;
}

void TTKMusicUtils::setNetworkBlockNotWifi()
{
#if defined (Q_OS_ANDROID)
bool block = M_SETTING_PTR->value(MusicSettingManager::MobileWifiConnectChoiced).toBool() && currentNetIsWifi();
M_NETWORK_PTR->setBlockNetWork(block);
#endif
}

void TTKMusicUtils::updateApplicationDialog()
{
#if defined (Q_OS_ANDROID)
Expand Down
6 changes: 5 additions & 1 deletion TTKMobile/MobileCore/ttkmusicutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,11 @@ class MUSIC_MOBILE_EXPORT TTKMusicUtils : public QObject
*/
Q_INVOKABLE bool currentNetIsWifi();
/*!
* Show message box.
* Check current network is wifi.
*/
Q_INVOKABLE void setNetworkBlockNotWifi();
/*!
* Set network block if it is not Wifi.
*/
Q_INVOKABLE void updateApplicationDialog();
/*!
Expand Down
30 changes: 25 additions & 5 deletions TTKMobile/MobileCore/ttknetworkhelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,45 +26,65 @@ TTKNetworkHelper::~TTKNetworkHelper()
delete m_queryThread;
}

void TTKNetworkHelper::setBlockNetWork(int block)
{
M_NETWORK_PTR->setBlockNetWork(block);
}

void TTKNetworkHelper::setQueryType(int type)
{
m_queryType = MStatic_cast(Type, type);
}

void TTKNetworkHelper::searchSong(const QString &text)
{
if(!M_NETWORK_PTR->isOnline())
{
return;
}

m_queryType = T_SearcSong;
m_queryThread->setQueryAllRecords(true);
m_queryThread->startSearchSong(MusicDownLoadQueryThreadAbstract::MusicQuery, text);
}

void TTKNetworkHelper::searchMovie(const QString &text)
{
if(!M_NETWORK_PTR->isOnline())
{
return;
}

m_queryType = T_SearcMovie;
m_queryThread->setQueryAllRecords(true);
m_queryThread->startSearchSong(MusicDownLoadQueryThreadAbstract::MovieQuery, text);
}

void TTKNetworkHelper::searchLrc(const QString &text)
{
if(!M_NETWORK_PTR->isOnline())
{
return;
}

m_queryType = T_SearcLrc;
m_queryThread->startSearchSong(MusicDownLoadQueryThreadAbstract::LrcQuery, text);
}

void TTKNetworkHelper::downloadSong(const QString &text)
{
if(!M_NETWORK_PTR->isOnline())
{
return;
}

m_queryType = T_DownloadSong;
m_queryThread->setQueryAllRecords(true);
m_queryThread->startSearchSong(MusicDownLoadQueryThreadAbstract::MusicQuery, text);
}

void TTKNetworkHelper::setCurrentIndex(int index, const QVariant &data)
{
if(!M_NETWORK_PTR->isOnline())
{
return;
}

switch(m_queryType)
{
case T_SearcSong:
Expand Down
5 changes: 0 additions & 5 deletions TTKMobile/MobileCore/ttknetworkhelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,6 @@ class MUSIC_MOBILE_EXPORT TTKNetworkHelper : public QObject
*/
~TTKNetworkHelper();

//////////////////////////////////////////////////////
Q_INVOKABLE void setBlockNetWork(int block);
/*!
* Set flag wheather to block current network.
*/
//////////////////////////////////////////////////////
Q_INVOKABLE void setQueryType(int type);
/*!
Expand Down
31 changes: 22 additions & 9 deletions TTKMobile/MobileWidgets/TTKMainSettingPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ Item {
width: parent.width
height: parent.height

property bool justUseWifi: false;

function timeToQuitApp(time) {
firstListModel.set(3, {
imageSource: "qrc:/image/more_icon_timer",
Expand All @@ -33,6 +31,27 @@ Item {
TTK_APP.setTimeToQuitApp(time*1000*60);
}

function updateWifiConnect(state) {
var justUseWifi = TTK_UTILS.getValue("MobileWifiConnectChoiced");
if(state)
{
justUseWifi = !justUseWifi;
TTK_UTILS.setValue("MobileWifiConnectChoiced", justUseWifi);
}
TTK_UTILS.setNetworkBlockNotWifi();

firstListModel.set(1, {
imageSource: "qrc:/image/more_icon_wifionly",
imageSubSource: justUseWifi ? "qrc:/image/switch_on_normal"
: "qrc:/image/switching_off",
title: qsTr("仅Wi-Fi联网")
});
}

Component.onCompleted: {
updateWifiConnect(false);
}

ColumnLayout {
spacing: 0
anchors.fill: parent
Expand Down Expand Up @@ -171,13 +190,7 @@ Item {
ttkOutStackView.push("qrc:/MobileWidgets/TTKMainMoreSettingPage.qml");
break;
case 1:
firstListModel.set(1, {
imageSource: "qrc:/image/more_icon_wifionly",
imageSubSource: justUseWifi ? "qrc:/image/switching_off"
: "qrc:/image/switch_on_normal",
title: qsTr("仅Wi-Fi联网")
});
justUseWifi = !justUseWifi;
updateWifiConnect(true);
break;
case 2: break;
case 3:
Expand Down
3 changes: 3 additions & 0 deletions TTKMobile/MobileWidgets/TTKMusicListsPage.qml
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,9 @@ Item {

MouseArea {
anchors.fill: parent
onPressAndHold: {

}
onClicked: {
itemListView.currentIndex = index;
TTK_APP.setCurrentIndex(ttkTheme.music_normal_list, index);
Expand Down
1 change: 1 addition & 0 deletions TTKMobile/extra/musicconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<playMode value="2"/>
<playVolume value="100"/>
<lastPlayIndex value="1">0,-1</lastPlayIndex>
<WifiConnect value="0"/>
</music>
<equalizer>
<enhancedMusic value="1"/>
Expand Down

0 comments on commit 007d946

Please sign in to comment.