From: <hug...@li...> - 2011-03-13 08:22:03
|
branch: details: http://hugin.hg.sourceforge.net/hgweb/hugin/hugin/hgrepo/h/hu/hugin/hugin/rev/5f15f569cdc8 changeset: 5103:5f15f569cdc8 user: tmodes date: Sun Mar 13 09:12:16 2011 +0100 description: Propose correct and valid filename for saving project and stitching [731217] diffstat: src/hugin1/hugin/MainFrame.cpp | 6 +- src/hugin1/hugin/PanoPanel.cpp | 50 +++++++++--------------- src/hugin1/hugin/huginApp.cpp | 12 +++--- src/hugin_base/hugin_utils/utils.cpp | 41 -------------------- src/hugin_base/hugin_utils/utils.h | 3 - 5 files changed, 28 insertions(+), 84 deletions(-) diffs (182 lines): diff -r 315050341fea -r 5f15f569cdc8 src/hugin1/hugin/MainFrame.cpp --- a/src/hugin1/hugin/MainFrame.cpp Sat Mar 12 11:35:13 2011 -0500 +++ b/src/hugin1/hugin/MainFrame.cpp Sun Mar 13 09:12:16 2011 +0100 @@ -652,13 +652,13 @@ void MainFrame::OnSaveProjectAs(wxCommandEvent & e) { DEBUG_TRACE(""); - wxString scriptName; + wxFileName scriptName; if (m_filename == wxT("")) { - scriptName = getDefaultProjectName(pano) + wxT(".pto"); + scriptName.Assign(getDefaultProjectName(pano) + wxT(".pto")); } wxFileDialog dlg(this, _("Save project file"), - wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")), scriptName, + scriptName.GetPath(), scriptName.GetFullName(), _("Project files (*.pto)|*.pto|All files (*)|*"), wxFD_SAVE, wxDefaultPosition); dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT(""))); diff -r 315050341fea -r 5f15f569cdc8 src/hugin1/hugin/PanoPanel.cpp --- a/src/hugin1/hugin/PanoPanel.cpp Sat Mar 12 11:35:13 2011 -0500 +++ b/src/hugin1/hugin/PanoPanel.cpp Sun Mar 13 09:12:16 2011 +0100 @@ -1032,48 +1032,36 @@ // Derive a default output prefix from the project filename if set, otherwise default project filename wxString ptofile = MainFrame::Get()->getProjectName(); - wxString outputPrefix; + wxFileName outputPrefix; if (ptofile == wxT("")) { - outputPrefix = getDefaultProjectName(*pano); + outputPrefix.Assign(getDefaultProjectName(*pano)); } else { - wxFileName prefixFN(ptofile); - if (prefixFN.GetExt() == wxT("pto")) { - prefixFN.ClearExt(); - outputPrefix = prefixFN.GetFullPath(); - } else { - outputPrefix = ptofile; - } + outputPrefix.Assign(ptofile); + if (outputPrefix.GetExt() == wxT("pto")) { + outputPrefix.ClearExt(); + }; } // Show a file save dialog so user can confirm/change the prefix. // (We don't have to worry about overwriting existing files, since hugin_switch_project checks this.) // TODO: The following code is similar to stitchApp::OnInit in hugin_switch_project.cpp. Should be refactored. // TODO: We should save the output prefix somewhere, so we can recall it as the default if the user stitches this project again. + wxFileDialog dlg(this,_("Specify output prefix"), + outputPrefix.GetPath(), outputPrefix.GetName(), wxT(""), + wxFD_SAVE, wxDefaultPosition); + if (dlg.ShowModal() != wxID_OK) { - wxFileDialog dlg(this,_("Specify output prefix"), - wxConfigBase::Get()->Read(wxT("/actualPath"),wxT("")), - outputPrefix, wxT(""), - wxFD_SAVE, wxDefaultPosition); - dlg.SetDirectory(wxConfigBase::Get()->Read(wxT("/actualPath"),wxT(""))); - if (dlg.ShowModal() == wxID_OK) - { - while(containsInvalidCharacters(dlg.GetPath())) - { - wxMessageBox(wxString::Format(_("The given filename contains one of the following invalid characters: %s\nHugin can not work with this filename. Please enter a valid filename."),getInvalidCharacters().c_str()), - _("Error"),wxOK | wxICON_EXCLAMATION); - if(dlg.ShowModal()!=wxID_OK) - return; - }; - } - else - { + return; + }; + while(containsInvalidCharacters(dlg.GetPath())) + { + wxMessageBox(wxString::Format(_("The given filename contains one of the following invalid characters: %s\nHugin can not work with this filename. Please enter a valid filename."),getInvalidCharacters().c_str()), + _("Error"),wxOK | wxICON_EXCLAMATION); + if(dlg.ShowModal()!=wxID_OK) return; - }; - wxConfig::Get()->Write(wxT("/actualPath"), dlg.GetDirectory()); // remember for later - outputPrefix = dlg.GetPath(); - } + }; - wxString command = hugin_stitch_project + wxT(" --delete -o ") + wxQuoteFilename(outputPrefix) + wxT(" ") + wxQuoteFilename(currentPTOfn); + wxString command = hugin_stitch_project + wxT(" --delete -o ") + wxQuoteFilename(dlg.GetPath()) + wxT(" ") + wxQuoteFilename(currentPTOfn); wxConfigBase::Get()->Flush(); #ifdef __WXGTK__ diff -r 315050341fea -r 5f15f569cdc8 src/hugin1/hugin/huginApp.cpp --- a/src/hugin1/hugin/huginApp.cpp Sat Mar 12 11:35:13 2011 -0500 +++ b/src/hugin1/hugin/huginApp.cpp Sun Mar 13 09:12:16 2011 +0100 @@ -81,17 +81,17 @@ bool t = (wxConfigBase::Get()->Read(wxT("ProjectNamingConvention"), HUGIN_PROJECT_NAMING_CONVENTION) != 0); if(t){ if (pano.getNrOfImages() > 0) { - wxString first_img(hugin_utils::getFolder(pano.getImage(0).getFilename()).c_str(), HUGIN_CONV_FILENAME); - return first_img; + wxFileName first_img(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME)); + return first_img.GetPath(); } else { return wxString(wxT("pano")); } }else{ if (pano.getNrOfImages() > 0) { - - wxString first_img(stripExtension(stripPath(pano.getImage(0).getFilename())).c_str(), HUGIN_CONV_FILENAME); - wxString last_img(stripExtension(stripPath(pano.getImage(pano.getNrOfImages()-1).getFilename())).c_str(), HUGIN_CONV_FILENAME); - return first_img + wxT("-") + last_img; + wxFileName first_img(wxString(pano.getImage(0).getFilename().c_str(),HUGIN_CONV_FILENAME)); + first_img.ClearExt(); + wxFileName last_img(wxString(pano.getImage(pano.getNrOfImages()-1).getFilename().c_str(),HUGIN_CONV_FILENAME)); + return first_img.GetFullPath() + wxT("-") + last_img.GetName(); } else { return wxString(wxT("pano")); } diff -r 315050341fea -r 5f15f569cdc8 src/hugin_base/hugin_utils/utils.cpp --- a/src/hugin_base/hugin_utils/utils.cpp Sat Mar 12 11:35:13 2011 -0500 +++ b/src/hugin_base/hugin_utils/utils.cpp Sun Mar 13 09:12:16 2011 +0100 @@ -142,47 +142,6 @@ } } -std::string getFolder(const std::string & filename) -{ -#ifdef UNIX_LIKE - std::string::size_type idx = filename.rfind('/'); - std::string f = filename.substr(0, idx); - std::string::size_type idy = f.rfind('/'); -#else - - std::string::size_type idx1 = filename.rfind('\\'); - std::string::size_type idx2 = filename.rfind('/'); - std::string::size_type idx; - std::string::size_type idy; - std::string f; - if (idx1 == std::string::npos) { - idx = idx2; - f = filename.substr(0, idx); - idy = f.rfind('/', idx); - } else if (idx2 == std::string::npos) { - idx = idx1; - f = filename.substr(0, idx); - idy = f.rfind('\\', idx); - } else { - idx = std::max(idx1, idx2); - f = filename.substr(0, idx); - if (idx == idx2) { - idy = f.rfind('/', idx); - } else { - idy = f.rfind('\\', idx); - } - } -#endif - if (idx != std::string::npos) { -// DEBUG_DEBUG("returning substring: " << f.substr(idy, idx)); - return f.substr(idy+1, idx-idy); - } else { - return filename; - } -} - - - std::string getPathPrefix(const std::string & filename) { #ifdef UNIX_LIKE diff -r 315050341fea -r 5f15f569cdc8 src/hugin_base/hugin_utils/utils.h --- a/src/hugin_base/hugin_utils/utils.h Sat Mar 12 11:35:13 2011 -0500 +++ b/src/hugin_base/hugin_utils/utils.h Sun Mar 13 09:12:16 2011 +0100 @@ -209,9 +209,6 @@ /** Get the path to a filename */ IMPEX std::string getPathPrefix(const std::string & filename); - /** Get the folder for a filename */ - IMPEX std::string getFolder(const std::string & filename); - /** Get extension of a filename */ IMPEX std::string getExtension(const std::string & basename); |