diff options
author | Justin Lewis <jtl1728@rit.edu> | 2010-01-19 18:02:39 (GMT) |
---|---|---|
committer | Justin Lewis <jtl1728@rit.edu> | 2010-01-19 18:02:39 (GMT) |
commit | 8ec9754f330ea91b0d43e6f81873ead612bdb71e (patch) | |
tree | 55f877989f4b77c4edda5a95cf670c65b4afa870 | |
parent | 62aa66103fbf207e14861fec99273b91ccf53bdd (diff) |
Now checks if server available during boot in new thread
If server is found, it activates the icon to allow switching to the
server.
-rw-r--r-- | FileShare.activity/FileShareActivity.py | 147 | ||||
-rw-r--r-- | FileShare.activity/GuiView.py | 22 |
2 files changed, 82 insertions, 87 deletions
diff --git a/FileShare.activity/FileShareActivity.py b/FileShare.activity/FileShareActivity.py index b19381c..551c92b 100644 --- a/FileShare.activity/FileShareActivity.py +++ b/FileShare.activity/FileShareActivity.py @@ -41,7 +41,7 @@ import FileInfo from hashlib import sha1 import urllib, urllib2, MultipartPostHandler, httplib -import threading, signal +import threading import logging _logger = logging.getLogger('fileshare-activity') @@ -96,37 +96,14 @@ class FileShareActivity(Activity): # Set to true when closing for keep cleanup self._close_requested = False - # If they are the server, ask them if they want to be the server and use - # P2P share system or if they want to do a client/server with an - # external server - + # Set up internals for server mode if later requested self._mode = "P2P" prof = profile.get_profile() self._user_key_hash = sha1(prof.pubkey).hexdigest() self._user_nick = profile.get_nick_name() self._user_permissions = 0 + self.server_ip = None - # INITIALIZE GUI - ################ - self.set_title('File Share') - - # Set gui display object - self.disp = GuiView(self) - - # Set Toolbars - self.disp.build_toolbars() - - # Build table and display the gui - self.disp.build_table() - - # Connect to shared and join calls - self._sh_hnd = self.connect('shared', self._shared_cb) - self._jo_hnd = self.connect('joined', self._joined_cb) - - self.set_canvas(self.disp) - self.show_all() - - def switch_to_server(self): jabber_serv = None prof = profile.get_profile() #Need to check if on 82 or higher @@ -143,71 +120,84 @@ class FileShareActivity(Activity): self.server_port= 14623 self.s_version = 0 - self.disp.guiHandler.show_throbber(True, _("Please Wait... Searching for Server")) - if self.isServer and self.check_for_server(): - self._mode = "SERVER" - self.isServer = False - # Remove shared mode - # Disable handlers incase not shared yet - self.disconnect( self._sh_hnd ) - self.disconnect( self._jo_hnd ) - - # Disable notify the tube of changes - self.initiating = False - - # Disable greeting people joining tube - if self.controlTube: - self.controlTube.switch_to_server_mode() + # INITIALIZE GUI + ################ + self.set_title('File Share') - # Set activity to private mode if shared - if self._shared_activity: - ##TODO: - pass + # Set gui display object + self.disp = GuiView(self) - # Clear file List (can't go to server mode after sharing, clear list) - # Will not delete files so connected people can still download files. - self.disp.clear_files(False) + # Set Toolbars + self.disp.build_toolbars() - # Rebuild gui, now we are in server mode - self.disp.build_toolbars() + # Build table and display the gui + self.disp.build_table() - #self.set_canvas(self.disp) - #self.show_all() + # Connect to shared and join calls + self._sh_hnd = self.connect('shared', self._shared_cb) + self._jo_hnd = self.connect('joined', self._joined_cb) - #IN SERVER MODE, GET SERVER FILE LIST - def call(): - try: - conn = httplib.HTTPConnection( self.server_ip, self.server_port) - conn.request("GET", "/filelist") - r1 = conn.getresponse() - if r1.status == 200: - data = r1.read() - conn.close() - self.incomingRequest('filelist',data) - else: - self.disp.guiHandler._alert(str(r1.status), _("Error getting file list") ) - except: - self.disp.guiHandler._alert(_("Error getting file list")) - self.disp.guiHandler.show_throbber(False) + self.set_canvas(self.disp) + self.show_all() - self.disp.guiHandler.show_throbber(True, _("Requesting file list from server")) - threading.Thread(target=call).start() + def switch_to_server(self): + if self.server_ip and self.isServer: + self._mode = "SERVER" + self.isServer = False + + # Remove shared mode + # Disable handlers incase not shared yet + self.disconnect( self._sh_hnd ) + self.disconnect( self._jo_hnd ) + + # Disable notify the tube of changes + self.initiating = False + + # Disable greeting people joining tube + if self.controlTube: + self.controlTube.switch_to_server_mode() + + # Set activity to private mode if shared + if self._shared_activity: + ##TODO: + pass + + # Clear file List (can't go to server mode after sharing, clear list) + # Will not delete files so connected people can still download files. + self.disp.clear_files(False) + + # Rebuild gui, now we are in server mode + self.disp.build_toolbars() + + #self.set_canvas(self.disp) + #self.show_all() + + #IN SERVER MODE, GET SERVER FILE LIST + def call(): + try: + conn = httplib.HTTPConnection( self.server_ip, self.server_port) + conn.request("GET", "/filelist") + r1 = conn.getresponse() + if r1.status == 200: + data = r1.read() + conn.close() + self.incomingRequest('filelist',data) + else: + self.disp.guiHandler._alert(str(r1.status), _("Error getting file list") ) + except: + self.disp.guiHandler._alert(_("Error getting file list")) + self.disp.guiHandler.show_throbber(False) + + self.disp.guiHandler.show_throbber(True, _("Requesting file list from server")) + threading.Thread(target=call).start() def check_for_server(self): - - def raise_timeout(signum, frame): - raise TimeOut("Timeout!") - - signal.signal(signal.SIGALRM, raise_timeout) - s_version = None try: - signal.alarm(10) # raise alarm in 10 seconds conn = httplib.HTTPConnection( self.server_ip, self.server_port) conn.request("GET", "/version") r1 = conn.getresponse() - signal.alarm(0) if r1.status == 200: s_version= r1.read() conn.close() @@ -230,13 +220,10 @@ class FileShareActivity(Activity): # Older version didn't have permissions, set 1 as default (upload/remove) self._user_permissions = 1 self.s_version = s_version - signal.alarm(0) # disable alarm return True else: - signal.alarm(0) # disable alarm return False except: - signal.alarm(0) # disable alarm return False def get_server_user_list(self): diff --git a/FileShare.activity/GuiView.py b/FileShare.activity/GuiView.py index d0c0431..d900632 100644 --- a/FileShare.activity/GuiView.py +++ b/FileShare.activity/GuiView.py @@ -293,7 +293,7 @@ class GuiView(gtk.ScrolledWindow): self.guiHandler = GuiHandler( activity, self.treeview, self ) #self.build_table(activity) - def build_toolbars(self, custom = True): + def build_toolbars(self): self.action_buttons = {} # BUILD CUSTOM TOOLBAR @@ -316,7 +316,7 @@ class GuiView(gtk.ScrolledWindow): self.action_buttons['server'] = ToolButton('gaim-link') self.action_buttons['server'].set_tooltip( _('Connect to Server') ) - + self.action_buttons['server'].set_sensitive( False ) if self.activity.isServer: self.action_buttons['add'].connect("clicked", self.guiHandler.requestAddFile, None) @@ -329,6 +329,15 @@ class GuiView(gtk.ScrolledWindow): self.action_bar.insert(self.action_buttons['rem'], -1) self.action_bar.insert(self.action_buttons['server'], -1) + # Check for server, if found activate connect link + def check_server_status(): + try: + if self.activity.check_for_server(): + self.action_buttons['server'].set_sensitive( True ) + except ServerRequestFailure: + pass + threading.Thread(target=check_server_status).start() + else: self.action_buttons['down'].connect("clicked", self.guiHandler.requestDownloadFile, None) self.action_bar.insert(self.action_buttons['down'], -1) @@ -349,13 +358,12 @@ class GuiView(gtk.ScrolledWindow): self.toolbar_set_selection( False ) # Create Toolbox - toolbox = ActivityToolbox(self.activity) + self.toolbox = ActivityToolbox(self.activity) - if custom: - toolbox.add_toolbar(_("Actions"), self.action_bar) + self.toolbox.add_toolbar(_("Actions"), self.action_bar) - self.activity.set_toolbox(toolbox) - toolbox.show() + self.activity.set_toolbox(self.toolbox) + self.toolbox.show() def on_selection_changed(self, selection): if selection.count_selected_rows() == 0: |