Mixxx

/home/maxime/Projets/Mixxx/1.10/mixxx/src/errordialoghandler.h

Go to the documentation of this file.
00001 /***************************************************************************
00002                           errordialoghandler.h  -  description
00003                              -------------------
00004     begin                : Fri Feb 20 2009
00005     copyright            : (C) 2009 by Sean M. Pappalardo
00006     email                : pegasus@c64.org
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #ifndef ERRORDIALOGHANDLER_H
00019 #define ERRORDIALOGHANDLER_H
00020 
00021 #include <QObject>
00022 #include <QMessageBox>
00023 #include <QSignalMapper>
00024 #include <QMutex>
00025 
00033 typedef enum {
00034     DLG_FATAL       = 5,
00035     DLG_CRITICAL    = 4,
00036     DLG_WARNING     = 3,
00037     DLG_INFO        = 2,
00038     DLG_QUESTION    = 1,
00039     DLG_NONE        = 0 // No icon (default)
00040 } DialogType;
00041 
00042 class ErrorDialogProperties {
00043     public:
00044         // Befriending ErrorDialogHandler allows it to have cleaner code
00045         //  since the two are closely related anyway
00046         friend class ErrorDialogHandler;
00047         
00049         void setTitle(QString title);
00051         void setKey(QString key) { m_key = key; }
00052         QString getKey() { return m_key; }
00054         void setText(QString text);
00055         QString getText() { return m_text; }
00057         void setInfoText(QString text) { m_infoText = text; }
00059         void setDetails(QString text) { m_details = text; }
00061         void setModal(bool modal) { m_modal = modal; }
00063         void setType(DialogType typeToSet);
00065         void setIcon(QMessageBox::Icon icon) { m_icon = icon; }
00066         
00068         void addButton(QMessageBox::StandardButton);
00070         void setDefaultButton(QMessageBox::StandardButton button) { m_defaultButton = button; }
00072         void setEscapeButton(QMessageBox::StandardButton button) { m_escapeButton = button; }
00073 
00074     protected:
00075         // Protected since only ErrorDialogHandler should instantiate this
00076         ErrorDialogProperties();
00077         
00078         QString m_title;
00079         QString m_key;
00080         QString m_text;
00081         QString m_infoText;
00082         QString m_details;
00083         bool m_modal;
00084         DialogType m_type;
00085         QMessageBox::Icon m_icon;
00089         QList<QMessageBox::StandardButton> m_buttons;
00091         QMessageBox::StandardButton m_defaultButton;
00093         QMessageBox::StandardButton m_escapeButton;
00094 };
00095 
00097 class ErrorDialogHandler : public QObject {
00098    Q_OBJECT
00099 public:
00100     static ErrorDialogHandler* instance() {
00101         if (!s_pInstance)
00102             s_pInstance = new ErrorDialogHandler;
00103         return s_pInstance;
00104     }
00105 
00106     ~ErrorDialogHandler();
00108     ErrorDialogProperties* newDialogProperties();
00111     bool requestErrorDialog(DialogType type, QString message);
00112     bool requestErrorDialog(ErrorDialogProperties* props);
00114     bool checkError();
00115     
00116 signals:
00117     void showErrorDialog(ErrorDialogProperties* props);
00118     void stdButtonClicked(QString key, QMessageBox::StandardButton whichStdButton);
00119 
00120 private:
00121     ErrorDialogHandler();                                       // Private constructor
00122     ErrorDialogHandler(const ErrorDialogHandler&);              // Prevent copy-construction
00123     ErrorDialogHandler& operator=(const ErrorDialogHandler&);   // Prevent assignment
00124     
00125     static ErrorDialogHandler *s_pInstance;
00126     
00127     bool m_errorCondition;
00128     QList<QString> m_dialogKeys;
00129     QSignalMapper* m_pSignalMapper;
00130     QMutex m_mutex;
00131 
00132 private slots:
00134     void errorDialog(ErrorDialogProperties* props);
00135     void boxClosed(QString key);
00136 };
00137 
00138 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines