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 #if defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
33 #include "base_wx/platform.h"
34 #endif
35 
36 ChangeUserDefinedSequenceDialog::ChangeUserDefinedSequenceDialog(wxWindow* parent, wxString xrcPrefix, wxString userDefinedSequence, bool assistantUserDefined)
37 {
38  // load our children. some children might need special
39  // initialization. this will be done later.
40  wxXmlResource::Get()->LoadDialog(this, parent, "change_user_defined_dialog");
41 
42  m_radio_default = XRCCTRL(*this, "radio_default_sequence", wxRadioButton);
43  m_radio_default->Bind(wxEVT_RADIOBUTTON, &ChangeUserDefinedSequenceDialog::UpdateStatus, this);
44  m_radio_user_sequence = XRCCTRL(*this, "radio_user_defined", wxRadioButton);
46  m_choice_user_define=XRCCTRL(*this, "choice_user_defined", wxChoice);
48  m_label_user_define = XRCCTRL(*this, "label_user_defined", wxStaticText);
49  m_label_user_define_filename = XRCCTRL(*this, "label_user_defined_filename", wxStaticText);
50  m_radio_external = XRCCTRL(*this, "radio_external_sequence", wxRadioButton);
51  m_radio_external->Bind(wxEVT_RADIOBUTTON, &ChangeUserDefinedSequenceDialog::UpdateStatus, this);
52  m_text_external_file = XRCCTRL(*this, "text_external_file", wxTextCtrl);
53  m_text_external_file->AutoCompleteFileNames();
54  m_button_external_file = XRCCTRL(*this, "button_external_file", wxButton);
56 
57  m_isAssistantUserDefined = assistantUserDefined;
59  {
61  }
62  else
63  {
65  };
66  if (userDefinedSequence.IsEmpty())
67  {
68  m_radio_default->SetValue(true);
69  }
70  else
71  {
72  int index = m_userFileNames.Index(userDefinedSequence);
73  if (index == wxNOT_FOUND)
74  {
75  // user defined sequence not found in list
76  // so use external entry
77  m_radio_external->SetValue(true);
78  m_text_external_file->SetValue(userDefinedSequence);
79  }
80  else
81  {
82  // item found in list
83  m_radio_user_sequence->SetValue(true);
84  m_choice_user_define->Select(index);
85  };
86  };
87  wxCommandEvent dummy;
88  UpdateStatus(dummy);
89 
90  //set parameters
91  wxConfigBase* config = wxConfigBase::Get();
92  // restore position and size
93  int dx,dy;
94  wxDisplaySize(&dx,&dy);
95  //size
96  int w = config->Read("/UserDefinedSequenceDialog/width", -1l);
97  int h = config->Read("/UserDefinedSequenceDialog/height", -1l);
98  if (w > 0 && w <= dx)
99  {
100  this->SetClientSize(w,h);
101  }
102  else
103  {
104  this->Fit();
105  }
106  //position
107  int x = config->Read("/UserDefinedSequenceDialog/positionX", -1l);
108  int y = config->Read("/UserDefinedSequenceDialog/positionY", -1l);
109  if ( y >= 0 && x >= 0 && x < dx && y < dy)
110  {
111  this->Move(x, y);
112  }
113  else
114  {
115  this->Move(0, 44);
116  }
117  Bind(wxEVT_BUTTON, &ChangeUserDefinedSequenceDialog::OnOk, this, wxID_OK);
118 }
119 
121 {
122  wxConfigBase* config=wxConfigBase::Get();
123  wxSize sz = this->GetClientSize();
124  config->Write("/UserDefinedSequenceDialog/width", sz.GetWidth());
125  config->Write("/UserDefinedSequenceDialog/height", sz.GetHeight());
126  wxPoint ps = this->GetPosition();
127  config->Write("/UserDefinedSequenceDialog/positionX", ps.x);
128  config->Write("/UserDefinedSequenceDialog/positionY", ps.y);
129 }
130 
132 {
133  m_choice_user_define->Enable(m_radio_user_sequence->GetValue());
134  m_label_user_define->Enable(m_radio_user_sequence->GetValue());
136  m_text_external_file->Enable(m_radio_external->GetValue());
137  m_button_external_file->Enable(m_radio_external->GetValue());
138 }
139 
141 {
142  // update help text
143  const long id = e.GetSelection();
144  if (id >= 0 && id < m_userHelpTexts.size())
145  {
147  m_label_user_define->SetLabel(m_userHelpTexts[id]);
148  };
149 }
150 
152 {
153  wxFileDialog userOutputDlg(this, (m_isAssistantUserDefined ? _("Select user defined assistant") : _("Select user defined output")),
154  m_text_external_file->GetValue(), wxEmptyString, (m_isAssistantUserDefined ? _("User defined assistant|*.assistant") : _("User defined output|*.executor")),
155  wxFD_OPEN | wxFD_FILE_MUST_EXIST, wxDefaultPosition);
156  if (userOutputDlg.ShowModal() == wxID_OK)
157  {
158  m_text_external_file->SetValue(userOutputDlg.GetPath());
159  };
160 }
161 
163 {
164  if (m_radio_external->GetValue())
165  {
166  // check that a valid file was given
167  wxString filename = m_text_external_file->GetValue();
168  if (filename.IsEmpty())
169  {
170  wxMessageBox(_("Please provide a filename to the user defined sequence."),
171 #ifdef __WXMSW__
172  "PTBatcherGUI",
173 #else
174  wxEmptyString,
175 #endif
176  wxOK | wxOK_DEFAULT | wxICON_WARNING);
177  return;
178  };
179  if (!wxFileName::FileExists(filename))
180  {
181  wxMessageBox(wxString::Format(_("The file \"%s\" does not exists.\nPlease provide an existing file to the user defined sequence."), filename.c_str()),
182 #ifdef __WXMSW__
183  "PTBatcherGUI",
184 #else
185  wxEmptyString,
186 #endif
187  wxOK | wxOK_DEFAULT | wxICON_WARNING);
188  return;
189  };
190  }
191  EndModal(wxID_OK);
192 }
193 
195 {
196  if (m_radio_default->GetValue())
197  {
198  return wxEmptyString;
199  };
200  if (m_radio_user_sequence->GetValue())
201  {
202  if (m_choice_user_define->GetCount() > 0 && m_choice_user_define->GetSelection() != wxNOT_FOUND)
203  {
204  return m_userFileNames[m_choice_user_define->GetSelection()];
205  }
206  else
207  {
208  return wxEmptyString;
209  };
210  };
211  return m_text_external_file->GetValue();
212 }
213 
215 wxString GetDataPath()
216 {
217 #if defined __WXMSW__
218  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
219  exePath.RemoveLastDir();
220  const wxString huginRoot = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
221  return huginRoot + "share\\hugin\\data\\";
222 #elif defined __WXMAC__ && defined MAC_SELF_CONTAINED_BUNDLE
223  // initialize paths
224  {
225  wxString thePath = MacGetPathToBundledResourceFile(CFSTR("xrc"));
226  if (thePath.IsEmpty())
227  {
228  wxMessageBox(_("xrc directory not found in bundle"), _("Fatal Error"));
229  return wxEmptyString;
230  }
231  return thePath + "/";
232  }
233 #elif defined UNIX_SELF_CONTAINED_BUNDLE
234  // initialize paths
235  {
236  wxFileName exePath(wxStandardPaths::Get().GetExecutablePath());
237  exePath.RemoveLastDir();
238  const wxString huginRoot = exePath.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
239  return huginRoot + "share/hugin/data/";
240  }
241 #else
242  // add the locale directory specified during configure
243  return INSTALL_DATA_DIR;
244 #endif
245 }
246 
248 {
249  wxArrayString files;
250  // search all .assistant files, do not follow links
251  wxDir::GetAllFiles(GetDataPath() + "assistant", &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
252  wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.assistant", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
253  FillUserDefinedChoice(files);
254 }
255 
257 {
258  wxArrayString files;
259  // search all .executor files, do not follow links
260  wxDir::GetAllFiles(GetDataPath() + "output", &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
261  wxDir::GetAllFiles(hugin_utils::GetUserAppDataDir(), &files, "*.executor", wxDIR_FILES | wxDIR_HIDDEN | wxDIR_NO_FOLLOW);
262  FillUserDefinedChoice(files);
263 }
264 
266 {
267  if (!files.IsEmpty())
268  {
269  for (auto file : files)
270  {
271  // read all files
272  wxFileInputStream inputStream(file);
273  if (inputStream.IsOk())
274  {
275  // read descriptions from file
276  wxFileConfig executorFile(inputStream);
277  wxString desc = HuginQueue::GetSettingStringTranslated(&executorFile, "/General/Description", wxEmptyString);
278  if (desc.IsEmpty())
279  {
280  desc = file;
281  };
282  wxString help = HuginQueue::GetSettingStringTranslated(&executorFile, "/General/Help", wxEmptyString);
283  if (help.IsEmpty())
284  {
285  help = wxString::Format(_("User defined sequence: %s"), file);
286  };
287  // add to wxChoice and remember help text
288  m_choice_user_define->AppendString(desc);
289  m_userFileNames.Add(file);
290  m_userHelpTexts.Add(help);
291  };
292  };
293  if (m_choice_user_define->GetCount() > 0)
294  {
295  m_choice_user_define->Select(0);
296  wxCommandEvent dummy;
297  dummy.SetInt(0);
299  };
300  };
301 }
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