Skip to content

Commit f2d44e1

Browse files
author
Teuniz
committed
Added the possibility to use a hostname instead of an IP-address for the LAN connection.
1 parent 8603a33 commit f2d44e1

File tree

6 files changed

+189
-54
lines changed

6 files changed

+189
-54
lines changed

global.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636

3737
#define PROGRAM_NAME "DSRemote"
38-
#define PROGRAM_VERSION "0.35_1707091429"
38+
#define PROGRAM_VERSION "0.35_1709091834"
3939

4040
#define MAX_PATHLEN 4096
4141

@@ -124,6 +124,8 @@ struct device_settings
124124
int vertdivisions; // number of vertical divisions, 8 or 10
125125
int use_extra_vertdivisions; // If 1: use 10 vertical divisions instead of 8, DS1000Z only
126126

127+
char hostname[128];
128+
127129
int screentimerival;
128130

129131
int channel_cnt; // Device has 2 or 4 channels

lan_connect_thread.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ struct tmcdev * lan_connect_thread::get_device(void)
5555

5656
void lan_connect_thread::set_device_address(const char *addr)
5757
{
58-
strncpy(dev_str, addr, 16);
58+
strncpy(dev_str, addr, 63);
5959

60-
dev_str[15] = 0;
60+
dev_str[63] = 0;
6161
}
6262

6363

mainwindow.cpp

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -98,53 +98,62 @@ void UI_Mainwindow::open_connection()
9898

9999
if(devparms.connectiontype == 1) // LAN
100100
{
101-
strcpy(dev_str, settings.value("connection/ip", "192.168.1.100").toString().toLatin1().data());
101+
strcpy(devparms.hostname, settings.value("connection/hostname", "").toString().toLatin1().data());
102102

103-
if(!strcmp(dev_str, ""))
103+
if(strlen(devparms.hostname))
104104
{
105-
sprintf(str, "No IP address set");
106-
goto OC_OUT_ERROR;
105+
strcpy(dev_str, devparms.hostname);
107106
}
108-
109-
len = strlen(dev_str);
110-
111-
if(len < 7)
107+
else
112108
{
113-
sprintf(str, "No IP address set");
114-
goto OC_OUT_ERROR;
115-
}
109+
strcpy(dev_str, settings.value("connection/ip", "192.168.1.100").toString().toLatin1().data());
116110

117-
int cf = 0;
111+
if(!strcmp(dev_str, ""))
112+
{
113+
sprintf(str, "No IP address or hostname set");
114+
goto OC_OUT_ERROR;
115+
}
118116

119-
for(i=0; i<len; i++)
120-
{
121-
if(dev_str[i] == '.')
117+
len = strlen(dev_str);
118+
119+
if(len < 7)
122120
{
123-
cf = 0;
121+
sprintf(str, "No IP address set");
122+
goto OC_OUT_ERROR;
124123
}
125124

126-
if(dev_str[i] == '0')
125+
int cf = 0;
126+
127+
for(i=0; i<len; i++)
127128
{
128-
if(cf == 0)
129+
if(dev_str[i] == '.')
129130
{
130-
if((dev_str[i+1] != 0) && (dev_str[i+1] != '.'))
131+
cf = 0;
132+
}
133+
134+
if(dev_str[i] == '0')
135+
{
136+
if(cf == 0)
131137
{
132-
for(j=i; j<len; j++)
138+
if((dev_str[i+1] != 0) && (dev_str[i+1] != '.'))
133139
{
134-
dev_str[j] = dev_str[j+1];
135-
}
140+
for(j=i; j<len; j++)
141+
{
142+
dev_str[j] = dev_str[j+1];
143+
}
136144

137-
i--;
145+
i--;
138146

139-
len--;
147+
len--;
148+
}
140149
}
141150
}
142-
}
143-
else
144-
{
145-
if(dev_str[i] != '.')
151+
else
146152
{
147-
cf = 1;
153+
if(dev_str[i] != '.')
154+
{
155+
cf = 1;
156+
}
148157
}
149158
}
150159
}
@@ -548,6 +557,8 @@ void UI_Mainwindow::close_connection()
548557
}
549558

550559
statusLabel->setText("Disconnected");
560+
561+
printf("Disconnected from device\n");
551562
}
552563

553564

settings_dialog.cpp

Lines changed: 89 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -57,14 +57,19 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
5757
usbRadioButton->setChecked(true);
5858
}
5959

60-
lanRadioButton = new QRadioButton("LAN", this);
61-
lanRadioButton->setAutoExclusive(true);
62-
lanRadioButton->setGeometry(40, 70, 110, 25);
60+
lanIPRadioButton = new QRadioButton("LAN", this);
61+
lanIPRadioButton->setAutoExclusive(true);
62+
lanIPRadioButton->setGeometry(40, 70, 110, 25);
6363
if(mainwindow->devparms.connectiontype == 1)
6464
{
65-
lanRadioButton->setChecked(true);
65+
lanIPRadioButton->setChecked(true);
6666
}
6767

