From 91b7beea71cb3f83eab969b91fa38a1ef16b3250 Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Sun, 28 Oct 2012 19:47:32 +0100 Subject: [PATCH] use GajimPluginConfig for file sharing plugin --- file_sharing/config.py | 26 -------------------------- file_sharing/fileshare_window.py | 12 ++++++------ file_sharing/fshare.py | 3 ++- 3 files changed, 8 insertions(+), 33 deletions(-) delete mode 100644 file_sharing/config.py diff --git a/file_sharing/config.py b/file_sharing/config.py deleted file mode 100644 index 6b454ee..0000000 --- a/file_sharing/config.py +++ /dev/null @@ -1,26 +0,0 @@ -import ConfigParser -import sys -import os - -def set(option, value): - _file = open(path, 'w') - cp.set('General', option, value) - cp.write(_file) - _file.close() - -def set_defaults(): - cp.add_section('General') - set('incoming_dir', '/home') - -path = sys.path[1] -path = path + '/file_sharing/' + 'conf.cfg' -cp = ConfigParser.ConfigParser() -if os.path.exists(path): - _file = open(path) - cp.readfp(_file) - _file.close() -else: - set_defaults() -INCOMING_DIR = cp.get('General', 'incoming_dir') - - diff --git a/file_sharing/fileshare_window.py b/file_sharing/fileshare_window.py index a53491f..3699ade 100644 --- a/file_sharing/fileshare_window.py +++ b/file_sharing/fileshare_window.py @@ -7,11 +7,11 @@ from common.file_props import FilesProp import fshare import os import fshare_protocol -import config class FileShareWindow(gtk.Window): - def __init__(self): + def __init__(self, plugin): + self.plugin = plugin gtk.Window.__init__(self) self.set_title('File Share') self.connect('delete_event', self.delete_event) @@ -115,7 +115,7 @@ class FileShareWindow(gtk.Window): # Preferences page self.lbl_pref = gtk.Label('Preferences') self.entry_dir_pref = gtk.Entry(max=0) - self.entry_dir_pref.set_text(config.INCOMING_DIR) + self.entry_dir_pref.set_text(self.plugin.config['incoming_dir']) self.bt_sel_dir_pref = gtk.Button('Select dir', gtk.STOCK_OPEN) self.bt_sel_dir_pref.connect('clicked', self.on_bt_sel_dir_pref_clicked) self.frm_dir_pref = gtk.Frame('Incoming files directory') @@ -372,7 +372,7 @@ class FileShareWindow(gtk.Window): file_info = self.brw_file_info[path] fjid = self.get_contact_from_iter(tree, row) # Request the file - file_path = config.INCOMING_DIR + '/%s' % file_info[0] + file_path = os.path.join(self.plugin.config['incoming_dir'], file_info[0]) sid = helpers.get_random_string_16() new_file_props = FilesProp.getNewFileProp(self.account, sid) new_file_props.file_name = file_path @@ -400,12 +400,12 @@ class FileShareWindow(gtk.Window): if response == gtk.RESPONSE_OK: file_name = chooser.get_filename() self.entry_dir_pref.set_text(file_name) - config.set('incoming_dir', file_name) + self.plugin.config['incoming_dir'] = file_name chooser.destroy() if __name__ == "__main__": - f = FileShareWindow() + f = FileShareWindow(None) f.show() gtk.main() diff --git a/file_sharing/fshare.py b/file_sharing/fshare.py index fd7d748..c865c15 100644 --- a/file_sharing/fshare.py +++ b/file_sharing/fshare.py @@ -27,6 +27,7 @@ class FileSharePlugin(GajimPlugin): self.description = _('This plugin allows you to share folders'+ ' with a peer using jingle file transfer.') self.config_dialog = None + self.config_default_values = {'incoming_dir': ('/home/', '')} # Create one protocol handler per account accounts = gajim.contacts.get_accounts() for account in gajim.contacts.get_accounts(): @@ -133,7 +134,7 @@ class FileSharePlugin(GajimPlugin): def __get_fsw_instance(self, account): # Makes sure we only have one instance of the window per account if account not in FileSharePlugin.filesharewindow: - FileSharePlugin.filesharewindow[account] = fsw = FileShareWindow() + FileSharePlugin.filesharewindow[account] = fsw = FileShareWindow(self) FileSharePlugin.prohandler[account].set_window(fsw) return FileSharePlugin.filesharewindow[account]