Skip to content

Commit e5452ae

Browse files
authored
New feature QuickNote and controls position fix
* New feature - QuickNote - work-in-progress - Where you click an item in the hostlist and you can enter a very short note / message about it at bottom-left of app window (I think I want to change the Fl_Box to Fl_Multiline_Output) * Was using wrong hostlist dimension in control positioning -- fixed
1 parent ee89151 commit e5452ae

File tree

5 files changed

+214
-27
lines changed

5 files changed

+214
-27
lines changed

src/app.cxx

Lines changed: 177 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,31 @@
4040
*/
4141
int SVInput::handle (int evt)
4242
{
43+
// save and close the quicknote editor
44+
if (evt == FL_KEYUP && app->quickNoteWindow != 0)
45+
{
46+
if (Fl::event_key() == FL_Enter)
47+
{
48+
// get currently selected list item
49+
int curLine = app->hostList->value();
50+
51+
if (curLine > 0)
52+
{
53+
HostItem * itm = static_cast<HostItem *>(app->hostList->data(curLine));
54+
55+
if (itm != NULL)
56+
{
57+
itm->quickNote = app->quickNoteInput->value();
58+
app->quickNote->copy_label(itm->quickNote.c_str());
59+
app->quickNoteInput->value("");
60+
app->quickNoteWindow->hide();
61+
svConfigWrite();
62+
}
63+
}
64+
}
65+
return 1;
66+
}
67+
4368
static bool inMenu;
4469

4570
// handle child window input controls right-click
@@ -148,6 +173,56 @@ int SVSecretInput::handle (int evt)
148173
}
149174

150175

