예제 #1
0
class Radar_Plugin(Plugin):
    def __init__(self, main_gui):
        self.register_plugin(PLUGIN_TYPE_RADAR)
        self.community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY)
        self.myself = self.community.get_myself()
        self.main_gui = main_gui

        self.page = GUI_Page('Radar')
        self.user_radar = UserRadar(main_gui)
        self.page.pack_start(self.user_radar)
        self.action_list = User_Action_List(self.community.community_gui,
            self.user_radar.get_selected)
        self.page.pack_start(self.action_list.get_widget(), False, True)
        self.page.show_all()
        self.main_gui.add_page(self.page)
    
        # Press 'r' to switch to radar view
        self.main_gui.add_key_binding(gtk.gdk.CONTROL_MASK, gtk.keysyms.r, self.key_pressed_r)

        self.radar_icon = gtk.gdk.pixbuf_new_from_file(join(get_dir(ICON_DIR),
            'radar.png'))
        self.main_gui.add_statusbar_icon(self.radar_icon, 'Open radar',
            self.statusbar_icon_clicked)

    def key_pressed_r(self, target, ctx):
        self.run()

    def statusbar_icon_clicked(self):
        if self.page.is_visible:
            self.main_gui.hide_page(self.page)
        else:
            self.run()

    def run(self):
        # get the last opened community from the main gui
        open_community = self.community.get_default_community()
        for page in reversed(self.main_gui.page_history):
            com = page.get_community()
            if com != None:
                open_community = com
                break
        cname = open_community.get('name')
        debug('radar: Opening radar view for community %s\n' % cname)
        self.page.set_page_title(cname, sub=True)
        self.user_radar.set_community(open_community)
        self.main_gui.show_page(self.page)

    def user_appears(self, user):
        if user != self.myself and self.main_gui:
            self.user_radar.new_user(user)

    def user_changes(self, user, what=None):
        if user != self.myself and self.main_gui:
            self.user_radar.update_user(user, what)

    def user_disappears(self, user):
        if user != self.myself and self.main_gui:
            self.user_radar.remove_user(user)
예제 #2
0
class Watches_GUI:

    # list store columns
    COL_ICON = 0
    COL_NAME = 1
    COL_TARGET = 2

    def __init__(self, main_gui, getstatecb, modifycb):
        self.main_gui = main_gui

        self.modifycb = modifycb
        self.getstatecb = getstatecb

        self.guistate = 0

        self.page = GUI_Page('Watches')

        # self.watch_list stores columns: possible picture, keyword, target
        self.watch_list = gtk.ListStore(gtk.gdk.Pixbuf, str, str)
        self.update()

        self.watch_view = gtk.TreeView(self.watch_list)
        self.pic_cell = gtk.CellRendererPixbuf()
        self.name_cell = gtk.CellRendererText()
        self.target_cell = gtk.CellRendererText()
        self.pic_column = self.watch_view.insert_column_with_attributes(
            self.COL_ICON, '', self.pic_cell, pixbuf=self.COL_ICON)
        self.name_column = self.watch_view.insert_column_with_attributes(
            self.COL_NAME, '', self.name_cell, text=self.COL_NAME)
        self.target_column = self.watch_view.insert_column_with_attributes(
            self.COL_TARGET, '', self.target_cell, text=self.COL_TARGET)
        self.page.pack_start(self.watch_view, True, True)

        add_icon = gtk.gdk.pixbuf_new_from_file(join(get_dir(ICON_DIR), "64px-add_content_icon.png"))
        remove_icon = gtk.gdk.pixbuf_new_from_file(join(get_dir(ICON_DIR), "64px-remove_content_icon.png"))

        action_buttons = [(add_icon, 'Add', self.add_clicked),
                          (remove_icon, 'Remove', self.remove_clicked)
                         ]

        self.actions = Action_List()

        for action in action_buttons:
            (icon, text, cb) = action
            self.actions.add_button(icon, text, cb)

        self.page.pack_start(self.actions.get_widget(), False, True)

        self.main_gui.add_page(self.page)

    def show(self):
        self.page.show_all()
        self.main_gui.show_page(self.page)

    def add_clicked(self, widget):
        if self.guistate != 0:
            return
        self.guistate = 1
        Input_Dialog(self.main_gui.main_window, 'Add watch', 'Please give a keyword:', self.watch_added)

    def remove_clicked(self, widget):
        if self.guistate != 0:
            return
        selection = self.watch_view.get_selection()
        if selection == None:
            return
        model, selected = selection.get_selected()
        if selected != None:
            keyword = model[selected][1]
            self.modifycb(False, keyword)
        self.update()

    def update(self):
        self.watch_list.clear()
        for keyword in self.getstatecb():
            self.watch_list.append([None, keyword, ''])

    def watch_added(self, keyword, ctx=None):
        self.guistate = 0
        if keyword:
            self.modifycb(True, keyword)
        self.update()
