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

ConnectionDlg.cpp

Go to the documentation of this file.
00001 #include "ConnectionDlg.h"
00002 #include "ClientGui.h"
00003 
00004 // Event Table - Inizio
00005 BEGIN_EVENT_TABLE(ConnectionDlg,wxDialog)
00006         EVT_CLOSE(ConnectionDlg::ConnectionDlgClose)
00007         EVT_BUTTON(OK, ConnectionDlg::OnOk)
00008         EVT_BUTTON(CANCEL, ConnectionDlg::OnCancel)
00009 END_EVENT_TABLE()
00010 // Event Table - Fine
00011 
00012 ConnectionDlg::ConnectionDlg(wxWindow* parent, wxWindowID id,
00013                              const wxString& title, const wxPoint& pos,
00014                              const wxSize& size , long style ,
00015                              const wxString& name)
00016                              : wxDialog(parent, id, title, pos, size, style, name)
00017 {
00018     CreateGUIControls();   // Inizializza e dispone i componenti grafici
00019     wxArrayString param;
00020     param = LoadCfg();  // Alla creazione della finestra viene caricata la
00021                         // configurazione salvata in precedenza.
00022     if(!(param.IsEmpty())){  // Se tale configurazione esiste si popolano i
00023                              // campi nel modo adeguato.
00024         nick->SetValue(param[0]);
00025         this->name->SetValue(param[1]);
00026         serveraddr->SetValue(param[2]);
00027         port->SetValue(param[3]);
00028         timeout->SetValue(param[4]);
00029         long rfc_value;
00030         param[5].ToLong(&rfc_value);
00031         rfcCompliant->SetValue(rfc_value);
00032     }
00033     else{
00034         nick->SetValue(_("Quirck"));
00035         this->name->SetValue(_("Quirck IRC Client"));
00036         serveraddr->SetValue(_("quirck.webfuture.it"));
00037         port->SetValue(_("6667"));
00038         timeout->SetValue(_("3"));
00039         rfcCompliant->SetValue(FALSE);
00040     }    
00041 }  
00042 
00043 ConnectionDlg::~ConnectionDlg()
00044 {
00045 }
00046 
00047 void ConnectionDlg::CreateGUIControls()
00048 {
00049     wxArrayString comboList;
00050     comboList.Add("1");
00051     comboList.Add("2");
00052     comboList.Add("3");
00053     comboList.Add("5");
00054     comboList.Add("10");
00055     SetIcon(wxNullIcon); 
00056     nick = new wxTextCtrl(this, NICK, _(""), wxPoint(110,20),
00057                           wxSize(100, 20), wxTE_RICH2);
00058     name = new wxTextCtrl(this, NAME, _(""), wxPoint(110,50),
00059                           wxSize(100, 20), wxTE_RICH2);
00060     serveraddr = new wxTextCtrl(this, SERVERADDR, _(""), wxPoint(110,80),
00061                                 wxSize(100, 20), wxTE_RICH2);
00062     port = new wxTextCtrl(this, PORT, _(""), wxPoint(110,110),
00063                           wxSize(60, 20), wxTE_RICH2);
00064     timeout = new wxComboBox(this, TIMEOUT,_(""), wxPoint(110,140),
00065                              wxSize(60, 20), 5, comboList.GetStringArray(),
00066                              wxCB_READONLY);
00067     rfcCompliant = new wxCheckBox(this, RFC_COMPLIANT,_("RFC Compliant"),
00068                                   wxPoint(110,170));
00069     
00070     nick_lab = new wxStaticText(this, -1, _("Nick: "), wxPoint(20,20),
00071                                 wxSize(60, 20), wxTE_RICH2);
00072     name_lab = new wxStaticText(this, -1, _("Full Name: "), wxPoint(20,50),
00073                                 wxSize(60, 20), wxTE_RICH2);
00074     serveraddr_lab = new wxStaticText(this, -1, _("Server Address: "),
00075                                       wxPoint(20,80), wxSize(90, 20), wxTE_RICH2);
00076     port_lab = new wxStaticText(this, -1, _("Port: "), wxPoint(20,110),
00077                                 wxSize(60, 20), wxTE_RICH2);
00078     timeout_lab = new wxStaticText(this, -1, _("Timeout: "), wxPoint(20,140),
00079                                    wxSize(60, 20), wxTE_RICH2);
00080     
00081     ok = new wxButton(this,OK,_("Ok"), wxPoint(50, 200),
00082                       wxSize(60, 20), wxBU_EXACTFIT);
00083     cancel = new wxButton(this,CANCEL,_("Annulla"), wxPoint(130, 200),
00084                           wxSize(60, 20) ,wxBU_EXACTFIT);
00085 }
00086 
00087 void ConnectionDlg::ConnectionDlgClose(wxCloseEvent& event)
00088 {
00089     Destroy();  // Distrugge i componenti grafici quando il terminale viene chiuso
00090 }       
00091 void ConnectionDlg::OnCancel(wxCommandEvent& event)
00092 {
00093     Destroy();  // Equivalente all'evento di close
00094 }    
00095 void ConnectionDlg::OnOk(wxCommandEvent& event)
00096 {
00097     wxString nick_s,name_s,serverAddr_s,port_s,timeout_s;
00098     bool rfcCompliant_s;
00099     nick_s = nick->GetValue();
00100     name_s = name->GetValue();
00101     serverAddr_s = serveraddr->GetValue();
00102     port_s = port->GetValue();
00103     timeout_s = timeout->GetValue();
00104     rfcCompliant_s = rfcCompliant->GetValue();
00105     // Crea una connessione con i parametri impostati dall'utente tramite
00106     // l'interfaccia grafica.
00107     ((ClientGui*)GetParent())->CreateConnection(nick_s, name_s, serverAddr_s,
00108                                                 port_s, timeout_s, rfcCompliant_s);
00109     StoreCfg(); //Salva i parametri immessi.
00110     Destroy();  //Distrugge la finestra.
00111 }    
00112 
00113 void ConnectionDlg::StoreCfg()
00114 {
00115     // Salva (nel registro di Windows o in un file di configurazione)
00116     // i parametri di connessione.
00117     wxConfig* cfg = new wxConfig(_("Quirck"));
00118     wxString key = LOCATION2;
00119     cfg->Write(key + _("/nick"), nick->GetValue());
00120     cfg->Write(key + _("/name"), name->GetValue());
00121     cfg->Write(key + _("/serveraddr"), serveraddr->GetValue());
00122     cfg->Write(key + _("/port"), port->GetValue());
00123     cfg->Write(key + _("/timeout"), timeout->GetValue());
00124     
00125 #ifdef _WIN32
00126     // Somma 48 perchè viene salvato come stringa
00127     cfg->Write(key + _("/rfcCompliant"), rfcCompliant->GetValue() + 48);
00128 #else
00129     cfg->Write(key + _("/rfcCompliant"), rfcCompliant->GetValue());
00130 #endif
00131     delete cfg;
00132     
00133 }    
00134 
00135 wxArrayString ConnectionDlg::LoadCfg()
00136 {
00137     // Carica una configurazione salvata precedentemente e ritorna un'array con i vari
00138     // parametri di connessione che verranno impostati nell'interfaccia grafica.
00139     wxConfig* cfg = new wxConfig(_("Quirck"));
00140     wxString key = LOCATION2;
00141     wxArrayString param;
00142     wxString tmp;
00143     if (cfg->Exists(key)){
00144         tmp = cfg->Read(key + _("/nick"), tmp);
00145         param.Add(tmp);
00146         tmp =cfg->Read(key + _("/name"), tmp);
00147         param.Add(tmp);
00148         tmp =cfg->Read(key + _("/serveraddr"), tmp);
00149         param.Add(tmp);
00150         tmp =cfg->Read(key + _("/port"), tmp);
00151         param.Add(tmp);
00152         tmp =cfg->Read(key + _("/timeout"), tmp);
00153         param.Add(tmp);
00154         tmp = cfg->Read(key + _("/rfcCompliant"), tmp);
00155         param.Add(tmp);  
00156     }
00157     delete cfg;
00158     return param;
00159 }    

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