Index: src/core.py =================================================================== --- src/core.py (revision 909) +++ src/core.py (working copy) @@ -223,16 +223,19 @@ class Manager: # Load the preferences self.config = pref.Preferences(os.path.join(self.base_dir, PREFS_FILENAME)) # Apply preferences. Note that this is before any torrents are added self.apply_prefs() PREF_FUNCTIONS["enable_dht"] = self.set_DHT + # event callbacks for use with plugins + self.event_callback = {} + # Unpickle the state, or create a new one if not blank_slate: try: pkl_file = open(os.path.join(self.base_dir, STATE_FILENAME), 'rb') self.state = pickle.load(pkl_file) pkl_file.close() # Sync with the core: tell core about torrents, and get unique_IDs @@ -243,17 +246,20 @@ class Manager: # Apply the queue at this time, after all is loaded and ready self.apply_queue() except IOError: self.state = persistent_state() else: self.state = persistent_state() - + def connect_event(self, event_type, callback): + if event_type not in self.event_callback: + self.event_callback[event_type] = [] + self.event_callback[event_type].append(callback) def quit(self): # Analyze data needed for pickling, etc. self.pre_quitting() # Pickle the prefs print "Saving prefs..." self.config.save() @@ -523,17 +529,20 @@ class Manager: ret.append(event) try: if event['unique_ID'] not in self.unique_IDs: event = pop_event() continue except KeyError: event = pop_event() continue - + # Call any event callbacks + for event in self.event_callback[event['event_type']]: + event() + if event['event_type'] is self.constants['EVENT_FINISHED']: # Queue seeding torrent to bottom if needed if(self.get_pref('enable_move_completed')): try: deluge_core.move_storage(event['unique_ID'], self.get_pref('default_finished_path')) except SystemError: raise SystemError("You cannot move torrent to a different partition. Please fix your preferences") continue