예제 #1
0
	def __init__(self, folder):
		'''
		Constructor. GUI
		'''
		self.folder = folder
		
		gtk.Window.__init__(self)
		self.set_modal(True)
		self.set_default_size(500,200)
		self.set_title('Share folder through NFS')
		mainVBox = gtk.VBox(False, 10)
		mainHBox = gtk.HBox(False, 10)
		
		self.fileLabel = gtk.Label('file')
		infoVBox = gtk.VBox(False, 10)
		infoVBox.pack_start(gtk.Label('Share this folder through NFS'), False, False, 10)
		infoVBox.pack_start(self.fileLabel, True, True, 10)
		
		image = gtk.image_new_from_gicon(gio.ThemedIcon('folder-remote'),gtk.ICON_SIZE_DIALOG)
		mainHBox.pack_start(image, False, False, 30)
		mainHBox.pack_start(infoVBox, True, True, 10)
		
		self.shareCheckBtn = gtk.CheckButton('Share this folder')
		self.writeCheckBtn = gtk.CheckButton('Allow other users to create, update and delete files')
		mainVBox.set_border_width(10)
		self.okBtn = gtk.Button('', gtk.STOCK_OK)
		self.cancelBtn = gtk.Button('', gtk.STOCK_CANCEL)
		btnBox = gtk.HButtonBox()
		btnBox.add(self.okBtn)
		btnBox.add(self.cancelBtn)
		btnBox.set_layout(gtk.BUTTONBOX_END)
		btnBox.set_spacing(10)
		
		mainVBox.pack_start(mainHBox, True, True)
		mainVBox.pack_start(self.shareCheckBtn, False, False)
		mainVBox.pack_start(self.writeCheckBtn, False, False)
		mainVBox.pack_start(gtk.HSeparator(), False, False)
		mainVBox.pack_start(btnBox, False, False)		
		
		self.shareCheckBtn.connect('toggled', self.on_shareCheckBtn_toggled)
		self.writeCheckBtn.connect('toggled', self.on_writeCheckBtn_toggled)
		self.okBtn.connect('clicked', self.on_okBtn_clicked)
		self.cancelBtn.connect('clicked', self.on_cancelBtn_clicked)		
		self.connect('destroy', self.on_cancelBtn_clicked)
		
		self.add(mainVBox)
		
		self.es = ExportsSharing(self.folder)
		self.shareCheckBtn.set_active(self.es.isShared())
		self.writeCheckBtn.set_active(self.es.isWritable())
		self.fileLabel.set_label(self.folder)
		self.on_cb_toggled()
예제 #2
0
class NfsShareWindow(gtk.Window):
	'''
	"Share" window 
	'''
	def __init__(self, folder):
		'''
		Constructor. GUI
		'''
		self.folder = folder
		
		gtk.Window.__init__(self)
		self.set_modal(True)
		self.set_default_size(500,200)
		self.set_title('Share folder through NFS')
		mainVBox = gtk.VBox(False, 10)
		mainHBox = gtk.HBox(False, 10)
		
		self.fileLabel = gtk.Label('file')
		infoVBox = gtk.VBox(False, 10)
		infoVBox.pack_start(gtk.Label('Share this folder through NFS'), False, False, 10)
		infoVBox.pack_start(self.fileLabel, True, True, 10)
		
		image = gtk.image_new_from_gicon(gio.ThemedIcon('folder-remote'),gtk.ICON_SIZE_DIALOG)
		mainHBox.pack_start(image, False, False, 30)
		mainHBox.pack_start(infoVBox, True, True, 10)
		
		self.shareCheckBtn = gtk.CheckButton('Share this folder')
		self.writeCheckBtn = gtk.CheckButton('Allow other users to create, update and delete files')
		mainVBox.set_border_width(10)
		self.okBtn = gtk.Button('', gtk.STOCK_OK)
		self.cancelBtn = gtk.Button('', gtk.STOCK_CANCEL)
		btnBox = gtk.HButtonBox()
		btnBox.add(self.okBtn)
		btnBox.add(self.cancelBtn)
		btnBox.set_layout(gtk.BUTTONBOX_END)
		btnBox.set_spacing(10)
		
		mainVBox.pack_start(mainHBox, True, True)
		mainVBox.pack_start(self.shareCheckBtn, False, False)
		mainVBox.pack_start(self.writeCheckBtn, False, False)
		mainVBox.pack_start(gtk.HSeparator(), False, False)
		mainVBox.pack_start(btnBox, False, False)		
		
		self.shareCheckBtn.connect('toggled', self.on_shareCheckBtn_toggled)
		self.writeCheckBtn.connect('toggled', self.on_writeCheckBtn_toggled)
		self.okBtn.connect('clicked', self.on_okBtn_clicked)
		self.cancelBtn.connect('clicked', self.on_cancelBtn_clicked)		
		self.connect('destroy', self.on_cancelBtn_clicked)
		
		self.add(mainVBox)
		
		self.es = ExportsSharing(self.folder)
		self.shareCheckBtn.set_active(self.es.isShared())
		self.writeCheckBtn.set_active(self.es.isWritable())
		self.fileLabel.set_label(self.folder)
		self.on_cb_toggled()

	def _errorMessage(self, message):
		'''
		Error message dialog
		'''
		self.dialogError = gtk.MessageDialog(self, gtk.DIALOG_MODAL |  gtk.DIALOG_DESTROY_WITH_PARENT, gtk.MESSAGE_ERROR, gtk.BUTTONS_OK, message)
		self.dialogError.set_default_response(gtk.RESPONSE_OK)
		self.dialogError.connect('response', self._dialogError_closed)
		self.dialogError.show_all()
		
	def _dialogError_closed(self, *args):
		'''
		Error dialog closing
		'''
		self.dialogError.destroy()
		gtk.main_quit()

	def on_okBtn_clicked(self, widget):
		'''
		Ok button callback
		'''
		if (self.shareCheckBtn.get_active()):
			if not self.es.share(self.writeCheckBtn.get_active()):
				self._errorMessage("Error occured while sharing")
			else:
				self.es.restartNFS()
				gtk.main_quit()
		else:
			if not self.es.unshare():
				self._errorMessage("Error occured while unsharing")
			else:
				self.es.restartNFS()
				gtk.main_quit()

	def on_cancelBtn_clicked(self, widget):
		'''
		Cancel button callback
		'''
		gtk.main_quit()

	def on_shareCheckBtn_toggled(self, widget):
		'''
		Share checkbox toggle
		'''
		if self.shareCheckBtn.get_active() == True:
			self.writeCheckBtn.set_sensitive(1)
		else:
			self.writeCheckBtn.set_sensitive(0)
		self.on_cb_toggled()

	def on_writeCheckBtn_toggled(self, widget):
		'''
		"Allow write" checkbox toggle
		'''
		self.on_cb_toggled()
	
	def on_cb_toggled(self):
		'''
		Enable/disable Ok button on toggle checkboxes
		'''
		if (self.shareCheckBtn.get_active() != self.es.isShared() or self.writeCheckBtn.get_active() != self.es.isWritable()):
			self.okBtn.set_sensitive(1)
		else:
			self.okBtn.set_sensitive(0)