Skip to content

Commit

Permalink
converted all QMessageDialog in new Dialog type
Browse files Browse the repository at this point in the history
  • Loading branch information
mellotanica committed Jan 5, 2015
1 parent 07fcf5c commit c0bc36c
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 60 deletions.
6 changes: 3 additions & 3 deletions qarm/hex_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
#include <QTextBlock>
#include <QPainter>
#include <QScrollBar>
#include <QMessageBox>

#include "qarm/procdisplay.h"

Expand All @@ -40,6 +39,7 @@

//#include "qmps/application.h"
//#include "qmps/debug_session.h"
//#include "qarm/qarmmessagebox.h"
#include "qarm/hex_view_priv.h"
//#include "qmps/ui_utils.h"

Expand Down Expand Up @@ -194,8 +194,8 @@ void HexView::keyPressEvent(QKeyEvent* event)
Word paddr = start + currentWord() * WS;
if (debugSession->getMachine()->WriteMemory(paddr, dataAtCursor())) {
QMessageBox::warning(this, "Warning",
QString("Could not write location %1").arg(FormatAddress(paddr)));
QarmMessageBox *warning = new QarmMessageBox(QarmMessageBox::WARNING, "Warning", QString("Could not write location %1").arg(FormatAddress(paddr)).toStdString().c_str(), this);
warning->show();
Refresh();
} else {
moveCursor(QTextCursor::Right, 1 + kHorizontalSpacing * nibble);
Expand Down
46 changes: 28 additions & 18 deletions qarm/qarm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ qarm::qarm(QApplication *app):
QDir *defaultPath = new QDir(QDir::homePath()+"/"+DEFAULT_CONFIG_PATH);
if(!defaultPath->exists())
if(!defaultPath->mkdir(defaultPath->absolutePath())){ //config folder not accessible..
QMessageBox::critical(this, "Fatal", "Cannot create .uarm folder in home directory.\nCheck HOME environment variable.");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Fatal", "Cannot create .uarm folder in home directory.\nCheck HOME environment variable.", this);
error->show();
app->exit();
}

Expand Down Expand Up @@ -202,18 +203,19 @@ void qarm::showRam(){
connect(mac, SIGNAL(dataReady(Word*,Word*,Word*,Word,Word,Word,QString)), ramWindow, SLOT(update()));
ramWindow->show();
} else {
QarmMessageBox *warning = new QarmMessageBox(QarmMessageBox::WARNING, "Warning", "Machine not initialized,\ncannot display memory contents.", this);
QarmMessageBox *warning = new QarmMessageBox(QarmMessageBox::WARNING, "Warning",
"Machine not initialized,\ncannot display memory contents.", this);
warning->show();
//QMessageBox::warning(this, "Warning", "Machine not initialized,\ncannot display memory contents.", QMessageBox::Ok);
}
}