예제 #3
0
class File_Transfer_Plugin(Plugin):
    """FileTransferGui forms a window for active file transfers.
    Construct it from the main gui when the first transfer starts
    and destroy it when they're all done.

    """

    STATUSBAR_ICON = "transfer_status_icon.png"
    CLOSE_ICON = "48px-messaging_close.png"

    COL_ICON = 0
    COL_MSG = 1
    COL_PROG = 2
    COL_TRANSFER = 3
    COL_DELETE = 4

    def __init__(self, gui):
        self.register_plugin(PLUGIN_TYPE_FILE_TRANSFER)
        self.community = get_plugin_by_type(PLUGIN_TYPE_COMMUNITY)
        self.notification = get_plugin_by_type(PLUGIN_TYPE_NOTIFICATION)
        self.filesharing = get_plugin_by_type(PLUGIN_TYPE_FILE_SHARING)

        self.main_gui = gui
        self.ft_statusbar_icon = gtk.gdk.pixbuf_new_from_file_at_size(
            join(get_dir(ICON_DIR), self.STATUSBAR_ICON), STATUSBAR_ICON_SIZE, STATUSBAR_ICON_SIZE
        )
        self.ft_icon = gtk.gdk.pixbuf_new_from_file(join(get_dir(ICON_DIR), self.STATUSBAR_ICON))

        self.statusbar_icon = None

        self.page = GUI_Page("File transfers")
        self.main_vbox = gtk.VBox()

        # Top row
        top_hbox = gtk.HBox()
        headline = gtk.Label("File Transfers")
        close_eb = gtk.EventBox()
        close_img = gtk.Image()
        close_eb.add(close_img)
        close_img.set_from_file(join(get_dir(ICON_DIR), self.CLOSE_ICON))
        top_hbox.pack_start(headline)
        top_hbox.pack_end(close_eb, expand=False)
        self.main_vbox.pack_start(top_hbox, False, False)

        # store = (icon, message, transfer, delete_icon)
        self.transfer_list = gtk.ListStore(gtk.gdk.Pixbuf, str, int, object, gtk.gdk.Pixbuf)

        cr_icon = gtk.CellRendererPixbuf()
        cr_msg = gtk.CellRendererText()
        cr_prog = ProgressCellRenderer()
        cr_delete_icon = gtk.CellRendererPixbuf()

        self.transfer_view = gtk.TreeView(self.transfer_list)
        self.transfer_view.set_headers_visible(False)
        self.transfer_view.connect("row-activated", self.row_activated_cb)

        column = gtk.TreeViewColumn("")
        column.pack_start(cr_icon, False)
        column.pack_start(cr_msg)
        column.add_attribute(cr_icon, "pixbuf", self.COL_ICON)
        column.add_attribute(cr_msg, "text", self.COL_MSG)
        column.set_expand(True)
        self.transfer_view.append_column(column)

        column = gtk.TreeViewColumn("")
        column.pack_start(cr_prog)
        column.add_attribute(cr_prog, "percent", self.COL_PROG)
        self.transfer_view.append_column(column)

        self.delete_column = gtk.TreeViewColumn("")
        self.delete_column.pack_start(cr_delete_icon, False)
        self.delete_column.add_attribute(cr_delete_icon, "pixbuf", self.COL_DELETE)
        self.transfer_view.append_column(self.delete_column)

        scrollwin = new_scrollarea()
        scrollwin.add(self.transfer_view)
        self.main_vbox.pack_start(scrollwin, True, True)

        style = self.transfer_view.get_style()
        abort_iconset = style.lookup_icon_set(gtk.STOCK_CLOSE)
        self.abort_icon = abort_iconset.render_icon(style, gtk.TEXT_DIR_NONE, gtk.STATE_NORMAL, gtk.ICON_SIZE_BUTTON)
        delete_iconset = style.lookup_icon_set(gtk.STOCK_DELETE)
        self.delete_icon = delete_iconset.render_icon(style, gtk.TEXT_DIR_NONE, gtk.STATE_NORMAL, gtk.ICON_SIZE_BUTTON)

        self.statusLabel = gtk.Label("")
        self.statusLabel.set_padding(3, 3)
        self.abort_all = gtk.Button("Abort all")
        self.delete_all = gtk.Button("Delete all")
        self.open_dldir = gtk.Button("Open download directory")

        status_hbox = gtk.HBox()
        status_hbox.set_size_request(-1, 50)
        status_hbox.pack_start(self.statusLabel, True, True)
        status_hbox.pack_start(self.open_dldir, False, False, padding=5)
        status_hbox.pack_start(self.delete_all, False, False, padding=5)
        status_hbox.pack_start(self.abort_all, False, False, padding=5)
        self.main_vbox.pack_start(status_hbox, False, False)

        # callbacks
        self.delete_all.connect("clicked", self.delete_all_cb)
        self.abort_all.connect("clicked", self.abort_all_cb)
        self.open_dldir.connect("clicked", self.open_dldir_cb)
        close_eb.connect("button-press-event", self.close_cb)

        self.page.pack_start(self.main_vbox)
        self.page.show_all()
        self.main_gui.add_page(self.page)

    def row_activated_cb(self, treeview, path, view_column):
        row = self.transfer_list[path]

        transfer = row[self.COL_TRANSFER]

        if view_column == self.delete_column:
            transfer.clicked()

    def abort_all_cb(self, widget, data=None):
        for row in self.transfer_list:
            transfer = row[self.COL_TRANSFER]
            transfer.abort()

    def delete_all_cb(self, widget, data=None):
        for row in self.transfer_list:
            transfer = row[self.COL_TRANSFER]
            transfer.delete()

    def open_dldir_cb(self, widget, data=None):
        open_with_file_manager(self.filesharing.get_download_path())

    def close_cb(self, widget, event):
        if self.page.is_visible:
            self.main_gui.hide_page(self.page)

        if self.statusbar_icon != None:
            self.main_gui.remove_statusbar_icon(self.statusbar_icon)
            self.statusbar_icon = None
        return True

    def open_filetransfergui(self):
        if self.statusbar_icon == None:
            self.statusbar_icon = self.main_gui.add_statusbar_icon(
                self.ft_statusbar_icon, "File Transfers", self.statusbar_icon_clicked
            )

    def statusbar_icon_clicked(self):
        if self.page.is_visible:
            self.main_gui.hide_page(self.page)
        else:
            self.main_gui.show_page(self.page)

    def add_transfer(self, title, size, abort_cb, ctx=None, silent=False):
        self.open_filetransfergui()

        title = cut_text(title, MAX_TITLE)

        # popping up the transfer notification window, that returns
        # a handel to a function advancing its progressbar
        dialog = None
        if not silent:
            dialog = Transfer_Dialog(self.main_gui.get_main_window(), title, abort_cb, ctx)

        transfer = Transfer_Item(self, title, size, abort_cb, ctx, dialog)
        riter = self.transfer_list.append([self.ft_icon, title, 0, transfer, self.abort_icon])
        transfer.iter = riter

        return transfer