From 4696bba0897715cb79eb75fcb14169964e1562e2 Mon Sep 17 00:00:00 2001 From: deva Date: Wed, 18 Mar 2009 13:21:45 +0000 Subject: Made a messagebox wrapper that does the button translation. --- client/client.pro | 4 ++ client/macrowindow.cc | 35 +++++----- client/messagebox.cc | 153 +++++++++++++++++++++++++++++++++++++++++++ client/messagebox.h | 50 ++++++++++++++ client/pracro_dk.ts | 105 +++++++++++++++++++++++++++++ client/widgets/metawidget.cc | 6 +- client/widgets/multilist.cc | 17 ++--- 7 files changed, 342 insertions(+), 28 deletions(-) create mode 100644 client/messagebox.cc create mode 100644 client/messagebox.h create mode 100644 client/pracro_dk.ts (limited to 'client') diff --git a/client/client.pro b/client/client.pro index 6df6c3f..1faa111 100644 --- a/client/client.pro +++ b/client/client.pro @@ -29,6 +29,7 @@ HEADERS += \ macrowindow.h \ mainwindow.h \ macrodrawer.h \ + messagebox.h \ netcom.h \ resumewidget.h \ widgetbuilder.h \ @@ -61,6 +62,7 @@ SOURCES += \ macrowindow.cc \ mainwindow.cc \ macrodrawer.cc \ + messagebox.cc \ netcom.cc \ resumewidget.cc \ widgetbuilder.cc \ @@ -83,3 +85,5 @@ SOURCES += \ widgets/window.cc \ widgets/altcombobox.cc \ widgets/metawidget.cc + +TRANSLATIONS=pracro_dk.ts \ No newline at end of file diff --git a/client/macrowindow.cc b/client/macrowindow.cc index 6beba85..80649a7 100644 --- a/client/macrowindow.cc +++ b/client/macrowindow.cc @@ -27,12 +27,13 @@ #include "macrowindow.h" #include -#include #include #include #include #include +#include "messagebox.h" + #include "widgets/widget.h" #include "widgets/window.h" #include "widgetbuilder.h" @@ -168,19 +169,19 @@ void MacroWindow::commit() if(doCommit()) { // close(); } else { - QMessageBox::critical(NULL, "Fejl", - "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n" - , QMessageBox::Ok); + MessageBox::critical(NULL, "Fejl", + "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n", + MessageBox::Ok); } } void MacroWindow::reset() { /* - QMessageBox::warning(NULL, tr("Reset"), + MessageBox::warning(NULL, tr("Reset"), tr("Du har valgt at nulstille de indtastede data.\n" "Er du sikker?"), - QMessageBox::Yes | QMessageBox::Cancel); + MessageBox::Yes | MessageBox::Cancel); printf("MacroWindow -> resetting...\n"); */ QVector< Widget* >::iterator i = widgets.begin(); @@ -225,9 +226,9 @@ void MacroWindow::cont(QString name) // new_macro("example", macro); // close(); } else { - QMessageBox::critical(NULL, "Fejl", + MessageBox::critical(NULL, "Fejl", "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n", - QMessageBox::Ok); + MessageBox::Ok); } printf("%s : MacroWindow -> continuing...\n", macro.toStdString().c_str()); } @@ -252,9 +253,9 @@ void MacroWindow::cont_nocommit(QString name) // new_macro("example", macro); // close(); } else { - QMessageBox::critical(NULL, "Fejl", + MessageBox::critical(NULL, "Fejl", "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n", - QMessageBox::Ok); + MessageBox::Ok); } printf("%s : MacroWindow -> continuing...\n", macro.toStdString().c_str()); } @@ -351,23 +352,23 @@ void MacroWindow::collapseWrapper() if(isCollapsed()) return; if(waschanged) { - switch(QMessageBox::warning(NULL, + switch(MessageBox::warning(NULL, "Gem ændringerne i makroen?", "Du har valgt at lukke makroen " + macrotitle + ".\n" "Ønsker du at gemme inden du lukker?", - QMessageBox::Save | QMessageBox::Close | QMessageBox::Cancel)) { - case QMessageBox::Save: + MessageBox::Save | MessageBox::Close | MessageBox::Cancel)) { + case MessageBox::Save: if(doCommit()) setCollapsed(true); - else QMessageBox::critical(NULL, + else MessageBox::critical(NULL, "Fejl", "Makroen " + macrotitle + " er ikke udfyldt korrekt, prøv igen.\n", - QMessageBox::Ok); + MessageBox::Ok); break; - case QMessageBox::Close: + case MessageBox::Close: collapse(); break; - case QMessageBox::Cancel: + case MessageBox::Cancel: default: // emit expanding(); // signal the other to close again (if any) break; diff --git a/client/messagebox.cc b/client/messagebox.cc new file mode 100644 index 0000000..902d2fd --- /dev/null +++ b/client/messagebox.cc @@ -0,0 +1,153 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * messagebox.cc + * + * Wed Mar 18 13:33:05 CET 2009 + * Copyright 2009 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro 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 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#include "messagebox.h" + +#include +#include +/* + QString p = tr("KEY", "default vaerdi"); + printf("\n\n\n#######################\n%s\n\n\n", p.toStdString().c_str()); +*/ + +static MessageBox::StandardButton showNewMessageBox(QWidget *parent, + MessageBox::Icon icon, + const QString& title, const QString& text, + MessageBox::StandardButtons buttons, + MessageBox::StandardButton defaultButton) +{ + QMessageBox msgBox(icon, title, text, MessageBox::NoButton, parent); + QDialogButtonBox *buttonBox = qFindChild(&msgBox); + Q_ASSERT(buttonBox != 0); + + uint mask = MessageBox::FirstButton; + while(mask <= MessageBox::LastButton) { + uint sb = buttons & mask; + mask <<= 1; + + if(!sb) continue; + + QPushButton *button = msgBox.addButton((MessageBox::StandardButton)sb); + + switch(sb) { + case MessageBox::Ok: // An "OK" button defined with the AcceptRole. + button->setText(QObject::tr("Ok")); + break; + case MessageBox::Open: // A "Open" button defined with the AcceptRole. + button->setText(QObject::tr("Open")); + break; + case MessageBox::Save: // A "Save" button defined with the AcceptRole. + button->setText(QObject::tr("Save")); + break; + case MessageBox::Cancel: // A "Cancel" button defined with the RejectRole. + button->setText(QObject::tr("Cancel")); + break; + case MessageBox::Close: // A "Close" button defined with the RejectRole. + button->setText(QObject::tr("Close")); + break; + case MessageBox::Discard: // A "Discard" or "Don't Save" button, depending on the platform, defined with the DestructiveRole. + button->setText(QObject::tr("Discard")); + break; + case MessageBox::Apply: // An "Apply" button defined with the ApplyRole. + button->setText(QObject::tr("Apply")); + break; + case MessageBox::Reset: // A "Reset" button defined with the ResetRole. + button->setText(QObject::tr("Reset")); + break; + case MessageBox::RestoreDefaults: // A "Restore Defaults" button defined with the ResetRole. + button->setText(QObject::tr("Restore Defaults")); + break; + case MessageBox::Help: // A "Help" button defined with the HelpRole. + button->setText(QObject::tr("Help")); + break; + case MessageBox::SaveAll: // A "Save All" button defined with the AcceptRole. + button->setText(QObject::tr("Save All")); + break; + case MessageBox::Yes: // A "Yes" button defined with the YesRole. + button->setText(QObject::tr("Yes")); + break; + case MessageBox::YesToAll: // A "Yes to All" button defined with the YesRole. + button->setText(QObject::tr("Yes To All")); + break; + case MessageBox::No: // A "No" button defined with the NoRole. + button->setText(QObject::tr("No")); + break; + case MessageBox::NoToAll: // A "No to All" button defined with the NoRole. + button->setText(QObject::tr("No To All")); + break; + case MessageBox::Abort: // An "Abort" button defined with the RejectRole. + button->setText(QObject::tr("Abort")); + break; + case MessageBox::Retry: // A "Retry" button defined with the AcceptRole. + button->setText(QObject::tr("Retry")); + break; + case MessageBox::Ignore: // An "Ignore" button defined with the AcceptRole. + button->setText(QObject::tr("Ignore")); + break; + case MessageBox::NoButton: // An invalid button. + break; + } + + // Choose the first accept role as the default + if(msgBox.defaultButton()) continue; + if((defaultButton == MessageBox::NoButton + && buttonBox->buttonRole(button) == QDialogButtonBox::AcceptRole) + || (defaultButton != MessageBox::NoButton && sb == uint(defaultButton))) + msgBox.setDefaultButton(button); + } + + if (msgBox.exec() == -1) return MessageBox::Cancel; + + return msgBox.standardButton(msgBox.clickedButton()); +} + +MessageBox::StandardButton MessageBox::information(QWidget *parent, const QString &title, + const QString& text, StandardButtons buttons, + StandardButton defaultButton) +{ + return showNewMessageBox(parent, Information, title, text, buttons, defaultButton); +} + +MessageBox::StandardButton MessageBox::question(QWidget *parent, const QString &title, + const QString& text, StandardButtons buttons, + StandardButton defaultButton) +{ + return showNewMessageBox(parent, Question, title, text, buttons, defaultButton); +} +MessageBox::StandardButton MessageBox::warning(QWidget *parent, const QString &title, + const QString& text, StandardButtons buttons, + StandardButton defaultButton) +{ + return showNewMessageBox(parent, Warning, title, text, buttons, defaultButton); +} + +MessageBox::StandardButton MessageBox::critical(QWidget *parent, const QString &title, + const QString& text, StandardButtons buttons, + StandardButton defaultButton) +{ + return showNewMessageBox(parent, Critical, title, text, buttons, defaultButton); +} diff --git a/client/messagebox.h b/client/messagebox.h new file mode 100644 index 0000000..2987c65 --- /dev/null +++ b/client/messagebox.h @@ -0,0 +1,50 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* vim: set et sw=2 ts=2: */ +/*************************************************************************** + * messagebox.h + * + * Wed Mar 18 13:33:05 CET 2009 + * Copyright 2009 Bent Bisballe Nyeng + * deva@aasimon.org + ****************************************************************************/ + +/* + * This file is part of Pracro. + * + * Pracro 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 2 of the License, or + * (at your option) any later version. + * + * Pracro 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 Pracro; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +#ifndef __PRACRO_MESSAGEBOX_H__ +#define __PRACRO_MESSAGEBOX_H__ + +#include + +class MessageBox : public QMessageBox +{ +public: + static StandardButton information(QWidget *parent, const QString &title, + const QString &text, StandardButtons buttons = Ok, + StandardButton defaultButton = NoButton); + static StandardButton question(QWidget *parent, const QString &title, + const QString &text, StandardButtons buttons = Ok, + StandardButton defaultButton = NoButton); + static StandardButton warning(QWidget *parent, const QString &title, + const QString &text, StandardButtons buttons = Ok, + StandardButton defaultButton = NoButton); + static StandardButton critical(QWidget *parent, const QString &title, + const QString &text, StandardButtons buttons = Ok, + StandardButton defaultButton = NoButton); +}; + +#endif/*__PRACRO_MESSAGEBOX_H__*/ diff --git a/client/pracro_dk.ts b/client/pracro_dk.ts new file mode 100644 index 0000000..d2d5698 --- /dev/null +++ b/client/pracro_dk.ts @@ -0,0 +1,105 @@ + + + + + ComboBox + + + goddaws do + weeee + + + + QObject + + + Ok + Ok + + + + Open + Ã…bn + + + + Save + Gem + + + + Cancel + Annullér + + + + Close + Luk + + + + Discard + Kassér + + + + Apply + Tag i brug + + + + Reset + Nulstil + + + + Restore Defaults + Genopret default + + + + Help + Hjælp + + + + Save All + Gem alle + + + + Yes + Ja + + + + Yes To All + Ja til alle + + + + No + Nej + + + + No To All + Nej til alle + + + + Abort + Afbryd + + + + Retry + Prøv igen + + + + Ignore + Ignorér + + + diff --git a/client/widgets/metawidget.cc b/client/widgets/metawidget.cc index c085f10..5491790 100644 --- a/client/widgets/metawidget.cc +++ b/client/widgets/metawidget.cc @@ -29,7 +29,7 @@ #include #include -#include +#include "messagebox.h" #include "widgetbuilder.h" #include "formatparser.h" @@ -120,10 +120,10 @@ bool MetaWidget::isValid() while (i != widgets.end()) { Widget* w = *i; if(w->isValid() == false) { - QMessageBox::critical(NULL, "Fejl", + MessageBox::critical(NULL, "Fejl", "Et af inputfelterne (" + w->getName() + ") er ikke udfyldt korrekt, prøv igen.\n" - , QMessageBox::Ok); + , MessageBox::Ok); return false; } i++; diff --git a/client/widgets/multilist.cc b/client/widgets/multilist.cc index 4d34691..87f4975 100644 --- a/client/widgets/multilist.cc +++ b/client/widgets/multilist.cc @@ -26,12 +26,13 @@ */ #include "multilist.h" -#include #include #include #include #include +#include "messagebox.h" + #include "widgetbuilder.h" #include "common.h" @@ -127,25 +128,25 @@ void MultiList::changed() bool MultiList::isValid() { if(innerwidget_has_changes) { - switch(QMessageBox::warning(NULL, + switch(MessageBox::warning(NULL, "Gem ændringerne i listen?", "Der er lavet en ændring som ikke er tilføjet til listen.\n" "Ønsker du at tilføje ændringen til listen inden du gemmer makroen?", - QMessageBox::Save | QMessageBox::Close | QMessageBox::Cancel)) { - case QMessageBox::Save: + MessageBox::Save | MessageBox::Close | MessageBox::Cancel)) { + case MessageBox::Save: if(innerwidget && innerwidget->isValid()) { add(); } else { - QMessageBox::critical(NULL, + MessageBox::critical(NULL, "Fejl", "Der er fejl i ændringen, og den kan ikke tilføjes til listen.\n", - QMessageBox::Ok); + MessageBox::Ok); return false; } break; - case QMessageBox::Close: + case MessageBox::Close: break; - case QMessageBox::Cancel: + case MessageBox::Cancel: default: // FIXME: How to we actually block the commit and return to the editor? return false; -- cgit v1.2.3