def commit(self):
    person_name = gutils.on_combo_box_entry_changed(self.widgets['movie']['loan_to'])
    if not person_name:
        return False
    self.widgets['w_loan_to'].hide()

    person = self.db.session.query(db.Person.person_id).filter_by(name=person_name).first()
    if not person:
        log.info("loan_commit: person doesn't exist")
        return False
    if self._movie_id:
        movie = self.db.session.query(db.Movie.movie_id, db.Movie.collection_id).filter_by(movie_id=self._movie_id).first()
        if not movie:
            log.info("loan_commit: wrong movie_id")
            return False
    else:
        log.info("loan_commit: movie not selected")
        return False

    # ask if user wants to loan whole collection
    loan_whole_collection = False
    if movie.collection_id > 0:
        response = gutils.question(_("Do you want to loan whole collection?"), window=self.widgets['window'])
        if response == gtk.RESPONSE_YES:
            loan_whole_collection = True
        elif response == gtk.RESPONSE_CANCEL:
            return False
    
    resp = sql.loan_movie(self.db, movie.movie_id, person.person_id, loan_whole_collection)
    if resp == -1:
        gutils.warning(_("Collection contains loaned movie.\nLoan aborted!"))
        return False
    elif resp:
        self.update_statusbar(_("Movie loaned"))
        self.treeview_clicked()
def commit_loan(self):
	person = gutils.on_combo_box_entry_changed(self.loan_to)
	if person == '' or person == None:
		return
	self.w_loan_to.hide()

	# movie is now loaned. change db
	movie_id = self.e_number.get_text()
	self.db.cursor.execute("SELECT volume_id, collection_id FROM movies WHERE number='%s'"%movie_id)
	volume_id, collection_id = self.db.cursor.fetchall()[0]
	data_person = self.db.select_person_by_name(person)

	# ask if user wants to loan whole collection
	if collection_id>0:
		loan_whole_collection = False
		response = gutils.question(self, msg=_("Do you want to loan whole collection?"), parent=self.main_window)
		if response == gtk.RESPONSE_YES:
			loan_whole_collection = True
		elif response == gtk.RESPONSE_CANCEL:
			return False

	if volume_id>0 and collection_id>0:
		if loan_whole_collection:
			self.db.update_collection(id=collection_id, volume_id=volume_id, loaned=1)
		else:
			self.db.update_volume(id=volume_id, loaned=1)
	elif collection_id>0:
		if loan_whole_collection:
			self.db.update_collection(id=collection_id, loaned=1)
		else:
			self.db.cursor.execute("UPDATE movies SET loaned='1' WHERE number='%s';" % movie_id)
	elif volume_id>0:
		self.db.update_volume(id=volume_id, loaned=1)
	else:
		self.db.cursor.execute("UPDATE movies SET loaned='1' WHERE number='%s';" % movie_id)
	self.update_statusbar(_("Movie loaned"))

	# next, we insert a new row on the loans table
	data_movie=self.db.select_movie_by_num(movie_id)
	query = "INSERT INTO 'loans'('id', 'person_id','"
	if collection_id > 0 and loan_whole_collection:
		query +="collection_id"
	elif volume_id > 0:
		query +="volume_id"
	else:
		query +="movie_id"
	query += "', 'date', 'return_date') VALUES (Null, '" + str(data_person[0]['id']) + "', '"
	if collection_id > 0 and loan_whole_collection:
		query += str(collection_id)
	elif volume_id>0:
		query += str(volume_id)
	else:
		query += str(movie_id)
	query += "', '" + str(datetime.date.today()) + "', '');"
	self.db.cursor.execute(query)
	self.db.con.commit()
	
	# finally, force a refresh
	self.treeview_clicked()
Exemple #3
0
def commit(self):
    person_name = gutils.on_combo_box_entry_changed(
        self.widgets['movie']['loan_to'])
    if not person_name:
        return False
    self.widgets['w_loan_to'].hide()

    session = self.db.Session()

    person = session.query(
        db.Person.person_id).filter_by(name=person_name).first()
    if not person:
        log.warn("loan_commit: person doesn't exist")
        return False
    if self._movie_id:
        movie = session.query(
            db.Movie).filter_by(movie_id=self._movie_id).first()
        if not movie:
            log.warn("loan_commit: movie doesn't exist")
            return False
    else:
        log.warn("loan_commit: movie not selected")
        return False

    # ask if user wants to loan whole collection
    loan_whole_collection = False
    if movie.collection_id > 0:
        if gutils.question(_('Do you want to loan the whole collection?'),
                           window=self.widgets['window']):
            loan_whole_collection = True

    try:
        if movie.loan_to(person, whole_collection=loan_whole_collection):
            session.commit()
    except Exception, e:
        session.rollback()
        if e.message == 'loaned movies in the collection already':
            gutils.warning(
                _("Collection contains loaned movie.\nLoan aborted!"))
            return False
        else:
            raise e
def commit(self):
    person_name = gutils.on_combo_box_entry_changed(self.widgets['movie']['loan_to'])
    if not person_name:
        return False
    self.widgets['w_loan_to'].hide()

    session = self.db.Session()

    person = session.query(db.Person.person_id).filter_by(name=person_name).first()
    if not person:
        log.warn("loan_commit: person doesn't exist")
        return False
    if self._movie_id:
        movie = session.query(db.Movie).filter_by(movie_id=self._movie_id).first()
        if not movie:
            log.warn("loan_commit: movie doesn't exist")
            return False
    else:
        log.warn("loan_commit: movie not selected")
        return False

    # ask if user wants to loan whole collection
    loan_whole_collection = False
    if movie.collection_id > 0:
        response = gutils.question(_("Do you want to loan whole collection?"), window=self.widgets['window'])
        if response == gtk.RESPONSE_YES:
            loan_whole_collection = True
        elif response == gtk.RESPONSE_CANCEL:
            return False
    
    try:
        if movie.loan_to(person, whole_collection=loan_whole_collection):
            session.commit()
    except Exception, e:
        session.rollback()
        if e.message == 'loaned movies in the collection already':
            gutils.warning(_("Collection contains loaned movie.\nLoan aborted!"))
            return False
        else:
            raise e
