create: Don't skip distro detection if URL is pasted

Track whether we have already detected the current URL, and if not, force
a detection when the user press 'forward'
This commit is contained in:
Cole Robinson 2010-12-03 12:55:56 -05:00
parent 28fc9a3d5c
commit c871cc1d45

View File

@ -86,9 +86,10 @@ class vmmCreate(gobject.GObject):
self.conn_signals = [] self.conn_signals = []
# Distro detection state variables # Distro detection state variables
self.detectThread = None
self.detectedDistro = None self.detectedDistro = None
self.detectThreadLock = threading.Lock() self.detectThreadEvent = threading.Event()
self.detectThreadEvent.set()
self.mediaDetected = False
# 'Guest' class from the previous failed install # 'Guest' class from the previous failed install
self.failed_guest = None self.failed_guest = None
@ -230,14 +231,16 @@ class vmmCreate(gobject.GObject):
iso_model = gtk.ListStore(str) iso_model = gtk.ListStore(str)
iso_list.set_model(iso_model) iso_list.set_model(iso_model)
iso_list.set_text_column(0) iso_list.set_text_column(0)
self.window.get_widget("install-local-box").child.connect("activate", self.detect_media_os) self.window.get_widget("install-local-box").child.connect("activate",
self.detect_media_os)
# Lists for the install urls # Lists for the install urls
media_url_list = self.window.get_widget("install-url-box") media_url_list = self.window.get_widget("install-url-box")
media_url_model = gtk.ListStore(str) media_url_model = gtk.ListStore(str)
media_url_list.set_model(media_url_model) media_url_list.set_model(media_url_model)
media_url_list.set_text_column(0) media_url_list.set_text_column(0)
self.window.get_widget("install-url-box").child.connect("activate", self.detect_media_os) self.window.get_widget("install-url-box").child.connect("activate",
self.detect_media_os)
ks_url_list = self.window.get_widget("install-ks-box") ks_url_list = self.window.get_widget("install-ks-box")
ks_url_model = gtk.ListStore(str) ks_url_model = gtk.ListStore(str)
@ -914,14 +917,19 @@ class vmmCreate(gobject.GObject):
def url_box_changed(self, ignore): def url_box_changed(self, ignore):
# If the url_entry has focus, don't fire detect_media_os, it means # If the url_entry has focus, don't fire detect_media_os, it means
# the user is probably typing # the user is probably typing
if self.window.get_widget("install-url-box").child.flags() & gtk.HAS_FOCUS: self.mediaDetected = False
if (self.window.get_widget("install-url-box").child.flags() &
gtk.HAS_FOCUS):
return return
self.detect_media_os() self.detect_media_os()
def detect_media_os(self, ignore1=None): def should_detect_media(self):
curpage = self.window.get_widget("create-pages").get_current_page() return (self.is_detect_active() and not self.mediaDetected)
if self.is_detect_active() and curpage == PAGE_INSTALL:
self.detect_os_distro() def detect_media_os(self, ignore1=None, forward=False):
if not self.should_detect_media():
return
self.start_detect_thread(forward=forward)
def toggle_detect_os(self, src): def toggle_detect_os(self, src):
dodetect = src.get_active() dodetect = src.get_active()
@ -1043,11 +1051,16 @@ class vmmCreate(gobject.GObject):
notebook.set_current_page(next_page) notebook.set_current_page(next_page)
def forward(self, ignore): def forward(self, ignore=None):
notebook = self.window.get_widget("create-pages") notebook = self.window.get_widget("create-pages")
curpage = notebook.get_current_page() curpage = notebook.get_current_page()
is_import = (self.get_config_install_page() == INSTALL_PAGE_IMPORT) is_import = (self.get_config_install_page() == INSTALL_PAGE_IMPORT)
if curpage == PAGE_INSTALL and self.should_detect_media():
# Make sure we have detected the OS before validating the page
self.detect_media_os(forward=True)
return
if self.validate(notebook.get_current_page()) != True: if self.validate(notebook.get_current_page()) != True:
return return
@ -1639,26 +1652,18 @@ class vmmCreate(gobject.GObject):
# Distro detection methods # Distro detection methods
# Clear global detection thread state
def _clear_detect_thread(self):
self.detectThreadLock.acquire()
self.detectThread = None
self.detectThreadLock.release()
# Create and launch a detection thread (if no detection already running) # Create and launch a detection thread (if no detection already running)
def detect_os_distro(self): def start_detect_thread(self, forward):
self.detectThreadLock.acquire() if not self.detectThreadEvent.isSet():
if self.detectThread is not None:
# We are already checking (some) media, so let that continue # We are already checking (some) media, so let that continue
self.detectThreadLock.release()
return return
self.detectThread = threading.Thread(target=self.do_detect, self.detectThreadEvent.clear()
name="Detect OS") detectThread = threading.Thread(target=self.do_detect,
self.detectThread.setDaemon(True) args=(forward,),
self.detectThreadLock.release() name="Detect OS")
detectThread.setDaemon(True)
self.detectThread.start() detectThread.start()
def set_distro_labels(self, distro, ver): def set_distro_labels(self, distro, ver):
# Helper to set auto detect result labels # Helper to set auto detect result labels
@ -1718,7 +1723,7 @@ class vmmCreate(gobject.GObject):
self.window.get_widget("create-forward").set_sensitive(val) self.window.get_widget("create-forward").set_sensitive(val)
# The actual detection routine # The actual detection routine
def do_detect(self): def do_detect(self, forward):
try: try:
media = self._safe_wrapper(self.get_config_detectable_media, ()) media = self._safe_wrapper(self.get_config_detectable_media, ())
if not media: if not media:
@ -1750,9 +1755,12 @@ class vmmCreate(gobject.GObject):
self._safe_wrapper(self.set_distro_selection, results) self._safe_wrapper(self.set_distro_selection, results)
finally: finally:
self._clear_detect_thread()
self._safe_wrapper(self._set_forward_sensitive, (True,)) self._safe_wrapper(self._set_forward_sensitive, (True,))
self.detectThreadEvent.set()
self.mediaDetected = True
logging.debug("Leaving OS detection thread.") logging.debug("Leaving OS detection thread.")
if forward:
util.safe_idle_add(self.forward, ())
return return