importwidget.cpp 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. #include "importwidget.h"
  2. #include "ui_importwidget.h"
  3. #include "models/lotromanager.h"
  4. #include <QFileDialog>
  5. #include <QMessageBox>
  6. #include <QTextEdit>
  7. #include <QDebug>
  8. ImportWidget::ImportWidget(LotroManager* mgr, QSettings* settings, QWidget *parent) :
  9. QWidget(parent), lotro_manager(mgr), settings(settings),
  10. ui(new Ui::ImportWidget)
  11. {
  12. ui->setupUi(this);
  13. ui->database_import_radiobutton_common->click();
  14. connect(lotro_manager, &LotroManager::textFragmentReceived, this, &ImportWidget::onTextFragmentContentsReceived, Qt::QueuedConnection);
  15. }
  16. ImportWidget::~ImportWidget()
  17. {
  18. delete ui;
  19. }
  20. void ImportWidget::hideAllImportOptions()
  21. {
  22. ui->file_import_widget->hide();
  23. ui->textfragment_import_widget->hide();
  24. ui->database_import_widget->hide();
  25. }
  26. void ImportWidget::onTextFragmentContentsReceived(QString args, QString content)
  27. {
  28. ui->fragment_args_common->setText(args);
  29. ui->fragment_content_common->setText(content);
  30. }
  31. void ImportWidget::on_database_import_radiobutton_common_clicked()
  32. {
  33. hideAllImportOptions();
  34. ui->database_import_widget->show();
  35. }
  36. void ImportWidget::on_file_import_radiobutton_common_clicked()
  37. {
  38. hideAllImportOptions();
  39. ui->file_import_widget->show();
  40. }
  41. void ImportWidget::on_textfragment_import_radiobutton_common_clicked()
  42. {
  43. hideAllImportOptions();
  44. ui->textfragment_import_widget->show();
  45. }
  46. void ImportWidget::on_database_import_button_common_clicked()
  47. {
  48. QString fileName = QFileDialog::getOpenFileName(this->parentWidget(), "Открытие файла",
  49. settings->value("advanced/import_path", "").toString(), "База данных (*.db);;Все файлы (*)");
  50. if (fileName.isEmpty())
  51. return;
  52. settings->setValue("advanced/import_path", fileName.left(std::max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'))));
  53. settings->sync();
  54. QMetaObject::invokeMethod(lotro_manager, "importFilesFromDatabase",
  55. Qt::QueuedConnection, Q_ARG(QString, fileName));
  56. }
  57. void ImportWidget::on_file_import_button_common_clicked()
  58. {
  59. if (ui->import_file_id_common->text().toLongLong() == 0) {
  60. QMessageBox::warning(this->parentWidget(), "Не указан ID импортируемого файла!", "Укажите, пожалуйста, корректный (числовой) ID импортируемого файла");
  61. return;
  62. }
  63. QString fileName = QFileDialog::getOpenFileName(this->parentWidget(), "Открытие файла",
  64. settings->value("advanced/import_path", "").toString(), "Все файлы (*)");
  65. if (fileName.isEmpty())
  66. return;
  67. settings->setValue("advanced/import_path", fileName.left(std::max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'))));
  68. settings->sync();
  69. QMetaObject::invokeMethod(lotro_manager, "importFile", Qt::QueuedConnection,
  70. Q_ARG(long long, ui->import_file_id_common->text().toLongLong()),
  71. Q_ARG(QString, fileName)
  72. );
  73. }
  74. void ImportWidget::on_get_file_fragments_button_common_clicked()
  75. {
  76. if (ui->file_id_input_common->text().toLongLong() == 0) {
  77. QMessageBox::warning(this->parentWidget(), "Не указан ID импортируемого файла!", "Укажите, пожалуйста, корректный (числовой) ID импортируемого текстового файла!");
  78. return;
  79. }
  80. if (ui->fragment_id_input_common->text().toLongLong() == 0) {
  81. QMessageBox::warning(this->parentWidget(), "Не указан ID фрагмента!", "Укажите, пожалуйста, корректный (числовой) ID фрагмента!");
  82. return;
  83. }
  84. QMetaObject::invokeMethod(lotro_manager, "getTextFragment", Qt::QueuedConnection,
  85. Q_ARG(long long, ui->file_id_input_common->text().toLongLong()),
  86. Q_ARG(long long, ui->fragment_id_input_common->text().toLongLong())
  87. );
  88. }
  89. void ImportWidget::on_textfragment_import_common_clicked()
  90. {
  91. if (ui->file_id_input_common->text().toLongLong() == 0) {
  92. QMessageBox::warning(this->parentWidget(), "Не указан ID импортируемого файла!", "Укажите, пожалуйста, корректный (числовой) ID импортируемого текстового файла!");
  93. return;
  94. }
  95. if (ui->fragment_id_input_common->text().toLongLong() == 0) {
  96. QMessageBox::warning(this->parentWidget(), "Не указан ID фрагмента!", "Укажите, пожалуйста, корректный (числовой) ID фрагмента!");
  97. return;
  98. }
  99. QMetaObject::invokeMethod(lotro_manager, "importTextFragment", Qt::QueuedConnection,
  100. Q_ARG(long long, ui->file_id_input_common->text().toLongLong()),
  101. Q_ARG(long long, ui->fragment_id_input_common->text().toLongLong()),
  102. Q_ARG(QString, ui->fragment_content_common->toPlainText()),
  103. Q_ARG(QString, ui->fragment_args_common->text())
  104. );
  105. }