summaryrefslogtreecommitdiff
path: root/core/applets/logoutapplet/logout.cpp
blob: dc0c67c5458cc82ab46b1681a7f7aa4135c55719 (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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#include "logout.h"

#include <opie2/oresource.h>

#include <qpe/applnk.h>
#include <qpe/qcopenvelope_qws.h>

#include <qapplication.h>
#include <qmessagebox.h>

#include <unistd.h>

LogoutApplet::LogoutApplet ( )
	: QObject ( 0, "LogoutApplet" )
{
}

LogoutApplet::~LogoutApplet ( )
{
}

int LogoutApplet::position ( ) const
{
    return 0;
}

QString LogoutApplet::name ( ) const
{
	return tr( "Logout shortcut" );
}

QString LogoutApplet::text ( ) const
{
	return tr( "Logout" );
}

QString LogoutApplet::tr( const char* s ) const
{
    return qApp->translate( "LogoutApplet", s, 0 );
}

QString LogoutApplet::tr( const char* s, const char* p ) const
{
    return qApp->translate( "LogoutApplet", s, p );
}

QIconSet LogoutApplet::icon ( ) const
{
    QPixmap pix = Opie::Core::OResource::loadPixmap("logout", Opie::Core::OResource::SmallIcon );
	return pix;
}

QPopupMenu *LogoutApplet::popup ( QWidget * ) const
{
	return 0;
}

// This is a workaround for a Qt bug
// clipboard applet has to stop its poll timer, or Qt/E
// will hang on quit() right before it emits aboutToQuit()

class HackApplication : public QApplication {
public:
	HackApplication ( ) : QApplication ( dummy, 0 )
	{
	}

	void emit_about_to_quit ( )
	{
		emit aboutToQuit ( );
	}

	int dummy;
};


void LogoutApplet::activated ( )
{
	QMessageBox mb ( tr( "Logout" ),
	                 tr( "Do you really want to\nend this session ?" ),
	                 QMessageBox::NoIcon,
	                 QMessageBox::Yes | QMessageBox::Default,
	                 QMessageBox::No | QMessageBox::Escape,
	                 QMessageBox::NoButton );

	mb. setButtonText ( QMessageBox::Yes, "Yes" );
	mb. setButtonText ( QMessageBox::No, "No" );
	mb. setIconPixmap ( icon ( ). pixmap ( ));

	if ( mb. exec ( ) == QMessageBox::Yes ) {
		{ QCopEnvelope envelope( "QPE/System", "forceQuit()" ); }

		qApp-> processEvents ( ); // ensure the message goes out.
		sleep ( 1 );  // You have 1 second to comply.

		((HackApplication *) qApp )-> emit_about_to_quit ( );
		qApp-> quit();
	}
}


QRESULT LogoutApplet::queryInterface ( const QUuid &uuid, QUnknownInterface **iface )
{
	*iface = 0;
	if ( uuid == IID_QUnknown )
		*iface = this;
	else if ( uuid == IID_MenuApplet )
		*iface = this;
	else
	    return QS_FALSE;

	if ( *iface )
		(*iface)-> addRef ( );
	return QS_OK;
}

Q_EXPORT_INTERFACE( )
{
	Q_CREATE_INSTANCE( LogoutApplet )
}