Skip to content
This repository has been archived by the owner on Jul 4, 2020. It is now read-only.

Commit

Permalink
Added button to save current listing to json.
Browse files Browse the repository at this point in the history
  • Loading branch information
codestation committed Oct 23, 2016
1 parent 8a876a6 commit 4d1249b
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
5 changes: 5 additions & 0 deletions gui/forms/backupitem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions gui/forms/backupitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
31 changes: 31 additions & 0 deletions gui/forms/backupmanagerform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <QDebug>
#include <QDialogButtonBox>
#include <QDir>
#include <QFileDialog>
#include <QJsonDocument>
#include <QSettings>

#include <vitamtp.h>
Expand All @@ -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<BackupItem *>(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;
Expand Down
2 changes: 2 additions & 0 deletions gui/forms/backupmanagerform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 7 additions & 0 deletions gui/forms/backupmanagerform.ui
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="saveButton">
<property name="text">
<string>Save listing</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
Expand Down

0 comments on commit 4d1249b

Please sign in to comment.