Source

lrc / src / gui / EditDialog.cxx

Full commit
/*
 * EditDialog.cxx
 *
 * Copyright 2013 Andreas Tscharner <andy@vis.ethz.ch>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 * MA 02110-1301, USA.
 */


#include "EditDialog.hxx"
#include "Utils.hxx"
#include "../include/CompressDecompress.hxx"
#include "../include/EncryptDecrypt.hxx"


inline int EditDialog::compNameToIndex(const char *p_compName)
{
	if (strcmp("None", p_compName) == 0) {
		return 0;
	};

	for (int iter = lrc::NoneCompression; iter < lrc::lastCompression; iter++) {
		if (strcmp(lrc::CompressionTypeNames[iter], p_compName) == 0) {
			return iter;
		};
	};

	return 0;
}

inline int EditDialog::encNameToIndex(const char *p_encName)
{
	if (strcmp("None", p_encName) == 0) {
		return 0;
	};

	for (int iter = lrc::NoneEncryption; iter < lrc::lastEncryption; iter++) {
		if (strcmp(lrc::EncryptionTypeNames[iter], p_encName) == 0) {
			return iter;
		};
	};

	return 0;
}

void EditDialog::SetUpValues(Gtk::TreeModel::Row p_row)
{
	Gtk::Entry *edResID;
	Gtk::Entry *edResFilename;
	Gtk::Entry *edResPassword;
	Glib::ustring compTypeName;
	Glib::ustring encTypeName;


	this->m_compSelect->set_active(0);
	this->m_encSelect->set_active(0);

	this->m_refBuilder->get_widget("edID", edResID);
	edResID->set_text(p_row[this->m_resColModel->FUniqueResID]);

	this->m_refBuilder->get_widget("edFilename", edResFilename);
	edResFilename->set_text(p_row[this->m_resColModel->FResFilename]);

	compTypeName = p_row[this->m_resColModel->FCompressTypeName];
	this->m_compSelect->set_active(this->compNameToIndex(compTypeName.c_str()));

	encTypeName = p_row[this->m_resColModel->FEncryptTypeName];
	this->m_encSelect->set_active(this->encNameToIndex(encTypeName.c_str()));

	this->m_refBuilder->get_widget("edPassword", edResPassword);
	if (this->encNameToIndex(encTypeName.c_str()) > lrc::NoneEncryption) {
		edResPassword->set_text(p_row[this->m_resColModel->FEncPassword]);
	};
	edResPassword->set_editable(this->encNameToIndex(encTypeName.c_str()) > lrc::NoneEncryption);
}


void EditDialog::on_enc_combo_changed(void)
{
	Gtk::TreeModel::iterator activeEncIter;
	Gtk::TreeModel::Row activeEncRow;
	Gtk::Entry *edResPassword;
	Glib::ustring encTypeName;


	DEBUG_PRINT(("on_enc_combo_changed starts\n"))
	activeEncIter = this->m_encSelect->get_active();
	if (!activeEncIter)
		return;

	DEBUG_PRINT(("We have an active encryption iterator..."))
	activeEncRow = *activeEncIter;
	if (!activeEncRow)
		return;

	DEBUG_PRINT((" and a corresponding row\n"))
	DEBUG_PRINT(("this->m_resColModel->FEncryptTypeName: %s\n", this->m_resColModel->FEncryptTypeName))
	encTypeName = activeEncRow[this->m_resColModel->FEncryptTypeName];
	m_refBuilder->get_widget("edPassword", edResPassword);
	edResPassword->set_editable(this->encNameToIndex(encTypeName.c_str()) > lrc::NoneEncryption);

	DEBUG_PRINT(("on_enc_combo_changed ends. New encryption: %s\n", encTypeName.c_str()))
}


EditDialog::EditDialog(Glib::RefPtr<Gtk::Builder> p_refBuilder, ResColumnModel *p_resColModel)
{
	m_refBuilder = p_refBuilder;
	m_resColModel = p_resColModel;

	m_refBuilder->get_widget("dlgEdit", m_editDialog);

	p_refBuilder->get_widget("cbxCompression", m_compSelect);
	for (unsigned int iter = lrc::NoneCompression; iter < lrc::lastCompression; iter++) {
		m_compSelect->append(lrc::CompressionTypeNames[iter]);
	};

	p_refBuilder->get_widget("cbxEncryption", m_encSelect);
	for (unsigned int iter = lrc::NoneEncryption; iter < lrc::lastEncryption; iter++) {
		m_encSelect->append(lrc::EncryptionTypeNames[iter]);
	};
	this->m_encSelect->signal_changed().connect(sigc::mem_fun(*this, &EditDialog::on_enc_combo_changed));
}

EditDialog::~EditDialog(void)
{
	delete m_encSelect;
	delete m_compSelect;
	delete m_editDialog;
}

int EditDialog::show_dialog(Gtk::TreeModel::Row p_row)
{
	int retVal;


	if (!this->m_editDialog)
		return -1;

	this->SetUpValues(p_row);

	retVal = this->m_editDialog->run();
	this->m_editDialog->hide();

	return retVal;
}

void EditDialog::GetEditedValues(Gtk::TreeModel::Row p_row)
{
}