Beispiel #1
0
    def on_download_files_to(self, widget):

        folder = choose_dir(self.frame.MainWindow, self.frame.np.config.sections["transfers"]["downloaddir"], multichoice=False)

        if folder is None:
            return

        for folders in folder:
            self.on_download_files(widget, folders)
            break
Beispiel #2
0
    def on_download_directory_recursive_to(self, widget):

        folder = choose_dir(self.frame.MainWindow, self.frame.np.config.sections["transfers"]["downloaddir"], multichoice=False)

        if folder is None:
            return

        try:
            self.download_directory(self.selected_folder, os.path.join(folder[0], ""), 1)
        except IOError:  # failed to open
            log.add('Failed to open %r for reading', folder[0])  # notify user
Beispiel #3
0
    def on_download_files_to(self, widget):

        try:
            _, folder = self.selected_folder.rsplit("\\", 1)
        except ValueError:
            folder = self.selected_folder

        path = os.path.join(self.frame.np.config.sections["transfers"]["downloaddir"], folder)

        if os.path.exists(path) and os.path.isdir(path):
            ldir = choose_dir(self.frame.MainWindow, path, multichoice=False)
        else:
            ldir = choose_dir(self.frame.MainWindow, self.frame.np.config.sections["transfers"]["downloaddir"], multichoice=False)

        if ldir is None:
            return

        try:
            self.on_download_files(widget, ldir[0])
        except IOError:  # failed to open
            log.add('failed to open %r for reading', ldir[0])  # notify user
Beispiel #4
0
    def on_download_folders_to(self, widget):

        directories = choose_dir(self.frame.MainWindow, self.frame.np.config.sections["transfers"]["downloaddir"], multichoice=False)

        if directories is None or directories == []:
            return

        destination = directories[0]

        for i in self.selected_results:

            user = i[0]
            folder = i[1].rsplit('\\', 1)[0]

            if user not in self.frame.np.requested_folders:
                self.frame.np.requested_folders[user] = {}

            if folder not in self.frame.np.requested_folders[user]:
                """ Ensure we don't send folder content requests for a folder more than once,
                e.g. when several selected resuls belong to the same folder. """

                self.frame.np.requested_folders[user][folder] = destination
                self.frame.np.process_request_to_peer(user, slskmessages.FolderContentsRequest(None, folder))
Beispiel #5
0
    def on_button_pressed(self, widget):

        if self.initphase:
            return

        name = Gtk.Buildable.get_name(widget)

        if name == "checkmyport":
            open_uri(
                '='.join([
                    'http://tools.slsknet.org/porttest.php?port',
                    str(self.frame.np.waitport)
                ]), self.window)

        if name == "addshare":

            selected = choose_dir(self.window.get_toplevel(),
                                  title=_("Add a shared directory"))

            if selected:

                for directory in selected:

                    virtual = combo_box_dialog(
                        parent=self.frame.MainWindow,
                        title=_("Virtual name"),
                        message=_("Enter virtual name for '%(dir)s':") %
                        {'dir': directory})

                    # If the virtual name is empty
                    if virtual == '' or virtual is None:

                        dlg = Gtk.MessageDialog(transient_for=self.window,
                                                flags=0,
                                                type=Gtk.MessageType.WARNING,
                                                buttons=Gtk.ButtonsType.OK,
                                                text=_("Warning"))
                        dlg.format_secondary_text(
                            _("The chosen virtual name is empty"))
                        dlg.run()
                        dlg.destroy()

                    else:
                        # We get the current defined shares from the treeview
                        model, paths = self.kids[
                            'shareddirectoriestree'].get_selection(
                            ).get_selected_rows()

                        iterator = model.get_iter_first()

                        while iterator is not None:

                            # We reject the share if the virtual share name is already used
                            if virtual == model.get_value(iterator, 0):

                                dlg = Gtk.MessageDialog(
                                    transient_for=self.window,
                                    flags=0,
                                    type=Gtk.MessageType.WARNING,
                                    buttons=Gtk.ButtonsType.OK,
                                    text=_("Warning"))
                                dlg.format_secondary_text(
                                    _("The chosen virtual name already exists")
                                )
                                dlg.run()
                                dlg.destroy()
                                return

                            # We also reject the share if the directory is already used
                            elif directory == model.get_value(iterator, 6):

                                dlg = Gtk.MessageDialog(
                                    transient_for=self.window,
                                    flags=0,
                                    type=Gtk.MessageType.WARNING,
                                    buttons=Gtk.ButtonsType.OK,
                                    text=_("Warning"))
                                dlg.format_secondary_text(
                                    _("The chosen directory is already shared")
                                )
                                dlg.run()
                                dlg.destroy()
                                return

                            else:
                                iterator = model.iter_next(iterator)

                        # The share is unique: we can add it
                        self.addshareddir((virtual, directory))

        if name == "removeshares":

            model, paths = self.kids['shareddirectoriestree'].get_selection(
            ).get_selected_rows()
            refs = [Gtk.TreeRowReference(model, x) for x in paths]

            for i in refs:
                self.sharelist.remove(self.sharelist.get_iter(i.get_path()))

        self.resetcompleteness()