# dependdialog.py
#
# Copyright (C) 2011 - Yasumichi Akahoshi
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 this program. If not, see <http://www.gnu.org/licenses/>.

from gi.repository import Gtk, GdkPixbuf, Gdk
import os, sys, rpm

UI_FILE = "ui/dependdialog.ui"

class DependDialog:
	def __init__(self, unresolved_dependencies):
		self.builder = Gtk.Builder()
		self.builder.set_translation_domain('rpminstall')
		self.builder.add_from_file(os.path.join (os.path.dirname(__file__), UI_FILE))
		self.builder.connect_signals(self)
		self.build_depend_listview()
		depend_liststore = self.builder.get_object('depend_liststore')
		for tup in unresolved_dependencies:
			object_package = '-'.join(tup[0])
			depend_package = '-'.join(tup[1])
			if tup[3] == rpm.RPMDEP_SENSE_CONFLICTS:
				reason = _("Conflict")
			elif tup[3] == rpm.RPMDEP_SENSE_REQUIRES:
				reason = _("Requires")
			else:
				reason = _("Unknown")
			depend_liststore.append([object_package, depend_package, reason])

	def build_depend_listview(self):
		depend_listview = self.builder.get_object('depend_listview')
		index = 0
		for column_title in [_("Object Package"), _("Depend Package"), _("Reason")]:
			column_text = Gtk.TreeViewColumn(column_title)
			renderer_text = Gtk.CellRendererText()
			column_text.pack_start(renderer_text, True)
			column_text.add_attribute(renderer_text, "text", index)
			index += 1
			depend_listview.append_column(column_text)

	def run(self):
		self.dialog = self.builder.get_object('dialog1')
		self.dialog.run()

	def ok(self, widget):
		self.dialog.destroy()
