diff --git a/gui/forms/backupitem.cpp b/gui/forms/backupitem.cpp index d62a5d6..41cc657 100644 --- a/gui/forms/backupitem.cpp +++ b/gui/forms/backupitem.cpp @@ -84,6 +84,11 @@ int BackupItem::getIconWidth() return ui->itemPicture->width(); } +QString BackupItem::getPath() +{ + return m_path; +} + void BackupItem::setItemIcon(const QString &path, int item_width, bool try_dds) { ui->itemPicture->setMinimumWidth(item_width); diff --git a/gui/forms/backupitem.h b/gui/forms/backupitem.h index b68b5bb..7da4a8a 100644 --- a/gui/forms/backupitem.h +++ b/gui/forms/backupitem.h @@ -39,6 +39,7 @@ class BackupItem : public QWidget void setDirectory(const QString &m_path); const QPixmap *getIconPixmap(); int getIconWidth(); + QString getPath(); static bool lessThan(const BackupItem *s1, const BackupItem *s2); diff --git a/gui/forms/backupmanagerform.cpp b/gui/forms/backupmanagerform.cpp index 352dcf3..e90887e 100644 --- a/gui/forms/backupmanagerform.cpp +++ b/gui/forms/backupmanagerform.cpp @@ -28,6 +28,8 @@ #include #include #include +#include +#include #include #include @@ -49,10 +51,39 @@ void BackupManagerForm::setupForm() { this->resize(800, 480); connect(ui->backupComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(loadBackupListing(int))); + connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(saveListing())); ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel); ui->tableWidget->horizontalHeader()->hide(); } +void BackupManagerForm::saveListing() +{ + int rows = ui->tableWidget->rowCount(); + QVariantList items; + + for(int i = 0; i < rows; ++i) { + BackupItem *item = static_cast(ui->tableWidget->cellWidget(i, 0)); + + QVariantMap entry; + entry.insert("title", item->title); + entry.insert("gameid", QFileInfo(item->getPath()).fileName()); + entry.insert("path", item->getPath()); + + items.append(entry); + } + + QString output = QFileDialog::getSaveFileName( + this, tr("Select save location"), QDir::homePath() + "/listing.json", + "JSON (*.json)"); + + if(!output.isEmpty()) { + QJsonDocument doc = QJsonDocument::fromVariant(items); + QFile jsonFile(output); + jsonFile.open(QFile::WriteOnly); + jsonFile.write(doc.toJson()); + } +} + void BackupManagerForm::removeEntry(BackupItem *item) { ConfirmDialog msgBox; diff --git a/gui/forms/backupmanagerform.h b/gui/forms/backupmanagerform.h index 2613df3..3f74ba0 100644 --- a/gui/forms/backupmanagerform.h +++ b/gui/forms/backupmanagerform.h @@ -48,8 +48,10 @@ class BackupManagerForm : public QDialog public slots: void loadBackupListing(int index); void removeEntry(BackupItem *item); + private slots: void on_filterLineEdit_textChanged(const QString &arg1); + void saveListing(); }; #endif // BACKUPMANAGERFORM_H diff --git a/gui/forms/backupmanagerform.ui b/gui/forms/backupmanagerform.ui index 7fbf81d..e14dab5 100644 --- a/gui/forms/backupmanagerform.ui +++ b/gui/forms/backupmanagerform.ui @@ -123,6 +123,13 @@ + + + + Save listing + + +