Changeset View
Changeset View
Standalone View
Standalone View
src/services/magnatune/MagnatuneAlbumDownloader.cpp
Show All 13 Lines | |||||
14 | * this program. If not, see <http://www.gnu.org/licenses/>. * | 14 | * this program. If not, see <http://www.gnu.org/licenses/>. * | ||
15 | ****************************************************************************************/ | 15 | ****************************************************************************************/ | ||
16 | 16 | | |||
17 | #include "MagnatuneAlbumDownloader.h" | 17 | #include "MagnatuneAlbumDownloader.h" | ||
18 | 18 | | |||
19 | #include "core/support/Amarok.h" | 19 | #include "core/support/Amarok.h" | ||
20 | #include "core/support/Components.h" | 20 | #include "core/support/Components.h" | ||
21 | #include "core/support/Debug.h" | 21 | #include "core/support/Debug.h" | ||
22 | #include "core/interfaces/Logger.h" | 22 | #include "core/logger/Logger.h" | ||
23 | #include "MagnatuneMeta.h" | 23 | #include "MagnatuneMeta.h" | ||
24 | 24 | | |||
25 | #include <QTemporaryDir> | 25 | #include <QTemporaryDir> | ||
26 | 26 | | |||
27 | #include <KLocalizedString> | 27 | #include <KLocalizedString> | ||
28 | #include <KZip> | 28 | #include <KZip> | ||
29 | 29 | | |||
30 | MagnatuneAlbumDownloader::MagnatuneAlbumDownloader() | 30 | MagnatuneAlbumDownloader::MagnatuneAlbumDownloader() | ||
Show All 35 Lines | 46 | { | |||
66 | { | 66 | { | ||
67 | msgText = i18n( "Downloading '%1' by %2 from Magnatune.com", info.albumName(), info.artistName() ); | 67 | msgText = i18n( "Downloading '%1' by %2 from Magnatune.com", info.albumName(), info.artistName() ); | ||
68 | } | 68 | } | ||
69 | else | 69 | else | ||
70 | { | 70 | { | ||
71 | msgText = i18n( "Downloading album from Magnatune.com" ); | 71 | msgText = i18n( "Downloading album from Magnatune.com" ); | ||
72 | } | 72 | } | ||
73 | 73 | | |||
74 | Amarok::Components::logger()->newProgressOperation( m_albumDownloadJob, msgText, this, &MagnatuneAlbumDownloader::albumDownloadAborted ); | 74 | Amarok::Logger::newProgressOperation( m_albumDownloadJob, msgText, this, &MagnatuneAlbumDownloader::albumDownloadAborted ); | ||
75 | } | 75 | } | ||
76 | 76 | | |||
77 | void | 77 | void | ||
78 | MagnatuneAlbumDownloader::albumDownloadComplete( KJob * downloadJob ) | 78 | MagnatuneAlbumDownloader::albumDownloadComplete( KJob * downloadJob ) | ||
79 | { | 79 | { | ||
80 | DEBUG_BLOCK | 80 | DEBUG_BLOCK | ||
81 | 81 | | |||
82 | debug() << "album download complete"; | 82 | debug() << "album download complete"; | ||
Show All 9 Lines | |||||
92 | const QString finalAlbumPath = m_currentAlbumUnpackLocation + '/' + m_currentAlbumInfo.artistName() + '/' + m_currentAlbumInfo.albumName(); | 92 | const QString finalAlbumPath = m_currentAlbumUnpackLocation + '/' + m_currentAlbumInfo.artistName() + '/' + m_currentAlbumInfo.albumName(); | ||
93 | 93 | | |||
94 | //ok, now we have the .zip file downloaded. All we need is to unpack it to the desired location and add it to the collection. | 94 | //ok, now we have the .zip file downloaded. All we need is to unpack it to the desired location and add it to the collection. | ||
95 | 95 | | |||
96 | KZip kzip( m_tempDir->path() + '/' + m_currentAlbumFileName ); | 96 | KZip kzip( m_tempDir->path() + '/' + m_currentAlbumFileName ); | ||
97 | 97 | | |||
98 | if ( !kzip.open( QIODevice::ReadOnly ) ) | 98 | if ( !kzip.open( QIODevice::ReadOnly ) ) | ||
99 | { | 99 | { | ||
100 | Amarok::Components::logger()->shortMessage( i18n( "Magnatune download seems to have failed. Cannot read zip file" ) ); | 100 | Amarok::Logger::shortMessage( i18n( "Magnatune download seems to have failed. Cannot read zip file" ) ); | ||
101 | emit( downloadComplete( false ) ); | 101 | emit( downloadComplete( false ) ); | ||
102 | return; | 102 | return; | ||
103 | } | 103 | } | ||
104 | 104 | | |||
105 | debug() << m_tempDir->path() + '/' + m_currentAlbumFileName << " opened for decompression"; | 105 | debug() << m_tempDir->path() + '/' + m_currentAlbumFileName << " opened for decompression"; | ||
106 | 106 | | |||
107 | const KArchiveDirectory * directory = kzip.directory(); | 107 | const KArchiveDirectory * directory = kzip.directory(); | ||
108 | 108 | | |||
109 | Amarok::Components::logger()->shortMessage( i18n( "Uncompressing Magnatune.com download..." ) ); | 109 | Amarok::Logger::shortMessage( i18n( "Uncompressing Magnatune.com download..." ) ); | ||
110 | 110 | | |||
111 | //Is this really blocking with no progress status!? Why is it not a KJob? | 111 | //Is this really blocking with no progress status!? Why is it not a KJob? | ||
112 | 112 | | |||
113 | debug() << "decompressing to " << finalAlbumPath; | 113 | debug() << "decompressing to " << finalAlbumPath; | ||
114 | directory->copyTo( m_currentAlbumUnpackLocation ); | 114 | directory->copyTo( m_currentAlbumUnpackLocation ); | ||
115 | 115 | | |||
116 | debug() << "done!"; | 116 | debug() << "done!"; | ||
117 | 117 | | |||
118 | 118 | | |||
119 | 119 | | |||
120 | //now I really want to add the album cover to the same folder where I just unzipped the album... The | 120 | //now I really want to add the album cover to the same folder where I just unzipped the album... The | ||
121 | //only way of getting the actual location where the album was unpacked is using the artist and album names | 121 | //only way of getting the actual location where the album was unpacked is using the artist and album names | ||
122 | 122 | | |||
123 | QString coverUrlString = m_currentAlbumInfo.coverUrl(); | 123 | QString coverUrlString = m_currentAlbumInfo.coverUrl(); | ||
124 | 124 | | |||
125 | QUrl downloadUrl( coverUrlString.replace( "_200.jpg", ".jpg") ); | 125 | QUrl downloadUrl( coverUrlString.replace( "_200.jpg", ".jpg") ); | ||
126 | 126 | | |||
127 | debug() << "Adding cover " << downloadUrl.url() << " to collection at " << finalAlbumPath; | 127 | debug() << "Adding cover " << downloadUrl.url() << " to collection at " << finalAlbumPath; | ||
128 | 128 | | |||
129 | m_coverDownloadJob = KIO::file_copy( downloadUrl, QUrl::fromLocalFile( finalAlbumPath + "/cover.jpg" ), -1, KIO::Overwrite | KIO::HideProgressInfo ); | 129 | m_coverDownloadJob = KIO::file_copy( downloadUrl, QUrl::fromLocalFile( finalAlbumPath + "/cover.jpg" ), -1, KIO::Overwrite | KIO::HideProgressInfo ); | ||
130 | 130 | | |||
131 | connect( m_coverDownloadJob, &KJob::result, this, &MagnatuneAlbumDownloader::coverDownloadComplete ); | 131 | connect( m_coverDownloadJob, &KJob::result, this, &MagnatuneAlbumDownloader::coverDownloadComplete ); | ||
132 | 132 | | |||
133 | Amarok::Components::logger()->newProgressOperation( m_coverDownloadJob, i18n( "Adding album cover to collection" ), this, &MagnatuneAlbumDownloader::coverAddAborted ); | 133 | Amarok::Logger::newProgressOperation( m_coverDownloadJob, i18n( "Adding album cover to collection" ), this, &MagnatuneAlbumDownloader::coverAddAborted ); | ||
134 | 134 | | |||
135 | emit( downloadComplete( true ) ); | 135 | emit( downloadComplete( true ) ); | ||
136 | } | 136 | } | ||
137 | 137 | | |||
138 | void | 138 | void | ||
139 | MagnatuneAlbumDownloader::coverDownloadComplete(KJob* downloadJob) | 139 | MagnatuneAlbumDownloader::coverDownloadComplete(KJob* downloadJob) | ||
140 | { | 140 | { | ||
141 | DEBUG_BLOCK | 141 | DEBUG_BLOCK | ||
Show All 38 Lines |