Commits

Andreas Tscharner  committed 44d4321

gui: Make sure the edit dialog is pre-filled with the correct values

  • Participants
  • Parent commits 705a879

Comments (0)

Files changed (5)

File src/gui/ButtonHandlers.cxx

 #include "../include/EncryptDecrypt.hxx"
 
 
+void ButtonHandlers::setupEditDialog(Gtk::TreeModel::Row p_row)
+{
+	Gtk::Entry *edResID;
+	Gtk::Entry *edResFilename;
+	Gtk::Entry *edResPassword;
+	Glib::ustring compTypeName;
+	Glib::ustring encTypeName;
+
+
+	if (!m_editDialog) {
+		return;
+	};
+
+	m_refBuilder->get_widget("edID", edResID);
+	edResID->set_text(p_row[m_resColModel->FUniqueResID]);
+
+	m_refBuilder->get_widget("edFilename", edResFilename);
+	edResFilename->set_text(p_row[m_resColModel->FResFilename]);
+
+	compTypeName = p_row[m_resColModel->FCompressTypeName];
+	m_compSelect->set_active(this->compNameToIndex(compTypeName.c_str()));
+
+	encTypeName = p_row[m_resColModel->FEncryptTypeName];
+	m_encSelect->set_active(this->encNameToIndex(encTypeName.c_str()));
+
+	m_refBuilder->get_widget("edPassword", edResPassword);
+	edResPassword->set_text(p_row[m_resColModel->FEncPassword]);
+}
+
+inline int ButtonHandlers::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 ButtonHandlers::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 ButtonHandlers::on_add_button_clicked(void)
 {
 	int dlgRet;
 void ButtonHandlers::on_edit_button_clicked(void)
 {
 	int dlgRet;
+	Gtk::TreeView *resFileView;
+	Glib::RefPtr<Gtk::TreeSelection> selectedRes;
+	std::vector<Gtk::TreeModel::Path> selectedRows;
+	Gtk::TreeModel::Row currentRow;
 
 
-	dlgRet = m_editDialog->run();
-	m_editDialog->hide();
+	m_refBuilder->get_widget("resTreeView", resFileView);
+	selectedRes = resFileView->get_selection();
+	if (!selectedRes) {
+		return;
+	};
+
+	selectedRows = selectedRes->get_selected_rows();
+
+	for (auto eachPath : selectedRows) {
+		currentRow = m_listHandler->getResourceEntry(eachPath);
+		this->setupEditDialog(currentRow);
+		dlgRet = m_editDialog->run();
+		m_editDialog->hide();
+	};
 }
 
-ButtonHandlers::ButtonHandlers(Glib::RefPtr<Gtk::Builder> p_refBuilder)
+ButtonHandlers::ButtonHandlers(Glib::RefPtr<Gtk::Builder> p_refBuilder, ResColumnModel *p_resColModel)
 {
 	Gtk::Window *mainWin;
 	Glib::RefPtr<Gtk::FileFilter> anyFile = Gtk::FileFilter::create();
 
 
 	m_refBuilder = p_refBuilder;
+	m_resColModel = p_resColModel;
 
 	p_refBuilder->get_widget("bnAdd", m_addButton);
 	m_addButton->signal_clicked().connect(sigc::mem_fun(*this,
 	m_addFilesDlg->set_create_folders(false);
 	m_addFilesDlg->add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
 	m_addFilesDlg->add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_OK);
-	anyFile->set_name("Any file");
+	anyFile->set_name("Alle Dateien");
 	anyFile->add_pattern("*");
 	m_addFilesDlg->add_filter(anyFile);
 

File src/gui/ButtonHandlers.hxx

  * on the main window
  *
  * \author Andreas Tscharner
- * \date 2013-03-09
+ * \date 2013-03-10
  */
 
 
 #include <gtkmm/dialog.h>
 #include <gtkmm/comboboxtext.h>
 #include "ListHandler.hxx"
+#include "ResColumnModel.hxx"
 
 
 /*! \class ButtonHandlers
 		Gtk::ComboBoxText *m_compSelect;    //!< Reference to compression combobox
 		Gtk::ComboBoxText *m_encSelect;     //!< Reference to encryption combobox
 		ListHandler *m_listHandler;    //!< Reference to (global) list handler class
+		ResColumnModel *m_resColModel; //!< Reference to instance of column model
+
+		/*! \brief Fill values from row into dialog
+		 *
+		 * This method is used to fill the given values into the edit dialog
+		 *
+		 * \param[in] p_row Row containing the values
+		 */
+		void setupEditDialog(Gtk::TreeModel::Row);
+
+		/*! \brief Get integer index from compression name
+		 *
+		 * This method returns the index of the given compression name
+		 * within the static array of all compression names
+		 *
+		 * \param[in] p_compName Compression name
+		 *
+		 * \return Index within array
+		 */
+		inline int compNameToIndex(const char *);
+		/*! \brief Get integer index from encryption name
+		 *
+		 * This method returns the index of the given encryption name within
+		 * the static array of all encryption names
+		 *
+		 * \param[in] p_encName Encryption name
+		 *
+		 * \return Index within array
+		 */
+		inline int encNameToIndex(const char *);
 
 	protected:
 		/*! \brief Signal handler for "Add" button
 		 *
 		 * \param[in] p_refBuilder Reference to the builder that loaded the
 		 *                         glade GUI file
+		 * \param[in] p_resColModel Reference to instance of column model
 		 */
-		ButtonHandlers(Glib::RefPtr<Gtk::Builder>);
+		ButtonHandlers(Glib::RefPtr<Gtk::Builder>, ResColumnModel *);
 		/*! \brief Destructor
 		 *
 		 * Frees all the used memory

File src/gui/ListHandler.cxx

 
 	return NO_ERROR;
 }
+
+Gtk::TreeModel::Row ListHandler::getResourceEntry(Gtk::TreeModel::Path p_treemodelPath)
+{
+	Gtk::TreeModel::iterator iter;
+
+
+	iter = m_listResEntries->get_iter(p_treemodelPath);
+	return *iter;
+}

File src/gui/ListHandler.hxx

  * removing new entries
  *
  * \author Andreas Tscharner
- * \date 2013-03-09
+ * \date 2013-03-10
  */
 
 
 		 * \retval NO_ERROR Resource successfully removed
 		 */
 		int removeSelected(Glib::RefPtr<Gtk::TreeSelection>);
+
+		/*! \brief Return desired resource entry
+		 *
+		 * This method returns the desired resource entry from the list
+		 *
+		 * \param[in] p_treemodelPath Path to entry within the tree model
+		 *
+		 * \return Resource entry as row of the tree model
+		 */
+		Gtk::TreeModel::Row getResourceEntry(Gtk::TreeModel::Path);
 };
 
 

File src/gui/MainWindow.cxx

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