def test_basic(self): self.failIf(get_scan_dirs()) if os.name == "nt": set_scan_dirs([u"C:\\foo", u"D:\\bar", u""]) self.failUnlessEqual(get_scan_dirs(), [u"C:\\foo", u"D:\\bar"]) else: set_scan_dirs(["foo", "bar", ""]) self.failUnlessEqual(get_scan_dirs(), ["foo", "bar"])
def open_chooser(self, action): last_dir = self.last_dir if not os.path.exists(last_dir): last_dir = get_home_dir() class MusicFolderChooser(FolderChooser): def __init__(self, parent, init_dir): super(MusicFolderChooser, self).__init__(parent, _("Add Music"), init_dir) cb = Gtk.CheckButton(_("Watch this folder for new songs")) # enable if no folders are being watched cb.set_active(not get_scan_dirs()) cb.show() self.set_extra_widget(cb) def run(self): fns = super(MusicFolderChooser, self).run() cb = self.get_extra_widget() return fns, cb.get_active() class MusicFileChooser(FileChooser): def __init__(self, parent, init_dir): super(MusicFileChooser, self).__init__(parent, _("Add Music"), formats.filter, init_dir) if action.get_name() == "AddFolders": dialog = MusicFolderChooser(self, last_dir) fns, do_watch = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) # scan them self.last_dir = fns[0] copool.add(self.__library.scan, fns, cofuncid="library", funcid="library") # add them as library scan directory if do_watch: dirs = get_scan_dirs() for fn in fns: if fn not in dirs: dirs.append(fn) set_scan_dirs(dirs) else: dialog = MusicFileChooser(self, last_dir) fns = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) self.last_dir = os.path.dirname(fns[0]) for filename in map(os.path.realpath, fns): self.__library.add_filename(filename)
def open_chooser(self, action): last_dir = self.last_dir if not os.path.exists(last_dir): last_dir = get_home_dir() class MusicFolderChooser(FolderChooser): def __init__(self, parent, init_dir): super(MusicFolderChooser, self).__init__( parent, _("Add Music"), init_dir) cb = Gtk.CheckButton(_("Watch this folder for new songs")) # enable if no folders are being watched cb.set_active(not get_scan_dirs()) cb.show() self.set_extra_widget(cb) def run(self): fns = super(MusicFolderChooser, self).run() cb = self.get_extra_widget() return fns, cb.get_active() class MusicFileChooser(FileChooser): def __init__(self, parent, init_dir): super(MusicFileChooser, self).__init__( parent, _("Add Music"), formats.filter, init_dir) if action.get_name() == "AddFolders": dialog = MusicFolderChooser(self, last_dir) fns, do_watch = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) # scan them self.last_dir = fns[0] copool.add(self.__library.scan, fns, cofuncid="library", funcid="library") # add them as library scan directory if do_watch: dirs = get_scan_dirs() for fn in fns: if fn not in dirs: dirs.append(fn) set_scan_dirs(dirs) else: dialog = MusicFileChooser(self, last_dir) fns = dialog.run() dialog.destroy() if fns: fns = map(glib2fsnative, fns) self.last_dir = os.path.dirname(fns[0]) for filename in map(os.path.realpath, fns): self.__library.add_filename(filename)
def __save(self): set_scan_dirs(list(self.model.itervalues()))
def test_set_scan_dirs_colons(self): set_scan_dirs([STANDARD_PATH, GVFS_PATH]) expected = GVFS_PATH if is_windows() else GVFS_PATH_ESCAPED self.assertEqual(self.scan_dirs, "%s:%s" % (STANDARD_PATH, expected))
def test_set_scan_dirs_multiple(self): set_scan_dirs([OTHER_PATH, STANDARD_PATH]) self.assertEqual(self.scan_dirs, "%s:%s" % (OTHER_PATH, STANDARD_PATH))
def test_set_scan_dirs_single(self): set_scan_dirs([STANDARD_PATH]) self.assertEqual(self.scan_dirs, STANDARD_PATH)
def test_set_scan_dirs_empty(self): set_scan_dirs([]) self.assertEqual(self.scan_dirs, "")
def __save(self): set_scan_dirs([r[0] for r in self.model])
def test_set_scan_dirs_colons(self): set_scan_dirs([STANDARD_PATH, GVFS_PATH]) expected = GVFS_PATH if ON_WINDOWS else GVFS_PATH_ESCAPED self.assertEqual(self.scan_dirs, "%s:%s" % (STANDARD_PATH, expected))