~ubuntu-branches/debian/sid/filezilla/sid

« back to all changes in this revision

Viewing changes to src/interface/Options.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adrien Cunin
  • Date: 2009-02-22 21:27:48 UTC
  • mfrom: (1.3.1 upstream) (3.1.20 jaunty)
  • Revision ID: james.westby@ubuntu.com-20090222212748-p4zso8kd6t5y9zwn
* Upload to unstable now that lenny is released
* New upstream release (LP: #326578)
   - New features: bookmarks, logging to file and synchronized browsing
   - libdbus support
   - Fixes some encoding issues with some locales (LP: #312246)
   - Better handles editing files with no application associated (LP: #310167)
* Updated features list in package description with new features
* Added libdbus-1-dev build-dep and explicitely use --with-dbus when
  configuring

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "FileZilla.h"
2
2
#include "Options.h"
3
 
#include "../tinyxml/tinyxml.h"
4
3
#include "xmlfunctions.h"
5
4
#include "filezillaapp.h"
6
5
#include <wx/tokenzr.h>
59
58
        { "FTP Proxy password", string, _T("") },
60
59
        { "FTP Proxy login sequence", string, _T("") },
61
60
        { "SFTP keyfiles", string, _T("") },
 
61
        { "Proxy type", number, _T("0") },
 
62
        { "Proxy host", string, _T("") },
 
63
        { "Proxy port", number, _T("0") },
 
64
        { "Proxy user", string, _T("") },
 
65
        { "Proxy password", string, _T("") },
 
66
        { "Logging file", string, _T("") },
 
67
        { "Logging filesize limit", number, _T("10") },
62
68
 
63
69
        // Interface settings
64
70
        { "Number of Transfers", number, _T("2") },
93
99
        { "Local filelist colwidths", string, _T("") },
94
100
        { "Remote filelist colwidths", string, _T("") },
95
101
        { "Window position and size", string, _T("") },
96
 
        { "Splitter positions", string, _T("") },
 
102
        { "Splitter positions (v2)", string, _T("") },
97
103
        { "Local filelist sortorder", string, _T("") },
98
104
        { "Remote filelist sortorder", string, _T("") },
99
105
        { "Time Format", string, _T("") },
116
122
        { "Remote filelist shown columns", string, _T("") },
117
123
        { "Local filelist column order", string, _T("") },
118
124
        { "Remote filelist column order", string, _T("") },
119
 
        { "Filelist status bar", number, _T("1") }
120
 
};
 
125
        { "Filelist status bar", number, _T("1") },
 
126
        { "Filter toggle state", number, _T("0") },
 
127
        { "Size decimal places", number, _T("0") },
 
128
        { "Show quickconnect bar", number, _T("1") },
 
129
        { "Messagelog position", number, _T("0") },
 
130
        { "Last connected site", string, _T("") },
 
131
        { "File doubleclock action", number, _T("0") },
 
132
        { "Dir doubleclock action", number, _T("0") }
 
133
};
 
134
 
 
135
struct t_default_option
 
136
{
 
137
        const wxChar name[30];
 
138
        enum Type type;
 
139
        wxString value_str;
 
140
        int value_number;
 
141
};
 
142
 
 
143
static t_default_option default_options[DEFAULTS_NUM] =
 
144
{
 
145
        { _T("Config Location"), string, _T(""), 0 },
 
146
        { _T("Kiosk mode"), number, _T(""), 0 },
 
147
        { _T("Disable update check"), number, _T(""), 0 }
 
148
};
 
149
 
 
150
BEGIN_EVENT_TABLE(COptions, wxEvtHandler)
 
151
EVT_TIMER(wxID_ANY, COptions::OnTimer)
 
152
END_EVENT_TABLE()
121
153
 
122
154
COptions::COptions()
123
155
{
128
160
        for (unsigned int i = 0; i < OPTIONS_NUM; i++)
129
161
                m_optionsCache[i].cached = false;
130
162
 
 
163
        m_save_timer.SetOwner(this);
 
164
 
131
165
        CInterProcessMutex mutex(MUTEX_OPTIONS);
132
166
        m_pXmlFile = new CXmlFile(_T("filezilla"));
133
167
        if (!m_pXmlFile->Load())
134
168
        {
135
 
                wxString msg = wxString::Format(_("Could not load \"%s\", make sure the file is valid.\nFor this session, default settings will be used and any changes to the settings are not persistent."), m_pXmlFile->GetFileName().GetFullPath().c_str());
 
169
                wxString msg = m_pXmlFile->GetError() + _T("\n\n") + _("For this session the default settings will be used. Any changes to the settings will not be saved.");
136
170
                wxMessageBox(msg, _("Error loading xml file"), wxICON_ERROR);
137
171
                delete m_pXmlFile;
138
172
                m_pXmlFile = 0;
139
173
        }
140
174
        else
141
175
                CreateSettingsXmlElement();
 
176
 
 
177
        LoadGlobalDefaultOptions();
142
178
}
143
179
 
144
180
COptions::~COptions()
199
235
 
200
236
bool COptions::SetOption(unsigned int nID, int value)
201
237
{
202
 
        if (!SetOptionNoSave(nID, value))
203
 
                return false;
204
 
 
205
 
        if (m_pXmlFile)
206
 
        {
207
 
                CInterProcessMutex mutex(MUTEX_OPTIONS);
208
 
                m_pXmlFile->Save();
209
 
        }
210
 
 
211
 
        return true;
212
 
}
213
 
 
214
 
bool COptions::SetOptionNoSave(unsigned int nID, int value)
215
 
{
216
238
        if (nID >= OPTIONS_NUM)
217
239
                return false;
218
240
 
225
247
        m_optionsCache[nID].numValue = value;
226
248
 
227
249
        if (m_pXmlFile)
 
250
        {
228
251
                SetXmlValue(nID, wxString::Format(_T("%d"), value));
229
252
 
 
253
                if (!m_save_timer.IsRunning())
 
254
                        m_save_timer.Start(15000, true);
 
255
        }
 
256
 
230
257
        return true;
231
258
}
232
259
 
233
260
bool COptions::SetOption(unsigned int nID, wxString value)
234
261
{
235
 
        if (!SetOptionNoSave(nID, value))
236
 
                return false;
237
 
 
238
 
        if (m_pXmlFile)
239
 
        {
240
 
                CInterProcessMutex mutex(MUTEX_OPTIONS);
241
 
                m_pXmlFile->Save();
242
 
        }
243
 
 
244
 
        return true;
245
 
}
246
 
 
247
 
bool COptions::SetOptionNoSave(unsigned int nID, wxString value)
248
 
{
249
262
        if (nID >= OPTIONS_NUM)
250
263
                return false;
251
264
 
264
277
        m_optionsCache[nID].strValue = value;
265
278
 
266
279
        if (m_pXmlFile)
 
280
        {
267
281
                SetXmlValue(nID, value);
268
282
 
 
283
                if (!m_save_timer.IsRunning())
 
284
                        m_save_timer.Start(15000, true);
 
285
        }
 
286
 
269
287
 
270
288
        return true;
271
289
}
457
475
                if (value < 0 || value > 1440)
458
476
                        value = 1;
459
477
                break;
 
478
        case OPTION_SIZE_DECIMALPLACES:
 
479
                if (value < 0 || value > 3)
 
480
                        value = 0;
 
481
                break;
 
482
        case OPTION_MESSAGELOG_POSITION:
 
483
                if (value < 0 || value > 2)
 
484
                        value = 0;
 
485
                break;
 
486
        case OPTION_DOUBLECLICK_ACTION_FILE:
 
487
        case OPTION_DOUBLECLICK_ACTION_DIRECTORY:
 
488
                if (value < 0 || value > 3)
 
489
                        value = 0;
 
490
                break;
460
491
        }
