Пример #1
0
    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        Gtk.Box.__init__(self)
        self.strip = StripUI(element)

        self.conf = context.get_conf()
        self.dispatcher = context.get_dispatcher()
        self.repository = context.get_repository()
        self.network = False
        self.dispatcher.connect_ui("opencast-status", self.network_status)
Пример #2
0
    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        gtk.Box.__init__(self)
        self.strip = StripUI(element)

        self.conf = context.get_conf()
        self.dispatcher = context.get_dispatcher()
        self.repository = context.get_repository()
        self.network = False

        self.dispatcher.connect("net-up", self.network_status, True)
        self.dispatcher.connect("net-down", self.network_status, False)
Пример #3
0
    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        Gtk.Box.__init__(self)
        self.strip = StripUI(element)

        self.conf = context.get_conf()
        self.dispatcher = context.get_dispatcher()
        self.repository = context.get_repository()
        self.network = False
        self.dispatcher.connect_ui("opencast-status", self.network_status)
Пример #4
0
    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        gtk.Box.__init__(self)
        self.strip = StripUI(element)
        
	self.conf = context.get_conf()
	self.dispatcher = context.get_dispatcher() 
	self.repository = context.get_repository()
	self.network = False	    

	self.dispatcher.connect("net-up", self.network_status, True)
	self.dispatcher.connect("net-down", self.network_status, False)
Пример #5
0
    def __init__(self):
        Gtk.Box.__init__(self)
        dbuilder= Gtk.Builder()
        dbuilder.add_from_file(get_ui_path('distrib.glade'))
        self.builder = dbuilder
        self.gui = dbuilder
        dbox = dbuilder.get_object("distbox")
        release = dbuilder.get_object("release_label")
        release.set_label(get_footer())

        recorder = dbuilder.get_object("button1")
        manager = dbuilder.get_object("button2")
        quit_button =  dbuilder.get_object("button3")
        shutdown_button =  dbuilder.get_object("button4")

        profile_button = dbuilder.get_object("profile_button")
        self.selected = dbuilder.get_object("selected_profile")
        self.update_selected_profile()

        strip = StripUI(None)
        strip.resize()
        strip.set_logo()
        dbox.pack_start(strip,False,False,0)
        dbox.reorder_child(strip,0)

        #Connect signals
        dispatcher = context.get_dispatcher()
        dispatcher.connect_ui("action-reload-profile", self.update_selected_profile)
        recorder.connect("clicked", self.emit_signal, "action-view-change", 0)
        manager.connect("clicked", self.emit_signal, "action-view-change", 1)
        quit_button.connect("clicked", self.emit_signal, "action-quit")
        shutdown_button.connect("clicked", self.emit_signal, "action-shutdown")
        profile_button.connect("clicked", self.on_profile_button)

        conf = context.get_conf()
        quit_button.set_visible(conf.get_boolean("basic", "quit"))
        shutdown_button.set_visible(conf.get_boolean("basic", "shutdown"))
        self.pack_start(dbox, True, True, 0)
