use GajimPluginConfig for file sharing plugin

This commit is contained in:
Yann Leboulanger
2012-10-28 19:47:32 +01:00
parent f9271e9809
commit 91b7beea71
3 changed files with 8 additions and 33 deletions

View File

@@ -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')

View File

@@ -7,11 +7,11 @@ from common.file_props import FilesProp
import fshare import fshare
import os import os
import fshare_protocol import fshare_protocol
import config
class FileShareWindow(gtk.Window): class FileShareWindow(gtk.Window):
def __init__(self): def __init__(self, plugin):
self.plugin = plugin
gtk.Window.__init__(self) gtk.Window.__init__(self)
self.set_title('File Share') self.set_title('File Share')
self.connect('delete_event', self.delete_event) self.connect('delete_event', self.delete_event)
@@ -115,7 +115,7 @@ class FileShareWindow(gtk.Window):
# Preferences page # Preferences page
self.lbl_pref = gtk.Label('Preferences') self.lbl_pref = gtk.Label('Preferences')
self.entry_dir_pref = gtk.Entry(max=0) 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 = gtk.Button('Select dir', gtk.STOCK_OPEN)
self.bt_sel_dir_pref.connect('clicked', self.on_bt_sel_dir_pref_clicked) self.bt_sel_dir_pref.connect('clicked', self.on_bt_sel_dir_pref_clicked)
self.frm_dir_pref = gtk.Frame('Incoming files directory') self.frm_dir_pref = gtk.Frame('Incoming files directory')
@@ -372,7 +372,7 @@ class FileShareWindow(gtk.Window):
file_info = self.brw_file_info[path] file_info = self.brw_file_info[path]
fjid = self.get_contact_from_iter(tree, row) fjid = self.get_contact_from_iter(tree, row)
# Request the file # 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() sid = helpers.get_random_string_16()
new_file_props = FilesProp.getNewFileProp(self.account, sid) new_file_props = FilesProp.getNewFileProp(self.account, sid)
new_file_props.file_name = file_path new_file_props.file_name = file_path
@@ -400,12 +400,12 @@ class FileShareWindow(gtk.Window):
if response == gtk.RESPONSE_OK: if response == gtk.RESPONSE_OK:
file_name = chooser.get_filename() file_name = chooser.get_filename()
self.entry_dir_pref.set_text(file_name) self.entry_dir_pref.set_text(file_name)
config.set('incoming_dir', file_name) self.plugin.config['incoming_dir'] = file_name
chooser.destroy() chooser.destroy()
if __name__ == "__main__": if __name__ == "__main__":
f = FileShareWindow() f = FileShareWindow(None)
f.show() f.show()
gtk.main() gtk.main()

View File

@@ -27,6 +27,7 @@ class FileSharePlugin(GajimPlugin):
self.description = _('This plugin allows you to share folders'+ self.description = _('This plugin allows you to share folders'+
' with a peer using jingle file transfer.') ' with a peer using jingle file transfer.')
self.config_dialog = None self.config_dialog = None
self.config_default_values = {'incoming_dir': ('/home/', '')}
# Create one protocol handler per account # Create one protocol handler per account
accounts = gajim.contacts.get_accounts() accounts = gajim.contacts.get_accounts()
for account in gajim.contacts.get_accounts(): for account in gajim.contacts.get_accounts():
@@ -133,7 +134,7 @@ class FileSharePlugin(GajimPlugin):
def __get_fsw_instance(self, account): def __get_fsw_instance(self, account):
# Makes sure we only have one instance of the window per account # Makes sure we only have one instance of the window per account
if account not in FileSharePlugin.filesharewindow: if account not in FileSharePlugin.filesharewindow:
FileSharePlugin.filesharewindow[account] = fsw = FileShareWindow() FileSharePlugin.filesharewindow[account] = fsw = FileShareWindow(self)
FileSharePlugin.prohandler[account].set_window(fsw) FileSharePlugin.prohandler[account].set_window(fsw)
return FileSharePlugin.filesharewindow[account] return FileSharePlugin.filesharewindow[account]