def __init__(self, searches, text, id, mode, remember, showtab): self.searches = searches self.frame = searches.frame # 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", "search.ui")) self.search_tab = builder.get_object("SearchTab") for i in builder.get_objects(): try: self.__dict__[Gtk.Buildable.get_name(i)] = i except TypeError: pass self.search_tab.remove(self.Main) self.search_tab.destroy() builder.connect_signals(self) self.text = text self.searchterm_words_include = [p for p in text.lower().split() if not p.startswith('-')] self.searchterm_words_ignore = [p[1:] for p in text.lower().split() if p.startswith('-') and len(p) > 1] self.id = id self.mode = mode self.remember = remember self.showtab = showtab self.usersiters = {} self.directoryiters = {} self.users = set() self.all_data = [] self.filters = None self.resultslimit = 2000 self.numvisibleresults = 0 self.operators = { '<': operator.lt, '<=': operator.le, '==': operator.eq, '!=': operator.ne, '>=': operator.ge, '>': operator.gt } fill_file_grouping_combobox(self.ResultGrouping) self.ResultGrouping.set_active(self.frame.np.config.sections["searches"]["group_searches"]) self.ResultGrouping.connect("changed", self.on_group) self.ExpandButton.set_active(self.frame.np.config.sections["searches"]["expand_searches"]) self.ExpandButton.connect("toggled", self.on_toggle_expand_all) if mode > 0: self.RememberCheckButton.set_sensitive(False) self.RememberCheckButton.set_active(remember) """ Columns """ self.ResultsList.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.ResultsList.set_enable_tree_lines(True) self.ResultsList.set_headers_clickable(True) self.ResultsList.set_rubber_banding(True) if self.ResultGrouping.get_active() > 0: # Group by folder or user self.ResultsList.set_show_expanders(True) else: self.ResultsList.set_show_expanders(False) self.resultsmodel = Gtk.TreeStore( GObject.TYPE_UINT64, # (0) num str, # (1) user GObject.TYPE_OBJECT, # (2) flag str, # (3) immediatedl str, # (4) h_speed str, # (5) h_queue str, # (6) directory str, # (7) filename str, # (8) h_size str, # (9) h_bitrate str, # (10) length GObject.TYPE_UINT64, # (11) bitrate str, # (12) fullpath str, # (13) country GObject.TYPE_UINT64, # (14) size GObject.TYPE_UINT64, # (15) speed GObject.TYPE_UINT64 # (16) queue ) widths = self.frame.np.config.sections["columns"]["filesearch_widths"] cols = initialise_columns( self.ResultsList, [_("ID"), widths[0], "text", self.cell_data_func], [_("User"), widths[1], "text", self.cell_data_func], [_("Country"), widths[2], "pixbuf"], [_("Immediate Download"), widths[3], "center", self.cell_data_func], [_("Speed"), widths[4], "number", self.cell_data_func], [_("In queue"), widths[5], "center", self.cell_data_func], [_("Directory"), widths[6], "text", self.cell_data_func], [_("Filename"), widths[7], "text", self.cell_data_func], [_("Size"), widths[8], "number", self.cell_data_func], [_("Bitrate"), widths[9], "number", self.cell_data_func], [_("Length"), widths[10], "number", self.cell_data_func] ) self.col_num, self.col_user, self.col_country, self.col_immediate, self.col_speed, self.col_queue, self.col_directory, self.col_file, self.col_size, self.col_bitrate, self.col_length = cols if self.ResultGrouping.get_active() > 0: # Group by folder or user self.ResultsList.get_columns()[0].set_visible(False) self.ExpandButton.show() hide_columns(cols, self.frame.np.config.sections["columns"]["filesearch_columns"]) self.col_num.set_sort_column_id(0) self.col_user.set_sort_column_id(1) self.col_country.set_sort_column_id(13) self.col_immediate.set_sort_column_id(3) self.col_speed.set_sort_column_id(15) self.col_queue.set_sort_column_id(16) self.col_directory.set_sort_column_id(6) self.col_file.set_sort_column_id(7) self.col_size.set_sort_column_id(14) self.col_bitrate.set_sort_column_id(11) self.col_length.set_sort_column_id(10) self.col_country.get_widget().hide() self.ResultsList.set_model(self.resultsmodel) self.ResultsList.connect("button_press_event", self.on_list_clicked) self.change_colours() """ Filters """ self.filter_bitrate_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterBitrate.set_model(self.filter_bitrate_model) self.FilterBitrate.set_entry_text_column(0) self.filter_size_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterSize.set_model(self.filter_size_model) self.FilterSize.set_entry_text_column(0) self.filter_country_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterCountry.set_model(self.filter_country_model) self.FilterCountry.set_entry_text_column(0) self.filter_in_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterIn.set_model(self.filter_in_model) self.FilterIn.set_entry_text_column(0) self.filter_out_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterOut.set_model(self.filter_out_model) self.FilterOut.set_entry_text_column(0) self.populate_filters() self.FilterSize.clear() sizecell = Gtk.CellRendererText() sizecell.set_property("xalign", 1) self.FilterSize.pack_start(sizecell, True) self.FilterSize.add_attribute(sizecell, "text", 0) self.FilterBitrate.clear() bit_cell = Gtk.CellRendererText() bit_cell.set_property("xalign", 1) self.FilterBitrate.pack_start(bit_cell, True) self.FilterBitrate.add_attribute(bit_cell, "text", 0) self.FilterIn.connect("changed", self.on_filter_changed) self.FilterOut.connect("changed", self.on_filter_changed) self.FilterSize.connect("changed", self.on_filter_changed) self.FilterBitrate.connect("changed", self.on_filter_changed) self.FilterCountry.connect("changed", self.on_filter_changed) self.FilterIn.get_child().connect("activate", self.on_refilter) self.FilterOut.get_child().connect("activate", self.on_refilter) self.FilterSize.get_child().connect("activate", self.on_refilter) self.FilterBitrate.get_child().connect("activate", self.on_refilter) self.FilterCountry.get_child().connect("activate", self.on_refilter) """ Popup """ self.popup_menu_users = PopupMenu(self.frame, False) self.popup_menu = popup = PopupMenu(self.frame) popup.setup( ("#" + _("_Download file(s)"), self.on_download_files), ("#" + _("Download file(s) _to..."), self.on_download_files_to), ("#" + _("Download _folder(s)"), self.on_download_folders), ("#" + _("Download f_older(s) to..."), self.on_download_folders_to), ("#" + _("View Metadata of file(s)"), self.on_search_meta), ("", None), ("#" + _("Copy _URL"), self.on_copy_url), ("#" + _("Copy folder U_RL"), self.on_copy_dir_url), ("", None), (1, _("User(s)"), self.popup_menu_users, self.on_popup_menu_users) )
def __init__(self, searches, text, id, mode, remember, showtab): self.searches = searches self.frame = searches.frame # Build the window load_ui_elements(self, os.path.join(self.frame.gui_dir, "ui", "search.ui")) self.text = text self.searchterm_words_include = [ p for p in text.lower().split() if not p.startswith('-') ] self.searchterm_words_ignore = [ p[1:] for p in text.lower().split() if p.startswith('-') and len(p) > 1 ] self.id = id self.mode = mode self.remember = remember self.showtab = showtab self.usersiters = {} self.directoryiters = {} self.users = set() self.all_data = [] self.filters = None self.resultslimit = 2000 self.numvisibleresults = 0 self.operators = { '<': operator.lt, '<=': operator.le, '==': operator.eq, '!=': operator.ne, '>=': operator.ge, '>': operator.gt } if mode != "global": self.RememberCheckButton.set_sensitive(False) self.RememberCheckButton.set_active(remember) """ Columns """ self.ResultsList.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.ResultsList.set_enable_tree_lines(True) self.ResultsList.set_headers_clickable(True) self.ResultsList.set_rubber_banding(True) self.resultsmodel = Gtk.TreeStore( GObject.TYPE_UINT64, # (0) num str, # (1) user GObject.TYPE_OBJECT, # (2) flag str, # (3) immediatedl str, # (4) h_speed str, # (5) h_queue str, # (6) directory str, # (7) filename str, # (8) h_size str, # (9) h_bitrate str, # (10) length GObject.TYPE_UINT64, # (11) bitrate str, # (12) fullpath str, # (13) country GObject.TYPE_UINT64, # (14) size GObject.TYPE_UINT64, # (15) speed GObject.TYPE_UINT64 # (16) queue ) widths = self.frame.np.config.sections["columns"]["filesearch_widths"] cols = initialise_columns( self.ResultsList, [_("ID"), widths[0], "text", self.cell_data_func], [_("User"), widths[1], "text", self.cell_data_func], [_("Country"), widths[2], "pixbuf"], [ _("Immediate Download"), widths[3], "center", self.cell_data_func ], [_("Speed"), widths[4], "number", self.cell_data_func], [_("In Queue"), widths[5], "center", self.cell_data_func], [_("Folder"), widths[6], "text", self.cell_data_func], [_("Filename"), widths[7], "text", self.cell_data_func], [_("Size"), widths[8], "number", self.cell_data_func], [_("Bitrate"), widths[9], "number", self.cell_data_func], [_("Length"), widths[10], "number", self.cell_data_func]) self.col_num, self.col_user, self.col_country, self.col_immediate, self.col_speed, self.col_queue, self.col_directory, self.col_file, self.col_size, self.col_bitrate, self.col_length = cols hide_columns( cols, self.frame.np.config.sections["columns"]["filesearch_columns"]) self.col_num.set_sort_column_id(0) self.col_user.set_sort_column_id(1) self.col_country.set_sort_column_id(13) self.col_immediate.set_sort_column_id(3) self.col_speed.set_sort_column_id(15) self.col_queue.set_sort_column_id(16) self.col_directory.set_sort_column_id(6) self.col_file.set_sort_column_id(7) self.col_size.set_sort_column_id(14) self.col_bitrate.set_sort_column_id(11) self.col_length.set_sort_column_id(10) self.col_country.get_widget().hide() self.ResultsList.set_model(self.resultsmodel) self.ResultsList.connect("button_press_event", self.on_list_clicked) self.ResultsList.connect("key-press-event", self.on_key_press_event) self.update_visuals() """ Filters """ self.filter_bitrate_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterBitrate.set_model(self.filter_bitrate_model) self.FilterBitrate.set_entry_text_column(0) self.filter_size_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterSize.set_model(self.filter_size_model) self.FilterSize.set_entry_text_column(0) self.filter_country_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterCountry.set_model(self.filter_country_model) self.FilterCountry.set_entry_text_column(0) self.filter_in_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterIn.set_model(self.filter_in_model) self.FilterIn.set_entry_text_column(0) self.filter_out_model = Gtk.ListStore(GObject.TYPE_STRING) self.FilterOut.set_model(self.filter_out_model) self.FilterOut.set_entry_text_column(0) self.populate_filters() self.FilterSize.clear() sizecell = Gtk.CellRendererText() sizecell.set_property("xalign", 1) self.FilterSize.pack_start(sizecell, True) self.FilterSize.add_attribute(sizecell, "text", 0) self.FilterBitrate.clear() bit_cell = Gtk.CellRendererText() bit_cell.set_property("xalign", 1) self.FilterBitrate.pack_start(bit_cell, True) self.FilterBitrate.add_attribute(bit_cell, "text", 0) self.FilterIn.connect("changed", self.on_filter_changed) self.FilterOut.connect("changed", self.on_filter_changed) self.FilterSize.connect("changed", self.on_filter_changed) self.FilterBitrate.connect("changed", self.on_filter_changed) self.FilterCountry.connect("changed", self.on_filter_changed) self.FilterIn.get_child().connect("activate", self.on_refilter) self.FilterOut.get_child().connect("activate", self.on_refilter) self.FilterSize.get_child().connect("activate", self.on_refilter) self.FilterBitrate.get_child().connect("activate", self.on_refilter) self.FilterCountry.get_child().connect("activate", self.on_refilter) """ Popup """ self.popup_menu_users = PopupMenu(self.frame, False) self.popup_menu = popup = PopupMenu(self.frame) popup.setup( ("#" + _("_Download File(s)"), self.on_download_files), ("#" + _("Download File(s) _To..."), self.on_download_files_to), ("#" + _("Download _Folder(s)"), self.on_download_folders), ("#" + _("Download F_older(s) To..."), self.on_download_folders_to), ("#" + _("_Browse Folder"), self.on_browse_folder), ("#" + _("File _Properties"), self.on_file_properties), ("", None), ("#" + _("Copy _File Path"), self.on_copy_file_path), ("#" + _("Copy _URL"), self.on_copy_url), ("#" + _("Copy Folder U_RL"), self.on_copy_dir_url), ("", None), (1, _("User(s)"), self.popup_menu_users, self.on_popup_menu_users)) """ Grouping """ self.ResultGrouping.set_active( self.frame.np.config.sections["searches"]["group_searches"]) self.ExpandButton.set_active( self.frame.np.config.sections["searches"]["expand_searches"])
def __init__(self, frame, widget, type): self.frame = frame self.widget = widget self.type = type self.last_ui_update = self.last_save = time() self.list = None self.users = {} self.paths = {} # Status list self.statuses = {} self.statuses["Waiting for download"] = _("Waiting for download") self.statuses["Requesting file"] = _("Requesting file") self.statuses["Initializing transfer"] = _("Initializing transfer") self.statuses["Cannot connect"] = _("Cannot connect") self.statuses["Waiting for peer to connect"] = _( "Waiting for peer to connect") self.statuses["Connecting"] = _("Connecting") self.statuses["Getting address"] = _("Getting address") self.statuses["Getting status"] = _("Getting status") self.statuses["Queued"] = _("Queued") self.statuses["User logged off"] = _("User logged off") self.statuses["Aborted"] = _("Aborted") self.statuses["Finished"] = _("Finished") self.statuses["Paused"] = _("Paused") self.statuses["Transferring"] = _("Transferring") self.statuses["Filtered"] = _("Filtered") self.statuses["Connection closed by peer"] = _( "Connection closed by peer") self.statuses["File not shared"] = _("File not shared") self.statuses["File not shared."] = _( "File not shared" ) # The official client sends a variant containing a dot self.statuses["Establishing connection"] = _("Establishing connection") self.statuses["Download directory error"] = _( "Download directory error") self.statuses["Local file error"] = _("Local file error") self.statuses["Remote file error"] = _("Remote file error") # String templates self.extension_list_template = _("All %(ext)s") self.files_template = _("%(number)2s files ") widget.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) widget.set_enable_tree_lines(True) widget.set_rubber_banding(True) self.transfersmodel = Gtk.TreeStore( str, # (0) user str, # (1) path str, # (2) file name str, # (3) status str, # (4) hqueue position GObject.TYPE_UINT64, # (5) percent str, # (6) hsize str, # (7) hspeed str, # (8) htime elapsed str, # (9) time left str, # (10) path str, # (11) status (non-translated) GObject.TYPE_UINT64, # (12) size GObject.TYPE_UINT64, # (13) current bytes GObject.TYPE_UINT64, # (14) speed GObject.TYPE_UINT64, # (15) time elapsed GObject.TYPE_UINT64, # (16) file count GObject.TYPE_UINT64, # (17) queue position ) text_color = self.frame.np.config.sections["ui"]["search"] widths = self.frame.np.config.sections["columns"]["{}_widths".format( type)] self.cols = cols = initialise_columns( widget, [_("User"), widths[0], "text", None, (text_color, None)], [_("Path"), widths[1], "text", None, (text_color, None)], [_("Filename"), widths[2], "text", None, (text_color, None)], [_("Status"), widths[3], "text", None, (text_color, None)], [ _("Queue Position"), widths[4], "number", None, (text_color, None) ], [_("Percent"), widths[5], "progress"], [_("Size"), widths[6], "number", None, (text_color, None)], [_("Speed"), widths[7], "number", None, (text_color, None)], [_("Time elapsed"), widths[8], "number", None, (text_color, None)], [_("Time left"), widths[9], "number", None, (text_color, None)], ) self.col_user, self.col_path, self.col_filename, self.col_status, self.col_position, self.col_percent, self.col_human_size, self.col_human_speed, self.col_time_elapsed, self.col_time_left = cols hide_columns( cols, self.frame.np.config.sections["columns"][self.type + "_columns"]) self.col_user.set_sort_column_id(0) self.col_path.set_sort_column_id(1) self.col_filename.set_sort_column_id(2) self.col_status.set_sort_column_id(11) self.col_position.set_sort_column_id(17) self.col_percent.set_sort_column_id(5) self.col_human_size.set_sort_column_id(12) self.col_human_speed.set_sort_column_id(14) self.col_time_elapsed.set_sort_column_id(8) self.col_time_left.set_sort_column_id(9) widget.set_model(self.transfersmodel) widget.connect("button_press_event", self.on_popup_menu, "mouse") widget.connect("key-press-event", self.on_key_press_event) self.update_colours()
def __init__(self, frame): # Build the window self.frame = frame config = self.frame.np.config.sections load_ui_elements( self, os.path.join(self.frame.gui_dir, "ui", "buddylist.ui")) self.frame.userlistvbox = self.userlistvbox self.frame.UserListToolbar = self.UserListToolbar """ Columns """ self.usersmodel = Gtk.ListStore( GObject.TYPE_OBJECT, # (0) status icon GObject.TYPE_OBJECT, # (1) flag str, # (2) username str, # (3) hspeed str, # (4) hfile count bool, # (5) trusted bool, # (6) notify bool, # (7) privileged str, # (8) hlast seen str, # (9) comments GObject.TYPE_INT64, # (10) status GObject.TYPE_UINT64, # (11) speed GObject.TYPE_UINT64, # (12) file count int, # (13) last seen str # (14) country ) widths = self.frame.np.config.sections["columns"]["userlist_widths"] self.cols = cols = initialise_columns( self.UserListTree, [_("Status"), widths[0], "pixbuf"], [_("Country"), widths[1], "pixbuf"], [_("User"), widths[2], "text"], [_("Speed"), widths[3], "number"], [_("Files"), widths[4], "number"], [_("Trusted"), widths[5], "toggle"], [_("Notify"), widths[6], "toggle"], [_("Privileged"), widths[7], "toggle"], [_("Last seen"), widths[8], "text"], [_("Comments"), widths[9], "edit"]) self.col_status, self.col_country, self.col_user, self.col_speed, self.col_files, self.col_trusted, self.col_notify, self.col_privileged, self.col_last_seen, self.col_comments = cols hide_columns(cols, config["columns"]["userlist"]) self.col_status.set_sort_column_id(10) self.col_country.set_sort_column_id(14) self.col_user.set_sort_column_id(2) self.col_speed.set_sort_column_id(11) self.col_files.set_sort_column_id(12) self.col_trusted.set_sort_column_id(5) self.col_notify.set_sort_column_id(6) self.col_privileged.set_sort_column_id(7) self.col_last_seen.set_sort_column_id(13) self.col_comments.set_sort_column_id(9) self.col_status.get_widget().hide() self.col_country.get_widget().hide() if config["columns"]["hideflags"]: cols[1].set_visible(0) config["columns"]["userlist"][1] = 0 for render in self.col_trusted.get_cells(): render.connect('toggled', self.cell_toggle_callback, self.UserListTree, 5) for render in self.col_notify.get_cells(): render.connect('toggled', self.cell_toggle_callback, self.UserListTree, 6) for render in self.col_privileged.get_cells(): render.connect('toggled', self.cell_toggle_callback, self.UserListTree, 7) for render in self.col_comments.get_cells(): render.connect('edited', self.cell_edited_callback, self.UserListTree, 9) self.UserListTree.set_model(self.usersmodel) """ Buddy list """ for user in self.frame.np.config.sections["server"]["userlist"]: username, comment, notify, privileged, trusted, last_seen, country = user 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 row = [ self.frame.get_status_image(0), self.frame.get_flag_image(country), username, "", "", trusted, notify, privileged, last_seen, comment, 0, 0, 0, time_from_epoch, country ] self.usersmodel.insert(0, row) self.usersmodel.set_sort_column_id(2, Gtk.SortType.ASCENDING) """ Popup """ self.popup_menu_private_rooms = PopupMenu(self.frame, False) self.popup_menu = popup = PopupMenu(frame) popup.setup( ("#" + _("Send _message"), popup.on_send_message), ("", None), ("#" + _("Show IP a_ddress"), popup.on_show_ip_address), ("#" + _("Get user i_nfo"), popup.on_get_user_info), ("#" + _("Brow_se files"), popup.on_browse_user), ("#" + _("Gi_ve privileges"), popup.on_give_privileges), ("$" + _("_Ban this user"), popup.on_ban_user), ("$" + _("_Ignore this user"), popup.on_ignore_user), ("", None), ("$" + _("_Online notify"), self.on_notify), ("$" + _("_Privileged"), self.on_privileged), ("$" + _("_Trusted"), self.on_trusted), ("", None), ("#" + _("Edit _comments"), self.on_edit_comments), ("#" + _("_Remove"), self.on_remove_user), (1, _("Private rooms"), self.popup_menu_private_rooms, popup.on_private_rooms, self.popup_menu_private_rooms)) items = self.popup_menu.get_children() self.menu_send_message = items[0] self.menu_show_ip_address = items[2] self.menu_get_user_info = items[3] self.menu_browse_user = items[4] self.menu_give_privileges = items[5] self.menu_ban_user = items[6] self.menu_ignore_user = items[7] self.menu_on_notify = items[9] self.menu_on_privileged = items[10] self.menu_on_trusted = items[11] self.menu_edit_comments = items[13] self.menu_remove_user = items[14] self.menu_private_rooms = items[15] self.UserListTree.connect("button_press_event", self.on_popup_menu) self.update_visuals()
def __init__(self, userbrowses, user, conn): # 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.user_browse_tab = builder.get_object("UserBrowseTab") for i in builder.get_objects(): try: self.__dict__[Gtk.Buildable.get_name(i)] = i except TypeError: pass self.user_browse_tab.remove(self.Main) self.user_browse_tab.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.dir_store = Gtk.TreeStore(str, str) self.FolderTreeView.set_headers_visible(True) self.FolderTreeView.set_enable_tree_lines(True) cols = initialise_columns( self.FolderTreeView, [_("Directories"), -1, "text", self.cell_data_func] # 0 ) cols[0].set_sort_column_id(0) self.popup_menu_users = PopupMenu(self.frame, False) self.popup_menu_users2 = PopupMenu(self.frame, False) for menu in [self.popup_menu_users, self.popup_menu_users2]: menu.setup( ("#" + _("Send _message"), menu.on_send_message), ("#" + _("Show IP a_ddress"), menu.on_show_ip_address), ("#" + _("Get user i_nfo"), menu.on_get_user_info), ("#" + _("Gi_ve privileges"), menu.on_give_privileges), ("", None), ("$" + _("_Add user to list"), menu.on_add_to_list), ("$" + _("_Ban this user"), menu.on_ban_user), ("$" + _("_Ignore this user"), menu.on_ignore_user) ) self.popup_menu_downloads_folders = PopupMenu(self.frame, False) self.popup_menu_downloads_folders.setup( ("#" + _("_Download directory"), self.on_download_directory), ("#" + _("Download directory _to..."), self.on_download_directory_to), ("#" + _("Download _recursive"), self.on_download_directory_recursive), ("#" + _("Download r_ecursive to..."), self.on_download_directory_recursive_to) ) self.popup_menu_downloads_files = PopupMenu(self.frame, False) self.popup_menu_downloads_files.setup( ("#" + _("_Download file(s)"), self.on_download_files), ("#" + _("Download _to..."), self.on_download_files_to), ("", None), ("#" + _("_Download directory"), self.on_download_directory), ("#" + _("Download directory _to..."), self.on_download_directory_to), ("#" + _("Download _recursive"), self.on_download_directory_recursive), ("#" + _("Download r_ecursive to..."), self.on_download_directory_recursive_to) ) self.popup_menu_uploads_folders = PopupMenu(self.frame, False) self.popup_menu_uploads_folders.setup( ("#" + _("Upload Directory to..."), self.on_upload_directory_to), ("#" + _("Upload Directory recursive to..."), self.on_upload_directory_recursive_to) ) self.popup_menu_uploads_files = PopupMenu(self.frame, False) self.popup_menu_uploads_files.setup( ("#" + _("Upload Directory to..."), self.on_upload_directory_to), ("#" + _("Upload Directory recursive to..."), self.on_upload_directory_recursive_to), ("#" + _("Up_load file(s)"), self.on_upload_files) ) 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.on_popup_menu_folder_user), ("", None), (1, _("Download"), self.popup_menu_downloads_folders, None), (1, _("Upload"), self.popup_menu_uploads_folders, None), ("", None), ("#" + _("Copy _URL"), self.on_copy_dir_url), ("#" + _("Open in File Manager"), self.on_file_manager) ) else: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.on_popup_menu_folder_user), ("", None), (1, _("Download"), self.popup_menu_downloads_folders, None), ("", None), ("#" + _("Copy _URL"), self.on_copy_dir_url) ) self.FolderTreeView.connect("button_press_event", self.on_folder_clicked) self.FolderTreeView.get_selection().connect("changed", self.on_select_dir) # Filename, HSize, Bitrate, HLength, Size, Length, RawFilename self.file_store = Gtk.ListStore(str, str, str, str, GObject.TYPE_INT64, int, str) self.FileTreeView.set_model(self.file_store) widths = self.frame.np.config.sections["columns"]["userbrowse_widths"] cols = initialise_columns( self.FileTreeView, [_("Filename"), widths[0], "text", self.cell_data_func], [_("Size"), widths[1], "number", self.cell_data_func], [_("Bitrate"), widths[2], "number", self.cell_data_func], [_("Length"), widths[3], "number", self.cell_data_func] ) 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.file_store.set_sort_column_id(0, Gtk.SortType.ASCENDING) hide_columns(cols, self.frame.np.config.sections["columns"]["userbrowse"]) self.FileTreeView.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.FileTreeView.set_headers_clickable(True) self.FileTreeView.set_rubber_banding(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.on_popup_menu_file_user), ("", None), (1, _("Download"), self.popup_menu_downloads_files, None), (1, _("Upload"), self.popup_menu_uploads_files, None), ("", None), ("#" + _("Copy _URL"), self.on_copy_url), ("#" + _("Send to _player"), self.on_play_files), ("#" + _("Open in File Manager"), self.on_file_manager) ) else: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.on_popup_menu_file_user), ("", None), (1, _("Download"), self.popup_menu_downloads_files, None), ("", None), ("#" + _("Copy _URL"), self.on_copy_url) ) self.FileTreeView.connect("button_press_event", self.on_file_clicked) self.change_colours() for name, object in list(self.__dict__.items()): if isinstance(object, PopupMenu): object.set_user(self.user)
def __init__(self, userbrowses, user): self.userbrowses = userbrowses self.frame = userbrowses.frame # Build the window load_ui_elements( self, os.path.join(self.frame.gui_dir, "ui", "userbrowse.ui")) self.info_bar = InfoBar(self.InfoBar, Gtk.MessageType.INFO) self.user = user self.conn = None self.finished = False # selected_folder is the current selected folder self.selected_folder = None # queued_folder is a folder that should be opened once the share has loaded self.queued_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.dir_store = Gtk.TreeStore(str, str) self.FolderTreeView.set_headers_visible(True) self.FolderTreeView.set_enable_tree_lines(True) cols = initialise_columns( self.FolderTreeView, [_("Directories"), -1, "text"] # 0 ) cols[0].set_sort_column_id(0) self.popup_menu_users = PopupMenu(self.frame, False) self.popup_menu_users2 = PopupMenu(self.frame, False) self.popup_menu_users_tab = PopupMenu(self.frame) for menu in (self.popup_menu_users, self.popup_menu_users2, self.popup_menu_users_tab): menu.setup(("#" + _("Send _message"), menu.on_send_message), ("#" + _("Show IP a_ddress"), menu.on_show_ip_address), ("#" + _("Get user i_nfo"), menu.on_get_user_info), ("#" + _("Gi_ve privileges"), menu.on_give_privileges), ("#" + _("Client Version"), menu.on_version), ("", None), ("#" + _("_Save shares list to disk"), self.on_save), ("", None), ("$" + _("_Add user to list"), menu.on_add_to_list), ("$" + _("_Ban this user"), menu.on_ban_user), ("$" + _("_Ignore this user"), menu.on_ignore_user), ("", None), ("#" + _("_Close this tab"), self.on_close)) self.popup_menu_downloads_folders = PopupMenu(self.frame, False) self.popup_menu_downloads_folders.setup( ("#" + _("_Download Folder"), self.on_download_directory), ("#" + _("Download Folder _To..."), self.on_download_directory_to), ("#" + _("Download _Recursive"), self.on_download_directory_recursive), ("#" + _("Download R_ecursive To..."), self.on_download_directory_recursive_to)) self.popup_menu_downloads_files = PopupMenu(self.frame, False) self.popup_menu_downloads_files.setup( ("#" + _("_Download File(s)"), self.on_download_files), ("#" + _("Download _To..."), self.on_download_files_to), ("", None), ("#" + _("_Download Folder"), self.on_download_directory), ("#" + _("Download Folder _To..."), self.on_download_directory_to), ("#" + _("Download _Recursive"), self.on_download_directory_recursive), ("#" + _("Download R_ecursive To..."), self.on_download_directory_recursive_to)) self.popup_menu_uploads_folders = PopupMenu(self.frame, False) self.popup_menu_uploads_folders.setup( ("#" + _("Upload Folder To..."), self.on_upload_directory_to), ("#" + _("Upload Folder Recursive To..."), self.on_upload_directory_recursive_to)) self.popup_menu_uploads_files = PopupMenu(self.frame, False) self.popup_menu_uploads_files.setup( ("#" + _("Upload Folder To..."), self.on_upload_directory_to), ("#" + _("Upload Folder Recursive To..."), self.on_upload_directory_recursive_to), ("#" + _("Up_load File(s)"), self.on_upload_files)) self.folder_popup_menu = PopupMenu(self.frame) if user == self.frame.np.config.sections["server"]["login"]: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.on_popup_menu_folder_user), ("", None), (1, _("Download"), self.popup_menu_downloads_folders, None), (1, _("Upload"), self.popup_menu_uploads_folders, None), ("", None), ("#" + _("Open in File _Manager"), self.on_file_manager), ("", None), ("#" + _("Copy _Folder Path"), self.on_copy_file_path, False), ("#" + _("Copy _URL"), self.on_copy_dir_url), ) else: self.folder_popup_menu.setup( ("USERMENU", _("User"), self.popup_menu_users, self.on_popup_menu_folder_user), ("", None), (1, _("Download"), self.popup_menu_downloads_folders, None), ("", None), ("#" + _("Copy _Folder Path"), self.on_copy_file_path, False), ("#" + _("Copy _URL"), self.on_copy_dir_url)) self.FolderTreeView.connect("button_press_event", self.on_folder_clicked) self.FolderTreeView.get_selection().connect("changed", self.on_select_dir) # Filename, HSize, Bitrate, HLength, Size, Length, RawFilename self.file_store = Gtk.ListStore(str, str, str, str, GObject.TYPE_INT64, int, str) self.FileTreeView.set_model(self.file_store) widths = self.frame.np.config.sections["columns"]["userbrowse_widths"] cols = initialise_columns(self.FileTreeView, [_("Filename"), widths[0], "text"], [_("Size"), widths[1], "number"], [_("Bitrate"), widths[2], "number"], [_("Length"), widths[3], "number"]) 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.file_store.set_sort_column_id(0, Gtk.SortType.ASCENDING) hide_columns(cols, self.frame.np.config.sections["columns"]["userbrowse"]) self.FileTreeView.get_selection().set_mode(Gtk.SelectionMode.MULTIPLE) self.FileTreeView.set_headers_clickable(True) self.FileTreeView.set_rubber_banding(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.on_popup_menu_file_user), ("", None), (1, _("Download"), self.popup_menu_downloads_files, None), (1, _("Upload"), self.popup_menu_uploads_files, None), ("", None), ("#" + _("Send to _Player"), self.on_play_files), ("#" + _("Open in File _Manager"), self.on_file_manager), ("#" + _("File _Properties"), self.on_file_properties), ("", None), ("#" + _("Copy _File Path"), self.on_copy_file_path, True), ("#" + _("Copy _URL"), self.on_copy_url)) else: self.file_popup_menu.setup( ("USERMENU", "User", self.popup_menu_users2, self.on_popup_menu_file_user), ("", None), (1, _("Download"), self.popup_menu_downloads_files, None), ("", None), ("#" + _("File _Properties"), self.on_file_properties), ("", None), ("#" + _("Copy _File Path"), self.on_copy_file_path, True), ("#" + _("Copy _URL"), self.on_copy_url)) self.FolderTreeView.connect("key-press-event", self.on_key_press_event) self.FileTreeView.connect("button_press_event", self.on_file_clicked) self.FileTreeView.connect("key-press-event", self.on_key_press_event) self.update_visuals() for name, object in self.__dict__.items(): if isinstance(object, PopupMenu): object.set_user(self.user)