File: SFTPQuickConnectDlg.cpp

package info (click to toggle)
codelite 14.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 112,816 kB
  • sloc: cpp: 483,662; ansic: 150,144; php: 9,569; lex: 4,186; python: 3,417; yacc: 2,820; sh: 1,147; makefile: 52; xml: 13
file content (90 lines) | stat: -rw-r--r-- 3,348 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "SFTPQuickConnectDlg.h"
#include "cl_config.h"
#include "sftp_settings.h"
#include "windowattrmanager.h"

SFTPQuickConnectDlg::SFTPQuickConnectDlg(wxWindow* parent)
    : SFTPQuickConnectBaseDlg(parent)
{
    SFTPSettings settings;
    settings.Load();

    // Read previous settings
    bool selecteExistingAccount = true;
    wxString selectedAccount;
    wxString host;
    wxString user;
    wxString port;

    selecteExistingAccount = clConfig::Get().Read("SFTPQuickConnect/ChooseExistingAccount", selecteExistingAccount);
    selectedAccount = clConfig::Get().Read("SFTPQuickConnect/SelectedAccount", selectedAccount);
    host = clConfig::Get().Read("SFTPQuickConnect/Host", wxString());
    user = clConfig::Get().Read("SFTPQuickConnect/User", wxString());
    port = clConfig::Get().Read("SFTPQuickConnect/Port", wxString("22"));

    const SSHAccountInfo::Vect_t& accounts = settings.GetAccounts();
    SSHAccountInfo::Vect_t::const_iterator iter = accounts.begin();
    for(; iter != accounts.end(); ++iter) {
        m_choiceAccount->Append(iter->GetAccountName());
    }
    int where = m_choiceAccount->FindString(selectedAccount);
    if(where != wxNOT_FOUND) { m_choiceAccount->SetSelection(where); }

    m_checkBoxChooseAccount->SetValue(selecteExistingAccount);
    m_checkBoxQuickConnect->SetValue(!selecteExistingAccount);
    m_textCtrlHost->ChangeValue(host);
    m_textCtrlUsername->ChangeValue(user);
    m_textCtrlPort->ChangeValue(port);
    WindowAttrManager::Load(this);
}

SFTPQuickConnectDlg::~SFTPQuickConnectDlg()
{
    clConfig::Get().Write("SFTPQuickConnect/ChooseExistingAccount", m_checkBoxChooseAccount->IsChecked());
    clConfig::Get().Write("SFTPQuickConnect/SelectedAccount", m_choiceAccount->GetStringSelection());
    clConfig::Get().Write("SFTPQuickConnect/Host", m_textCtrlHost->GetValue());
    clConfig::Get().Write("SFTPQuickConnect/User", m_textCtrlUsername->GetValue());
    clConfig::Get().Write("SFTPQuickConnect/Port", m_textCtrlPort->GetValue());
}

void SFTPQuickConnectDlg::OnCheckboxChooseAccount(wxCommandEvent& event)
{
    m_checkBoxQuickConnect->SetValue(!event.IsChecked());
}

void SFTPQuickConnectDlg::OnChooseAccountUI(wxUpdateUIEvent& event)
{
    event.Enable(m_checkBoxChooseAccount->IsChecked());
}

void SFTPQuickConnectDlg::OnOKUI(wxUpdateUIEvent& event) {}

void SFTPQuickConnectDlg::OnQuickConnect(wxCommandEvent& event)
{
    m_checkBoxChooseAccount->SetValue(!event.IsChecked());
}

void SFTPQuickConnectDlg::OnQuickConnectUI(wxUpdateUIEvent& event)
{
    event.Enable(m_checkBoxQuickConnect->IsChecked());
}

SSHAccountInfo SFTPQuickConnectDlg::GetSelectedAccount() const
{
    SSHAccountInfo acc;
    if(m_checkBoxChooseAccount->IsChecked()) {
        SFTPSettings settings;
        settings.Load();
        settings.GetAccount(m_choiceAccount->GetStringSelection(), acc);
    } else {
        // Create a dummy account
        acc.SetUsername(m_textCtrlUsername->GetValue());
        acc.SetAccountName(wxString() << m_textCtrlUsername->GetValue() << "@" << m_textCtrlHost->GetValue());
        acc.SetPassword(m_textCtrlPassword->GetValue());
        acc.SetHost(m_textCtrlHost->GetValue());
        long nPort = 22; // Default is 22
        if(!m_textCtrlPort->GetValue().ToCLong(&nPort)) { nPort = 22; }
        acc.SetPort(nPort);
    }
    return acc;
}