def TabPopup(self, user): popup = PopupMenu(self.frame) popup.setup(("#" + _("Send _message"), popup.OnSendMessage), ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo), ("#" + _("Brow_se files"), popup.OnBrowseUser), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges), ("#" + _("Client Version"), popup.OnVersion), ("", None), ("$" + _("Add user to list"), popup.OnAddToList), ("$" + _("Ban this user"), popup.OnBanUser), ("$" + _("Ignore this user"), popup.OnIgnoreUser), ("", None), ("#" + _("Detach this tab"), self.users[user].Detach), ("#" + _("Close this tab"), self.users[user].OnClose)) popup.set_user(user) items = popup.get_children() items[7].set_active(user in [ i[0] for i in self.frame.np.config.sections["server"]["userlist"] ]) items[8].set_active( user in self.frame.np.config.sections["server"]["banlist"]) items[9].set_active( user in self.frame.np.config.sections["server"]["ignorelist"]) return popup
def TabPopup(self, user): popup = PopupMenu(self.frame) popup.setup( ("#" + _("Send _message"), popup.OnSendMessage), ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo), ("#" + _("Brow_se files"), popup.OnBrowseUser), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges), ("#" + _("Client Version"), popup.OnVersion), ("", None), ("$" + _("Add user to list"), popup.OnAddToList), ("$" + _("Ban this user"), popup.OnBanUser), ("$" + _("Ignore this user"), popup.OnIgnoreUser), ("", None), ("#" + _("Detach this tab"), self.users[user].Detach), ("#" + _("Close this tab"), self.users[user].OnClose) ) popup.set_user(user) items = popup.get_children() items[7].set_active(user in [i[0] for i in self.frame.np.config.sections["server"]["userlist"]]) items[8].set_active(user in self.frame.np.config.sections["server"]["banlist"]) items[9].set_active(user in self.frame.np.config.sections["server"]["ignorelist"]) return popup
def OnPopupMenuUsers(self, widget): self.selected_transfers = [] self.selected_users = [] self.widget.get_selection().selected_foreach(self.SelectedTransfersCallback) self.popup_menu_users.clear() if len(self.selected_users) > 0: items = [] self.selected_users.sort(key=str.lower) for user in self.selected_users: popup = PopupMenu(self.frame) popup.setup( ("#" + _("Send _message"), popup.OnSendMessage, gtk.STOCK_EDIT), ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress, gtk.STOCK_NETWORK), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo, gtk.STOCK_DIALOG_INFO), ("#" + _("Brow_se files"), popup.OnBrowseUser, gtk.STOCK_HARDDISK), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges, gtk.STOCK_JUMP_TO), ("", None), ("$" + _("_Add user to list"), popup.OnAddToList), ("$" + _("_Ban this user"), popup.OnBanUser), ("$" + _("_Ignore this user"), popup.OnIgnoreUser), ("#" + _("Select User's Transfers"), self.OnSelectUserTransfer, gtk.STOCK_INDEX), ) popup.set_user(user) items.append((1, user, popup, self.OnPopupMenuUser, popup)) self.popup_menu_users.setup(*items) return True
def TabPopup(self, user): popup = PopupMenu(self.frame) popup.setup( ("#" + _("Send _message"), popup.OnSendMessage, gtk.STOCK_EDIT), ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress, gtk.STOCK_NETWORK), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo, gtk.STOCK_DIALOG_INFO), ("#" + _("Brow_se files"), popup.OnBrowseUser, gtk.STOCK_HARDDISK), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges, gtk.STOCK_JUMP_TO), ("#" + _("Client Version"), popup.OnVersion, gtk.STOCK_ABOUT), ("", None), ("$" + _("Add user to list"), popup.OnAddToList), ("$" + _("Ban this user"), popup.OnBanUser), ("$" + _("Ignore this user"), popup.OnIgnoreUser), ("", None), ("#" + _("Detach this tab"), self.users[user].Detach, gtk.STOCK_REDO), ("#" + _("Close this tab"), self.users[user].OnClose, gtk.STOCK_CLOSE), ) popup.set_user(user) items = popup.get_children() items[7].set_active(user in [ i[0] for i in self.frame.np.config.sections["server"]["userlist"] ]) items[8].set_active( user in self.frame.np.config.sections["server"]["banlist"]) items[9].set_active( user in self.frame.np.config.sections["server"]["ignorelist"]) return popup
def OnPopupMenuUsers(self, widget): self.selected_transfers = [] self.selected_users = [] self.widget.get_selection().selected_foreach( self.SelectedTransfersCallback) self.popup_menu_users.clear() if len(self.selected_users) > 0: items = [] self.selected_users.sort(key=str.lower) for user in self.selected_users: popup = PopupMenu(self.frame) popup.setup( ("#" + _("Send _message"), popup.OnSendMessage), ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo), ("#" + _("Brow_se files"), popup.OnBrowseUser), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges), ("", None), ("$" + _("_Add user to list"), popup.OnAddToList), ("$" + _("_Ban this user"), popup.OnBanUser), ("$" + _("_Ignore this user"), popup.OnIgnoreUser), ("#" + _("Select User's Transfers"), self.OnSelectUserTransfer)) popup.set_user(user) items.append((1, user, popup, self.OnPopupMenuUser, popup)) self.popup_menu_users.setup(*items) return True
def OnPopupMenuUsers(self, widget): self.select_results() #(user, fn, size, bitrate, length) self.popup_menu_users.clear() if len(self.selected_users) > 0: items = [] self.selected_users.sort(key=str.lower) for user in self.selected_users: popup = PopupMenu(self.frame) popup.setup( ("#" + _("Send _message"), popup.OnSendMessage, gtk.STOCK_EDIT), ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress, gtk.STOCK_NETWORK), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo, gtk.STOCK_DIALOG_INFO), ("#" + _("Brow_se files"), popup.OnBrowseUser, gtk.STOCK_HARDDISK), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges, gtk.STOCK_JUMP_TO), ("", None), ("$" + _("_Add user to list"), popup.OnAddToList), ("$" + _("_Ban this user"), popup.OnBanUser), ("$" + _("_Ignore this user"), popup.OnIgnoreUser), ("#" + _("Select User's Results"), self.OnSelectUserResults, gtk.STOCK_INDEX), ) popup.set_user(user) items.append((1, user, popup, self.OnPopupMenuUser, popup)) self.popup_menu_users.setup(*items) return True
def TabPopup(self, user): popup = PopupMenu(self.frame) popup.setup( ("#" + _("Send _message"), popup.OnSendMessage, gtk.STOCK_EDIT), ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress, gtk.STOCK_NETWORK), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo, gtk.STOCK_DIALOG_INFO), ("#" + _("Brow_se files"), popup.OnBrowseUser, gtk.STOCK_HARDDISK), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges, gtk.STOCK_JUMP_TO), ("#" + _("Client Version"), popup.OnVersion, gtk.STOCK_ABOUT ), ("", None), ("$" + _("Add user to list"), popup.OnAddToList), ("$" + _("Ban this user"), popup.OnBanUser), ("$" + _("Ignore this user"), popup.OnIgnoreUser), ("", None), ("#" + _("Detach this tab"), self.users[user].Detach, gtk.STOCK_REDO), ("#" + _("Close this tab"), self.users[user].OnClose, gtk.STOCK_CLOSE), ) popup.set_user(user) items = popup.get_children() items[7].set_active(user in [i[0] for i in self.frame.np.config.sections["server"]["userlist"]]) items[8].set_active(user in self.frame.np.config.sections["server"]["banlist"]) items[9].set_active(user in self.frame.np.config.sections["server"]["ignorelist"]) return popup
def TabPopup(self, user): if user not in self.users: return popup = PopupMenu(self.frame) popup.setup( ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo), ("#" + _("Brow_se files"), popup.OnBrowseUser), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges), ("#" + _("Client Version"), popup.OnVersion), ("", None), ("$" + _("Add user to list"), popup.OnAddToList), ("$" + _("Ban this user"), popup.OnBanUser), ("$" + _("Ignore this user"), popup.OnIgnoreUser), ("$" + _("B_lock this user's IP Address"), popup.OnBlockUser), ("$" + _("Ignore this user's IP Address"), popup.OnIgnoreIP), ("", None), ("#" + _("Detach this tab"), self.users[user].Detach), ("#" + _("Close this tab"), self.users[user].OnClose)) popup.set_user(user) me = (popup.user is None or popup.user == self.frame.np.config.sections["server"]["login"]) items = popup.get_children() items[6].set_active(user in [ i[0] for i in self.frame.np.config.sections["server"]["userlist"] ]) items[7].set_active( user in self.frame.np.config.sections["server"]["banlist"]) items[8].set_active( user in self.frame.np.config.sections["server"]["ignorelist"]) items[9].set_active(self.frame.UserIpIsBlocked(user)) items[9].set_sensitive(not me) items[10].set_active(self.frame.UserIpIsIgnored(user)) items[10].set_sensitive(not me) return popup
def TabPopup(self, user): if user not in self.users: return popup = PopupMenu(self.frame) popup.setup( ("#" + _("Show IP a_ddress"), popup.OnShowIPaddress), ("#" + _("Get user i_nfo"), popup.OnGetUserInfo), ("#" + _("Brow_se files"), popup.OnBrowseUser), ("#" + _("Gi_ve privileges"), popup.OnGivePrivileges), ("#" + _("Client Version"), popup.OnVersion), ("", None), ("$" + _("Add user to list"), popup.OnAddToList), ("$" + _("Ban this user"), popup.OnBanUser), ("$" + _("Ignore this user"), popup.OnIgnoreUser), ("$" + _("B_lock this user's IP Address"), popup.OnBlockUser), ("$" + _("Ignore this user's IP Address"), popup.OnIgnoreIP), ("", None), ("#" + _("Detach this tab"), self.users[user].Detach), ("#" + _("Close this tab"), self.users[user].OnClose) ) popup.set_user(user) me = (popup.user is None or popup.user == self.frame.np.config.sections["server"]["login"]) items = popup.get_children() items[6].set_active(user in [i[0] for i in self.frame.np.config.sections["server"]["userlist"]]) items[7].set_active(user in self.frame.np.config.sections["server"]["banlist"]) items[8].set_active(user in self.frame.np.config.sections["server"]["ignorelist"]) items[9].set_active(self.frame.UserIpIsBlocked(user)) items[9].set_sensitive(not me) items[10].set_active(self.frame.UserIpIsIgnored(user)) items[10].set_sensitive(not me) return popup
class UserBrowse: def __init__(self, userbrowses, user, conn): self.wTree = gtk.glade.XML(os.path.join(os.path.dirname(os.path.realpath(__file__)), "userbrowse.glade"), None) widgets = self.wTree.get_widget_prefix("") for i in widgets: name = gtk.glade.get_widget_name(i) self.__dict__[name] = i self.UserBrowseTab.remove(self.Main) self.UserBrowseTab.destroy() self.wTree.signal_autoconnect(self) self.userbrowses = userbrowses self.frame = userbrowses.frame self.user = user self.conn = conn # selected_folder is the current selected folder self.selected_folder = None self.search_list = [] self.query = None self.search_position = 0 self.selected_files = [] self.shares = [] self.Elist = {} # Iters for current DirStore self.directories = {} # Iters for current FileStore self.files = {} self.totalsize = 0 self.encoding, m = EncodingsMenu(self.frame.np, "userencoding", user) self.EncodingStore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self.Encoding.set_size_request(100, -1) self.Encoding.set_model(self.EncodingStore) cell = gtk.CellRendererText() self.Encoding.pack_start(cell, True) self.Encoding.add_attribute(cell, 'text', 0) cell2 = gtk.CellRendererText() self.Encoding.pack_start(cell2, False) self.Encoding.add_attribute(cell2, 'text', 1) for item in m: self.Elist[item[1]] = self.EncodingStore.append([item[1], item[0]]) if self.encoding == item[1]: self.Encoding.set_active_iter(self.Elist[self.encoding]) self.DirStore = gtk.TreeStore(str, str) self.FolderTreeView.set_headers_visible(True) self.FolderTreeView.set_enable_tree_lines(True) cols = InitialiseColumns( self.FolderTreeView, [_("Directories"), -1, "text", self.CellDataFunc] # 0 ) cols[0].set_sort_column_id(0) self.popup_menu_users = PopupMenu(self.frame) self.popup_menu_users2 = PopupMenu(self.frame) for menu in [self.popup_menu_users, self.popup_menu_users2]: menu.setup( ("#" + _("Send _message"), menu.OnSendMessage, gtk.STOCK_EDIT), ("#" + _("Show IP a_ddress"), menu.OnShowIPaddress, gtk.STOCK_NETWORK), ("#" + _("Get user i_nfo"), menu.OnGetUserInfo, gtk.STOCK_DIALOG_INFO), ("#" + _("Gi_ve privileges"), menu.OnGivePrivileges, gtk.STOCK_JUMP_TO), ("", None), ("$" + _("_Add user to list"), menu.OnAddToList), ("$" + _("_Ban this user"), menu.OnBanUser), ("$" + _("_Ignore this user"), menu.OnIgnoreUser) ) self.popup_menu_downloads_folders = PopupMenu(self.frame) self.popup_menu_downloads_folders.setup( ("#" + _("_Download directory"), self.OnDownloadDirectory, gtk.STOCK_GO_DOWN), ("#" + _("Download directory _to..."), self.OnDownloadDirectoryTo, gtk.STOCK_GO_DOWN), ("#" + _("Download _recursive"), self.OnDownloadDirectoryRecursive, gtk.STOCK_GO_DOWN), ("#" + _("Download r_ecursive to..."), self.OnDownloadDirectoryRecursiveTo, gtk.STOCK_GO_DOWN) ) self.popup_menu_downloads_files = PopupMenu(self.frame) self.popup_menu_downloads_files.setup( ("#" + _("_Download file(s)"), self.OnDownloadFiles, gtk.STOCK_GO_DOWN), ("#" + _("Download _to..."), self.OnDownloadFilesTo, gtk.STOCK_GO_DOWN), ("", None), ("#" + _("_Download directory"), self.OnDownloadDirectory, gtk.STOCK_GO_DOWN), ("#" + _("Download directory _to..."), self.OnDownloadDirectoryTo, gtk.STOCK_GO_DOWN), ("#" + _("Download _recursive"), self.OnDownloadDirectoryRecursive, gtk.STOCK_GO_DOWN), ("#" + _("Download r_ecursive to..."), self.OnDownloadDirectoryRecursiveTo, gtk.STOCK_GO_DOWN) ) self.popup_menu_uploads_folders = PopupMenu(self.frame) self.popup_menu_uploads_folders.setup( ("#" + _("Upload Directory to..."), self.OnUploadDirectoryTo, gtk.STOCK_GO_UP), ("#" + _("Upload Directory recursive to..."), self.OnUploadDirectoryRecursiveTo, gtk.STOCK_GO_UP) ) self.popup_menu_uploads_files = PopupMenu(self.frame) self.popup_menu_uploads_files.setup( ("#" + _("Upload Directory to..."), self.OnUploadDirectoryTo, gtk.STOCK_GO_UP), ("#" + _("Upload Directory recursive to..."), self.OnUploadDirectoryRecursiveTo, gtk.STOCK_GO_UP), ("#" + _("Up_load file(s)"), self.OnUploadFiles, gtk.STOCK_GO_UP) ) self.folder_popup_menu = PopupMenu(self.frame) self.folder_popup_menu.set_user(user) if user == self.frame.np.config.sections["server"]["login"]: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.OnPopupMenuFolderUser), ("", None), (2, _("Download"), self.popup_menu_downloads_folders, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), (2, _("Upload"), self.popup_menu_uploads_folders, self.OnPopupMenuDummy, gtk.STOCK_GO_UP), ("", None), ("#" + _("Copy _URL"), self.OnCopyDirURL, gtk.STOCK_COPY), ("#" + _("Open in File Manager"), self.OnFileManager, gtk.STOCK_OPEN) ) else: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.OnPopupMenuFolderUser), ("", None), (2, _("Download"), self.popup_menu_downloads_folders, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), ("", None), ("#" + _("Copy _URL"), self.OnCopyDirURL, gtk.STOCK_COPY) ) self.FolderTreeView.connect("button_press_event", self.OnFolderClicked) self.FolderTreeView.get_selection().connect("changed", self.OnSelectDir) # DecodedFilename, HSize, Bitrate, HLength, Size, Length, RawFilename self.FileStore = gtk.ListStore(str, str, str, str, gobject.TYPE_INT64, int, str) self.FileTreeView.set_model(self.FileStore) cols = InitialiseColumns( self.FileTreeView, [_("Filename"), 250, "text", self.CellDataFunc], [_("Size"), 100, "number", self.CellDataFunc], [_("Bitrate"), 70, "text", self.CellDataFunc], [_("Length"), 50, "number", self.CellDataFunc] ) cols[0].set_sort_column_id(0) cols[1].set_sort_column_id(4) cols[2].set_sort_column_id(2) cols[3].set_sort_column_id(5) self.FileStore.set_sort_column_id(0, gtk.SORT_ASCENDING) for i in range(4): parent = cols[i].get_widget().get_ancestor(gtk.Button) if parent: parent.connect('button_press_event', PressHeader) # Read Show / Hide column settings from last session self.FileTreeView.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.FileTreeView.set_headers_clickable(True) self.FileTreeView.set_property("rules-hint", True) self.file_popup_menu = PopupMenu(self.frame) if user == self.frame.np.config.sections["server"]["login"]: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.OnPopupMenuFileUser), ("", None), (2, _("Download"), self.popup_menu_downloads_files, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), (2, _("Upload"), self.popup_menu_uploads_files, self.OnPopupMenuDummy, gtk.STOCK_GO_UP), ("", None), ("#" + _("Copy _URL"), self.OnCopyURL, gtk.STOCK_COPY), ("#" + _("Send to _player"), self.OnPlayFiles, gtk.STOCK_MEDIA_PLAY), ("#" + _("Open in File Manager"), self.OnFileManager, gtk.STOCK_OPEN) ) else: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.OnPopupMenuFileUser), ("", None), (2, _("Download"), self.popup_menu_downloads_files, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), ("", None), ("#" + _("Copy _URL"), self.OnCopyURL, gtk.STOCK_COPY) ) self.FileTreeView.connect("button_press_event", self.OnFileClicked) self.ChangeColours() for name, object in self.__dict__.items(): if type(object) is PopupMenu: object.set_user(self.user) def OnPopupMenuDummy(self, widget, something): pass def Attach(self, widget=None): self.userbrowses.attach_tab(self.Main) def Detach(self, widget=None): self.userbrowses.detach_tab( self.Main, _("Nicotine+ User Browse: %(user)s (%(status)s)") % { 'user': self.user, 'status': [_("Offline"), _("Away"), _("Online")][self.status] } ) def ConnClose(self): pass def OnPopupMenuFileUser(self, widget): self.OnPopupMenuUsers(self.popup_menu_users2) def OnPopupMenuFolderUser(self, widget): self.OnPopupMenuUsers(self.popup_menu_users) def OnPopupMenuUsers(self, menu): items = menu.get_children() act = True items[0].set_sensitive(act) items[1].set_sensitive(act) items[2].set_sensitive(act) items[5].set_active(self.user in [i[0] for i in self.frame.np.config.sections["server"]["userlist"]]) items[6].set_active(self.user in self.frame.np.config.sections["server"]["banlist"]) items[7].set_active(self.user in self.frame.np.config.sections["server"]["ignorelist"]) for i in range(3, 8): items[i].set_sensitive(act) return True def ChangeColours(self): self.frame.SetTextBG(self.FileTreeView) self.frame.SetTextBG(self.FolderTreeView) self.frame.SetTextBG(self.entry4) self.frame.ChangeListFont(self.FolderTreeView, self.frame.np.config.sections["ui"]["browserfont"]) self.frame.ChangeListFont(self.FileTreeView, self.frame.np.config.sections["ui"]["browserfont"]) def CellDataFunc(self, column, cellrenderer, model, iter): colour = self.frame.np.config.sections["ui"]["search"] if colour == "": colour = None cellrenderer.set_property("foreground", colour) def decode(self, str): return self.frame.np.decode(str, self.encoding) def OnExpand(self, widget): if self.ExpandButton.get_active(): self.FolderTreeView.expand_all() self.ExpandDirectoriesImage.set_from_stock(gtk.STOCK_REMOVE, 4) else: self.FolderTreeView.collapse_all() self.ExpandDirectoriesImage.set_from_stock(gtk.STOCK_ADD, 4) dirs = list(self.directories.keys()) dirs.sort() if dirs != []: self.SetDirectory(dirs[0]) else: self.SetDirectory(None) def OnFolderClicked(self, widget, event): if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: self.OnDownloadDirectory(widget) return True elif event.button == 3: return self.OnFolderPopupMenu(widget, event) return False def OnFolderPopupMenu(self, widget, event): act = True if self.selected_folder is None: act = False items = self.folder_popup_menu.get_children() for item in items[1:]: item.set_sensitive(act) self.folder_popup_menu.popup(None, None, None, event.button, event.time) def SelectedFilesCallback(self, model, path, iter): rawfilename = self.FileStore.get_value(iter, 6) self.selected_files.append(rawfilename) def OnFileClicked(self, widget, event): if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: self.selected_files = [] self.FileTreeView.get_selection().selected_foreach(self.SelectedFilesCallback) self.OnDownloadFiles(widget) self.FileTreeView.get_selection().unselect_all() return True elif event.button == 3: return self.OnFilePopupMenu(widget, event) return False def OnFilePopupMenu(self, widget, event): self.selected_files = [] self.FileTreeView.get_selection().selected_foreach(self.SelectedFilesCallback) files = True multiple = False if len(self.selected_files) > 1: multiple = True if len(self.selected_files) >= 1: files = True else: files = False items = self.file_popup_menu.get_children() if self.user == self.frame.np.config.sections["server"]["login"]: items[2].set_sensitive(files) # Downloads items[3].set_sensitive(files) # Uploads items[5].set_sensitive(not multiple and files) # Copy URL items[6].set_sensitive(files) # Send to player else: items[2].set_sensitive(files) # Downloads items[4].set_sensitive(not multiple and files) # Copy URL self.FileTreeView.emit_stop_by_name("button_press_event") self.file_popup_menu.popup(None, None, None, event.button, event.time) return True def MakeNewModel(self, list): self.shares = list self.selected_folder = None self.selected_files = [] self.directories.clear() self.files.clear() self.DirStore.clear() # Compute the number of shared dirs and total size self.totalsize = 0 for dir, files in self.shares: for filedata in files: if filedata[2] < 18446744000000000000: self.totalsize += filedata[2] else: print "Unbelievable filesize: %s, %s" % (HumanizeBytes(filedata[2]), repr(filedata)) self.AmountShared.set_text(_("Shared: %s") % HumanizeBytes(self.totalsize)) self.NumDirectories.set_text(_("Dirs: %s") % len(self.shares)) # Generate the directory tree and select first directory currentdir = self.BrowseGetDirs() sel = self.FolderTreeView.get_selection() sel.unselect_all() if currentdir in self.directories: path = self.DirStore.get_path(self.directories[currentdir]) if path is not None: sel.select_path(path) self.FolderTreeView.set_sensitive(True) self.FileTreeView.set_sensitive(True) self.SaveButton.set_sensitive(True) if self.ExpandButton.get_active(): self.FolderTreeView.expand_all() else: self.FolderTreeView.collapse_all() def BrowseGetDirs(self): directory = "" dirseparator = '\\' # If there is no share if self.shares == []: # Set the model of the treeviex self.FolderTreeView.set_model(self.DirStore) # Sort the DirStore self.DirStore.set_sort_column_id(0, gtk.SORT_ASCENDING) return directory def builddicttree(p, s): """ Build recursively a hierarchical dict containing raw subdir 'p' is a reference to the parent 's' a list of the subdir of a path ex of 's': ['music', 'rock', 'doors'] """ if s: subdir = s.pop(0) if subdir not in p: p[subdir] = {} builddicttree(p[subdir], s) def buildgtktree(dictdir, parent, path): """ Build recursively self.directories with iters pointing to directories 'dictdir' is a hierarchical dict containing raw subdir 'parent' is the iter pointing to the parent 'path' is the current raw path """ # Foreach subdir for subdir in dictdir.keys(): if parent is None: # The first sudirs are attached to the root (None) current_path = subdir else: # Other sudirs futher down the path are attached to their parent current_path = dirseparator.join([path, subdir]) self.directories[current_path] = self.DirStore.append(parent, [self.decode(subdir), current_path]) # If there are subdirs futher down the path: recurse if len(dictdir[subdir]): buildgtktree(dictdir[subdir], self.directories[current_path], current_path) # For each shared dir we will complete the dictionnary dictdir = {} for dirshares, f in self.shares: # Split the path s = dirshares.split(dirseparator) # and build a hierarchical dictionnary containing raw subdir if len(s) >= 1: builddicttree(dictdir, s) # Append data to the DirStore buildgtktree(dictdir, None, None) # Select the first directory sortlist = list(self.directories.keys()) sortlist.sort() directory = sortlist[0] # Sort the DirStore self.DirStore.set_sort_column_id(0, gtk.SORT_ASCENDING) # Set the model of the treeviex self.FolderTreeView.set_model(self.DirStore) return directory def SetDirectory(self, directory): self.selected_folder = directory self.FileStore.clear() self.files.clear() found_dir = False for d, f in self.shares: if d == directory: found_dir = True files = f break if not found_dir: return for file in files: # DecodedFilename, HSize, Bitrate, HLength, Size, Length, RawFilename rl = 0 try: size = int(file[2]) except ValueError: size = 0 f = [self.decode(file[1]), Humanize(size)] if file[3] == "": f += ["", ""] else: # file[4] is for file types such as 'mp3' attrs = file[4] if attrs != [] and type(attrs) is list: if len(attrs) >= 3: br = str(attrs[0]) if attrs[2]: br = br + " (vbr)" try: rl = int(attrs[1]) except ValueError: rl = 0 l = "%i:%02i" % (rl / 60, rl % 60) f += [br, l] else: f += ["", ""] else: f += ["", ""] f += [long(size), rl, file[1]] try: self.files[f[0]] = self.FileStore.append(f) except Exception, error: displayTraceback()
class UserBrowse: def __init__(self, userbrowses, user, conn, data_dir): self.data_dir = data_dir # Build the window builder = gtk.Builder() builder.set_translation_domain('nicotine') builder.add_from_file( os.path.join(os.path.dirname(os.path.realpath(__file__)), "ui", "userbrowse.ui")) self.UserBrowseTab = builder.get_object("UserBrowseTab") for i in builder.get_objects(): try: self.__dict__[gtk.Buildable.get_name(i)] = i except TypeError: pass self.UserBrowseTab.remove(self.Main) self.UserBrowseTab.destroy() builder.connect_signals(self) self.userbrowses = userbrowses self.frame = userbrowses.frame self.user = user self.conn = conn # selected_folder is the current selected folder self.selected_folder = None self.search_list = [] self.query = None self.search_position = 0 self.selected_files = [] self.shares = [] # Iters for current DirStore self.directories = {} # Iters for current FileStore self.files = {} self.totalsize = 0 self.encoding, m = EncodingsMenu(self.frame.np, "userencoding", user) # Encoding Combobox self.Elist = {} self.EncodingStore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self.Encoding.set_model(self.EncodingStore) cell = gtk.CellRendererText() self.Encoding.pack_start(cell, True) self.Encoding.add_attribute(cell, 'text', 0) cell2 = gtk.CellRendererText() self.Encoding.pack_start(cell2, False) self.Encoding.add_attribute(cell2, 'text', 1) for item in m: self.Elist[item[1]] = self.EncodingStore.append([item[1], item[0]]) if self.encoding == item[1]: self.Encoding.set_active_iter(self.Elist[self.encoding]) self.DirStore = gtk.TreeStore(str, str) self.FolderTreeView.set_headers_visible(True) self.FolderTreeView.set_enable_tree_lines(True) cols = InitialiseColumns( self.FolderTreeView, [_("Directories"), -1, "text", self.CellDataFunc] # 0 ) cols[0].set_sort_column_id(0) self.popup_menu_users = PopupMenu(self.frame) self.popup_menu_users2 = PopupMenu(self.frame) for menu in [self.popup_menu_users, self.popup_menu_users2]: menu.setup(("#" + _("Send _message"), menu.OnSendMessage), ("#" + _("Show IP a_ddress"), menu.OnShowIPaddress), ("#" + _("Get user i_nfo"), menu.OnGetUserInfo), ("#" + _("Gi_ve privileges"), menu.OnGivePrivileges), ("", None), ("$" + _("_Add user to list"), menu.OnAddToList), ("$" + _("_Ban this user"), menu.OnBanUser), ("$" + _("_Ignore this user"), menu.OnIgnoreUser)) self.popup_menu_downloads_folders = PopupMenu(self.frame) self.popup_menu_downloads_folders.setup( ("#" + _("_Download directory"), self.OnDownloadDirectory), ("#" + _("Download directory _to..."), self.OnDownloadDirectoryTo), ("#" + _("Download _recursive"), self.OnDownloadDirectoryRecursive), ("#" + _("Download r_ecursive to..."), self.OnDownloadDirectoryRecursiveTo)) self.popup_menu_downloads_files = PopupMenu(self.frame) self.popup_menu_downloads_files.setup( ("#" + _("_Download file(s)"), self.OnDownloadFiles), ("#" + _("Download _to..."), self.OnDownloadFilesTo), ("", None), ("#" + _("_Download directory"), self.OnDownloadDirectory), ("#" + _("Download directory _to..."), self.OnDownloadDirectoryTo), ("#" + _("Download _recursive"), self.OnDownloadDirectoryRecursive), ("#" + _("Download r_ecursive to..."), self.OnDownloadDirectoryRecursiveTo)) self.popup_menu_uploads_folders = PopupMenu(self.frame) self.popup_menu_uploads_folders.setup( ("#" + _("Upload Directory to..."), self.OnUploadDirectoryTo), ("#" + _("Upload Directory recursive to..."), self.OnUploadDirectoryRecursiveTo)) self.popup_menu_uploads_files = PopupMenu(self.frame) self.popup_menu_uploads_files.setup( ("#" + _("Upload Directory to..."), self.OnUploadDirectoryTo), ("#" + _("Upload Directory recursive to..."), self.OnUploadDirectoryRecursiveTo), ("#" + _("Up_load file(s)"), self.OnUploadFiles)) self.folder_popup_menu = PopupMenu(self.frame) self.folder_popup_menu.set_user(user) if user == self.frame.np.config.sections["server"]["login"]: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.OnPopupMenuFolderUser), ("", None), (1, _("Download"), self.popup_menu_downloads_folders, self.OnPopupMenuDummy), (1, _("Upload"), self.popup_menu_uploads_folders, self.OnPopupMenuDummy), ("", None), ("#" + _("Copy _URL"), self.OnCopyDirURL), ("#" + _("Open in File Manager"), self.OnFileManager)) else: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.OnPopupMenuFolderUser), ("", None), (1, _("Download"), self.popup_menu_downloads_folders, self.OnPopupMenuDummy), ("", None), ("#" + _("Copy _URL"), self.OnCopyDirURL)) self.FolderTreeView.connect("button_press_event", self.OnFolderClicked) self.FolderTreeView.get_selection().connect("changed", self.OnSelectDir) # DecodedFilename, HSize, Bitrate, HLength, Size, Length, RawFilename self.FileStore = gtk.ListStore(str, str, str, str, gobject.TYPE_INT64, int, str) self.FileTreeView.set_model(self.FileStore) cols = InitialiseColumns( self.FileTreeView, [_("Filename"), 250, "text", self.CellDataFunc], [_("Size"), 100, "text", self.CellDataFunc], [_("Bitrate"), 70, "text", self.CellDataFunc], [_("Length"), 50, "text", self.CellDataFunc]) cols[0].set_sort_column_id(0) cols[1].set_sort_column_id(4) cols[2].set_sort_column_id(2) cols[3].set_sort_column_id(5) self.FileStore.set_sort_column_id(0, gtk.SORT_ASCENDING) for i in range(4): parent = cols[i].get_widget().get_ancestor(gtk.Button) if parent: parent.connect('button_press_event', PressHeader) # Read Show / Hide column settings from last session self.FileTreeView.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.FileTreeView.set_headers_clickable(True) self.FileTreeView.set_property("rules-hint", True) self.file_popup_menu = PopupMenu(self.frame) if user == self.frame.np.config.sections["server"]["login"]: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.OnPopupMenuFileUser), ("", None), (1, _("Download"), self.popup_menu_downloads_files, self.OnPopupMenuDummy), (1, _("Upload"), self.popup_menu_uploads_files, self.OnPopupMenuDummy), ("", None), ("#" + _("Copy _URL"), self.OnCopyURL), ("#" + _("Send to _player"), self.OnPlayFiles), ("#" + _("Open in File Manager"), self.OnFileManager)) else: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.OnPopupMenuFileUser), ("", None), (1, _("Download"), self.popup_menu_downloads_files, self.OnPopupMenuDummy), ("", None), ("#" + _("Copy _URL"), self.OnCopyURL)) self.FileTreeView.connect("button_press_event", self.OnFileClicked) self.ChangeColours() for name, object in self.__dict__.items(): if type(object) is PopupMenu: object.set_user(self.user) def OnPopupMenuDummy(self, widget): pass def Attach(self, widget=None): self.userbrowses.attach_tab(self.Main) def Detach(self, widget=None): self.userbrowses.detach_tab( self.Main, _("Nicotine+ User Browse: %(user)s (%(status)s)") % { 'user': self.user, 'status': [_("Offline"), _("Away"), _("Online")][self.status] }) def ConnClose(self): pass def OnPopupMenuFileUser(self, widget): self.OnPopupMenuUsers(self.popup_menu_users2) def OnPopupMenuFolderUser(self, widget): self.OnPopupMenuUsers(self.popup_menu_users) def OnPopupMenuUsers(self, menu): items = menu.get_children() act = True items[0].set_sensitive(act) items[1].set_sensitive(act) items[2].set_sensitive(act) items[5].set_active(self.user in [ i[0] for i in self.frame.np.config.sections["server"]["userlist"] ]) items[6].set_active( self.user in self.frame.np.config.sections["server"]["banlist"]) items[7].set_active( self.user in self.frame.np.config.sections["server"]["ignorelist"]) for i in range(3, 8): items[i].set_sensitive(act) return True def ChangeColours(self): self.frame.SetTextBG(self.FileTreeView) self.frame.SetTextBG(self.FolderTreeView) self.frame.SetTextBG(self.entry4) self.frame.ChangeListFont( self.FolderTreeView, self.frame.np.config.sections["ui"]["browserfont"]) self.frame.ChangeListFont( self.FileTreeView, self.frame.np.config.sections["ui"]["browserfont"]) def CellDataFunc(self, column, cellrenderer, model, iter): colour = self.frame.np.config.sections["ui"]["search"] if colour == "": colour = None cellrenderer.set_property("foreground", colour) def decode(self, str): return self.frame.np.decode(str, self.encoding) def OnExpand(self, widget): if self.ExpandButton.get_active(): self.FolderTreeView.expand_all() self.ExpandDirectoriesImage.set_from_stock(gtk.STOCK_REMOVE, 4) else: self.FolderTreeView.collapse_all() self.ExpandDirectoriesImage.set_from_stock(gtk.STOCK_ADD, 4) dirs = list(self.directories.keys()) dirs.sort() if dirs != []: self.SetDirectory(dirs[0]) else: self.SetDirectory(None) def OnFolderClicked(self, widget, event): if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: self.OnDownloadDirectory(widget) return True elif event.button == 3: return self.OnFolderPopupMenu(widget, event) return False def OnFolderPopupMenu(self, widget, event): act = True if self.selected_folder is None: act = False items = self.folder_popup_menu.get_children() for item in items[1:]: item.set_sensitive(act) self.folder_popup_menu.popup(None, None, None, event.button, event.time) def SelectedFilesCallback(self, model, path, iter): rawfilename = self.FileStore.get_value(iter, 6) self.selected_files.append(rawfilename) def OnFileClicked(self, widget, event): if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: self.selected_files = [] self.FileTreeView.get_selection().selected_foreach( self.SelectedFilesCallback) self.OnDownloadFiles(widget) self.FileTreeView.get_selection().unselect_all() return True elif event.button == 3: return self.OnFilePopupMenu(widget, event) return False def OnFilePopupMenu(self, widget, event): self.selected_files = [] self.FileTreeView.get_selection().selected_foreach( self.SelectedFilesCallback) files = True multiple = False if len(self.selected_files) > 1: multiple = True if len(self.selected_files) >= 1: files = True else: files = False items = self.file_popup_menu.get_children() if self.user == self.frame.np.config.sections["server"]["login"]: items[2].set_sensitive(files) # Downloads items[3].set_sensitive(files) # Uploads items[5].set_sensitive(not multiple and files) # Copy URL items[6].set_sensitive(files) # Send to player else: items[2].set_sensitive(files) # Downloads items[4].set_sensitive(not multiple and files) # Copy URL self.FileTreeView.emit_stop_by_name("button_press_event") self.file_popup_menu.popup(None, None, None, event.button, event.time) return True def MakeNewModel(self, list): self.shares = list self.selected_folder = None self.selected_files = [] self.directories.clear() self.files.clear() self.DirStore.clear() # Compute the number of shared dirs and total size self.totalsize = 0 for dir, files in self.shares: for filedata in files: if filedata[2] < 18446744000000000000: self.totalsize += filedata[2] else: print "Unbelievable filesize: %s, %s" % (HumanSize( filedata[2]), repr(filedata)) self.AmountShared.set_text(_("Shared: %s") % HumanSize(self.totalsize)) self.NumDirectories.set_text(_("Dirs: %s") % len(self.shares)) # Generate the directory tree and select first directory currentdir = self.BrowseGetDirs() sel = self.FolderTreeView.get_selection() sel.unselect_all() if currentdir in self.directories: path = self.DirStore.get_path(self.directories[currentdir]) if path is not None: sel.select_path(path) self.FolderTreeView.set_sensitive(True) self.FileTreeView.set_sensitive(True) self.SaveButton.set_sensitive(True) if self.ExpandButton.get_active(): self.FolderTreeView.expand_all() else: self.FolderTreeView.collapse_all() def BrowseGetDirs(self): directory = "" dirseparator = '\\' # If there is no share if self.shares == []: # Set the model of the treeviex self.FolderTreeView.set_model(self.DirStore) # Sort the DirStore self.DirStore.set_sort_column_id(0, gtk.SORT_ASCENDING) return directory def builddicttree(p, s): """ Build recursively a hierarchical dict containing raw subdir 'p' is a reference to the parent 's' a list of the subdir of a path ex of 's': ['music', 'rock', 'doors'] """ if s: subdir = s.pop(0) if subdir not in p: p[subdir] = {} builddicttree(p[subdir], s) def buildgtktree(dictdir, parent, path): """ Build recursively self.directories with iters pointing to directories 'dictdir' is a hierarchical dict containing raw subdir 'parent' is the iter pointing to the parent 'path' is the current raw path """ # Foreach subdir for subdir in dictdir.keys(): if parent is None: # The first sudirs are attached to the root (None) current_path = subdir else: # Other sudirs futher down the path are attached to their parent current_path = dirseparator.join([path, subdir]) self.directories[current_path] = self.DirStore.append( parent, [self.decode(subdir), current_path]) # If there are subdirs futher down the path: recurse if len(dictdir[subdir]): buildgtktree(dictdir[subdir], self.directories[current_path], current_path) # For each shared dir we will complete the dictionnary dictdir = {} for dirshares, f in self.shares: # Split the path s = dirshares.split(dirseparator) # and build a hierarchical dictionnary containing raw subdir if len(s) >= 1: builddicttree(dictdir, s) # Append data to the DirStore buildgtktree(dictdir, None, None) # Select the first directory sortlist = list(self.directories.keys()) sortlist.sort() directory = sortlist[0] # Sort the DirStore self.DirStore.set_sort_column_id(0, gtk.SORT_ASCENDING) # Set the model of the treeviex self.FolderTreeView.set_model(self.DirStore) return directory def SetDirectory(self, directory): self.selected_folder = directory self.FileStore.clear() self.files.clear() found_dir = False for d, f in self.shares: if d == directory: found_dir = True files = f break if not found_dir: return for file in files: # DecodedFilename, HSize, Bitrate, HLength, Size, Length, RawFilename rl = 0 try: size = int(file[2]) except ValueError: size = 0 f = [self.decode(file[1]), Humanize(size)] if file[3] == "": f += ["", ""] else: # file[4] is for file types such as 'mp3' attrs = file[4] if attrs != [] and type(attrs) is list: if len(attrs) >= 3: br = str(attrs[0]) if attrs[2]: br = br + " (vbr)" try: rl = int(attrs[1]) except ValueError: rl = 0 l = "%i:%02i" % (rl / 60, rl % 60) f += [br, l] else: f += ["", ""] else: f += ["", ""] f += [long(size), rl, file[1]] try: self.files[f[0]] = self.FileStore.append(f) except Exception, error: displayTraceback()
class UserBrowse: def __init__(self, userbrowses, user, conn): self.wTree = gtk.glade.XML(os.path.join(os.path.dirname(os.path.realpath(__file__)), "userbrowse.glade" ), None, "nicotine" ) widgets = self.wTree.get_widget_prefix("") for i in widgets: name = gtk.glade.get_widget_name(i) self.__dict__[name] = i self.UserBrowseTab.remove(self.Main) self.UserBrowseTab.destroy() #UserBrowseTab.__init__(self, False) self.wTree.signal_autoconnect(self) self.userbrowses = userbrowses self.frame = userbrowses.frame #self.tooltips = self.frame.tooltips #if not self.frame.np.config.sections["ui"]["tooltips"]: # self.tooltips.disable() self.user = user self.conn = conn # selected_folder is a path for TreeStore, i.e. a tuple self.selected_folder = None self.search_list = [] self.query = None self.search_position = 0 self.selected_files = [] self.shares = [] self.Elist = {} # Iters for current FileStore self.files = {} self.totalsize = 0 self.encoding, m = EncodingsMenu(self.frame.np, "userencoding", user) self.EncodingStore = gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_STRING) self.Encoding.set_size_request(100, -1) self.Encoding.set_model(self.EncodingStore) cell = gtk.CellRendererText() self.Encoding.pack_start(cell, True) self.Encoding.add_attribute(cell, 'text', 0) cell2 = gtk.CellRendererText() self.Encoding.pack_start(cell2, False) self.Encoding.add_attribute(cell2, 'text', 1) for item in m: self.Elist[item[1]] = self.EncodingStore.append([item[1], item[0] ]) if self.encoding == item[1]: self.Encoding.set_active_iter(self.Elist[self.encoding]) # Is there a need for this here? self.DirStore = UglyTree([gobject.TYPE_STRING, gobject.TYPE_STRING]) self.FolderTreeView.set_model(self.DirStore) self.FolderTreeView.set_headers_visible(True) # GTK 2.10 if gtk.pygtk_version[0] >= 2 and gtk.pygtk_version[1] >= 10: self.FolderTreeView.set_enable_tree_lines(True) cols = InitialiseColumns(self.FolderTreeView, [_("Directories"), -1, "text", self.CellDataFunc], #0 ) self.popup_menu_users = PopupMenu(self.frame) self.popup_menu_users2 = PopupMenu(self.frame) for menu in [self.popup_menu_users, self.popup_menu_users2]: menu.setup( ("#" + _("Send _message"), menu.OnSendMessage, gtk.STOCK_EDIT), ("#" + _("Show IP a_ddress"), menu.OnShowIPaddress, gtk.STOCK_NETWORK), ("#" + _("Get user i_nfo"), menu.OnGetUserInfo, gtk.STOCK_DIALOG_INFO), ("#" + _("Gi_ve privileges"), menu.OnGivePrivileges, gtk.STOCK_JUMP_TO), ("", None), ("$" + _("_Add user to list"), menu.OnAddToList), ("$" + _("_Ban this user"), menu.OnBanUser), ("$" + _("_Ignore this user"), menu.OnIgnoreUser), ) self.popup_menu_downloads_folders = PopupMenu(self.frame) self.popup_menu_downloads_folders.setup( ("#" + _("_Download directory"), self.OnDownloadDirectory, gtk.STOCK_GO_DOWN), ("#" + _("Download directory _to..."), self.OnDownloadDirectoryTo, gtk.STOCK_GO_DOWN), ("#" + _("Download _recursive"), self.OnDownloadDirectoryRecursive, gtk.STOCK_GO_DOWN), ("#" + _("Download r_ecursive to..."), self.OnDownloadDirectoryRecursiveTo, gtk.STOCK_GO_DOWN), ) self.popup_menu_downloads_files = PopupMenu(self.frame) self.popup_menu_downloads_files.setup( ("#" + _("_Download file(s)"), self.OnDownloadFiles, gtk.STOCK_GO_DOWN), ("#" + _("Download _to..."), self.OnDownloadFilesTo, gtk.STOCK_GO_DOWN), ("", None), ("#" + _("_Download directory"), self.OnDownloadDirectory, gtk.STOCK_GO_DOWN), ("#" + _("Download directory _to..."), self.OnDownloadDirectoryTo, gtk.STOCK_GO_DOWN), ("#" + _("Download _recursive"), self.OnDownloadDirectoryRecursive, gtk.STOCK_GO_DOWN), ("#" + _("Download r_ecursive to..."), self.OnDownloadDirectoryRecursiveTo, gtk.STOCK_GO_DOWN), ) self.popup_menu_uploads_folders = PopupMenu(self.frame) self.popup_menu_uploads_folders.setup( ("#" + _("Upload Directory to..."), self.OnUploadDirectoryTo, gtk.STOCK_GO_UP), ("#" + _("Upload Directory recursive to..."), self.OnUploadDirectoryRecursiveTo, gtk.STOCK_GO_UP), ) self.popup_menu_uploads_files = PopupMenu(self.frame) self.popup_menu_uploads_files.setup( ("#" + _("Upload Directory to..."), self.OnUploadDirectoryTo, gtk.STOCK_GO_UP), ("#" + _("Upload Directory recursive to..."), self.OnUploadDirectoryRecursiveTo, gtk.STOCK_GO_UP), ("#" + _("Up_load file(s)"), self.OnUploadFiles, gtk.STOCK_GO_UP), ) self.folder_popup_menu = PopupMenu(self.frame) self.folder_popup_menu.set_user(user) if user == self.frame.np.config.sections["server"]["login"]: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.OnPopupMenuFolderUser), ("", None), (2, _("Download"), self.popup_menu_downloads_folders, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), (2, _("Upload"), self.popup_menu_uploads_folders, self.OnPopupMenuDummy, gtk.STOCK_GO_UP), ("", None), ("#" + _("Copy _URL"), self.OnCopyDirURL, gtk.STOCK_COPY), ("#" + _("Open in File Manager"), self.OnFileManager, gtk.STOCK_OPEN), ) else: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.OnPopupMenuFolderUser), ("", None), (2, _("Download"), self.popup_menu_downloads_folders, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), ("", None), ("#" + _("Copy _URL"), self.OnCopyDirURL, gtk.STOCK_COPY), ) self.FolderTreeView.connect("button_press_event", self.OnFolderClicked) self.FolderTreeView.get_selection().connect("changed", self.OnSelectDir) # DecodedFilename, HSize, Bitrate, HLength, Size, Length, RawFilename self.FileStore = gtk.ListStore(str, str, str, str, gobject.TYPE_INT64, int, str) self.FileTreeView.set_model(self.FileStore) cols = InitialiseColumns(self.FileTreeView, [_("Filename"), 250, "text", self.CellDataFunc], [_("Size"), 100, "number", self.CellDataFunc], [_("Bitrate"), 70, "text", self.CellDataFunc], [_("Length"), 50, "number", self.CellDataFunc], ) cols[0].set_sort_column_id(0) cols[1].set_sort_column_id(4) cols[2].set_sort_column_id(2) cols[3].set_sort_column_id(5) self.FileStore.set_sort_column_id(0, gtk.SORT_ASCENDING) for i in range (4): parent = cols[i].get_widget().get_ancestor(gtk.Button) if parent: parent.connect('button_press_event', PressHeader) # Read Show / Hide column settings from last session self.FileTreeView.get_selection().set_mode(gtk.SELECTION_MULTIPLE) self.FileTreeView.set_headers_clickable(True) self.FileTreeView.set_property("rules-hint", True) self.file_popup_menu = PopupMenu(self.frame) if user == self.frame.np.config.sections["server"]["login"]: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.OnPopupMenuFileUser), ("", None), (2, _("Download"), self.popup_menu_downloads_files, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), (2, _("Upload"), self.popup_menu_uploads_files, self.OnPopupMenuDummy, gtk.STOCK_GO_UP), ("", None), ("#" + _("Copy _URL"), self.OnCopyURL, gtk.STOCK_COPY), ("#" + _("Send to _player"), self.OnPlayFiles, gtk.STOCK_MEDIA_PLAY), ("#" + _("Open in File Manager"), self.OnFileManager, gtk.STOCK_OPEN), ) else: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.OnPopupMenuFileUser), ("", None), (2, _("Download"), self.popup_menu_downloads_files, self.OnPopupMenuDummy, gtk.STOCK_GO_DOWN), ("", None), ("#" + _("Copy _URL"), self.OnCopyURL, gtk.STOCK_COPY), ) self.FileTreeView.connect("button_press_event", self.OnFileClicked) self.ChangeColours() for name, object in self.__dict__.items(): if type(object) is PopupMenu: object.set_user(self.user) def OnPopupMenuDummy(self, widget, something): pass def Attach(self, widget=None): self.userbrowses.attach_tab(self.Main) def Detach(self, widget=None): self.userbrowses.detach_tab(self.Main, _("Nicotine+ User Browse: %s (%s)") % (self.user, [_("Offline"), _("Away"), _("Online")][self.status])) def ConnClose(self): pass def OnPopupMenuFileUser(self, widget): self.OnPopupMenuUsers(self.popup_menu_users2) def OnPopupMenuFolderUser(self, widget): self.OnPopupMenuUsers(self.popup_menu_users) def OnPopupMenuUsers(self, menu): items = menu.get_children() act = True items[0].set_sensitive(act) items[1].set_sensitive(act) items[2].set_sensitive(act) items[5].set_active(self.user in [i[0] for i in self.frame.np.config.sections["server"]["userlist"]]) items[6].set_active(self.user in self.frame.np.config.sections["server"]["banlist"]) items[7].set_active(self.user in self.frame.np.config.sections["server"]["ignorelist"]) for i in range(3, 8): items[i].set_sensitive(act) return True def ChangeColours(self): self.frame.SetTextBG(self.FileTreeView) self.frame.SetTextBG(self.FolderTreeView) self.frame.SetTextBG(self.entry4) self.frame.ChangeListFont(self.FolderTreeView, self.frame.np.config.sections["ui"]["browserfont"]) self.frame.ChangeListFont(self.FileTreeView, self.frame.np.config.sections["ui"]["browserfont"]) def CellDataFunc(self, column, cellrenderer, model, iter): colour = self.frame.np.config.sections["ui"]["search"] if colour == "": colour = None cellrenderer.set_property("foreground", colour) def decode(self, str): return self.frame.np.decode(str, self.encoding) def OnExpand(self, widget): if self.ExpandButton.get_active(): self.FolderTreeView.expand_all() self.ExpandDirectoriesImage.set_from_stock(gtk.STOCK_REMOVE, 4) else: self.FolderTreeView.collapse_all() self.ExpandDirectoriesImage.set_from_stock(gtk.STOCK_ADD, 4) nchildren, node = self.DirStore.GetChildren(0,0) if nchildren > 0: self.SetDirectory((0,)) else: self.SetDirectory(None) def OnFolderClicked(self, widget, event): if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: self.OnDownloadDirectory(widget) return True elif event.button == 3: return self.OnFolderPopupMenu(widget, event) return False def OnFolderPopupMenu(self, widget, event): act = True if self.selected_folder is None: act = False items = self.folder_popup_menu.get_children() for item in items[1:]: item.set_sensitive(act) self.folder_popup_menu.popup(None, None, None, event.button, event.time) def SelectedFilesCallback(self, model, path, iter): rawfilename = self.FileStore.get_value(iter, 6) self.selected_files.append(rawfilename) def OnFileClicked(self, widget, event): if event.button == 1 and event.type == gtk.gdk._2BUTTON_PRESS: self.selected_files = [] self.FileTreeView.get_selection().selected_foreach(self.SelectedFilesCallback) self.OnDownloadFiles(widget) self.FileTreeView.get_selection().unselect_all() return True elif event.button == 3: return self.OnFilePopupMenu(widget, event) return False def OnFilePopupMenu(self, widget, event): self.selected_files = [] self.FileTreeView.get_selection().selected_foreach(self.SelectedFilesCallback) files = True multiple = False if len(self.selected_files) > 1: multiple = True if len(self.selected_files) >= 1: files = True else: files = False items = self.file_popup_menu.get_children() if self.user == self.frame.np.config.sections["server"]["login"]: items[2].set_sensitive(files) # Downloads items[3].set_sensitive(files) # Uploads items[5].set_sensitive(not multiple and files) # Copy URL items[6].set_sensitive(files) # Send to player else: items[2].set_sensitive(files) # Downloads items[4].set_sensitive(not multiple and files) # Copy URL self.FileTreeView.emit_stop_by_name("button_press_event") self.file_popup_menu.popup(None, None, None, event.button, event.time) return True def MakeNewModel(self, list): self.shares = list self.selected_folder = None self.selected_files = [] self.files.clear() # self.DirStore.clear() self.DirStore=None self.totalsize = 0 self.FolderTreeView.set_model(None) self.DirStore = UglyTree([gobject.TYPE_STRING, gobject.TYPE_STRING], list) for dir, files in self.shares: for filedata in files: if filedata[2] < 18446744000000000000: self.totalsize += filedata[2] else: print "Unbelievable filesize: %s, %s" % (HumanizeBytes(filedata[2]), repr(filedata)) self.AmountShared.set_text(_("Shared: %s") % HumanizeBytes(self.totalsize)) self.NumDirectories.set_text(_("Dirs: %s") % len(self.shares)) self.FolderTreeView.set_model(self.DirStore) sel = self.FolderTreeView.get_selection() sel.unselect_all() # Select first directory sel.select_path((0,)) self.FolderTreeView.set_sensitive(True) self.FileTreeView.set_sensitive(True) self.SaveButton.set_sensitive(True) if self.ExpandButton.get_active(): self.FolderTreeView.expand_all() else: self.FolderTreeView.collapse_all() def SetDirectory(self, path): self.selected_folder = path self.FileStore.clear() self.files.clear() node = self.DirStore.on_get_iter(path) if node == None or node == (0,0): return files = self.DirStore.GetData(node) for file in files: # DecodedFilename, HSize, Bitrate, HLength, Size, Length, RawFilename rl = 0 try: size = int(file[2]) except ValueError: size = 0 f = [self.decode(file[1]), Humanize(size)] if file[3] == "": f += ["", ""] else: #file[4] is for file types such as 'mp3' attrs = file[4] if attrs != [] and type(attrs) is list: if len(attrs) >= 3: br = str(attrs[0]) if len(attrs) > 2 and attrs[2]: br = br + _(" (vbr)") try: rl = int(attrs[1]) except ValueError: rl = 0 l = "%i:%02i" % (rl / 60, rl % 60) f += [br, l] else: f += ["", ""] else: f += ["", ""] f += [long(size), rl, file[1]] try: self.files[f[0]] = self.FileStore.append(f) except Exception, error: displayTraceback()