A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita audio rust zig deno mpris rockbox mpd
at master 139 lines 3.5 kB view raw
1/*************************************************************************** 2 * __________ __ ___. 3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___ 4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / 5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * \/ \/ \/ \/ \/ 8 * $Id$ 9 * 10 * Copyright (C) 2010 Robert Bieber 11 * 12 * This program is free software; you can redistribute it and/or 13 * modify it under the terms of the GNU General Public License 14 * as published by the Free Software Foundation; either version 2 15 * of the License, or (at your option) any later version. 16 * 17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY 18 * KIND, either express or implied. 19 * 20 ****************************************************************************/ 21 22#include "targetdownloader.h" 23#include "ui_targetdownloader.h" 24 25#include "quazip.h" 26#include "quazipfile.h" 27#include "quazipfileinfo.h" 28 29#include <QNetworkRequest> 30#include <QNetworkReply> 31#include <QCloseEvent> 32 33#include <QDebug> 34 35TargetDownloader::TargetDownloader(QWidget *parent, QString path) : 36 QDialog(parent), 37 ui(new Ui::TargetDownloader), reply(0), cancelled(false) 38{ 39 ui->setupUi(this); 40 41 QObject::connect(ui->cancelButton, SIGNAL(clicked()), 42 this, SLOT(cancel())); 43 44 manager = new QNetworkAccessManager(); 45 46 fout.setFileName(path); 47 if(fout.open(QFile::WriteOnly)) 48 { 49 ui->label->setText(tr("Downloading targetdb")); 50 51 QNetworkRequest request; 52 request.setUrl( 53 QUrl("https://git.rockbox.org/cgit/rockbox.git/plain/" 54 "utils/themeeditor/resources/targetdb")); 55 request.setRawHeader("User-Agent", "Rockbox Theme Editor"); 56 57 reply = manager->get(request); 58 59 QObject::connect(reply, SIGNAL(readyRead()), 60 this, SLOT(dataReceived())); 61 QObject::connect(reply, SIGNAL(finished()), 62 this, SLOT(finished())); 63 QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)), 64 this, SLOT(progress(qint64,qint64))); 65 } 66 else 67 { 68 ui->label->setText(tr("Error: Couldn't open output file")); 69 } 70 71} 72 73TargetDownloader::~TargetDownloader() 74{ 75 delete ui; 76 fout.close(); 77 manager->deleteLater(); 78 79 if(reply) 80 { 81 reply->abort(); 82 reply->deleteLater(); 83 } 84} 85 86void TargetDownloader::cancel() 87{ 88 cancelled = true; 89 90 if(reply) 91 { 92 reply->abort(); 93 reply->deleteLater(); 94 reply = 0; 95 } 96 97 fout.close(); 98 fout.remove(); 99 100 close(); 101} 102 103void TargetDownloader::dataReceived() 104{ 105 fout.write(reply->readAll()); 106} 107 108void TargetDownloader::progress(qint64 bytes, qint64 available) 109{ 110 if(available > 0) 111 { 112 ui->progressBar->setMaximum(available); 113 ui->progressBar->setValue(bytes); 114 } 115} 116 117void TargetDownloader::finished() 118{ 119 if(cancelled) 120 return; 121 122 fout.close(); 123 reply->deleteLater(); 124 reply = 0; 125 ui->label->setText(tr("Download complete")); 126 hide(); 127 this->deleteLater(); 128} 129 130void TargetDownloader::netError(QNetworkReply::NetworkError code) 131{ 132 ui->label->setText(tr("Network error: ") + reply->errorString()); 133} 134 135void TargetDownloader::closeEvent(QCloseEvent *event) 136{ 137 cancel(); 138 event->accept(); 139}