# HG changeset patch # User dag10 # Date 1358165987 -3600 # Node ID b557c73a75934d23f0f76a724b24287af6ee6e8e # Parent 67e257b98422dbd0e17785909da64b277f588548 GCI2012: Abstract Hedgewars Dialogs diff -r 67e257b98422 -r b557c73a7593 QTfrontend/CMakeLists.txt --- a/QTfrontend/CMakeLists.txt Mon Jan 14 12:45:01 2013 +0100 +++ b/QTfrontend/CMakeLists.txt Mon Jan 14 13:19:47 2013 +0100 @@ -116,6 +116,7 @@ team.h util/DataManager.h util/LibavInteraction.h + util/MessageDialog.h ) set(hwfr_hdrs diff -r 67e257b98422 -r b557c73a7593 QTfrontend/hwform.cpp --- a/QTfrontend/hwform.cpp Mon Jan 14 12:45:01 2013 +0100 +++ b/QTfrontend/hwform.cpp Mon Jan 14 13:19:47 2013 +0100 @@ -96,6 +96,7 @@ #include "recorder.h" #include "playerslistmodel.h" +#include "MessageDialog.h" #include "DataManager.h" #include "AutoUpdater.h" @@ -961,7 +962,7 @@ ui.pageScheme->selectScheme->setCurrentIndex(ui.pageOptions->SchemesName->currentIndex()); if (ui.pageOptions->SchemesName->currentIndex() < ammoSchemeModel->numberOfDefaultSchemes) { - ShowErrorMessage(QMessageBox::tr("Cannot delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText())); + MessageDialog::ShowErrorMessage(QMessageBox::tr("Cannot delete default scheme '%1'!").arg(ui.pageOptions->SchemesName->currentText()), this); } else { @@ -987,7 +988,7 @@ QListWidgetItem * curritem = ui.pagePlayDemo->DemosList->currentItem(); if (!curritem) { - ShowErrorMessage(QMessageBox::tr("Please select a record from the list")); + MessageDialog::ShowErrorMessage(QMessageBox::tr("Please select a record from the list"), this); return; } CreateGame(0, 0, 0); @@ -1161,7 +1162,7 @@ switch (ui.Pages->currentIndex()) { case ID_PAGE_INGAME: - ShowErrorMessage(errmsg); + MessageDialog::ShowErrorMessage(errmsg, this); // no break case ID_PAGE_NETGAME: ui.pageNetGame->displayError(errmsg); @@ -1438,7 +1439,7 @@ pnetserver = new HWNetServer; if (!pnetserver->StartServer(ui.pageNetServer->sbPort->value())) { - ShowErrorMessage(QMessageBox::tr("Unable to start server")); + MessageDialog::ShowErrorMessage(QMessageBox::tr("Unable to start server"), this); delete pnetserver; pnetserver = 0; @@ -1497,7 +1498,7 @@ if (hwnet) { QString errorStr = QMessageBox::tr("Connection to server is lost") + (reason.isEmpty()?"":("\n\n" + HWNewNet::tr("Quit reason: ") + '"' + reason +'"')); - ShowErrorMessage(errorStr); + MessageDialog::ShowErrorMessage(errorStr, this); } while (ui.Pages->currentIndex() != ID_PAGE_NET @@ -1603,16 +1604,6 @@ m_lastDemo = QByteArray(); } -void HWForm::ShowErrorMessage(const QString & msg) -{ - QMessageBox msgMsg(this); - msgMsg.setIcon(QMessageBox::Warning); - msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error")); - msgMsg.setText(msg); - msgMsg.setWindowModality(Qt::WindowModal); - msgMsg.exec(); -} - void HWForm::GetRecord(RecordType type, const QByteArray & record) { if (type != rtNeither) @@ -1645,7 +1636,7 @@ QFile demofile(filename); if (!demofile.open(QIODevice::WriteOnly)) - ShowErrorMessage(tr("Cannot save record to file %1").arg(filename)); + MessageDialog::ShowErrorMessage(tr("Cannot save record to file %1").arg(filename), this); else { demofile.write(demo); @@ -1926,7 +1917,7 @@ infoMsg.exec(); } else - ShowErrorMessage(QMessageBox::tr("File association failed.")); + MessageDialog::ShowErrorMessage(QMessageBox::tr("File association failed."), this); } void HWForm::openRegistrationPage() @@ -1950,7 +1941,7 @@ QFile demofile(filePath); ok = demofile.open(QIODevice::WriteOnly); if (!ok) - ShowErrorMessage(tr("Cannot save record to file %1").arg(filePath)); + MessageDialog::ShowErrorMessage(tr("Cannot save record to file %1").arg(filePath), this); else { ok = -1 != demofile.write(m_lastDemo); @@ -1975,7 +1966,7 @@ if (summary.isEmpty() || description.isEmpty()) { - ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional.")); + MessageDialog::ShowErrorMessage(QMessageBox::tr("Please fill out all fields. Email is optional."), this); return; } @@ -2030,8 +2021,12 @@ } else { - ShowErrorMessage(QString("Error: ") + reply->readAll()); + MessageDialog::ShowErrorMessage(QString("Error: ") + reply->readAll(), this); ui.pageFeedback->LoadCaptchaImage(); } } +void HWForm::ShowErrorMessage(const QString & msg) +{ + MessageDialog::ShowErrorMessage(msg, this); +} diff -r 67e257b98422 -r b557c73a7593 QTfrontend/ui/page/pagefeedback.cpp --- a/QTfrontend/ui/page/pagefeedback.cpp Mon Jan 14 12:45:01 2013 +0100 +++ b/QTfrontend/ui/page/pagefeedback.cpp Mon Jan 14 13:19:47 2013 +0100 @@ -48,6 +48,7 @@ #include #include "pagefeedback.h" +#include "MessageDialog.h" #include "hwconsts.h" QLayout * PageFeedback::bodyLayoutDefinition() @@ -144,7 +145,7 @@ if (reply->error() != QNetworkReply::NoError) { qDebug() << "Error generating captcha image: " << reply->errorString(); - ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); + MessageDialog::ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"), this); return; } @@ -155,7 +156,7 @@ if (!okay) { qDebug() << "Failed to get captcha ID: " << body; - ShowErrorMessage(QMessageBox::tr("Failed to generate captcha")); + MessageDialog::ShowErrorMessage(QMessageBox::tr("Failed to generate captcha"), this); return; } @@ -172,7 +173,7 @@ if (reply->error() != QNetworkReply::NoError) { qDebug() << "Error loading captcha image: " << reply->errorString(); - ShowErrorMessage(QMessageBox::tr("Failed to download captcha")); + MessageDialog::ShowErrorMessage(QMessageBox::tr("Failed to download captcha"), this); return; } @@ -370,16 +371,6 @@ //TODO } -void PageFeedback::ShowErrorMessage(const QString & msg) -{ - QMessageBox msgMsg(this); - msgMsg.setIcon(QMessageBox::Warning); - msgMsg.setWindowTitle(QMessageBox::tr("Hedgewars - Error")); - msgMsg.setText(msg); - msgMsg.setWindowModality(Qt::WindowModal); - msgMsg.exec(); -} - void PageFeedback::ShowSpecs() { QMessageBox msgMsg(this); diff -r 67e257b98422 -r b557c73a7593 QTfrontend/util/MessageDialog.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/util/MessageDialog.cpp Mon Jan 14 13:19:47 2013 +0100 @@ -0,0 +1,39 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2004-2012 Andrey Korotaev + * + * 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; version 2 of the License + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#include "MessageDialog.h" + +int MessageDialog::ShowErrorMessage(const QString & msg, QWidget * parent) +{ + return ShowMessage(msg, QMessageBox::tr("Hedgewars - Warning"), QMessageBox::Warning, parent); +} + +int MessageDialog::ShowInfoMessage(const QString & msg, QWidget * parent) +{ + return ShowMessage(msg, QMessageBox::tr("Hedgewars - Information"), QMessageBox::Information, parent); +} + +int MessageDialog::ShowMessage(const QString & msg, const QString & title, QMessageBox::Icon icon, QWidget * parent) +{ + QMessageBox msgMsg(parent); + msgMsg.setIcon(icon); + msgMsg.setWindowTitle(title.isEmpty() ? QMessageBox::tr("Hedgewars") : title); + msgMsg.setText(msg); + msgMsg.setWindowModality(Qt::WindowModal); + return msgMsg.exec(); +} \ No newline at end of file diff -r 67e257b98422 -r b557c73a7593 QTfrontend/util/MessageDialog.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QTfrontend/util/MessageDialog.h Mon Jan 14 13:19:47 2013 +0100 @@ -0,0 +1,35 @@ +/* + * Hedgewars, a free turn based strategy game + * Copyright (c) 2004-2012 Andrey Korotaev + * + * 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; version 2 of the License + * + * 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + */ + +#ifndef MESSAGEDIALOG_H +#define MESSAGEDIALOG_H + +#include +#include + +class QWidget; + +class MessageDialog +{ + public: + static int ShowErrorMessage(const QString & msg, QWidget * parent = 0); + static int ShowInfoMessage(const QString & msg, QWidget * parent = 0); + static int ShowMessage(const QString & msg, const QString & title = QString(), QMessageBox::Icon icon = QMessageBox::NoIcon, QWidget * parent = 0); +}; + +#endif \ No newline at end of file