Source

vpackager / src / vpackager / viewcontrollers.py

Full commit
#!/usr/bin/env python

#    This file is part of vpackager.
#
#    vpackager is free software: you can redistribute it and/or modify
#    it under the terms of the GNU General Public License v2 as published by
#    the Free Software Foundation.
#
#    vpackager is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with vpackager.  If not, see <http://www.gnu.org/licenses/>.


import gtk
import dbutils
import dbviews
import guitools

__author__ = 'M0E-lnx'
__author_email__ = 'moc.liamg@xnl.E0M'[::-1]
__version__ = '0.1'

class QueueController(object):
    """ Controller for the queue view"""
    def __init__(self, model, view):
        self.model = model
        self.view = view
        self.setup_observers()
        self._parentwindow = self.view.get_parent_window()
        self.connect_signals()
        self.refresh_view()

    def refresh_view(self):
        self._show_queue()

    def setup_observers(self):
        self.model.add_observer(
            self.view.Update_TableView, table='queue')
        return

    def connect_signals(self):
        # Connect buttons
        self.view.connect_item('about_job', self._about_job_event)
        self.view.connect_item('add_job', self._add_job_event)
        self.view.connect_item('remove_job', self._delete_job_event)
        # connect right-click menu items
        self.view.rc_menu.connect_item('job_details', self._about_job_event)
        self.view.rc_menu.connect_item('delete_job', self._delete_job_event)

    def _show_queue(self, widget=None):
        """ Force the queue to be displayed"""
        return self.model.RefreshQueue()

    def _about_job_event(self, widget=None):
        """ Display a dialog showing detailed information about a queued job"""
        dia = guitools.AboutJob(parent = self._parentwindow,
                                jobid=self.view._selectedjob)
        if dia.run():
            dia.destroy()

    def _delete_job_event(self, widget=None):
        return self.model.DeleteJob(self.view._selectedjob)

    def _add_job_event(self, widget=None):
        """ Display a dialog to add a new job to the queue"""
        dia = guitools.JobAddDialog(parent=self._parentwindow)
        res = dia.run()
        dia.hide()

        if res == gtk.RESPONSE_OK:
            return self.model.NewJob(
                app = dia.app,
                ver = dia.ver,
                srcURI = dia.SrcURI,
                descURI = dia.DescURI,
                release = dia.release,
                _type = dia.srctype,
                install = dia.install,
                patches = ','.join(dia.patches))
        else:
            dia.destroy()
            return None


class HistoryController(QueueController):
    """ Controller for the history view """
    def __init__(self, model, view):
        self.model = model
        self.view = view
        QueueController.__init__(self, self.model, self.view)

    def setup_observers(self):
        """ Connect observers to the signalers"""
        self.model.add_observer(self.view.Update_TableView, table='history')


    def refresh_view(self):
        return self.model.RefreshHistory()

    def connect_signals(self):
        # Connect buttons
        self.view.connect_item('about_task', self._about_task_event)
        self.view.connect_item('wipe_history', self._wipe_history_event)
        # Connect menu items.
        self.view.rc_menu.connect_item('about_job', self._about_task_event)

    def _about_task_event(self, widget=None):
        pass

    def _wipe_history_event(self, widget=None):
        pass




if __name__ == "__main__":
    model = dbutils.dbase()
    view = dbviews.HistoryView()
    control = HistoryController(model = model,
                              view = view)
    control.Run()