From 674005383b068f0c04153c8f03fbe7b687445054 Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Thu, 7 Aug 2014 11:54:26 -0400 Subject: [PATCH 1/3] Added a button and the functionality to clear all downloaded images (all images within subfolders at picsPath/downloadedPics) under Settings. --- cockatrice/src/dlg_settings.cpp | 33 +++++++++++++++++++++++++++------ cockatrice/src/dlg_settings.h | 1 + 2 files changed, 28 insertions(+), 6 deletions(-) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 0950ec60..9e94b084 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -76,6 +76,8 @@ GeneralSettingsPage::GeneralSettingsPage() picsPathEdit->setReadOnly(true); QPushButton *picsPathButton = new QPushButton("..."); connect(picsPathButton, SIGNAL(clicked()), this, SLOT(picsPathButtonClicked())); + QPushButton *clearDownloadedPicsButton = new QPushButton(tr("Clear Downloaded Pics")); + connect(clearDownloadedPicsButton, SIGNAL(clicked()), this, SLOT(clearDownloadedPicsButtonClicked())); cardDatabasePathLabel = new QLabel; cardDatabasePathEdit = new QLineEdit(settingsCache->getCardDatabasePath()); @@ -99,12 +101,13 @@ GeneralSettingsPage::GeneralSettingsPage() pathsGrid->addWidget(picsPathLabel, 2, 0); pathsGrid->addWidget(picsPathEdit, 2, 1); pathsGrid->addWidget(picsPathButton, 2, 2); - pathsGrid->addWidget(cardDatabasePathLabel, 3, 0); - pathsGrid->addWidget(cardDatabasePathEdit, 3, 1); - pathsGrid->addWidget(cardDatabasePathButton, 3, 2); - pathsGrid->addWidget(tokenDatabasePathLabel, 4, 0); - pathsGrid->addWidget(tokenDatabasePathEdit, 4, 1); - pathsGrid->addWidget(tokenDatabasePathButton, 4, 2); + pathsGrid->addWidget(clearDownloadedPicsButton, 3, 1); + pathsGrid->addWidget(cardDatabasePathLabel, 4, 0); + pathsGrid->addWidget(cardDatabasePathEdit, 4, 1); + pathsGrid->addWidget(cardDatabasePathButton, 4, 2); + pathsGrid->addWidget(tokenDatabasePathLabel, 5, 0); + pathsGrid->addWidget(tokenDatabasePathEdit, 5, 1); + pathsGrid->addWidget(tokenDatabasePathButton, 5, 2); pathsGroupBox = new QGroupBox; pathsGroupBox->setLayout(pathsGrid); @@ -161,6 +164,24 @@ void GeneralSettingsPage::picsPathButtonClicked() settingsCache->setPicsPath(path); } +void GeneralSettingsPage::clearDownloadedPicsButtonClicked() +{ + QString picsPath = settingsCache->getPicsPath() + "/downloadedPics/"; + QStringList dirs = QDir(picsPath).entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + for (int i = 0; i < dirs.length(); i ++) { + QString currentPath = picsPath + dirs.at(i) + "/"; + QStringList files = QDir(currentPath).entryList(QDir::Files); + bool failRemove = false; + for (int j = 0; j < files.length(); j ++) + if (!QDir(currentPath).remove(files.at(j))) { + qDebug() << "Failed to remove " + currentPath.toUtf8() + files.at(j).toUtf8(); + failRemove = true; + } + if (!failRemove) + QDir(picsPath).rmdir(dirs.at(i)); + } +} + void GeneralSettingsPage::cardDatabasePathButtonClicked() { QString path = QFileDialog::getOpenFileName(this, tr("Choose path")); diff --git a/cockatrice/src/dlg_settings.h b/cockatrice/src/dlg_settings.h index 55685e1e..0303ceef 100644 --- a/cockatrice/src/dlg_settings.h +++ b/cockatrice/src/dlg_settings.h @@ -31,6 +31,7 @@ private slots: void deckPathButtonClicked(); void replaysPathButtonClicked(); void picsPathButtonClicked(); + void clearDownloadedPicsButtonClicked(); void cardDatabasePathButtonClicked(); void tokenDatabasePathButtonClicked(); void languageBoxChanged(int index); From ae807524972342baaa243de852b3b33323dc871a Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Thu, 7 Aug 2014 14:00:59 -0400 Subject: [PATCH 2/3] Added notification messages informing users of the success or failure of clearing downloaded images. --- cockatrice/src/dlg_settings.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index 9e94b084..ed88e36d 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -168,18 +168,24 @@ void GeneralSettingsPage::clearDownloadedPicsButtonClicked() { QString picsPath = settingsCache->getPicsPath() + "/downloadedPics/"; QStringList dirs = QDir(picsPath).entryList(QDir::AllDirs | QDir::NoDotAndDotDot); + bool outerSuccessRemove = true; for (int i = 0; i < dirs.length(); i ++) { QString currentPath = picsPath + dirs.at(i) + "/"; QStringList files = QDir(currentPath).entryList(QDir::Files); - bool failRemove = false; + bool innerSuccessRemove = true; for (int j = 0; j < files.length(); j ++) if (!QDir(currentPath).remove(files.at(j))) { qDebug() << "Failed to remove " + currentPath.toUtf8() + files.at(j).toUtf8(); - failRemove = true; + outerSuccessRemove = false; + innerSuccessRemove = false; } - if (!failRemove) + if (innerSuccessRemove) QDir(picsPath).rmdir(dirs.at(i)); } + if (outerSuccessRemove) + QMessageBox::information(this, tr("Success"), tr("Downloaded card images have been cleared.")); + else + QMessageBox::critical(this, tr("Error"), tr("One or more downloaded card images could not be cleared.")); } void GeneralSettingsPage::cardDatabasePathButtonClicked() From d3459aabf97eecf1abb7f0c526711bec119a313b Mon Sep 17 00:00:00 2001 From: Peng Liu Date: Thu, 7 Aug 2014 14:15:02 -0400 Subject: [PATCH 3/3] Moved the button from the paths section to be below the "Download high-quality card pictures" checkbox. Button now reads "Reset/Clear Downloaded Pictures". Removed "Path to"s from card/token database, hand/stack/table/player info background, and card back labels. --- cockatrice/src/dlg_settings.cpp | 37 +++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/cockatrice/src/dlg_settings.cpp b/cockatrice/src/dlg_settings.cpp index ed88e36d..414550a9 100644 --- a/cockatrice/src/dlg_settings.cpp +++ b/cockatrice/src/dlg_settings.cpp @@ -42,6 +42,9 @@ GeneralSettingsPage::GeneralSettingsPage() picDownloadCheckBox = new QCheckBox; picDownloadCheckBox->setChecked(settingsCache->getPicDownload()); + + QPushButton *clearDownloadedPicsButton = new QPushButton(tr("Reset/Clear Downloaded Pictures")); + connect(clearDownloadedPicsButton, SIGNAL(clicked()), this, SLOT(clearDownloadedPicsButtonClicked())); picDownloadHqCheckBox = new QCheckBox; picDownloadHqCheckBox->setChecked(settingsCache->getPicDownloadHq()); @@ -55,6 +58,7 @@ GeneralSettingsPage::GeneralSettingsPage() personalGrid->addWidget(languageBox, 0, 1); personalGrid->addWidget(picDownloadCheckBox, 1, 0, 1, 2); personalGrid->addWidget(picDownloadHqCheckBox, 2, 0, 1, 2); + personalGrid->addWidget(clearDownloadedPicsButton, 3, 0, 1, 1); personalGroupBox = new QGroupBox; personalGroupBox->setLayout(personalGrid); @@ -76,8 +80,6 @@ GeneralSettingsPage::GeneralSettingsPage() picsPathEdit->setReadOnly(true); QPushButton *picsPathButton = new QPushButton("..."); connect(picsPathButton, SIGNAL(clicked()), this, SLOT(picsPathButtonClicked())); - QPushButton *clearDownloadedPicsButton = new QPushButton(tr("Clear Downloaded Pics")); - connect(clearDownloadedPicsButton, SIGNAL(clicked()), this, SLOT(clearDownloadedPicsButtonClicked())); cardDatabasePathLabel = new QLabel; cardDatabasePathEdit = new QLineEdit(settingsCache->getCardDatabasePath()); @@ -101,13 +103,12 @@ GeneralSettingsPage::GeneralSettingsPage() pathsGrid->addWidget(picsPathLabel, 2, 0); pathsGrid->addWidget(picsPathEdit, 2, 1); pathsGrid->addWidget(picsPathButton, 2, 2); - pathsGrid->addWidget(clearDownloadedPicsButton, 3, 1); - pathsGrid->addWidget(cardDatabasePathLabel, 4, 0); - pathsGrid->addWidget(cardDatabasePathEdit, 4, 1); - pathsGrid->addWidget(cardDatabasePathButton, 4, 2); - pathsGrid->addWidget(tokenDatabasePathLabel, 5, 0); - pathsGrid->addWidget(tokenDatabasePathEdit, 5, 1); - pathsGrid->addWidget(tokenDatabasePathButton, 5, 2); + pathsGrid->addWidget(cardDatabasePathLabel, 3, 0); + pathsGrid->addWidget(cardDatabasePathEdit, 3, 1); + pathsGrid->addWidget(cardDatabasePathButton, 3, 2); + pathsGrid->addWidget(tokenDatabasePathLabel, 4, 0); + pathsGrid->addWidget(tokenDatabasePathEdit, 4, 1); + pathsGrid->addWidget(tokenDatabasePathButton, 4, 2); pathsGroupBox = new QGroupBox; pathsGroupBox->setLayout(pathsGrid); @@ -183,9 +184,9 @@ void GeneralSettingsPage::clearDownloadedPicsButtonClicked() QDir(picsPath).rmdir(dirs.at(i)); } if (outerSuccessRemove) - QMessageBox::information(this, tr("Success"), tr("Downloaded card images have been cleared.")); + QMessageBox::information(this, tr("Success"), tr("Downloaded card pictures have been reset.")); else - QMessageBox::critical(this, tr("Error"), tr("One or more downloaded card images could not be cleared.")); + QMessageBox::critical(this, tr("Error"), tr("One or more downloaded card pictures could not be cleared.")); } void GeneralSettingsPage::cardDatabasePathButtonClicked() @@ -223,8 +224,8 @@ void GeneralSettingsPage::retranslateUi() deckPathLabel->setText(tr("Decks directory:")); replaysPathLabel->setText(tr("Replays directory:")); picsPathLabel->setText(tr("Pictures directory:")); - cardDatabasePathLabel->setText(tr("Path to card database:")); - tokenDatabasePathLabel->setText(tr("Path to token database:")); + cardDatabasePathLabel->setText(tr("Card database:")); + tokenDatabasePathLabel->setText(tr("Token database:")); } AppearanceSettingsPage::AppearanceSettingsPage() @@ -362,11 +363,11 @@ AppearanceSettingsPage::AppearanceSettingsPage() void AppearanceSettingsPage::retranslateUi() { zoneBgGroupBox->setTitle(tr("Zone background pictures")); - handBgLabel->setText(tr("Path to hand background:")); - stackBgLabel->setText(tr("Path to stack background:")); - tableBgLabel->setText(tr("Path to table background:")); - playerAreaBgLabel->setText(tr("Path to player info background:")); - cardBackPicturePathLabel->setText(tr("Path to picture of card back:")); + handBgLabel->setText(tr("Hand background:")); + stackBgLabel->setText(tr("Stack background:")); + tableBgLabel->setText(tr("Table background:")); + playerAreaBgLabel->setText(tr("Player info background:")); + cardBackPicturePathLabel->setText(tr("Card back:")); cardsGroupBox->setTitle(tr("Card rendering")); displayCardNamesCheckBox->setText(tr("Display card names on cards having a picture"));