desktop: added simple EvoDefaultDlg
[barry/progweb.git] / desktop / src / EvoCfgDlg.cc
blobb62ce0578918c091d626b6e77461b40cf3ec26cd
1 ///
2 /// \file EvoCfgDlg.cc
3 /// The configuration dialog used to configure Evolution sources
4 ///
6 /*
7 Copyright (C) 2011, Net Direct Inc. (http://www.netdirect.ca/)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 See the GNU General Public License in the COPYING file at the
19 root directory of this project for more details.
22 #include "EvoCfgDlg.h"
23 #include "osconfig.h"
24 #include "windowids.h"
26 using namespace std;
28 EvoCfgDlg::EvoCfgDlg(wxWindow *parent,
29 const OpenSync::Config::Evolution &ec,
30 const EvoSources &es)
31 : wxDialog(parent, Dialog_EvoCfg, _T("Evolution Plugin Configuration"))
32 , m_address_path(ec.GetAddressPath())
33 , m_calendar_path(ec.GetCalendarPath())
34 , m_tasks_path(ec.GetTasksPath())
35 , m_memos_path(ec.GetMemosPath())
36 , m_sources(es)
38 CreateLayout();
41 void EvoCfgDlg::CreateLayout()
43 m_topsizer = new wxBoxSizer(wxVERTICAL);
45 m_topsizer->Add(
46 new wxStaticText(this, wxID_ANY, _T("Address Book:")),
47 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
48 AddCombo(&m_address_combo, wxID_ANY,
49 m_address_path, m_sources.GetAddressBook());
50 m_topsizer->Add(m_address_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
52 m_topsizer->Add(
53 new wxStaticText(this, wxID_ANY, _T("Calendar:")),
54 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
55 AddCombo(&m_calendar_combo, wxID_ANY,
56 m_calendar_path, m_sources.GetEvents());
57 m_topsizer->Add(m_calendar_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
59 m_topsizer->Add(
60 new wxStaticText(this, wxID_ANY, _T("Tasks:")),
61 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
62 AddCombo(&m_tasks_combo, wxID_ANY,
63 m_tasks_path, m_sources.GetTasks());
64 m_topsizer->Add(m_tasks_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
66 m_topsizer->Add(
67 new wxStaticText(this, wxID_ANY, _T("Memos:")),
68 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
69 AddCombo(&m_memos_combo, wxID_ANY,
70 m_memos_path, m_sources.GetMemos());
71 m_topsizer->Add(m_memos_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
73 wxSizer *button = CreateSeparatedButtonSizer(wxOK | wxCANCEL);
74 m_topsizer->Add(button, 0, wxALL | wxEXPAND | wxALIGN_RIGHT, 10);
76 SetSizer(m_topsizer);
77 m_topsizer->SetSizeHints(this);
78 m_topsizer->Layout();
81 void EvoCfgDlg::AddCombo(wxComboBox **combo, int id,
82 const std::string &current_path,
83 const EvoSources::List &list)
85 // is the current path in the list?
86 bool in_list = false;
87 for( EvoSources::List::const_iterator i = list.begin(); current_path.size() && i != list.end(); ++i ) {
88 if( i->m_SourcePath == current_path ) {
89 in_list = true;
90 break;
94 // create an array of choices, and add current_path as first in list
95 // if it is not already there
96 wxArrayString choices;
97 if( current_path.size() && !in_list ) {
98 choices.Add(wxString(current_path.c_str(), wxConvUTF8));
101 // add the sources list
102 for( EvoSources::List::const_iterator i = list.begin(); i!=list.end(); ++i ) {
103 if( i->m_SourcePath.size() ) {
104 choices.Add(wxString(i->m_SourcePath.c_str(), wxConvUTF8));
108 // create the combo box
109 *combo = new wxComboBox(this, id,
110 choices.GetCount() ? choices[0] : wxString(),
111 wxDefaultPosition, wxDefaultSize, // wxSize(250, -1), //wxDefaultSize,
112 choices,
113 wxCB_DROPDOWN);
116 void EvoCfgDlg::SetPaths(OpenSync::Config::Evolution &ec) const
118 ec.SetAddressPath(m_address_path);
119 ec.SetCalendarPath(m_calendar_path);
120 ec.SetTasksPath(m_tasks_path);
121 ec.SetMemosPath(m_memos_path);
124 wxString EvoCfgDlg::CheckPath(const wxString &name,
125 const std::string &path) const
127 if( path.size() > 7 && path.substr(0, 7) == "file://" ) {
128 std::string p = path.substr(7);
129 if( !EvoSources::PathExists(p) ) {
130 wxString msg = name + _T(" does not exist.");
131 return msg;
135 return _T("");
138 wxString EvoCfgDlg::ValidatePaths() const
140 if( m_address_path.empty() || m_calendar_path.empty() || m_tasks_path.empty() )
141 return _T("Address book, Event, and Tasks must be set.");
143 wxString msg;
144 msg = CheckPath(_T("Address book path"), m_address_path);
145 if( msg.size() )
146 return msg;
147 msg = CheckPath(_T("Event path"), m_calendar_path);
148 if( msg.size() )
149 return msg;
150 msg = CheckPath(_T("Tasks path"), m_tasks_path);
151 if( msg.size() )
152 return msg;
153 msg = CheckPath(_T("Memos path"), m_memos_path);
154 return msg;
157 bool EvoCfgDlg::TransferDataFromWindow()
159 m_address_path = string(m_address_combo->GetValue().utf8_str());
160 m_calendar_path = string(m_calendar_combo->GetValue().utf8_str());
161 m_tasks_path = string(m_tasks_combo->GetValue().utf8_str());
162 m_memos_path = string(m_memos_combo->GetValue().utf8_str());
164 wxString msg = ValidatePaths();
165 if( msg.size() ) {
166 wxMessageBox(msg, _T("Minimum Config Required"),
167 wxOK | wxICON_ERROR, this);
168 return false;
171 return true;
174 int EvoCfgDlg::ShowModal()
176 return wxDialog::ShowModal();