Skip to content

Commit

Permalink
Add UI for wwivd into init
Browse files Browse the repository at this point in the history
  • Loading branch information
wwiv committed Feb 20, 2017
1 parent e80c402 commit 2fe612f
Show file tree
Hide file tree
Showing 10 changed files with 249 additions and 14 deletions.
4 changes: 2 additions & 2 deletions core/stl.h
Expand Up @@ -105,8 +105,8 @@ const signed int size_int(C c) {
}

template <typename C, typename S = std::size_t, typename R>
bool insert_at(C& c, S on, R r) {
std::size_t n = static_cast<decltype(c.size())>(on);
bool insert_at(C& c, S pos, R r) {
std::size_t n = static_cast<decltype(c.size())>(pos);

if (n < 0 || n > c.size()) {
return false;
Expand Down
1 change: 1 addition & 0 deletions init/CMakeLists.txt
Expand Up @@ -25,6 +25,7 @@ set(COMMON_SOURCES
sysop_account.cpp
user_editor.cpp
utility.cpp
wwivd_ui.cpp
)

if(UNIX)
Expand Down
7 changes: 4 additions & 3 deletions init/init.cpp
Expand Up @@ -62,6 +62,7 @@
#include "init/system_info.h"
#include "init/sysop_account.h"
#include "init/user_editor.h"
#include "init/wwivd_ui.h"
#include "init/wwivinit.h"
#include "init/utility.h"

Expand Down Expand Up @@ -334,6 +335,7 @@ int WInitApp::main(int argc, char** argv) {
{ "R. Registration Information", 'R' },
{ "U. User Editor", 'U' },
{ "X. Update Sub/Directory Maximums", 'X' },
{ "W. wwivd Configuration", 'W' },
{ "Q. Quit", 'Q' }
};

Expand Down Expand Up @@ -399,15 +401,14 @@ int WInitApp::main(int argc, char** argv) {
case 'U':
user_editor(config);
break;
case 'W': wwivd_ui(config); break;
case 'X': up_subs_dirs(config.datadir()); break;
case '$': {
vector<string> lines;
lines.push_back(StringPrintf("QSCan Lenth: %lu", syscfg.qscn_len));
lines.push_back(StringPrintf("WWIV %s%s INIT compiled %s", wwiv_version, beta_version, const_cast<char*>(wwiv_date)));
messagebox(window, lines);
} break;
case 'X':
up_subs_dirs(config.datadir());
break;
}
out->SetIndicatorMode(IndicatorMode::NONE);
} while (!done);
Expand Down
3 changes: 2 additions & 1 deletion init/init.vcxproj
Expand Up @@ -94,7 +94,6 @@
<ClInclude Include="editors.h" />
<ClInclude Include="init.h" />
<ClInclude Include="instance_settings.h" />
<ClInclude Include="ivardec.h" />
<ClInclude Include="languages.h" />
<ClInclude Include="levels.h" />
<ClInclude Include="networks.h" />
Expand All @@ -108,6 +107,7 @@
<ClInclude Include="system_info.h" />
<ClInclude Include="user_editor.h" />
<ClInclude Include="utility.h" />
<ClInclude Include="wwivd_ui.h" />
<ClInclude Include="wwivinit.h" />
</ItemGroup>
<ItemGroup>
Expand All @@ -131,6 +131,7 @@
<ClCompile Include="system_info.cpp" />
<ClCompile Include="user_editor.cpp" />
<ClCompile Include="utility.cpp" />
<ClCompile Include="wwivd_ui.cpp" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\core\core.vcxproj">
Expand Down
9 changes: 6 additions & 3 deletions init/init.vcxproj.filters
Expand Up @@ -29,9 +29,6 @@
<ClInclude Include="wwivinit.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="ivardec.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="regcode.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -83,6 +80,9 @@
<ClInclude Include="sysop_account.h">
<Filter>Source Files</Filter>
</ClInclude>
<ClInclude Include="wwivd_ui.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="init.cpp">
Expand Down Expand Up @@ -145,5 +145,8 @@
<ClCompile Include="menus.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="wwivd_ui.cpp">
<Filter>Source Files</Filter>
</ClCompile>
</ItemGroup>
</Project>
3 changes: 0 additions & 3 deletions init/paths.cpp
Expand Up @@ -21,9 +21,6 @@
#include <cstdint>
#include <memory>
#include <string>
#ifdef _WIN32
#include <direct.h>
#endif

#include "core/strings.h"
#include "core/wwivport.h"
Expand Down
203 changes: 203 additions & 0 deletions init/wwivd_ui.cpp
@@ -0,0 +1,203 @@
/**************************************************************************/
/* */
/* WWIV Initialization Utility Version 5 */
/* Copyright (C)2014-2017, WWIV Software Services */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, */
/* software distributed under the License is distributed on an */
/* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, */
/* either express or implied. See the License for the specific */
/* language governing permissions and limitations under the License. */
/* */
/**************************************************************************/
#include "init/wwivd_ui.h"

#include <cstdint>
#include <memory>
#include <string>

#include "bbs/keycodes.h"
#include "core/scope_exit.h"
#include "core/strings.h"
#include "core/wwivport.h"
#include "init/init.h"
#include "init/utility.h"
#include "init/wwivinit.h"
#include "localui/wwiv_curses.h"
#include "localui/input.h"
#include "localui/listbox.h"
#include "sdk/wwivd_config.h"

using std::unique_ptr;
using std::string;
using std::vector;
using namespace wwiv::core;
using namespace wwiv::sdk;
using namespace wwiv::stl;
using namespace wwiv::strings;

static const int COL1_LINE = 2;
static const int COL1_POSITION = 19;

static void edit_matrix_entry(wwivd_matrix_entry_t& b) {
EditItems items{};
char key[2] = { b.key, 0 };
{
int y = 1;
items.add(new StringEditItem<char*>(COL1_POSITION, y++, 1, key));
items.add(new StringEditItem<std::string&>(COL1_POSITION, y++, 12, b.name, false));
items.add(new StringEditItem<std::string&>(COL1_POSITION, y++, 52, b.description, false));
items.add(new StringEditItem<std::string&>(COL1_POSITION, y++, 52, b.telnet_cmd, false));
items.add(new StringEditItem<std::string&>(COL1_POSITION, y++, 52, b.ssh_cmd, false));
items.add(new BooleanEditItem(out, COL1_POSITION, y++, &b.require_ansi));
items.add(new NumberEditItem<int>(COL1_POSITION, y++, &b.start_node));
items.add(new NumberEditItem<int>(COL1_POSITION, y++, &b.end_node));
items.add(new NumberEditItem<int>(COL1_POSITION, y++, &b.local_node));
}

out->Cls(ACS_CKBOARD);
unique_ptr<CursesWindow> window(out->CreateBoxedWindow("System Paths", items.size() + 2, 76));
items.set_curses_io(out, window.get());
{
int y = 1;
window->PutsXY(COL1_LINE, y++, "Key : ");
window->PutsXY(COL1_LINE, y++, "Name : ");
window->PutsXY(COL1_LINE, y++, "Description : ");
window->PutsXY(COL1_LINE, y++, "Telnet Command : ");
window->PutsXY(COL1_LINE, y++, "SSH Command : ");
window->PutsXY(COL1_LINE, y++, "Require ANSI : ");
window->PutsXY(COL1_LINE, y++, "Start Node : ");
window->PutsXY(COL1_LINE, y++, "End Node : ");
window->PutsXY(COL1_LINE, y++, "Local Node : ");
}

items.Run();
b.key = key[0];
}

// Base item of an editable value, this class does not use templates.
class MatrixSubDialog : public BaseEditItem {
public:
MatrixSubDialog(wwivd_config_t& c, int x, int y)
: BaseEditItem(x, y, 1), c_(c), x_(x), y_(y) {};
virtual ~MatrixSubDialog() {}

virtual int Run(CursesWindow* window) {
ScopeExit at_exit([] { out->footer()->SetDefaultFooter(); });
out->footer()->ShowHelpItems(0, { { "Esc", "Exit" },{ "ENTER", "Edit Items (opens new dialog)." } });
window->GotoXY(x_, y_);
int ch = window->GetChar();
if (ch == KEY_ENTER || ch == TAB || ch == 13) {
bool done = false;
do {
vector<ListBoxItem> items;
for (const auto& e : c_.bbses) {
items.emplace_back(e.name);
}
ListBox list(out, window, "Select BBS",
static_cast<int>(floor(window->GetMaxX() * 0.8)),
std::min<int>(10, static_cast<int>(floor(window->GetMaxY() * 0.8))),
items, out->color_scheme());

list.selection_returns_hotkey(true);
list.set_additional_hotkeys("DI");
list.set_help_items({ { "Esc", "Exit" },{ "Enter", "Edit" },{ "D", "Delete" },{ "I", "Insert" } });
ListBoxResult result = list.Run();
if (result.type == ListBoxResultType::HOTKEY) {
switch (result.hotkey) {
case 'D': {
if (items.empty()) {
break;
}
if (!dialog_yn(window, StrCat("Delete '", items[result.selected].text(), "' ?"))) {
break;
}
wwiv::stl::erase_at(c_.bbses, result.selected);
} break;
case 'I': {
const string name = dialog_input_string(window, "Enter BBS Name: ", 8);
if (name.empty()) { break; }
wwivd_matrix_entry_t e{};
e.name = name;
e.key = name.front();
auto pos = result.selected;
if (pos >= 0 && pos < size_int(items)) {
wwiv::stl::insert_at(c_.bbses, pos, e);
}
else {
c_.bbses.push_back(e);
}
} break;
}
}
else if (result.type == ListBoxResultType::SELECTION) {
auto& b = c_.bbses.at(result.selected);
edit_matrix_entry(b);
}
else if (result.type == ListBoxResultType::NO_SELECTION) {
done = true;
}
} while (!done);

return 2;
}
else if (ch == KEY_UP || ch == KEY_BTAB) {
return 1; // PREV
}
else {
return 2;
}
}
virtual void Display(CursesWindow* window) const { window->PutsXY(x_, y_, "[Enter to Edit]"); }
private:
wwivd_config_t& c_;
int x_ = 0;
int y_ = 0;
};


void wwivd_ui(const wwiv::sdk::Config& config) {

wwivd_config_t c{};
if (!c.Load(config)) {
messagebox(out->window(), "Unable to load or create wwivd.json");
return;
}

EditItems items{};
{
int y = 1;
items.add(new NumberEditItem<int>(COL1_POSITION, y++, &c.telnet_port));
items.add(new NumberEditItem<int>(COL1_POSITION, y++, &c.ssh_port));
items.add(new NumberEditItem<int>(COL1_POSITION, y++, &c.binkp_port));
items.add(new StringEditItem<std::string&>(COL1_POSITION, y++, 52, c.binkp_cmd, false));
items.add(new NumberEditItem<int>(COL1_POSITION, y++, &c.http_port));
items.add(new StringEditItem<std::string&>(COL1_POSITION, y++, 16, c.http_address, false));
items.add(new StringEditItem<std::string&>(COL1_POSITION, y++, 12, c.matrix_filename, false));
items.add(new MatrixSubDialog(c, COL1_POSITION, y++));
}

out->Cls(ACS_CKBOARD);
unique_ptr<CursesWindow> window(out->CreateBoxedWindow("System Paths", items.size() + 2, 76));
items.set_curses_io(out, window.get());
{
int y = 1;
window->PutsXY(COL1_LINE, y++, "Telnet Port : ");
window->PutsXY(COL1_LINE, y++, "SSH Port : ");
window->PutsXY(COL1_LINE, y++, "BinkP Port : ");
window->PutsXY(COL1_LINE, y++, "BinkP Cmd : ");
window->PutsXY(COL1_LINE, y++, "HTTP Port : ");
window->PutsXY(COL1_LINE, y++, "HTTP Address : ");
window->PutsXY(COL1_LINE, y++, "Matrix Filename : ");
window->PutsXY(COL1_LINE, y++, "Matrix Settings : ");
}

items.Run();
c.Save(config);
}
26 changes: 26 additions & 0 deletions init/wwivd_ui.h
@@ -0,0 +1,26 @@
/**************************************************************************/
/* */
/* WWIV Initialization Utility Version 5 */
/* Copyright (C)2014-2017, WWIV Software Services */
/* */
/* Licensed under the Apache License, Version 2.0 (the "License"); */
/* you may not use this file except in compliance with the License. */
/* You may obtain a copy of the License at */
/* */
/* http://www.apache.org/licenses/LICENSE-2.0 */
/* */
/* Unless required by applicable law or agreed to in writing, */
/* software distributed under the License is distributed on an */
/* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, */
/* either express or implied. See the License for the specific */
/* language governing permissions and limitations under the License. */
/* */
/**************************************************************************/
#ifndef __INCLUDED_WWIVD_UI_H__
#define __INCLUDED_WWIVD_UI_H__

#include "sdk/config.h"

void wwivd_ui(const wwiv::sdk::Config& config);

#endif // __INCLUDED_WWIVD_UI_H__
3 changes: 2 additions & 1 deletion localui/input.cpp
Expand Up @@ -460,7 +460,8 @@ int editline(CursesWindow* window, char *s, int len, EditLineMode status, const
if ((pos < len) &&
(status == EditLineMode::ALL || (status == EditLineMode::UPPER_ONLY)
|| (status == EditLineMode::SET)
|| ((status == EditLineMode::NUM_ONLY) && (((ch >= '0') && (ch <= '9')) || (ch == ' '))))) {
|| ((status == EditLineMode::NUM_ONLY)
&& (((ch >= '0') && (ch <= '9')) || (ch == ' ') || (pos == 0) && (ch == '-') ) ))) {
if (bInsert) {
for (int i = len - 1; i > pos; i--) {
s[i] = s[i - 1];
Expand Down
4 changes: 3 additions & 1 deletion localui/input.h
Expand Up @@ -148,6 +148,8 @@ template<typename T> class StringEditItem: public EditItem<T> {
public:
StringEditItem(int x, int y, int maxsize, T data, bool uppercase)
: EditItem<T>(x, y, maxsize, data), uppercase_(uppercase) {}
StringEditItem(int x, int y, int maxsize, T data)
: StringEditItem(x, y, maxsize, data, false) {}
virtual ~StringEditItem() {}

int Run(CursesWindow* window) override {
Expand Down Expand Up @@ -196,7 +198,7 @@ class NumberEditItem : public EditItem<T*> {

virtual int Run(CursesWindow* window) {
window->GotoXY(this->x_, this->y_);
std::string s = wwiv::strings::StringPrintf("%-7u", *this->data_);
std::string s = std::to_string(*this->data_);
int return_code = editline(window, &s, MAXLEN + 1, EditLineMode::NUM_ONLY, "");
*this->data_ = static_cast<T>(atoi(s.c_str()));
return return_code;
Expand Down

0 comments on commit 2fe612f

Please sign in to comment.