From: <sv...@va...> - 2010-01-23 09:40:48
|
Author: cerion Date: 2010-01-23 09:40:36 +0000 (Sat, 23 Jan 2010) New Revision: 469 Log: reinstated message dialogs - error, info, etc. Added: branches/valkyrie_qt4port/utils/vk_messages.cpp branches/valkyrie_qt4port/utils/vk_messages.h Modified: branches/valkyrie_qt4port/help/help_handbook.cpp branches/valkyrie_qt4port/mainwindow.cpp branches/valkyrie_qt4port/options/valgrind_options_page.cpp branches/valkyrie_qt4port/options/vk_options_page.cpp branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp branches/valkyrie_qt4port/valkyrie.pro Modified: branches/valkyrie_qt4port/help/help_handbook.cpp =================================================================== --- branches/valkyrie_qt4port/help/help_handbook.cpp 2010-01-22 20:09:37 UTC (rev 468) +++ branches/valkyrie_qt4port/help/help_handbook.cpp 2010-01-23 09:40:36 UTC (rev 469) @@ -106,6 +106,7 @@ void HandBook::bookmarkChosen( QAction* act ) { if ( !bookmarkMenu->actions().contains( act ) ) { + cerr << "Error: HandBook::bookmarkChosen: act not in bookmarks!" << endl; //TODO: shouldn't ever happen: vkError return; } @@ -118,7 +119,7 @@ void HandBook::bookmarkHighlighted( QAction* act ) { if ( !bookmarkMenu->actions().contains( act ) ) { - cerr << "Error: act not in bookmarks!" << endl; + cerr << "Error: HandBook::bookmarkHighlighted: act not in bookmarks!" << endl; //TODO: shouldn't ever happen: vkError return; } Modified: branches/valkyrie_qt4port/mainwindow.cpp =================================================================== --- branches/valkyrie_qt4port/mainwindow.cpp 2010-01-22 20:09:37 UTC (rev 468) +++ branches/valkyrie_qt4port/mainwindow.cpp 2010-01-23 09:40:36 UTC (rev 469) @@ -34,6 +34,7 @@ #include "help/help_urls.h" #include "options/vk_option.h" #include "utils/vk_config.h" +#include "utils/vk_messages.h" /***************************************************************************/ Modified: branches/valkyrie_qt4port/options/valgrind_options_page.cpp =================================================================== --- branches/valkyrie_qt4port/options/valgrind_options_page.cpp 2010-01-22 20:09:37 UTC (rev 468) +++ branches/valkyrie_qt4port/options/valgrind_options_page.cpp 2010-01-23 09:40:36 UTC (rev 469) @@ -25,7 +25,7 @@ #include "help/help_context.h" #include "help/help_urls.h" #include "utils/vk_config.h" -//#include "vk_messages.h" +#include "utils/vk_messages.h" #include "utils/vk_utils.h" #include "objects/valgrind_object.h" @@ -401,12 +401,9 @@ if (((QListWidget*)lbSel->widget())->count() < VG_CLO_MAX_SFILES) { lbSel->insertItem(suppr); } else { -cerr << "TODO: vkError: Valgrind won't accept more than VG_CLO_MAX_SFILES suppression files" << endl; -#if 0 /* valgrind doesn't accept any more suppression files */ vkError( this, "Error", "Valgrind won't accept more than %d suppression files", VG_CLO_MAX_SFILES ); -#endif } } Modified: branches/valkyrie_qt4port/options/vk_options_page.cpp =================================================================== --- branches/valkyrie_qt4port/options/vk_options_page.cpp 2010-01-22 20:09:37 UTC (rev 468) +++ branches/valkyrie_qt4port/options/vk_options_page.cpp 2010-01-23 09:40:36 UTC (rev 469) @@ -36,6 +36,7 @@ #include "options/widgets/opt_le_widget.h" #include "options/widgets/opt_sp_widget.h" #include "utils/vk_config.h" +#include "utils/vk_messages.h" #include <QList> @@ -196,12 +197,11 @@ // Note: argval may be altered by checkOptArg() int errval = m_vkObj->checkOptArg( optId, argval ); if ( errval != PARSED_OK ) { -cerr << "TODO: vkError: Invalid Entry: " << errval << endl; -#if 0 // TODO + vkError( this, "Invalid Entry", "%s:\n\"%s\"", parseErrString(errval), - m_itemList[optId]->currValue().latin1() ); -#endif + qPrintable( m_itemList[optId]->currValue() ) ); + m_itemList[optId]->cancelEdit(); return false; } Modified: branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp =================================================================== --- branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp 2010-01-22 20:09:37 UTC (rev 468) +++ branches/valkyrie_qt4port/options/widgets/opt_lb_widget.cpp 2010-01-23 09:40:36 UTC (rev 469) @@ -25,8 +25,9 @@ #include "help/help_urls.h" #include "options/widgets/opt_lb_widget.h" #include "options/vk_option.h" -#include "utils/vk_utils.h" #include "utils/vk_config.h" +#include "utils/vk_messages.h" +#include "utils/vk_utils.h" /***************************************************************************/ @@ -323,12 +324,9 @@ // check not a duplicate entry if ( ! m_lbox->findItems( supp_dir, Qt::MatchExactly ).isEmpty() ) { -cerr << "TODO: vkInfo: Duplicate Entry Error" << endl; -/* TODO vkInfo( m_lbox, "Duplicate Entry", - "<p>The entry '%s' is already in the list.</p>", - supp_dir.latin1() ); -*/ + "The entry '%s' is already in the list.", + qPrintable( supp_dir ) ); } else { m_lbox->addItem( supp_dir ); changed = true; Added: branches/valkyrie_qt4port/utils/vk_messages.cpp =================================================================== --- branches/valkyrie_qt4port/utils/vk_messages.cpp (rev 0) +++ branches/valkyrie_qt4port/utils/vk_messages.cpp 2010-01-23 09:40:36 UTC (rev 469) @@ -0,0 +1,285 @@ +/**************************************************************************** +** Definition of class MsgBox +** - various types of messages: Query, Info ... +** -------------------------------------------------------------------------- +** +** Copyright (C) 2000-2010, OpenWorks LLP. All rights reserved. +** <in...@op...> +** +** This file is part of Valkyrie, a front-end for Valgrind. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 as published by the Free Software Foundation +** and appearing in the file COPYING included in the packaging of +** this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#include "utils/vk_messages.h" +#include "utils/vk_config.h" +//#include "valkyrie_xpm.h" +//#include "msgbox_icons.h" + +#include <stdarg.h> /* va_start, va_end */ +#include <stdlib.h> /* exit errno */ + +#include <QApplication> +#include <QHBoxLayout> +#include <QKeyEvent> +#include <QObjectList> +#include <QPixmap> +#include <QStyle> + +#include <iostream> + + +/***************************************************************************/ +/*! + message dialogs +*/ +#define VK_BUFLEN 8196 + +/*! + vkQuery: ask user a question + Modal dialog box +*/ +int vkQuery( QWidget* w, int nbutts, QString hdr, + const char* msg, ... ) +{ + // setup message + char buf[VK_BUFLEN]; + va_list ap; + va_start( ap, msg ); + vsnprintf( buf, VK_BUFLEN, msg, ap ); + va_end( ap ); + + // setup and show dialog box + MsgBox mb( w, MsgBox::Query, buf, hdr, nbutts ); + QStringList names; + names << "&Yes" << "&No" << "&Cancel"; + mb.setButtonTexts( names ); + return mb.exec(); +} + + +/*! + vkQuery: ask user a question + set custom button labels + Modal dialog box +*/ +int vkQuery( QWidget* w, QString hdr, + QString labels, const char* msg, ... ) +{ + // setup message + char buf[VK_BUFLEN]; + va_list ap; + va_start( ap, msg ); + vsnprintf( buf, VK_BUFLEN, msg, ap ); + va_end( ap ); + + // setup and show dialog box + QStringList buttonLabels( labels.split( ";" ) ); + int nbutts = buttonLabels.count(); + MsgBox mb( w, MsgBox::Query, buf, hdr, nbutts ); + mb.setButtonTexts( buttonLabels ); + return mb.exec(); +} + + +/*! + vkInfo: show information message + Modal dialog box +*/ +void vkInfo( QWidget* w, QString hdr, const char* msg, ... ) +{ + // setup message + char buf[VK_BUFLEN]; + va_list ap; + va_start( ap, msg ); + vsnprintf( buf, VK_BUFLEN, msg, ap ); + va_end( ap ); + + // setup and show dialog box + MsgBox mb( w, MsgBox::Info, buf, hdr, 1 ); + mb.setButtonTexts( QStringList( "O&K" ) ); + mb.exec(); +} + + +/*! + vkError: error message box + Modal dialog box +*/ +void vkError( QWidget* w, QString hdr, const char* msg, ... ) +{ + // setup message + char buf[VK_BUFLEN]; + va_list ap; + va_start( ap, msg ); + vsnprintf( buf, VK_BUFLEN, msg, ap ); + va_end( ap ); + + // setup and show dialog box + MsgBox mb( w, MsgBox::Error, buf, hdr ); + mb.setButtonTexts( QStringList( "O&K" ) ); + mb.exec(); +} + + + + + +/***************************************************************************/ +/*! + Base dialog box implementation +*/ +MsgBox::MsgBox( QWidget* parent, Icon icon, QString msg, + const QString& hdr, int num_buttons ) + : QDialog( parent ) +{ + setObjectName( QString::fromUtf8("msgbox") ); + + msg = "<p>" + msg + "</p>"; + if ( !hdr.isEmpty() ) { + msg = "<b>" + hdr + "</b>" + msg; + } + + numButtons = num_buttons; + int defButton = 0; + button[0] = MsgBox::vkYes; + + QString caption; + QPixmap pm_file; + switch ( icon ) { + case Query: + caption = "Query"; + defButton = 1; /* No */ + pm_file = QPixmap( QString::fromUtf8(":/vk_icons/icons/msgbox_query.xpm") ); + break; + case Info: + caption = "Information"; + pm_file = QPixmap( QString::fromUtf8(":/vk_icons/icons/msgbox_info.xpm") ); + break; + case Error: + caption = "Error"; + pm_file = QPixmap( QString::fromUtf8(":/vk_icons/icons/msgbox_error.xpm") ); + break; + default: + break; + } + setWindowTitle( caption ); + + switch ( numButtons ) { + case 1: // ok button + escButton = -1; + break; + case 2: // yes + no + button[1] = MsgBox::vkNo; + escButton = 1; + break; + case 3: // yes + no + cancel + button[1] = MsgBox::vkNo; + button[2] = MsgBox::vkCancel; + escButton = 2; + break; + } + + + QVBoxLayout* vLayout = new QVBoxLayout( this ); + vLayout->setObjectName(QString::fromUtf8("vlayout")); + vLayout->setAlignment( Qt::AlignTop ); + + QHBoxLayout* hLayout = new QHBoxLayout(); + hLayout->setObjectName(QString::fromUtf8("hlayout")); + hLayout->setSpacing( 14 ); + vLayout->addLayout( hLayout ); + + iconLabel = new QLabel( this ); + iconLabel->setObjectName( "icon_lbl" ); + iconLabel->setAlignment( Qt::AlignTop ); + iconLabel->setPixmap( pm_file ); + hLayout->addWidget( iconLabel ); + + msgLabel = new QLabel( this ); // default: left aligned, tabs expanded. + msgLabel->setObjectName( "msg_lbl" ); + msgLabel->setText( msg ); + hLayout->addWidget( msgLabel ); + hLayout->addStretch( 1 ); + + + QHBoxLayout* hLayoutButtons = new QHBoxLayout(); + hLayoutButtons->setObjectName(QString::fromUtf8("hLayoutButtons")); + hLayoutButtons->addStretch( 1 ); + vLayout->addSpacing( 18 ); + vLayout->addStretch( 1 ); + vLayout->addLayout( hLayoutButtons ); + + for ( int i=0; i<numButtons; i++ ) { + pb[i] = new QPushButton( this ); + pb[i]->setObjectName( "button" + QString::number( i+1 ) ); + hLayoutButtons->addWidget( pb[i] ); + if ( defButton == i ) { + pb[i]->setDefault( true ); + pb[i]->setFocus(); + } + pb[i]->setAutoDefault( true ); + connect( pb[i], SIGNAL(clicked()), + this, SLOT(pbClicked()) ); + } +} + + + +MsgBox::~MsgBox() +{ } + + + +void MsgBox::setButtonTexts( const QStringList &btexts ) +{ + for ( int i=0; i<numButtons; i++ ) { + pb[i]->setText( btexts[i] ); + } +} + + +void MsgBox::pbClicked() +{ + int result = 0; + const QObject* s = sender(); + for ( int i=0; i<numButtons; i++ ) { + if ( pb[i] == s ) { + result = button[i]; + break; + } + } + done( result ); +} + + +// An escape key triggers the assigned 'default-escape' button +void MsgBox::keyPressEvent( QKeyEvent* e ) +{ + if ( e->key() == Qt::Key_Escape ) { + if ( escButton >= 0 ) { + pb[escButton]->animateClick(); + e->accept(); + return; + } + } + QDialog::keyPressEvent( e ); +} + +// Any close event other than via pbClicked() gives 'default-escape' button result. +void MsgBox::closeEvent( QCloseEvent* ce ) +{ + QDialog::closeEvent( ce ); + if ( escButton != -1 ) + setResult( button[escButton] ); +} + + + + Added: branches/valkyrie_qt4port/utils/vk_messages.h =================================================================== --- branches/valkyrie_qt4port/utils/vk_messages.h (rev 0) +++ branches/valkyrie_qt4port/utils/vk_messages.h 2010-01-23 09:40:36 UTC (rev 469) @@ -0,0 +1,85 @@ +/**************************************************************************** +** Definition of class MsgBox +** - various types of messages: Query, Info ... +** -------------------------------------------------------------------------- +** +** Copyright (C) 2000-2010, OpenWorks LLP. All rights reserved. +** <in...@op...> +** +** This file is part of Valkyrie, a front-end for Valgrind. +** +** This file may be used under the terms of the GNU General Public +** License version 2.0 as published by the Free Software Foundation +** and appearing in the file COPYING included in the packaging of +** this file. +** +** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +** +****************************************************************************/ + +#ifndef __VK_MESSAGES_H +#define __VK_MESSAGES_H + +#include <QDialog> +#include <QLabel> +#include <QPushButton> +#include <QString> +#include <QWidget> + + + +// ============================================================ +/* ask user a question */ +int vkQuery( QWidget* w, int nbutts, QString hdr, const char*, ... ) + __attribute__ (( format( printf, 4, 5 ) )); + +/* ask user a question, + set custom button labels. + Note button ordering - vkYes : vkNo : vkCancel */ +int vkQuery( QWidget* w, QString hdr, QString butt_labels, const char*, ... ) + __attribute__ (( format( printf, 4, 5 ) )); + +/* show information message box */ +void vkInfo( QWidget* w, QString hdr, const char* format, ...) + __attribute__((__format__ (__printf__, 3, 4))); + +/* error message box */ +void vkError( QWidget* w, QString hdr, const char*, ... ) + __attribute__ (( format( printf, 3, 4 ) )); + + + + +// ============================================================ +// Don't call this class directly: used for standard vkError() etc. functions +class MsgBox : public QDialog +{ + Q_OBJECT +public: + enum Icon { Query, Info, Error }; + enum rVal { vkYes=0, vkNo=1, vkCancel=2 }; + + MsgBox( QWidget* parent, Icon icon, QString msg, + const QString& hdr=QString::null, int num_buttons=1 ); + ~MsgBox(); + + void setButtonTexts( const QStringList &texts ); + +protected: + void closeEvent( QCloseEvent * ); + void keyPressEvent( QKeyEvent * ); + +private slots: + void pbClicked(); + +private: + int button[3]; /* button types */ + int escButton; /* escape button (index) */ + int numButtons; /* number of buttons */ + + QLabel* msgLabel; /* label holding msg text */ + QLabel* iconLabel; /* label holding any icon */ + QPushButton *pb[3]; /* buttons */ +}; + +#endif Modified: branches/valkyrie_qt4port/valkyrie.pro =================================================================== --- branches/valkyrie_qt4port/valkyrie.pro 2010-01-22 20:09:37 UTC (rev 468) +++ branches/valkyrie_qt4port/valkyrie.pro 2010-01-23 09:40:36 UTC (rev 469) @@ -4,12 +4,12 @@ TARGET = valkyrie TEMPLATE = app SOURCES += \ + main.cpp \ + mainwindow.cpp \ help/help_about.cpp \ help/help_context.cpp \ help/help_handbook.cpp \ help/help_urls.cpp \ - main.cpp \ - mainwindow.cpp \ objects/valkyrie_object.cpp \ objects/valgrind_object.cpp \ objects/vk_objects.cpp \ @@ -30,13 +30,14 @@ toolview/memcheckview.cpp \ toolview/toolview.cpp \ utils/vk_config.cpp \ + utils/vk_messages.cpp \ utils/vk_utils.cpp HEADERS += \ + mainwindow.h \ help/help_about.h \ help/help_context.h \ help/help_handbook.h \ help/help_urls.h \ - mainwindow.h \ objects/valkyrie_object.h \ objects/valgrind_object.h \ objects/vk_objects.h \ @@ -57,5 +58,6 @@ toolview/memcheckview.h \ toolview/toolview.h \ utils/vk_config.h \ + utils/vk_messages.h \ utils/vk_utils.h RESOURCES += icons.qrc |