diff --git a/backupitem.cpp b/backupitem.cpp
new file mode 100644
index 0000000..9a0e54d
--- /dev/null
+++ b/backupitem.cpp
@@ -0,0 +1,87 @@
+/*
+ * QCMA: Cross-platform content manager assistant for the PS Vita
+ *
+ * Copyright (C) 2013 Codestation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "backupitem.h"
+#include "ui_backupitem.h"
+#include "utils.h"
+
+#include
+#include
+
+const QString BackupItem::nameTemplate = ""
+"%1
"
+"%2
"
+"";
+
+BackupItem::BackupItem(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::BackupItem)
+{
+ ui->setupUi(this);
+ // connect the buttons
+ connect(ui->openButton, SIGNAL(clicked()), this, SLOT(openDirectory()));
+ connect(ui->deleteButton, SIGNAL(clicked()), this, SLOT(removeEntry()));
+}
+
+BackupItem::~BackupItem()
+{
+ delete ui;
+}
+
+void BackupItem::openDirectory()
+{
+ QDesktopServices::openUrl(QUrl("file:///" + path));
+}
+
+void BackupItem::removeEntry()
+{
+ emit deleteEntry(this);
+}
+
+const QPixmap *BackupItem::getIconPixmap()
+{
+ return ui->itemPicture->pixmap();
+}
+
+void BackupItem::setDirectory(const QString path)
+{
+ this->path = path;
+}
+
+void BackupItem::setItemInfo(const QString name, const QString size)
+{
+ ui->itemName->setText(nameTemplate.arg(name, size));
+}
+
+int BackupItem::getIconWidth()
+{
+ return ui->itemPicture->width();
+}
+
+void BackupItem::setItemIcon(const QString path, int width)
+{
+ ui->itemPicture->setMinimumWidth(width);
+ ui->itemPicture->setPixmap(QPixmap(path));
+}
+
+bool BackupItem::lessThan(const BackupItem *s1, const BackupItem *s2)
+{
+ return s1->title.compare(s2->title) < 0;
+}
+
diff --git a/backupitem.h b/backupitem.h
new file mode 100644
index 0000000..a7f4c0d
--- /dev/null
+++ b/backupitem.h
@@ -0,0 +1,62 @@
+/*
+ * QCMA: Cross-platform content manager assistant for the PS Vita
+ *
+ * Copyright (C) 2013 Codestation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef BACKUPITEM_H
+#define BACKUPITEM_H
+
+#include
+
+namespace Ui {
+class BackupItem;
+}
+
+class BackupItem : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit BackupItem(QWidget *parent = 0);
+ ~BackupItem();
+
+ void setItemInfo(const QString name, const QString size);
+ void setItemIcon(const QString path, int width = 48);
+ void setDirectory(const QString path);
+ const QPixmap *getIconPixmap();
+ int getIconWidth();
+
+ static bool lessThan(const BackupItem *s1, const BackupItem *s2);
+
+ int ohfi;
+ int row;
+ QString title;
+
+private:
+ QString path;
+ Ui::BackupItem *ui;
+ static const QString nameTemplate;
+
+signals:
+ void deleteEntry(BackupItem *entry);
+
+private slots:
+ void openDirectory();
+ void removeEntry();
+};
+
+#endif // BACKUPITEM_H
diff --git a/backupitem.ui b/backupitem.ui
new file mode 100644
index 0000000..b0a5755
--- /dev/null
+++ b/backupitem.ui
@@ -0,0 +1,102 @@
+
+
+ BackupItem
+
+
+
+ 0
+ 0
+ 634
+ 86
+
+
+
+ Form
+
+
+ -
+
+
-
+
+
+
+ 48
+ 48
+
+
+
+
+ 0
+ 48
+
+
+
+
+
+
+ true
+
+
+ Qt::AlignCenter
+
+
+
+ -
+
+
+ <html><head/><body><p><span style=" font-size:12pt; font-weight:600;">Game Name</span></p><p><span style=" font-size:10pt;">0.00 GiB</span></p></body></html>
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+
+ 40
+ 20
+
+
+
+
+ -
+
+
+
+ 0
+ 0
+
+
+
+
+ 0
+ 32
+
+
+
+ Delete entry
+
+
+
+ -
+
+
+
+ 0
+ 32
+
+
+
+ Open folder
+
+
+
+
+
+
+
+
+
+
diff --git a/backupmanagerform.cpp b/backupmanagerform.cpp
new file mode 100644
index 0000000..839fe3c
--- /dev/null
+++ b/backupmanagerform.cpp
@@ -0,0 +1,195 @@
+/*
+ * QCMA: Cross-platform content manager assistant for the PS Vita
+ *
+ * Copyright (C) 2013 Codestation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "backupmanagerform.h"
+#include "ui_backupmanagerform.h"
+#include "cmaobject.h"
+#include "sforeader.h"
+#include "confirmdialog.h"
+#include "utils.h"
+
+#include
+#include
+#include
+#include
+
+#include
+
+BackupManagerForm::BackupManagerForm(QWidget *parent) :
+ QWidget(parent),
+ ui(new Ui::BackupManagerForm)
+{
+ ui->setupUi(this);
+ setupForm();
+}
+
+BackupManagerForm::~BackupManagerForm()
+{
+ delete ui;
+}
+
+void BackupManagerForm::setupForm()
+{
+ this->resize(800, 480);
+ connect(ui->backupComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(loadBackupListing(int)));
+ ui->tableWidget->setVerticalScrollMode(QAbstractItemView::ScrollPerPixel);
+ ui->tableWidget->horizontalHeader()->hide();
+ // the the account name when vitamtp returns this value
+ ui->accountBox->addItem(QSettings().value("lastAccountId", tr("Default account")).toString());
+}
+
+void BackupManagerForm::removeEntry(BackupItem *item)
+{
+ ConfirmDialog msgBox;
+
+ msgBox.setMessageText(tr("Are you sure to remove the backup of the following entry?"), item->title);
+ msgBox.setMessagePixmap(*item->getIconPixmap(), item->getIconWidth());
+
+ switch(msgBox.exec()) {
+ case QDialogButtonBox::Ok:
+ break;
+ case QDialogButtonBox::Cancel:
+ return;
+ default:
+ return;
+ }
+
+ QMutexLocker locker(&db->mutex);
+
+ CMAObject *obj = db->ohfiToObject(item->ohfi);
+ if(obj) {
+ obj->removeReferencedObject();
+ db->remove(obj);
+ }
+ ui->tableWidget->removeRow(item->row);
+}
+
+void BackupManagerForm::loadBackupListing(int index)
+{
+ int ohfi;
+ bool sys_dir;
+ int img_width;
+
+ ui->tableWidget->clear();
+
+ switch(index) {
+ case 0:
+ ohfi = VITA_OHFI_VITAAPP;
+ img_width = 48;
+ sys_dir = true;
+ break;
+ case 1:
+ ohfi = VITA_OHFI_PSPAPP;
+ img_width = 80;
+ sys_dir = true;
+ break;
+ case 2:
+ ohfi = VITA_OHFI_PSMAPP;
+ img_width = 48;
+ sys_dir = true;
+ break;
+ case 3:
+ ohfi = VITA_OHFI_PSXAPP;
+ img_width = 48;
+ sys_dir = true;
+ break;
+ case 4:
+ ohfi = VITA_OHFI_PSPSAVE;
+ img_width = 80;
+ sys_dir = false;
+ break;
+ case 5:
+ ohfi = VITA_OHFI_BACKUP;
+ img_width = 48;
+ sys_dir = false;
+ break;
+ default:
+ ohfi = VITA_OHFI_VITAAPP;
+ img_width = 48;
+ sys_dir = true;
+ }
+
+ db->mutex.lock();
+
+ // get the item list
+ metadata_t *meta;
+ int row_count = db->filterObjects(ohfi, &meta);
+ ui->tableWidget->setRowCount(row_count);
+
+ // adjust the table item width to fill all the widget
+ QHeaderView *vert_header = ui->tableWidget->verticalHeader();
+ QHeaderView *horiz_header = ui->tableWidget->horizontalHeader();
+ horiz_header->setResizeMode(QHeaderView::Stretch);
+
+ CMAObject *obj = db->ohfiToObject(ohfi);
+ ui->usageLabel->setText(tr("Backup disk usage: %1").arg(readable_size(obj->metadata.size, true)));
+
+ QList item_list;
+
+ while(meta) {
+ QString base_path = obj->path + QDir::separator() + meta->name;
+ QString parent_path = sys_dir ? base_path + QDir::separator() + "sce_sys" : base_path;
+ SfoReader reader;
+ QString game_name;
+
+ // retrieve the game name from the SFO
+ if(reader.load(QDir(parent_path).absoluteFilePath(sys_dir ? "param.sfo" : "PARAM.SFO"))) {
+ game_name = QString::fromUtf8(reader.value("TITLE", meta->name));
+ } else {
+ game_name = QString(meta->name);
+ }
+
+ BackupItem *item = new BackupItem();
+ // save the game title and ohfi for sorting/deleting
+ item->ohfi = meta->ohfi;
+ item->title = game_name;
+
+ connect(item, SIGNAL(deleteEntry(BackupItem*)), this, SLOT(removeEntry(BackupItem*)));
+ QString size = readable_size(meta->size);
+
+ // check if the game data is present, else is just a LiveArea launcher
+ if(sys_dir && !(QDir(base_path + QDir::separator() + "app").exists() || QDir(base_path + QDir::separator() + "game").exists())) {
+ size.append(tr(" - (Launcher only)"));
+ }
+
+ item->setItemInfo(game_name, size);
+ item->setItemIcon(QDir(parent_path).absoluteFilePath(sys_dir ? "icon0.png" : "ICON0.PNG"), img_width);
+ item->setDirectory(obj->path + QDir::separator() + meta->name);
+ item->resize(646, 60);
+
+ item_list << item;
+ meta = meta->next_metadata;
+ }
+
+ qSort(item_list.begin(), item_list.end(), BackupItem::lessThan);
+
+ int row;
+ QList::iterator it;
+ vert_header->setUpdatesEnabled(false);
+
+ // insert the sorted items into the table
+ for(it = item_list.begin(), row = 0; it != item_list.end(); ++it, ++row) {
+ (*it)->row = row;
+ ui->tableWidget->setCellWidget(row, 0, *it);
+ vert_header->resizeSection(row, 60);
+ }
+
+ vert_header->setUpdatesEnabled(true);
+ db->mutex.unlock();
+}
diff --git a/backupmanagerform.h b/backupmanagerform.h
new file mode 100644
index 0000000..b914098
--- /dev/null
+++ b/backupmanagerform.h
@@ -0,0 +1,52 @@
+/*
+ * QCMA: Cross-platform content manager assistant for the PS Vita
+ *
+ * Copyright (C) 2013 Codestation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef BACKUPMANAGERFORM_H
+#define BACKUPMANAGERFORM_H
+
+#include "database.h"
+#include "backupitem.h"
+
+#include
+
+namespace Ui {
+class BackupManagerForm;
+}
+
+class BackupManagerForm : public QWidget
+{
+ Q_OBJECT
+
+public:
+ explicit BackupManagerForm(QWidget *parent = 0);
+ ~BackupManagerForm();
+
+ Database *db;
+
+private:
+ void setupForm();
+
+ Ui::BackupManagerForm *ui;
+
+public slots:
+ void loadBackupListing(int index);
+ void removeEntry(BackupItem *item);
+};
+
+#endif // BACKUPMANAGERFORM_H
diff --git a/backupmanagerform.ui b/backupmanagerform.ui
new file mode 100644
index 0000000..6930f40
--- /dev/null
+++ b/backupmanagerform.ui
@@ -0,0 +1,109 @@
+
+
+ BackupManagerForm
+
+
+
+ 0
+ 0
+ 857
+ 478
+
+
+
+ Backup Manager
+
+
+ -
+
+
-
+
+
-
+
+
+ Account ID / Username
+
+
+
+ -
+
+
+
+
+ -
+
+
+ QFormLayout::AllNonFixedFieldsGrow
+
+
-
+
+
+ Backup Type
+
+
+ 2
+
+
+
+ -
+
+
-
+
+ PS Vita Games
+
+
+ -
+
+ PSP Games
+
+
+ -
+
+ PSM Games
+
+
+ -
+
+ PSOne Games
+
+
+ -
+
+ PSP Savedatas
+
+
+ -
+
+ Backups
+
+
+
+
+
+
+
+
+ -
+
+
+ 1
+
+
+
+
+ -
+
+
-
+
+
+ Backup disk usage
+
+
+
+
+
+
+
+
+
+
diff --git a/confirmdialog.cpp b/confirmdialog.cpp
new file mode 100644
index 0000000..7aea061
--- /dev/null
+++ b/confirmdialog.cpp
@@ -0,0 +1,50 @@
+/*
+ * QCMA: Cross-platform content manager assistant for the PS Vita
+ *
+ * Copyright (C) 2013 Codestation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include "confirmdialog.h"
+#include "ui_confirmdialog.h"
+
+const QString ConfirmDialog::messageTemplate = ""
+"%1
"
+"%2
"
+"";
+
+ConfirmDialog::ConfirmDialog(QWidget *parent) :
+ QDialog(parent),
+ ui(new Ui::ConfirmDialog)
+{
+ ui->setupUi(this);
+ this->layout()->setSizeConstraint(QLayout::SetFixedSize);
+}
+
+void ConfirmDialog::setMessageText(const QString message, const QString game_title)
+{
+ ui->confirmText->setText(messageTemplate.arg(message, game_title));
+}
+
+void ConfirmDialog::setMessagePixmap(const QPixmap &pixmap, int width)
+{
+ ui->itemPicture->setPixmap(pixmap);
+ ui->itemPicture->setMinimumWidth(width);
+}
+
+ConfirmDialog::~ConfirmDialog()
+{
+ delete ui;
+}
diff --git a/confirmdialog.h b/confirmdialog.h
new file mode 100644
index 0000000..f9be667
--- /dev/null
+++ b/confirmdialog.h
@@ -0,0 +1,46 @@
+/*
+ * QCMA: Cross-platform content manager assistant for the PS Vita
+ *
+ * Copyright (C) 2013 Codestation
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef CONFIRMDIALOG_H
+#define CONFIRMDIALOG_H
+
+#include
+
+namespace Ui {
+class ConfirmDialog;
+}
+
+class ConfirmDialog : public QDialog
+{
+ Q_OBJECT
+
+public:
+ explicit ConfirmDialog(QWidget *parent = 0);
+ ~ConfirmDialog();
+
+ void setMessageText(const QString message, const QString game_title);
+ void setMessagePixmap(const QPixmap &pixmap, int width);
+
+ static const QString messageTemplate;
+
+private:
+ Ui::ConfirmDialog *ui;
+};
+
+#endif // CONFIRMDIALOG_H
diff --git a/confirmdialog.ui b/confirmdialog.ui
new file mode 100644
index 0000000..7eae756
--- /dev/null
+++ b/confirmdialog.ui
@@ -0,0 +1,120 @@
+
+
+ ConfirmDialog
+
+
+
+ 0
+ 0
+ 519
+ 106
+
+
+
+ Confirmation Message
+
+
+ true
+
+
+ -
+
+
-
+
+
+
+ 48
+ 48
+
+
+
+
+ 0
+ 48
+
+
+
+
+
+
+ true
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QSizePolicy::Fixed
+
+
+
+ 10
+ 0
+
+
+
+
+ -
+
+
+ <html><head/><body><p><span style=" font-size:10pt;">Are you sure to delete the backup of the following game?</span></p><p><span style=" font-size:12pt; font-weight:600;">Game Name</span></p></body></html>
+
+
+
+ 0
+
+
+
+
+
+ -
+
+
+ Qt::Horizontal
+
+
+ QDialogButtonBox::Cancel|QDialogButtonBox::Ok
+
+
+
+
+
+
+
+
+ buttonBox
+ accepted()
+ ConfirmDialog
+ accept()
+
+
+ 248
+ 254
+
+
+ 157
+ 274
+
+
+
+
+ buttonBox
+ rejected()
+ ConfirmDialog
+ reject()
+
+
+ 316
+ 260
+
+
+ 286
+ 274
+
+
+
+
+