Beispiel #1
0
    def __drag_data_received(self, view, ctx, x, y, sel, tid, etime):
        view.emit_stop_by_name('drag-data-received')
        targets = [
            ("text/uri-list", 0, DND_URI_LIST),
            ("text/x-moz-url", 0, DND_MOZ_URL)
        ]
        targets = [Gtk.TargetEntry.new(*t) for t in targets]

        view.drag_dest_set(Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY)
        if tid == DND_URI_LIST:
            uri = sel.get_uris()[0]
        elif tid == DND_MOZ_URL:
            uri = sel.data.decode('utf16', 'replace').split('\n')[0]
        else:
            ctx.finish(False, False, etime)
            return

        ctx.finish(True, False, etime)

        feed = Feed(uri.encode("ascii", "replace"))
        feed.changed = feed.parse()
        if feed:
            self.__feeds.append(row=[feed])
            AudioFeeds.write()
        else:
            ErrorMessage(
                self, _("Unable to add feed"),
                _("%s could not be added. The server may be down, "
                  "or the location may not be an audio feed.") %
                util.bold(util.escape(feed.uri))).run()
Beispiel #2
0
    def __drag_data_received(self, view, ctx, x, y, sel, tid, etime):
        view.emit_stop_by_name('drag-data-received')
        targets = [
            ("text/uri-list", 0, DND_URI_LIST),
            ("text/x-moz-url", 0, DND_MOZ_URL)
        ]
        targets = [Gtk.TargetEntry.new(*t) for t in targets]

        view.drag_dest_set(Gtk.DestDefaults.ALL, targets, Gdk.DragAction.COPY)
        if tid == DND_URI_LIST:
            uri = sel.get_uris()[0]
        elif tid == DND_MOZ_URL:
            uri = sel.data.decode('utf16', 'replace').split('\n')[0]
        else:
            ctx.finish(False, False, etime)
            return

        ctx.finish(True, False, etime)

        feed = Feed(uri.encode("ascii", "replace"))
        feed.changed = feed.parse()
        if feed:
            self.__feeds.append(row=[feed])
            AudioFeeds.write()
        else:
            ErrorMessage(
                self, _("Unable to add feed"),
                _("%s could not be added. The server may be down, "
                  "or the location may not be an audio feed.") %
                util.bold(util.escape(feed.uri))).run()
Beispiel #3
0
    def __refresh_space(self, device):
        try:
            space, free = device.get_space()
        except NotImplementedError:
            self.__device_space.set_text("")
            self.__progress.hide()
        else:
            used = space - free
            fraction = float(used) / space

            self.__device_space.set_markup(
                _("%(used-size)s used, %(free-size)s available") %
                {"used-size": util.bold(util.format_size(used)),
                 "free-size": util.bold(util.format_size(free))})
            self.__progress.set_fraction(fraction)
            self.__progress.set_text("%.f%%" % round(fraction * 100))
            self.__progress.show()
Beispiel #4
0
 def __check_device(self, device, message):
     if not device.is_connected():
         qltk.WarningMessage(
             self, message,
             _("%s is not connected.") %
             util.bold(util.escape(device['name']))).run()
         return False
     return True
Beispiel #5
0
    def __refresh_space(self, device):
        try:
            space, free = device.get_space()
        except NotImplementedError:
            self.__device_space.set_text("")
            self.__progress.hide()
        else:
            used = space - free
            fraction = float(used) / space

            self.__device_space.set_markup(
                _("%(used-size)s used, %(free-size)s available") %
                {"used-size": util.bold(util.format_size(used)),
                 "free-size": util.bold(util.format_size(free))})
            self.__progress.set_fraction(fraction)
            self.__progress.set_text("%.f%%" % round(fraction * 100))
            self.__progress.show()
