blob: e65cbadb247a0b71d6ffff717b1d5ff3abd98151 [file] [log] [blame]
Pierre Ossman561ff0c2011-05-13 14:04:59 +00001/* Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
2 *
3 * This is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation; either version 2 of the License, or
6 * (at your option) any later version.
7 *
8 * This software is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this software; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
16 * USA.
17 */
18
19#include <FL/Fl.H>
20#include <FL/Fl_Input.H>
21#include <FL/Fl_Button.H>
22#include <FL/Fl_Return_Button.H>
23#include <FL/fl_draw.H>
24
25#include "ServerDialog.h"
Pierre Ossmand463b572011-05-16 12:04:43 +000026#include "OptionsDialog.h"
27#include "fltk_layout.h"
Pierre Ossman561ff0c2011-05-13 14:04:59 +000028#include "i18n.h"
29
30extern void about_vncviewer();
31
32ServerDialog::ServerDialog()
33 : Fl_Window(400, 112, _("VNC Viewer: Connection Details"))
34{
35 int width;
36 Fl_Button *button;
37
Pierre Ossmand463b572011-05-16 12:04:43 +000038 width = gui_str_len(_("VNC server:"));
Pierre Ossman561ff0c2011-05-13 14:04:59 +000039 serverName = new Fl_Input(20 + width, 20, w() - 20*2 - width, 25, _("VNC server:"));
40
41 width = (w() - 20) / 4;
42
43 button = new Fl_Button(20 + width*0, 20+25+20, width - 20, 27, _("About..."));
44 button->callback(this->handleAbout, this);
45
Pierre Ossmand463b572011-05-16 12:04:43 +000046 button = new Fl_Button(20 + width*1, 20+25+20, width - 20, 27, _("Options..."));
47 button->callback(this->handleOptions, this);
48
Pierre Ossman561ff0c2011-05-13 14:04:59 +000049 button = new Fl_Button(20 + width*2, 20+25+20, width - 20, 27, _("Cancel"));
50 button->callback(this->handleCancel, this);
51
52 button = new Fl_Return_Button(20 + width*3, 20+25+20, width - 20, 27, _("OK"));
53 button->callback(this->handleOK, this);
54
55 callback(this->handleCancel, this);
56
57 set_modal();
58}
59
60
61ServerDialog::~ServerDialog()
62{
63}
64
65
66const char *ServerDialog::run()
67{
68 ServerDialog dialog;
69 static char buffer[256];
70
71 dialog.show();
72 while (dialog.shown()) Fl::wait();
73
74 if (dialog.serverName->value() == NULL)
75 return NULL;
76
77 strncpy(buffer, dialog.serverName->value(), sizeof(buffer));
78 buffer[sizeof(buffer)-1] = '\0';
79
80 return buffer;
81}
82
83
84void ServerDialog::handleAbout(Fl_Widget *widget, void *data)
85{
86 about_vncviewer();
87}
88
89
Pierre Ossmand463b572011-05-16 12:04:43 +000090void ServerDialog::handleOptions(Fl_Widget *widget, void *data)
91{
92 OptionsDialog::showDialog();
93}
94
95
Pierre Ossman561ff0c2011-05-13 14:04:59 +000096void ServerDialog::handleCancel(Fl_Widget *widget, void *data)
97{
98 ServerDialog *dialog = (ServerDialog*)data;
99
100 dialog->serverName->value(NULL);
101 dialog->hide();
102}
103
104
105void ServerDialog::handleOK(Fl_Widget *widget, void *data)
106{
107 ServerDialog *dialog = (ServerDialog*)data;
108
109 dialog->hide();
110}