Commits

Erik Grinaker committed 7183141

added preference for autosaving data on change

  • Participants
  • Parent commits cbb553f

Comments (0)

Files changed (5)

 
 	* when adding an entry the default type is Generic (not Folder)
 
+	* added a preference for automatically saving data when changed
+
 2004-07-14  Erik Grinaker <erikg@codepoet.no>
 
 	* rewrote the application use of data files and replaced the
 - string cleanups
 - program-launchers for misc account types (announce on rvl-list
   when done in svn)
-- add autosaving of files (needs a preference)
 - add docstrings to all objects, methods and functions
 - export to XHTML/CSS files
 

gnome/revelation.schemas

 		</schema>
 
 		<schema>
+			<key>/schemas/apps/revelation/file/autosave</key>
+			<applyto>/apps/revelation/file/autosave</applyto>
+			<owner>revelation</owner>
+			<type>bool</type>
+			<default>false</default>
+
+			<locale name="C">
+				<short>Autosave data when changed</short>
+				<long>
+					If true, Revelation will automatically
+					save the data file when an entry is added,
+					updated or removed.
+				</long>
+			</locale>
+		</schema>
+
+		<schema>
 			<key>/schemas/apps/revelation/passwordgen/avoid_ambiguous</key>
 			<applyto>/apps/revelation/passwordgen/avoid_ambiguous</applyto>
 			<owner>revelation</owner>

src/lib/dialog.py

 		self.tooltips.set_tip(self.entry_autoload_file, "A file to be opened when the program is started")
 		self.section_file.add_inputrow("File to open", self.entry_autoload_file)
 
+		self.check_autosave = revelation.widget.CheckButton("Autosave data when changed")
+		self.check_autosave.gconf_bind("/apps/revelation/file/autosave")
+		self.tooltips.set_tip(self.check_autosave, "Automatically saves the data file when an entry is added, modified or removed")
+		self.section_file.add_inputrow(None, self.check_autosave)
+
 
 	def __init_section_pwgen(self):
 		self.section_pwgen = self.add_section("Password Generator")
 			self.tree.select(match)
 
 
+	def __file_autosave(self):
+		"Autosaves the current file, due to data modification"
+
+		if self.file is None or self.password is None:
+			return
+
+		if not self.gconf.get_bool("/apps/revelation/file/autosave"):
+			return
+
+		self.file_save(self.file, self.password)
+
+
 	def __file_load(self, datafile):
 		"Loads data from a file into an entrystore"
 
 		try:
 			entry = revelation.dialog.EditEntry(self, "Add entry").run()
 			iter = self.data.add_entry(self.tree.get_active(), entry)
+
 			self.undoqueue.add_action(revelation.data.UNDO_ACTION_ADD, iter)
+			self.__file_autosave()
 			self.tree.select(iter)
 			self.statusbar.set_status("Added entry '" + entry.name + "'")
 
 			newentry = dialog.run()
 			self.data.update_entry(iter, newentry)
 			self.undoqueue.add_action(revelation.data.UNDO_ACTION_EDIT, iter, entry)
+			self.__file_autosave()
 			self.tree.select(iter)
 			self.statusbar.set_status("Updated entry '" + newentry.name + "'")
 
 			for iter in iters:
 				self.data.remove_entry(iter)
 
+			self.__file_autosave()
 			self.tree.unselect_all()
 			self.statusbar.set_status(statustext)
 
 		else:
 			iters = self.data.import_entrystore(entrystore)
 			self.undoqueue.add_action(revelation.data.UNDO_ACTION_IMPORT, iters)
+			self.__file_autosave()
 			self.statusbar.set_status("Data imported from " + datafile.file)