def commit_loan(self):
	person_name = gutils.on_combo_box_entry_changed(self.widgets['movie']['loan_to'])
	if person_name == '' or person_name is None:
		return False
	self.widgets['w_loan_to'].hide()

	person = self.db.Person.get_by(name=person_name)
	if person is None:
		self.debug.show("commit_loan: person doesn't exist")
		return False
	if self._movie_id:
		movie = self.db.Movie.get_by(movie_id=self._movie_id)
		if not movie:
			self.debug.show("commit_loan: wrong movie_id")
			return False
	else:
		self.debug.show("commit_loan: movie not selected")
		return False

	# ask if user wants to loan whole collection
	loan_whole_collection = False
	if movie.collection_id>0:
		response = gutils.question(self, msg=_("Do you want to loan whole collection?"), parent=self.widgets['window'])
		if response == gtk.RESPONSE_YES:
			loan_whole_collection = True
		elif response == gtk.RESPONSE_CANCEL:
			return False
	
	loan = self.db.Loan(movie_id=movie.movie_id, person_id=person.person_id)
	if loan_whole_collection:
		loan.collection_id = movie.collection_id
	if movie.volume_id>0:
		loan.volume_id = movie.volume_id
	if loan.set_loaned():
		self.update_statusbar(_("Movie loaned"))
		self.treeview_clicked()
def save_preferences(self):
	w = self.widgets['preferences']
	c = self.config
	global spell_support

	was_false = notes_was_false = plot_was_false = 1	

	if c.get('gtkspell', False, section='spell') == True:
		was_false = 0

	if c.get('notes', False, section='spell') == True:
		notes_was_false = 0

	if c.get('plot', False, section='spell') == True:
		plot_was_false = 0

	# number
	if w['view_number'].get_active():
		c.set('number', 'True', section='mainlist')
	else:
		c.set('number', 'False', section='mainlist')
	# image
	if w['view_image'].get_active():
		c.set('image', 'True', section='mainlist')
	else:
		c.set('image', 'False', section='mainlist')
	# original title
	if w['view_o_title'].get_active():
		c.set('otitle', 'True', section='mainlist')
	else:
		c.set('otitle', 'False', section='mainlist')
	# title
	if w['view_title'].get_active():
		c.set('title', 'True', section='mainlist')
	else:
		c.set('title', 'False', section='mainlist')
	# director
	if w['view_director'].get_active():
		c.set('director', 'True', section='mainlist')
	else:
		c.set('director', 'False', section='mainlist')
	# genre
	if w['view_genre'].get_active():
		c.set('genre', 'True', section='mainlist')
	else:
		c.set('genre', 'False', section='mainlist')
	# seen
	if w['view_seen'].get_active():
		c.set('seen', 'True', section='mainlist')
	else:
		c.set('seen', 'False', section='mainlist')
	# year
	if w['view_year'].get_active():
		c.set('year', 'True', section='mainlist')
	else:
		c.set('year', 'False', section='mainlist')
	# runtime
	if w['view_runtime'].get_active():
		c.set('runtime', 'True', section='mainlist')
	else:
		c.set('runtime', 'False', section='mainlist')
	# rating
	if w['view_rating'].get_active():
		c.set('rating', 'True', section='mainlist')
	else:
		c.set('rating', 'False', section='mainlist')
	
	# sortby
	if w['sortby'].get_active():
		field = self.sort_criteria[w['sortby'].get_active()]
		if field:
			c.set('sortby', field, section='mainlist')
	else:
		c.set('sortby', 'number', section='mainlist')
	c.set('sortby_reverse', w['sortby_reverse'].get_active(), section='mainlist')
	
	c.set('limit', str(int(w['s_limit'].get_value())), section='mainlist')
	

	# pdf font
	if w['font'].get_filename():
		c['font'] = w['font'].get_filename()

	# spellchecker
	if w['spellchecker'].get_active():
		c.set('gtkspell', True, section='spell')
	else:
		c.set('gtkspell', False, section='spell')
	if w['spell_notes'].get_active():
		c.set('notes', True, section='spell')
	else:
		c.set('notes', False, section='spell')
	if w['spell_plot'].get_active():
		c.set('plot', True, section='spell')
	else:
		c.set('plot', False, section='spell')

	# rating image
	c['rating_image'] = str(w['rating_image'].get_active())

	#defaults
	media_id = self.media_ids[w['media'].get_active()]
	if media_id is None:
		media_id = 0
	c.set('media', media_id, section='defaults')
	vcodec_id = self.vcodecs_ids[w['vcodec'].get_active()]
	if vcodec_id is None:
		vcodec_id = 0
	c.set('vcodec', vcodec_id, section='defaults')
	c.set('condition', str(w['condition'].get_active()), section='defaults')
	c.set('region', str(w['region'].get_active()), section='defaults')
	c.set('layers', str(w['layers'].get_active()), section='defaults')
	c.set('color', str(w['color'].get_active()), section='defaults')

	# email reminder
	if w['mail_use_auth'].get_active():
		c.set('use_auth', True, section='mail')
	else:
		c.set('use_auth', False, section='mail')
		
	if w['mail_use_tls'].get_active():
		c.set('mail_use_tls', True, section='mail')
	else:
		c.set('mail_use_tls', False, section='mail')

	c.set('smtp_server', w['mail_smtp_server'].get_text(), section='mail')
	c.set('mail_smtp_port', w['mail_smtp_port'].get_text(), section='mail')

	c.set('username', w['mail_username'].get_text(), section='mail')
	c.set('password', w['mail_password'].get_text(), section='mail')
	c.set('email', w['mail_email'].get_text(), section='mail')

	# default movie plugin
	if w['default_plugin'].get_active():
		c['default_movie_plugin'] = \
			gutils.on_combo_box_entry_changed(w['default_plugin'])
	# search for:
	c.set('s_classification', w['s_classification'].get_active(), section='add')
	c.set('s_country', w['s_country'].get_active(), section='add')
	c.set('s_director', w['s_director'].get_active(), section='add')
	c.set('s_genre', w['s_genre'].get_active(), section='add')
	c.set('s_image', w['s_image'].get_active(), section='add')
	c.set('s_notes', w['s_notes'].get_active(), section='add')
	c.set('s_o_site', w['s_o_site'].get_active(), section='add')
	c.set('s_o_title', w['s_o_title'].get_active(), section='add')
	c.set('s_plot', w['s_plot'].get_active(), section='add')
	c.set('s_rating', w['s_rating'].get_active(), section='add')
	c.set('s_runtime', w['s_runtime'].get_active(), section='add')
	c.set('s_site', w['s_site'].get_active(), section='add')
	c.set('s_studio', w['s_studio'].get_active(), section='add')
	c.set('s_title', w['s_title'].get_active(), section='add')
	c.set('s_trailer', w['s_trailer'].get_active(), section='add')
	c.set('s_cast', w['s_cast'].get_active(), section='add')
	c.set('s_year', w['s_year'].get_active(), section='add')
	
	mcounter = 0
	for p in self.plugins:
		plugin_module = os.path.basename(p).replace('.py','')
		plugin_name = plugin_module.replace('PluginMovie','')
		if gutils.on_combo_box_entry_changed(w['default_plugin']) == plugin_name:
			self.d_plugin = mcounter
		mcounter = mcounter + 1
	self.widgets['add']['source'].set_active(self.d_plugin)

	if self.windows:
		save_reader = ''
	else:
		save_reader = w['epdf_reader'].get_text()

	c.set('lang', w['spell_lang'].get_text(), section='spell')
	c['pdf_reader'] = save_reader

	c.set('amazon_locale', w['amazon_locale'].get_active(), section='add')
	
	if spell_support:
		if c.get('gtkspell', False, section='spell') == False and not was_false:
			self.notes_spell.detach()
			self.plot_spell.detach()
		elif c.get('gtkspell', False, section='spell') == True and was_false:
			initialize.initialize_gtkspell(self)
		else:
			pass

		if c.get('gtkspell', False, section='spell') == True:
			if c.get('plot', True, section='spell') == False and not plot_was_false:
				self.plot_spell.detach()
			elif c.get('plot', True, section='spell') == True and plot_was_false:
				self.plot_spell = gtkspell.Spell(self.widgets['add']['plot'])
				self.plot_spell.set_language(c.get('lang', 'en', section='spell'))
			else:
				pass

			if c.get('notes', True, section='spell') == False and not notes_was_false:
				self.notes_spell.detach()
			elif c.get('notes', True, section='spell') == True and notes_was_false:
				self.notes_spell = gtkspell.Spell(self.widgets['add']['notes'])
				self.notes_spell.set_language(c.get('lang', 'en', section='spell'))
			else:
				pass
	self.pdf_reader = save_reader

	# database
	old = c.toDict(section='database')
	
	c.set('host', w['db_host'].get_text(), section='database')
	c.set('port', int(w['db_port'].get_value()), section='database')
	c.set('name', w['db_name'].get_text(), section='database')
	c.set('user', w['db_user'].get_text(), section='database')
	c.set('passwd', w['db_passwd'].get_text(), section='database')
	db_type = int(w['db_type'].get_active())
	if db_type == 1:
		c.set('type', 'postgres', section='database')
	elif db_type == 2:
		c.set('type', 'mysql', section='database')
	elif db_type == 3:
		c.set('type', 'mssql', section='database')
	else:
		c.set('type', 'sqlite', section='database')

	if old['type'] != c.get('type', section='database') or (old['type']!='sqlite' and (\
			old['host'] != c.get('host', section='database') or \
			old['port'] != c.get('port', section='database') or \
			old['user'] != c.get('user', section='database') or \
			old['passwd'] != c.get('passwd', section='database'))) or \
			old['name'] != c.get('name', section='database'):
		self.debug.show('DATABASE: connecting to new db server...')
		
		# new database connection
		import sql
		self.initialized = False
		self.db.metadata.clear()
		from sqlalchemy.orm import clear_mappers
		from sqlalchemy.exceptions import InvalidRequestError
		clear_mappers()
		try:
			self.db = sql.GriffithSQL(c, self.debug, self.locations['home'])
		except InvalidRequestError, e:
			self.debug.show(str(e))
			c.set('type', 'sqlite', section='database')
			w['db_type'].set_active(0)
			self.db = sql.GriffithSQL(c, self.debug, self.locations['home'])

		self.debug.show("New database Engine: %s" % self.db.metadata.engine.name)
		
		# initialize new database
		self.total = int(self.db.Movie.count())
		self.count_statusbar()
		from initialize	import dictionaries, people_treeview, location_posters
		c['posters'] = None # force update
		location_posters(self.locations, self.config)
		dictionaries(self)
		people_treeview(self, False)
		self.initialized = True
