~ubuntu-branches/ubuntu/utopic/psi/utopic

« back to all changes in this revision

Viewing changes to iris/irisnet/processquit.h

  • Committer: Bazaar Package Importer
  • Author(s): Jan Niehusmann
  • Date: 2009-09-25 17:49:51 UTC
  • mfrom: (6.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090925174951-lvm7kdap82o8xhn3
Tags: 0.13-1
* Updated to upstream version 0.13
* Set Standards-Version to 3.8.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2006  Justin Karneges
3
 
 *
4
 
 * This library is free software; you can redistribute it and/or
5
 
 * modify it under the terms of the GNU Lesser General Public
6
 
 * License as published by the Free Software Foundation; either
7
 
 * version 2.1 of the License, or (at your option) any later version.
8
 
 *
9
 
 * This library is distributed in the hope that it will be useful,
10
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
 
 * Lesser General Public License for more details.
13
 
 *
14
 
 * You should have received a copy of the GNU Lesser General Public
15
 
 * License along with this library; if not, write to the Free Software
16
 
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17
 
 * 02110-1301  USA
18
 
 *
19
 
 */
20
 
 
21
 
#ifndef PROCESSQUIT_H
22
 
#define PROCESSQUIT_H
23
 
 
24
 
#ifdef NO_IRISNET
25
 
# include <QtCore>
26
 
# define IRISNET_EXPORT
27
 
#else
28
 
# include "irisnetglobal.h"
29
 
#endif
30
 
 
31
 
#ifndef NO_IRISNET
32
 
namespace XMPP {
33
 
#endif
34
 
 
35
 
/**
36
 
   \brief Listens for termination requests
37
 
 
38
 
   ProcessQuit listens for requests to terminate the application process.  On Unix platforms, these are the signals SIGINT, SIGHUP, and SIGTERM.  On Windows, these are the console control events for Ctrl+C, console window close, and system shutdown.  For Windows GUI programs, ProcessQuit has no effect.
39
 
 
40
 
   For GUI programs, ProcessQuit is not a substitute for QSessionManager.  The only safe way to handle termination of a GUI program in the usual way is to use QSessionManager.  However, ProcessQuit does give additional benefit to Unix GUI programs that might be terminated unconventionally, so it can't hurt to support both.
41
 
 
42
 
   When a termination request is received, the application should exit gracefully, and generally without user interaction.  Otherwise, it is at risk of being terminated outside of its control.  For example, if a Windows console application does not exit after just a few seconds of attempting to close the console window, Windows will display a prompt to the user asking if the process should be ended immediately.
43
 
 
44
 
   Using ProcessQuit is easy, and it usually amounts to a single line:
45
 
   \code
46
 
myapp.connect(ProcessQuit::instance(), SIGNAL(quit()), SLOT(do_quit()));
47
 
   \endcode
48
 
 
49
 
   Calling instance() returns a pointer to the global ProcessQuit instance, which will be created if necessary.  The quit() signal is emitted when a request to terminate is received.    The quit() signal is only emitted once, future termination requests are ignored.  Call reset() to allow the quit() signal to be emitted again.
50
 
*/
51
 
class IRISNET_EXPORT ProcessQuit : public QObject
52
 
{
53
 
        Q_OBJECT
54
 
public:
55
 
        /**
56
 
           \brief Returns the global ProcessQuit instance
57
 
 
58
 
           If the global instance does not exist yet, it will be created, and the termination handlers will be installed.
59
 
 
60
 
           \sa cleanup
61
 
        */
62
 
        static ProcessQuit *instance();
63
 
 
64
 
        /**
65
 
           \brief Allows the quit() signal to be emitted again
66
 
 
67
 
           ProcessQuit only emits the quit() signal once, so that if a user repeatedly presses Ctrl-C or sends SIGTERM, your shutdown slot will not be called multiple times.  This is normally the desired behavior, but if you are ignoring the termination request then you may want to allow future notifications.  Calling this function will allow the quit() signal to be emitted again, if a new termination request arrives.
68
 
 
69
 
           \sa quit
70
 
        */
71
 
        static void reset();
72
 
 
73
 
        /**
74
 
           \brief Frees all resources used by ProcessQuit
75
 
 
76
 
           This function will free any resources used by ProcessQuit, including the global instance, and the termination handlers will be uninstalled (reverted to default).  Future termination requests will cause the application to exit abruptly.
77
 
 
78
 
           \note You normally do not need to call this function directly.  When IrisNet cleans up, it will be called.
79
 
 
80
 
           \sa instance
81
 
        */
82
 
        static void cleanup();
83
 
 
84
 
signals:
85
 
        /**
86
 
           \brief Notification of termination request
87
 
 
88
 
           This signal is emitted when a termination request is received.  It is only emitted once, unless reset() is called.
89
 
 
90
 
           Upon receiving this signal, the application should proceed to exit gracefully, and generally without user interaction.
91
 
 
92
 
           \sa reset
93
 
        */
94
 
        void quit();
95
 
 
96
 
private:
97
 
        class Private;
98
 
        friend class Private;
99
 
        Private *d;
100
 
 
101
 
        ProcessQuit(QObject *parent = 0);
102
 
        ~ProcessQuit();
103
 
};
104
 
 
105
 
#ifndef NO_IRISNET
106
 
}
107
 
#endif
108
 
 
109
 
#endif