Diffstat (limited to 'core/applets/logoutapplet/logout.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | core/applets/logoutapplet/logout.cpp | 115 |
1 files changed, 115 insertions, 0 deletions
diff --git a/core/applets/logoutapplet/logout.cpp b/core/applets/logoutapplet/logout.cpp new file mode 100644 index 0000000..9470401 --- a/dev/null +++ b/core/applets/logoutapplet/logout.cpp | |||
@@ -0,0 +1,115 @@ | |||
1 | #include <qpe/resource.h> | ||
2 | #include <qpe/qcopenvelope_qws.h> | ||
3 | |||
4 | #include <qapplication.h> | ||
5 | #include <qiconset.h> | ||
6 | #include <qpopupmenu.h> | ||
7 | #include <qmessagebox.h> | ||
8 | |||
9 | #include <unistd.h> | ||
10 | |||
11 | #include "logout.h" | ||
12 | |||
13 | |||
14 | LogoutApplet::LogoutApplet ( ) | ||
15 | : QObject ( 0, "LogoutApplet" ), ref ( 0 ) | ||
16 | { | ||
17 | } | ||
18 | |||
19 | LogoutApplet::~LogoutApplet ( ) | ||
20 | { | ||
21 | } | ||
22 | |||
23 | int LogoutApplet::position ( ) const | ||
24 | { | ||
25 | return 0; | ||
26 | } | ||
27 | |||
28 | QString LogoutApplet::name ( ) const | ||
29 | { | ||
30 | return tr( "Logout shortcut" ); | ||
31 | } | ||
32 | |||
33 | QString LogoutApplet::text ( ) const | ||
34 | { | ||
35 | return tr( "Logout" ); | ||
36 | } | ||
37 | |||
38 | QIconSet LogoutApplet::icon ( ) const | ||
39 | { | ||
40 | QPixmap pix; | ||
41 | QImage img = Resource::loadImage ( "logout" ); | ||
42 | |||
43 | if ( !img. isNull ( )) | ||
44 | pix. convertFromImage ( img. smoothScale ( 14, 14 )); | ||
45 | return pix; | ||
46 | } | ||
47 | |||
48 | QPopupMenu *LogoutApplet::popup ( QWidget * ) const | ||
49 | { | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | // This is a workaround for a Qt bug | ||
54 | // clipboard applet has to stop its poll timer, or Qt/E | ||
55 | // will hang on quit() right before it emits aboutToQuit() | ||
56 | |||
57 | class HackApplication : public QApplication { | ||
58 | public: | ||
59 | HackApplication ( ) : QApplication ( dummy, 0 ) | ||
60 | { | ||
61 | } | ||
62 | |||
63 | void emit_about_to_quit ( ) | ||
64 | { | ||
65 | emit aboutToQuit ( ); | ||
66 | } | ||
67 | |||
68 | int dummy; | ||
69 | }; | ||
70 | |||
71 | |||
72 | void LogoutApplet::activated ( ) | ||
73 | { | ||
74 | QMessageBox mb ( tr( "Logout" ), | ||
75 | tr( "Do you really want to\nend this session ?" ), | ||
76 | QMessageBox::NoIcon, | ||
77 | QMessageBox::Yes | QMessageBox::Default, | ||
78 | QMessageBox::No | QMessageBox::Escape, | ||
79 | QMessageBox::NoButton ); | ||
80 | |||
81 | mb. setButtonText ( QMessageBox::Yes, "Yes" ); | ||
82 | mb. setButtonText ( QMessageBox::No, "No" ); | ||
83 | mb. setIconPixmap ( icon ( ). pixmap ( )); | ||
84 | |||
85 | if ( mb. exec ( ) == QMessageBox::Yes ) { | ||
86 | { QCopEnvelope envelope( "QPE/System", "forceQuit()" ); } | ||
87 | |||
88 | qApp-> processEvents ( ); // ensure the message goes out. | ||
89 | sleep ( 1 ); // You have 1 second to comply. | ||
90 | |||
91 | ((HackApplication *) qApp )-> emit_about_to_quit ( ); | ||
92 | qApp-> quit(); | ||
93 | } | ||
94 | } | ||
95 | |||
96 | |||
97 | QRESULT LogoutApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface ) | ||
98 | { | ||
99 | *iface = 0; | ||
100 | if ( uuid == IID_QUnknown ) | ||
101 | *iface = this; | ||
102 | else if ( uuid == IID_MenuApplet ) | ||
103 | *iface = this; | ||
104 | |||
105 | if ( *iface ) | ||
106 | (*iface)-> addRef ( ); | ||
107 | return QS_OK; | ||
108 | } | ||
109 | |||
110 | Q_EXPORT_INTERFACE( ) | ||
111 | { | ||
112 | Q_CREATE_INSTANCE( LogoutApplet ) | ||
113 | } | ||
114 | |||
115 | |||