def save_preferences(self):
    w = self.widgets['preferences']
    c = self.config
    global spell_support

    was_false = notes_was_false = plot_was_false = 1

    if c.get('gtkspell', False, section='spell') == True:
        was_false = 0

    if c.get('notes', False, section='spell') == True:
        notes_was_false = 0

    if c.get('plot', False, section='spell') == True:
        plot_was_false = 0

    # number
    if w['view_number'].get_active():
        c.set('number', 'True', section='mainlist')
    else:
        c.set('number', 'False', section='mainlist')
    # image
    if w['view_image'].get_active():
        c.set('image', 'True', section='mainlist')
    else:
        c.set('image', 'False', section='mainlist')
    # original title
    if w['view_o_title'].get_active():
        c.set('otitle', 'True', section='mainlist')
    else:
        c.set('otitle', 'False', section='mainlist')
    # title
    if w['view_title'].get_active():
        c.set('title', 'True', section='mainlist')
    else:
        c.set('title', 'False', section='mainlist')
    # director
    if w['view_director'].get_active():
        c.set('director', 'True', section='mainlist')
    else:
        c.set('director', 'False', section='mainlist')
    # genre
    if w['view_genre'].get_active():
        c.set('genre', 'True', section='mainlist')
    else:
        c.set('genre', 'False', section='mainlist')
    # seen
    if w['view_seen'].get_active():
        c.set('seen', 'True', section='mainlist')
    else:
        c.set('seen', 'False', section='mainlist')
    # year
    if w['view_year'].get_active():
        c.set('year', 'True', section='mainlist')
    else:
        c.set('year', 'False', section='mainlist')
    # runtime
    if w['view_runtime'].get_active():
        c.set('runtime', 'True', section='mainlist')
    else:
        c.set('runtime', 'False', section='mainlist')
    # rating
    if w['view_rating'].get_active():
        c.set('rating', 'True', section='mainlist')
    else:
        c.set('rating', 'False', section='mainlist')
    # created
    if w['view_created'].get_active():
        c.set('created', 'True', section='mainlist')
    else:
        c.set('created', 'False', section='mainlist')
    # updated
    if w['view_updated'].get_active():
        c.set('updated', 'True', section='mainlist')
    else:
        c.set('updated', 'False', section='mainlist')

    # sortby
    if w['sortby'].get_active():
        field = self.sort_criteria[w['sortby'].get_active()]
        if field:
            c.set('sortby', field, section='mainlist')
    else:
        c.set('sortby', 'number', section='mainlist')
    c.set('sortby_reverse', w['sortby_reverse'].get_active(), section='mainlist')

    c.set('limit', str(int(w['s_limit'].get_value())), section='mainlist')


    # pdf font
    if w['font'].get_filename():
        c['font'] = w['font'].get_filename()
    c['font_size'] = int(w['font_size'].get_value())

    # pdf elements
    pdf_elements = ''
    for child in w['pdf_elements_table']:
        if child.get_active():
            pdf_elements = pdf_elements + child.get_name()[4:] + ','
    if pdf_elements:
        c.set('pdf_elements', pdf_elements[:-1])
    else:
        c.set('pdf_elements', pdf_elements)

    # spellchecker
    if w['spellchecker'].get_active():
        c.set('gtkspell', True, section='spell')
    else:
        c.set('gtkspell', False, section='spell')
    if w['spell_notes'].get_active():
        c.set('notes', True, section='spell')
    else:
        c.set('notes', False, section='spell')
    if w['spell_plot'].get_active():
        c.set('plot', True, section='spell')
    else:
        c.set('plot', False, section='spell')

    # rating image
    c['rating_image'] = str(w['rating_image'].get_active())

    #defaults
    media_id = self.media_ids[w['media'].get_active()]
    if media_id is None:
        media_id = 0
    c.set('media', media_id, section='defaults')
    vcodec_id = self.vcodecs_ids[w['vcodec'].get_active()]
    if vcodec_id is None:
        vcodec_id = 0
    c.set('vcodec', vcodec_id, section='defaults')
    c.set('condition', str(w['condition'].get_active()), section='defaults')
    c.set('region', str(w['region'].get_active()), section='defaults')
    c.set('layers', str(w['layers'].get_active()), section='defaults')
    c.set('color', str(w['color'].get_active()), section='defaults')

    # email reminder
    if w['mail_use_auth'].get_active():
        c.set('use_auth', True, section='mail')
    else:
        c.set('use_auth', False, section='mail')

    if w['mail_use_tls'].get_active():
        c.set('mail_use_tls', True, section='mail')
    else:
        c.set('mail_use_tls', False, section='mail')

    c.set('smtp_server', w['mail_smtp_server'].get_text(), section='mail')
    c.set('mail_smtp_port', w['mail_smtp_port'].get_text(), section='mail')

    c.set('username', w['mail_username'].get_text(), section='mail')
    c.set('password', w['mail_password'].get_text(), section='mail')
    c.set('email', w['mail_email'].get_text(), section='mail')

    # default movie plugin
    if w['default_plugin'].get_active():
        c['default_movie_plugin'] = \
            gutils.on_combo_box_entry_changed(w['default_plugin'])
    # search for:
    c.set('s_classification', w['s_classification'].get_active(), section='add')
    c.set('s_country', w['s_country'].get_active(), section='add')
    c.set('s_director', w['s_director'].get_active(), section='add')
    c.set('s_genre', w['s_genre'].get_active(), section='add')
    c.set('s_image', w['s_image'].get_active(), section='add')
    c.set('s_notes', w['s_notes'].get_active(), section='add')
    c.set('s_o_site', w['s_o_site'].get_active(), section='add')
    c.set('s_o_title', w['s_o_title'].get_active(), section='add')
    c.set('s_plot', w['s_plot'].get_active(), section='add')
    c.set('s_rating', w['s_rating'].get_active(), section='add')
    c.set('s_runtime', w['s_runtime'].get_active(), section='add')
    c.set('s_site', w['s_site'].get_active(), section='add')
    c.set('s_studio', w['s_studio'].get_active(), section='add')
    c.set('s_title', w['s_title'].get_active(), section='add')
    c.set('s_trailer', w['s_trailer'].get_active(), section='add')
    c.set('s_cast', w['s_cast'].get_active(), section='add')
    c.set('s_year', w['s_year'].get_active(), section='add')
    c.set('s_screenplay', w['s_screenplay'].get_active(), section='add')
    c.set('s_cameraman', w['s_cameraman'].get_active(), section='add')
    c.set('s_resolution', w['s_resolution'].get_active(), section='add')
    c.set('s_barcode', w['s_barcode'].get_active(), section='add')

    mcounter = 0
    for p in self.plugins:
        plugin_module = os.path.basename(p).replace('.py','')
        plugin_name = plugin_module.replace('PluginMovie','')
        if gutils.on_combo_box_entry_changed(w['default_plugin']) == plugin_name:
            break
        mcounter = mcounter + 1
    self.widgets['add']['source'].set_active(mcounter)

    save_reader = w['epdf_reader'].get_text()

    c.set('lang', w['spell_lang'].get_text(), section='spell')
    c['pdf_reader'] = save_reader

    if spell_support:
        if c.get('gtkspell', False, section='spell') == False and not was_false:
            self.notes_spell.detach()
            self.plot_spell.detach()
        elif c.get('gtkspell', False, section='spell') == True and was_false:
            initialize.spellcheck(self)
        else:
            pass

        if c.get('gtkspell', False, section='spell') == True:
            if c.get('plot', True, section='spell') == False and not plot_was_false:
                self.plot_spell.detach()
            elif c.get('plot', True, section='spell') == True and plot_was_false:
                self.plot_spell = gtkspell.Spell(self.widgets['add']['plot'])
                self.plot_spell.set_language(c.get('lang', 'en', section='spell'))
            else:
                pass

            if c.get('notes', True, section='spell') == False and not notes_was_false:
                self.notes_spell.detach()
            elif c.get('notes', True, section='spell') == True and notes_was_false:
                self.notes_spell = gtkspell.Spell(self.widgets['add']['notes'])
                self.notes_spell.set_language(c.get('lang', 'en', section='spell'))
            else:
                pass
    self.pdf_reader = save_reader

    # extensions settings
    for ext_name in plugins.extensions.by_name:
        preferenceswidgets = plugins.extensions.by_name[ext_name].preferenceswidgets
        for prefname in preferenceswidgets:
            widget = preferenceswidgets[prefname]
            if isinstance(widget, gtk.CheckButton):
                value = widget.get_active()
            elif isinstance(widget, gtk.Entry):
                value = widget.get_text()
            elif isinstance(widget, gtk.ComboBox):
                iter = widget.get_active_iter()
                if iter:
                    value = widget.get_model().get_value(iter, 1)
            else:
                log.error('widget type not supported %s', type(widget))
                continue
            c.set("%s_%s" % (ext_name, prefname), value, section='extensions')

    # database
    old = c.to_dict(section='database')

    c.set('host', w['db_host'].get_text(), section='database')
    c.set('port', int(w['db_port'].get_value()), section='database')
    c.set('name', w['db_name'].get_text(), section='database')
    c.set('user', w['db_user'].get_text(), section='database')
    c.set('passwd', w['db_passwd'].get_text(), section='database')
    db_type = int(w['db_type'].get_active())
    if db_type == 1:
        c.set('type', 'postgres', section='database')
    elif db_type == 2:
        c.set('type', 'mysql', section='database')
    elif db_type == 3:
        c.set('type', 'mssql', section='database')
    else:
        c.set('type', 'sqlite', section='database')

    if old['type'] != c.get('type', section='database') or (old['type']!='sqlite' and (\
            old['host'] != c.get('host', section='database') or \
            old['port'] != c.get('port', section='database') or \
            old['user'] != c.get('user', section='database') or \
            old['passwd'] != c.get('passwd', section='database'))) or \
            old['name'] != c.get('name', section='database'):
        log.info('DATABASE: connecting to new db server...')
        import sql
        from sqlalchemy.exceptions import InvalidRequestError
        from initialize import dictionaries, people_treeview

        # new database connection
        self.initialized = False
        if c.has_key('posters'):
            c['posters'] = None # force update
        try:
            self.db.dispose()
            self.db = sql.GriffithSQL(c, self.locations['home'], fallback=True)
        except InvalidRequestError, e:
            log.exception('')
            c.set('type', 'sqlite', section='database')
            w['db_type'].set_active(0)
            self.db = sql.GriffithSQL(c, self.locations['home'])

        log.info("New database Engine: %s" % self.db.session.bind.engine.name)

        # initialize new database
        self.total = int(self.db.session.query(db.Movie).count())
        self.count_statusbar()
        dictionaries(self)
        people_treeview(self, False)
        self.initialized = True
def save_preferences(self):

	global spell_support

	was_false = obs_was_false = plot_was_false = 1	

	if self.config.get('use_gtkspell', 'False') == 'True':
		was_false = 0

	if self.config.get('spell_notes', 'False') == 'True':
		obs_was_false = 0

	if self.config.get('spell_plot', 'False') == 'True':
		plot_was_false = 0

	# image
	if self.view_image.get_active():
		self.config['view_image'] = 'True'
	else:
		self.config['view_image'] = 'False'
	# original title
	if self.view_otitle.get_active():
		self.config['view_otitle'] = 'True'
	else:
		self.config['view_otitle'] = 'False'
	# title
	if self.view_title.get_active():
		self.config['view_title'] = 'True'
	else:
		self.config['view_title'] = 'False'
	# director
	if self.view_director.get_active():
		self.config['view_director'] = 'True'
	else:
		self.config['view_director'] = 'False'

	# pdf font
	if self.p_font.get_filename():
		self.config['font'] = self.p_font.get_filename()

	# spellchecker
	if self.spellchecker.get_active():
		self.config['use_gtkspell'] = 'True'
	else:
		self.config['use_gtkspell'] = 'False'		
	if self.spell_notes.get_active():
		self.config['spell_notes'] = 'True'
	else:
		self.config['spell_notes'] = 'False'
	if self.spell_plot.get_active():
		self.config['spell_plot'] = 'True'
	else:
		self.config['spell_plot'] = 'False'

	# rating image
	self.config['rating_image'] = str(self.rating_image.get_active())

	#defaults
	self.config['media'] = str(self.p_media.get_active())
	self.config['condition'] = str(self.p_condition.get_active())
	self.config['region'] = str(self.p_region.get_active())
	self.config['layers'] = str(self.p_layers.get_active())
	self.config['color'] = str(self.p_color.get_active())

	# email reminder
	if self.mail_use_auth.get_active():
		self.config['mail_use_auth'] = 'True'
	else:
		self.config['mail_use_auth'] = 'False'

	self.config['mail_smtp_server'] = self.mail_smtp_server.get_text()
	self.config['mail_username'] = self.mail_username.get_text()
	self.config['mail_password'] = self.mail_password.get_text()
	self.config['mail_email'] = self.mail_email.get_text()

	# default movie plugin
	if self.default_plugin.get_active():
		self.config['default_movie_plugin'] = \
			gutils.on_combo_box_entry_changed(self.default_plugin)  
	mcounter = 0		
	for p in self.plugins:
		plugin_module = os.path.basename(p).replace(".py","")
		plugin_name = plugin_module.replace("PluginMovie","")
		if gutils.on_combo_box_entry_changed(self.default_plugin) == plugin_name:
			self.d_plugin = mcounter
		mcounter = mcounter + 1
	self.am_source.set_active(self.d_plugin)

	if self.windows:
		save_reader = ''
	else:
		save_reader = self.epdf_reader.get_text()

	self.config['spell_lang'] = self.spell_lang.get_text()
	self.config['pdf_reader'] = save_reader
	self.config.save()

	if spell_support:
		if self.config.get('use_gtkspell', 'False') == 'False' and not was_false:
			self.obs_spell.detach()
			self.plot_spell.detach()
		elif self.config.get('use_gtkspell', 'False') == 'True' and was_false:
			initialize.initialize_gtkspell(self)
		else:
			pass

		if self.config.get('use_gtkspell', 'False') == 'True':	
			if self.config.get('spell_plot', 'True') == 'False' and not plot_was_false:
				self.plot_spell.detach()
			elif self.config.get('spell_plot', 'True') == 'True' and plot_was_false:
				self.plot_spell = gtkspell.Spell(self.e_plot)
				self.plot_spell.set_language(self.config.get('spell_lang', 'en'))
			else:
				pass

			if self.config.get('spell_notes', 'True') == 'False' and not obs_was_false:
				self.obs_spell.detach()
			elif self.config.get('spell_notes', 'True') == 'True' and obs_was_false:
				self.obs_spell = gtkspell.Spell(self.e_obs)
				self.obs_spell.set_language(self.config.get('spell_lang', 'en'))
			else:
				pass

	self.pdf_reader = save_reader
	self.clear_details()
	self.populate_treeview(self.db.get_all_data(order_by="number ASC"))
	self.select_last_row(self.total)
def save_preferences(self):
	w = self.widgets['preferences']
	c = self.config
	global spell_support

	was_false = notes_was_false = plot_was_false = 1	

	if c.get('use_gtkspell', 'False') == 'True':
		was_false = 0

	if c.get('spell_notes', 'False') == 'True':
		notes_was_false = 0

	if c.get('spell_plot', 'False') == 'True':
		plot_was_false = 0

	# image
	if w['view_image'].get_active():
		c['view_image'] = 'True'
	else:
		c['view_image'] = 'False'
	# original title
	if w['view_o_title'].get_active():
		c['view_otitle'] = 'True'
	else:
		c['view_otitle'] = 'False'
	# title
	if w['view_title'].get_active():
		c['view_title'] = 'True'
	else:
		c['view_title'] = 'False'
	# director
	if w['view_director'].get_active():
		c['view_director'] = 'True'
	else:
		c['view_director'] = 'False'
	
	# sortby
	if w['sortby'].get_active():
		field = self.sort_criteria[w['sortby'].get_active()]
		if field:
			c['sortby'] = field
	else:
		c['sortby'] = 'number'
	c['sortby_reverse'] = w['sortby_reverse'].get_active()
	

	# pdf font
	if w['font'].get_filename():
		c['font'] = w['font'].get_filename()

	# spellchecker
	if w['spellchecker'].get_active():
		c['use_gtkspell'] = 'True'
	else:
		c['use_gtkspell'] = 'False'		
	if w['spell_notes'].get_active():
		c['spell_notes'] = 'True'
	else:
		c['spell_notes'] = 'False'
	if w['spell_plot'].get_active():
		c['spell_plot'] = 'True'
	else:
		c['spell_plot'] = 'False'

	# rating image
	c['rating_image'] = str(w['rating_image'].get_active())

	#defaults
	c['media'] = self.media_ids[w['media'].get_active()]
	c['vcodec'] = self.vcodecs_ids[w['vcodec'].get_active()]
	c['condition'] = str(w['condition'].get_active())
	c['region'] = str(w['region'].get_active())
	c['layers'] = str(w['layers'].get_active())
	c['color'] = str(w['color'].get_active())

	# email reminder
	if w['mail_use_auth'].get_active():
		c['mail_use_auth'] = 'True'
	else:
		c['mail_use_auth'] = 'False'

	c['mail_smtp_server'] = w['mail_smtp_server'].get_text()
	c['mail_username'] = w['mail_username'].get_text()
	c['mail_password'] = w['mail_password'].get_text()
	c['mail_email'] = w['mail_email'].get_text()

	# default movie plugin
	if w['default_plugin'].get_active():
		c['default_movie_plugin'] = \
			gutils.on_combo_box_entry_changed(w['default_plugin'])
	# search for:
	c['s_classification'] = w['s_classification'].get_active()
	c['s_country'] = w['s_country'].get_active()
	c['s_director'] = w['s_director'].get_active()
	c['s_genre'] = w['s_genre'].get_active()
	c['s_image'] = w['s_image'].get_active()
	c['s_notes'] = w['s_notes'].get_active()
	c['s_o_site'] = w['s_o_site'].get_active()
	c['s_o_title'] = w['s_o_title'].get_active()
	c['s_plot'] = w['s_plot'].get_active()
	c['s_rating'] = w['s_rating'].get_active()
	c['s_runtime'] = w['s_runtime'].get_active()
	c['s_site'] = w['s_site'].get_active()
	c['s_studio'] = w['s_studio'].get_active()
	c['s_title'] = w['s_title'].get_active()
	c['s_trailer'] = w['s_trailer'].get_active()
	c['s_cast'] = w['s_cast'].get_active()
	c['s_year'] = w['s_year'].get_active()
	
	mcounter = 0
	for p in self.plugins:
		plugin_module = os.path.basename(p).replace('.py','')
		plugin_name = plugin_module.replace('PluginMovie','')
		if gutils.on_combo_box_entry_changed(w['default_plugin']) == plugin_name:
			self.d_plugin = mcounter
		mcounter = mcounter + 1
	self.widgets['add']['source'].set_active(self.d_plugin)

	if self.windows:
		save_reader = ''
	else:
		save_reader = w['epdf_reader'].get_text()

	c['spell_lang'] = w['spell_lang'].get_text()
	c['pdf_reader'] = save_reader

	c['amazon_locale'] = w['amazon_locale'].get_active()
	
	if spell_support:
		if c.get('use_gtkspell', 'False') == 'False' and not was_false:
			self.notes_spell.detach()
			self.plot_spell.detach()
		elif c.get('use_gtkspell', 'False') == 'True' and was_false:
			initialize.initialize_gtkspell(self)
		else:
			pass

		if c.get('use_gtkspell', 'False') == 'True':
			if c.get('spell_plot', 'True') == 'False' and not plot_was_false:
				self.plot_spell.detach()
			elif c.get('spell_plot', 'True') == 'True' and plot_was_false:
				self.plot_spell = gtkspell.Spell(self.widgets['add']['plot'])
				self.plot_spell.set_language(c.get('spell_lang', 'en'))
			else:
				pass

			if c.get('spell_notes', 'True') == 'False' and not notes_was_false:
				self.notes_spell.detach()
			elif c.get('spell_notes', 'True') == 'True' and notes_was_false:
				self.notes_spell = gtkspell.Spell(self.widgets['add']['notes'])
				self.notes_spell.set_language(c.get('spell_lang', 'en'))
			else:
				pass
	self.pdf_reader = save_reader

	# database
	old = {
		'db_type':   c['db_type'],
		'db_host':   c['db_host'],
		'db_port':   c['db_port'],
		'db_name':   c['db_name'],
		'db_user':   c['db_user'],
		'db_passwd': c['db_passwd'],
	}
	c['db_host']   = w['db_host'].get_text()
	c['db_port']   = int(w['db_port'].get_value())
	c['db_name']   = w['db_name'].get_text()
	c['db_user']   = w['db_user'].get_text()
	c['db_passwd'] = w['db_passwd'].get_text()
	db_type = int(w['db_type'].get_active())
	if db_type == 1:
		c['db_type'] = 'postgres'
	elif db_type == 2:
		c['db_type'] = 'mysql'
	else:
		c['db_type'] = 'sqlite'

	if old['db_type'] != c['db_type'] or (old['db_type']!='sqlite' and (\
			old['db_host'] != c['db_host'] or \
			old['db_port'] != c['db_port'] or \
			old['db_name'] != c['db_name'] or \
			old['db_user'] != c['db_user'] or \
			old['db_passwd'] != c['db_passwd'])):
		self.debug.show('DATABASE: connecting to new db server...')
		
		# new database connection
		import sql
		self.initialized = False
		self.db.metadata.clear()
		from sqlalchemy.orm import clear_mappers
		clear_mappers()
		self.db = sql.GriffithSQL(c, self.debug, self.locations['home'])
		self.debug.show("New database Engine: %s" % self.db.metadata.engine.name)
		
		# initialize new database
		self.total = int(self.db.Movie.count())
		self.count_statusbar()
		from initialize	import dictionaries, people_treeview, location_posters
		c['posters'] = None # force update
		location_posters(self.locations, self.config)
		dictionaries(self)
		people_treeview(self, False)
		self.initialized = True
	self.clear_details()
	self.populate_treeview()
	self.go_last()
	c.save()