68+
hostnameLabel = new QLabel(this);
69+
hostnameLabel->setGeometry(40, 120, 120, 35);
70+
hostnameLabel->setText("Hostname\n(overides IP-address)");
71+
hostnameLabel->setToolTip("Leave empty if you want to use the above IP-address");
72+
6873
comboBox1 = new QComboBox(this);
6974
comboBox1->setGeometry(180, 20, 110, 25);
7075
comboBox1->addItem("/dev/usbtmc0");
@@ -129,23 +134,34 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
129134
ipSpinbox4->setValue(100);
130135
}
131136

137+
if(settings.contains("connection/hostname"))
138+
{
139+
strncpy(mainwindow->devparms.hostname, settings.value("connection/hostname").toString().toLatin1().data(), 63);
140+
}
141+
142+
HostLineEdit = new QLineEdit(this);
143+
HostLineEdit->setGeometry(180, 120, 240, 25);
144+
HostLineEdit->setMaxLength(63);
145+
HostLineEdit->setText(mainwindow->devparms.hostname);
146+
HostLineEdit->setToolTip("Leave empty if you want to use the above IP-address");
147+
132148
refreshLabel = new QLabel(this);
133-
refreshLabel->setGeometry(40, 120, 120, 35);
134-
refreshLabel->setText("Screen update\n interval");
149+
refreshLabel->setGeometry(40, 170, 120, 35);
150+
refreshLabel->setText("Screen update\ninterval");
135151

136152
refreshSpinbox = new QSpinBox(this);
137-
refreshSpinbox->setGeometry(180, 120, 100, 25);
153+
refreshSpinbox->setGeometry(180, 170, 100, 25);
138154
refreshSpinbox->setSuffix(" mS");
139155
refreshSpinbox->setRange(50, 2000);
140156
refreshSpinbox->setSingleStep(10);
141157
refreshSpinbox->setValue(mainwindow->devparms.screentimerival);
142158

143159
invScrShtLabel = new QLabel(this);
144-
invScrShtLabel->setGeometry(40, 170, 120, 35);
160+
invScrShtLabel->setGeometry(40, 220, 120, 35);
145161
invScrShtLabel->setText("Screenshot invert\n colors");
146162

147163
invScrShtCheckbox = new QCheckBox(this);
148-
invScrShtCheckbox->setGeometry(180, 170, 120, 35);
164+
invScrShtCheckbox->setGeometry(180, 220, 120, 35);
149165
invScrShtCheckbox->setTristate(false);
150166
if(mainwindow->devparms.screenshot_inv)
151167
{
@@ -157,11 +173,11 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
157173
}
158174

159175
showfpsLabel = new QLabel(this);
160-
showfpsLabel->setGeometry(40, 220, 120, 35);
176+
showfpsLabel->setGeometry(40, 270, 120, 35);
161177
showfpsLabel->setText("Show frames\n per second");
162178

163179
showfpsCheckbox = new QCheckBox(this);
164-
showfpsCheckbox->setGeometry(180, 220, 120, 35);
180+
showfpsCheckbox->setGeometry(180, 270, 120, 35);
165181
showfpsCheckbox->setTristate(false);
166182
if(mainwindow->devparms.show_fps)
167183
{
@@ -173,11 +189,11 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
173189
}
174190

175191
extendvertdivLabel = new QLabel(this);
176-
extendvertdivLabel->setGeometry(40, 270, 120, 35);
192+
extendvertdivLabel->setGeometry(40, 320, 120, 35);
177193
extendvertdivLabel->setText("Use extended\n vertical range");
178194

