File: joinprogressdialog.hpp

package info (click to toggle)
gobby 0.4.12-2
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 2,712 kB
  • ctags: 1,488
  • sloc: cpp: 11,818; sh: 3,918; makefile: 221
file content (172 lines) | stat: -rw-r--r-- 4,298 bytes parent folder | download | duplicates (2)
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/* gobby - A GTKmm driven libobby client
 * Copyright (C) 2005, 2006 0x539 dev group
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the Free
 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#ifndef _GOBBY_JOINPROGRESSDIALOG_HPP_
#define _GOBBY_JOINPROGRESSDIALOG_HPP_

#include <gtkmm/colorbutton.h>
#include <obby/error.hpp>
#include "buffer_def.hpp"
#include "progressdialog.hpp"
#include "colorsel.hpp"
#include "config.hpp"

namespace Gobby
{

class JoinProgressDialog: public ProgressDialog
{
public:
	JoinProgressDialog(Gtk::Window& parent,
	                   Config::ParentEntry& config_entry,
	                   const Glib::ustring& hostname,
			   unsigned int port,
	                   const net6::address* addr,
	                   const Glib::ustring& username,
	                   const Gdk::Color& color);

	/** Never call this function twice because the auto_ptr of the
	 * JoinDialog will be reset to NULL after having transferred the data
	 * to the caller.
	 */
	std::auto_ptr<ClientBuffer> get_buffer();

private:
	typedef ClientBuffer::connection_settings connection_settings;

	class Prompt: public Gtk::Dialog
	{
	protected:
		Prompt(Gtk::Window& parent,
		       const Glib::ustring& title,
		       const Glib::ustring& info,
		       const Gtk::StockID& icon);

		void set_custom_widget(Widget& widget);

		Gtk::Table m_table;
		Gtk::Label m_info;
		Gtk::Image m_icon;
	};

	class NamePrompt: public Prompt
	{
	public:
		NamePrompt(Gtk::Window& parent,
		           const Glib::ustring& initial_name);

		Glib::ustring get_name() const;
	protected:
		void on_change();

		const Glib::ustring m_initial_name;

		Gtk::HBox m_box;
		Gtk::Label m_label;
		Gtk::Entry m_entry;
	};

	class ColorPrompt: public Prompt
	{
	public:
		ColorPrompt(Gtk::Window& parent,
		            Config::ParentEntry& config_entry,
		            const Gdk::Color& initial_color);

		Gdk::Color get_color() const;
	protected:
		ColorButton m_button;
	};

	class SessionPasswordPrompt: public Prompt
	{
	public:
		SessionPasswordPrompt(Gtk::Window& parent,
		                      bool password_tried);

		Glib::ustring get_password() const;
	protected:
		void on_change();

		Gtk::HBox m_box;
		Gtk::Label m_label;
		Gtk::Entry m_entry;
	};

	class UserPasswordPrompt: public Prompt
	{
	public:
		UserPasswordPrompt(Gtk::Window& parent,
		                   const Glib::ustring& initial_name);

		Glib::ustring get_name() const;
		Glib::ustring get_password() const;
	protected:
		void on_change();

		const Glib::ustring m_initial_name;

		Gtk::Table m_table;
		Gtk::Label m_lbl_name;
		Gtk::Label m_lbl_password;
		Gtk::Entry m_ent_name;
		Gtk::Entry m_ent_password;
	};

	virtual void on_thread(Thread& thread);
	virtual void on_done();

	void on_welcome();
	void on_login_failed(obby::login::error error);

	bool on_prompt_name(connection_settings& settings);
	bool on_prompt_colour(connection_settings& settings);
	bool on_prompt_global_password(connection_settings& settings);
	bool on_prompt_user_password(connection_settings& settings);

	void on_sync_init(unsigned int count);
	void on_sync_final();
	void on_close();

	void display_error(const Glib::ustring& message);

	virtual void on_response(int response_id);

	Config::ParentEntry& m_config_entry;

	Glib::ustring m_hostname;
	unsigned int m_port;
	std::auto_ptr<net6::address> m_address;
	Glib::ustring m_username;
	Gdk::Color m_color;

	Glib::ustring m_error;

	std::auto_ptr<ClientBuffer> m_buffer;

	// Got done signal from connection thread
	bool m_got_done;
	// Got welcome packet
	bool m_got_welcome;
	// First time password question
	bool m_password_tried;
};

} // namespace Gobby

#endif // _GOBBY_JOINPROGRESSDIALOG_HPP_