Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed oostudio downloader to properly work with redirected URLs like …

…those of sourceforge, this removes the need to hard code a mirror, thus our euro friends can also use it
  • Loading branch information...
commit 3178a260f47ab83fecab64c6ed6c8120ed7c34d7 1 parent 5bf86f5
@linuxras linuxras authored
View
13 oom/widgets/commentdock.cpp
@@ -27,8 +27,11 @@ CommentDock::CommentDock(QWidget* parent, Track* t)
connect(songComment, SIGNAL(textChanged()), this, SLOT(songCommentChanged()));
updateComments();
commentDockSplitter->setChildrenCollapsible(false);
- QList<int> sizes;
+ QByteArray str = tconfig().get_property("CommentDock", "settings", "").toByteArray();
+ commentDockSplitter->restoreState(str);
+ /*
QString str = tconfig().get_property("CommentDock", "sizes", "30 250").toString();
+ QList<int> sizes;
QStringList sl = str.split(QString(" "), QString::SkipEmptyParts);
foreach (QString s, sl)
{
@@ -36,18 +39,20 @@ CommentDock::CommentDock(QWidget* parent, Track* t)
sizes.append(val);
}
commentDockSplitter->setSizes(sizes);
+ */
}
CommentDock::~CommentDock()
{
//QList<int> sizes = commentDockSplitter->sizes();
- QStringList out;
+ //QStringList out;
/*foreach(int s, sizes)
{
out << QString::number(s);
}*/
- out << QString::number(songComment->height()) << QString::number(textentry->height());
- tconfig().set_property("CommentDock", "sizes", out.join(" "));
+ //out << QString::number(songComment->height()) << QString::number(textentry->height());
+ //tconfig().set_property("CommentDock", "sizes", out.join(" "));
+ tconfig().set_property("CommentDock", "settings", commentDockSplitter->saveState());
tconfig().save();
}
View
104 oostudio/OODownload.cpp
@@ -49,8 +49,10 @@ void OODownload::startDownload(DownloadPackage* pkg)
qDebug() << "OODownload::startDownload Unknown progress";
break;
}
+ emit displayMessage(QString("Fetching library from url: ").append(pkg->path.toString()));
m_currentDownloads[pkg->type] = reply;
m_currentPackages[pkg->type] = pkg;
+ m_redirectUrl[pkg->type] = pkg->path;
emit downloadStarted(pkg->type);
}
@@ -60,6 +62,16 @@ void OODownload::trackProgress(qint64 bytesReceived, qint64 bytesTotal)
Q_UNUSED(bytesTotal);
}
+QUrl OODownload::detectRedirect(const QUrl& possibleRedir, const QUrl& oldUrl) const
+{
+ QUrl redirUrl;
+ if(!possibleRedir.isEmpty() && possibleRedir != oldUrl)
+ {
+ redirUrl = possibleRedir;
+ }
+ return redirUrl;
+}
+
QString OODownload::getFilename(const QString &name)
{
QString filename(name);
@@ -113,45 +125,81 @@ bool OODownload::processDownload(DownloadPackage* pkg, QIODevice* data)
void OODownload::downloadFinished(QNetworkReply* reply)
{
- QUrl url = reply->url();
int index = m_currentDownloads.key(reply);
DownloadPackage* pkg = m_currentPackages.value(index);
int id = pkg->type;
- if(reply->error())
- {
- qDebug() << "OODownload::downloadFinished Download finished with error: " << pkg->name;
- if(reply->error() == QNetworkReply::OperationCanceledError)
+ QVariant possibleRedirectUrl = reply->attribute(QNetworkRequest::RedirectionTargetAttribute);
+ QUrl redirUrl = detectRedirect(possibleRedirectUrl.toUrl(), m_redirectUrl.value(id));
+ if(!redirUrl.isEmpty())
+ {//Try again to follow the redirect
+ QNetworkRequest request(redirUrl);
+ request.setRawHeader("User-Agent", "OOStudio "VERSION);
+ QNetworkReply *reply = m_manager.get(request);/*{{{*/
+ switch(pkg->type)
+ {
+ case Sonatina:
+ connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(trackSonatinaProgress(qint64, qint64)));
+ break;
+ case Maestro:
+ connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(trackMaestroProgress(qint64, qint64)));
+ break;
+ case ClassicGuitar:
+ connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(trackClassicProgress(qint64, qint64)));
+ break;
+ case AcousticGuitar:
+ connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(trackAcousticProgress(qint64, qint64)));
+ break;
+ case M7IR44:
+ case M7IR48:
+ connect(reply, SIGNAL(downloadProgress(qint64, qint64)), this, SIGNAL(trackM7Progress(qint64, qint64)));
+ break;
+ default:
+ qDebug() << "OODownload::startDownload Unknown progress";
+ break;
+ }/*}}}*/
+ m_currentDownloads[pkg->type] = reply;
+ m_redirectUrl[pkg->type] = redirUrl;
+ emit displayMessage(QString("Following redirect url: ").append(redirUrl.toString()));
+ }
+ else
+ {//Complete the process
+ QUrl url = reply->url();
+ if(reply->error())
{
- emit downloadCanceled(id);
- cleanup(id);
- if(m_currentDownloads.isEmpty())
+ qDebug() << "OODownload::downloadFinished Download finished with error: " << pkg->name;
+ if(reply->error() == QNetworkReply::OperationCanceledError)
{
- emit downloadsComplete();
+ emit downloadCanceled(id);
+ cleanup(id);
+ if(m_currentDownloads.isEmpty())
+ {
+ emit downloadsComplete();
+ }
}
- }
- else
- {
- emit downloadError(id, QString(reply->errorString()));
- cleanup(id);
- if(m_currentDownloads.isEmpty())
+ else
{
- emit downloadsComplete();
+ emit downloadError(id, QString(reply->errorString()));
+ cleanup(id);
+ if(m_currentDownloads.isEmpty())
+ {
+ emit downloadsComplete();
+ }
}
}
- }
- else
- {
- if(pkg)
+ else
{
- //QString filename = pkg->filename; //getFilename(url);
- if(!processDownload(pkg, reply))
+ if(pkg)
{
- cleanup(pkg->type);
- emit downloadError(pkg->type, QString(reply->errorString()));
- qDebug() << "OODownload::downloadFinished Download finished: " << pkg->name;
- //Add message to log
- //TODO: fire extract thread
- //emit downloadEnded(pkg->type);
+ //QString filename = pkg->filename; //getFilename(url);
+ if(!processDownload(pkg, reply))
+ {
+ cleanup(pkg->type);
+ emit downloadError(pkg->type, QString(reply->errorString()));
+ qDebug() << "OODownload::downloadFinished Download finished: " << pkg->name;
+ //Add message to log
+ //TODO: fire extract thread
+ //emit downloadEnded(pkg->type);
+ }
}
}
}
View
3  oostudio/OODownload.h
@@ -29,7 +29,9 @@ class OODownload : public QObject
QMap<int, ExtractJob*> m_currentJobs;
QMap<int, QNetworkReply*> m_currentDownloads;
QMap<int, DownloadPackage*> m_currentPackages;
+ QMap<int, QUrl> m_redirectUrl;
void cleanup(int);
+ QUrl detectRedirect(const QUrl&, const QUrl&) const;
public:
OODownload(QObject* parent = 0);
@@ -58,6 +60,7 @@ public slots:
void trackClassicProgress(qint64 bytesReceived, qint64 bytesTotal);
void trackAcousticProgress(qint64 bytesReceived, qint64 bytesTotal);
void trackM7Progress(qint64 bytesReceived, qint64 bytesTotal);
+ void displayMessage(QString);
};
#endif
View
1  oostudio/OOStudio.cpp
@@ -378,6 +378,7 @@ void OOStudio::createConnections()/*{{{*/
connect(m_downloader, SIGNAL(downloadCanceled(int)), this, SLOT(downloadCanceled(int)));
connect(m_downloader, SIGNAL(downloadError(int, QString)), this, SLOT(downloadError(int, QString)));
connect(m_downloader, SIGNAL(downloadsComplete()), this, SLOT(downloadsComplete()));
+ connect(m_downloader, SIGNAL(displayMessage(QString)), this, SLOT(showMessage(QString)));
connect(m_downloader, SIGNAL(trackSonatinaProgress(qint64, qint64)), this, SLOT(trackSonatinaProgress(qint64, qint64)));
connect(m_downloader, SIGNAL(trackMaestroProgress(qint64, qint64)), this, SLOT(trackMaestroProgress(qint64, qint64)));
View
2  oostudio/OOStudio.h
@@ -106,7 +106,6 @@ class OOStudio :public QMainWindow ,public Ui::OOStudioBase
QString getValidName(QString);
QString convertPath(QString);
void doSessionDelete(OOSession*);
- void showMessage(QString);
bool checkPackageInstall(int);
protected:
@@ -114,6 +113,7 @@ class OOStudio :public QMainWindow ,public Ui::OOStudioBase
void resizeEvent(QResizeEvent*);
private slots:
+ void showMessage(QString);
void linuxSamplerStarted();
void oomStarted();
void jackStarted();
View
4 oostudio/oostudio.xml
@@ -1,7 +1,7 @@
<!DOCTYPE OOStudioDownloader>
<OOStudioDownloader>
- <sonatina id="0" path="http://hivelocity.dl.sourceforge.net/project/openoctave/libraries/sonatina1.tar.bz2" format="1" homepage="http://sso.mattiaswestlund.net/" filename="sonatina1.tar.bz2"/>
- <maestro id="1" path="http://hivelocity.dl.sourceforge.net/project/openoctave/libraries/maestro_concert_grand_v2.rar" format="2" homepage="http://www.linuxsampler.org/instruments.html" filename="maestro_concert_grand_v2.rar"/>
+ <sonatina id="0" path="http://sourceforge.net/projects/openoctave/files/libraries/sonatina1.tar.bz2/download" format="1" homepage="http://sso.mattiaswestlund.net/" filename="sonatina1.tar.bz2"/>
+ <maestro id="1" path="http://sourceforge.net/projects/openoctave/files/libraries/maestro_concert_grand_v2.rar/download" format="2" homepage="http://www.linuxsampler.org/instruments.html" filename="maestro_concert_grand_v2.rar"/>
<classicfree id="2" path="http://www.pettinhouse.com/Free/ClassicFREE.rar" format="2" homepage="http://www.pettinhouse.com/html/classicfree.html" filename="ClassicFREE.rar"/>
<acousticfree id="3" path="http://www.pettinhouse.com/Free/ACFree.rar" format="2" homepage="http://www.pettinhouse.com/html/acousticguitar_free.html" filename="ACFree.rar"/>
<!--<m7ir id="5" path="http://www.samplicity.com/wp-content/plugins/download-monitor/download.php?id=4" format="3" homepage="http://www.samplicity.com/bricasti-m7-impulse-responses/" filename="Samplicity M7 Main - 04 - Wave Quad files, 32 bit, 48 Khz, v1.1.zip"/>-->
Please sign in to comment.
Something went wrong with that request. Please try again.