void qarm::selectCore(){
if(dataLoaded){
QMessageBox::StandardButton reply = QMessageBox::question(this,"Caution",
"Program File already loaded..\nReset machine and load new Program?",
QMessageBox::Yes|QMessageBox::No);
if(reply == QMessageBox::No)
QarmMessageBox *question = new QarmMessageBox(QarmMessageBox::QUESTION, "Caution",
"Program File already loaded..\nReset machine and load new Program?", this);
question->show();

if(question->result() == QarmMessageBox::Rejected)
return;
else {
initialized = false;
Expand All @@ -229,10 +231,11 @@ void qarm::selectCore(){

void qarm::selectBios(){
if(biosLoaded){
QMessageBox::StandardButton reply = QMessageBox::question(this,"Caution",
"BIOS ROM already loaded..\nReset machine and load new BIOS?",
QMessageBox::Yes|QMessageBox::No);
if(reply == QMessageBox::No)
QarmMessageBox *question = new QarmMessageBox(QarmMessageBox::QUESTION, "Caution",
"BIOS ROM already loaded..\nReset machine and load new BIOS?", this);
question->show();

if(question->result() == QarmMessageBox::Rejected)
return;
else {
initialized = false;
Expand All @@ -251,7 +254,8 @@ bool qarm::openRAM(){
if(coreF != ""){
QFile f (coreF);
if(!f.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Error", "Could not open Core file");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error", "Could not open Core file", this);
error->show();
return false;
}
QDataStream in(&f);
Expand All @@ -261,12 +265,14 @@ bool qarm::openRAM(){
char *buffer = new char[len];
int sz = in.readRawData(buffer, len);
if(sz <= 0 || (buffer[0] | buffer[1]<<8 | buffer[2]<<16 | buffer[3]<<24) != COREFILEID){
QMessageBox::critical(this, "Error", "Irregular Core file");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error", "Irregular Core file", this);
error->show();
return false;
}
sz -= 4;
if(sz <= 0 || !mac->getBus()->loadRAM(buffer+4, (Word) sz, true)){
QMessageBox::critical(this, "Error", "Problems while loading Core file");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error", "Problems while loading Core file", this);
error->show();
return false;
}
delete [] buffer;
Expand All @@ -282,20 +288,23 @@ bool qarm::openBIOS(){
if(biosF != ""){
QFile f (biosF);
if(!f.open(QIODevice::ReadOnly)) {
QMessageBox::critical(this, "Error", "Could not open BIOS file");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error", "Could not open BIOS file", this);
error->show();
return false;
}
QDataStream in(&f);
Word len = (Word) f.size();
char *buffer = new char[len];
Word sz = in.readRawData(buffer, len);
if(sz <= 0 || (buffer[0] | buffer[1]<<8 | buffer[2]<<16 | buffer[3]<<24) != BIOSFILEID){
QMessageBox::critical(this, "Error", "Irregular BIOS file");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error", "Irregular BIOS file", this);
error->show();
return false;
}
sz -= 8;
if(sz <= 0 || !mac->getBus()->loadBIOS(buffer+8, (Word) sz)){
QMessageBox::critical(this, "Error", "Problems while flashing BIOS ROM");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error", "Problems while flashing BIOS ROM", this);
error->show();
return false;
}
delete [] buffer;
Expand All @@ -312,7 +321,8 @@ void qarm::showConfigDialog(){
try {
MC_Holder::getInstance()->getConfig()->Save();
} catch (FileError& e) {
QMessageBox::critical(this, QString("%1: Error").arg(application->applicationName()), e.what());
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error", e.what(), this);
error->show();
return;
}
// EDIT: no config view for now..
Expand Down
1 change: 0 additions & 1 deletion qarm/qarm.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
#include <QFile>
#include <QDataStream>
#include <QPointer>
#include <QMessageBox>
#include <QApplication>

class qarm : public QMainWindow{
Expand Down
6 changes: 5 additions & 1 deletion qarm/qarmmessagebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ QarmMessageBox::QarmMessageBox(DType t, const char *title, const char *text, QWi
{
setModal(true);
setWindowTitle(title);
setWindowIcon(parent->windowIcon());

QLayout *mainLayout = new QVBoxLayout;
QWidget *topWidget = new QWidget;
Expand All @@ -43,6 +42,11 @@ QarmMessageBox::QarmMessageBox(DType t, const char *title, const char *text, QWi
this->setAccessibleName("Question Dialog");
break;
}
if(parent)
setWindowIcon(parent->windowIcon());
else
setWindowIcon(icon);

QLabel *iconL = new QLabel;
iconL->setAlignment(Qt::AlignCenter);
//iconL->setFrameShape(QFrame::Box);
Expand Down
7 changes: 4 additions & 3 deletions qarm/ramview.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
#define QARM_RAMVIEW_CC

#include "ramview.h"
#include "qarm/qarmmessagebox.h"
#include <QHBoxLayout>
#include <QMessageBox>
#include <QLabel>
#include "armProc/machine_config.h"

Expand Down Expand Up @@ -85,13 +85,14 @@ void ramView::visualize(){
if(start > end || (end - start) > MAX_VIEWABLE_RAM){
mainLayout->removeWidget(ramViewer);
delete ramViewer;
QString message;
char *message;
if(start > end){
message = "Start address cannot be higher than End address...";
} else {
message = "Memory segment too large,\n max displayble size: 10 KB";
}
QMessageBox::warning(this, "Warning", message, QMessageBox::Ok);
QarmMessageBox *warning = new QarmMessageBox(QarmMessageBox::WARNING, "Warning", message, this);
warning->show();
} else if(conv && (start != startAddr || end != endAddr)){

if(start & 3){
Expand Down
57 changes: 25 additions & 32 deletions services/debug_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

#include <QAction>
#include <QTimer>
#include <QMessageBox>
#include "qarm/qarmmessagebox.h"

#include "services/error.h"
#include "armProc/machine_config.h"
Expand Down Expand Up @@ -81,11 +81,10 @@ void DebugSession::resetSymbolTable(){
stab = new SymbolTable(config->getSymbolTableASID(),
config->getROM(ROM_TYPE_STAB).c_str());
} catch (const Error& e) {
QMessageBox::critical(
mainW,
QString("%1: Error").arg(app->applicationName()),
"<b>Could not initialize debugger:</b> "
"invalid or missing symbol table file");
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
"<b>Could not initialize debugger:</b> "
"invalid or missing symbol table file", mainW);
error->show();
//machine.reset();
symbolTable.reset();
return;
Expand Down Expand Up @@ -207,51 +206,46 @@ void DebugSession::initializeMachine()
foreach (const std::string& s, errors)
el += QString("<li>%1</li>").arg(s.c_str());
el += "</ul>";
QMessageBox::critical(
0, QString("%1: Error").arg(Appl()->applicationName()),
"Invalid and/or incomplete machine configuration: " + el);
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
"Invalid and/or incomplete machine configuration: " + el);
error->show();
return;
}
try {
machine.reset(new Machine(config, &breakpoints, &suspects, &tracepoints));
} catch (const FileError& e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QString("<b>Could not initialize machine:</b> "
"the file `%1' is nonexistent or inaccessible").arg(e.fileName.c_str()));
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
QString("<b>Could not initialize machine:</b> "
"the file `%1' is nonexistent or inaccessible").arg(e.fileName.c_str()).toStdString().c_str());
error->show();
return;
} catch (const InvalidCoreFileError& e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
QString("<b>Could not initialize machine:</b> "
"the file `%1' does not appear to be a valid <i>Core</i> file; "
"make sure you are creating the file with the <code>umps2-elf2umps</code> utility")
.arg(e.fileName.c_str()));
.arg(e.fileName.c_str()).toStdString().c_str());
error->show();
return;
} catch (const CoreFileOverflow& e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
"<b>Could not initialize machine:</b> "
"the core file does not fit in memory; "
"please increase available RAM and try again");
error->show();
return;
} catch (const InvalidFileFormatError& e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
QString("<b>Could not initialize machine:</b> "
"the file `%1' has wrong format").arg(e.fileName.c_str()));
"the file `%1' has wrong format").arg(e.fileName.c_str()).toStdString().c_str());
error->show();
return;
} catch (const EthError& e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
QString("<b>Could not initialize machine:</b> "
"error initializing network device %1").arg(e.devNo));
"error initializing network device %1").arg(e.devNo).toStdString().c_str());
error->show();
return;
}
Expand All @@ -262,11 +256,10 @@ void DebugSession::initializeMachine()
stab = new SymbolTable(config->getSymbolTableASID(),
config->getROM(ROM_TYPE_STAB).c_str());
} catch (const Error& e) {
QMessageBox::critical(
Appl()->getApplWindow(),
QString("%1: Error").arg(Appl()->applicationName()),
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "Error",
"<b>Could not initialize machine:</b> "
"invalid or missing symbol table file");
error->show();
machine.reset();
return;
}
Expand Down
5 changes: 3 additions & 2 deletions services/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,13 @@
#ifndef BASE_ERROR_CC
#define BASE_ERROR_CC

#include <QMessageBox>
#include "qarm/qarmmessagebox.h"
#include "armProc/machine_config.h"

void Panic(const char* message)
{
QMessageBox::critical(0, "PANIC", QString("PANIC: %1").arg(message));
QarmMessageBox *error = new QarmMessageBox(QarmMessageBox::CRITICAL, "PANIC", QString("PANIC: %1").arg(message).toStdString().c_str());
error->show();
// WARN: is it necessary?
MC_Holder::getInstance()->getConfig()->getApp()->quit();
}
Expand Down

0 comments on commit c0bc36c

Please sign in to comment.