Пример #6
0
class ManagerUI(gtk.Box):
    """
    Create Recording Listing in a VBOX with TreeView from an MP list
    """
    __gtype_name__ = 'Manager'

    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        gtk.Box.__init__(self)
        self.strip = StripUI(element)
        

	self.conf = context.get_conf()
	self.dispatcher = context.get_dispatcher() 
	self.repository = context.get_repository()
	self.network = False	    

	self.dispatcher.connect("net-up", self.network_status, True)
	self.dispatcher.connect("net-down", self.network_status, False)


    def sorting(self, treemodel, iter1, iter2, data, regular=True, ascending=1):	 
        """Basic Sort comparisson"""
        first =treemodel[iter1][data]
        second = treemodel[iter2][data]

        if  first >  second:
            return 1 * ascending

        elif first == second:
            if regular:
                if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                    ascending=-1
                # order by date
                response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
                return response
            else:
                return 0		       
        else:
            return -1 * ascending

    def sorting_text(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sort algorithm, giving similar value to capital and regular letters"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first != None:
            first = first.lower()
        if second != None:
            second = second.lower()

        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return -1  
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return 1  
            else:
                return -1

	    # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response 
        else:
            return -1 * ascending

    def sorting_empty(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sorting algorithm, placing empty values always and the end, both descending and ascending"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return -1  
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return 1  
            else:
                return -1

	    # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response 
        else:
            return -1 * ascending
        

#-------------------------------- DATA PRESENTATION --------------------------------


    def size_readable(self,column,cell,model,iterador,user_data):
        """Generates human readable string for a number.
        Returns: A string form of the number using size abbreviations (KB, MB, etc.) """
        resultado = readable.size(cell.get_property('text'))
        cell.set_property('text',resultado)
        return resultado

    def date_readable(self,column,cell,model,iterador,user_data):
        """ Generates date readable string from an isoformat datetime. """		
        novo=readable.date(cell.get_property('text'))
        cell.set_property('text',novo)		
        return novo

    def time_readable(self,column,cell,model,iterador,user_data):
        """Generates date hout:minute:seconds from seconds."""		
        ms = cell.get_property('text')
        novo = readable.time(int(ms)/1000)
        cell.set_property('text',novo)		
        return novo

    def list_readable(self,listed):
        """Generates a string of items from a list, separated by commas."""		
        novo = readable.list(listed)
        return novo

    def status_readable(self,column,cell,model,iterator,user_data):
        """Set text equivalent for numeric status of mediapackages."""	
        ms = cell.get_property('text')
        novo = mediapackage.mp_status[int(ms)]
        cell.set_property('text',novo)

    def operation_readable(self,column,cell,model,iterator,operation):
        """Sets text equivalent for numeric operation status of mediapackages."""	
        mp=self.repository.get((model[iterator])[0])
        status=mp.getOpStatus(operation)
        out = mediapackage.op_status[status]
        cell.set_property('text', out)
        old_style = context.get_conf().get_color_style()
        if old_style:
            color = model[iterator][8]
        else:
            palette = context.get_conf().get_palette()
            color = palette[status]
        cell.set_property('background', color)
     

    def series_readable(self,column,cell,model,iterator,user_data):
        """Sets text equivalent for numeric status of mediapackages."""	
        ms = cell.get_property('text')
        if ms == None:
            novo=""
        else: 
            novo=self.repository.get((model[iterator])[0]).series_title
        cell.set_property('text',novo)
        return novo

#---------------------------------------- ACTION CALLBACKS ------------------

    def ingest_question(self,package):            
        """Pops up a question dialog for available operations."""
        buttons = None
        disabled = not self.conf.get_boolean("ingest", "active")
        day,night = context.get_worker().get_all_job_types_by_mp(package)
        jobs = day+night
        text = {"title" : "Media Manager",
                "main" : "Which operation do you want to perform?"
                        }
        text['text'] = ''
        icon = message.QUESTION

        if disabled:                                         
            text['text']=text['text']+"The ingest service is disabled."

        if not self.network:                                         
            text['text']=text['text']+"Ingest disabled because of network problems."
            for job in day:
                if job.lower().count("ingest"):
                    jobs.remove(job)            
                    day.remove(job)
            for job in night:
                if job.lower().count("ingest"):
                    pass
                    #jobs.remove(job)            
                    #night.remove(job)

        for job in day:
            op_state = package.operation[job.lower().replace(" ", "")]
            if op_state == mediapackage.OP_DONE:
                text['text']="\n" + text['text'] + job + " already perfomed"
            elif op_state == mediapackage.OP_NIGHTLY:
                text['text']="\n"+ text['text'] + job + " will be performed tonight" 
            

        index = 0
        response_dict = {}
        grouped1 = []
        grouped2 = []
        for job in day:
            index+=1  
            response_dict[index]=job
            grouped1.append(job)
            grouped1.append(index)

        for job in night:
            index+=1
            response_dict[index]=job
            grouped2.append(job)
            grouped2.append(index)

        grouped2.append("Cancel")
        grouped2.append(0) 

        buttons = tuple(grouped1)
        buttons2 = tuple(grouped2)
        if icon == message.QUESTION:
            icon = "INGEST"

        warning = message.PopUp(icon,text,
                                context.get_mainwindow(),
                                buttons2, buttons)

        if warning.response == 0:               
            return True
        elif warning.response == gtk.RESPONSE_OK: # Warning
            return True
        else:
            chosen_job = response_dict[warning.response].lower().replace (" ", "_")
            if chosen_job.count('nightly'):
                context.get_worker().do_job_nightly(chosen_job.replace("_",""), package)
            else:                
                context.get_worker().do_job(chosen_job, package)
            return True


    def play(self,key):
	"""Retrieves mediapackage and send videos to player."""
	logger.info("Play: "+str(key))
	package = self.repository.get(key)

	if package.status == mediapackage.RECORDED:
	    self.dispatcher.emit("play-list", package)
	else:			
	    text = {"title" : "Media Manager",
		    "main" : "This recording can't be played",
		    }
	    buttons = ( gtk.STOCK_OK, gtk.RESPONSE_OK )
	    message.PopUp(message.WARNING, text, 
                          context.get_mainwindow(),
                          buttons)
	return True


    def change_mode(self,button):
        """Handles a change mode"""
	text=button.get_children()[0].get_text()
        
	if text == "Recorder":
	    self.dispatcher.emit("change-mode", 0)
	else:
	    self.dispatcher.emit("change-mode", 2)


#--------------------------------------- METADATA -----------------------------

    def edit(self,key):
        """Pop ups the Metadata Editor"""
	logger.info("Edit: "+str(key))
	selected_mp = self.repository.get(key)
	Metadata(selected_mp)
	self.repository.update(selected_mp)

    def info(self,key):
        """Pops up de MP info dialog"""
        logger.info("Info: "+str(key))
        MPinfo(key)

    def do_resize(self, buttonlist, secondlist=[]): 
        """Force a resize on the Media Manager"""
        size = context.get_mainwindow().get_size()
        self.strip.resize()
	altura = size[1]
	anchura = size[0]

	k1 = anchura / 1920.0
	k2 = altura / 1080.0
	self.proportion = k1

	for name  in buttonlist:
	    button = self.gui.get_object(name) 
	    button.set_property("width-request", int(k2*100) )
	    button.set_property("height-request", int(k2*100) )

	    image = button.get_children()
	    if type(image[0]) == gtk.Image:
		image[0].set_pixel_size(int(k1*80))   

	    elif type(image[0]) == gtk.VBox:
		for element in image[0].get_children():
		    if type(element) == gtk.Image:
			element.set_pixel_size(int(k1*46))

	for name in secondlist:
	    button = self.gui.get_object(name) 
	    button.set_property("width-request", int(k2*85) )
	    button.set_property("height-request", int(k2*85) )

	    image = button.get_children()
	    if type(image[0]) == gtk.Image:
		image[0].set_pixel_size(int(k1*56))   

	    elif type(image[0]) == gtk.VBox:
		for element in image[0].get_children():
		    if type(element) == gtk.Image:
			element.set_pixel_size(int(k1*46))

	return True

    def delete(self,key):
        """Pops up a dialog. If response is positive, deletes a MP."""
	logger.info("Delete: "+str(key))
	package = self.repository.get(key)
	t1 = "This action will remove the recording from the hard disk."
	t2 = 'Recording:  "'+package.getTitle()+'"'
	text = {"title" : "Media Manager",
		"main" : "Are you sure you want to delete?",
		"text" : t1+"\n\n"+t2
		    }
	buttons = ( gtk.STOCK_DELETE, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
	warning = message.PopUp(message.WARNING, text,
                                context.get_mainwindow(),
                                buttons)

	if warning.response in message.POSITIVE:                
	    self.repository.delete(package)
	    return True
	else:
	    return False


    def network_status(self, signal, status):
        """Updates the signal status from a received signal"""
        self.network = status           
Пример #7
0
class ManagerUI(gtk.Box):
    """
    Create Recording Listing in a VBOX with TreeView from an MP list
    """
    __gtype_name__ = 'Manager'

    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        gtk.Box.__init__(self)
        self.strip = StripUI(element)

        self.conf = context.get_conf()
        self.dispatcher = context.get_dispatcher()
        self.repository = context.get_repository()
        self.network = False

        self.dispatcher.connect("net-up", self.network_status, True)
        self.dispatcher.connect("net-down", self.network_status, False)

    def sorting(self,
                treemodel,
                iter1,
                iter2,
                data,
                regular=True,
                ascending=1):
        """Basic Sort comparisson"""
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]

        if first > second:
            return 1 * ascending

        elif first == second:
            if regular:
                if self.vista.get_column(self.equivalent[data]).get_sort_order(
                ) == gtk.SORT_DESCENDING:
                    ascending = -1
                # order by date
                response = self.sorting(treemodel, iter1, iter2, 6, False,
                                        ascending)
                return response
            else:
                return 0
        else:
            return -1 * ascending

    def sorting_text(self,
                     treemodel,
                     iter1,
                     iter2,
                     data,
                     regular=True,
                     ascending=1):
        """Sort algorithm, giving similar value to capital and regular letters"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first != None:
            first = first.lower()
        if second != None:
            second = second.lower()

        if first in ["", None] and second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response

        elif first in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                return -1
            else:
                return 1

        elif second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                return 1
            else:
                return -1

# Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response
        else:
            return -1 * ascending

    def sorting_empty(self,
                      treemodel,
                      iter1,
                      iter2,
                      data,
                      regular=True,
                      ascending=1):
        """Sorting algorithm, placing empty values always and the end, both descending and ascending"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first in ["", None] and second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response

        elif first in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                return -1
            else:
                return 1

        elif second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                return 1
            else:
                return -1

# Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == gtk.SORT_DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response
        else:
            return -1 * ascending

#-------------------------------- DATA PRESENTATION --------------------------------

    def size_readable(self, column, cell, model, iterador, user_data):
        """Generates human readable string for a number.
        Returns: A string form of the number using size abbreviations (KB, MB, etc.) """
        resultado = readable.size(cell.get_property('text'))
        cell.set_property('text', resultado)
        return resultado

    def date_readable(self, column, cell, model, iterador, user_data):
        """ Generates date readable string from an isoformat datetime. """
        novo = readable.date(cell.get_property('text'))
        cell.set_property('text', novo)
        return novo

    def time_readable(self, column, cell, model, iterador, user_data):
        """Generates date hout:minute:seconds from seconds."""
        ms = cell.get_property('text')
        novo = readable.time(int(ms) / 1000)
        cell.set_property('text', novo)
        return novo

    def list_readable(self, listed):
        """Generates a string of items from a list, separated by commas."""
        novo = readable.list(listed)
        return novo

    def status_readable(self, column, cell, model, iterator, user_data):
        """Set text equivalent for numeric status of mediapackages."""
        ms = cell.get_property('text')
        novo = mediapackage.mp_status[int(ms)]
        cell.set_property('text', novo)

    def operation_readable(self, column, cell, model, iterator, operation):
        """Sets text equivalent for numeric operation status of mediapackages."""
        mp = self.repository.get((model[iterator])[0])
        status = mp.getOpStatus(operation)
        out = mediapackage.op_status[status]
        cell.set_property('text', out)
        old_style = context.get_conf().get_color_style()
        if old_style:
            color = model[iterator][8]
        else:
            palette = context.get_conf().get_palette()
            color = palette[status]
        cell.set_property('background', color)

    def series_readable(self, column, cell, model, iterator, user_data):
        """Sets text equivalent for numeric status of mediapackages."""
        ms = cell.get_property('text')
        if ms == None:
            novo = ""
        else:
            novo = self.repository.get((model[iterator])[0]).series_title
        cell.set_property('text', novo)
        return novo

#---------------------------------------- ACTION CALLBACKS ------------------

    def ingest_question(self, package):
        """Pops up a question dialog for available operations."""
        buttons = None
        disabled = not self.conf.get_boolean("ingest", "active")
        day, night = context.get_worker().get_all_job_types_by_mp(package)
        jobs = day + night
        text = {
            "title": "Media Manager",
            "main": "Which operation do you want to perform?"
        }
        text['text'] = ''
        icon = message.QUESTION

        if disabled:
            text['text'] = text['text'] + "The ingest service is disabled."

        if not self.network:
            text['text'] = text[
                'text'] + "Ingest disabled because of network problems."
            for job in day:
                if job.lower().count("ingest"):
                    jobs.remove(job)
                    day.remove(job)
            for job in night:
                if job.lower().count("ingest"):
                    pass
                    #jobs.remove(job)
                    #night.remove(job)

        for job in day:
            op_state = package.operation[job.lower().replace(" ", "")]
            if op_state == mediapackage.OP_DONE:
                text['text'] = "\n" + text['text'] + job + " already perfomed"
            elif op_state == mediapackage.OP_NIGHTLY:
                text['text'] = "\n" + text[
                    'text'] + job + " will be performed tonight"

        index = 0
        response_dict = {}
        grouped1 = []
        grouped2 = []
        for job in day:
            index += 1
            response_dict[index] = job
            grouped1.append(job)
            grouped1.append(index)

        for job in night:
            index += 1
            response_dict[index] = job
            grouped2.append(job)
            grouped2.append(index)

        grouped2.append("Cancel")
        grouped2.append(0)

        buttons = tuple(grouped1)
        buttons2 = tuple(grouped2)
        if icon == message.QUESTION:
            icon = "INGEST"

        warning = message.PopUp(icon, text, context.get_mainwindow(), buttons2,
                                buttons)

        if warning.response == 0:
            return True
        elif warning.response == gtk.RESPONSE_OK:  # Warning
            return True
        else:
            chosen_job = response_dict[warning.response].lower().replace(
                " ", "_")
            if chosen_job.count('nightly'):
                context.get_worker().do_job_nightly(
                    chosen_job.replace("_", ""), package)
            else:
                context.get_worker().do_job(chosen_job, package)
            return True

    def play(self, key):
        """Retrieves mediapackage and send videos to player."""
        logger.info("Play: " + str(key))
        package = self.repository.get(key)

        if package.status == mediapackage.RECORDED:
            self.dispatcher.emit("play-list", package)
        else:
            text = {
                "title": "Media Manager",
                "main": "This recording can't be played",
            }
            buttons = (gtk.STOCK_OK, gtk.RESPONSE_OK)
            message.PopUp(message.WARNING, text, context.get_mainwindow(),
                          buttons)
        return True

    def change_mode(self, button):
        """Handles a change mode"""
        text = button.get_children()[0].get_text()

        if text == "Recorder":
            self.dispatcher.emit("change-mode", 0)
        else:
            self.dispatcher.emit("change-mode", 2)


#--------------------------------------- METADATA -----------------------------

    def edit(self, key):
        """Pop ups the Metadata Editor"""
        logger.info("Edit: " + str(key))
        selected_mp = self.repository.get(key)
        Metadata(selected_mp)
        self.repository.update(selected_mp)

    def info(self, key):
        """Pops up de MP info dialog"""
        logger.info("Info: " + str(key))
        MPinfo(key)

    def do_resize(self, buttonlist, secondlist=[]):
        """Force a resize on the Media Manager"""
        size = context.get_mainwindow().get_size()
        self.strip.resize()
        altura = size[1]
        anchura = size[0]

        k1 = anchura / 1920.0
        k2 = altura / 1080.0
        self.proportion = k1

        for name in buttonlist:
            button = self.gui.get_object(name)
            button.set_property("width-request", int(k2 * 100))
            button.set_property("height-request", int(k2 * 100))

            image = button.get_children()
            if type(image[0]) == gtk.Image:
                image[0].set_pixel_size(int(k1 * 80))

            elif type(image[0]) == gtk.VBox:
                for element in image[0].get_children():
                    if type(element) == gtk.Image:
                        element.set_pixel_size(int(k1 * 46))

        for name in secondlist:
            button = self.gui.get_object(name)
            button.set_property("width-request", int(k2 * 85))
            button.set_property("height-request", int(k2 * 85))

            image = button.get_children()
            if type(image[0]) == gtk.Image:
                image[0].set_pixel_size(int(k1 * 56))

            elif type(image[0]) == gtk.VBox:
                for element in image[0].get_children():
                    if type(element) == gtk.Image:
                        element.set_pixel_size(int(k1 * 46))

        return True

    def delete(self, key):
        """Pops up a dialog. If response is positive, deletes a MP."""
        logger.info("Delete: " + str(key))
        package = self.repository.get(key)
        t1 = "This action will remove the recording from the hard disk."
        t2 = 'Recording:  "' + package.getTitle() + '"'
        text = {
            "title": "Delete",
            "main": "Are you sure you want to delete?",
            "text": t1 + "\n\n" + t2
        }
        buttons = (gtk.STOCK_DELETE, gtk.RESPONSE_OK, gtk.STOCK_CANCEL,
                   gtk.RESPONSE_REJECT)
        warning = message.PopUp(message.WARNING, text,
                                context.get_mainwindow(), buttons)

        if warning.response in message.POSITIVE:
            self.repository.delete(package)
            return True
        else:
            return False

    def network_status(self, signal, status):
        """Updates the signal status from a received signal"""
        self.network = status
Пример #8
0
class ManagerUI(Gtk.Box):
    """
    Create Recording Listing in a VBOX with TreeView from an MP list
    """
    __gtype_name__ = 'Manager'

    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        Gtk.Box.__init__(self)
        self.strip = StripUI(element)
        
	self.conf = context.get_conf()
	self.dispatcher = context.get_dispatcher() 
	self.repository = context.get_repository()
	self.network = False	    

	self.dispatcher.connect("net-up", self.network_status, True)
	self.dispatcher.connect("net-down", self.network_status, False)


    def sorting(self, treemodel, iter1, iter2, data, regular=True, ascending=1):	 
        """Basic Sort comparisson"""
        first =treemodel[iter1][data]
        second = treemodel[iter2][data]

        if  first >  second:
            return 1 * ascending

        elif first == second:
            if regular:
                if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                    ascending=-1
                # order by date
                response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
                return response
            else:
                return 0		       
        else:
            return -1 * ascending

    def sorting_text(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sort algorithm, giving similar value to capital and regular letters"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first != None:
            first = first.lower()
        if second != None:
            second = second.lower()

        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:	
                return -1  
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:	
                return 1  
            else:
                return -1

	    # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response 
        else:
            return -1 * ascending

    def sorting_empty(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sorting algorithm, placing empty values always and the end, both descending and ascending"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:	
                return -1  
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:	
                return 1  
            else:
                return -1

	    # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response 
        else:
            return -1 * ascending
        

#---------------------------------------- ACTION CALLBACKS ------------------

    def ingest_question(self,package):            
        """Pops up a question dialog for available operations."""
        buttons = None
        disabled = not self.conf.get_boolean("ingest", "active")
        day,night = context.get_worker().get_all_job_types_by_mp(package)
        jobs = day+night
        text = {"title" : _("Media Manager"),
                "main" : _("Which operation do you want to perform?")
               }
        text['text'] = ''
        icon = message.QUESTION

        if disabled or not self.network:
            for job in day:
                if job.lower().count("ingest"):
                    jobs.remove(job)            
                    day.remove(job)
            for job in night:
                if job.lower().count("ingest"):
                    pass
                    #jobs.remove(job)            
                    #night.remove(job)

        if disabled:                                         
            text['text']=text['text']+_("The ingest service is disabled. ")
        elif not self.network:
            text['text'] = text['text'] + _("Ingest disabled because of network problems. ")

        for job in day:
            op_state = package.operation[job.lower().replace(" ", "")]
            if op_state == mediapackage.OP_DONE:
                text['text']="\n" + text['text'] + _("{0} already performed").format(OPERATION_NAMES[job])
            elif op_state == mediapackage.OP_NIGHTLY:
                text['text']="\n"+ text['text'] + _("{0} will be performed tonight").format(OPERATION_NAMES[job]) 
            

        index = 0
        response_dict = {}
        grouped1 = []
        grouped2 = []
        for job in day:
            index+=1  
            response_dict[index]=job
            grouped1.append(job)
            grouped1.append(index)

        for job in night:
            index+=1
            response_dict[index]=job
            grouped2.append(job)
            grouped2.append(index)

        grouped2.append("Cancel")
        grouped2.append(0) 

        buttons = tuple(grouped1)
        buttons2 = tuple(grouped2)
        if icon == message.QUESTION:
            icon = "INGEST"

        warning = message.PopUp(icon,text,
                                context.get_mainwindow(),
                                buttons2, buttons)

        if warning.response == 0:               
            return True
        elif warning.response == -4:
            return True # Escape key used
        elif warning.response == Gtk.ResponseType.OK: # Warning
            return True
        else:
            chosen_job = response_dict[warning.response].lower().replace (" ", "_")
            if chosen_job.count('nightly'):
                context.get_worker().do_job_nightly(chosen_job.replace("_",""), package)
            else:                
                context.get_worker().do_job(chosen_job, package)
            return True



#--------------------------------------- METADATA -----------------------------

    def edit(self,key):
        """Pop ups the Metadata Editor"""
	logger.info("Edit: {0}".format(str(key)))
	selected_mp = self.repository.get(key)
	Metadata(selected_mp, series.get_series())
	self.repository.update(selected_mp)

    def info(self,key):
        """Pops up de MP info dialog"""
        logger.info("Info: {0}".format(str(key)))
        MPinfo(key)

    def do_resize(self, buttonlist, secondlist=[]): 
        """Force a resize on the Media Manager"""
        size = context.get_mainwindow().get_size()
        self.strip.resize()
	altura = size[1]
	anchura = size[0]

	k1 = anchura / 1920.0
	k2 = altura / 1080.0
	self.proportion = k1

	for name in buttonlist:
	    button = self.gui.get_object(name) 
	    button.set_property("width-request", int(k1*100) )
	    button.set_property("height-request", int(k1*100) )

	    image = button.get_children()
	    if type(image[0]) == Gtk.Image:
		image[0].set_pixel_size(int(k1*80))   

	    elif type(image[0]) == Gtk.VBox:
		for element in image[0].get_children():
		    if type(element) == Gtk.Image:
			element.set_pixel_size(int(k1*46))

	for name in secondlist:
	    button2 = self.gui.get_object(name) 
	    button2.set_property("width-request", int(k2*85) )
	    button2.set_property("height-request", int(k2*85) )

	    image = button2.get_children()
	    if type(image[0]) == Gtk.Image:
		image[0].set_pixel_size(int(k1*56))
                image[0].show()

	    elif type(image[0]) == Gtk.VBox:
		for element in image[0].get_children():
		    if type(element) == Gtk.Image:
			element.set_pixel_size(int(k1*46))

	return True

    def delete(self,key):
        """Pops up a dialog. If response is positive, deletes a MP."""
	logger.info("Delete: {0}".format(str(key)))
	package = self.repository.get(key)
	t1 = _("This action will remove the recording from the hard disk.")
	t2 = _('Recording: "{0}"').format(package.getTitle())
	text = {"title" : _("Media Manager"),
		"main" : _("Are you sure you want to delete?"),
		"text" : t1+"\n\n"+t2
		    }
	buttons = ( Gtk.STOCK_DELETE, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
	warning = message.PopUp(message.WARN_DELETE, text,
                                context.get_mainwindow(),
                                buttons)

	if warning.response in message.POSITIVE:                
	    self.repository.delete(package)
	    return True
	else:
	    return False


    def network_status(self, signal, status):
        """Updates the signal status from a received signal"""
        self.network = status           
Пример #9
0
class ManagerUI(Gtk.Box):
    """
    Create Recording Listing in a VBOX with TreeView from an MP list
    """
    __gtype_name__ = 'Manager'

    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        Gtk.Box.__init__(self)
        self.strip = StripUI(element)

        self.conf = context.get_conf()
        self.dispatcher = context.get_dispatcher()
        self.repository = context.get_repository()
        self.network = False
        self.dispatcher.connect_ui("opencast-status", self.network_status)


    def sorting(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Basic Sort comparisson"""
        first =treemodel[iter1][data]
        second = treemodel[iter2][data]

        if  first >  second:
            return 1 * ascending

        elif first == second:
            if regular:
                if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                    ascending=-1
                # order by date
                response = self.sorting(treemodel,iter1,iter2,6,False,ascending)
                return response
            else:
                return 0
        else:
            return -1 * ascending

    def sorting_text(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sort algorithm, giving similar value to capital and regular letters"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first != None:
            first = first.lower()
        if second != None:
            second = second.lower()

        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending)
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                return -1
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                return 1
            else:
                return -1

            # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending)
            return response
        else:
            return -1 * ascending

    def sorting_empty(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sorting algorithm, placing empty values always and the end, both descending and ascending"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending)
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                return -1
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                return 1
            else:
                return -1

            # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == Gtk.SortType.DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending)
            return response
        else:
            return -1 * ascending


#---------------------------------------- ACTION CALLBACKS ------------------

    def ingest_question(self,package):
        """Pops up a question dialog for available operations."""
        disabled = not self.conf.get_boolean("ingest", "active")
        day,night = context.get_worker().get_all_job_types_by_mp(package)
        jobs = day+night
        text = {"title" : _("Media Manager"),
                "main" : _("Which operation do you want to perform?")
               }
        text['text'] = ''

        if disabled or not self.network:
            for job in day:
                if job.lower().count("ingest"):
                    jobs.remove(job)
                    day.remove(job)
            for job in night:
                if job.lower().count("ingest"):
                    pass
                    #jobs.remove(job)
                    #night.remove(job)

        if disabled:
            text['text']=text['text']+_("The ingest service is disabled. ")
        elif not self.network:
            text['text'] = text['text'] + _("Ingest disabled because of network problems. ")

        for job in day:
            op_state = package.operations[job.lower().replace(" ", "")]
            if op_state == mediapackage.OP_DONE:
                text['text']=text['text'] + "\n" + _("{0} already performed").format(OPERATION_NAMES.get(job, job))
            elif op_state == mediapackage.OP_NIGHTLY:
                text['text']=text['text'] + "\n" + _("{0} will be performed tonight").format(OPERATION_NAMES.get(job, job))


        response_list = ['Ingest', # Resp 1
                         'Ingest Nightly', # Resp 2
                         'Cancel Ingest Nightly', # Resp 3
                         'Export to Zip', # Resp 4
                         'Export to Zip Nightly', # Resp 5
                         'Cancel Export to Zip Nightly', # Resp 6
                         'Side by Side', # Resp 7
                         'Side by Side Nightly', # Resp 8
                         'Cancel Side by Side Nightly'] # Resp 9

        operations = {}
        for job in jobs:
            if job in response_list:
                operations[job] = response_list.index(job)+1


        operations_dialog = message.PopUp(message.OPERATIONS,text,
                                context.get_mainwindow(),
                                operations)

        if operations_dialog.response == Gtk.ResponseType.REJECT or \
            operations_dialog.response == Gtk.ResponseType.DELETE_EVENT or \
            operations_dialog.response == Gtk.ResponseType.OK:
            return True

        elif 0 < operations_dialog.response <= len(response_list):
            chosen_job = response_list[operations_dialog.response-1].lower().replace (" ", "")
            if chosen_job.count('nightly'):
                context.get_worker().do_job_nightly(chosen_job.replace("_",""), package)
            else:
                context.get_worker().do_job(chosen_job, package)
            return True

        else:
            logger.error("Incorrect operation response: {}".format(operations_dialog.response))
            return False



#--------------------------------------- METADATA -----------------------------

    def edit(self,key):
        """Pop ups the Metadata Editor"""
        logger.info("Edit: {0}".format(str(key)))
        selected_mp = self.repository.get(key)
        Metadata(selected_mp)
        self.repository.update(selected_mp)

    def info(self,key):
        """Pops up de MP info dialog"""
        logger.info("Info: {0}".format(str(key)))
        text = self.get_mp_info(key)
        text['title'] = 'Mediapackage Info'
        message.PopUp(message.MP_INFO, text,
                      context.get_mainwindow(),
                      response_action=self.create_mp_info_response(text['folder']),
                      close_on_response=False)


    def create_mp_info_response(self, folder):
        def on_mp_info_response(response_id, **kwargs):
            """ Opens the MP folder """
            open_folder(folder)

        return on_mp_info_response

    def get_mp_info(self,key):
        """ Retrieves a dictionary with the information of the MP
        with the given key

        Args:
            key (str): the MP identifier

        Returns:
            Dict {}: with the label of the info.glade dialog as key
                    and the content of the label as values.
        """
        mp = self.repository.get(key)

        data = set_manifest_json(mp)

        # General
        data['title_mp'] = data['title']
        del data['title']

        data['duration'] = readable.time((data['duration'])/1000)
        data['size'] = readable.size(data['size'])
        data['created'] = readable.date(mp.getStartDateAsString(),
                                   "%B %d, %Y - %H:%M").replace(' 0',' ')

        if data.has_key('seriestitle'):
            data['isPartOf'] = data['seriestitle']

        # Operations
        for op,status in data['operations'].iteritems():
            data[op] = mediapackage.op_status[status]
        del data['operations']

        # Tracks
        tracks = []
        for track in data['media']['track']:
            t = {}
            t[_('Name:')] = track['id']
            t[_('Type:')] = track['mimetype']
            t[_('Flavor:')] = track['type']
            t[_('File:')] = path.split(track['url'])[1]
            tracks.append(t)
        if tracks:
            data['tracks'] = tracks
            del data['media']

        # Catalogs
        catalogs = []
        for catalog in data['metadata']['catalog']:
            c = {}
            c[_('Name:')] = catalog['id']
            c[_('Flavor:')] = catalog['type']
            c[_('Type:')] = catalog['mimetype']
            catalogs.append(c)
        if catalogs:
            data['catalogs'] = catalogs
            del data['metadata']

        return data

    def do_resize(self, buttonlist, secondlist=[]):
        """Force a resize on the Media Manager"""
        size = context.get_mainwindow().get_size()
        self.strip.resize()
        altura = size[1]
        anchura = size[0]

        k1 = anchura / 1920.0
        k2 = altura / 1080.0
        self.proportion = k1

        for name in buttonlist:
            button = self.gui.get_object(name)
            button.set_property("width-request", int(k1*100) )
            button.set_property("height-request", int(k1*100) )

            resize_button(button,size_image=k1*80,size_vbox=k1*46)

        for name in secondlist:
            button2 = self.gui.get_object(name)
            button2.set_property("width-request", int(k2*85) )
            button2.set_property("height-request", int(k2*85) )

            resize_button(button2.get_children()[0],size_image=k1*56,size_vbox=k1*46)

        return True

    def delete(self,key, response=None):
        """Pops up a dialog. If response is positive, deletes a MP."""
        self.selected = key
        package = self.repository.get(key)
        logger.info("Delete: {0}".format(str(key)))
        t1 = _("This action will remove the recording from the hard disk.")
        t2 = _('Recording: "{0}"').format(package.getTitle())
        text = {"title" : _("Media Manager"),
                "main" : _("Are you sure you want to delete?"),
                "text" : t1+"\n\n"+t2
                    }
        buttons = ( Gtk.STOCK_DELETE, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL, Gtk.ResponseType.REJECT)
        message.PopUp(message.WARN_DELETE, text,
                      context.get_mainwindow(),
                      buttons, response)

    def network_status(self, signal, status):
        """Updates the signal status from a received signal"""
        self.network = status
Пример #10
0
class ManagerUI(Gtk.Box):
    """
    Create Recording Listing in a VBOX with TreeView from an MP list
    """
    __gtype_name__ = 'Manager'

    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        Gtk.Box.__init__(self)
        self.strip = StripUI(element)

        self.conf = context.get_conf()
        self.dispatcher = context.get_dispatcher()
        self.repository = context.get_repository()
        self.network = False
        self.dispatcher.connect_ui("opencast-status", self.network_status)

    def sorting(self,
                treemodel,
                iter1,
                iter2,
                data,
                regular=True,
                ascending=1):
        """Basic Sort comparisson"""
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]

        if first > second:
            return 1 * ascending

        elif first == second:
            if regular:
                if self.vista.get_column(self.equivalent[data]).get_sort_order(
                ) == Gtk.SortType.DESCENDING:
                    ascending = -1
                # order by date
                response = self.sorting(treemodel, iter1, iter2, 6, False,
                                        ascending)
                return response
            else:
                return 0
        else:
            return -1 * ascending

    def sorting_text(self,
                     treemodel,
                     iter1,
                     iter2,
                     data,
                     regular=True,
                     ascending=1):
        """Sort algorithm, giving similar value to capital and regular letters"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first != None:
            first = first.lower()
        if second != None:
            second = second.lower()

        if first in ["", None] and second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response

        elif first in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                return -1
            else:
                return 1

        elif second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                return 1
            else:
                return -1

            # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response
        else:
            return -1 * ascending

    def sorting_empty(self,
                      treemodel,
                      iter1,
                      iter2,
                      data,
                      regular=True,
                      ascending=1):
        """Sorting algorithm, placing empty values always and the end, both descending and ascending"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first in ["", None] and second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response

        elif first in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                return -1
            else:
                return 1

        elif second in ["", None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                return 1
            else:
                return -1

            # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order(
            ) == Gtk.SortType.DESCENDING:
                ascending = -1
            # order by date
            response = self.sorting(treemodel, iter1, iter2, 6, False,
                                    ascending)
            return response
        else:
            return -1 * ascending

#---------------------------------------- ACTION CALLBACKS ------------------

    def ingest_question(self, package):
        """Pops up a question dialog for available operations."""
        disabled = not self.conf.get_boolean("ingest", "active")
        day, night = context.get_worker().get_all_job_types_by_mp(package)
        jobs = day + night
        text = {
            "title": _("Media Manager"),
            "main": _("Which operation do you want to perform?")
        }
        text['text'] = ''

        if disabled or not self.network:
            for job in day:
                if job.lower().count("ingest"):
                    jobs.remove(job)
                    day.remove(job)
            for job in night:
                if job.lower().count("ingest"):
                    pass
                    #jobs.remove(job)
                    #night.remove(job)

        if disabled:
            text['text'] = text['text'] + _("The ingest service is disabled. ")
        elif not self.network:
            text['text'] = text['text'] + _(
                "Ingest disabled because of network problems. ")

        for job in day:
            op_state = package.operation[job.lower().replace(" ", "")]
            if op_state == mediapackage.OP_DONE:
                text['text'] = text['text'] + "\n" + _(
                    "{0} already performed").format(
                        OPERATION_NAMES.get(job, job))
            elif op_state == mediapackage.OP_NIGHTLY:
                text['text'] = text['text'] + "\n" + _(
                    "{0} will be performed tonight").format(
                        OPERATION_NAMES.get(job, job))

        response_list = [
            'Ingest',  # Resp 1
            'Ingest Nightly',  # Resp 2
            'Cancel Ingest Nightly',  # Resp 3
            'Export to Zip',  # Resp 4
            'Export to Zip Nightly',  # Resp 5
            'Cancel Export to Zip Nightly',  # Resp 6
            'Side by Side',  # Resp 7
            'Side by Side Nightly',  # Resp 8
            'Cancel Side by Side Nightly'
        ]  # Resp 9

        operations = {}
        for job in jobs:
            if job in response_list:
                operations[job] = response_list.index(job) + 1

        operations_dialog = message.PopUp(message.OPERATIONS, text,
                                          context.get_mainwindow(), operations)

        if operations_dialog.response == Gtk.ResponseType.REJECT or \
            operations_dialog.response == Gtk.ResponseType.DELETE_EVENT or \
            operations_dialog.response == Gtk.ResponseType.OK:
            return True

        elif 0 < operations_dialog.response <= len(response_list):
            chosen_job = response_list[operations_dialog.response -
                                       1].lower().replace(" ", "")
            if chosen_job.count('nightly'):
                context.get_worker().do_job_nightly(
                    chosen_job.replace("_", ""), package)
            else:
                context.get_worker().do_job(chosen_job, package)
            return True

        else:
            logger.error("Incorrect operation response: {}".format(
                operations_dialog.response))
            return False


#--------------------------------------- METADATA -----------------------------

    def edit(self, key):
        """Pop ups the Metadata Editor"""
        logger.info("Edit: {0}".format(str(key)))
        selected_mp = self.repository.get(key)
        Metadata(selected_mp)
        self.repository.update(selected_mp)

    def info(self, key):
        """Pops up de MP info dialog"""
        logger.info("Info: {0}".format(str(key)))
        text = self.get_mp_info(key)
        text['title'] = 'Mediapackage Info'
        message.PopUp(message.MP_INFO,
                      text,
                      context.get_mainwindow(),
                      response_action=self.create_mp_info_response(
                          text['folder']),
                      close_on_response=False)

    def create_mp_info_response(self, folder):
        def on_mp_info_response(response_id, **kwargs):
            """ Opens the MP folder """
            open_folder(folder)

        return on_mp_info_response

    def get_mp_info(self, key):
        """ Retrieves a dictionary with the information of the MP
        with the given key

        Args:
            key (str): the MP identifier

        Returns:
            Dict {}: with the label of the info.glade dialog as key
                    and the content of the label as values.
        """
        mp = self.repository.get(key)

        data = set_manifest_json(mp)

        # General
        data['title_mp'] = data['title']
        del data['title']

        data['duration'] = readable.time((data['duration']) / 1000)
        data['size'] = readable.size(data['size'])
        data['created'] = readable.date(mp.getStartDateAsString(),
                                        "%B %d, %Y - %H:%M").replace(
                                            ' 0', ' ')

        if data.has_key('seriestitle'):
            data['isPartOf'] = data['seriestitle']

        # Operations
        for op, status in data['operations'].iteritems():
            data[op] = mediapackage.op_status[status]
        del data['operations']

        # Tracks
        tracks = []
        for track in data['media']['track']:
            t = {}
            t[_('Name:')] = track['id']
            t[_('Type:')] = track['mimetype']
            t[_('Flavor:')] = track['type']
            t[_('File:')] = path.split(track['url'])[1]
            tracks.append(t)
        if tracks:
            data['tracks'] = tracks
            del data['media']

        # Catalogs
        catalogs = []
        for catalog in data['metadata']['catalog']:
            c = {}
            c[_('Name:')] = catalog['id']
            c[_('Flavor:')] = catalog['type']
            c[_('Type:')] = catalog['mimetype']
            catalogs.append(c)
        if catalogs:
            data['catalogs'] = catalogs
            del data['metadata']

        return data

    def do_resize(self, buttonlist, secondlist=[]):
        """Force a resize on the Media Manager"""
        size = context.get_mainwindow().get_size()
        self.strip.resize()
        altura = size[1]
        anchura = size[0]

        k1 = anchura / 1920.0
        k2 = altura / 1080.0
        self.proportion = k1

        for name in buttonlist:
            button = self.gui.get_object(name)
            button.set_property("width-request", int(k1 * 100))
            button.set_property("height-request", int(k1 * 100))

            resize_button(button, size_image=k1 * 80, size_vbox=k1 * 46)

        for name in secondlist:
            button2 = self.gui.get_object(name)
            button2.set_property("width-request", int(k2 * 85))
            button2.set_property("height-request", int(k2 * 85))

            resize_button(button2.get_children()[0],
                          size_image=k1 * 56,
                          size_vbox=k1 * 46)

        return True

    def delete(self, key, response=None):
        """Pops up a dialog. If response is positive, deletes a MP."""
        self.selected = key
        package = self.repository.get(key)
        logger.info("Delete: {0}".format(str(key)))
        t1 = _("This action will remove the recording from the hard disk.")
        t2 = _('Recording: "{0}"').format(package.getTitle())
        text = {
            "title": _("Media Manager"),
            "main": _("Are you sure you want to delete?"),
            "text": t1 + "\n\n" + t2
        }
        buttons = (Gtk.STOCK_DELETE, Gtk.ResponseType.OK, Gtk.STOCK_CANCEL,
                   Gtk.ResponseType.REJECT)
        message.PopUp(message.WARN_DELETE, text, context.get_mainwindow(),
                      buttons, response)

    def network_status(self, signal, status):
        """Updates the signal status from a received signal"""
        self.network = status
Пример #11
0
class ManagerUI(gtk.Box):
    """
    Create Recording Listing in a VBOX with TreeView from an MP list
    """
    __gtype_name__ = 'Manager'

    def __init__(self, element):
        """elements set the previous area to which the top bar's back button points to"""
        gtk.Box.__init__(self)
        self.strip = StripUI(element)
        
	self.conf = context.get_conf()
	self.dispatcher = context.get_dispatcher() 
	self.repository = context.get_repository()
	self.network = False	    

	self.dispatcher.connect("net-up", self.network_status, True)
	self.dispatcher.connect("net-down", self.network_status, False)


    def sorting(self, treemodel, iter1, iter2, data, regular=True, ascending=1):	 
        """Basic Sort comparisson"""
        first =treemodel[iter1][data]
        second = treemodel[iter2][data]

        if  first >  second:
            return 1 * ascending

        elif first == second:
            if regular:
                if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                    ascending=-1
                # order by date
                response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
                return response
            else:
                return 0		       
        else:
            return -1 * ascending

    def sorting_text(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sort algorithm, giving similar value to capital and regular letters"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first != None:
            first = first.lower()
        if second != None:
            second = second.lower()

        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return -1  
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return 1  
            else:
                return -1

	    # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response 
        else:
            return -1 * ascending

    def sorting_empty(self, treemodel, iter1, iter2, data, regular=True, ascending=1):
        """Sorting algorithm, placing empty values always and the end, both descending and ascending"""
        # Null sorting
        first = treemodel[iter1][data]
        second = treemodel[iter2][data]
        if first in ["",None] and second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response

        elif  first in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return -1  
            else:
                return 1

        elif  second in ["",None]:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:	
                return 1  
            else:
                return -1

	    # Regular sorting
        if first > second:
            return 1 * ascending
        elif first == second:
            if self.vista.get_column(self.equivalent[data]).get_sort_order() == gtk.SORT_DESCENDING:
                ascending=-1
            # order by date
            response = self.sorting(treemodel,iter1,iter2,6,False,ascending) 
            return response 
        else:
            return -1 * ascending
        

#---------------------------------------- ACTION CALLBACKS ------------------

    def ingest_question(self,package):            
        """Pops up a question dialog for available operations."""
        buttons = None
        disabled = not self.conf.get_boolean("ingest", "active")
        day,night = context.get_worker().get_all_job_types_by_mp(package)
        jobs = day+night
        text = {"title" : _("Media Manager"),
                "main" : _("Which operation do you want to perform?")
               }
        text['text'] = ''
        icon = message.QUESTION

        if disabled:                                         
            text['text']=text['text']+_("The ingest service is disabled.")

        if not self.network:                                         
            text['text']=text['text']+_("Ingest disabled because of network problems. ")
            for job in day:
                if job.lower().count("ingest"):
                    jobs.remove(job)            
                    day.remove(job)
            for job in night:
                if job.lower().count("ingest"):
                    pass
                    #jobs.remove(job)            
                    #night.remove(job)

        for job in day:
            op_state = package.operation[job.lower().replace(" ", "")]
            if op_state == mediapackage.OP_DONE:
                text['text']="\n" + text['text'] + _("{0} already performed").format(OPERATION_NAMES[job])
            elif op_state == mediapackage.OP_NIGHTLY:
                text['text']="\n"+ text['text'] + _("{0} will be performed tonight").format(OPERATION_NAMES[job]) 
            

        index = 0
        response_dict = {}
        grouped1 = []
        grouped2 = []
        for job in day:
            index+=1  
            response_dict[index]=job
            grouped1.append(job)
            grouped1.append(index)

        for job in night:
            index+=1
            response_dict[index]=job
            grouped2.append(job)
            grouped2.append(index)

        grouped2.append("Cancel")
        grouped2.append(0) 

        buttons = tuple(grouped1)
        buttons2 = tuple(grouped2)
        if icon == message.QUESTION:
            icon = "INGEST"

        warning = message.PopUp(icon,text,
                                context.get_mainwindow(),
                                buttons2, buttons)

        if warning.response == 0:               
            return True
        elif warning.response == -4:
            return True # Escape key used
        elif warning.response == gtk.RESPONSE_OK: # Warning
            return True
        else:
            chosen_job = response_dict[warning.response].lower().replace (" ", "_")
            if chosen_job.count('nightly'):
                context.get_worker().do_job_nightly(chosen_job.replace("_",""), package)
            else:                
                context.get_worker().do_job(chosen_job, package)
            return True



#--------------------------------------- METADATA -----------------------------

    def edit(self,key):
        """Pop ups the Metadata Editor"""
	logger.info("Edit: {0}".format(str(key)))
	selected_mp = self.repository.get(key)
	Metadata(selected_mp, series.get_series())
	self.repository.update(selected_mp)

    def info(self,key):
        """Pops up de MP info dialog"""
        logger.info("Info: {0}".format(str(key)))
        MPinfo(key)

    def do_resize(self, buttonlist, secondlist=[]): 
        """Force a resize on the Media Manager"""
        size = context.get_mainwindow().get_size()
        self.strip.resize()
	altura = size[1]
	anchura = size[0]

	k1 = anchura / 1920.0
	k2 = altura / 1080.0
	self.proportion = k1

	for name in buttonlist:
	    button = self.gui.get_object(name) 
	    button.set_property("width-request", int(k1*100) )
	    button.set_property("height-request", int(k1*100) )

	    image = button.get_children()
	    if type(image[0]) == gtk.Image:
		image[0].set_pixel_size(int(k1*80))   

	    elif type(image[0]) == gtk.VBox:
		for element in image[0].get_children():
		    if type(element) == gtk.Image:
			element.set_pixel_size(int(k1*46))

	for name in secondlist:
	    button2 = self.gui.get_object(name) 
	    button2.set_property("width-request", int(k2*85) )
	    button2.set_property("height-request", int(k2*85) )

	    image = button2.get_children()
	    if type(image[0]) == gtk.Image:
		image[0].set_pixel_size(int(k1*56))
                image[0].show()

	    elif type(image[0]) == gtk.VBox:
		for element in image[0].get_children():
		    if type(element) == gtk.Image:
			element.set_pixel_size(int(k1*46))

	return True

    def delete(self,key):
        """Pops up a dialog. If response is positive, deletes a MP."""
	logger.info("Delete: {0}".format(str(key)))
	package = self.repository.get(key)
	t1 = _("This action will remove the recording from the hard disk.")
	t2 = _('Recording: "{0}"').format(package.getTitle())
	text = {"title" : _("Media Manager"),
		"main" : _("Are you sure you want to delete?"),
		"text" : t1+"\n\n"+t2
		    }
	buttons = ( gtk.STOCK_DELETE, gtk.RESPONSE_OK, gtk.STOCK_CANCEL, gtk.RESPONSE_REJECT)
	warning = message.PopUp(message.WARNING, text,
                                context.get_mainwindow(),
                                buttons)

	if warning.response in message.POSITIVE:                
	    self.repository.delete(package)
	    return True
	else:
	    return False


    def network_status(self, signal, status):
        """Updates the signal status from a received signal"""
        self.network = status