2323#include < QProcess>
2424#include < QByteArray>
2525#include < QMessageBox>
26+ #include < QMovie>
2627
2728YoutubeDL::YoutubeDL (QWidget *parent) :
2829QMainWindow(parent),
@@ -72,22 +73,9 @@ void YoutubeDL::on_browseButton_clicked() {
7273void YoutubeDL::on_url_textChanged (const QString &arg1) {
7374 // Check if URL is correct and valid
7475 if (arg1.isEmpty () || !QUrl (arg1).isValid ()) {
75- info->kill ();
76- ui->pasteButton ->setEnabled (true );
77- ui->downloadButton ->setDisabled (true );
78- ui->cancelButton ->setDisabled (true );
79- ui->pauseButton ->setDisabled (true );
80- ui->downloadOptions ->setDisabled (true );
81- ui->downloadProgressBar ->setValue (0 );
82- ui->downloadProgressBar ->setFormat (" 0%" );
83- ui->titleDescLabel ->setText (" " );
84- ui->imageLabel ->setPixmap (QPixmap ());
85- ui->downloadOptionsFrame ->setHidden (true );
86- ui->audioCheckBox ->setChecked (false );
87- ui->audioFormatCombo ->setDisabled (true );
88- ui->audioQualityCombo ->setDisabled (true );
89- ui->keepVideoCheckBox ->setDisabled (true );
90- ui->keepVideoCheckBox ->setChecked (false );
76+ if (NULL != info && info->state () != 0 )
77+ info->kill ();
78+ this ->resetInterface ();
9179 } else {
9280 ui->pasteButton ->setDisabled (true );
9381 // Get video info
@@ -96,12 +84,36 @@ void YoutubeDL::on_url_textChanged(const QString &arg1) {
9684 arguments <<" --get-thumbnail" <<" --get-title" <<" --get-description" << arg1;
9785 info = new QProcess (this );
9886 info->start (program, arguments);
99- QObject::connect (info, SIGNAL ( finished ( int )), this , SLOT ( getInfo ()));
87+
10088 QObject::connect (info, SIGNAL (readyReadStandardError ()), this , SLOT (printError ()));
101- ui->titleDescLabel ->setText (" Fetching video/audio info..." );
89+ QObject::connect (info, SIGNAL (finished (int )), this , SLOT (getInfo ()));
90+
91+ QMovie *movie = new QMovie (" :images/loader.gif" );
92+ ui->titleDescLabel ->setAlignment (Qt::AlignCenter);
93+ ui->titleDescLabel ->setMovie (movie);
94+ movie->start ();
95+
10296 }
10397}
10498
99+ void YoutubeDL::resetInterface () {
100+ ui->pasteButton ->setEnabled (true );
101+ ui->downloadButton ->setDisabled (true );
102+ ui->cancelButton ->setDisabled (true );
103+ ui->pauseButton ->setDisabled (true );
104+ ui->downloadOptions ->setDisabled (true );
105+ ui->downloadProgressBar ->setValue (0 );
106+ ui->downloadProgressBar ->setFormat (" 0%" );
107+ ui->titleDescLabel ->setText (" " );
108+ ui->imageLabel ->setPixmap (QPixmap ());
109+ ui->downloadOptionsFrame ->setHidden (true );
110+ ui->audioCheckBox ->setChecked (false );
111+ ui->audioFormatCombo ->setDisabled (true );
112+ ui->audioQualityCombo ->setDisabled (true );
113+ ui->keepVideoCheckBox ->setDisabled (true );
114+ ui->keepVideoCheckBox ->setChecked (false );
115+ }
116+
105117void YoutubeDL::printError () {
106118 QString errorInfo (info->readAllStandardError ());
107119 if (errorInfo.length () > 0 ) {
@@ -134,6 +146,7 @@ void YoutubeDL::getInfo()
134146 connect (m_netwManager, SIGNAL (finished (QNetworkReply*)), this , SLOT (slot_netwManagerFinished (QNetworkReply*)));
135147 QNetworkRequest request (thumbnail);
136148 m_netwManager->get (request);
149+ ui->titleDescLabel ->setAlignment (Qt::AlignLeft);
137150 ui->titleDescLabel ->setText (" <b>" +title+" </b>" +" <br><br>" +description);
138151 ui->downloadButton ->setEnabled (true );
139152 ui->pasteButton ->setEnabled (true );
0 commit comments