summaryrefslogtreecommitdiffstats
path: root/kexi/kexidb/msghandler.h
blob: da907c7e6411449c241647114f98976efbc0c00d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
/* This file is part of the KDE project
   Copyright (C) 2004-2005 Jaroslaw Staniek <[email protected]>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library 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
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA 02110-1301, USA.
*/

#ifndef KEXIDB_MSGHANDLER_H
#define KEXIDB_MSGHANDLER_H

#include <kexidb/object.h>
#include <qguardedptr.h>
#include <qwidget.h>

namespace KexiDB {

/*! A helper class for setting temporary message title for an KexiDB::Object. 
 Message title is a text prepended to error or warning messages.
 Use it this way:
 \code
 KexiDB::MessageTitle title(myKexiDBObject, i18n("Terrible error occurred"));
 \endcode
 After leaving current from code block, object's message title will be reverted 
 to previous value.
*/
class KEXI_DB_EXPORT MessageTitle
{
	public:
		MessageTitle(KexiDB::Object* o, const QString& msg = QString::null);
		~MessageTitle();
	
	protected:
		Object* m_obj;
		QString m_prevMsgTitle;
};

/*! A prototype for Message Handler usable 
 for reacting on messages sent by KexiDB::Object object(s).
*/
class KEXI_DB_EXPORT MessageHandler
{
	public:
		enum MessageType { Error, Sorry, Warning };

		/*! Constructs mesage handler, \a parent is a widget that will be a parent 
		 for displaying gui elements (e.g. message boxes). Can be 0 for non-gui usage. */
		MessageHandler(QWidget *parent = 0);
		virtual ~MessageHandler();

		/*! This method can be used to block/unblock messages.
		 Sometimes you are receiving both lower- and higher-level messages,
		 but you do not need to display two message boxes but only one (higher level with details).
		 All you need is to call enableMessages(false) before action that can fail
		 and restore messages by enableMessages(true) after the action. 
		 See KexiMainWindowImpl::renameObject() implementation for example. */
		inline void enableMessages(bool enable) { m_enableMessages = enable; }

		/*! Shows error message with \a title (it is not caption) and details. */
		virtual void showErrorMessage(const QString &title, 
			const QString &details = QString::null) = 0;
		
		/*! Shows error message with \a msg text. Existing error message from \a obj object
		 is also copied, if present. */
		virtual void showErrorMessage(KexiDB::Object *obj, const QString& msg = QString::null) = 0;

		/*! Interactively asks a question. For GUI version, KMessageBox class is used.
		 See KMessageBox documentation for explanation of the parameters.
		 \a defaultResult is returned in case when no message handler is installed. 
		 \a message should be i18n's string. 
		 Value from KMessageBox::ButtonCode enum is returned.
		 Reimplement this. This implementation does nothing, just returns \a defaultResult. */
		virtual int askQuestion( const QString& message, 
			KMessageBox::DialogType dlgType, KMessageBox::ButtonCode defaultResult,
			const KGuiItem &buttonYes=KStdGuiItem::yes(), 
			const KGuiItem &buttonNo=KStdGuiItem::no(),
			const QString &dontShowAskAgainName = QString::null,
			int options = KMessageBox::Notify );

	protected:
		QGuardedPtr<QWidget> m_messageHandlerParentWidget;
		bool m_enableMessages : 1;
};

}

#endif