From aa658f95f6c47385f9bbb310a5c80550b1511d5b Mon Sep 17 00:00:00 2001 From: Ira Aspen Date: Tue, 9 Feb 2016 03:10:57 +0000 Subject: [PATCH] Gave error dlg a description of the error for the user. --- cockatrice/src/dlg_add_set_result.cpp | 9 +++++---- cockatrice/src/dlg_add_set_result.h | 5 +++-- cockatrice/src/tab_deck_editor.cpp | 11 +++++++++-- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/cockatrice/src/dlg_add_set_result.cpp b/cockatrice/src/dlg_add_set_result.cpp index 03645408..ca5107be 100644 --- a/cockatrice/src/dlg_add_set_result.cpp +++ b/cockatrice/src/dlg_add_set_result.cpp @@ -4,18 +4,19 @@ #include #include -DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success) : QDialog(parent) { +DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success, QString msg) : QDialog(parent) { status = new QLabel(this); - restart = new QLabel(this); + message = new QLabel(this); if (success) { setWindowTitle(tr("Success")); status->setText(QString("Sets/cards added to Cockatrice.")); - restart->setText(QString("You must restart Cockatrice to use the new sets/cards.")); + message->setText(QString("You must restart Cockatrice to use the new sets/cards.")); } else { setWindowTitle(tr("Failed")); status->setText(QString("Sets/cards failed to import.")); + message->setText(msg); } QDialogButtonBox *buttonBox = new QDialogButtonBox(this); @@ -25,7 +26,7 @@ DlgAddSetResult::DlgAddSetResult(QWidget *parent, bool success) : QDialog(parent QVBoxLayout *parentLayout = new QVBoxLayout(this); parentLayout->addWidget(status); - parentLayout->addWidget(restart); + parentLayout->addWidget(message); parentLayout->addWidget(buttonBox); setLayout(parentLayout); diff --git a/cockatrice/src/dlg_add_set_result.h b/cockatrice/src/dlg_add_set_result.h index 6a30af24..d7645313 100644 --- a/cockatrice/src/dlg_add_set_result.h +++ b/cockatrice/src/dlg_add_set_result.h @@ -3,15 +3,16 @@ #include #include +#include class DlgAddSetResult : public QDialog { Q_OBJECT public: - DlgAddSetResult(QWidget *parent, bool success); + DlgAddSetResult(QWidget *parent, bool success, QString msg); private slots: void closeDialog(); private: - QLabel *status, *restart; + QLabel *status, *message; QPushButton *ok; }; diff --git a/cockatrice/src/tab_deck_editor.cpp b/cockatrice/src/tab_deck_editor.cpp index 7c170181..a874f22f 100644 --- a/cockatrice/src/tab_deck_editor.cpp +++ b/cockatrice/src/tab_deck_editor.cpp @@ -885,16 +885,23 @@ void TabDeckEditor::actAddCustomSet() if (!dialog.exec()) return; + QString fileName = dialog.selectedFiles().at(0); + + if (!QFile::exists(fileName)) { + DlgAddSetResult dlg(this, false, QString("Selected file cannot be found.")); + dlg.exec(); + return; + } + QDir dir(dataDir + "/customsets"); int nextPrefix = getNextCustomSetPrefix(dir); - QString fileName = dialog.selectedFiles().at(0); bool res = QFile::copy( fileName, dir.absolutePath() + "/" + (nextPrefix > 9 ? "" : "0") + QString::number(nextPrefix) + "." + QFileInfo(fileName).fileName() ); - DlgAddSetResult dlg(this, res); + DlgAddSetResult dlg(this, res, QString()); dlg.exec(); }