179195
extendvertdivCheckbox = new QCheckBox(this);
180-
extendvertdivCheckbox->setGeometry(180, 270, 120, 35);
196+
extendvertdivCheckbox->setGeometry(180, 320, 120, 35);
181197
extendvertdivCheckbox->setTristate(false);
182198
if(mainwindow->devparms.use_extra_vertdivisions)
183199
{
@@ -210,7 +226,7 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
210226
if(mainwindow->devparms.connected)
211227
{
212228
usbRadioButton->setEnabled(false);
213-
lanRadioButton->setEnabled(false);
229+
lanIPRadioButton->setEnabled(false);
214230
ipSpinbox1->setEnabled(false);
215231
ipSpinbox2->setEnabled(false);
216232
ipSpinbox3->setEnabled(false);
@@ -223,11 +239,12 @@ UI_settings_window::UI_settings_window(QWidget *parnt)
223239
QObject::connect(applyButton, SIGNAL(clicked()), this, SLOT(applyButtonClicked()));
224240
}
225241

226-
QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
227-
QObject::connect(refreshSpinbox, SIGNAL(valueChanged(int)), this, SLOT(refreshSpinboxChanged(int)));
228-
QObject::connect(invScrShtCheckbox, SIGNAL(stateChanged(int)), this, SLOT(invScrShtCheckboxChanged(int)));
229-
QObject::connect(showfpsCheckbox, SIGNAL(stateChanged(int)), this, SLOT(showfpsCheckboxChanged(int)));
230-
QObject::connect(extendvertdivCheckbox, SIGNAL(stateChanged(int)), this, SLOT(extendvertdivCheckboxChanged(int)));
242+
QObject::connect(cancelButton, SIGNAL(clicked()), this, SLOT(close()));
243+
QObject::connect(refreshSpinbox, SIGNAL(valueChanged(int)), this, SLOT(refreshSpinboxChanged(int)));
244+
QObject::connect(invScrShtCheckbox, SIGNAL(stateChanged(int)), this, SLOT(invScrShtCheckboxChanged(int)));
245+
QObject::connect(showfpsCheckbox, SIGNAL(stateChanged(int)), this, SLOT(showfpsCheckboxChanged(int)));
246+
QObject::connect(extendvertdivCheckbox, SIGNAL(stateChanged(int)), this, SLOT(extendvertdivCheckboxChanged(int)));
247+
QObject::connect(HostLineEdit, SIGNAL(textEdited(QString)), this, SLOT(hostnamechanged(QString)));
231248

232249
exec();
233250
}
@@ -268,6 +285,10 @@ void UI_settings_window::applyButtonClicked()
268285

269286
settings.setValue("connection/ip", dev_str);
270287

288+
strncpy(mainwindow->devparms.hostname, HostLineEdit->text().toLatin1().data(), 64);
289+
290+
settings.setValue("connection/hostname", mainwindow->devparms.hostname);
291+
271292
if(invScrShtCheckbox->checkState() == Qt::Checked)
272293
{
273294
mainwindow->devparms.screenshot_inv = 1;
@@ -388,6 +409,55 @@ void UI_settings_window::extendvertdivCheckboxChanged(int state)
388409
}
389410

390411

412+
void UI_settings_window::hostnamechanged(QString qstr)
413+
{
414+
int i, j, len, trunc=0;
415+
416+
char str[128];
417+
418+
strncpy(str, qstr.toLatin1().data(), 63);
419+
420+
str[63] = 0;
421+
422+
len = strlen(str);
423+
424+
for(i=0; i<len; i++)
425+
{
426+
if(((str[i] < '0') && (str[i] != '-') && (str[i] != '.')) ||
427+
((str[i] > '9') && (str[i] < 'A')) ||
428+
((str[i] > 'Z') && (str[i] < 'a')) ||
429+
(str[i] > 'z'))
430+
{
431+
for(j=i; j<len; j++)
432+
{
433+
str[j] = str[j+1];
434+
}
435+
436+
len--;
437+
438+
i--;
439+
440+
trunc = 1;
441+
}
442+
}
443+
444+
for(i=0; i<len; i++)
445+
{
446+
if((str[i] >= 'A') && (str[i] <= 'Z'))
447+
{
448+
str[i] += 32;
449+
450+
trunc = 1;
451+
}
452+
}
453+
454+
if(trunc)
455+
{
456+
HostLineEdit->setText(str);
457+
}
458+
}
459+
460+
391461

392462

393463

settings_dialog.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@
4343
#include <QSettings>
4444
#include <QRadioButton>
4545
#include <QSpinBox>
46+
#include <QLineEdit>
47+
48+
#include <stdio.h>
49+
#include <stdlib.h>
50+
#include <string.h>
4651

4752
#include "mainwindow.h"
4853
#include "global.h"
@@ -65,7 +70,7 @@ QPushButton *cancelButton,
6570
*applyButton;
6671

6772
QRadioButton *usbRadioButton,
68-
*lanRadioButton;
73+
*lanIPRadioButton;
6974

7075
QComboBox *comboBox1;
7176

@@ -78,12 +83,15 @@ QSpinBox *refreshSpinbox,
7883
QLabel *refreshLabel,
7984
*invScrShtLabel,
8085
*showfpsLabel,
81-
*extendvertdivLabel;
86+
*extendvertdivLabel,
87+
*hostnameLabel;
8288

8389
QCheckBox *invScrShtCheckbox,
8490
*showfpsCheckbox,
8591
*extendvertdivCheckbox;
8692

93+
QLineEdit *HostLineEdit;
94+
8795
UI_Mainwindow *mainwindow;
8896

8997
private slots:
@@ -93,6 +101,7 @@ void refreshSpinboxChanged(int);
93101
void invScrShtCheckboxChanged(int);
94102
void showfpsCheckboxChanged(int);
95103
void extendvertdivCheckboxChanged(int);
104+
void hostnamechanged(QString);
96105

97106
};
98107

0 commit comments

Comments
 (0)