[Syncropated-commits] r170 - trunk/src

zimmerle at garage.maemo.org zimmerle at garage.maemo.org
Tue Jan 30 02:37:58 EET 2007


Author: zimmerle
Date: 2007-01-30 02:37:58 +0200 (Tue, 30 Jan 2007)
New Revision: 170

Added:
   trunk/src/DevicesManager.py
Log:
DevicesManager.py first commit

Added: trunk/src/DevicesManager.py
===================================================================
--- trunk/src/DevicesManager.py	2007-01-30 00:35:22 UTC (rev 169)
+++ trunk/src/DevicesManager.py	2007-01-30 00:37:58 UTC (rev 170)
@@ -0,0 +1,133 @@
+#!/usr/bin/python
+
+# DevicesManager.py
+#
+#  Copyright (c) 2006 INdT (Instituto Nokia de Technologia)
+#
+#  Author: Felipe Zimmerle <felipe at zimmerle.org>
+#          Kenneth Rohde Christiansen <kenneth.christiansen at gmail.com>
+#
+#  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, write to the Free Software
+#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
+#  USA
+
+import gobject
+import gtk
+
+from Logger import Logger
+from Utils import Utils
+from Icons import Icons
+from Configuration import Configuration
+from DeviceDetection import DeviceDetection
+
+log = Logger()
+utils = Utils()
+icons = Icons()
+
+
+class DevicesManager(gobject.GObject):
+	"""
+	Manage the pluged-in devices
+
+	If its in dryrun mode, starts a fake device
+
+	"""
+
+	DEVICE_TYPE = { '770':  ('Nokia 770', 'device-nokia-770'),
+			'fake': ('Fake Device', 'gtk-connect') }
+
+	__notebook = None
+	__deviceDetection = None
+
+	def __init__(self, notebook, dryrun=False):
+		log.debug('DevicesManager :: Starting devices manager....')
+		log.debug('DevicesManager :: Dryrun mode? ' + str(dryrun))
+		self.__notebook = notebook
+		if self.__notebook == None:
+			log.debug('DevicesManager :: Sorry unknown notebook :(')
+		notebook.remove_page(0)
+
+		self.__deviceDetection = DeviceDetection(dryrun)
+		self.__deviceDetection.connect('device_detection', 
+			self.cb_device_detection)
+		self.__deviceDetection.start()
+
+
+
+	def cb_device_detection(self, deviceDetection, action, device_type, mount_point):
+		"""
+		Called when the device_detection signal is emited, its
+		add or remove the new device to the UI.
+
+		"""
+		log.debug('DevicesMenager :: Device list needs to be changed: ')
+		log.debug('DevicesManager :: action      : ' + str(action))
+		log.debug('DevicesManager :: device_type : ' + str(device_type))
+		log.debug('DevicesManager :: mount_point : ' + str(mount_point))
+
+		if action == 'del':
+			item = DevicesManager.DEVICE_TYPE[device_type][0]
+
+			log.debug('DevicesManager :: Prepare to delete item: ' + str(device_type))
+			pages = self.__notebook.get_n_pages()
+			for i in range(pages):
+				page = self.__notebook.get_nth_page(i)
+				page_label = self.__notebook.get_tab_label(page)
+				(img, label, path) = page_label.get_children()
+				log.debug('DevicesManager :: Verifying to remove : ' +
+					str(label.get_text()) + ' item: ' + str(item))
+				if label.get_text() == item and path.get_text() == '(' + mount_point + ')':
+					log.debug('DevicesManager :: founded!')
+					self.__notebook.remove_page(i)
+					return True
+
+		if action == 'add':
+			## Creating tab widget...
+			img = icons.load_icon_as_image(DevicesManager.DEVICE_TYPE[device_type][1], 18)
+			img.set_padding(3, 0)
+			label = gtk.Label(DevicesManager.DEVICE_TYPE[device_type][0])
+			mount_point_label = gtk.Label('(' + mount_point + ')')
+			label.set_padding(3, 0)
+
+			tab_button = gtk.HBox()
+			tab_button.add(img)
+			tab_button.add(label)
+			tab_button.add(mount_point_label)
+			tab_button.show_all()
+
+			## Creating page widget...
+			scrolled_window = gtk.ScrolledWindow()
+			scrolled_window.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
+			tree_view = gtk.TreeView()
+			scrolled_window.add(tree_view)
+
+			progress_bar = gtk.ProgressBar()
+
+			
+
+			page = gtk.VBox()
+			page.add(scrolled_window)
+			page.pack_start(progress_bar, fill=False, expand=False)
+			page.show_all()
+
+			#self.__free_space_watch_dog
+
+
+			## Insert both at main window.
+			self.__notebook.insert_page(page, tab_button, -1)
+
+
+
+
+



More information about the Syncropated-commits mailing list