Skip to content

Commit

Permalink
Fixed a bug in setting the last modified date for files and other min…
Browse files Browse the repository at this point in the history
…or improvements.
  • Loading branch information
RobertKrajewski committed Dec 27, 2014
1 parent 66edd2d commit ea80591
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 44 deletions.
3 changes: 2 additions & 1 deletion browser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ void Browser::on_syncPushButton_clicked()
directory.absoluteFilePath(filename),
QUrl(url),
changedCounter++,
currentElement->data(sizeRole).toInt()))
currentElement->data(sizeRole).toInt(),
currentElement->data(dateRole).toDateTime().toMSecsSinceEpoch()/1000))
{
break;
}
Expand Down
46 changes: 19 additions & 27 deletions filedownloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,47 +43,46 @@ FileDownloader::~FileDownloader()
delete ui;
}

int FileDownloader::startNextDownload(QString filename, QString event, QString verzeichnisPfad, QUrl url, int itemNummer, int itemSize)
int FileDownloader::startNextDownload(QString fileName, QString courseName, QString filePath, QUrl fileUrl, int itemNummer, int itemSize, int time)
{
// Anpassen der Labels
// Aktualisieren der Itemnummer
ui->progressLabel->setText(QString("Datei %1/%2").arg(itemNummer).arg(itemNumber));
// Aktualisieren des Veranstaltungsnamen
ui->veranstaltungLabel->setText(event);
// Aktualisieren des Dateinamens
ui->dateinameLabel->setText(filename);
ui->veranstaltungLabel->setText(courseName);
ui->dateinameLabel->setText(fileName);
ui->progressBar->setFormat(QString("%v ") % correctUnit(itemSize) % " / %m " % correctUnit(itemSize));
ui->progressBar->setMaximum(correctSize(itemSize));

times.actime = 0;
times.modtime = time;

// Erstellen des Outputstreams
output.setFileName(verzeichnisPfad);
output.setFileName(filePath);

// Öffnen des Ausgabestreams
if(!output.open(QIODevice::WriteOnly))
{
// Fehlerbehandlung
Utils::errorMessageBox("Fehler beim Öffnen mit Schreibberechtigung.", filename);
Utils::errorMessageBox("Fehler beim Öffnen mit Schreibberechtigung.", fileName);
return 0;
}

// Start des Requests

QLOG_DEBUG() << url.toString();
reply = manager->get(QNetworkRequest(url));
ui->progressBar->setFormat(QString("%v ").append(dataUnitFromBytes(itemSize)).append(" / %m ").append(dataUnitFromBytes(itemSize)));
ui->progressBar->setMaximum(roundBytes(itemSize));
reply = manager->get(QNetworkRequest(fileUrl));
QObject::connect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgressSlot(qint64,qint64)));
QObject::connect(reply, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
QObject::connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot()));

// Starten der Schleife, die vor sich hinläuft, bis der Download abgeschlossen ist
// Während des Downloads blockieren
return(loop.exec());
}

/// Anzeige des Downloadfortschritts der aktuellen Datei
void FileDownloader::downloadProgressSlot(qint64 bytesReceived, qint64 bytesTotal)
{
(void) bytesTotal;

// Aktualisieren der Progressbar anhand der Größe der empfangenen Bytes
ui->progressBar->setValue(roundBytes(bytesReceived));
ui->progressBar->setValue(correctSize(bytesReceived));
ui->progressBar->update();
}

/// Abspeichern von empfangenen Dateiteilen
Expand All @@ -92,7 +91,7 @@ void FileDownloader::readyReadSlot()
// Schreiben der runtergeladenen Bytes in die Datei
if (output.write(reply->readAll()) == -1)
{
Utils::errorMessageBox("Beim Schreiben einer Datei auf die Fesplatte ist ein Fehler aufgetreten.", ui->dateinameLabel->text());
Utils::errorMessageBox("Fehler beim Schreiben der Datei", ui->dateinameLabel->text());
reply->abort();
}
}
Expand All @@ -103,12 +102,7 @@ void FileDownloader::finishedSlot()
output.flush();
output.close();

if (originalModifiedDate)
{
times.actime = 0;
times.modtime = reply->header(QNetworkRequest::LastModifiedHeader).toDateTime().toTime_t();
utime(output.fileName().toLocal8Bit(), &times);
}
utime(output.fileName().toLocal8Bit(), &times);