Beispiel #6
0
 def __check_device(self, device, message):
     if not device.is_connected():
         qltk.WarningMessage(
             self, message,
             _("%s is not connected.") %
             util.bold(util.escape(device['name']))
         ).run()
         return False
     return True
 def open_location(self, action):
     name = GetStringDialog(self, _("Add a Location"),
         _("Enter the location of an audio file:"),
         okbutton=Gtk.STOCK_ADD).run()
     if name:
         if not util.uri_is_valid(name):
             ErrorMessage(
                 self, _("Unable to add location"),
                 _("%s is not a valid location.") % (
                 util.bold(util.escape(name)))).run()
         elif not app.player.can_play_uri(name):
             ErrorMessage(
                 self, _("Unable to add location"),
                 _("%s uses an unsupported protocol.") % (
                 util.bold(util.escape(name)))).run()
         else:
             if name not in self.__library:
                 self.__library.add([RemoteFile(name)])
Beispiel #8
0
 def open_location(self, action):
     name = GetStringDialog(self, _("Add a Location"),
         _("Enter the location of an audio file:"),
         okbutton=Gtk.STOCK_ADD).run()
     if name:
         if not util.uri_is_valid(name):
             ErrorMessage(
                 self, _("Unable to add location"),
                 _("%s is not a valid location.") % (
                 util.bold(util.escape(name)))).run()
         elif not app.player.can_play_uri(name):
             ErrorMessage(
                 self, _("Unable to add location"),
                 _("%s uses an unsupported protocol.") % (
                 util.bold(util.escape(name)))).run()
         else:
             if name not in self.__library:
                 self.__library.add([RemoteFile(name)])
Beispiel #9
0
 def __eject(self, button):
     model, iter = self.__view.get_selection().get_selected()
     if iter:
         device = model[iter][0]
         status = device.eject()
         if status is not True:
             msg = _("Ejecting %s failed.") % util.bold(device['name'])
             if status:
                 msg += "\n\n%s" % status
             qltk.ErrorMessage(self, _("Unable to eject device"), msg).run()
Beispiel #10
0
 def __eject(self, button):
     model, iter = self.__view.get_selection().get_selected()
     if iter:
         device = model[iter][0]
         status = device.eject()
         if status is not True:
             msg = _("Ejecting %s failed.") % util.bold(device['name'])
             if status:
                 msg += "\n\n%s" % status
             qltk.ErrorMessage(self, _("Unable to eject device"), msg).run()
Beispiel #11
0
    def __copy_songs(self, songs):
        model, iter = self.__view.get_selection().get_selected()
        if not iter:
            return False

        device = model[iter][0]
        if not self.__check_device(device, _("Unable to copy songs")):
            return False

        self.__busy = True

        wlb = self.__statusbar
        wlb.setup(
            len(songs),
            _("Copying %(song)s") % {'song': '<b>%(song)s</b>'},
            {'song': ''})
        wlb.show()

        for song in songs:
            label = util.escape(song('~artist~title'))
            if wlb.step(song=label):
                wlb.hide()
                break

            space, free = device.get_space()
            if free < os.path.getsize(song['~filename']):
                wlb.hide()
                qltk.WarningMessage(
                    self, _("Unable to copy song"),
                    _("There is not enough free space for this song.")
                ).run()
                break

            status = device.copy(self, song)
            if isinstance(status, AudioFile):
                try:
                    self.__cache[device.bid].append(song)
                except KeyError:
                    pass
                self.__refresh_space(device)
            else:
                msg = _("%s could not be copied.") % util.bold(label)
                if type(status) == unicode:
                    msg += "\n\n" + util.escape(status)
                qltk.WarningMessage(self, _("Unable to copy song"), msg).run()

        if device.cleanup and not device.cleanup(wlb, 'copy'):
            pass
        else:
            wlb.hide()

        self.__busy = False
        return True
Beispiel #12
0
    def __copy_songs(self, songs):
        model, iter = self.__view.get_selection().get_selected()
        if not iter:
            return False

        device = model[iter][0]
        if not self.__check_device(device, _("Unable to copy songs")):
            return False

        self.__busy = True

        wlb = self.__statusbar
        wlb.setup(
            len(songs),
            _("Copying %(song)s") % {'song': '<b>%(song)s</b>'},
            {'song': ''})
        wlb.show()

        for song in songs:
            label = util.escape(song('~artist~title'))
            if wlb.step(song=label):
                wlb.hide()
                break

            space, free = device.get_space()
            if free < os.path.getsize(song['~filename']):
                wlb.hide()
                qltk.WarningMessage(
                    self, _("Unable to copy song"),
                    _("There is not enough free space for this song.")
                ).run()
                break

            status = device.copy(self, song)
            if isinstance(status, AudioFile):
                try:
                    self.__cache[device.bid].append(song)
                except KeyError:
                    pass
                self.__refresh_space(device)
            else:
                msg = _("%s could not be copied.") % util.bold(label)
                if type(status) == unicode:
                    msg += "\n\n" + util.escape(status)
                qltk.WarningMessage(self, _("Unable to copy song"), msg).run()

        if device.cleanup and not device.cleanup(wlb, 'copy'):
            pass
        else:
            wlb.hide()

        self.__busy = False
        return True
