lrc / src / gui / MainWindow.cxx

/*
 * MainWindow.cxx
 *
 * Copyright 2012 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 <gtkmm/treeview.h>
#include <gtkmm/cellrenderercombo.h>
#include "../include/CompressDecompress.hxx"
#include "../include/EncryptDecrypt.hxx"
#include "MainWindow.hxx"
#include "AddRemoveHandlers.hxx"
#include "ComboModels.hxx"
#include "ResColumnModel.hxx"

#ifdef HAVE_CONFIG_H
#include "../lrc_config.h"
#endif


MainWindow::MainWindow(Gtk::Window *p_mainWin, Glib::RefPtr<Gtk::Builder> p_refBuilder)
{
	Gtk::TreeView *resFileView;
	Gtk::TreeModel::Row aRow;
	Gtk::TreeView::Column *compCol;
	Gtk::TreeView::Column *encCol;
	Gtk::CellRendererCombo *compRenderer;
	Gtk::CellRendererCombo *encRenderer;


	m_mainWindow = p_mainWin;
	m_refBuilder = p_refBuilder;

	m_resColModel = new ResColumnModel();
	m_listResFiles = Gtk::ListStore::create(*m_resColModel);
	m_addRemove = new AddRemoveHandlers(m_refBuilder);
	m_listHandler = new ListHandler(m_listResFiles, m_resColModel);
	m_addRemove->setListHandler(m_listHandler);

	m_listCompTypes = Gtk::ListStore::create(*m_listHandler->FCompColModel);
	aRow = *(m_listCompTypes->append());
	aRow[m_listHandler->FCompColModel->FCompTypeName] = "Keine";
	aRow[m_listHandler->FCompColModel->FCompTypeData] = lrc::NoneCompression;
	aRow = *(m_listCompTypes->append());
	aRow[m_listHandler->FCompColModel->FCompTypeName] = "zLib";
	aRow[m_listHandler->FCompColModel->FCompTypeData] = lrc::zLibCompression;
	aRow = *(m_listCompTypes->append());
	aRow[m_listHandler->FCompColModel->FCompTypeName] = "bzip2";
	aRow[m_listHandler->FCompColModel->FCompTypeData] = lrc::bz2LibCompression;

	m_listEncTypes = Gtk::ListStore::create(*m_listHandler->FEncColModel);
	aRow = *(m_listEncTypes->append());
	aRow[m_listHandler->FEncColModel->FEncTypeName] = "Keine";
	aRow[m_listHandler->FEncColModel->FEncTypeData] = lrc::NoneEncryption;
#ifndef NO_ENCRYPTION
	aRow = *(m_listEncTypes->append());
	aRow[m_listHandler->FEncColModel->FEncTypeName] = "Serpent";
	aRow[m_listHandler->FEncColModel->FEncTypeData] = lrc::SerpentEncryption;
#endif

	m_refBuilder->get_widget("resTreeView", resFileView);
	resFileView->set_model(m_listResFiles);

	resFileView->append_column_editable("Resource ID", m_resColModel->FUniqueResID);
	resFileView->append_column("Dateiname", m_resColModel->FResFilename);
	//resFileView->append_column("Komprimierung", m_resColModel->FCompressTypeName);
	compCol = Gtk::manage(new Gtk::TreeView::Column("Komprimierung"));
	compRenderer = Gtk::manage(new Gtk::CellRendererCombo);
	compCol->pack_start(*compRenderer);
	resFileView->append_column(*compCol);
#ifdef GLIBMM_PROPERTIES_ENABLED
	compCol->add_attribute(compRenderer->property_text(), m_resColModel->FCompressTypeName);
#else
	compCol->add_ttribute(*compRenderer, "Keine", m_resColModel->FCompressTypeName);
#endif /* GLIBMM_PROPERTIES_ENABLED */

#ifndef NO_ENCRYPTION
	//resFileView->append_column("Verschlüsselung", m_resColModel->FEncryptTypeName);
	encCol = Gtk::manage(new Gtk::TreeView::Column("Verschlüsselung"));
	encRenderer = Gtk::manage(new Gtk::CellRendererCombo);
	encCol->pack_start(*encRenderer);
	resFileView->append_column(*encCol);
#ifdef GLIBMM_PROPERTIES_ENABLED
	encCol->add_attribute(encRenderer->property_text(), m_resColModel->FEncryptTypeName);
#else
	encCol->add_ttribute(*encRenderer, "Keine", m_resColModel->FEncryptTypeName);
#endif /* GLIBMM_PROPERTIES_ENABLED */
	resFileView->append_column_editable("Passwort", m_resColModel->FEncPassword);
#endif /* NO_ENCRYPTION */
}

MainWindow::~MainWindow()
{
	delete m_listHandler;
	delete m_resColModel;
	delete m_addRemove;

	//m_refBuilder = nullptr;
	m_mainWindow = nullptr;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.