exportwidget.cpp 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. #include "exportwidget.h"
  2. #include "ui_exportwidget.h"
  3. #include "models/lotromanager.h"
  4. #include <QFileDialog>
  5. #include <QDebug>
  6. ExportWidget::ExportWidget(LotroManager* mgr, QSettings* settings, QWidget *parent) :
  7. QWidget(parent), lotro_manager(mgr), settings(settings),
  8. ui(new Ui::ExportWidget)
  9. {
  10. ui->setupUi(this);
  11. ui->singlefile_radio_common->click();
  12. }
  13. ExportWidget::~ExportWidget()
  14. {
  15. delete ui;
  16. }
  17. void ExportWidget::addConnections()
  18. {
  19. connect(lotro_manager, &LotroManager::processStarted, this, &ExportWidget::on_lotromanager_process_started, Qt::BlockingQueuedConnection);
  20. connect(lotro_manager, &LotroManager::processFinished, this, &ExportWidget::on_lotromanager_process_finished, Qt::BlockingQueuedConnection);
  21. }
  22. void ExportWidget::on_lotromanager_process_started(QString, QVector<QVariant>)
  23. {
  24. ui->extract_button_common->setEnabled(false);
  25. ui->filesbytype_radio_common->setEnabled(false);
  26. ui->filetype_dds_common->setEnabled(false);
  27. ui->filetype_fontbin_common->setEnabled(false);
  28. ui->filetype_jpg_common->setEnabled(false);
  29. ui->filetype_ogg_common->setEnabled(false);
  30. ui->filetype_txt_common->setEnabled(false);
  31. ui->filetype_unknown_common->setEnabled(false);
  32. ui->filetype_wav_common->setEnabled(false);
  33. ui->singlefile_radio_common->setEnabled(false);
  34. ui->single_file_id_common->setEnabled(false);
  35. ui->target_database_radio_common->setEnabled(false);
  36. ui->target_files_radio_common->setEnabled(false);
  37. }
  38. void ExportWidget::on_lotromanager_process_finished(QString, QVector<QVariant>)
  39. {
  40. ui->extract_button_common->setEnabled(true);
  41. ui->filesbytype_radio_common->setEnabled(true);
  42. ui->filetype_dds_common->setEnabled(true);
  43. ui->filetype_fontbin_common->setEnabled(true);
  44. ui->filetype_jpg_common->setEnabled(true);
  45. ui->filetype_ogg_common->setEnabled(true);
  46. ui->filetype_txt_common->setEnabled(true);
  47. ui->filetype_unknown_common->setEnabled(true);
  48. ui->filetype_wav_common->setEnabled(true);
  49. ui->singlefile_radio_common->setEnabled(true);
  50. ui->single_file_id_common->setEnabled(true);
  51. ui->target_database_radio_common->setEnabled(true);
  52. ui->target_files_radio_common->setEnabled(true);
  53. if (ui->singlefile_radio_common->isChecked())
  54. emit ui->singlefile_radio_common->click();
  55. if (ui->filesbytype_radio_common->isChecked())
  56. emit ui->filesbytype_radio_common->click();
  57. }
  58. void ExportWidget::on_singlefile_radio_common_clicked()
  59. {
  60. ui->single_file_id_common->setEnabled(true);
  61. ui->filetype_dds_common->setDisabled(true);
  62. ui->filetype_fontbin_common->setDisabled(true);
  63. ui->filetype_jpg_common->setDisabled(true);
  64. ui->filetype_ogg_common->setDisabled(true);
  65. ui->filetype_txt_common->setDisabled(true);
  66. ui->filetype_unknown_common->setDisabled(true);
  67. ui->filetype_wav_common->setDisabled(true);
  68. }
  69. void ExportWidget::on_filesbytype_radio_common_clicked()
  70. {
  71. ui->single_file_id_common->setDisabled(true);
  72. ui->filetype_dds_common->setEnabled(true);
  73. ui->filetype_fontbin_common->setEnabled(true);
  74. ui->filetype_jpg_common->setEnabled(true);
  75. ui->filetype_ogg_common->setEnabled(true);
  76. ui->filetype_txt_common->setEnabled(true);
  77. ui->filetype_unknown_common->setEnabled(true);
  78. ui->filetype_wav_common->setEnabled(true);
  79. }
  80. void ExportWidget::on_extract_button_common_clicked()
  81. {
  82. bool to_database = ui->target_database_radio_common->isChecked();
  83. bool is_single_file = ui->singlefile_radio_common->isChecked();
  84. LOTRO_DAT::FILE_TYPE file_type = LOTRO_DAT::FILE_TYPE::NO_TYPE;
  85. if (ui->filetype_dds_common->isChecked())
  86. file_type = LOTRO_DAT::FILE_TYPE(file_type | LOTRO_DAT::DDS);
  87. if (ui->filetype_fontbin_common->isChecked())
  88. file_type = LOTRO_DAT::FILE_TYPE(file_type | LOTRO_DAT::FONT);
  89. if (ui->filetype_jpg_common->isChecked())
  90. file_type = LOTRO_DAT::FILE_TYPE(file_type | LOTRO_DAT::JPG);
  91. if (ui->filetype_ogg_common->isChecked())
  92. file_type = LOTRO_DAT::FILE_TYPE(file_type | LOTRO_DAT::OGG);
  93. if (ui->filetype_txt_common->isChecked())
  94. file_type = LOTRO_DAT::FILE_TYPE(file_type | LOTRO_DAT::TEXT);
  95. if (ui->filetype_unknown_common->isChecked())
  96. file_type = LOTRO_DAT::FILE_TYPE(file_type | LOTRO_DAT::UNKNOWN);
  97. if (ui->filetype_wav_common->isChecked())
  98. file_type = LOTRO_DAT::FILE_TYPE(file_type | LOTRO_DAT::WAV);
  99. long long file_id = ui->single_file_id_common->text().toLongLong();
  100. if (is_single_file && !to_database) {
  101. QString fileName = QFileDialog::getSaveFileName(this->parentWidget(), "Сохранение файла",
  102. settings->value("advanced/export_path", "").toString(), "Все файлы (*)");
  103. if (fileName.isEmpty())
  104. return;
  105. settings->setValue("advanced/export_path", fileName.left(std::max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'))));
  106. settings->sync();
  107. qDebug() << "Saving export path to " << settings->value("advanced/export_path", "").toString();
  108. QMetaObject::invokeMethod(lotro_manager, "extractSingleFile",
  109. Qt::QueuedConnection, Q_ARG(QString, fileName),
  110. Q_ARG(long long, file_id));
  111. }
  112. if (is_single_file && to_database) {
  113. QString fileName = QFileDialog::getSaveFileName(this->parentWidget(), "Сохранение файла",
  114. settings->value("advanced/export_path", "").toString(), "База данных (*.db);;Все файлы (*)");
  115. if (fileName.isEmpty())
  116. return;
  117. settings->setValue("advanced/export_path", fileName.left(std::max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'))));
  118. settings->sync();
  119. qDebug() << "Saving export path to " << settings->value("advanced/export_path", "").toString();
  120. QMetaObject::invokeMethod(lotro_manager, "extractSingleFileToDatabase",
  121. Qt::QueuedConnection, Q_ARG(QString, fileName),
  122. Q_ARG(long long, file_id));
  123. }
  124. if (!is_single_file && !to_database) {
  125. QString folderName = QFileDialog::getExistingDirectory(this->parentWidget(), "Выбор папки для экспорта",
  126. settings->value("advanced/export_path", "").toString(), QFileDialog::ShowDirsOnly) + "/";
  127. if (folderName.isEmpty())
  128. return;
  129. settings->setValue("advanced/export_path", folderName);
  130. settings->sync();
  131. qDebug() << "Saving export path to " << settings->value("advanced/export_path", "").toString();
  132. QMetaObject::invokeMethod(lotro_manager, "extractGrouppedFiles",
  133. Qt::QueuedConnection, Q_ARG(QString, folderName),
  134. Q_ARG(LOTRO_DAT::FILE_TYPE, file_type));
  135. }
  136. if (!is_single_file && to_database) {
  137. QString fileName = QFileDialog::getSaveFileName(this->parentWidget(), "Сохранение файла",
  138. settings->value("advanced/export_path", "").toString(), "База данных (*.db);;Все файлы (*)");
  139. if (fileName.isEmpty())
  140. return;
  141. settings->setValue("advanced/export_path", fileName.left(std::max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'))));
  142. settings->sync();
  143. qDebug() << "Saving export path to " << settings->value("advanced/export_path", "").toString();
  144. QMetaObject::invokeMethod(lotro_manager, "extractGrouppedFilesToDatabase",
  145. Qt::QueuedConnection, Q_ARG(QString, fileName),
  146. Q_ARG(LOTRO_DAT::FILE_TYPE, file_type));
  147. }
  148. }