Beispiel #13
0
 def __new_feed(self, activator):
     feed = AddFeedDialog(self).run()
     if feed is not None:
         feed.changed = feed.parse()
         if feed:
             self.__feeds.append(row=[feed])
             AudioFeeds.write()
         else:
             ErrorMessage(
                 self, _("Unable to add feed"),
                 _("%s could not be added. The server may be down, "
                   "or the location may not be an audio feed.") %
                 util.bold(util.escape(feed.uri))).run()
Beispiel #14
0
 def __new_feed(self, activator):
     feed = AddFeedDialog(self).run()
     if feed is not None:
         feed.changed = feed.parse()
         if feed:
             self.__feeds.append(row=[feed])
             AudioFeeds.write()
         else:
             ErrorMessage(
                 self, _("Unable to add feed"),
                 _("%s could not be added. The server may be down, "
                   "or the location may not be an audio feed.") %
                 util.bold(util.escape(feed.uri))).run()
Beispiel #15
0
    def __delete_songs(self, songs):
        model, iter = self.__view.get_selection().get_selected()
        if not iter:
            return False

        device = model[iter][0]
        if not self.__check_device(device, _("Unable to delete songs")):
            return False

        dialog = DeleteDialog.for_songs(self, songs)
        if dialog.run() != DeleteDialog.RESPONSE_DELETE:
            return False

        self.__busy = True

        wlb = self.__statusbar
        wlb.setup(
            len(songs),
            _("Deleting %(song)s") % {"song": "<b>%(song)s</b>"},
            {'song': ''})
        wlb.show()

        for song in songs:
            label = util.escape(song('~artist~title'))
            if wlb.step(song=label):
                wlb.hide()
                break

            status = device.delete(self, song)
            if status is True:
                try:
                    self.__cache[device.bid].remove(song)
                except (KeyError, ValueError):
                    pass
                self.__refresh_space(device)
            else:
                msg = _("%s could not be deleted.") % util.bold(label)
                if type(status) == unicode:
                    msg += "\n\n%s" % status
                qltk.WarningMessage(
                    self, _("Unable to delete song"), msg).run()

        if device.cleanup and not device.cleanup(wlb, 'delete'):
            pass
        else:
            wlb.hide()

        self.__busy = False
Beispiel #16
0
    def __delete_songs(self, songs):
        model, iter = self.__view.get_selection().get_selected()
        if not iter:
            return False

        device = model[iter][0]
        if not self.__check_device(device, _("Unable to delete songs")):
            return False

        dialog = DeleteDialog.for_songs(self, songs)
        if dialog.run() != DeleteDialog.RESPONSE_DELETE:
            return False

        self.__busy = True

        wlb = self.__statusbar
        wlb.setup(
            len(songs),
            _("Deleting %(song)s") % {"song": "<b>%(song)s</b>"},
            {'song': ''})
        wlb.show()

        for song in songs:
            label = util.escape(song('~artist~title'))
            if wlb.step(song=label):
                wlb.hide()
                break

            status = device.delete(self, song)
            if status is True:
                try:
                    self.__cache[device.bid].remove(song)
                except (KeyError, ValueError):
                    pass
                self.__refresh_space(device)
            else:
                msg = _("%s could not be deleted.") % util.bold(label)
                if type(status) == unicode:
                    msg += "\n\n%s" % status
                qltk.WarningMessage(
                    self, _("Unable to delete song"), msg).run()

        if device.cleanup and not device.cleanup(wlb, 'delete'):
            pass
        else:
            wlb.hide()

        self.__busy = False
