summaryrefslogtreecommitdiffstats
path: root/src/jabber_whiteboard/invitation-handlers.cpp
blob: 124b9515be23e95aca88c5ed25606082232a7e68 (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
139
140
141
142
143
144
145
146
147
148
149
150
/**
 * Whiteboard session manager - invitation handling methods
 *
 * Authors: 
 * David Yip <yipdw@rose-hulman.edu>
 * Bob Jamison (Pedro port)
 *
 * Copyright (c) 2005 Authors
 *
 * Released under GNU GPL, read the file 'COPYING' for more information
 */

#include <gtkmm.h>
#include <glibmm/i18n.h>

#include "util/ucompose.hpp"

#include "document.h"
#include "desktop-handles.h"

#include "jabber_whiteboard/inkboard-document.h"
#include "jabber_whiteboard/session-manager.h"
#include "jabber_whiteboard/invitation-confirm-dialog.h"


namespace Inkscape {

namespace Whiteboard {

bool
SessionManager::_checkInvitationQueue()
{
	int x, y;
	Gdk::ModifierType mt;
	Gdk::Display::get_default()->get_pointer(x, y, mt);
	if (mt & GDK_BUTTON1_MASK) {
		// The user is currently busy with an action.  Defer invitation processing 
		// until the user is free.
		return true;
	}

	if (_pending_invitations.size() > 0) {
		// There's an invitation to process; process it.
		Glib::ustring from = _pending_invitations.front();

		Glib::ustring primary = "<span weight=\"bold\" size=\"larger\">" + String::ucompose(_("<b>%1</b> has invited you to a whiteboard session."), from) + "</span>\n\n";
		primary += String::ucompose(_("Do you wish to accept <b>%1</b>'s whiteboard session invitation?"), from);

		InvitationConfirmDialog dialog(primary);
		
		dialog.add_button(_("Accept invitation"), ACCEPT_INVITATION);
		dialog.add_button(_("Decline invitation"), DECLINE_INVITATION);

		InvitationResponses resp = static_cast< InvitationResponses >(dialog.run());

		switch (resp) {
			case ACCEPT_INVITATION:
			{
				SPDesktop* dt = createInkboardDesktop(from, INKBOARD_PRIVATE);
				InkboardDocument* idoc = dynamic_cast< InkboardDocument* >(sp_desktop_document(dt)->rdoc);
				send(from, CONNECT_REQUEST_RESPONSE_USER, " ");
				break;
			}
			case DECLINE_INVITATION:
			{
				break;
			}
			default:
				send(from, CONNECT_REQUEST_REFUSED_BY_PEER, " ");
				break;
		}

		_pending_invitations.pop_front();
	}

	return true;
}


bool
SessionManager::_checkInvitationResponseQueue()
{
	int x, y;
	Gdk::ModifierType mt;
	Gdk::Display::get_default()->get_pointer(x, y, mt);
	if (mt & GDK_BUTTON1_MASK) {
		// The user is currently busy with an action.  Defer invitation response processing 
		// until the user is free.
		return true;
	}

	if (_invitation_responses.size() > 0) {
		Invitation_response_type response = _invitation_responses.front();

		switch (response.second) {
			case ACCEPT_INVITATION:
			{
				break;
			}
			case DECLINE_INVITATION:
			{
				Glib::ustring primary = String::ucompose(_("<span weight=\"bold\" size=\"larger\">The user <b>%1</b> has refused your whiteboard invitation.</span>\n\n"), response.first);

				// TRANSLATORS: %1 is the peer whom refused our invitation, %2 is our Jabber identity.
				Glib::ustring secondary = String::ucompose(_("You are still connected to a Jabber server as <b>%2</b>, and may send an invitation to <b>%1</b> again, or you may send an invitation to a different user."), response.first, this->getClient().getJid());

				Gtk::MessageDialog dialog(primary + secondary, true, Gtk::MESSAGE_INFO, Gtk::BUTTONS_CLOSE, false);
				dialog.run();
				terminateInkboardSession(response.first);
				break;
			}
			case PEER_ALREADY_IN_SESSION:
				break;

			case UNSUPPORTED_PROTOCOL:
			{
				Glib::ustring primary = String::ucompose(_("<span weight=\"bold\" size=\"larger\">The user <b>%1</b> is using an incompatible version of Inkboard.</span>\n\n"), response.first);

				// TRANSLATORS: %1 is the peer whom refused our invitation, %2 is our Jabber identity.
				Glib::ustring secondary = String::ucompose(_("Inkscape cannot connect to <b>%1</b>.\n\nYou are still connected to a Jabber server as <b>%2</b>."), response.first, this->getClient().getJid());

				Gtk::MessageDialog dialog(primary + secondary, true, Gtk::MESSAGE_INFO, Gtk::BUTTONS_CLOSE, false);
				dialog.run();
				terminateInkboardSession(response.first);
				break;
			}
			default:
				break;
		}

		_invitation_responses.pop_front();
	}

	return true;
}

}

}

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :