コード例 #1
0
ファイル: SFTPTreeView.cpp プロジェクト: lpc1996/codelite
void SFTPTreeView::OnOpenAccountManager(wxCommandEvent& event)
{
    SSHAccountManagerDlg dlg(EventNotifier::Get()->TopFrame());
    if(dlg.ShowModal() == wxID_OK) {
        SFTPSettings settings;
        settings.Load().SetAccounts(dlg.GetAccounts());
        settings.Save();
    }
}
コード例 #2
0
void SFTPTreeView::OnAddBookmark(wxAuiToolBarEvent& event)
{
    if ( event.IsDropDownClicked() ) {
        
        // Show the menu
        const wxArrayString &bookmarks = m_account.GetBookmarks();
        wxMenu menu;
        for(size_t i=0; i<bookmarks.GetCount(); ++i) {
            menu.Append(ID_SFTP_BOOKMARK_FIRST+i, bookmarks.Item(i));
        }
        menu.AppendSeparator();
        menu.Append(ID_SFTP_BOOKMARK_SETTINGS, _("Manage bookmarks..."));
        
        wxPoint pt = event.GetItemRect().GetBottomLeft();
        pt.y++;
        
        int sel = m_auibar->GetPopupMenuSelectionFromUser( menu, pt );
        if ( sel >= ID_SFTP_BOOKMARK_FIRST && sel <= ID_SFTP_BOOKMARK_LAST ) {
            // A bookmark was selected
            CallAfter( &SFTPTreeView::DoBuildTree, bookmarks.Item(sel - ID_SFTP_BOOKMARK_FIRST) );
            
        } else if ( sel == ID_SFTP_BOOKMARK_SETTINGS ) {
            // Bookmark settings
            CallAfter( &SFTPTreeView::ManageBookmarks );
        }
        
    } else {
        try {
            // sanity
            if ( !m_sftp || !m_sftp->IsConnected() ) {
                return;
            }
            
            // Get the current selection
            MyClientDataVect_t selections = GetSelectionsItemData();
            if ( selections.size() != 1 )
                return;

            MyClientData* cd = selections.at(0);
            CHECK_PTR_RET( cd );
            
            if ( !cd->IsFolder() )
                return;
            
            m_account.AddBookmark( cd->GetFullPath() );
            SFTPSettings settings;
            settings.Load();
            settings.UpdateAccount( m_account );
            settings.Save();

        } catch (clException &e) {
            ::wxMessageBox(e.What(), "SFTP", wxICON_ERROR|wxOK|wxCENTER);
        }
    }
}
コード例 #3
0
ファイル: SFTPTreeView.cpp プロジェクト: Jactry/codelite
void SFTPTreeView::ManageBookmarks()
{
    SFTPManageBookmarkDlg dlg(NULL, m_account.GetBookmarks());
    if(dlg.ShowModal() == wxID_OK) {
        m_account.SetBookmarks(dlg.GetBookmarks());
        SFTPSettings settings;
        settings.Load();
        settings.UpdateAccount(m_account);
        settings.Save();
    }
}
コード例 #4
0
ファイル: sftp.cpp プロジェクト: Jactry/codelite
void SFTP::OnAccountManager(wxCommandEvent& e)
{
    wxUnusedVar(e);
    SSHAccountManagerDlg dlg(wxTheApp->GetTopWindow());
    if(dlg.ShowModal() == wxID_OK) {

        SFTPSettings settings;
        settings.Load();
        settings.SetAccounts(dlg.GetAccounts());
        settings.Save();
    }
}
コード例 #5
0
ファイル: SFTPTreeView.cpp プロジェクト: Jactry/codelite
void SFTPTreeView::OnOpenAccountManager(wxCommandEvent& event)
{
    SSHAccountManagerDlg dlg(this);
    if(dlg.ShowModal() == wxID_OK) {

        SFTPSettings settings;
        settings.Load();
        settings.SetAccounts(dlg.GetAccounts());
        settings.Save();

        // Update the selections at the top
        wxString curselection = m_choiceAccount->GetStringSelection();

        m_choiceAccount->Clear();
        const SSHAccountInfo::Vect_t& accounts = settings.GetAccounts();
        if(accounts.empty()) {
            DoCloseSession();
            return;

        } else {
            SSHAccountInfo::Vect_t::const_iterator iter = accounts.begin();
            for(; iter != accounts.end(); ++iter) {
                m_choiceAccount->Append(iter->GetAccountName());
            }

            int where = m_choiceAccount->FindString(curselection);
            if(where == wxNOT_FOUND) {
                // Our previous session is no longer available, close the session
                DoCloseSession();
                where = 0;
            }

            m_choiceAccount->SetSelection(where);
        }
    }
}
コード例 #6
0
ファイル: SFTPTreeView.cpp プロジェクト: lpc1996/codelite
void SFTPTreeView::DoOpenSession()
{
    DoCloseSession();
    if(!GetAccountFromUser(m_account)) { return; }

    wxString message;
    wxProgressDialog dlg(_("SFTP"), wxString(' ', 100) + "\n\n", 10);
    dlg.Show();
    dlg.Update(1, wxString() << _("Connecting to: ") << m_account.GetAccountName() << "..."
                             << _("\n(this may take a few seconds)"));

    // We know that there is a bug that libssh succeeded on connecting only on the second attempt..
    // to workaround it, we issue first connect with 1 second timeout, and then re-open the connection
    try {
        clSSH::Ptr_t ssh(
            new clSSH(m_account.GetHost(), m_account.GetUsername(), m_account.GetPassword(), m_account.GetPort()));
        ssh->Connect(wxNOT_FOUND);
    } catch(...) {
    }

    try {
        clSSH::Ptr_t ssh(
            new clSSH(m_account.GetHost(), m_account.GetUsername(), m_account.GetPassword(), m_account.GetPort()));
        ssh->Connect(5);
        dlg.Update(5, _("Connected!"));
        dlg.Update(6, _("Authenticating server..."));

        if(!ssh->AuthenticateServer(message)) {
            if(::wxMessageBox(message, "SSH", wxYES_NO | wxCENTER | wxICON_QUESTION) == wxYES) {
                dlg.Update(7, _("Accepting server authentication server..."));
                ssh->AcceptServerAuthentication();
            }
        } else {
            dlg.Update(7, _("Server authenticated"));
        }

        dlg.Update(8, _("Logging in.."));
        ssh->Login();
        m_sftp.reset(new clSFTP(ssh));
        m_sftp->Initialize();
        m_sftp->SetAccount(m_account.GetAccountName());
        m_plugin->GetManager()->SetStatusMessage(wxString() << _("Done!"));

        dlg.Update(9, _("Fetching directory list..."));
        DoBuildTree(m_account.GetDefaultFolder().IsEmpty() ? "/" : m_account.GetDefaultFolder());
        dlg.Update(10, _("Done"));

        CallAfter(&SFTPTreeView::DoLoadSession);

        // If this is a new account, offer the user to save it
        SFTPSettings s;
        s.Load();
        SSHAccountInfo dummy;
        if(!s.GetAccount(m_account.GetAccountName(), dummy)) {
            wxString message;
            message << _("Would you like to save this account?\n") << _("It will be saved as '")
                    << m_account.GetAccountName() << "'";
            wxStandardID res = ::PromptForYesNoCancelDialogWithCheckbox(message, "SFTPQuickConnectSaveDlg");
            if(res == wxID_YES) {
                // This 'Connect' was via Quick Connect option
                SSHAccountInfo::Vect_t accounts = s.GetAccounts();
                accounts.push_back(m_account);
                s.SetAccounts(accounts);
                s.Save();
            }
        }

    } catch(clException& e) {
        ::wxMessageBox(e.What(), "CodeLite", wxICON_ERROR | wxOK);
        DoCloseSession();
    }
}