Beispiel #17
0
    def schedule_change(self, album):
        if self.delay:
            srcid = GLib.timeout_add(1000 * self.delay, self.change_album,
                                     album)
            task = notif.Task(_("Random Album"),
                              _("Waiting to start %s") %
                              util.bold(util.escape(album("album"))),
                              stop=lambda: GLib.source_remove(srcid))

            def countdown():
                for i in range(10 * self.delay):
                    task.update(i / (10. * self.delay))
                    yield True
                task.finish()
                yield False

            GLib.timeout_add(100, next, countdown())
        else:
            self.change_album(album)
Beispiel #18
0
    def schedule_change(self, album):
        if self.delay:
            srcid = GLib.timeout_add(1000 * self.delay,
                                     self.change_album, album)
            if notif is None:
                return
            task = notif.Task(_("Random Album"),
                              _("Waiting to start %s") %
                                    util.bold(util.escape(album("album"))),
                              stop=lambda: GLib.source_remove(srcid))

            def countdown():
                for i in range(10 * self.delay):
                    task.update(i / (10. * self.delay))
                    yield True
                task.finish()
                yield False
            GLib.timeout_add(100, next, countdown())
        else:
            self.change_album(album)
Beispiel #19
0
    def __drag_data_received(self, widget, ctx, x, y, sel, tid, etime):
        assert tid == DND_URI_LIST

        uris = sel.get_uris()

        dirs = []
        error = False
        for uri in uris:
            try:
                uri = URI(uri)
            except ValueError:
                continue

            if uri.is_filename:
                loc = os.path.normpath(uri.filename)
                if os.path.isdir(loc):
                    dirs.append(loc)
                else:
                    loc = os.path.realpath(loc)
                    if loc not in self.__library:
                        self.__library.add_filename(loc)
            elif app.player.can_play_uri(uri):
                if uri not in self.__library:
                    self.__library.add([RemoteFile(uri)])
            else:
                error = True
                break
        Gtk.drag_finish(ctx, not error, False, etime)
        if error:
            ErrorMessage(
                self, _("Unable to add songs"),
                _("%s uses an unsupported protocol.") % util.bold(uri)).run()
        else:
            if dirs:
                copool.add(self.__library.scan,
                           dirs,
                           cofuncid="library",
                           funcid="library")
    def __drag_data_received(self, widget, ctx, x, y, sel, tid, etime):
        assert tid == DND_URI_LIST

        uris = sel.get_uris()

        dirs = []
        error = False
        for uri in uris:
            try:
                uri = URI(uri)
            except ValueError:
                continue

            if uri.is_filename:
                loc = os.path.normpath(uri.filename)
                if os.path.isdir(loc):
                    dirs.append(loc)
                else:
                    loc = os.path.realpath(loc)
                    if loc not in self.__library:
                        self.__library.add_filename(loc)
            elif app.player.can_play_uri(uri):
                if uri not in self.__library:
                    self.__library.add([RemoteFile(uri)])
            else:
                error = True
                break
        Gtk.drag_finish(ctx, not error, False, etime)
        if error:
            ErrorMessage(
                self, _("Unable to add songs"),
                _("%s uses an unsupported protocol.") % util.bold(uri)).run()
        else:
            if dirs:
                copool.add(
                    self.__library.scan, dirs,
                    cofuncid="library", funcid="library")
Beispiel #21
0
 def test_format(self):
     self.assertEqual(util.bold("foo"), "<b>foo</b>")
     self.assertEqual(util.italic("foo"), "<i>foo</i>")
     self.assertEqual(util.monospace("foo"), "<tt>foo</tt>")
Beispiel #22
0
 def feed_error(self, feed: Feed) -> ErrorMessage:
     return ErrorMessage(
         self, _("Unable to add feed"),
         _("%s could not be added. The server may be down, "
           "or the location may not be an audio feed.") %
         util.bold(util.escape(feed.uri)))
Beispiel #23
0
 def test_format(self):
     self.assertEqual(util.bold("foo"), "<b>foo</b>")
     self.assertEqual(util.italic("foo"), "<i>foo</i>")
     self.assertEqual(util.monospace("foo"), "<tt>foo</tt>")