* more changes to the savetoy example. now it actually does stuff

git-svn-id: http://wiiqt.googlecode.com/svn/trunk@38 389f4c8b-5dfe-645f-db0e-df882bc27289
This commit is contained in:
giantpune@gmail.com 2011-01-02 08:18:00 +00:00
parent cc09d9e72f
commit a5d91b5bbb
3 changed files with 132 additions and 50 deletions

View File

@ -11,12 +11,13 @@
#include "quazipfile.h" #include "quazipfile.h"
//TODO... get these from settings and dont use global variables //TODO... get these from settings and dont use global variables
//static QString sneekPath = "/media/SDHC_4GB"; static QString sneekPath = "/media/SDHC_4GB";
static QString sneekPath = "/home/j/c/QtWii/test";
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), bannerthread( this ) MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow), bannerthread( this )
{ {
ui->setupUi(this); ui->setupUi(this);
ClearSneekGuiInfo();
ClearPcGuiInfo();
progressBar.setVisible( false ); progressBar.setVisible( false );
ui->statusBar->addPermanentWidget( &progressBar, 0 ); ui->statusBar->addPermanentWidget( &progressBar, 0 );
ngID = 0; ngID = 0;
@ -32,21 +33,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
connect( &sneekIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextSneekIcon() ) ); connect( &sneekIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextSneekIcon() ) );
connect( &pcIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextPcIcon() ) ); connect( &pcIconTimer, SIGNAL( timeout() ), this, SLOT( ShowNextPcIcon() ) );
pcPath = "./saveBackups"; //GetSavesFromSneek( "/media/WiiFat500" );
//GetSavesFromSneek( "/media/WiiFat500" );
GetSavesFromSneek( sneekPath ); GetSavesFromSneek( sneekPath );
GetSavesFromPC( pcPath ); //GetSavesFromPC( "./saveBackups" );
ngID = 0x4324c84;
ngKeyID = 0x6aedb6ed;
ngMac = QByteArray::fromHex( "0017abd2f253" );
ngPriv = QByteArray::fromHex( "00633682060dc10f5e8ec41907745f6380b67f8ad11019caf21a3ea242d2" );
ngSig = QByteArray::fromHex( "0015097c4e17ad791aa971221e07a0a2d9c97c6e2885fc7bf624e564c34100dd18568f683aa6f4f5a984842ddb002ef87724594975d0d43a0ecff81d" );
//QMessageBox::aboutQt( this, "bla" );
//QString bla = GetSaveName( 0x1000112345678ull );
//qDebug() << "bla" << bla;
} }
@ -96,6 +85,7 @@ void MainWindow::GetSavesFromPC( const QString &path )
progressBar.setVisible( true ); progressBar.setVisible( true );
bannerthread.GetBanners( pcPath ); bannerthread.GetBanners( pcPath );
} }
void MainWindow::ReceivePcItem( PcSaveInfo info ) void MainWindow::ReceivePcItem( PcSaveInfo info )
{ {
//qDebug() << "received a pc save"; //qDebug() << "received a pc save";
@ -103,40 +93,20 @@ void MainWindow::ReceivePcItem( PcSaveInfo info )
return; return;
SaveBanner sb( info.banner ); SaveBanner sb( info.banner );
new SaveListItem( sb, info.tid, 0, ui->listWidget_pcSaves ); new SaveListItem( sb, info.tid, 0, ui->listWidget_pcSaves );
//ui->listWidget_sneekSaves->addItem( item );
//descMap.insert( tid, descriptions );
pcInfos << info; pcInfos << info;
} }
/*
//sneek save clicked
void MainWindow::on_listWidget_sneekSaves_itemClicked(QListWidgetItem* item)
{
if( !item )
return;
SaveListItem *i = static_cast< SaveListItem * >( item );
qDebug() << "item clicked" << i->Tid();
}
//sneek save double clicked
void MainWindow::on_listWidget_sneekSaves_itemActivated( QListWidgetItem* item )
{
if( !item )
return;
SaveListItem *i = static_cast< SaveListItem * >( item );
qDebug() << "item activated" << i->Tid();
}*/
//sneek save item changed //sneek save item changed
void MainWindow::on_listWidget_sneekSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous) void MainWindow::on_listWidget_sneekSaves_currentItemChanged( QListWidgetItem* current, QListWidgetItem* previous )
{ {
Q_UNUSED( previous ); Q_UNUSED( previous );
if( !current ) if( !current )
{
ClearSneekGuiInfo();
return; return;
}
SaveListItem *i = static_cast< SaveListItem * >( current ); SaveListItem *i = static_cast< SaveListItem * >( current );
ShowSneekSaveDetails( i ); ShowSneekSaveDetails( i );
} }
@ -146,7 +116,6 @@ void MainWindow::ReceiveSneekBanner( QByteArray stuff, const QString& tid, int s
QByteArray copy = stuff; QByteArray copy = stuff;
SaveBanner sb( copy ); SaveBanner sb( copy );
new SaveListItem( sb, tid, size, ui->listWidget_sneekSaves ); new SaveListItem( sb, tid, size, ui->listWidget_sneekSaves );
//ui->listWidget_sneekSaves->addItem( item );
} }
//get a pregress update from something that is doing work //get a pregress update from something that is doing work
@ -232,6 +201,7 @@ void MainWindow::ShowSneekSaveDetails( SaveListItem *item )
} }
} }
//slots for cycling animated icons
void MainWindow::ShowNextSneekIcon() void MainWindow::ShowNextSneekIcon()
{ {
if( ++currentSneekIcon >= sneekIcon.size() ) if( ++currentSneekIcon >= sneekIcon.size() )
@ -333,7 +303,11 @@ bool MainWindow::NG_Ok()
//button to extract a save from sneek clicked //button to extract a save from sneek clicked
void MainWindow::on_pushButton_sneekExtract_clicked() void MainWindow::on_pushButton_sneekExtract_clicked()
{ {
if( pcPath.isEmpty() )
{
ui->statusBar->showMessage( tr( "Set a path to extract saves first" ) );
return;
}
QList<QListWidgetItem*>selected = ui->listWidget_sneekSaves->selectedItems(); QList<QListWidgetItem*>selected = ui->listWidget_sneekSaves->selectedItems();
quint16 cnt = selected.size(); quint16 cnt = selected.size();
if( !cnt ) if( !cnt )
@ -448,6 +422,12 @@ void MainWindow::AddNewPCSave( const QString &desc, const QString &tid, quint32
info.paths << path; info.paths << path;
pcInfos.replace( i, info ); pcInfos.replace( i, info );
if( currentPcSave == i )
{
QString version = path;
version.remove( 0, version.lastIndexOf( "/" ) + 1 );
ui->comboBox_pcSelect->addItem( version );
}
return; return;
} }
} }
@ -545,12 +525,12 @@ void MainWindow::on_actionSet_NG_Keys_triggered()
ngMac = d.ngMac; ngMac = d.ngMac;
ngPriv = d.ngPriv; ngPriv = d.ngPriv;
ngSig = d.ngSig; ngSig = d.ngSig;
/*qDebug() << "accepted"; qDebug() << "accepted";
qDebug() << hex << d.ngID qDebug() << hex << d.ngID
<< "\n" << d.ngKeyID << "\n" << d.ngKeyID
<< "\n" << d.ngMac.toHex() << "\n" << d.ngMac.toHex()
<< "\n" << d.ngPriv.toHex() << "\n" << d.ngPriv.toHex()
<< "\n" << d.ngSig.toHex();*/ << "\n" << d.ngSig.toHex();
} }
//PC list item changed //PC list item changed
@ -558,17 +538,19 @@ void MainWindow::on_listWidget_pcSaves_currentItemChanged( QListWidgetItem* curr
{ {
Q_UNUSED( previous ); Q_UNUSED( previous );
if( !current ) if( !current )
{
ClearPcGuiInfo();
return; return;
}
SaveListItem *i = static_cast< SaveListItem * >( current ); SaveListItem *i = static_cast< SaveListItem * >( current );
ShowPCSaveDetails( i ); ShowPCSaveDetails( i );
} }
//show detials for a save backed up on the PC //show detials for a save backed up on the PC
void MainWindow::ShowPCSaveDetails( SaveListItem *item ) void MainWindow::ShowPCSaveDetails( SaveListItem *item )
{ {
qDebug() << "MainWindow::ShowPCSaveDetails"; //qDebug() << "MainWindow::ShowPCSaveDetails";
pcIconTimer.stop(); pcIconTimer.stop();
currentPcIcon = 0; currentPcIcon = 0;
pcIcon.clear(); pcIcon.clear();
@ -636,7 +618,7 @@ void MainWindow::ShowPCSaveDetails( SaveListItem *item )
//pc combobox index changed //pc combobox index changed
void MainWindow::on_comboBox_pcSelect_currentIndexChanged( int index ) void MainWindow::on_comboBox_pcSelect_currentIndexChanged( int index )
{ {
qDebug() << "MainWindow::on_comboBox_pcSelect_currentIndexChanged" << index; //qDebug() << "MainWindow::on_comboBox_pcSelect_currentIndexChanged" << index;
if( index < 0 ) if( index < 0 )
return; return;
ui->plainTextEdit_pcDesc->clear(); ui->plainTextEdit_pcDesc->clear();
@ -674,3 +656,91 @@ void MainWindow::on_comboBox_pcSelect_currentIndexChanged( int index )
ui->plainTextEdit_pcDesc->clear(); ui->plainTextEdit_pcDesc->clear();
ui->plainTextEdit_pcDesc->insertPlainText( pcInfos.at( currentPcSave ).descriptions.at( index ) ); ui->plainTextEdit_pcDesc->insertPlainText( pcInfos.at( currentPcSave ).descriptions.at( index ) );
} }
//delete PC save button clicked
void MainWindow::on_pushButton_pcDelete_clicked()
{
QList<QListWidgetItem*>selected = ui->listWidget_pcSaves->selectedItems();
quint32 cnt = selected.size();
if( cnt != 1 )
return;
SaveListItem *si = static_cast< SaveListItem * >( selected.at( 0 ) );
int i = ui->comboBox_pcSelect->currentIndex();
//find the item in the list of infos that matches this item
currentPcSave = 0xffffffff;
cnt = pcInfos.size();
for( quint32 i = 0; i < cnt; i++ )
{
if( si->Tid() == pcInfos.at( i ).tid )
{
currentPcSave = i;
break;
}
}
if( currentPcSave == 0xffffffff )
{
qWarning() << "MainWindow::on_pushButton_pcDelete_clicked() -> tid not found";
return;
}
if( QMessageBox::question( this, tr( "Are you sure?" ), \
tr( "You are about to delete the backed up save<br>\"%1\"?" ).arg( pcInfos.at( currentPcSave ).paths.at( i ) ),
QMessageBox::Ok | QMessageBox::Cancel, QMessageBox::Cancel ) != QMessageBox::Ok )
return;
//delete the file
if( !QFile::remove( pcInfos.at( currentPcSave ).paths.at( ui->comboBox_pcSelect->currentIndex() ) ) )
{
ui->statusBar->showMessage( tr( "Error deleting file" ), 5000 );
return;
}
if( pcInfos.at( currentPcSave ).sizes.size() == 1 )//there are no more saves for this game
{
pcInfos.takeAt( currentPcSave ); //remove it entirely from the list of knowns
si = static_cast< SaveListItem * >( selected.takeFirst() );//delete its banner from the list
delete si;
}
else //theres more saves for this game on the PC, just remove the selected one
{
//remove entries for this save from the list
pcInfos[ currentPcSave ].descriptions.takeAt( i );
pcInfos[ currentPcSave ].paths.takeAt( i );
pcInfos[ currentPcSave ].sizes.takeAt( i );
ui->comboBox_pcSelect->removeItem( i ); //remove it from the combobox last
}
ui->statusBar->showMessage( tr( "Deleted 1 save from the PC" ), 5000 );
}
void MainWindow::on_actionSet_Local_Path_triggered()
{
QString p = QFileDialog::getExistingDirectory( this, tr( "Select Save Backup path" ), pcPath );
if( p.isEmpty() )
return;
GetSavesFromPC( p );
}
void MainWindow::ClearSneekGuiInfo()
{
ui->label_sneek_icon->clear();
ui->label_sneek_id->clear();
ui->label_sneek_path->clear();
ui->label_sneek_size->clear();
ui->label_sneek_title->clear();
ui->label_sneek_title2->clear();
}
void MainWindow::ClearPcGuiInfo()
{
ui->label_PC_icon->clear();
ui->label_pc_id->clear();
ui->label_pc_path->clear();
ui->label_pc_size->clear();
ui->label_pc_title->clear();
ui->label_pc_title2->clear();
ui->plainTextEdit_pcDesc->clear();
ui->comboBox_pcSelect->clear();
}

View File

@ -56,8 +56,14 @@ private:
bool WriteZipFile( const QByteArray &dataBin, const QByteArray &desc, const QString &path ); bool WriteZipFile( const QByteArray &dataBin, const QByteArray &desc, const QString &path );
void AddNewPCSave( const QString &desc, const QString &tid, quint32 size, const QString &path, SaveBanner banner ); void AddNewPCSave( const QString &desc, const QString &tid, quint32 size, const QString &path, SaveBanner banner );
//clear the data on teh right of the screen
void ClearSneekGuiInfo();
void ClearPcGuiInfo();
private slots: private slots:
void on_actionSet_Local_Path_triggered();
void on_pushButton_pcDelete_clicked();
void on_comboBox_pcSelect_currentIndexChanged(int index); void on_comboBox_pcSelect_currentIndexChanged(int index);
void on_listWidget_pcSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous); void on_listWidget_pcSaves_currentItemChanged(QListWidgetItem* current, QListWidgetItem* previous);
void on_actionSet_NG_Keys_triggered(); void on_actionSet_NG_Keys_triggered();

View File

@ -11,7 +11,7 @@
</rect> </rect>
</property> </property>
<property name="windowTitle"> <property name="windowTitle">
<string>MainWindow</string> <string>SaveToy</string>
</property> </property>
<widget class="QWidget" name="centralWidget"> <widget class="QWidget" name="centralWidget">
<layout class="QGridLayout" name="gridLayout"> <layout class="QGridLayout" name="gridLayout">
@ -21,13 +21,16 @@
<item row="0" column="0"> <item row="0" column="0">
<widget class="QTabWidget" name="tabWidget"> <widget class="QTabWidget" name="tabWidget">
<property name="currentIndex"> <property name="currentIndex">
<number>1</number> <number>0</number>
</property> </property>
<widget class="QWidget" name="sneekTab"> <widget class="QWidget" name="sneekTab">
<attribute name="title"> <attribute name="title">
<string>Sneek</string> <string>Sneek</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_2"> <layout class="QGridLayout" name="gridLayout_2">
<property name="margin">
<number>2</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QListWidget" name="listWidget_sneekSaves"> <widget class="QListWidget" name="listWidget_sneekSaves">
<property name="minimumSize"> <property name="minimumSize">
@ -180,6 +183,9 @@
<string>PC Backups</string> <string>PC Backups</string>
</attribute> </attribute>
<layout class="QGridLayout" name="gridLayout_4"> <layout class="QGridLayout" name="gridLayout_4">
<property name="margin">
<number>2</number>
</property>
<item row="0" column="0"> <item row="0" column="0">
<widget class="QListWidget" name="listWidget_pcSaves"> <widget class="QListWidget" name="listWidget_pcSaves">
<property name="minimumSize"> <property name="minimumSize">
@ -195,7 +201,7 @@
</size> </size>
</property> </property>
<property name="selectionMode"> <property name="selectionMode">
<enum>QAbstractItemView::ExtendedSelection</enum> <enum>QAbstractItemView::SingleSelection</enum>
</property> </property>
<property name="iconSize"> <property name="iconSize">
<size> <size>