QObject::disconnect(reply, SIGNAL(downloadProgress(qint64,qint64)), this, SLOT(downloadProgressSlot(qint64,qint64)));
QObject::disconnect(reply, SIGNAL(readyRead()), this, SLOT(readyReadSlot()));
Expand All @@ -117,7 +111,6 @@ void FileDownloader::finishedSlot()
// Freigabe des Speichers
reply->deleteLater();

// Fehlerbehandlung
if(reply->error())
{
QMessageBox messageBox;
Expand All @@ -129,7 +122,6 @@ void FileDownloader::finishedSlot()
output.remove();
loop.exit(0);
}
// Kein Fehler
else
{
loop.exit(1);
Expand Down Expand Up @@ -158,7 +150,7 @@ void FileDownloader::keyPressEvent(QKeyEvent *event)
}

/// Erzeugung der passenden Größeneinheit von der Dateigröße
QString FileDownloader::dataUnitFromBytes(qint64 bytes)
QString FileDownloader::correctUnit(qint64 bytes)
{
if(bytes > 1024 * 1024 * 5)
{
Expand All @@ -175,7 +167,7 @@ QString FileDownloader::dataUnitFromBytes(qint64 bytes)
}

/// Dateigröße in lesbare Größe umwandeln
qint64 FileDownloader::roundBytes(qint64 bytes)
qint64 FileDownloader::correctSize(qint64 bytes)
{
if(bytes > 1024 * 1024 * 5)
{
Expand Down
6 changes: 3 additions & 3 deletions filedownloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class FileDownloader : public QDialog
bool originalModifiedDate,
QWidget *parent= 0);
~FileDownloader();
int startNextDownload(QString, QString, QString, QUrl, int, int);
int startNextDownload(QString, QString, QString, QUrl, int, int, int time);

private:
void keyPressEvent(QKeyEvent *);
Expand All @@ -63,8 +63,8 @@ class FileDownloader : public QDialog
QFile output;
utimbuf times;

QString dataUnitFromBytes(qint64 bytes);
qint64 roundBytes(qint64 bytes);
QString correctUnit(qint64 bytes);
qint64 correctSize(qint64 bytes);

private slots:
void downloadProgressSlot(qint64,qint64);
Expand Down
12 changes: 2 additions & 10 deletions mymainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include "ui_mymainwindow.h"

#include "qslog/QsLog.h"
#include "utils.h"


MyMainWindow::MyMainWindow(QWidget *parent):
Expand Down Expand Up @@ -50,7 +51,7 @@ MyMainWindow::MyMainWindow(QWidget *parent):
this->show();

// Zentrieren des Fensters
centerOnDesktop();
Utils::centerWidgetOnDesktop(this);

// Erzeugt das Icon für das Tray im minimierten Zustand
createTrayIcon();
Expand Down Expand Up @@ -153,12 +154,3 @@ void MyMainWindow::trayClickedSlot(QSystemTrayIcon::ActivationReason reason)
}
}

/// Zentrieren des Programms auf dem Desktop
void MyMainWindow::centerOnDesktop()
{
QRect desktopRect = QApplication::desktop()->screenGeometry();
QRect windowRect = this->frameGeometry();
move((desktopRect.width() - windowRect.width()) / 2,
(desktopRect.height() - windowRect.height()) / 2);
}

4 changes: 1 addition & 3 deletions options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,6 @@ void Options::saveSettings()
}
}



void Options::on_loginPushButton_clicked()
{
LoginDialog ld;
Expand Down Expand Up @@ -251,7 +249,7 @@ void Options::loginResultSlot(int result)
ui->autoLoginOnStartCheckBox->setEnabled(true);
ui->userDataSaveCheckBox->setEnabled(true);

//emit switchTab(0);
emit switchTab(0);
// Sofortiges Aktualisiern der Daten
browser->on_refreshPushButton_clicked();
}
Expand Down
2 changes: 2 additions & 0 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ void Utils::errorMessageBox(QString message, QString detailMessage)
messageBox.setInformativeText(detailMessage);
messageBox.setStandardButtons(QMessageBox::Ok);
messageBox.exec();

QLOG_ERROR() << message << ": " << detailMessage;
}

/// Erstellung einer Liste mit allen Veransaltungen
Expand Down

0 comments on commit ea80591

Please sign in to comment.