Esempio n. 1
0
def set_leaf_widget(leaf):

    if leaf.type == 'file':
        if leaf.item.get('name'):
            leaf.widget = gtk.HBox(gtk.FALSE, 0)
            leaf.widget.pack_start(gtk.Label(_('URL: ')), gtk.FALSE, gtk.FALSE, 0)
            entry = gtk.Entry()
            entry.set_text(hash.hash_to_url(leaf.item['name']))
            leaf.widget.pack_start(entry, gtk.TRUE, gtk.TRUE, 0)

    elif leaf.type == 'identity':
        leaf.widget = widgets.Signature(key_name(leaf.item['key']))

    elif leaf.type == 'auction':
        leaf.widget = gtk.HBox(gtk.FALSE, 0)
        leaf.widget.pack_start(gtk.Label(_('Bid: ')), gtk.FALSE, gtk.FALSE, 0)
        entry = gtk.Entry()
        entry.set_text('0')
        leaf.widget.pack_start(entry, gtk.TRUE, gtk.TRUE, 0)
Esempio n. 2
0
def get_leaf_buttons(leaf,app):

    list = []
    if leaf.sources and leaf.type == 'file':
        set_leaf_player(leaf,app)
        for action in leaf.players.keys():
            list.append((action, lambda b, leaf=leaf,app=app,action=action: play_file(leaf,action,app)))
        if leaf.item.get('local_path'):
            list.append(
                (_("Delete"),lambda _b, leaf=leaf,app=app,item=leaf.item: leaf.delete(app,item)))
        elif leaf.item.get('name'):
            list.append(
                (_("Download"), lambda _b, leaf=leaf,app=app: leaf.download(app)))
        list.append(
            (_("View sources"), lambda _b,leaf=leaf,app=app:
             search_show_sources(leaf.sources, app.node, app)))

    elif leaf.type == 'channel exists':
        if app.chat.channels.list.has_key(leaf.item['name']):
            list.append(
                (_("Unsubscribe"),lambda _b, leaf=leaf,app=app:
                 app.chat.channel_unsub(leaf.item['name'])))
        else:
            list.append(
                (_("Subscribe"),lambda _b, leaf=leaf,app=app:
                 app.chat.channel_sub(leaf.item['name'])))
        list.append(
            (_("List subscribers"), lambda _b,_leaf=leaf, _app=app:
             search_for_people_on_channel(leaf.item['name'],_app.node,_app)))

    elif leaf.type == 'identity':
        if app.name_server.acquaintances.has_key(key_name(leaf.item['key'])):
            str = _("View")
        else:
            str = _("Add to contact list")
        def on_complete(acq,app=app):
            app.edit_acquaintance(acq,app.name_server)
        list.append((str,
                     lambda _b, leaf=leaf,app=app, on_complete=on_complete:
                     app.name_server.make_acquaintance_sync(
            leaf.item,on_complete,app,leaf.address)))
        if leaf.address:
            list.append(
                (_("Browse their files"), lambda _b, leaf=leaf,app=app:
                 search_browse_files(leaf.sources[0], app.node,app)))

    elif leaf.type =='auction':
        list.append((_("View"), lambda _b, leaf=leaf, app=app:
                     app.edit_auction(leaf.item)))

    elif leaf.type == 'daemonic node':
        list.append(
            (_("Browse their files"), lambda _b, leaf=leaf, app=app:
             search_browse_files(leaf.sources[0], app.node,app)))

    elif leaf.type == 'directory':
        if not leaf.item.get('local_path'):
            list.append((_("Download directory"),
                         lambda _b, leaf=leaf, app=app: app.download_directory_dialog(leaf)))

    buttons = []
    for title,action in list:
        button = gtk.Button(title)
        button.connect("clicked",action)
        buttons.append(button)
    return buttons