sammarks

jarprogress.cpp

Apr 14th, 2011
217
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include "jarprogress.h"
  2. #include "ui_jarprogress.h"
  3. #include "minecraftmanager.h"
  4. #include "minemod.h"
  5. #include "syncmods.h"
  6. #include "extractasync.h"
  7. #include "simpledownloader.h"
  8.  
  9. #include <QMessageBox>
  10. #include <QEventLoop>
  11.  
  12. JarProgress::JarProgress(QWidget *parent) :
  13.     QDialog(parent),
  14.     ui(new Ui::JarProgress)
  15. {
  16.     ui->setupUi(this);
  17. }
  18.  
  19. JarProgress::~JarProgress()
  20. {
  21.     delete ui;
  22. }
  23.  
  24. void JarProgress::ProgressUpdated(int min, int max, QString detail, QString subDetail) {
  25.     ui->prgProgress->setMinimum(0);
  26.     ui->prgProgress->setValue(min);
  27.     ui->prgProgress->setMaximum(max);
  28.     ui->txtStatus->setText(detail);
  29.     ui->txtSubStatus->setText(subDetail);
  30. }
  31.  
  32. void JarProgress::ExtractMinecraft(QString minecraftLocation, QString modLocation) {
  33.     this->show();
  34.     /*MinecraftManager *mgr = new MinecraftManager();
  35.     connect(mgr, SIGNAL(ProgressUpdated(int,int,QString,QString)), this, SLOT(ProgressUpdated(int,int,QString,QString)), Qt::BlockingQueuedConnection);
  36.     connect(mgr, SIGNAL(Completed()), this, SLOT(Completed()));
  37.     mgr->UnzipMinecraft(minecraftLocation, modLocation, this);*/
  38.  
  39.     ExtractAsync *async = new ExtractAsync();
  40.     connect(async, SIGNAL(ProgressUpdated(int,int,QString,QString)), this, SLOT(ProgressUpdated(int,int,QString,QString)));
  41.     connect(async, SIGNAL(Completed()), this, SLOT(Completed()));
  42.     async->start();
  43. }
  44.  
  45. void JarProgress::Completed() {
  46.     this->close();
  47. }
  48.  
  49. void JarProgress::Sync(QString minecraftLocation, QString modLocation) {
  50.     this->show();
  51.  
  52.     // ORDER: First, download the latest version of Minecraft, then
  53.     // use the SyncM class to sync up the mods.
  54.  
  55.     this->ProgressUpdated(-1, 0, "Downloading Minecraft", "Connecting");
  56.  
  57.     SimpleDownloader *down = new SimpleDownloader();
  58.     //QEventLoop loop(this);
  59.     connect(down, SIGNAL(Progress(int,int,QString)), this, SLOT(DownloadProgress(int,int,QString)));
  60.     connect(down, SIGNAL(Finished(QString,bool,QString)), this, SLOT(DownloadFinished(QString,bool,QString)));
  61.     //loop.exec();
  62.     down->InitDownload("http://minecraft.net/download/minecraft.jar", modLocation + "/tempDL");
  63. }
  64.  
  65. void JarProgress::DownloadFinished(QString filename, bool success, QString message) {
  66.     if (success) {
  67.         SyncMods *syncM = new SyncMods(filename);
  68.         connect(syncM, SIGNAL(Progress(int,int,QString,QString)), this, SLOT(SyncProgressUpdated(int,int,QString,QString)));
  69.         connect(syncM, SIGNAL(Complete(bool,QString)), this, SLOT(SyncComplete(bool,QString)));
  70.         syncM->start();
  71.     } else {
  72.         QMessageBox::critical(this, "Error", "There was an error downloading Minecraft.<p><b>Details:</b> " + message + "</p>",
  73.                               QMessageBox::Ok, QMessageBox::NoButton);
  74.         this->reject();
  75.     }
  76. }
  77.  
  78. void JarProgress::DownloadProgress(int min, int max, QString message) {
  79.  
  80. }
  81.  
  82. void JarProgress::SyncComplete(bool successful, QString message) {
  83.     if (successful)
  84.         this->accept();
  85.     else {
  86.         QMessageBox::critical(this, "Error",
  87.                               "There was an error syncing with Minecraft.<p><b>Error Details:</b> " + message + "</p>",
  88.                               QMessageBox::Ok, QMessageBox::NoButton);
  89.         this->reject();
  90.     }
  91. }
  92.  
  93. void JarProgress::SyncProgressUpdated(int val, int max, QString top, QString bottom) {
  94.     ui->prgProgress->setMinimum(0);
  95.     ui->prgProgress->setValue(val);
  96.     ui->prgProgress->setMaximum(max);
  97.     ui->txtStatus->setText(top);
  98.     ui->txtSubStatus->setText(bottom);
  99. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×