2010-01-25 14:01:22 +01:00
|
|
|
#include "gui.hh"
|
|
|
|
#include "menu.hh"
|
|
|
|
#include "help_box.hh"
|
|
|
|
#include "virtual_keyboard.hh"
|
|
|
|
|
|
|
|
#include <sysdeps.h>
|
|
|
|
#include <C64.h>
|
|
|
|
|
2011-08-08 13:21:52 +02:00
|
|
|
#ifdef GEKKO
|
|
|
|
#include <smb.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Mount SMB Share
|
|
|
|
****************************************************************************/
|
|
|
|
extern bool smbismount;
|
|
|
|
|
|
|
|
bool ConnectShare ()
|
|
|
|
{
|
|
|
|
|
|
|
|
if(smbismount)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
#ifdef GEKKO
|
|
|
|
if(smbInit(ThePrefs.SmbUser, ThePrefs.SmbPwd,ThePrefs.SmbShare, ThePrefs.SmbIp))
|
|
|
|
smbismount = true;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if(!smbismount) Gui::gui->status_bar->queueMessage("Failed to connect to SMB share");
|
|
|
|
else {
|
|
|
|
Gui::gui->status_bar->queueMessage("Established connection to SMB share");
|
|
|
|
Gui::gui->np->Port = PORT_SMB;
|
|
|
|
}
|
|
|
|
|
|
|
|
return smbismount;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void CloseShare(bool silent)
|
|
|
|
{
|
|
|
|
|
|
|
|
if(smbismount) {
|
|
|
|
if (!silent) Gui::gui->status_bar->queueMessage("Disconnected from SMB share");
|
|
|
|
#ifdef GEKKO
|
|
|
|
smbClose("smb");
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
smbismount = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
extern bool networkisinit;
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
class NetworkView;
|
|
|
|
|
|
|
|
class NetworkMenu : public Menu, public KeyboardListener
|
|
|
|
{
|
|
|
|
friend class NetworkView;
|
|
|
|
|
|
|
|
public:
|
|
|
|
NetworkMenu(Font *font, HelpBox *help) : Menu(font)
|
|
|
|
{
|
|
|
|
this->help = help;
|
|
|
|
memset(this->messages, 0, sizeof(this->messages));
|
|
|
|
memset(this->strs, 0, sizeof(this->strs));
|
|
|
|
}
|
|
|
|
|
|
|
|
~NetworkMenu()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void stringCallback(const char *str)
|
|
|
|
{
|
|
|
|
switch (this->cur_sel)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
strncpy(Gui::gui->np->NetworkName, str, sizeof(Gui::gui->np->NetworkName));
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
strncpy(Gui::gui->np->NetworkServer, str, sizeof(Gui::gui->np->NetworkName));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
{
|
|
|
|
char *endp;
|
|
|
|
unsigned long v;
|
|
|
|
|
|
|
|
v = strtoul(str, &endp, 0);
|
|
|
|
if (endp == str)
|
|
|
|
{
|
|
|
|
DialogueBox *error_dialogue = new DialogueBox(network_port_dialogue_messages);
|
|
|
|
Gui::gui->pushDialogueBox(error_dialogue);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
Gui::gui->np->NetworkPort = v;
|
|
|
|
} break;
|
2011-08-08 13:21:52 +02:00
|
|
|
case 9:
|
|
|
|
strncpy(Gui::gui->np->SmbUser, str, sizeof(Gui::gui->np->SmbUser));
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
strncpy(Gui::gui->np->SmbPwd, str, sizeof(Gui::gui->np->SmbPwd));
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
strncpy(Gui::gui->np->SmbShare, str, sizeof(Gui::gui->np->SmbShare));
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
if (!inet_aton(str, NULL))
|
|
|
|
{
|
|
|
|
DialogueBox *error_dialogue = new DialogueBox(network_bad_ip_dlg);
|
|
|
|
Gui::gui->pushDialogueBox(error_dialogue);
|
|
|
|
}
|
|
|
|
else strncpy(Gui::gui->np->SmbIp, str, sizeof(Gui::gui->np->SmbIp));
|
|
|
|
break;
|
2010-01-25 14:01:22 +01:00
|
|
|
default:
|
|
|
|
panic("Cur sel is %d, not possible!\n", this->cur_sel);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
this->updateMessages();
|
|
|
|
}
|
2011-08-08 13:21:52 +02:00
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
virtual void selectCallback(int which)
|
|
|
|
{
|
2011-08-08 13:21:52 +02:00
|
|
|
//printf("option entry %d selected: %s\n", which, this->pp_msgs[which]);
|
2010-01-25 14:01:22 +01:00
|
|
|
switch (which)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
case 1:
|
|
|
|
VirtualKeyboard::kbd->activate();
|
|
|
|
VirtualKeyboard::kbd->registerListener(this);
|
|
|
|
break;
|
2010-02-21 11:25:39 +01:00
|
|
|
case 2:
|
|
|
|
Gui::gui->pushView(Gui::gui->nrv);
|
|
|
|
break;
|
2010-01-25 14:01:22 +01:00
|
|
|
case 4:
|
2011-08-08 13:21:52 +02:00
|
|
|
if (!networkisinit) Gui::gui->pushDialogueBox(new DialogueBox(network_is_not_init_dlg));
|
|
|
|
else if (TheC64->network)
|
2010-03-10 07:37:25 +01:00
|
|
|
TheC64->network->Disconnect();
|
|
|
|
else if ( strncmp(Gui::gui->np->NetworkName, "Unset", strlen("Unset")) == 0)
|
2010-01-25 14:01:22 +01:00
|
|
|
Gui::gui->pushDialogueBox(new DialogueBox(network_unset_name_dlg));
|
|
|
|
else
|
2010-02-14 10:41:14 +01:00
|
|
|
{
|
|
|
|
TheC64->network = new Network(Gui::gui->np->NetworkServer,
|
|
|
|
Gui::gui->np->NetworkPort);
|
2010-01-25 14:01:22 +01:00
|
|
|
TheC64->network_connection_type = CONNECT;
|
2010-02-24 13:10:56 +01:00
|
|
|
Gui::gui->exitMenu();
|
2010-03-10 19:37:06 +01:00
|
|
|
TheC64->network->ConnectToBroker();
|
2010-02-14 10:41:14 +01:00
|
|
|
}
|
2010-01-25 14:01:22 +01:00
|
|
|
break;
|
|
|
|
case 6:
|
2010-02-21 14:16:04 +01:00
|
|
|
if (TheC64->network_connection_type == NONE)
|
|
|
|
Gui::gui->pushDialogueBox(new DialogueBox(network_need_connection));
|
|
|
|
else
|
2010-02-21 17:33:25 +01:00
|
|
|
{
|
|
|
|
Gui::gui->exitMenu();
|
|
|
|
TheC64->TheDisplay->TypeNetworkMessage(true);
|
|
|
|
}
|
2010-01-25 14:01:22 +01:00
|
|
|
break;
|
2010-02-21 14:05:01 +01:00
|
|
|
case 7:
|
2010-02-21 14:16:04 +01:00
|
|
|
if (TheC64->network_connection_type != MASTER &&
|
|
|
|
TheC64->network_connection_type != CLIENT)
|
|
|
|
Gui::gui->pushDialogueBox(new DialogueBox(network_need_peer));
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Gui::gui->exitMenu();
|
|
|
|
TheC64->TheDisplay->TypeNetworkMessage();
|
|
|
|
}
|
2010-02-21 14:05:01 +01:00
|
|
|
break;
|
2011-08-08 13:21:52 +02:00
|
|
|
case 9:
|
|
|
|
case 10:
|
|
|
|
case 11:
|
|
|
|
case 12:
|
|
|
|
VirtualKeyboard::kbd->activate();
|
|
|
|
VirtualKeyboard::kbd->registerListener(this);
|
|
|
|
break;
|
|
|
|
case 13:
|
|
|
|
if (!networkisinit) Gui::gui->pushDialogueBox(new DialogueBox(network_is_not_init_dlg));
|
|
|
|
else {if (smbismount) CloseShare(false); else ConnectShare();this->updateMessages();}
|
|
|
|
break;
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void hoverCallback(int which)
|
|
|
|
{
|
|
|
|
this->help->updateHelpMessage(which);
|
|
|
|
}
|
|
|
|
|
|
|
|
virtual void escapeCallback(int which)
|
|
|
|
{
|
|
|
|
Gui::gui->popView();
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
void updateMessages()
|
|
|
|
{
|
|
|
|
memset(this->strs, 0, sizeof(this->strs));
|
|
|
|
snprintf(this->strs[0], sizeof(this->strs[0]) - 1, "Set username (%s)",
|
|
|
|
Gui::gui->np->NetworkName);
|
|
|
|
snprintf(this->strs[1], sizeof(this->strs[1]) - 1, "Server (%s)",
|
|
|
|
Gui::gui->np->NetworkServer);
|
2010-02-21 11:25:39 +01:00
|
|
|
snprintf(this->strs[2], sizeof(this->strs[2]) - 1, "Set region (%s)",
|
|
|
|
region_to_str(Gui::gui->np->NetworkRegion));
|
2011-08-08 13:21:52 +02:00
|
|
|
snprintf(this->strs[3], sizeof(this->strs[3]) - 1, "Set SMB user (%s)",
|
|
|
|
Gui::gui->np->SmbUser);
|
|
|
|
snprintf(this->strs[4], sizeof(this->strs[4]) - 1, "Set SMB psw (%s)",
|
|
|
|
Gui::gui->np->SmbPwd);
|
|
|
|
snprintf(this->strs[5], sizeof(this->strs[5]) - 1, "Set SMB folder (%s)",
|
|
|
|
Gui::gui->np->SmbShare);
|
|
|
|
snprintf(this->strs[6], sizeof(this->strs[6]) - 1, "Set SMB IP (%s)",
|
|
|
|
Gui::gui->np->SmbIp);
|
|
|
|
|
2010-01-25 14:01:22 +01:00
|
|
|
this->messages[0] = this->strs[0];
|
|
|
|
this->messages[1] = this->strs[1];
|
|
|
|
this->messages[2] = this->strs[2];
|
|
|
|
|
|
|
|
this->messages[3] = " ";
|
2011-08-08 13:21:52 +02:00
|
|
|
this->messages[4] = TheC64->network ? "Disconnect C64 network" : "Connect to C64 network!";
|
2010-01-25 14:01:22 +01:00
|
|
|
this->messages[5] = " ";
|
|
|
|
this->messages[6] = "Post network message";
|
2010-02-21 14:05:01 +01:00
|
|
|
this->messages[7] = "Post peer message";
|
2011-08-08 13:21:52 +02:00
|
|
|
this->messages[8] = " ";
|
|
|
|
this->messages[9] = this->strs[3];
|
|
|
|
this->messages[10] = this->strs[4];
|
|
|
|
this->messages[11] = this->strs[5];
|
|
|
|
this->messages[12] = this->strs[6];
|
|
|
|
this->messages[13] = smbismount ? "Disconnect from SMB share" : "Connect to SMB share";
|
|
|
|
this->messages[14] = NULL;
|
2010-01-25 14:01:22 +01:00
|
|
|
this->setText(this->messages);
|
|
|
|
}
|
|
|
|
|
2011-08-08 13:21:52 +02:00
|
|
|
char strs[7][255];
|
|
|
|
const char *messages[15];
|
2010-01-25 14:01:22 +01:00
|
|
|
|
|
|
|
HelpBox *help;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class NetworkView : public GuiView
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
NetworkView() : GuiView()
|
|
|
|
{
|
|
|
|
this->help = new HelpBox(Gui::gui->small_font, network_menu_help);
|
|
|
|
this->menu = new NetworkMenu(Gui::gui->default_font, this->help);
|
|
|
|
}
|
|
|
|
|
|
|
|
~NetworkView()
|
|
|
|
{
|
|
|
|
delete this->help;
|
|
|
|
delete this->menu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void runLogic()
|
|
|
|
{
|
|
|
|
this->menu->runLogic();
|
|
|
|
}
|
|
|
|
|
2010-02-28 11:06:59 +01:00
|
|
|
void pushEvent(event_t ev)
|
2010-01-25 14:01:22 +01:00
|
|
|
{
|
|
|
|
this->menu->pushEvent(ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void viewPushCallback()
|
|
|
|
{
|
|
|
|
this->menu->updateMessages();
|
|
|
|
}
|
|
|
|
|
|
|
|
void draw(SDL_Surface *where)
|
|
|
|
{
|
|
|
|
SDL_Rect dst;
|
|
|
|
|
|
|
|
/* Blit the backgrounds */
|
|
|
|
dst = (SDL_Rect){20,45,300,400};
|
|
|
|
SDL_BlitSurface(Gui::gui->main_menu_bg, NULL, where, &dst);
|
|
|
|
|
|
|
|
dst = (SDL_Rect){350,13,0,0};
|
|
|
|
SDL_BlitSurface(Gui::gui->infobox, NULL, where, &dst);
|
|
|
|
|
|
|
|
this->menu->draw(where, 50, 70, 300, 400);
|
|
|
|
this->help->draw(where, 354, 24, 264, 210);
|
2010-02-28 08:59:36 +01:00
|
|
|
Gui::gui->server_msgs->draw(where);
|
2010-01-25 14:01:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected:
|
|
|
|
NetworkMenu *menu;
|
|
|
|
HelpBox *help;
|
|
|
|
};
|