def get_user_status(self, msg): user = msg.user iterator = self.users.get(user) if iterator is None: return status = msg.status if status == self.usersmodel.get_value(iterator, 5): return status_icon = get_status_icon(status) if status_icon is None: return if status == 1: action = _("%s has gone away") elif status == 2: action = _("%s has returned") else: # If we reach this point, the server did something wrong. The user should have # left the room before an offline status is sent. return if not self.frame.np.network_filter.is_user_ignored(user) and \ not self.frame.np.network_filter.is_user_ip_ignored(user): self.log_textview.append_line(action % user, self.tag_log) self.usersmodel.set_value(iterator, 0, status_icon) self.usersmodel.set_value(iterator, 5, status) self.update_user_tag(user)
def add_user_row(self, userdata): username = userdata.username status = userdata.status country = userdata.country or "" # country can be None, ensure string is used status_icon = get_status_icon(status) or get_status_icon(0) flag_icon = get_flag_icon_name(country) # Request user's IP address, so we can get the country and ignore messages by IP self.frame.np.queue.append(slskmessages.GetPeerAddress(username)) h_speed = "" avgspeed = userdata.avgspeed if avgspeed > 0: h_speed = human_speed(avgspeed) files = userdata.files h_files = humanize(files) weight = Pango.Weight.NORMAL underline = Pango.Underline.NONE if self.room in self.frame.np.chatrooms.private_rooms: if username == self.frame.np.chatrooms.private_rooms[ self.room]["owner"]: weight = Pango.Weight.BOLD underline = Pango.Underline.SINGLE elif username in self.frame.np.chatrooms.private_rooms[ self.room]["operators"]: weight = Pango.Weight.BOLD underline = Pango.Underline.NONE iterator = self.usersmodel.insert_with_valuesv( -1, self.column_numbers, [ status_icon, flag_icon, username, h_speed, h_files, status, GObject.Value(GObject.TYPE_UINT, avgspeed), GObject.Value(GObject.TYPE_UINT, files), country, weight, underline ]) self.users[username] = iterator
def append_user_row(self, row): if not row or not isinstance(row, list): return username = str(row[0]) if not username: return try: note = str(row[1]) except IndexError: note = "" try: notify = bool(row[2]) except IndexError: notify = False try: prioritized = bool(row[3]) except IndexError: prioritized = False try: trusted = bool(row[4]) except IndexError: trusted = False try: last_seen = str(row[5]) except IndexError: last_seen = "" try: time_from_epoch = time.mktime( time.strptime(last_seen, "%m/%d/%Y %H:%M:%S")) except ValueError: last_seen = _("Never seen") time_from_epoch = 0 try: country = str(row[6]) except IndexError: country = "" row = [ get_status_icon(0), get_flag_icon_name(country), username, "", "", trusted, notify, prioritized, last_seen, note, 0, 0, 0, time_from_epoch, country ] self.user_iterators[username] = self.usersmodel.insert_with_valuesv( 0, self.column_numbers, row)
def get_user_status(self, msg): iterator = self.recommendation_users.get(msg.user) if iterator is None: return status_icon = get_status_icon(msg.status) if status_icon is None: return self.recommendation_users_model.set_value(iterator, 0, status_icon) self.recommendation_users_model.set_value(iterator, 4, msg.status)
def server_disconnect(self): for i in self.usersmodel: iterator = i.iter self.usersmodel.set_value(iterator, 0, get_status_icon(0)) self.usersmodel.set_value(iterator, 3, "") self.usersmodel.set_value(iterator, 4, "") self.usersmodel.set_value(iterator, 10, 0) self.usersmodel.set_value(iterator, 11, 0) self.usersmodel.set_value(iterator, 12, 0) if not self.usersmodel.get_value(iterator, 8): user = self.usersmodel.get_value(iterator, 2) self.set_last_seen(user) self.save_user_list()
def set_similar_users(self, users, item=None): if item: self.SimilarUsersLabel.set_label(_("Similar Users (%s)") % item) else: self.SimilarUsersLabel.set_label(_("Similar Users")) self.recommendation_users_model.clear() self.recommendation_users = {} for user in users: iterator = self.recommendation_users_model.insert_with_valuesv( -1, self.recommendation_users_column_numbers, [get_status_icon(0), user, "", "0", 0, 0, 0]) self.recommendation_users[user] = iterator # Request user status, speed and number of shared files self.frame.np.watch_user(user, force_update=True)
def add_user(self, user): if user in self.user_iterators: return empty_int = 0 empty_str = "" self.user_iterators[user] = self.usersmodel.insert_with_valuesv( -1, self.column_numbers, [ get_status_icon(0), empty_str, user, empty_str, empty_str, False, False, False, _("Never seen"), empty_str, empty_int, empty_int, empty_int, empty_int, empty_str ]) self.save_user_list() self.update() if config.sections["words"]["buddies"]: self.frame.update_completions()
def get_user_status(self, msg): user = msg.user iterator = self.user_iterators.get(user) if iterator is None: return status = msg.status if status == self.usersmodel.get_value(iterator, 10): return status_icon = get_status_icon(status) if status_icon is None: return notify = self.usersmodel.get_value(iterator, 6) if notify: if status == 1: status_text = _("User %s is away") elif status == 2: status_text = _("User %s is online") else: status_text = _("User %s is offline") log.add(status_text, user) self.frame.notifications.new_text_notification(status_text % user) self.usersmodel.set_value(iterator, 0, status_icon) self.usersmodel.set_value(iterator, 10, status) if status: # online self.set_last_seen(user, online=True) elif not self.usersmodel.get_value(iterator, 8): # disconnected self.set_last_seen(user)