461
492
        return value;
462
493
}
609
640
                if (!GetXmlValue(i, value, pElement))
610
641
                        continue;
611
642
 
612
 
                SetOptionNoSave(i, value);
 
643
                SetOption(i, value);
613
644
        }
614
 
 
615
 
        if (m_pXmlFile)
 
645
}
 
646
 
 
647
void COptions::LoadGlobalDefaultOptions()
 
648
{
 
649
        const wxString& defaultsDir = wxGetApp().GetDefaultsDir();
 
650
        if (defaultsDir == _T(""))
 
651
                return;
 
652
        
 
653
        wxFileName name(defaultsDir, _T("fzdefaults.xml"));
 
654
        CXmlFile file(name);
 
655
        if (!file.Load())
 
656
                return;
 
657
 
 
658
        TiXmlElement* pElement = file.GetElement();
 
659
        if (!pElement)
 
660
                return;
 
661
 
 
662
        pElement = pElement->FirstChildElement("Settings");
 
663
        if (!pElement)
 
664
                return;
 
665
 
 
666
        for (TiXmlElement* pSetting = pElement->FirstChildElement("Setting"); pSetting; pSetting = pSetting->NextSiblingElement("Setting"))
616
667
        {
617
 
                CInterProcessMutex mutex(MUTEX_OPTIONS);
618
 
                m_pXmlFile->Save();
 
668
                wxString name = GetTextAttribute(pSetting, "name");
 
669
                for (int i = 0; i < DEFAULTS_NUM; i++)
 
670
                {
 
671
                        if (name != default_options[i].name)
 
672
                                continue;
 
673
 
 
674
                        wxString value = GetTextElement(pSetting);
 
675
                        if (default_options[i].type == string)
 
676
                                default_options[i].value_str = value;
 
677
                        else
 
678
                        {
 
679
                                long v = 0;
 
680
                                if (!value.ToLong(&v))
 
681
                                        v = 0;
 
682
                                default_options[i].value_number = v;
 
683
                        }
 
684
 
 
685
                }
619
686
        }
620
687
}
 
688
 
 
689
int COptions::GetDefaultVal(unsigned int nID) const
 
690
{
 
691
        if (nID >= DEFAULTS_NUM)
 
692
                return 0;
 
693
 
 
694
        return default_options[nID].value_number;
 
695
}
 
696
 
 
697
wxString COptions::GetDefault(unsigned int nID) const
 
698
{
 
699
        if (nID >= DEFAULTS_NUM)
 
700
                return _T("");
 
701
 
 
702
        return default_options[nID].value_str;
 
703
}
 
704
 
 
705
void COptions::OnTimer(wxTimerEvent& event)
 
706
{
 
707
        Save();
 
708
}
 
709
 
 
710
void COptions::Save()
 
711
{
 
712
        if (!m_pXmlFile)
 
713
                return;
 
714
 
 
715
        CInterProcessMutex mutex(MUTEX_OPTIONS);
 
716
        m_pXmlFile->Save();
 
717
}
 
718
 
 
719
void COptions::SaveIfNeeded()
 
720
{
 
721
        if (!m_save_timer.IsRunning())
 
722
                return;
 
723
 
 
724
        m_save_timer.Stop();
 
725
        Save();
 
726
}