summaryrefslogtreecommitdiffstats
path: root/krfb/krfb/trayicon.cpp
blob: 5878b633382c27576531c4c55e8405d3f2bfbee3 (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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/***************************************************************************
                                trayicon.cpp
                             -------------------
    begin                : Tue Dec 11 2001
    copyright            : (C) 2001-2002 by Tim Jansen
    email                : tim@tjansen.de
 ***************************************************************************/

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

#include "trayicon.h"
#include <tqtooltip.h>
#include <kstdaction.h>
#include <kapplication.h>
#include <klocale.h>
#include <kdialog.h>
#include <kglobal.h>
#include <kiconloader.h>
#include <kpopupmenu.h>

KPassivePopup2::KPassivePopup2(TQWidget *parent) :
   KPassivePopup(parent){
}

void KPassivePopup2::hideEvent( TQHideEvent *e )
{
    KPassivePopup::hideEvent(e);
    emit hidden();
}

KPassivePopup2 *KPassivePopup2::message( const TQString &caption, const TQString &text,
				         const TQPixmap &icon,
				         TQWidget *parent)
{
    KPassivePopup2 *pop = new KPassivePopup2( parent);
    pop->setView( caption, text, icon );
    pop->show();

    return pop;
}


TrayIcon::TrayIcon(KDialog *d, Configuration *c) :
	KSystemTray(0, "krfb trayicon"),
	configuration(c),
	aboutDialog(d),
	actionCollection(this),
	quitting(false)
{
	KIconLoader *loader = KGlobal::iconLoader();
	trayIconOpen = loader->loadIcon("eyes-open24", KIcon::User);
	trayIconClosed = loader->loadIcon("eyes-closed24", KIcon::User);
	setPixmap(trayIconClosed);
	TQToolTip::add(this, i18n("Desktop Sharing - connecting"));

	manageInvitationsAction = new KAction(i18n("Manage &Invitations"), TQString(),
					      0, TQT_TQOBJECT(this), TQT_SIGNAL(showManageInvitations()),
					      &actionCollection);
	manageInvitationsAction->plug(contextMenu());

	contextMenu()->insertSeparator();

	enableControlAction = new KToggleAction(i18n("Enable Remote Control"));
	enableControlAction->setCheckedState(i18n("Disable Remote Control"));
	enableControlAction->plug(contextMenu());
	enableControlAction->setEnabled(false);
	connect(enableControlAction, TQT_SIGNAL(toggled(bool)), TQT_SIGNAL(enableDesktopControl(bool)));

	contextMenu()->insertSeparator();

	aboutAction = KStdAction::aboutApp(TQT_TQOBJECT(this), TQT_SLOT(showAbout()), &actionCollection);
	aboutAction->plug(contextMenu());

	show();
}

TrayIcon::~TrayIcon(){
}

void TrayIcon::showAbout() {
	aboutDialog->show();
}

void TrayIcon::prepareQuit() {
        quitting = true;
}



void TrayIcon::showConnectedMessage(TQString host) {

        setPixmap(trayIconOpen);
        KPassivePopup2::message(i18n("Desktop Sharing"),
				i18n("The remote user has been authenticated and is now connected."),
				trayIconOpen,
				this);
	TQToolTip::add(this, i18n("Desktop Sharing - connected with %1").tqarg(host));
}

void TrayIcon::showDisconnectedMessage() {
        if (quitting)
                return;

	TQToolTip::add(this, i18n("Desktop Sharing - disconnected"));
        setPixmap(trayIconClosed);
        KPassivePopup2 *p = KPassivePopup2::message(i18n("Desktop Sharing"),
						    i18n("The remote user has closed the connection."),
						    trayIconClosed,
						    this);
	connect(p, TQT_SIGNAL(hidden()), this, TQT_SIGNAL(diconnectedMessageDisplayed()));
}

void TrayIcon::setDesktopControlSetting(bool b) {
	enableControlAction->setEnabled(true);
	enableControlAction->setChecked(b);
}

void TrayIcon::mousePressEvent(TQMouseEvent *e)
{
        if (!TQT_TQRECT_OBJECT(rect()).contains(e->pos()))
                return;

	if (e->button() == Qt::LeftButton) {
	        contextMenuAboutToShow(contextMenu());
		contextMenu()->popup(e->globalPos());
	}
	else
	        KSystemTray::mousePressEvent(e);
}

#include "trayicon.moc"