Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/lintest/myrulib.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKandrashin Denis <mail@lintest.ru>2012-10-11 22:08:26 +0400
committerKandrashin Denis <mail@lintest.ru>2012-10-11 22:08:26 +0400
commit34d2b262a81e1041487859fa5f33cd02112cf6fb (patch)
tree713f2e6b4902427fe80059cb7a8ab7a1fb1ad274
parent07c38f2852f9f0b0c008c6e900b5eb482687e7df (diff)
Modify export dialog: transliterate
-rw-r--r--sources/MyRuLib/dialogs/FbExportDlg.cpp42
-rw-r--r--sources/MyRuLib/dialogs/FbExportDlg.h9
-rw-r--r--sources/MyRuLib/models/FbExportTree.cpp30
-rw-r--r--sources/MyRuLib/models/FbExportTree.h26
4 files changed, 72 insertions, 35 deletions
diff --git a/sources/MyRuLib/dialogs/FbExportDlg.cpp b/sources/MyRuLib/dialogs/FbExportDlg.cpp
index 88e56bb7..88330170 100644
--- a/sources/MyRuLib/dialogs/FbExportDlg.cpp
+++ b/sources/MyRuLib/dialogs/FbExportDlg.cpp
@@ -1,4 +1,5 @@
#include <wx/filename.h>
+#include <wx/filename.h>
#include <wx/artprov.h>
#include <wx/arrimpl.cpp>
#include "FbExportDlg.h"
@@ -15,6 +16,8 @@ BEGIN_EVENT_TABLE( FbExportDlg, wxDialog )
EVT_BUTTON( ID_DIR_TXT, FbExportDlg::OnSelectDir )
EVT_CHOICE( wxID_ANY, FbExportDlg::OnChangeFormat )
EVT_CHECKBOX( ID_AUTHOR, FbExportDlg::OnCheckAuthor )
+ EVT_CHECKBOX( ID_DIR, FbExportDlg::OnChangeFormat )
+ EVT_CHECKBOX( ID_FILE, FbExportDlg::OnChangeFormat )
EVT_TEXT( ID_STRUCT, FbExportDlg::OnCheckAuthor )
END_EVENT_TABLE()
@@ -60,10 +63,10 @@ FbExportDlg::FbExportDlg( wxWindow* parent, const wxString & selections, int iAu
wxBoxSizer * bSizerTrans = new wxBoxSizer( wxHORIZONTAL );
- m_transFold = new wxCheckBox( this, wxID_ANY, _("Transliterate folder name"));
- bSizerTrans->Add( m_transFold, 1, wxALL|wxEXPAND, 5 );
+ m_transDir = new wxCheckBox( this, ID_DIR, _("Transliterate folder name"));
+ bSizerTrans->Add( m_transDir, 1, wxALL|wxEXPAND, 5 );
- m_transFile = new wxCheckBox( this, wxID_ANY, _("Transliterate filename"));
+ m_transFile = new wxCheckBox( this, ID_FILE, _("Transliterate filename"));
bSizerTrans->Add( m_transFile, 1, wxALL|wxEXPAND, 5 );
bSizerMain->Add( bSizerTrans, 0, wxEXPAND, 5 );
@@ -78,7 +81,6 @@ FbExportDlg::FbExportDlg( wxWindow* parent, const wxString & selections, int iAu
m_books->SetMinSize( wxSize( -1,250 ) );
m_books->AddColumn (0, _("File name"), -10, wxALIGN_LEFT);
m_books->AddColumn (1, _("Size, Kb"), 6, wxALIGN_RIGHT);
- m_books->AssignModel(new FbExportTreeModel(m_selections, structure, m_author));
bSizerMain->Add( m_books, 1, wxALL|wxEXPAND, 5 );
@@ -95,7 +97,7 @@ FbExportDlg::FbExportDlg( wxWindow* parent, const wxString & selections, int iAu
bSizerMain->Add( bSizerFormat, 0, wxEXPAND, 5 );
m_folder->SetValue( FbParamItem::GetPath(FB_EXTERNAL_DIR) );
- m_transFold->SetValue( FbParams(FB_TRANSLIT_FOLDER) );
+ m_transDir->SetValue( FbParams(FB_TRANSLIT_FOLDER) );
m_transFile->SetValue( FbParams(FB_TRANSLIT_FILE) );
wxStdDialogButtonSizer * sdbSizerBtn = CreateStdDialogButtonSizer( wxOK | wxCANCEL );
@@ -109,6 +111,8 @@ FbExportDlg::FbExportDlg( wxWindow* parent, const wxString & selections, int iAu
SetEscapeId(wxID_CANCEL);
LoadFormats();
+
+ m_books->AssignModel(CreateModel());
}
FbExportDlg::~FbExportDlg()
@@ -142,7 +146,6 @@ void FbExportDlg::LoadFormats()
int index = m_format->Append(name, code);
if (code == format) m_format->SetSelection(index);
}
- ChangeFormat();
}
wxString FbExportDlg::GetExt(int format)
@@ -167,14 +170,15 @@ void FbExportDlg::OnSelectDir( wxCommandEvent& event )
void FbExportDlg::OnChangeFormat( wxCommandEvent& event )
{
- ChangeFormat();
+ if (FbExportTreeModel * model = wxDynamicCast(m_books->GetModel(), FbExportTreeModel)) {
+ ChangeFormat(model);
+ model->Create();
+ m_books->Refresh();
+ }
}
-void FbExportDlg::ChangeFormat()
+void FbExportDlg::ChangeFormat(FbExportTreeModel * model)
{
- FbExportTreeModel * model = wxDynamicCast(m_books->GetModel(), FbExportTreeModel);
- if (!model) return;
-
int format = m_format->GetValue();
int scale = format < 0 ? 43 : 100;
wxString arc, ext;
@@ -183,9 +187,9 @@ void FbExportDlg::ChangeFormat()
case -2: arc = wxT("gz"); break;
case -3: arc = wxT("bz2"); break;
}
-
model->SetFormat(GetExt(format), arc, scale);
- m_books->Refresh();
+ model->SetTransDir(m_transDir->GetValue());
+ model->SetTransFile(m_transFile->GetValue());
}
bool FbExportDlg::ExportBooks()
@@ -229,9 +233,15 @@ bool FbExportDlg::Execute(wxWindow* parent, FbBookPanel * books, int iAuthor)
void FbExportDlg::OnCheckAuthor( wxCommandEvent& event )
{
+ m_books->AssignModel(CreateModel());
+}
+
+FbModel * FbExportDlg::CreateModel()
+{
int author = 0;
if ( m_checkAuthor && m_checkAuthor->GetValue() ) author = m_author;
- m_books->AssignModel(new FbExportTreeModel(m_selections, m_struct->GetValue(), author));
- ChangeFormat();
+ FbExportTreeModel * model = new FbExportTreeModel(m_selections, m_struct->GetValue(), author);
+ ChangeFormat(model);
+ model->Create();
+ return model;
}
-
diff --git a/sources/MyRuLib/dialogs/FbExportDlg.h b/sources/MyRuLib/dialogs/FbExportDlg.h
index 96e9a5c4..f620bd15 100644
--- a/sources/MyRuLib/dialogs/FbExportDlg.h
+++ b/sources/MyRuLib/dialogs/FbExportDlg.h
@@ -29,6 +29,8 @@ class FbBookPanel;
class FbConvertArray;
+class FbExportTreeModel;
+
///////////////////////////////////////////////////////////////////////////////
/// Class FbExportDlg
///////////////////////////////////////////////////////////////////////////////
@@ -39,14 +41,15 @@ class FbExportDlg : public FbDialog
~FbExportDlg();
static bool Execute(wxWindow* parent, FbBookPanel * books, int iAuthor = 0);
private:
+ FbModel * CreateModel();
void FullBySequences(wxTreeItemId root, const wxString &selections, bool bUseLetter);
void FullNoSequences(wxTreeItemId root, const wxString &selections, bool bUseLetter);
wxTreeItemId AppendFolder(const wxTreeItemId &parent, const wxString & name);
void ChangeFilesExt(const wxTreeItemId &parent);
void FillFilelist(const wxTreeItemId &parent, FbConvertArray &filelist, const wxString &dir = wxEmptyString);
+ void ChangeFormat(FbExportTreeModel * model);
bool ExportBooks();
void LoadFormats();
- void ChangeFormat();
wxString GetExt(int format);
private:
wxString m_selections;
@@ -61,13 +64,15 @@ class FbExportDlg : public FbDialog
ID_BOOKS,
ID_FORMAT,
ID_AUTHOR,
+ ID_DIR,
+ ID_FILE,
};
FbCustomCombo * m_folder;
wxComboBox * m_struct;
FbTreeViewCtrl * m_books;
FbChoiceInt * m_format;
wxCheckBox * m_checkAuthor;
- wxCheckBox * m_transFold;
+ wxCheckBox * m_transDir;
wxCheckBox * m_transFile;
private:
void OnSelectDir( wxCommandEvent& event );
diff --git a/sources/MyRuLib/models/FbExportTree.cpp b/sources/MyRuLib/models/FbExportTree.cpp
index 95af676c..6467c58f 100644
--- a/sources/MyRuLib/models/FbExportTree.cpp
+++ b/sources/MyRuLib/models/FbExportTree.cpp
@@ -163,12 +163,12 @@ wxFileName FbExportChildData::GetPath(FbModel &model) const
//-----------------------------------------------------------------------------
// FbExportTreeContext
//-----------------------------------------------------------------------------
-
-FbExportTreeContext::FbExportTreeContext(const wxString &structure)
+
+FbExportTreeContext::FbExportTreeContext(FbExportTreeModel * model)
{
- m_template = structure;
- m_translit_folder = FbParams(FB_TRANSLIT_FOLDER);
- m_translit_file = FbParams(FB_TRANSLIT_FILE);
+ m_template = model->GetStructure();
+ m_translit_folder = model->GetTransDir();
+ m_translit_file = model->GetTransFile();;
m_underscores = FbParams(FB_USE_UNDERSCORE);
m_digits_count = FbParams(FB_NUMBER_FORMAT);
if (m_digits_count < 1) m_digits_count = 1;
@@ -193,7 +193,9 @@ wxString FbExportTreeContext::Normalize(const wxString &filename, bool translit)
if (ch == (wxChar)0x0401) ch = (wxChar)0x0415;
if (ch == (wxChar)0x0451) ch = (wxChar)0x0435;
if (!IsAlphaNumeric(ch)) ch = 0x20;
+ bool skip = space && ch == 0x20;
space = ch == 0x20;
+ if (skip) continue;
if (m_underscores && space) ch = (wxChar)0x5F;
newname << ch;
}
@@ -348,7 +350,17 @@ wxFileName FbExportTreeContext::GetFilename(wxSQLite3ResultSet &result)
IMPLEMENT_CLASS(FbExportTreeModel, FbTreeModel)
-FbExportTreeModel::FbExportTreeModel(const wxString &books, const wxString &structure, int author): m_scale(0)
+FbExportTreeModel::FbExportTreeModel(const wxString &books, const wxString &structure, int author)
+ : m_structure(structure)
+ , m_transDir(false)
+ , m_transFile(false)
+ , m_books(books)
+ , m_author(author)
+ , m_scale(0)
+{
+}
+
+void FbExportTreeModel::Create()
{
FbExportParentData * root = new FbExportParentData(*this, NULL, wxT('.'));
SetRoot(root);
@@ -366,10 +378,10 @@ FbExportTreeModel::FbExportTreeModel(const wxString &books, const wxString &stru
");
wxString filter;
- if ( author) filter = wxString::Format(wxT("AND (books.id_author=%d)"), author);
- sql = wxString::Format(sql, books.c_str(), filter.c_str());
+ if ( m_author) filter = wxString::Format(wxT("AND (books.id_author=%d)"), m_author);
+ sql = wxString::Format(sql, m_books.c_str(), filter.c_str());
- FbExportTreeContext context(structure);
+ FbExportTreeContext context(this);
FbSortedArrayInt items(FbArrayEvent::CompareInt);
FbCommonDatabase database;
diff --git a/sources/MyRuLib/models/FbExportTree.h b/sources/MyRuLib/models/FbExportTree.h
index ba919e85..ad544e4f 100644
--- a/sources/MyRuLib/models/FbExportTree.h
+++ b/sources/MyRuLib/models/FbExportTree.h
@@ -7,6 +7,8 @@
class FbConvertArray;
+class FbExportTreeModel;
+
class FbExportParentData: public FbParentData
{
public:
@@ -44,7 +46,7 @@ class FbExportChildData: public FbChildData
class FbExportTreeContext
{
public:
- FbExportTreeContext(const wxString &structure);
+ FbExportTreeContext(FbExportTreeModel * model);
wxFileName GetFilename(wxSQLite3ResultSet &result);
private:
wxString Get(wxSQLite3ResultSet &result, const wxString &field);
@@ -64,16 +66,24 @@ class FbExportTreeModel: public FbTreeModel
void GetFiles(FbConvertArray & files);
void SetFormat(const wxString & ext, const wxString & arc, int scale = 0)
{ m_ext = ext; m_arc = arc; m_scale = scale; }
- const wxString & GetExt() const
- { return m_ext; }
- const wxString & GetArc() const
- { return m_arc; }
- int GetScale() const
- { return m_scale; }
+ void SetTransDir(bool transDir) { m_transDir = transDir; }
+ void SetTransFile(bool transFile) { m_transFile = transFile; }
+ bool GetTransDir() const { return m_transDir; }
+ bool GetTransFile() const { return m_transFile; }
+ const wxString & GetStructure() const { return m_structure; }
+ const wxString & GetExt() const { return m_ext; }
+ const wxString & GetArc() const { return m_arc; }
+ int GetScale() const { return m_scale; }
+ void Create();
private:
+ wxString m_structure;
+ bool m_transDir;
+ bool m_transFile;
+ wxString m_books;
wxString m_ext;
wxString m_arc;
- int m_scale;
+ int m_author;
+ int m_scale;
DECLARE_CLASS(FbExportTreeModel)
};