]> code.citadel.org Git - citadel.git/commitdiff
Initial revision
authorArt Cancro <ajc@citadel.org>
Fri, 19 Feb 1999 19:25:46 +0000 (19:25 +0000)
committerArt Cancro <ajc@citadel.org>
Fri, 19 Feb 1999 19:25:46 +0000 (19:25 +0000)
daphne/Makefile [new file with mode: 0644]
daphne/citclient.cpp [new file with mode: 0644]
daphne/citclient.hpp [new file with mode: 0644]
daphne/daphne [new file with mode: 0755]
daphne/main.cpp [new file with mode: 0644]
daphne/userlogin.cpp [new file with mode: 0644]
daphne/userlogin.hpp [new file with mode: 0644]

diff --git a/daphne/Makefile b/daphne/Makefile
new file mode 100644 (file)
index 0000000..3e80ce7
--- /dev/null
@@ -0,0 +1,14 @@
+CFLAGS=`wx-config --cflags`
+LFLAGS=`wx-config --libs`
+
+daphne: main.o citclient.o userlogin.o
+       c++ main.o citclient.o userlogin.o $(LFLAGS) -o daphne
+
+main.o: main.cpp
+       c++ -c $(CFLAGS) main.cpp
+
+citclient.o: citclient.cpp
+       c++ -c $(CFLAGS) citclient.cpp
+
+userlogin.o: userlogin.cpp
+       c++ -c $(CFLAGS) userlogin.cpp
diff --git a/daphne/citclient.cpp b/daphne/citclient.cpp
new file mode 100644 (file)
index 0000000..dd034fb
--- /dev/null
@@ -0,0 +1,110 @@
+#include <ctype.h>
+#include <string.h>
+
+#include <wx/wx.h>
+
+#include "citclient.hpp"
+
+
+// methods
+
+// Attach to the Citadel server
+int CitClient::attach(const wxString& host, const wxString& port) {
+       wxString ServerReady;
+
+       if (sock.IsConnected())
+               sock.Close();
+
+       addr.Hostname(host);
+       addr.Service(port);
+       sock.SetNotify(0);
+       sock.Connect(addr, TRUE);
+       if (sock.IsConnected()) {
+               serv_gets(ServerReady);
+               // FIX ... add check for not allowed to log in
+               return(0);
+       }
+       else return(1);
+}
+
+
+
+// constructor
+CitClient::CitClient(void) {
+  wxSocketHandler::Master();
+  sock.SetFlags(wxSocketBase::WAITALL);
+  wxSocketHandler::Master().Register(&sock);
+  sock.SetNotify(wxSocketBase::REQ_LOST);
+}
+
+
+
+// destructor
+CitClient::~CitClient(void) {
+
+       // Be nice and log out from the server if it's still connected
+       detach();
+}
+
+void CitClient::detach(void) {
+       wxString buf;
+
+       if (sock.IsConnected()) {
+               serv_puts("QUIT");
+               serv_gets(buf);
+               sock.Close();
+       }
+}
+
+
+// Is this client connected?  Simply return the IsConnected status of sock.
+bool CitClient::IsConnected(void) {
+       return sock.IsConnected();
+}
+
+
+
+// Read a line of text from the server
+void CitClient::serv_gets(wxString& buf) {
+       char charbuf[2];
+
+       do {
+               sock.Read(charbuf, 1);
+               if (isprint(charbuf[0])) buf.Append(charbuf[0], 1);
+       } while(isprint(charbuf[0]));
+       printf("<%s\n", (const char *)buf);
+}
+
+
+// Write a line of text to the server
+void CitClient::serv_puts(wxString buf) {
+       printf(">%s\n", (const char *)buf);
+       sock.Write(buf, strlen(buf));
+       sock.Write("\n", 1);
+}
+
+// Server transaction (returns first digit of server response code)
+int CitClient::serv_trans(
+                       wxString& command,
+                       wxString& response,
+                       wxStringList& xferbuf
+                       ) {
+
+       int first_digit;
+
+       serv_puts(command);
+       serv_gets(response);
+       first_digit = (response.GetChar(0)) - '0';
+       return first_digit;
+}
+
+// Shorter forms of serv_trans()
+int CitClient::serv_trans(wxString& command, wxString& response) {
+       wxStringList junklist;
+       return serv_trans(command, response, junklist);
+}
+
+int CitClient::serv_trans(wxString& command) {
+       wxString junkbuf;
+       return serv_trans(command, junkbuf);
+}
diff --git a/daphne/citclient.hpp b/daphne/citclient.hpp
new file mode 100644 (file)
index 0000000..bc5ceae
--- /dev/null
@@ -0,0 +1,24 @@
+#include <wx/socket.h>
+
+class CitClient {
+public:
+       CitClient(void);
+       ~CitClient(void);
+       int attach(const wxString& host, const wxString& port);
+       void detach(void);
+       bool IsConnected(void);
+       void serv_gets(wxString& buf);
+       void serv_puts(wxString buf);
+       int CitClient::serv_trans(
+                       wxString& command,
+                       wxString& response,
+                       wxStringList& xferbuf
+                        );
+       int CitClient::serv_trans(wxString& command, wxString& response);
+       int CitClient::serv_trans(wxString& command);
+private:
+       wxSocketClient sock;
+       wxIPV4address addr;
+};
+
+
diff --git a/daphne/daphne b/daphne/daphne
new file mode 100755 (executable)
index 0000000..3dce601
Binary files /dev/null and b/daphne/daphne differ
diff --git a/daphne/main.cpp b/daphne/main.cpp
new file mode 100644 (file)
index 0000000..bbd0c0e
--- /dev/null
@@ -0,0 +1,243 @@
+/////////////////////////////////////////////////////////////////////////////
+// Name:        main.cpp
+// Purpose:     Main screen type thing
+/////////////////////////////////////////////////////////////////////////////
+
+// ============================================================================
+// declarations
+// ============================================================================
+
+
+#include <stdio.h>
+#include <wx/wx.h>
+#include <wx/socket.h>
+
+#include "citclient.hpp"
+#include "userlogin.hpp"
+
+// ----------------------------------------------------------------------------
+// private classes
+// ----------------------------------------------------------------------------
+
+// Define a new application type, each program should derive a class from wxApp
+class MyApp : public wxApp
+{
+public:
+    // override base class virtuals
+    // ----------------------------
+
+    // this one is called on application startup and is a good place for the app
+    // initialization (doing it here and not in the ctor allows to have an error
+    // return: if OnInit() returns false, the application terminates)
+    virtual bool OnInit();
+};
+
+// Define a new frame type: this is going to be our main frame
+class MyFrame : public wxFrame
+{
+public:
+    // constructor(s)
+    MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size);
+
+       // event handlers (these functions should _not_ be virtual)
+       void OnQuit(wxCommandEvent& event);
+       void OnAbout(wxCommandEvent& event);
+       void OnDoCmd(wxCommandEvent& event);
+       void OnConnect(wxCommandEvent& event);
+
+private:
+       wxTextCtrl *sendcmd;
+       wxTextCtrl *recvcmd;
+       wxButton *do_cmd;
+       // any class wishing to process wxWindows events must use this macro
+       DECLARE_EVENT_TABLE()
+};
+
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+// IDs for the controls and the menu commands
+enum
+{
+       IG_Quit,
+       IG_About,
+       IG_Text,
+       MENU_CONNECT,
+       BUTTON_DO_CMD
+};
+
+// ----------------------------------------------------------------------------
+// event tables and other macros for wxWindows
+// ----------------------------------------------------------------------------
+
+// the event tables connect the wxWindows events with the functions (event
+// handlers) which process them. It can be also done at run-time, but for the
+// simple menu events like this the static method is much simpler.
+BEGIN_EVENT_TABLE(     MyFrame, wxFrame)
+       EVT_MENU(       IG_Quit,                MyFrame::OnQuit)
+       EVT_MENU(       IG_About,               MyFrame::OnAbout)
+       EVT_MENU(       MENU_CONNECT,           MyFrame::OnConnect)
+       EVT_BUTTON(     BUTTON_DO_CMD,          MyFrame::OnDoCmd)
+END_EVENT_TABLE()
+
+// Create a new application object: this macro will allow wxWindows to create
+// the application object during program execution (it's better than using a
+// static object for many reasons) and also declares the accessor function
+// wxGetApp() which will return the reference of the right type (i.e. MyApp and
+// not wxApp)
+IMPLEMENT_APP(MyApp)
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+wxRadioBox *DevSelect;
+wxSlider *ndims;
+CitClient *citadel;
+
+// ----------------------------------------------------------------------------
+// the application class
+// ----------------------------------------------------------------------------
+
+// `Main program' equivalent: the program execution "starts" here
+bool MyApp::OnInit()
+{
+
+       citadel = new CitClient();
+
+    // Create the main application window
+    MyFrame *frame = new MyFrame("Daphne",
+                                 wxPoint(10, 10), wxSize(600, 450));
+
+    // Show it and tell the application that it's our main window
+    // @@@ what does it do exactly, in fact? is it necessary here?
+    frame->Show(TRUE);
+    SetTopWindow(frame);
+
+    // success: wxApp::OnRun() will be called which will enter the main message
+    // loop and the application will run. If we returned FALSE here, the
+    // application would exit immediately.
+    return TRUE;
+}
+
+// ----------------------------------------------------------------------------
+// main frame
+// ----------------------------------------------------------------------------
+
+// frame constructor
+MyFrame::MyFrame(const wxString& title, const wxPoint& pos, const wxSize& size)
+       : wxFrame((wxFrame *)NULL, -1, title, pos, size)
+{
+    // set the frame icon
+    /* SetIcon(wxICON(mondrian)); */
+
+       // create a menu bar
+       wxMenu *menuFile = new wxMenu;
+       menuFile->Append(MENU_CONNECT, "&Connect");
+       menuFile->AppendSeparator(); 
+       menuFile->Append(IG_Quit, "E&xit");
+
+       wxMenu *menuHelp = new wxMenu;
+       menuHelp->Append(IG_About, "&About...");
+
+       // now append the freshly created menu to the menu bar...
+       wxMenuBar *menuBar = new wxMenuBar;
+       menuBar->Append(menuFile, "&File");
+       menuBar->Append(menuHelp, "&Help");
+
+    // ... and attach this menu bar to the frame
+    SetMenuBar(menuBar);
+
+    // create a status bar just for fun (by default with 1 pane only)
+    CreateStatusBar(1);
+    SetStatusText("Not connected");
+
+    wxPanel *panel = new wxPanel(this);
+
+       sendcmd = new wxTextCtrl(
+               panel,
+               -1,
+               "",
+               wxPoint(10,10),
+               wxSize(300,30),
+               0, // no style
+               wxDefaultValidator,
+               "sendcmd"
+               );
+
+       recvcmd = new wxTextCtrl(
+               panel,
+               -1,
+               "",
+               wxPoint(10,100),
+               wxSize(300,30),
+               0, // no style
+               wxDefaultValidator,
+               "sendcmd"
+               );
+
+       do_cmd = new wxButton(
+               panel,
+               BUTTON_DO_CMD,
+               "Send command",
+               wxPoint(350,10),
+               wxSize(100,30),
+               0L,
+               wxDefaultValidator,
+               "do_cmd"
+               );
+
+}
+
+
+// event handlers
+
+void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
+{
+       // Kill the client connection
+       citadel->detach();
+
+       // TRUE is to force the frame to close
+       Close(TRUE);
+}
+
+void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
+{
+    wxString msg;
+    msg.Printf(
+       "This is the development version of a project code-named 'Daphne',\n"
+       "a GUI client for the Citadel/UX groupware system.  It is being\n"
+       "developed using the wxWindows toolkit, and therefore should be\n"
+       "easy to port to Linux, Windows, and eventually Macintosh."
+       );
+    wxMessageBox(msg, "Daphne", wxOK | wxICON_INFORMATION, this);
+}
+
+void MyFrame::OnDoCmd(wxCommandEvent& whichbutton) {
+       int retval;
+       wxString sendbuf;
+       wxString retbuf;
+
+       sendbuf = sendcmd->GetLineText(0);
+       
+       retval = citadel->serv_trans(sendbuf, retbuf);
+       recvcmd->SetValue(retbuf);
+}
+
+void MyFrame::OnConnect(wxCommandEvent& unused) {
+       int retval;
+
+       if (citadel->IsConnected()) {
+               wxMessageBox("You are already connected to a Citadel server.",
+                       "Oops!");
+       } else {
+               retval = citadel->attach("uncnsrd.mt-kisco.ny.us", "citadel");
+               if (retval == 0) {
+                       SetStatusText("** connected **");
+                       new UserLogin(citadel);
+               } else {
+                       wxMessageBox("Could not connect to server.", "Error");
+               }
+       }
+}
diff --git a/daphne/userlogin.cpp b/daphne/userlogin.cpp
new file mode 100644 (file)
index 0000000..5d22d23
--- /dev/null
@@ -0,0 +1,118 @@
+// ============================================================================
+// declarations
+// ============================================================================
+
+
+#include <wx/wx.h>
+#include "citclient.hpp"
+#include "userlogin.hpp"
+
+// ----------------------------------------------------------------------------
+// private classes
+// ----------------------------------------------------------------------------
+
+// userlogin is the frame for logging in.
+
+// ----------------------------------------------------------------------------
+// constants
+// ----------------------------------------------------------------------------
+
+// IDs for the controls and the menu commands
+enum
+{
+       BUTTON_LOGIN,
+       BUTTON_NEWUSER,
+       BUTTON_EXIT
+};
+
+// ----------------------------------------------------------------------------
+// event tables and other macros for wxWindows
+// ----------------------------------------------------------------------------
+
+// the event tables connect the wxWindows events with the functions (event
+// handlers) which process them. It can be also done at run-time, but for the
+// simple menu events like this the static method is much simpler.
+BEGIN_EVENT_TABLE(     UserLogin, wxFrame)
+       EVT_BUTTON(     BUTTON_LOGIN,           UserLogin::OnButtonPressed)
+END_EVENT_TABLE()
+
+// ============================================================================
+// implementation
+// ============================================================================
+
+
+// ----------------------------------------------------------------------------
+// the application class
+// ----------------------------------------------------------------------------
+
+// frame constructor
+UserLogin::UserLogin(CitClient *sock)
+       : wxFrame((wxFrame *)NULL, -1, "", wxPoint(50,50), wxSize(500,350)) {
+
+    // set the frame icon
+    /* SetIcon(wxICON(mondrian)); */
+
+       panel = new wxPanel(this);
+
+       username = new wxTextCtrl(
+               panel,
+               -1,
+               "",
+               wxPoint(10,10),
+               wxSize(300,30),
+               0, // no style
+               wxDefaultValidator,
+               "sendcmd"
+               );
+
+       password = new wxTextCtrl(
+               panel,
+               -1,
+               "",
+               wxPoint(10,100),
+               wxSize(300,30),
+               0, // no style
+               wxDefaultValidator,
+               "sendcmd"
+               );
+
+       login_button = new wxButton(
+               panel,
+               BUTTON_LOGIN,
+               "Login",
+               wxPoint(10,300),
+               wxSize(100,30),
+               0L,
+               wxDefaultValidator,
+               "login_button"
+               );
+
+       newuser_button = new wxButton(
+               panel,
+               BUTTON_NEWUSER,
+               "New user",
+               wxPoint(120,300),
+               wxSize(100,30),
+               0L,
+               wxDefaultValidator,
+               "newuser_button"
+               );
+
+       exit_button = new wxButton(
+               panel,
+               BUTTON_EXIT,
+               "Exit",
+               wxPoint(230,300),
+               wxSize(100,30),
+               0L,
+               wxDefaultValidator,
+               "exit_button"
+               );
+
+       Show(TRUE);
+}
+
+
+
+void UserLogin::OnButtonPressed(wxCommandEvent& whichbutton) {
+}
diff --git a/daphne/userlogin.hpp b/daphne/userlogin.hpp
new file mode 100644 (file)
index 0000000..03de34b
--- /dev/null
@@ -0,0 +1,15 @@
+// userlogin is the frame for logging in.
+class UserLogin : public wxFrame {
+public:
+       UserLogin(CitClient *sock);
+       int do_login();
+private:
+       wxPanel *panel;
+       wxTextCtrl *username;
+       wxTextCtrl *password;
+       wxButton *login_button;
+       wxButton *newuser_button;
+       wxButton *exit_button;
+       void OnButtonPressed(wxCommandEvent& whichbutton);
+       DECLARE_EVENT_TABLE()
+};