Main Page | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

ClientGui.cpp

Go to the documentation of this file.
00001 #include "ClientGui.h"
00002 #include "ChannelGui.h"
00003 #include "QueryGui.h"
00004 #include "StatusGui.h"
00005 #include "ConnectionDlg.h"
00006 
00007 // Event Table - Inizio
00008 BEGIN_EVENT_TABLE(ClientGui,PARENT_FRAME)
00009     EVT_CLOSE(ClientGui::ClientClose)
00010     EVT_MENU(NEWCONNECTION,ClientGui::OpenConnectionDlg)
00011 END_EVENT_TABLE()
00012 // Event Table - Fine
00013 
00014 ClientGui* ClientGui::clientInstance = 0;  // Singleton
00015 ClientGui* ClientGui::Instance(wxWindow* parent, wxWindowID id,
00016                                const wxString& title, const wxPoint& position,
00017                                const wxSize& size, long style,
00018                                const wxString& name)
00019 {
00020     if(!clientInstance)  // Se l'istanza non esiste...
00021         clientInstance = new ClientGui(parent, id, title,
00022                                        position, size, style, name); //...crea l'istanza
00023     return clientInstance;
00024 }
00025 
00026 ClientGui::ClientGui(wxWindow* parent, wxWindowID id, const wxString& title,
00027                      const wxPoint& position, const wxSize& size, long style,
00028                      const wxString& name) 
00029 : PARENT_FRAME( parent, id, title, position, size, style, name)
00030 { 
00031     CreateGUIControls();
00032 }
00033 
00034 ClientGui::~ClientGui()
00035 {
00036     StoreFrameSize(GetRect());  // Salva le dimensioni del frame
00037     for(unsigned int i = 0; i < openConnection.GetCount(); ++i)  // Distruzione
00038                                                                  // delle connessioni
00039         delete openConnection.Item(i);
00040     openConnection.Clear();  // Dealloca la memoria assegnata al dynarray
00041 }
00042 
00043 void ClientGui::CreateGUIControls()
00044 {
00045         SetSize(DetermineFrameSize());
00046         SetTitle(_("QUIrCK"));
00047 
00048         #ifdef _WIN32
00049         SetIcon(wxICON(A));  // Imposta l'icona 'A' definita nel file di risorse
00050         #else
00051         #include "res/Quirck_Icon.xpm"
00052         SetIcon(wxIcon(Quirck_Icon_xpm) );
00053         #endif
00054         clientMenuBar = new wxMenuBar();  // Crea la menubar
00055         wxMenu *menuFile = new wxMenu;  // Crea il menu
00056         
00057     // Inserisce la voce nel menu
00058         menuFile->Append(NEWCONNECTION, _("&Nuova Connessione\tCtrl+N"));
00059 
00060         clientMenuBar->Append(menuFile, _("&File"));  // Inserisce il menu nella menubar
00061         SetMenuBar(clientMenuBar);
00062 }
00063 
00064 void ClientGui::ClientClose(wxCloseEvent& event)
00065 {
00066     Destroy();  // Distrugge i componenti grafici quando il terminale viene chiuso
00067 }
00068 
00069 void ClientGui::OpenConnectionDlg(wxCommandEvent& event)
00070 {
00071     ConnectionDlg *newcon = new ConnectionDlg(this);  // Visualizza un nuovo
00072                                                       // dialog di connessione
00073     newcon->Show(TRUE);
00074 
00075 }
00076 
00077 void ClientGui::CreateConnection(wxString nick, wxString name,
00078                                  wxString serverAddr, wxString port,
00079                                  wxString timeout, bool rfcCompliant)
00080 {
00081     long port_n, timeout_n;
00082     port.ToLong(&port_n);
00083     timeout.ToLong(&timeout_n);
00084     Connessione* conn = new Connessione(serverAddr, port_n, timeout_n, rfcCompliant);
00085     
00086     openConnection.Add(conn);  // Inserisce la connessione nell'array di connessioni
00087     conn->Connect();  // Si connette
00088     
00089     // Utilizza il protocollo IRC per impostare il nickname e i dettagli dell'utente
00090     wxString reg_nick, reg_user;
00091     reg_nick = _("NICK ");
00092     reg_nick.Append(nick);
00093     reg_user = _("USER Quirck \"\" \"\" :");
00094     reg_user.Append(name);
00095 
00096     conn->sendCommand(reg_nick);
00097     conn->sendCommand(reg_user);
00098 }    
00099 
00100 void ClientGui::DeleteConnection(Connessione* connection)
00101 {
00102     openConnection.Remove(connection);  // Elimina la connessione dall'array di
00103                                         // connessioni
00104     delete connection;  // Invoca la distruzione della connessione
00105 
00106     #ifdef TESTING
00107     if(openConnection.IsEmpty())
00108         wxMessageBox(_("Non ci sono pił Connessioni!"), _("Informazione!"));
00109     #endif
00110 }
00111 
00112 // Salva le impostazioni grafiche della finestra
00113 
00114 wxRect ClientGui::DetermineFrameSize(wxConfig* config)
00115 {
00116     const int minFrameWidth = CLIENTWIDTH;
00117     const int minFrameHeight = CLIENTHEIGHT;
00118     wxSize scr = wxGetDisplaySize();
00119 
00120     wxRect rect;
00121     wxConfig* cfg = config;
00122     if (!config) cfg = new wxConfig(_("Quirck"));
00123     wxString key = LOCATION;
00124     if (cfg->Exists(key)){
00125         rect.x = cfg->Read(key + _("/") + LOCATION_X, rect.x);
00126         rect.y = cfg->Read(key + _("/") + LOCATION_Y, rect.y);
00127         rect.width = cfg->Read(key + _("/") + LOCATION_W, rect.width);
00128         rect.height = cfg->Read(key + _("/") + LOCATION_H, rect.height);
00129     }
00130     
00131     if (!config) delete cfg;
00132 
00133     // Verifica delle dimensioni
00134     rect.x = wxMin(abs(rect.x), (scr.x - minFrameWidth));
00135     rect.y = wxMin(abs(rect.y), (scr.y - minFrameHeight));
00136     rect.width = wxMax(abs(rect.width), (minFrameWidth));
00137     rect.width = wxMin(abs(rect.width), (scr.x - rect.x));
00138     rect.height = wxMax(abs(rect.height), (minFrameHeight));
00139     rect.height = wxMin(abs(rect.height), (scr.y - rect.y));
00140 
00141     return rect;
00142 }
00143 
00144 void ClientGui::StoreFrameSize(wxRect rect, wxConfig* config)
00145 {
00146     wxConfig* cfg = config;
00147     if (!config) cfg = new wxConfig(_("Quirck"));
00148     wxString key = LOCATION;
00149     cfg->Write(key + _("/") + LOCATION_X, rect.x);
00150     cfg->Write(key + _("/") + LOCATION_Y, rect.y);
00151     cfg->Write(key + _("/") + LOCATION_W, rect.width);
00152     cfg->Write(key + _("/") + LOCATION_H, rect.height);
00153     if (!config) delete cfg;
00154 }
00155 

Generated on Thu Dec 2 16:51:42 2004 for Quirck by  doxygen 1.3.9.1