176+
/* handle method for SVBox
177+
* (instance method)
178+
*/
179+
int SVQuickNoteBox::handle (int evt)
180+
{
181+
// get currently selected list item
182+
int curLine = app->hostList->value();
183+
184+
// handle quicknote click if an item is selected
185+
if (evt == FL_PUSH && curLine > 0)
186+
{
187+
// create a quicknote window if it doesn't exist
188+
if (app->quickNoteWindow == NULL)
189+
{
190+
app->quickNoteWindow = new Fl_Window(0, 0, 110, 32);
191+
192+
Fl_Group * inputGroup = new Fl_Group(3, 3, 100, 24);
193+
inputGroup->box(FL_THIN_DOWN_BOX);
194+
app->quickNoteInput = new SVInput(0, 0, 100, 24);
195+
inputGroup->end();
196+
197+
app->quickNoteWindow->end();
198+
app->quickNoteWindow->clear_border();
199+
app->quickNoteWindow->xclass("spiritvncfltktextentry");
200+
app->quickNoteWindow->callback(svHandleQuickNoteWindowEvents);
201+
}
202+
203+
// show the editor if there's a selected item
204+
if (curLine > 0)
205+
{
206+
HostItem * itm = static_cast<HostItem *>(app->hostList->data(curLine));
207+
208+
if (itm != NULL && itm->name != "")
209+
{
210+
app->quickNoteWindow->position(app->mainWin->x_root() + app->quickNote->x(),
211+
app->mainWin->y_root() + app->quickNote->y());
212+
app->quickNoteWindow->size(app->quickNote->w(), app->quickNoteWindow->h());
213+
app->quickNoteWindow->set_modal();
214+
215+
app->quickNoteInput->size(app->quickNote->w(), app->quickNoteWindow->h());
216+
app->quickNoteInput->value(itm->quickNote.c_str());
217+
218+
app->quickNoteWindow->show();
219+
}
220+
}
221+
}
222+
223+
return Fl_Box::handle(evt);
224+
}
225+
151226
/*
152227
child window 'OK' button callback - closes child windows (settings, options, etc
153228
(Fl_Widget * is unused, so parameter name removed according to 'best practices')
@@ -262,6 +337,15 @@ void svConfigReadCreateHostList ()
262337
app->nDeadTimeout = w;
263338
}
264339

340+
// ssh command
341+
if (strProp == "sshcommand")
342+
{
343+
app->sshCommand = strVal;
344+
345+
if (app->sshCommand == "")
346+
app->sshCommand = "ssh";
347+
}
348+
265349
// starting local port number for ssh
266350
if (strProp == "startinglocalport")
267351
{
@@ -485,6 +569,10 @@ void svConfigReadCreateHostList ()
485569
// center y?
486570
if (strProp == "centery")
487571
itm->centerY = svConvertStringToBoolean(strVal);
572+
573+
// quicknote
574+
if (strProp == "quicknote")
575+
itm->quickNote = base64Decode(strVal);
488576
}
489577
}
490578
else
@@ -554,6 +642,9 @@ void svConfigWrite ()
554642
// starting local port number (+99) for ssh connections
555643
ofs << "startinglocalport=" << app->nStartingLocalPort << std::endl;
556644

645+
// ssh command
646+
ofs << "sshcommand=" << app->sshCommand << std::endl;
647+
557648
// show tool tips
558649
ofs << "showtooltips=" << svConvertBooleanToString(app->showTooltips) << std::endl;
559650

@@ -613,6 +704,8 @@ void svConfigWrite ()
613704
ofs << "ignoreinactive=" << svConvertBooleanToString(itm->ignoreInactive) << std::endl;
614705
ofs << "centerx=" << svConvertBooleanToString(itm->centerX) << std::endl;
615706
ofs << "centery=" << svConvertBooleanToString(itm->centerY) << std::endl;
707+
ofs << "quicknote=" << base64Encode(reinterpret_cast<const unsigned char *>
708+
(itm->quickNote.c_str()), itm->quickNote.size()) << std::endl;
616709

617710
ofs << std::endl;
618711
}
@@ -813,7 +906,7 @@ void svCreateGUI ()
813906

814907
app->packButtons = new Fl_Pack(0, 0, 1, nBtnSize);
815908
app->packButtons->type(Fl_Pack::HORIZONTAL);
816-
app->packButtons->begin();
909+
//app->packButtons->begin();
817910

818911
app->btnListAdd = new Fl_Button(0, 0, nBtnSize, nBtnSize);
819912
app->btnListAdd->clear_visible_focus();
@@ -851,19 +944,41 @@ void svCreateGUI ()
851944

852945
app->packButtons->end();
853946

947+
// create host list
948+
app->hostList = new Fl_Hold_Browser(0, 0, 0, 0);
949+
app->hostList->clear_visible_focus();
950+
app->hostList->callback(svHandleHostListEvents, NULL);
951+
app->hostList->box(FL_THIN_DOWN_BOX);
952+
953+
// *** quicknote ***
954+
955+
// quicknote group
956+
app->quickNoteGroup = new Fl_Group(0, 0, 100, 68);
957+
958+
// quicknote label - item name
959+
app->quickNoteLabel = new Fl_Box(0, 0, 100, 18);
960+
app->quickNoteLabel->labelsize(app->nAppFontSize);
961+
app->quickNoteLabel->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE);
962+
app->quickNoteLabel->labelfont(1);
963+
app->quickNoteLabel->box(FL_THIN_DOWN_BOX);
964+
965+
// quicknote - very brief item info
966+
app->quickNote = new SVQuickNoteBox(0, 22, 100, 50);
967+
app->quickNote->labelsize(app->nAppFontSize);
968+
app->quickNote->align(FL_ALIGN_TOP_LEFT | FL_ALIGN_INSIDE);
969+
app->quickNote->box(FL_THIN_DOWN_BOX);
970+
//// app->quickNote->labelfont(1);
971+
972+
app->quickNoteGroup->end();
973+
854974
// create scrolling window we will add viewers to
855975
app->scroller = new Fl_Scroll(0, 0, 0, 0);
856976
app->vncViewer = new VncViewer(0, 0, 0, 0);
857977
app->scroller->box(FL_FLAT_BOX);
858978
app->scroller->type(0);
859979
app->scroller->end();
860980

861-
// create host list
862-
app->hostList = new Fl_Hold_Browser(0, 0, 0, 0);
863-
app->hostList->clear_visible_focus();
864-
app->hostList->callback(svHandleHostListEvents, NULL);
865-
app->hostList->box(FL_THIN_DOWN_BOX);
866-
981+
// set resizable widget for whole app
867982
app->mainWin->resizable(app->scroller);
868983
}
869984

@@ -1086,6 +1201,9 @@ void svHandleAppOptionsButtons (Fl_Widget * widget, void *)
10861201
if (strName == "spinDeadTimeout")
10871202
app->nDeadTimeout = static_cast<Fl_Spinner *>(wid)->value();
10881203

1204+
if (strName == "inSSHCommand")
1205+
app->sshCommand = static_cast<SVInput *>(wid)->value();
1206+
10891207
if (strName == "inAppFontSize")
10901208
app->nAppFontSize = atoi(static_cast<SVInput *>(wid)->value());
10911209

@@ -1354,12 +1472,22 @@ void svHandleHostListEvents (Fl_Widget *, void *)
13541472
HostItem * itm = static_cast<HostItem *>(app->hostList->data(nHostItemNum));
13551473

13561474
if (itm == NULL)
1475+
{
1476+
// set itm's quicknote text, if any
1477+
app->quickNoteLabel->label("");
1478+
app->quickNote->label("");
1479+
13571480
return;
1481+
}
13581482

13591483
VncObject * vnc = itm->vnc;
13601484

13611485
static bool menuUp;
13621486

1487+
// set itm's quicknote text, if any
1488+
app->quickNoteLabel->copy_label(itm->name.c_str());
1489+
app->quickNote->copy_label(itm->quickNote.c_str());
1490+
13631491
// *** DO *NOT* CHECK vnc FOR NULL HERE!!! ***
13641492
// *** IT'S OKAY IF vnc IS NULL AT THIS POINT!!! ***
13651493

@@ -1903,20 +2031,49 @@ void svHandleMainWindowEvents (Fl_Widget * window, void *)
19032031
}
19042032

19052033

2034+
/* handle quicknote's box events (mostly clicks) */
2035+
void svHandleQuickNoteWindowEvents (Fl_Widget *, void *)
2036+
{
2037+
int event = app->quickNoteWindow->when();
2038+
2039+
// window is closing
2040+
if (event == FL_LEAVE)
2041+
{
2042+
app->quickNoteInput->value("");
2043+
app->quickNoteWindow->hide();
2044+
}
2045+
}
2046+
2047+
19062048
/*
19072049
* handle app and main window events, such as resize, move, etc
19082050
* and resize gui elements
19092051
*/
19102052
void svPositionWidgets ()
19112053
{
1912-
// only continue if main window geometry changes
19132054
svDebugLog("svPositionWidgets - Resizing GUI elements");
19142055

19152056
// resize the host list vertically if the main window resizes
1916-
app->hostList->size(app->hostList->w(), app->mainWin->h() - 26);
2057+
app->hostList->size(app->hostList->w(),
2058+
app->mainWin->h() - //155); //26);
2059+
app->quickNoteGroup->h() -
2060+
//app->quickNoteLabel->h() - app->quickNote->h() -
2061+
app->packButtons->h());
2062+
2063+
// position QuickNote stuff
2064+
app->quickNoteGroup->size(app->hostList->w(), app->quickNoteGroup->h() - 3);
2065+
app->quickNoteGroup->position(0, app->hostList->y() + app->hostList->h() + 3);
2066+
2067+
app->quickNoteLabel->size(app->hostList->w(), app->quickNoteLabel->h() - 3);
2068+
//app->quickNoteLabel->position(0, app->hostList->y() + app->hostList->h() + 3);
2069+
2070+
app->quickNote->size(app->hostList->w(), app->quickNote->h() - 3);
2071+
//app->quickNote->position(0, app->quickNoteLabel->y() + app->quickNoteLabel->h() + 3);
19172072

19182073
// set list buttons position
1919-
app->packButtons->position(3, app->hostList->x() + app->hostList->h() + 3);
2074+
// app->packButtons->position(3, app->hostList->x() + app->hostList->h() + 3);
2075+
app->packButtons->position(0, app->quickNote->y() + app->quickNote->h()
2076+
+ 3);
19202077

19212078
// don't allow host list width to be smaller than right-most button's x+w
19222079
if (app->hostList->w() < (app->packButtons->x() + app->packButtons->w()))
@@ -2603,17 +2760,8 @@ void svShowAppOptions ()
26032760
// create window
26042761
Fl_Window * winAppOpts = new Fl_Window(nX, nY, nWinWidth, nWinHeight, "Application Options"); //NULL);
26052762
winAppOpts->set_non_modal();
2606-
//winAppOpts->box(FL_GTK_UP_BOX);
26072763
app->childWindowBeingDisplayed = winAppOpts;
26082764

2609-
//// add main top label, showing itm name
2610-
//Fl_Box * bxTopLabel = new Fl_Box(0, 0, nWinWidth, 28, "Application Options");
2611-
//bxTopLabel->align(FL_ALIGN_CENTER);
2612-
//bxTopLabel->labelfont(1);
2613-
//bxTopLabel->labelsize(app->nAppFontSize);
2614-
//bxTopLabel->box(FL_GTK_UP_BOX);
2615-
//bxTopLabel->color(17);
2616-
26172765
// add itm value editors / selectors
26182766
int nXPos = 300;
26192767
int nYStep = 31;
@@ -2666,6 +2814,16 @@ void svShowAppOptions ()
26662814
spinDeadTimeout->tooltip("This is the time, in seconds, SpiritVNC waits before"
26672815
" disconnecting a remote host due to inactivity");
26682816

2817+
// ssh command
2818+
SVInput * inSSHCommand = new SVInput(nXPos, nYPos += nYStep, 210, 28,
2819+
"SSH command (eg: ssh or /usr/bin/ssh) ");
2820+
inSSHCommand->textsize(app->nAppFontSize);
2821+
inSSHCommand->labelsize(app->nAppFontSize);
2822+
inSSHCommand->user_data(SV_OPTS_SSH_COMMAND);
2823+
inSSHCommand->value(app->sshCommand.c_str());
2824+
if (app->showTooltips == true)
2825+
inSSHCommand->tooltip("This is the command to start the SSH client on"
2826+
" your system");
26692827

26702828
Fl_Box * lblSep01 = new Fl_Box(nXPos, nYPos += nYStep + 14, 100, 28, "Appearance Options");
26712829
lblSep01->labelsize(app->nAppFontSize);

src/app.h

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
#include <FL/Fl_Scroll.H>
5555
#include <FL/Fl_Secret_Input.H>
5656
#include <FL/Fl_Spinner.H>
57+
//#include <FL/Fl_Text_Editor.H>
5758
#include <FL/Fl_Widget.H>
5859
#include <FL/Fl_Window.H>
5960

@@ -76,6 +77,8 @@
7677
#include "ssh.h"
7778

7879

80+
class SVInput;
81+
7982
/* global app class */
8083
class AppVars
8184
{
@@ -132,7 +135,12 @@ class AppVars
132135
createdObjects(0),
133136
msgThread(0),
134137
strF12ClipVar(""),
135-
sshCommand("ssh")
138+
sshCommand("ssh"),
139+
quickNoteGroup(NULL),
140+
quickNoteLabel(NULL),
141+
quickNote(NULL),
142+
quickNoteWindow(NULL),
143+
quickNoteInput(NULL)
136144
{
137145
// get user's login name for reading/writing config file
138146

@@ -228,6 +236,11 @@ class AppVars
228236
pthread_t msgThread;
229237
std::string strF12ClipVar;
230238
std::string sshCommand;
239+
Fl_Group * quickNoteGroup;
240+
Fl_Box * quickNoteLabel;
241+
Fl_Box * quickNote;
242+
Fl_Window * quickNoteWindow;
243+
SVInput * quickNoteInput;
231244
} extern * app;
232245

233246

@@ -241,7 +254,6 @@ class SVInput : public Fl_Input
241254
int handle (int event);
242255
};
243256

244-
245257
/* subclassed password input box */
246258
class SVSecretInput : public Fl_Secret_Input
247259
{
@@ -252,6 +264,16 @@ class SVSecretInput : public Fl_Secret_Input
252264
int handle (int evt);
253265
};
254266

267+
/* subclassed box */
268+
class SVQuickNoteBox : public Fl_Box
269+
{
270+
public:
271+
SVQuickNoteBox (int x, int y, int w, int h, const char * label = 0) :
272+
Fl_Box(x, y, w, h, label) {}
273+
private:
274+
int handle (int event);
275+
};
276+
255277

256278
/* forward function declarations */
257279
void svCloseChildWindow (Fl_Widget *, void *);
@@ -278,6 +300,7 @@ void svHandleHostListEvents (Fl_Widget *, void *);
278300
void svHandleMainWindowEvents (Fl_Widget *, void *);
279301
void svPositionWidgets ();
280302
void svHandleListItemIconChange (void *);
303+
void svHandleQuickNoteWindowEvents (Fl_Widget *, void *);
281304
void svHandleThreadConnection (void *);
282305
void svHandleThreadCursorChange (void *);
283306
void svInsertEmptyItem ();

src/consts_enums.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
#define SV_OPTS_SCN_TIMEOUT const_cast<char *>("spinScanTimeout")
5757
#define SV_OPTS_LOCAL_SSH_PORT const_cast<char *>("spinLocalSSHPort")
5858
#define SV_OPTS_DEAD_TIMEOUT const_cast<char *>("spinDeadTimeout")
59+
#define SV_OPTS_SSH_COMMAND const_cast<char *>("inSSHCommand")
5960
#define SV_OPTS_APP_FONT_SIZE const_cast<char *>("inAppFontSize")
6061
#define SV_OPTS_LIST_FONT_NAME const_cast<char *>("inListFont")
6162
#define SV_OPTS_LIST_FONT_SIZE const_cast<char *>("inListFontSize")

0 commit comments

Comments
 (0)