00001 #include "ChannelGui.h"
00002 #include "Connessione.h"
00003
00005
00007
00008
00009 BEGIN_EVENT_TABLE(ChannelGui,CHILD_FRAME)
00010 EVT_LISTBOX_DCLICK(USERLIST,ChannelGui::OnDoubleClick)
00011 EVT_TEXT_ENTER(COMMAND_LINE,TerminalGui::EnterCommand)
00012 EVT_CLOSE(ChannelGui::ChannelGuiClose)
00013 END_EVENT_TABLE()
00014
00015
00016 ChannelGui::ChannelGui(Connessione* connection, PARENT_FRAME* parent,
00017 wxWindowID id, const wxString& title,
00018 const wxPoint& position, const wxSize& size, long style,
00019 const wxString& name)
00020 : TerminalGui(connection, parent, id, title, position, size, style, name){
00021
00022
00023
00024 T_LOCATION = _("TerminalGuiPrefs/ChannelGui");
00025 userlist = new wxListBox(this, USERLIST, wxPoint(0,0), wxSize(LISTWIDTH,
00026 TERMINALHEIGHT-20), 0, NULL, wxLB_SORT);
00027 SetLayout();
00028 this->SetSize(DetermineFrameSize());
00029 active = false;
00030 }
00031
00032 void ChannelGui::SetLayout(){
00033 FONT_BOLD;
00034 userlist->SetFont(FONT);
00035
00036 wxBoxSizer *columnsizer = new wxBoxSizer(wxVERTICAL);
00037 wxBoxSizer *rowsizer = new wxBoxSizer(wxHORIZONTAL);
00038
00039 rowsizer->Add(viewer, 1, wxEXPAND);
00040 rowsizer->Add(userlist, 0, wxEXPAND);
00041
00042 columnsizer->Add(rowsizer, 1, wxEXPAND);
00043 columnsizer->Add(commandline, 0, wxEXPAND);
00044
00045 SetAutoLayout(TRUE);
00046 SetSizer(columnsizer);
00047
00048 columnsizer->Fit(this);
00049 columnsizer->SetSizeHints(this);
00050 }
00051
00052
00053 void ChannelGui::receiveMsg(wxString message, wxTextAttr style)
00054 {
00055
00056
00057 wxString mynick = connessione->GetMyNick();
00058 if(message.Contains(" " + mynick + " ") || message.Contains("<" + mynick + ">") ||
00059 message.StartsWith( mynick + " ") || message.Contains(" " + mynick + "\n") ){
00060 viewer->SetDefaultStyle(STYLE_RED);
00061 }
00062 else
00063 viewer->SetDefaultStyle(style);
00064
00065 viewer->AppendText(message);
00066 viewer->SetDefaultStyle(STYLE_DEFAULT);
00067
00068 }
00069
00070 void ChannelGui::ChannelGuiClose(wxCloseEvent& event)
00071 {
00072
00073
00074 wxString cmd = _("PART ");
00075 cmd.Append(GetName());
00076 connessione->sendCommand(cmd);
00077 connessione->DeleteTerminal(GetName());
00078 }
00079
00080 void ChannelGui::OnDoubleClick(wxCommandEvent& event)
00081 {
00082
00083
00084 wxString nick = userlist->GetStringSelection();
00085
00086 char specialChar = nick.GetChar(0);
00087 if(specialChar == '@' || specialChar == '+' || specialChar == '%' ){
00088
00089 nick = nick.Mid(1);
00090 }
00091 if(!connessione->TerminalExists(nick))
00092
00093 connessione->CreateQuery(nick);
00094 else{
00095
00096 connessione->GetTerminal(nick)->SetFocus();
00097
00098 connessione->GetTerminal(nick)->Maximize(false);
00099 }
00100 }
00101
00103
00105
00106 void ChannelGui::setNickList(wxString lista)
00107 {
00108 wxStringTokenizer tkz(lista, ' ');
00109 wxString nick;
00110 while(tkz.HasMoreTokens())
00111 userlist->Append(tkz.GetNextToken());
00112
00113
00114 wxString tmp = GetName();
00115 tmp << _(" [") << userlist->GetCount() << _("]");
00116 SetTitle(tmp);
00117 }
00118
00119 void ChannelGui::addUser(wxString nome){
00120 userlist->Append(nome);
00121 receiveMsg(nome+_(" è entrato nel canale\n"), STYLE_GREEN);
00122
00123
00124 wxString tmp = GetName();
00125 tmp << _(" [") << userlist->GetCount() << _("]");
00126 SetTitle(tmp);
00127 }
00128
00129 void ChannelGui::removeUser(wxString nome){
00130 int x;
00131
00132 if ((x=userlist->FindString(nome)) == -1)
00133 if ((x=userlist->FindString(_("@")+nome))== -1)
00134 if ((x=userlist->FindString(_("%")+nome))== -1)
00135 x=userlist->FindString(_("+")+nome);
00136
00137 if (x!=-1) userlist->Delete(x);
00138
00139 wxString tmp = GetName();
00140 tmp << _(" [") << userlist->GetCount() << _("]");
00141 SetTitle(tmp);
00142 }
00143
00144 bool ChannelGui::changeNick(wxString oldNick, wxString newNick)
00145 {
00146 bool ritorno=false;
00147 if(userlist->FindString(oldNick)!=-1)
00148 {
00149 ritorno=true;
00150 userlist->Delete(userlist->FindString(oldNick));
00151 userlist->Append(newNick);
00152 }
00153 else
00154 {
00155 if(userlist->FindString(_("@")+oldNick)!=-1)
00156 {
00157 ritorno=true;
00158 userlist->Delete(userlist->FindString(_("@")+oldNick));
00159 userlist->Append(_("@")+newNick);
00160 }
00161 else
00162 {
00163 if(userlist->FindString(_("+")+oldNick)!=-1)
00164 {
00165 ritorno=true;
00166 userlist->Delete(userlist->FindString(_("+")+oldNick));
00167 userlist->Append(_("+")+newNick);
00168 }
00169 else
00170 {
00171 if(userlist->FindString(_("%")+oldNick)!=-1)
00172 {
00173 ritorno=true;
00174 userlist->Delete(userlist->FindString(_("%")+oldNick));
00175 userlist->Append(_("%")+newNick);
00176 };
00177 };
00178 };
00179 };
00180
00181
00182
00183 return ritorno;
00184
00185 }
00186
00187
00188 void ChannelGui::opUser(wxString nome)
00189 {
00190 int x;
00191
00192 if ((x=userlist->FindString(nome)) == -1)
00193 if ((x=userlist->FindString(_("%")+nome))== -1)
00194 x=userlist->FindString(_("+")+nome);
00195
00196
00197 if (x!=-1) {
00198 userlist->Delete(x);
00199 userlist->Append(_("@")+nome);
00200 };
00201
00202
00203 }
00204
00205 void ChannelGui::deopUser(wxString nome)
00206 {
00207 int x;
00208
00209 if ((x=userlist->FindString(_("@")+nome))!= -1)
00210 {
00211
00212 userlist->Delete(x);
00213 userlist->Append(nome);
00214 };
00215
00216
00217 };
00218
00219 void ChannelGui::voiceUser(wxString nome)
00220 {
00221 int x;
00222 if ((x=userlist->FindString(nome)) != -1)
00223 {
00224
00225 userlist->Delete(x);
00226 userlist->Append(_("+")+nome);
00227 };
00228
00229
00230 }
00231
00232 void ChannelGui::devoiceUser(wxString nome)
00233 {
00234 int x;
00235
00236 if ((x=userlist->FindString(_("+")+nome))!= -1)
00237 {
00238
00239 userlist->Delete(x);
00240 userlist->Append(nome);
00241 };
00242
00243
00244 };
00245
00246 void ChannelGui::halfopUser(wxString nome)
00247 {
00248 int x;
00249
00250 if ((x=userlist->FindString(nome)) == -1)
00251 x=userlist->FindString(_("+")+nome);
00252
00253
00254 if (x!=-1) {
00255 userlist->Delete(x);
00256 userlist->Append(_("%")+nome);
00257 };
00258
00259
00260 }
00261
00262 void ChannelGui::dehalfopUser(wxString nome)
00263 {
00264 int x;
00265
00266 if ((x=userlist->FindString(_("%")+nome))!= -1)
00267 {
00268
00269 userlist->Delete(x);
00270 userlist->Append(nome);
00271 };
00272
00273
00274 };
00275
00276
00277 void ChannelGui::setTopic(wxString topic) {
00278 Topic=topic;
00279 receiveMsg((_("Il topic del canale è: ")+Topic), STYLE_BLUE);
00280 }
00281
00282 wxString ChannelGui::getTopic() {
00283 return Topic;
00284
00285 }
00286
00287 void ChannelGui::setModes(wxString input)
00288 {
00289
00290 bool onSet=false, onUnset=false;
00291 unsigned int i=0;
00292 char p;
00293
00294 while (i<input.Len()) {
00295 p=input.GetChar(i++);
00296 switch (p)
00297 {
00298 case '+':
00299 onSet=true;
00300 onUnset=false;
00301 break;
00302 case '-':
00303 onSet=false;
00304 onUnset=true;
00305 break;
00306
00307
00308 case 'm':
00309 if (onSet) modes[0]='m';
00310 if (onUnset) modes[0]='\0';
00311 break;
00312 case 'n':
00313 if (onSet) modes[1]='n';
00314 if (onUnset) modes[1]='\0';
00315 break;
00316 case 't':
00317 if (onSet) modes[2]='t';
00318 if (onUnset) modes[2]='\0';
00319 break;
00320 case 'r':
00321 if (onSet) modes[3]='r';
00322 if (onUnset) modes[3]='\0';
00323 break;
00324 case 'p':
00325 if (onSet) modes[4]='p';
00326 if (onUnset) modes[4]='\0';
00327 break;
00328 case 's':
00329 if (onSet) modes[5]='s';
00330 if (onUnset) modes[5]='\0';
00331 break;
00332 case 'k':
00333 if (onSet) modes[5]='k';
00334 if (onUnset) modes[5]='\0';
00335 break;
00336 case 'i':
00337 if (onSet) modes[6]='i';
00338 if (onUnset) modes[6]='\0';
00339 break;
00340 } ;
00341
00342 } ;
00343
00344 }
00345
00346 wxString ChannelGui::getModes()
00347 {
00348 wxString modi;
00349 for (int i=0; i<8; i++)
00350 if (modes[i]) modi+=modes[i];
00351
00352 return modi;
00353 }
00354
00355 bool ChannelGui::getMode(int index)
00356 {
00357 if (modes[index])
00358 return true;
00359 else
00360 return false;
00361 }
00362
00363 bool ChannelGui::IsActive() { return active; }
00364
00365 void ChannelGui::SetActive() { active = true; }
00366