Bumped copyright dates for 2013
[barry.git] / desktop / src / EvoCfgDlg.cc
blob57d9d13e9f10857b935437c55cb57e2dba7b982e
1 ///
2 /// \file EvoCfgDlg.cc
3 /// The configuration dialog used to configure Evolution sources
4 ///
6 /*
7 Copyright (C) 2011-2013, 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"
25 #include "wxi18n.h"
27 using namespace std;
29 EvoCfgDlg::EvoCfgDlg(wxWindow *parent,
30 const OpenSync::Config::Evolution &ec,
31 const EvoSources &es)
32 : wxDialog(parent, Dialog_EvoCfg, _W("Evolution Plugin Configuration"))
33 , m_address_path(ec.GetAddressPath())
34 , m_calendar_path(ec.GetCalendarPath())
35 , m_tasks_path(ec.GetTasksPath())
36 , m_memos_path(ec.GetMemosPath())
37 , m_empty_config(ec.GetAddressPath().empty() &&
38 ec.GetCalendarPath().empty() &&
39 ec.GetTasksPath().empty() &&
40 ec.GetMemosPath().empty())
41 , m_sources(es)
43 CreateLayout();
46 void EvoCfgDlg::CreateLayout()
48 m_topsizer = new wxBoxSizer(wxVERTICAL);
50 m_topsizer->Add(
51 new wxStaticText(this, wxID_ANY, _W("Address Book:")),
52 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
53 AddCombo(&m_address_combo, wxID_ANY,
54 m_address_path, m_sources.GetAddressBook());
55 m_topsizer->Add(m_address_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
57 m_topsizer->Add(
58 new wxStaticText(this, wxID_ANY, _W("Calendar:")),
59 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
60 AddCombo(&m_calendar_combo, wxID_ANY,
61 m_calendar_path, m_sources.GetEvents());
62 m_topsizer->Add(m_calendar_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
64 m_topsizer->Add(
65 new wxStaticText(this, wxID_ANY, _W("Tasks:")),
66 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
67 AddCombo(&m_tasks_combo, wxID_ANY,
68 m_tasks_path, m_sources.GetTasks());
69 m_topsizer->Add(m_tasks_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
71 m_topsizer->Add(
72 new wxStaticText(this, wxID_ANY, _W("Memos:")),
73 0, wxALIGN_LEFT | wxTOP | wxLEFT | wxRIGHT, 10);
74 AddCombo(&m_memos_combo, wxID_ANY,
75 m_memos_path, m_sources.GetMemos());
76 m_topsizer->Add(m_memos_combo, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
78 wxSizer *button = CreateSeparatedButtonSizer(wxOK | wxCANCEL);
79 m_topsizer->Add(button, 0, wxALL | wxEXPAND | wxALIGN_RIGHT, 10);
81 SetSizer(m_topsizer);
82 m_topsizer->SetSizeHints(this);
83 m_topsizer->Layout();
86 void EvoCfgDlg::AddCombo(wxComboBox **combo, int id,
87 const std::string &current_path,
88 const EvoSources::List &list)
91 // Note: the evolution opensync plugins allow "default" as a
92 // configuration string, to chose to connect to the default
93 // Evolution address book or calendar. This is not detected
94 // by the EvoSources detection, since this is a special property
95 // of the opensync plugin.
97 // So we handle the "default" strings specially below.
101 // is the current path in the list?
102 bool in_list = false;
103 for( EvoSources::List::const_iterator i = list.begin(); current_path.size() && i != list.end(); ++i ) {
104 if( i->m_SourcePath == current_path ) {
105 in_list = true;
106 break;
111 // create an array of choices
113 wxArrayString choices;
115 // add current_path as first in list if it is not already there
116 if( current_path.size() && !in_list && current_path != "default" ) {
117 choices.Add(wxString(current_path.c_str(), wxConvUTF8));
120 // add the evolution special "default" option before the sources
121 // list, since it's probably what the user wants
122 choices.Add(_T("default"));
124 // add the sources list
125 for( EvoSources::List::const_iterator i = list.begin(); i!=list.end(); ++i ) {
126 if( i->m_SourcePath.size() ) {
127 choices.Add(wxString(i->m_SourcePath.c_str(), wxConvUTF8));
131 // default choice... if we have an empty config, this is the first
132 // time the user is running this dialog, so use the first option
133 // in the combo box as the default.
135 // if not an empty config, then show what the user currently
136 // has in the config, even if it is empty
137 wxString default_value;
138 if( m_empty_config && choices.GetCount() ) {
139 // first run, use first item
140 default_value = choices[0];
142 else {
143 // show user's current config
144 default_value = wxString(current_path.c_str(), wxConvUTF8);
147 // create the combo box
148 *combo = new wxComboBox(this, id,
149 default_value,
150 wxDefaultPosition, wxDefaultSize, // wxSize(250, -1), //wxDefaultSize,
151 choices,
152 wxCB_DROPDOWN);
155 void EvoCfgDlg::SetPaths(OpenSync::Config::Evolution &ec) const
157 ec.SetAddressPath(m_address_path);
158 ec.SetCalendarPath(m_calendar_path);
159 ec.SetTasksPath(m_tasks_path);
160 ec.SetMemosPath(m_memos_path);
163 wxString EvoCfgDlg::CheckPath(const wxString &name,
164 const std::string &path) const
166 if( path.size() > 7 && path.substr(0, 7) == "file://" ) {
167 std::string p = path.substr(7);
168 if( !EvoSources::PathExists(p) ) {
169 wxString msg = wxString::Format(_W("File '%s' does not exist."), name.c_str());
170 return msg;
174 return _T("");
177 wxString EvoCfgDlg::ValidatePaths() const
179 if( m_address_path.empty() && m_calendar_path.empty() &&
180 m_tasks_path.empty() && m_memos_path.empty() )
181 return _W("No paths set! If there are no default options available in the drop down lists, please double check that you've initialized your Evolution account first.");
182 return _T("");
185 bool EvoCfgDlg::TransferDataFromWindow()
187 m_address_path = string(m_address_combo->GetValue().utf8_str());
188 m_calendar_path = string(m_calendar_combo->GetValue().utf8_str());
189 m_tasks_path = string(m_tasks_combo->GetValue().utf8_str());
190 m_memos_path = string(m_memos_combo->GetValue().utf8_str());
192 wxString msg = ValidatePaths();
193 if( msg.size() ) {
194 wxMessageBox(msg, _W("Minimum Config Required"),
195 wxOK | wxICON_ERROR, this);
196 return false;
199 return true;
202 int EvoCfgDlg::ShowModal()
204 return wxDialog::ShowModal();