Hugintrunk  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ChangeUserDefinedDialog.cpp
Go to the documentation of this file.
1 // -*- c-basic-offset: 4 -*-
2 
11 /* This is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public
13  * License as published by the Free Software Foundation; either
14  * version 2 of the License, or (at your option) any later version.
15  *
16  * This software is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19  * Lesser General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public
22  * License along with this software. If not, see
23  * <http://www.gnu.org/licenses/>.
24  *
25  */
26 
28 #include <wx/dir.h>
29 #include <wx/stdpaths.h>
30 #include <wx/wfstream.h>
31 #include "base_wx/Executor.h"
32 #include "base_wx/wxutils.h"
33 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
34 #include "base_wx/platform.h"
35 #endif
36 
37 ChangeUserDefinedSequenceDialog::ChangeUserDefinedSequenceDialog(wxWindow* parent, wxString xrcPrefix, wxString userDefinedSequence, bool assistantUserDefined)
38 {
39  // load our children. some children might need special
40  // initialization. this will be done later.
41  wxXmlResource::Get()->LoadDialog(this, parent, "change_user_defined_dialog");
42 
43  m_radio_default = XRCCTRL(*this, "radio_default_sequence", wxRadioButton);
44  m_radio_default->Bind(wxEVT_RADIOBUTTON, &ChangeUserDefinedSequenceDialog::UpdateStatus, this);
45  m_radio_user_sequence = XRCCTRL(*this, "radio_user_defined", wxRadioButton);
47  m_choice_user_define=XRCCTRL(*this, "choice_user_defined", wxChoice);
49  m_label_user_define = XRCCTRL(*this, "label_user_defined", wxStaticText);
50  m_label_user_define_filename = XRCCTRL(*this, "label_user_defined_filename", wxStaticText);
51  m_radio_external = XRCCTRL(*this, "radio_external_sequence", wxRadioButton);
52  m_radio_external->Bind(wxEVT_RADIOBUTTON, &ChangeUserDefinedSequenceDialog::UpdateStatus, this);
53  m_text_external_file = XRCCTRL(*this, "text_external_file", wxTextCtrl);
54  m_text_external_file->AutoCompleteFileNames();
55  m_button_external_file = XRCCTRL(*this, "button_external_file", wxButton);
57 
58  m_isAssistantUserDefined = assistantUserDefined;
60  {
62  }
63  else
64  {
66  };
67  if (userDefinedSequence.IsEmpty())
68  {
69  m_radio_default->SetValue(true);
70  }
71  else
72  {
73  int index = m_userFileNames.Index(userDefinedSequence);
74  if (index == wxNOT_FOUND)
75  {
76  // user defined sequence not found in list
77  // so use external entry
78  m_radio_external->SetValue(true);
79  m_text_external_file->SetValue(userDefinedSequence);
80  }
81  else
82  {
83  // item found in list
84  m_radio_user_sequence->SetValue(true);
85  m_choice_user_define->Select(index);
86  };
87  };
88  wxCommandEvent dummy;
89  UpdateStatus(dummy);
90 
91  //set parameters
92  wxConfigBase* config = wxConfigBase::Get();
93  // restore position and size
94  int dx,dy;
95  wxDisplaySize(&dx,&dy);
96  //size
97  int w = config->Read("/UserDefinedSequenceDialog/width", -1l);
98  int h = config->Read("/UserDefinedSequenceDialog/height", -1l);
99  if (w > 0 && w <= dx)
100  {
101  this->SetClientSize(w,h);
102  }
103  else
104  {
105  this->Fit();
106  }
107  //position
108  int x = config->Read("/UserDefinedSequenceDialog/positionX", -1l);
109  int y = config->Read("/UserDefinedSequenceDialog/positionY", -1l);
110  if ( y >= 0 && x >= 0 && x < dx && y < dy)
111  {
112  this->Move(x, y);
113  }
114  else
115  {
116  this->Move(0, 44);
117  }
118  Bind(wxEVT_BUTTON, &ChangeUserDefinedSequenceDialog::OnOk, this, wxID_OK);
119 }
120 
122 {
123  wxConfigBase* config=wxConfigBase::Get();
124  wxSize sz = this->GetClientSize();
125  config->Write("/UserDefinedSequenceDialog/width", sz.GetWidth());
126  config->Write("/UserDefinedSequenceDialog/height", sz.GetHeight());
127  wxPoint ps = this->GetPosition();
128  config->Write("/UserDefinedSequenceDialog/positionX", ps.x);
129  config->Write("/UserDefinedSequenceDialog/positionY", ps.y);
130 }
131 
133 {
134  m_choice_user_define->Enable(m_radio_user_sequence->GetValue());
135  m_label_user_define->Enable(m_radio_user_sequence->GetValue());
137  m_text_external_file->Enable(m_radio_external->GetValue());
138  m_button_external_file->Enable(m_radio_external->GetValue());
139 }
140 
142 {
143  // update help text
144  const long id = e.GetSelection();
145  if (id >= 0 && id < m_userHelpTexts.size())
146  {
148  m_label_user_define->SetLabel(m_userHelpTexts[id]);
149  };
150 }
151 
153 {
154  wxFileDialog userOutputDlg(this, (m_isAssistantUserDefined ? _("Select user defined assistant") : _("Select user defined output")),
155  m_text_external_file->GetValue(), wxEmptyString, (m_isAssistantUserDefined ? _("User defined assistant|*.assistant") : _("User defined output|*.executor")),
156  wxFD_OPEN | wxFD_FILE_MUST_EXIST, wxDefaultPosition);
157  if (userOutputDlg.ShowModal() == wxID_OK)
158  {
159  m_text_external_file->SetValue(userOutputDlg.GetPath());
160  };
161 }
162 
164 {
165  if (m_radio_external->GetValue())
166  {
167  // check that a valid file was given
168  wxString filename = m_text_external_file->GetValue();
169  if (filename.IsEmpty())
170  {
171  hugin_utils::HuginMessageBox(_("Please provide a filename to the user defined sequence."), _("PTBatcherGUI"), wxOK | wxOK_DEFAULT | wxICON_WARNING, this);
172  return;
173  };
174  if (!wxFileName::FileExists(filename))
175  {
176  hugin_utils::HuginMessageBox(wxString::Format(_("The file \"%s\" does not exists.\nPlease provide an existing file to the user defined sequence."), filename),
177  _("PTBatcherGUI"), wxOK | wxOK_DEFAULT | wxICON_WARNING, this);
178  return;
179  };
180  }
181  EndModal(wxID_OK);
182 }
183 
185 {
186  if (m_radio_default->GetValue())
187  {
188  return wxEmptyString;
189  };
190  if (m_radio_user_sequence->GetValue())
191  {
192  if (m_choice_user_define->GetCount() > 0 && m_choice_user_define->GetSelection() != wxNOT_FOUND)
193  {
194  return m_userFileNames[m_choice_user_define->GetSelection()];
195  }
196  else
197  {
198  return wxEmptyString;
199  };
200  };
201  return m_text_external_file->GetValue();
202 }
203 
205 wxString GetDataPath()
206 {
207 #if defined __WXMSW__
208  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
209  exePath.RemoveLastDir();
210  const wxString huginRoot = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
211  return huginRoot + "share\\hugin\\data\\";
212 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
213  // initialize paths
214  {
215  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
216  if (thePath.IsEmpty())
217  {
218  hugin_utils::HuginMessageBox(_("xrc directory not found in bundle"), _("PTBatcherGUI"), wxOK|wxICON_ERROR, this);
219  return wxEmptyString;
220  }
221  return thePath + "/";
222  }
223 #elif defined UNIX_SELF_CONTAINED_BUNDLE
224  // initialize paths
225  {
226  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
227  exePath.RemoveLastDir();
228  const wxString huginRoot = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
229  return huginRoot + "share/hugin/data/";
230  }
231 #else
232  // add the locale directory specified during configure
233  return INSTALL_DATA_DIR;
234 #endif
235 }
236 
238 {
239  wxArrayString files;
240  // search all .assistant files, do not follow links
241  wxDir::GetAllFiles(GetDataPath() + "assistant", &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
242  wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
243  FillUserDefinedChoice(files);
244 }
245 
247 {
248  wxArrayString files;
249  // search all .executor files, do not follow links
250  wxDir::GetAllFiles(GetDataPath() + "output", &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
251  wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
252  FillUserDefinedChoice(files);
253 }
254 
256 {
257  if (!files.IsEmpty())
258  {
259  for (auto file : files)
260  {
261  // read all files
262  wxFileInputStream inputStream(file);
263  if (inputStream.IsOk())
264  {
265  // read descriptions from file
266  wxFileConfig executorFile(inputStream);
267  wxString desc = HuginQueue::GetSettingStringTranslated(&executorFile, "/General/Description", wxEmptyString);
268  if (desc.IsEmpty())
269  {
270  desc = file;
271  };
272  wxString help = HuginQueue::GetSettingStringTranslated(&executorFile, "/General/Help", wxEmptyString);
273  if (help.IsEmpty())
274  {
275  help = wxString::Format(_("User defined sequence: %s"), file);
276  };
277  // add to wxChoice and remember help text
278  m_choice_user_define->AppendString(desc);
279  m_userFileNames.Add(file);
280  m_userHelpTexts.Add(help);
281  };
282  };
283  if (m_choice_user_define->GetCount() > 0)
284  {
285  m_choice_user_define->Select(0);
286  wxCommandEvent dummy;
287  dummy.SetInt(0);
289  };
290  };
291 }
implementation of huginApp Class
bool FileExists(const std::string &filename)
checks if file exists
Definition: utils.cpp:362
wxString GetDataPath()
return path to data directory, it depends on operating system
void OnChangeUserDefinedChoice(wxCommandEvent &e)
wxString GetNewSequence()
returns the newly selected sequence
~ChangeUserDefinedSequenceDialog()
destructor, saves size and position
basic classes and function for queuing commands in wxWidgets
void FillUserDefinedChoice(const wxArrayString &files)
IMPEX double h[25][1024]
Definition: emor.cpp:169
ChangeUserDefinedSequenceDialog(wxWindow *parent, wxString xrcPrefix, wxString userDefinedSequence, bool assistantUserDefined)
Constructor, read from xrc ressource; restore last uses size and position.
const wxString GetSettingStringTranslated(wxConfigBase *setting, const wxString &name, const wxString defaultValue)
read a translated string from settings and remove all whitespaces
Definition: Executor.cpp:288
std::string GetUserAppDataDir()
returns the directory for user specific Hugin settings, e.g.
Definition: utils.cpp:497
int HuginMessageBox(const wxString &message, const wxString &caption, int style, wxWindow *parent)
Definition: wxutils.cpp:176