src/eric7/Network/IRC/IrcNetworkManager.py

branch
eric7
changeset 10428
a071d4065202
parent 10373
093dcebe5ecb
child 10439
21c28b0f9e41
equal deleted inserted replaced
10427:3733e2b23cf7 10428:a071d4065202
33 33
34 def __init__(self, name): 34 def __init__(self, name):
35 """ 35 """
36 Constructor 36 Constructor
37 37
38 @param name name of the identity (string) 38 @param name name of the identity
39 @type str
39 """ 40 """
40 super().__init__() 41 super().__init__()
41 42
42 self.__name = name 43 self.__name = name
43 self.__realName = "" 44 self.__realName = ""
54 55
55 def save(self, settings): 56 def save(self, settings):
56 """ 57 """
57 Public method to save the identity data. 58 Public method to save the identity data.
58 59
59 @param settings reference to the settings object (QSettings) 60 @param settings reference to the settings object
61 @type QSettings
60 """ 62 """
61 # no need to save the name because that is the group key 63 # no need to save the name because that is the group key
62 settings.setValue("Ident", self.__ident) 64 settings.setValue("Ident", self.__ident)
63 settings.setValue("RealName", self.__realName) 65 settings.setValue("RealName", self.__realName)
64 settings.setValue("NickNames", self.__nickNames) 66 settings.setValue("NickNames", self.__nickNames)
71 73
72 def load(self, settings): 74 def load(self, settings):
73 """ 75 """
74 Public method to load the identity data. 76 Public method to load the identity data.
75 77
76 @param settings reference to the settings object (QSettings) 78 @param settings reference to the settings object
79 @type QSettings
77 """ 80 """
78 self.__ident = settings.value("Ident", OSUtilities.getUserName()) 81 self.__ident = settings.value("Ident", OSUtilities.getUserName())
79 self.__realName = settings.value("RealName", "") 82 self.__realName = settings.value("RealName", "")
80 self.__nickNames = Preferences.toList(settings.value("NickNames", [])) 83 self.__nickNames = Preferences.toList(settings.value("NickNames", []))
81 self.__serviceName = settings.value("ServiceName", "") 84 self.__serviceName = settings.value("ServiceName", "")
95 98
96 def setName(self, name): 99 def setName(self, name):
97 """ 100 """
98 Public method to set the identity name. 101 Public method to set the identity name.
99 102
100 @param name identity name (string) 103 @param name identity name
104 @type str
101 """ 105 """
102 self.__name = name 106 self.__name = name
103 107
104 def getName(self): 108 def getName(self):
105 """ 109 """
106 Public method to get the identity name. 110 Public method to get the identity name.
107 111
108 @return identity name (string) 112 @return identity name
113 @rtype str
109 """ 114 """
110 return self.__name 115 return self.__name
111 116
112 def setIdent(self, name): 117 def setIdent(self, name):
113 """ 118 """
114 Public method to set the real identity name. 119 Public method to set the real identity name.
115 120
116 @param name real identity name (string) 121 @param name real identity name
122 @type str
117 """ 123 """
118 self.__ident = name 124 self.__ident = name
119 125
120 def getIdent(self): 126 def getIdent(self):
121 """ 127 """
122 Public method to get the real identity name. 128 Public method to get the real identity name.
123 129
124 @return real identity name (string) 130 @return real identity name
131 @rtype str
125 """ 132 """
126 return self.__ident 133 return self.__ident
127 134
128 def setRealName(self, name): 135 def setRealName(self, name):
129 """ 136 """
130 Public method to set the real name of the identity. 137 Public method to set the real name of the identity.
131 138
132 @param name real name (string) 139 @param name real name
140 @type str
133 """ 141 """
134 self.__realName = name 142 self.__realName = name
135 143
136 def getRealName(self): 144 def getRealName(self):
137 """ 145 """
138 Public method to get the real name. 146 Public method to get the real name.
139 147
140 @return real name (string) 148 @return real name
149 @rtype str
141 """ 150 """
142 return self.__realName 151 return self.__realName
143 152
144 def setNickNames(self, names): 153 def setNickNames(self, names):
145 """ 154 """
146 Public method to set the nick names of the identity. 155 Public method to set the nick names of the identity.
147 156
148 @param names nick names (list of string) 157 @param names nick names
158 @type list of str
149 """ 159 """
150 self.__nickNames = names[:] 160 self.__nickNames = names[:]
151 161
152 def getNickNames(self): 162 def getNickNames(self):
153 """ 163 """
154 Public method to get the nick names. 164 Public method to get the nick names.
155 165
156 @return nick names (list of string) 166 @return nick names
167 @rtype list of str
157 """ 168 """
158 return self.__nickNames 169 return self.__nickNames
159 170
160 def setServiceName(self, name): 171 def setServiceName(self, name):
161 """ 172 """
162 Public method to set the service name of the identity used for 173 Public method to set the service name of the identity used for
163 identification. 174 identification.
164 175
165 @param name service name (string) 176 @param name service name
177 @type str
166 """ 178 """
167 self.__serviceName = name 179 self.__serviceName = name
168 180
169 def getServiceName(self): 181 def getServiceName(self):
170 """ 182 """
171 Public method to get the service name of the identity used for 183 Public method to get the service name of the identity used for
172 identification. 184 identification.
173 185
174 @return service name (string) 186 @return service name
187 @rtype str
175 """ 188 """
176 return self.__serviceName 189 return self.__serviceName
177 190
178 def setPassword(self, password): 191 def setPassword(self, password):
179 """ 192 """
180 Public method to set a new password. 193 Public method to set a new password.
181 194
182 @param password password to set (string) 195 @param password password to set
196 @type str
183 """ 197 """
184 self.__password = pwConvert(password, encode=True) 198 self.__password = pwConvert(password, encode=True)
185 199
186 def getPassword(self): 200 def getPassword(self):
187 """ 201 """
188 Public method to get the password. 202 Public method to get the password.
189 203
190 @return password (string) 204 @return password
205 @rtype str
191 """ 206 """
192 return pwConvert(self.__password, encode=False) 207 return pwConvert(self.__password, encode=False)
193 208
194 def setQuitMessage(self, message): 209 def setQuitMessage(self, message):
195 """ 210 """
196 Public method to set the QUIT message. 211 Public method to set the QUIT message.
197 212
198 @param message QUIT message (string) 213 @param message QUIT message
214 @type str
199 """ 215 """
200 if message: 216 if message:
201 self.__quitMessage = message 217 self.__quitMessage = message
202 else: 218 else:
203 self.__quitMessage = IrcIdentity.DefaultQuitMessage 219 self.__quitMessage = IrcIdentity.DefaultQuitMessage
204 220
205 def getQuitMessage(self): 221 def getQuitMessage(self):
206 """ 222 """
207 Public method to get the QUIT message. 223 Public method to get the QUIT message.
208 224
209 @return QUIT message (string) 225 @return QUIT message
226 @rtype str
210 """ 227 """
211 return self.__quitMessage 228 return self.__quitMessage
212 229
213 def setPartMessage(self, message): 230 def setPartMessage(self, message):
214 """ 231 """
215 Public method to set the PART message. 232 Public method to set the PART message.
216 233
217 @param message PART message (string) 234 @param message PART message
235 @type str
218 """ 236 """
219 if message: 237 if message:
220 self.__partMessage = message 238 self.__partMessage = message
221 else: 239 else:
222 self.__partMessage = IrcIdentity.DefaultPartMessage 240 self.__partMessage = IrcIdentity.DefaultPartMessage
223 241
224 def getPartMessage(self): 242 def getPartMessage(self):
225 """ 243 """
226 Public method to get the PART message. 244 Public method to get the PART message.
227 245
228 @return PART message (string) 246 @return PART message
247 @rtype str
229 """ 248 """
230 return self.__partMessage 249 return self.__partMessage
231 250
232 def setRememberAwayPosition(self, remember): 251 def setRememberAwayPosition(self, remember):
233 """ 252 """
234 Public method to set to remember the chat position upon AWAY. 253 Public method to set to remember the chat position upon AWAY.
235 254
236 @param remember flag indicating to remember the chat position (boolean) 255 @param remember flag indicating to remember the chat position
256 @type bool
237 """ 257 """
238 self.__rememberPosOnAway = remember 258 self.__rememberPosOnAway = remember
239 259
240 def rememberAwayPosition(self): 260 def rememberAwayPosition(self):
241 """ 261 """
242 Public method to get a flag indicating to remember the chat position 262 Public method to get a flag indicating to remember the chat position
243 upon AWAY. 263 upon AWAY.
244 264
245 @return flag indicating to remember the chat position (boolean) 265 @return flag indicating to remember the chat position
266 @rtype bool
246 """ 267 """
247 return self.__rememberPosOnAway 268 return self.__rememberPosOnAway
248 269
249 def setAwayMessage(self, message): 270 def setAwayMessage(self, message):
250 """ 271 """
251 Public method to set the AWAY message. 272 Public method to set the AWAY message.
252 273
253 @param message AWAY message (string) 274 @param message AWAY message
275 @type str
254 """ 276 """
255 if message: 277 if message:
256 self.__awayMessage = message 278 self.__awayMessage = message
257 else: 279 else:
258 self.__awayMessage = IrcIdentity.DefaultAwayMessage 280 self.__awayMessage = IrcIdentity.DefaultAwayMessage
259 281
260 def getAwayMessage(self): 282 def getAwayMessage(self):
261 """ 283 """
262 Public method to get the AWAY message. 284 Public method to get the AWAY message.
263 285
264 @return AWAY message (string) 286 @return AWAY message
287 @rtype str
265 """ 288 """
266 return self.__awayMessage 289 return self.__awayMessage
267 290
268 @classmethod 291 @classmethod
269 def createDefaultIdentity(cls): 292 def createDefaultIdentity(cls):
270 """ 293 """
271 Class method to create the default identity. 294 Class method to create the default identity.
272 295
273 @return default identity (IrcIdentity) 296 @return default identity
297 @rtype IrcIdentity
274 """ 298 """
275 userName = OSUtilities.getUserName() 299 userName = OSUtilities.getUserName()
276 realName = OSUtilities.getRealName() 300 realName = OSUtilities.getRealName()
277 if not realName: 301 if not realName:
278 realName = "eric IDE chat" 302 realName = "eric IDE chat"
293 317
294 def __init__(self, name): 318 def __init__(self, name):
295 """ 319 """
296 Constructor 320 Constructor
297 321
298 @param name name of the server (string) 322 @param name name of the server
323 @type str
299 """ 324 """
300 super().__init__() 325 super().__init__()
301 326
302 self.__server = name 327 self.__server = name
303 self.__port = IrcServer.DefaultPort 328 self.__port = IrcServer.DefaultPort
306 331
307 def save(self, settings): 332 def save(self, settings):
308 """ 333 """
309 Public method to save the server data. 334 Public method to save the server data.
310 335
311 @param settings reference to the settings object (QSettings) 336 @param settings reference to the settings object
337 @type QSettings
312 """ 338 """
313 settings.setValue("Name", self.__server) 339 settings.setValue("Name", self.__server)
314 settings.setValue("Port", self.__port) 340 settings.setValue("Port", self.__port)
315 settings.setValue("SSL", self.__ssl) 341 settings.setValue("SSL", self.__ssl)
316 settings.setValue("Password", self.__password) 342 settings.setValue("Password", self.__password)
317 343
318 def load(self, settings): 344 def load(self, settings):
319 """ 345 """
320 Public method to load the server data. 346 Public method to load the server data.
321 347
322 @param settings reference to the settings object (QSettings) 348 @param settings reference to the settings object
349 @type QSettings
323 """ 350 """
324 self.__server = settings.value("Name", "") 351 self.__server = settings.value("Name", "")
325 self.__port = int(settings.value("Port", IrcServer.DefaultPort)) 352 self.__port = int(settings.value("Port", IrcServer.DefaultPort))
326 self.__ssl = Preferences.toBool(settings.value("SSL", False)) 353 self.__ssl = Preferences.toBool(settings.value("SSL", False))
327 self.__password = settings.value("Password", "") 354 self.__password = settings.value("Password", "")
328 355
329 def getName(self): 356 def getName(self):
330 """ 357 """
331 Public method to get the server name. 358 Public method to get the server name.
332 359
333 @return server name (string) 360 @return server name
361 @rtype str
334 """ 362 """
335 return self.__server 363 return self.__server
336 364
337 def setName(self, name): 365 def setName(self, name):
338 """ 366 """
339 Public method to set the server name. 367 Public method to set the server name.
340 368
341 @param name server name (string) 369 @param name server name
370 @type str
342 """ 371 """
343 self.__server = name 372 self.__server = name
344 373
345 def getPort(self): 374 def getPort(self):
346 """ 375 """
347 Public method to get the server port number. 376 Public method to get the server port number.
348 377
349 @return port number (integer) 378 @return port number
379 @rtype int
350 """ 380 """
351 return self.__port 381 return self.__port
352 382
353 def setPort(self, port): 383 def setPort(self, port):
354 """ 384 """
355 Public method to set the server port number. 385 Public method to set the server port number.
356 386
357 @param port server port number (integer) 387 @param port server port number
388 @type int
358 """ 389 """
359 self.__port = port 390 self.__port = port
360 391
361 def useSSL(self): 392 def useSSL(self):
362 """ 393 """
363 Public method to check for SSL usage. 394 Public method to check for SSL usage.
364 395
365 @return flag indicating SSL usage (boolean) 396 @return flag indicating SSL usage
397 @rtype bool
366 """ 398 """
367 return self.__ssl 399 return self.__ssl
368 400
369 def setUseSSL(self, on): 401 def setUseSSL(self, on):
370 """ 402 """
371 Public method to set the SSL usage. 403 Public method to set the SSL usage.
372 404
373 @param on flag indicating SSL usage (boolean) 405 @param on flag indicating SSL usage
406 @type bool
374 """ 407 """
375 self.__ssl = on 408 self.__ssl = on
376 409
377 def setPassword(self, password): 410 def setPassword(self, password):
378 """ 411 """
379 Public method to set a new password. 412 Public method to set a new password.
380 413
381 @param password password to set (string) 414 @param password password to set
415 @type str
382 """ 416 """
383 self.__password = pwConvert(password, encode=True) 417 self.__password = pwConvert(password, encode=True)
384 418
385 def getPassword(self): 419 def getPassword(self):
386 """ 420 """
387 Public method to get the password. 421 Public method to get the password.
388 422
389 @return password (string) 423 @return password
424 @rtype str
390 """ 425 """
391 return pwConvert(self.__password, encode=False) 426 return pwConvert(self.__password, encode=False)
392 427
393 428
394 class IrcChannel: 429 class IrcChannel:
398 433
399 def __init__(self, name): 434 def __init__(self, name):
400 """ 435 """
401 Constructor 436 Constructor
402 437
403 @param name name of the network (string) 438 @param name name of the network
439 @type str
404 """ 440 """
405 super().__init__() 441 super().__init__()
406 442
407 self.__name = name 443 self.__name = name
408 self.__key = "" 444 self.__key = ""
410 446
411 def save(self, settings): 447 def save(self, settings):
412 """ 448 """
413 Public method to save the channel data. 449 Public method to save the channel data.
414 450
415 @param settings reference to the settings object (QSettings) 451 @param settings reference to the settings object
452 @type QSettings
416 """ 453 """
417 # no need to save the channel name because that is the group key 454 # no need to save the channel name because that is the group key
418 settings.setValue("Key", self.__key) 455 settings.setValue("Key", self.__key)
419 settings.setValue("AutoJoin", self.__autoJoin) 456 settings.setValue("AutoJoin", self.__autoJoin)
420 457
421 def load(self, settings): 458 def load(self, settings):
422 """ 459 """
423 Public method to load the network data. 460 Public method to load the network data.
424 461
425 @param settings reference to the settings object (QSettings) 462 @param settings reference to the settings object
463 @type QSettings
426 """ 464 """
427 self.__key = settings.value("Key", "") 465 self.__key = settings.value("Key", "")
428 self.__autoJoin = Preferences.toBool(settings.value("AutoJoin", False)) 466 self.__autoJoin = Preferences.toBool(settings.value("AutoJoin", False))
429 467
430 def getName(self): 468 def getName(self):
431 """ 469 """
432 Public method to get the channel name. 470 Public method to get the channel name.
433 471
434 @return channel name (string) 472 @return channel name
473 @rtype str
435 """ 474 """
436 return self.__name 475 return self.__name
437 476
438 def setKey(self, key): 477 def setKey(self, key):
439 """ 478 """
440 Public method to set a new channel key. 479 Public method to set a new channel key.
441 480
442 @param key channel key to set (string) 481 @param key channel key to set
482 @type str
443 """ 483 """
444 self.__key = pwConvert(key, encode=True) 484 self.__key = pwConvert(key, encode=True)
445 485
446 def getKey(self): 486 def getKey(self):
447 """ 487 """
448 Public method to get the channel key. 488 Public method to get the channel key.
449 489
450 @return channel key (string) 490 @return channel key
491 @rtype str
451 """ 492 """
452 return pwConvert(self.__key, encode=False) 493 return pwConvert(self.__key, encode=False)
453 494
454 def autoJoin(self): 495 def autoJoin(self):
455 """ 496 """
456 Public method to check the auto join status. 497 Public method to check the auto join status.
457 498
458 @return flag indicating if the channel should be 499 @return flag indicating if the channel should be
459 joined automatically (boolean) 500 joined automatically
501 @rtype bool
460 """ 502 """
461 return self.__autoJoin 503 return self.__autoJoin
462 504
463 def setAutoJoin(self, enable): 505 def setAutoJoin(self, enable):
464 """ 506 """
465 Public method to set the auto join status of the channel. 507 Public method to set the auto join status of the channel.
466 508
467 @param enable flag indicating if the channel should be 509 @param enable flag indicating if the channel should be
468 joined automatically (boolean) 510 joined automatically
511 @type bool
469 """ 512 """
470 self.__autoJoin = enable 513 self.__autoJoin = enable
471 514
472 515
473 class IrcNetwork: 516 class IrcNetwork:
477 520
478 def __init__(self, name): 521 def __init__(self, name):
479 """ 522 """
480 Constructor 523 Constructor
481 524
482 @param name name of the network (string) 525 @param name name of the network
526 @type str
483 """ 527 """
484 super().__init__() 528 super().__init__()
485 529
486 self.__name = name 530 self.__name = name
487 self.__identity = "" 531 self.__identity = ""
491 535
492 def save(self, settings): 536 def save(self, settings):
493 """ 537 """
494 Public method to save the network data. 538 Public method to save the network data.
495 539
496 @param settings reference to the settings object (QSettings) 540 @param settings reference to the settings object
541 @type QSettings
497 """ 542 """
498 # no need to save the network name because that is the group key 543 # no need to save the network name because that is the group key
499 settings.setValue("Identity", self.__identity) 544 settings.setValue("Identity", self.__identity)
500 settings.setValue("AutoConnect", self.__autoConnect) 545 settings.setValue("AutoConnect", self.__autoConnect)
501 546
512 557
513 def load(self, settings): 558 def load(self, settings):
514 """ 559 """
515 Public method to load the network data. 560 Public method to load the network data.
516 561
517 @param settings reference to the settings object (QSettings) 562 @param settings reference to the settings object
563 @type QSettings
518 """ 564 """
519 self.__identity = settings.value("Identity", "") 565 self.__identity = settings.value("Identity", "")
520 self.__autoConnect = Preferences.toBool(settings.value("AutoConnect", False)) 566 self.__autoConnect = Preferences.toBool(settings.value("AutoConnect", False))
521 567
522 settings.beginGroup("Server") 568 settings.beginGroup("Server")
534 580
535 def setName(self, name): 581 def setName(self, name):
536 """ 582 """
537 Public method to set the network name. 583 Public method to set the network name.
538 584
539 @param name network name (string) 585 @param name network name
586 @type str
540 """ 587 """
541 self.__name = name 588 self.__name = name
542 589
543 def getName(self): 590 def getName(self):
544 """ 591 """
545 Public method to get the network name. 592 Public method to get the network name.
546 593
547 @return network name (string) 594 @return network name
595 @rtype str
548 """ 596 """
549 return self.__name 597 return self.__name
550 598
551 def setIdentityName(self, name): 599 def setIdentityName(self, name):
552 """ 600 """
553 Public method to set the name of the identity. 601 Public method to set the name of the identity.
554 602
555 @param name identity name (string) 603 @param name identity name
604 @type str
556 """ 605 """
557 self.__identity = name 606 self.__identity = name
558 607
559 def getIdentityName(self): 608 def getIdentityName(self):
560 """ 609 """
561 Public method to get the name of the identity. 610 Public method to get the name of the identity.
562 611
563 @return identity name (string) 612 @return identity name
613 @rtype str
564 """ 614 """
565 return self.__identity 615 return self.__identity
566 616
567 def getServerName(self): 617 def getServerName(self):
568 """ 618 """
569 Public method to get the server name. 619 Public method to get the server name.
570 620
571 @return server name (string) 621 @return server name
622 @rtype str
572 """ 623 """
573 if self.__server: 624 if self.__server:
574 return self.__server.getName() 625 return self.__server.getName()
575 else: 626 else:
576 return "" 627 return ""
577 628
578 def getServer(self): 629 def getServer(self):
579 """ 630 """
580 Public method to get the server object. 631 Public method to get the server object.
581 632
582 @return reference to the server (IrcServer) 633 @return reference to the server
634 @rtype IrcServer
583 """ 635 """
584 return self.__server 636 return self.__server
585 637
586 def setServer(self, server): 638 def setServer(self, server):
587 """ 639 """
588 Public method to set the server. 640 Public method to set the server.
589 641
590 @param server server object to set (IrcServer) 642 @param server server object to set
643 @type IrcServer
591 """ 644 """
592 self.__server = server 645 self.__server = server
593 646
594 def setChannels(self, channels): 647 def setChannels(self, channels):
595 """ 648 """
596 Public method to set the list of channels. 649 Public method to set the list of channels.
597 650
598 @param channels list of channels for the network (list of IrcChannel) 651 @param channels list of channels for the network
652 @type list of IrcChannel
599 """ 653 """
600 self.__channels = {} 654 self.__channels = {}
601 for channel in channels: 655 for channel in channels:
602 self.__channels[channel.getName()] = channel 656 self.__channels[channel.getName()] = channel
603 657
604 def getChannels(self): 658 def getChannels(self):
605 """ 659 """
606 Public method to get the channels. 660 Public method to get the channels.
607 661
608 @return list of channels for the network (list of IrcChannel) 662 @return list of channels for the network
663 @rtype list of IrcChannel
609 """ 664 """
610 return list(copy.deepcopy(self.__channels).values()) 665 return list(copy.deepcopy(self.__channels).values())
611 666
612 def getChannelNames(self): 667 def getChannelNames(self):
613 """ 668 """
614 Public method to get the list of channels. 669 Public method to get the list of channels.
615 670
616 @return list of channel names (list of string) 671 @return list of channel names
672 @rtype list of str
617 """ 673 """
618 return sorted(self.__channels) 674 return sorted(self.__channels)
619 675
620 def getChannel(self, channelName): 676 def getChannel(self, channelName):
621 """ 677 """
622 Public method to get a channel. 678 Public method to get a channel.
623 679
624 @param channelName name of the channel to retrieve (string) 680 @param channelName name of the channel to retrieve
625 @return reference to the channel (IrcChannel) 681 @type str
682 @return reference to the channel
683 @rtype IrcChannel
626 """ 684 """
627 if channelName in self.__channels: 685 if channelName in self.__channels:
628 return self.__channels[channelName] 686 return self.__channels[channelName]
629 else: 687 else:
630 return None 688 return None
631 689
632 def setChannel(self, channel): 690 def setChannel(self, channel):
633 """ 691 """
634 Public method to set a channel. 692 Public method to set a channel.
635 693
636 @param channel channel object to set (IrcChannel) 694 @param channel channel object to set
695 @type IrcChannel
637 """ 696 """
638 channelName = channel.getName() 697 channelName = channel.getName()
639 if channelName in self.__channels: 698 if channelName in self.__channels:
640 self.__channels[channelName] = channel 699 self.__channels[channelName] = channel
641 700
642 def addChannel(self, channel): 701 def addChannel(self, channel):
643 """ 702 """
644 Public method to add a channel. 703 Public method to add a channel.
645 704
646 @param channel channel object to add (IrcChannel) 705 @param channel channel object to add
706 @type IrcChannel
647 """ 707 """
648 channelName = channel.getName() 708 channelName = channel.getName()
649 if channelName not in self.__channels: 709 if channelName not in self.__channels:
650 self.__channels[channelName] = channel 710 self.__channels[channelName] = channel
651 711
652 def deleteChannel(self, channelName): 712 def deleteChannel(self, channelName):
653 """ 713 """
654 Public method to delete the given channel. 714 Public method to delete the given channel.
655 715
656 @param channelName name of the channel to be deleted (string) 716 @param channelName name of the channel to be deleted
717 @type str
657 """ 718 """
658 if channelName in self.__channels: 719 if channelName in self.__channels:
659 del self.__channels[channelName] 720 del self.__channels[channelName]
660 721
661 def setAutoConnect(self, enable): 722 def setAutoConnect(self, enable):
662 """ 723 """
663 Public method to set the auto connect flag. 724 Public method to set the auto connect flag.
664 725
665 @param enable flag indicate to connect to the network at start-up. 726 @param enable flag indicate to connect to the network at start-up
727 @type bool
666 """ 728 """
667 self.__autoConnect = enable 729 self.__autoConnect = enable
668 730
669 def autoConnect(self): 731 def autoConnect(self):
670 """ 732 """
671 Public method to check, if the network should be connected to at 733 Public method to check, if the network should be connected to at
672 start-up. 734 start-up.
673 735
674 @return flag indicating an auto connect (boolean) 736 @return flag indicating an auto connect
737 @rtype bool
675 """ 738 """
676 return self.__autoConnect 739 return self.__autoConnect
677 740
678 @classmethod 741 @classmethod
679 def createDefaultNetwork(cls, ssl=False): 742 def createDefaultNetwork(cls, ssl=False):
680 """ 743 """
681 Class method to create the default network. 744 Class method to create the default network.
682 745
683 @param ssl flag indicating to create a SSL network configuration 746 @param ssl flag indicating to create a SSL network configuration
684 (boolean) 747 @type bool
685 @return default network object (IrcNetwork) 748 @return default network object
749 @rtype IrcNetwork
686 """ 750 """
687 # network 751 # network
688 networkName = "libera.chat (SSL)" if ssl else "libera.chat" 752 networkName = "libera.chat (SSL)" if ssl else "libera.chat"
689 network = IrcNetwork(networkName) 753 network = IrcNetwork(networkName)
690 network.setIdentityName(IrcIdentity.DefaultIdentityName) 754 network.setIdentityName(IrcIdentity.DefaultIdentityName)
725 789
726 def __init__(self, parent=None): 790 def __init__(self, parent=None):
727 """ 791 """
728 Constructor 792 Constructor
729 793
730 @param parent reference to the parent object (QObject) 794 @param parent reference to the parent object
795 @type QObject
731 """ 796 """
732 super().__init__(parent) 797 super().__init__(parent)
733 798
734 self.__loaded = False 799 self.__loaded = False
735 self.__saveTimer = AutoSaver(self, self.save) 800 self.__saveTimer = AutoSaver(self, self.save)
819 def __loadDefaults(self, identityOnly=False): 884 def __loadDefaults(self, identityOnly=False):
820 """ 885 """
821 Private method to load default values. 886 Private method to load default values.
822 887
823 @param identityOnly flag indicating to just load the default 888 @param identityOnly flag indicating to just load the default
824 identity (boolean) 889 identity
890 @type bool
825 """ 891 """
826 if not identityOnly: 892 if not identityOnly:
827 self.__networks = {} 893 self.__networks = {}
828 self.__identities = {} 894 self.__identities = {}
829 895
845 911
846 def getIdentity(self, name, create=False): 912 def getIdentity(self, name, create=False):
847 """ 913 """
848 Public method to get an identity object. 914 Public method to get an identity object.
849 915
850 @param name name of the identity to get (string) 916 @param name name of the identity to get
917 @type str
851 @param create flag indicating to create a new object, 918 @param create flag indicating to create a new object,
852 if none exists (boolean) 919 if none exists
853 @return reference to the identity (IrcIdentity) 920 @type bool
921 @return reference to the identity
922 @rtype IrcIdentity
854 """ 923 """
855 if not name: 924 if not name:
856 return None 925 return None
857 926
858 if not self.__loaded: 927 if not self.__loaded:
872 941
873 def getIdentities(self): 942 def getIdentities(self):
874 """ 943 """
875 Public method to get a copy of all identities. 944 Public method to get a copy of all identities.
876 945
877 @return dictionary of all identities (dict of IrcIdentity) 946 @return dictionary of all identities
947 @rtype dict of IrcIdentity
878 """ 948 """
879 return copy.deepcopy(self.__identities) 949 return copy.deepcopy(self.__identities)
880 950
881 def setIdentities(self, identities): 951 def setIdentities(self, identities):
882 """ 952 """
883 Public method to set the identities. 953 Public method to set the identities.
884 954
885 @param identities dictionary of all identities (dict of IrcIdentity) 955 @param identities dictionary of all identities
956 @type dict of IrcIdentity
886 """ 957 """
887 self.__identities = copy.deepcopy(identities) 958 self.__identities = copy.deepcopy(identities)
888 self.identityChanged() 959 self.identityChanged()
889 960
890 # Check all networks, if the identity they use is still available. 961 # Check all networks, if the identity they use is still available.
895 966
896 def getIdentityNames(self): 967 def getIdentityNames(self):
897 """ 968 """
898 Public method to get the names of all identities. 969 Public method to get the names of all identities.
899 970
900 @return names of all identities (list of string) 971 @return names of all identities
972 @rtype list of string)
901 """ 973 """
902 return list(self.__identities) 974 return list(self.__identities)
903 975
904 def addIdentity(self, identity): 976 def addIdentity(self, identity):
905 """ 977 """
906 Public method to add a new identity. 978 Public method to add a new identity.
907 979
908 @param identity reference to the identity to add (IrcIdentity) 980 @param identity reference to the identity to add
981 @type IrcIdentity
909 """ 982 """
910 name = identity.getName() 983 name = identity.getName()
911 self.__identities[name] = identity 984 self.__identities[name] = identity
912 self.identityChanged() 985 self.identityChanged()
913 986
914 def deleteIdentity(self, name): 987 def deleteIdentity(self, name):
915 """ 988 """
916 Public method to delete the given identity. 989 Public method to delete the given identity.
917 990
918 @param name name of the identity to delete (string) 991 @param name name of the identity to delete
992 @type str
919 """ 993 """
920 if name in self.__identities and name != IrcIdentity.DefaultIdentityName: 994 if name in self.__identities and name != IrcIdentity.DefaultIdentityName:
921 del self.__identities[name] 995 del self.__identities[name]
922 self.identityChanged() 996 self.identityChanged()
923 997
924 def renameIdentity(self, oldName, newName): 998 def renameIdentity(self, oldName, newName):
925 """ 999 """
926 Public method to rename an identity. 1000 Public method to rename an identity.
927 1001
928 @param oldName old name of the identity (string) 1002 @param oldName old name of the identity
929 @param newName new name of the identity (string) 1003 @type str
1004 @param newName new name of the identity
1005 @type str
930 """ 1006 """
931 if oldName in self.__identities: 1007 if oldName in self.__identities:
932 self.__identities[newName] = self.__identities[oldName] 1008 self.__identities[newName] = self.__identities[oldName]
933 del self.__identities[oldName] 1009 del self.__identities[oldName]
934 1010
951 1027
952 def getNetwork(self, name): 1028 def getNetwork(self, name):
953 """ 1029 """
954 Public method to get a network object. 1030 Public method to get a network object.
955 1031
956 @param name name of the network (string) 1032 @param name name of the network
957 @return reference to the network object (IrcNetwork) 1033 @type str
1034 @return reference to the network object
1035 @rtype IrcNetwork
958 """ 1036 """
959 if not self.__loaded: 1037 if not self.__loaded:
960 self.__load() 1038 self.__load()
961 1039
962 if name in self.__networks: 1040 if name in self.__networks:
966 1044
967 def setNetwork(self, network, networkName=""): 1045 def setNetwork(self, network, networkName=""):
968 """ 1046 """
969 Public method to set a network. 1047 Public method to set a network.
970 1048
971 @param network network object to set (IrcNetwork) 1049 @param network network object to set
972 @param networkName name the network was known for (string) 1050 @type IrcNetwork
1051 @param networkName name the network was known for
1052 @type str
973 """ 1053 """
974 name = network.getName() 1054 name = network.getName()
975 if networkName and name != networkName: 1055 if networkName and name != networkName:
976 # the network name has changed 1056 # the network name has changed
977 self.deleteNetwork(networkName) 1057 self.deleteNetwork(networkName)
982 1062
983 def addNetwork(self, network): 1063 def addNetwork(self, network):
984 """ 1064 """
985 Public method to add a network. 1065 Public method to add a network.
986 1066
987 @param network network object to add (IrcNetwork) 1067 @param network network object to add
1068 @type IrcNetwork
988 """ 1069 """
989 name = network.getName() 1070 name = network.getName()
990 if name not in self.__networks: 1071 if name not in self.__networks:
991 self.__networks[name] = network 1072 self.__networks[name] = network
992 self.networkChanged() 1073 self.networkChanged()
993 1074
994 def deleteNetwork(self, name): 1075 def deleteNetwork(self, name):
995 """ 1076 """
996 Public method to delete the given network. 1077 Public method to delete the given network.
997 1078
998 @param name name of the network to delete (string) 1079 @param name name of the network to delete
1080 @type str
999 """ 1081 """
1000 if name in self.__networks: 1082 if name in self.__networks:
1001 del self.__networks[name] 1083 del self.__networks[name]
1002 self.networkChanged() 1084 self.networkChanged()
1003 1085
1010 1092
1011 def getNetworkNames(self): 1093 def getNetworkNames(self):
1012 """ 1094 """
1013 Public method to get a list of all known network names. 1095 Public method to get a list of all known network names.
1014 1096
1015 @return list of network names (list of string) 1097 @return list of network names
1098 @rtype list of str
1016 """ 1099 """
1017 if not self.__loaded: 1100 if not self.__loaded:
1018 self.__load() 1101 self.__load()
1019 1102
1020 return sorted(self.__networks) 1103 return sorted(self.__networks)

eric ide

mercurial