glom r1611 - in trunk: . glom
- From: arminb svn gnome org
- To: svn-commits-list gnome org
- Subject: glom r1611 - in trunk: . glom
- Date: Fri, 16 May 2008 19:12:53 +0100 (BST)
Author: arminb
Date: Fri May 16 18:12:53 2008
New Revision: 1611
URL: http://svn.gnome.org/viewvc/glom?rev=1611&view=rev
Log:
2008-05-15 Armin Burgmeier <armin openismus com>
* glom/dialog_import_csv.h:
* glom/dialog_import_csv.cc: Added some more encodings, differentiate
between encoding name and charset.
* glom/application.cc (init_menus_file), (init_menus): Moved the
Import menu item from Tables to File menu.
* glom/frame_glom.h:
* glom/frame_glom.cc: Renamed the function from
on_menu_Tables_ImportIntoTable() to on_menu_file_import().
Modified:
trunk/ChangeLog
trunk/glom/application.cc
trunk/glom/dialog_import_csv.cc
trunk/glom/dialog_import_csv.h
trunk/glom/frame_glom.cc
trunk/glom/frame_glom.h
Modified: trunk/glom/application.cc
==============================================================================
--- trunk/glom/application.cc (original)
+++ trunk/glom/application.cc Fri May 16 18:12:53 2008
@@ -301,6 +301,9 @@
sigc::mem_fun(*m_pFrame, &Frame_Glom::on_menu_file_export));
#endif // !GLOM_ENABLE_CLIENT_ONLY
+ action = Gtk::Action::create("BakeryAction_Menu_File_Import", _("Import"));
+ m_refFileActionGroup->add(action, sigc::mem_fun(*m_pFrame, &Frame_Glom::on_menu_file_import));
+
m_refFileActionGroup->add(Gtk::Action::create("GlomAction_Menu_File_Print", Gtk::Stock::PRINT));
m_refFileActionGroup->add(Gtk::Action::create("GlomAction_File_Print", _("_Standard")),
sigc::mem_fun(*m_pFrame, &Frame_Glom::on_menu_file_print) );
@@ -336,6 +339,7 @@
" <menuitem action='BakeryAction_File_SaveAsExample' />"
" <menuitem action='BakeryAction_Menu_File_Export' />"
#endif // !GLOM_ENABLE_CLIENT_ONLY
+ " <menuitem action='BakeryAction_Menu_File_Import' />"
" <separator/>"
" <menu action='GlomAction_Menu_File_Print'>"
" <menuitem action='GlomAction_File_Print' />"
@@ -392,9 +396,6 @@
m_listDeveloperActions.push_back(action);
#endif // !GLOM_ENABLE_CLIENT_ONLY
- action = Gtk::Action::create("GlomAction_Menu_ImportIntoTable", _("Import _Into Table"));
- m_refActionGroup_Others->add(action, sigc::mem_fun(*m_pFrame, &Frame_Glom::on_menu_Tables_ImportIntoTable));
-
//"Reports" menu:
m_refActionGroup_Others->add( Gtk::Action::create("Glom_Menu_Reports", _("_Reports")) );
@@ -503,7 +504,6 @@
" <menuitem action='GlomAction_Menu_EditTables' />"
" <menuitem action='GlomAction_Menu_AddRelatedTable' />"
#endif // !GLOM_ENABLE_CLIENT_ONLY
- " <menuitem action='GlomAction_Menu_ImportIntoTable' />"
" </menu>"
" <menu action='Glom_Menu_Reports'>"
" <placeholder name='Menu_Reports_Dynamic' />"
Modified: trunk/glom/dialog_import_csv.cc
==============================================================================
--- trunk/glom/dialog_import_csv.cc (original)
+++ trunk/glom/dialog_import_csv.cc Fri May 16 18:12:53 2008
@@ -158,18 +158,69 @@
return walk;
}
+struct Encoding {
+ const char* name;
+ const char* charset;
+};
+
+const Encoding ENCODINGS[] = {
+ { N_("Unicode"), "UTF-8" },
+ { N_("Unicode"), "UTF-16" },
+ { N_("Unicode"), "UTF-16BE" },
+ { N_("Unicode"), "UTF-16LE" },
+ { N_("Unicode"), "UTF-32" },
+ { N_("Unicode"), "UTF-7" },
+ { N_("Unicode"), "UCS-2" },
+ { N_("Unicode"), "UCS-4" },
+ { NULL, NULL }, // This just adds a separator in the combo box
+ { N_("Western"), "ISO-8859-1" },
+ { N_("Central European"), "ISO-8859-2" },
+ { N_("South European"), "ISO-8859-3" },
+ { N_("Baltic"), "ISO-8859-4" },
+ { N_("Cyrillic"), "ISO-8859-5" },
+ { N_("Arabic"), "ISO-8859-6" },
+ { N_("Greek"), "ISO-8859-7" },
+ { N_("Hebrew Visual"), "ISO-8859-8" },
+ { N_("Hebrew"), "ISO-8859-8-I" },
+ { N_("Turkish"), "ISO-8859-9" },
+ { N_("Nordic"), "ISO-8859-10" },
+ { N_("Baltic"), "ISO-8859-13" },
+ { N_("Celtic"), "ISO-8859-14" },
+ { N_("Western"), "ISO-8859-15" },
+ { N_("Romanian"), "ISO-8859-16" },
+ { NULL, NULL },
+ { N_("Central European"), "WINDOWS-1250" },
+ { N_("Cyrillic"), "WINDOWS-1251" },
+ { N_("Western"), "WINDOWS-1252" },
+ { N_("Greek"), "WINDOWS-1253" },
+ { N_("Turkish"), "WINDOWS-1254" },
+ { N_("Hebrew"), "WINDOWS-1255" },
+ { N_("Arabic"), "WINDOWS-1256" },
+ { N_("Baltic"), "WINDOWS-1257" },
+ { N_("Vietnamese"), "WINDOWS-1258" }
+};
+
// When auto-detecting the encoding, we try to read the file in these
// encodings, in order:
-const char* ENCODINGS[] = {
- "UTF-8",
- "ISO-8859-1",
- "ISO-8859-15",
- "UTF-16",
- "UCS-2",
- "UCS-4"
+const Encoding AUTODETECT_ENCODINGS[] = {
+ { N_("Unicode"), "UTF-8" },
+ { N_("Western"), "ISO-8859-1" },
+ { N_("Western"), "ISO-8859-15" },
+ { N_("Unicode"), "UTF-16" },
+ { N_("Unicode"), "UCS-2" },
+ { N_("Unicode"), "UCS-4" }
};
const unsigned int N_ENCODINGS = sizeof(ENCODINGS)/sizeof(ENCODINGS[0]);
+const unsigned int N_AUTODETECT_ENCODINGS = sizeof(AUTODETECT_ENCODINGS)/sizeof(AUTODETECT_ENCODINGS[0]);
+
+Glib::ustring encoding_display(const Glib::ustring& name, const Glib::ustring& charset)
+{
+ if(charset.empty())
+ return name;
+ else
+ return name + " (" + charset + ")";
+}
}
@@ -192,7 +243,7 @@
m_encoding_model = Gtk::ListStore::create(m_encoding_columns);
Gtk::TreeIter iter = m_encoding_model->append();
- (*iter)[m_encoding_columns.m_col_encoding] = _("Auto Detect");
+ (*iter)[m_encoding_columns.m_col_name] = _("Auto Detect");
// Separator:
m_encoding_model->append();
@@ -200,13 +251,17 @@
for(unsigned int i = 0; i < N_ENCODINGS; ++ i)
{
iter = m_encoding_model->append();
- (*iter)[m_encoding_columns.m_col_encoding] = ENCODINGS[i];
+ if(ENCODINGS[i].name != NULL)
+ {
+ (*iter)[m_encoding_columns.m_col_name] = gettext(ENCODINGS[i].name);
+ (*iter)[m_encoding_columns.m_col_charset] = ENCODINGS[i].charset;
+ }
}
Gtk::CellRendererText* renderer = Gtk::manage(new Gtk::CellRendererText);
m_encoding_combo->set_model(m_encoding_model);
m_encoding_combo->pack_start(*renderer);
- m_encoding_combo->add_attribute(renderer->property_text(), m_encoding_columns.m_col_encoding);
+ m_encoding_combo->set_cell_data_func(*renderer, sigc::bind(sigc::mem_fun(*this, &Dialog_Import_CSV::encoding_data_func), sigc::ref(*renderer)));
m_encoding_combo->set_row_separator_func(sigc::mem_fun(*this, &Dialog_Import_CSV::row_separator_func));
m_encoding_combo->set_active(0);
m_encoding_combo->signal_changed().connect(sigc::mem_fun(*this, &Dialog_Import_CSV::on_encoding_changed));
@@ -325,9 +380,17 @@
dialog.run();
}
+void Dialog_Import_CSV::encoding_data_func(const Gtk::TreeIter& iter, Gtk::CellRendererText& renderer)
+{
+ Glib::ustring name = (*iter)[m_encoding_columns.m_col_name];
+ Glib::ustring charset = (*iter)[m_encoding_columns.m_col_charset];
+
+ renderer.set_property("text", encoding_display(name, charset));
+}
+
bool Dialog_Import_CSV::row_separator_func(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeIter& iter) const
{
- return (*iter)[m_encoding_columns.m_col_encoding] == "";
+ return (*iter)[m_encoding_columns.m_col_name] == "";
}
void Dialog_Import_CSV::on_query_info(const Glib::RefPtr<Gio::AsyncResult>& result)
@@ -409,7 +472,6 @@
switch(active)
{
case -1: // No active item
- case 1: // Separator
g_assert_not_reached();
break;
case 0: // Auto-Detect
@@ -518,29 +580,25 @@
}
}
-const char* Dialog_Import_CSV::get_current_encoding() const
+Glib::ustring Dialog_Import_CSV::get_current_encoding() const
{
- int active = m_encoding_combo->get_active_row_number();
- switch(active)
+ Gtk::TreeIter iter = m_encoding_combo->get_active();
+ Glib::ustring encoding = (*iter)[m_encoding_columns.m_col_charset];
+
+ if(encoding.empty())
{
- case -1: // No active item
- case 1: // Separator
- g_assert_not_reached();
- break;
- case 0: // Auto-Detect
+ // Auto-Detect
g_assert(m_auto_detect_encoding != -1);
- return ENCODINGS[m_auto_detect_encoding];
- default: // Some specific encoding
- g_assert(active >= 2);
- g_assert(static_cast<unsigned int>(active - 2) < N_ENCODINGS);
- return ENCODINGS[active - 2];
+ return AUTODETECT_ENCODINGS[m_auto_detect_encoding].charset;
}
+
+ return encoding.c_str();
}
void Dialog_Import_CSV::begin_parse()
{
if(m_auto_detect_encoding != -1)
- m_encoding_info->set_text(Glib::ustring::compose(_("Encoding detected as: %1"), Glib::ustring(get_current_encoding())));
+ m_encoding_info->set_text(Glib::ustring::compose(_("Encoding detected as: %1"), encoding_display(gettext(AUTODETECT_ENCODINGS[m_auto_detect_encoding].name), AUTODETECT_ENCODINGS[m_auto_detect_encoding].charset)));
else
m_encoding_info->set_text("");
@@ -551,7 +609,7 @@
m_sample_view->set_model(m_sample_model); // Empty model
m_rows.clear();
- m_parser.reset(new Parser(get_current_encoding()));
+ m_parser.reset(new Parser(get_current_encoding().c_str()));
set_state(PARSING);
// Allow the Import button to be pressed when a field for the primary key
@@ -581,7 +639,7 @@
if(m_auto_detect_encoding != -1)
{
++ m_auto_detect_encoding;
- if(static_cast<unsigned int>(m_auto_detect_encoding) < N_ENCODINGS)
+ if(static_cast<unsigned int>(m_auto_detect_encoding) < N_AUTODETECT_ENCODINGS)
begin_parse();
else
m_encoding_info->set_text(_("Encoding detection failed. Please manually choose one from the box to the left."));
Modified: trunk/glom/dialog_import_csv.h
==============================================================================
--- trunk/glom/dialog_import_csv.h (original)
+++ trunk/glom/dialog_import_csv.h Fri May 16 18:12:53 2008
@@ -71,6 +71,7 @@
void clear();
void show_error_dialog(const Glib::ustring& primary, const Glib::ustring& secondary);
+ void encoding_data_func(const Gtk::TreeIter& iter, Gtk::CellRendererText& renderer);
bool row_separator_func(const Glib::RefPtr<Gtk::TreeModel>& model, const Gtk::TreeIter& iter) const;
void on_query_info(const Glib::RefPtr<Gio::AsyncResult>& result);
@@ -81,7 +82,7 @@
void on_first_line_as_title_toggled();
void on_sample_rows_changed();
- const char* get_current_encoding() const;
+ Glib::ustring get_current_encoding() const;
void begin_parse();
void encoding_error();
@@ -98,9 +99,10 @@
class EncodingColumns: public Gtk::TreeModelColumnRecord
{
public:
- EncodingColumns() { add(m_col_encoding); }
+ EncodingColumns() { add(m_col_name); add(m_col_charset); }
- Gtk::TreeModelColumn<Glib::ustring> m_col_encoding;
+ Gtk::TreeModelColumn<Glib::ustring> m_col_name;
+ Gtk::TreeModelColumn<Glib::ustring> m_col_charset;
};
class FieldColumns: public Gtk::TreeModelColumnRecord
Modified: trunk/glom/frame_glom.cc
==============================================================================
--- trunk/glom/frame_glom.cc (original)
+++ trunk/glom/frame_glom.cc Fri May 16 18:12:53 2008
@@ -662,6 +662,59 @@
}
#endif // !GLOM_ENABLE_CLIENT_ONLY
+void Frame_Glom::on_menu_file_import()
+{
+ if(m_table_name.empty())
+ {
+ Gtk::MessageDialog dialog(*get_app_window(), "There is no table to import data into", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);
+ dialog.run();
+ }
+ else
+ {
+ Gtk::FileChooserDialog file_chooser(*get_app_window(), _("Choose a CSV file to open"), Gtk::FILE_CHOOSER_ACTION_OPEN);
+ file_chooser.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
+ file_chooser.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
+
+ if(file_chooser.run() == Gtk::RESPONSE_ACCEPT)
+ {
+ Dialog_Import_CSV* dialog = 0;
+ Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(Utils::get_glade_file_path("glom.glade"), "dialog_import_csv");
+ refXml->get_widget_derived("dialog_import_csv", dialog);
+ add_view(dialog);
+
+ file_chooser.hide();
+
+ dialog->import(file_chooser.get_uri(), m_table_name);
+ while(Glom::Utils::dialog_run_with_help(dialog, "dialog_import_csv") == Gtk::RESPONSE_ACCEPT)
+ {
+ dialog->hide();
+ Dialog_Import_CSV_Progress* progress_dialog = 0;
+ Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(Utils::get_glade_file_path("glom.glade"), "dialog_import_csv_progress");
+ refXml->get_widget_derived("dialog_import_csv_progress", progress_dialog);
+ add_view(progress_dialog);
+
+ progress_dialog->init_db_details(dialog->get_target_table_name());
+ progress_dialog->import(*dialog);
+ const int response = progress_dialog->run();
+
+ remove_view(progress_dialog);
+ delete progress_dialog;
+
+ // Force update from database so the newly added entries are shown
+ show_table_refresh();
+
+ // Re-show chooser dialog when an error occured or when the user
+ // cancelled.
+ if(response == Gtk::RESPONSE_OK)
+ break;
+ }
+
+ remove_view(dialog);
+ delete dialog;
+ }
+ }
+}
+
void Frame_Glom::on_menu_file_print()
{
Notebook_Glom* notebook_current = dynamic_cast<Notebook_Glom*>(m_pBox_Mode->get_child());
@@ -769,59 +822,6 @@
#endif
-void Frame_Glom::on_menu_Tables_ImportIntoTable()
-{
- if(m_table_name.empty())
- {
- Gtk::MessageDialog dialog(*get_app_window(), "There is no table to import data into", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK);
- dialog.run();
- }
- else
- {
- Gtk::FileChooserDialog file_chooser(*get_app_window(), _("Choose a CSV file to open"), Gtk::FILE_CHOOSER_ACTION_OPEN);
- file_chooser.add_button(Gtk::Stock::CANCEL, Gtk::RESPONSE_CANCEL);
- file_chooser.add_button(Gtk::Stock::OPEN, Gtk::RESPONSE_ACCEPT);
-
- if(file_chooser.run() == Gtk::RESPONSE_ACCEPT)
- {
- Dialog_Import_CSV* dialog = 0;
- Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(Utils::get_glade_file_path("glom.glade"), "dialog_import_csv");
- refXml->get_widget_derived("dialog_import_csv", dialog);
- add_view(dialog);
-
- file_chooser.hide();
-
- dialog->import(file_chooser.get_uri(), m_table_name);
- while(Glom::Utils::dialog_run_with_help(dialog, "dialog_import_csv") == Gtk::RESPONSE_ACCEPT)
- {
- dialog->hide();
- Dialog_Import_CSV_Progress* progress_dialog = 0;
- Glib::RefPtr<Gnome::Glade::Xml> refXml = Gnome::Glade::Xml::create(Utils::get_glade_file_path("glom.glade"), "dialog_import_csv_progress");
- refXml->get_widget_derived("dialog_import_csv_progress", progress_dialog);
- add_view(progress_dialog);
-
- progress_dialog->init_db_details(dialog->get_target_table_name());
- progress_dialog->import(*dialog);
- const int response = progress_dialog->run();
-
- remove_view(progress_dialog);
- delete progress_dialog;
-
- // Force update from database so the newly added entries are shown
- show_table_refresh();
-
- // Re-show chooser dialog when an error occured or when the user
- // cancelled.
- if(response == Gtk::RESPONSE_OK)
- break;
- }
-
- remove_view(dialog);
- delete dialog;
- }
- }
-}
-
#ifndef GLOM_ENABLE_CLIENT_ONLY
void Frame_Glom::on_dialog_add_related_table_response(int response)
Modified: trunk/glom/frame_glom.h
==============================================================================
--- trunk/glom/frame_glom.h (original)
+++ trunk/glom/frame_glom.h Fri May 16 18:12:53 2008
@@ -75,6 +75,7 @@
void on_menu_userlevel_Operator(const Glib::RefPtr<Gtk::RadioAction>& action);
void on_menu_file_export();
+ void on_menu_file_import();
void on_menu_file_print_edit_layouts();
#endif // !GLOM_ENABLE_CLIENT_ONLY
@@ -98,7 +99,6 @@
void on_menu_Tables_EditTables();
void on_menu_Tables_AddRelatedTable();
#endif // !GLOM_ENABLE_CLIENT_ONLY
- void on_menu_Tables_ImportIntoTable();
#ifndef GLOM_ENABLE_CLIENT_ONLY
void on_menu_Reports_EditReports();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]