#endif
#include "connectdialog.h"
+#include "rfb/rfbclient.h"
+const QString LISTEN_FOR_INCOMING_CONNECTIONS_STRING = QObject::tr("Listen for Incoming Connections");
+
ConnectDialog::ConnectDialog(QWidget *parent):
- QDialog(parent)
+ QDialog(parent),
+ done(new QPushButton)
{
setWindowTitle(tr("Connect to VNC Server"));
QSettings settings;
//set up combobox
hosts.addItems(hostnames_sorted);
hosts.insertSeparator(hosts.count());
- hosts.addItem(QIcon("/usr/share/icons/hicolor/48x48/hildon/general_received.png"), tr("Listen for Incoming Connections"));
+ hosts.addItem(QIcon("/usr/share/icons/hicolor/48x48/hildon/general_received.png"), LISTEN_FOR_INCOMING_CONNECTIONS_STRING);
hosts.setEditable(true);
#ifdef Q_WS_MAEMO_5
hosts.lineEdit()->setInputMethodHints(Qt::ImhNoAutoUppercase); //somehow this doesn't work that well here
#endif
connect(&hosts, SIGNAL(editTextChanged(QString)),
this, SLOT(hostnameUpdated(QString)));
- connect(&hosts, SIGNAL(currentIndexChanged(int)),
- this, SLOT(indexChanged(int)));
layout.addWidget(&hosts);
#ifdef Q_WS_MAEMO_5
hostnameUpdated(hosts.lineEdit()->text()); //get saved quality for last host, or 2
#endif
- QPushButton *done = new QPushButton(tr("Connect"));
done->setMaximumWidth(110);
connect(done, SIGNAL(clicked()),
this, SLOT(accept()));
this, SLOT(deleteLater()));
}
-void ConnectDialog::indexChanged(int index) {
- if(index == -1)
- return;
+void ConnectDialog::hostnameUpdated(QString newtext)
+{
+ const int cursorpos = hosts.lineEdit()->cursorPosition();
- //disallow editing for special entries (icon set)
- hosts.setEditable(hosts.itemIcon(index).isNull());
-}
+ const bool normal_entry = hosts.itemIcon(hosts.currentIndex()).isNull();
+ done->setText(normal_entry ? tr("Connect") : tr("Listen"));
+ //unselect 'listen ...' entry if edited
+ if(!normal_entry) {
+ if(newtext != LISTEN_FOR_INCOMING_CONNECTIONS_STRING) {
+ hosts.setCurrentIndex(-1);
+ } else {
+ return;
+ }
+ }
-void ConnectDialog::hostnameUpdated(QString newtext)
-{
- //clean up hostname
+ //clean up hostname (we don't want / or \ in saved hostnames)
newtext.remove(QChar('/'));
newtext.remove(QChar('\\'));
- int cursorpos = hosts.lineEdit()->cursorPosition();
- hosts.lineEdit()->setText(newtext.toLower());
+ hosts.lineEdit()->setText(newtext);
hosts.lineEdit()->setCursorPosition(cursorpos);
#ifdef Q_WS_MAEMO_5
if(selected_host.isEmpty()) {
return;
}
+
+#ifdef Q_WS_MAEMO_5
+ int quality = quality_selector->currentIndex() + 1;
+#else
+ int quality = 2;
+#endif
+
+ QSettings settings;
if(!hosts.itemIcon(hosts.currentIndex()).isNull()) {
- emit connectToHost("", 2, 5900); //TODO: quality and port from user input
+ int listen_port = settings.value("listen_port", LISTEN_PORT_OFFSET).toInt();
+
+#if QT_VERSION >= 0x040500
+ //ask user if listen_port is correct
+ bool ok;
+ listen_port = QInputDialog::getInt(this,
+ tr("Listen for Incoming Connections"),
+ tr("Listen on Port:"),
+ listen_port, 1, 65535, //value, min, max
+ 1, &ok);
+#else
+ bool ok = true;
+#endif
+ if(ok) {
+ settings.setValue("listen_port", listen_port);
+ emit connectToHost("", quality, listen_port);
+ }
return;
}
- QSettings settings;
settings.beginGroup("hosts");
- bool new_item = !hostnames_sorted.contains(selected_host);
- bool used_old_host = !new_item and hosts.currentIndex() > 0;
+ const bool new_item = !hostnames_sorted.contains(selected_host);
+ const bool used_old_host = !new_item and hosts.currentIndex() > 0;
//if both are false, we don't need to mess with positions
if(new_item or used_old_host) {
}
#ifdef Q_WS_MAEMO_5
- int quality = quality_selector->currentIndex() + 1;
settings.setValue(QString("%1/quality").arg(selected_host), quality);
-#else
- int quality = 2;
#endif
settings.endGroup();