Exemple #10
0
def save_preferences(self):
    w = self.widgets['preferences']
    c = self.config
    global spell_support

    was_false = notes_was_false = plot_was_false = 1

    if c.get('gtkspell', False, section='spell') == True:
        was_false = 0

    if c.get('notes', False, section='spell') == True:
        notes_was_false = 0

    if c.get('plot', False, section='spell') == True:
        plot_was_false = 0

    # number
    if w['view_number'].get_active():
        c.set('number', 'True', section='mainlist')
    else:
        c.set('number', 'False', section='mainlist')
    # image
    if w['view_image'].get_active():
        c.set('image', 'True', section='mainlist')
    else:
        c.set('image', 'False', section='mainlist')
    # original title
    if w['view_o_title'].get_active():
        c.set('otitle', 'True', section='mainlist')
    else:
        c.set('otitle', 'False', section='mainlist')
    # title
    if w['view_title'].get_active():
        c.set('title', 'True', section='mainlist')
    else:
        c.set('title', 'False', section='mainlist')
    # director
    if w['view_director'].get_active():
        c.set('director', 'True', section='mainlist')
    else:
        c.set('director', 'False', section='mainlist')
    # genre
    if w['view_genre'].get_active():
        c.set('genre', 'True', section='mainlist')
    else:
        c.set('genre', 'False', section='mainlist')
    # seen
    if w['view_seen'].get_active():
        c.set('seen', 'True', section='mainlist')
    else:
        c.set('seen', 'False', section='mainlist')
    # year
    if w['view_year'].get_active():
        c.set('year', 'True', section='mainlist')
    else:
        c.set('year', 'False', section='mainlist')
    # runtime
    if w['view_runtime'].get_active():
        c.set('runtime', 'True', section='mainlist')
    else:
        c.set('runtime', 'False', section='mainlist')
    # rating
    if w['view_rating'].get_active():
        c.set('rating', 'True', section='mainlist')
    else:
        c.set('rating', 'False', section='mainlist')
    # created
    if w['view_created'].get_active():
        c.set('created', 'True', section='mainlist')
    else:
        c.set('created', 'False', section='mainlist')
    # updated
    if w['view_updated'].get_active():
        c.set('updated', 'True', section='mainlist')
    else:
        c.set('updated', 'False', section='mainlist')

    # sortby
    if w['sortby'].get_active():
        field = self.sort_criteria[w['sortby'].get_active()]
        if field:
            c.set('sortby', field, section='mainlist')
    else:
        c.set('sortby', 'number', section='mainlist')
    c.set('sortby_reverse',
          w['sortby_reverse'].get_active(),
          section='mainlist')

    c.set('limit', str(int(w['s_limit'].get_value())), section='mainlist')

    # pdf font
    if w['font'].get_filename():
        c['font'] = w['font'].get_filename()
    c['font_size'] = int(w['font_size'].get_value())

    # pdf elements
    pdf_elements = ''
    for child in w['pdf_elements_table']:
        if child.get_active():
            pdf_elements = pdf_elements + child.get_name()[4:] + ','
    if pdf_elements:
        c.set('pdf_elements', pdf_elements[:-1])
    else:
        c.set('pdf_elements', pdf_elements)

    # spellchecker
    if w['spellchecker'].get_active():
        c.set('gtkspell', True, section='spell')
    else:
        c.set('gtkspell', False, section='spell')
    if w['spell_notes'].get_active():
        c.set('notes', True, section='spell')
    else:
        c.set('notes', False, section='spell')
    if w['spell_plot'].get_active():
        c.set('plot', True, section='spell')
    else:
        c.set('plot', False, section='spell')

    # rating image
    c['rating_image'] = str(w['rating_image'].get_active())

    #defaults
    media_id = self.media_ids[w['media'].get_active()]
    if media_id is None:
        media_id = 0
    c.set('media', media_id, section='defaults')
    vcodec_id = self.vcodecs_ids[w['vcodec'].get_active()]
    if vcodec_id is None:
        vcodec_id = 0
    c.set('vcodec', vcodec_id, section='defaults')
    c.set('condition', str(w['condition'].get_active()), section='defaults')
    c.set('region', str(w['region'].get_active()), section='defaults')
    c.set('layers', str(w['layers'].get_active()), section='defaults')
    c.set('color', str(w['color'].get_active()), section='defaults')
    c.set('seen', str(w['seen'].get_active()), section='defaults')

    # email reminder
    if w['mail_use_auth'].get_active():
        c.set('use_auth', True, section='mail')
    else:
        c.set('use_auth', False, section='mail')

    if w['mail_use_tls'].get_active():
        c.set('mail_use_tls', True, section='mail')
    else:
        c.set('mail_use_tls', False, section='mail')

    c.set('smtp_server', w['mail_smtp_server'].get_text(), section='mail')
    c.set('mail_smtp_port', w['mail_smtp_port'].get_text(), section='mail')

    c.set('username', w['mail_username'].get_text(), section='mail')
    c.set('password', w['mail_password'].get_text(), section='mail')
    c.set('email', w['mail_email'].get_text(), section='mail')

    # default movie plugin
    if w['default_plugin'].get_active():
        c['default_movie_plugin'] = \
            gutils.on_combo_box_entry_changed(w['default_plugin'])
    # search for:
    c.set('s_classification',
          w['s_classification'].get_active(),
          section='add')
    c.set('s_country', w['s_country'].get_active(), section='add')
    c.set('s_director', w['s_director'].get_active(), section='add')
    c.set('s_genre', w['s_genre'].get_active(), section='add')
    c.set('s_image', w['s_image'].get_active(), section='add')
    c.set('s_notes', w['s_notes'].get_active(), section='add')
    c.set('s_o_site', w['s_o_site'].get_active(), section='add')
    c.set('s_o_title', w['s_o_title'].get_active(), section='add')
    c.set('s_plot', w['s_plot'].get_active(), section='add')
    c.set('s_rating', w['s_rating'].get_active(), section='add')
    c.set('s_runtime', w['s_runtime'].get_active(), section='add')
    c.set('s_site', w['s_site'].get_active(), section='add')
    c.set('s_studio', w['s_studio'].get_active(), section='add')
    c.set('s_title', w['s_title'].get_active(), section='add')
    c.set('s_trailer', w['s_trailer'].get_active(), section='add')
    c.set('s_cast', w['s_cast'].get_active(), section='add')
    c.set('s_year', w['s_year'].get_active(), section='add')
    c.set('s_screenplay', w['s_screenplay'].get_active(), section='add')
    c.set('s_cameraman', w['s_cameraman'].get_active(), section='add')
    c.set('s_resolution', w['s_resolution'].get_active(), section='add')
    c.set('s_barcode', w['s_barcode'].get_active(), section='add')

    mcounter = 0
    for p in self.plugins:
        plugin_module = os.path.basename(p).replace('.py', '')
        plugin_name = plugin_module.replace('PluginMovie', '')
        if gutils.on_combo_box_entry_changed(
                w['default_plugin']) == plugin_name:
            break
        mcounter = mcounter + 1
    self.widgets['add']['source'].set_active(mcounter)

    save_reader = w['epdf_reader'].get_text()

    c.set('lang', w['spell_lang'].get_text(), section='spell')
    c['pdf_reader'] = save_reader

    if spell_support:
        if c.get('gtkspell', False,
                 section='spell') == False and not was_false:
            self.notes_spell.detach()
            self.plot_spell.detach()
        elif c.get('gtkspell', False, section='spell') == True and was_false:
            initialize.spellcheck(self)
        else:
            pass

        if c.get('gtkspell', False, section='spell') == True:
            if c.get('plot', True,
                     section='spell') == False and not plot_was_false:
                self.plot_spell.detach()
            elif c.get('plot', True,
                       section='spell') == True and plot_was_false:
                self.plot_spell = gtkspell.Spell(self.widgets['add']['plot'])
                self.plot_spell.set_language(
                    c.get('lang', 'en', section='spell'))
            else:
                pass

            if c.get('notes', True,
                     section='spell') == False and not notes_was_false:
                self.notes_spell.detach()
            elif c.get('notes', True,
                       section='spell') == True and notes_was_false:
                self.notes_spell = gtkspell.Spell(self.widgets['add']['notes'])
                self.notes_spell.set_language(
                    c.get('lang', 'en', section='spell'))
            else:
                pass
    self.pdf_reader = save_reader

    # extensions settings
    for ext_name in plugins.extensions.by_name:
        preferenceswidgets = plugins.extensions.by_name[
            ext_name].preferenceswidgets
        for prefname in preferenceswidgets:
            widget = preferenceswidgets[prefname]
            if isinstance(widget, gtk.CheckButton):
                value = widget.get_active()
            elif isinstance(widget, gtk.Entry):
                value = widget.get_text()
            elif isinstance(widget, gtk.ComboBox):
                iter = widget.get_active_iter()
                if iter:
                    value = widget.get_model().get_value(iter, 1)
            else:
                log.error('widget type not supported %s', type(widget))
                continue
            c.set("%s_%s" % (ext_name, prefname), value, section='extensions')

    # database
    old = c.to_dict(section='database')

    c.set('host', w['db_host'].get_text(), section='database')
    c.set('port', int(w['db_port'].get_value()), section='database')
    c.set('name', w['db_name'].get_text(), section='database')
    c.set('user', w['db_user'].get_text(), section='database')
    c.set('passwd', w['db_passwd'].get_text(), section='database')
    db_type = int(w['db_type'].get_active())
    if db_type == 1:
        c.set('type', 'postgres', section='database')
    elif db_type == 2:
        c.set('type', 'mysql', section='database')
    elif db_type == 3:
        c.set('type', 'mssql', section='database')
    else:
        c.set('type', 'sqlite', section='database')

    if old['type'] != c.get('type', section='database') or (old['type']!='sqlite' and (\
            old['host'] != c.get('host', section='database') or \
            old['port'] != c.get('port', section='database') or \
            old['user'] != c.get('user', section='database') or \
            old['passwd'] != c.get('passwd', section='database'))) or \
            old['name'] != c.get('name', section='database'):
        log.info('DATABASE: connecting to new db server...')
        import sql
        from sqlalchemy.exc import InvalidRequestError
        from initialize import dictionaries, people_treeview

        # new database connection
        self.initialized = False
        if c.has_key('posters'):
            c['posters'] = None  # force update
        try:
            self.db.dispose()
            self.db = sql.GriffithSQL(c, self.locations['home'], fallback=True)
        except InvalidRequestError, e:
            log.exception('')
            c.set('type', 'sqlite', section='database')
            w['db_type'].set_active(0)
            self.db = sql.GriffithSQL(c, self.locations['home'])

        log.info("New database Engine: %s" % self.db.session.bind.engine.name)

        # initialize new database
        self.total = int(self.db.session.query(db.Movie).count())
        self.count_statusbar()
        dictionaries(self)
        people_treeview(self, False)
        self.initialized = True