| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557 |
- //---------------------------------------------------------------------
- #include <vcl.h>
- #pragma hdrstop
- #include <StrUtils.hpp>
- #include <CoreMain.h>
- #include <Common.h>
- #include <PuttyTools.h>
- #include <TextsWin.h>
- #include <TextsCore.h>
- #include <HelpWin.h>
- #include <VCLCommon.h>
- #include "WinInterface.h"
- #include "Login.h"
- #include "GUITools.h"
- #include "Tools.h"
- #include "Setup.h"
- #include "WinConfiguration.h"
- //---------------------------------------------------------------------
- #pragma link "ComboEdit"
- #pragma link "GeneralSettings"
- #pragma link "LogSettings"
- #pragma link "PasswordEdit"
- #pragma link "UpDownEdit"
- #ifndef NO_RESOURCES
- #pragma resource "*.dfm"
- #endif
- //---------------------------------------------------------------------------
- // Sheet tag:
- // 01 top, 02 indented
- //---------------------------------------------------------------------------
- const int OpenFolderStateIndex = 2;
- const int ClosedFolderStateIndex = 3;
- const int WorkspaceStateIndex = 4;
- //---------------------------------------------------------------------------
- bool __fastcall DoLoginDialog(TStoredSessionList *SessionList,
- TList * DataList, int Options)
- {
- assert(DataList != NULL);
- TLoginDialog * LoginDialog = SafeFormCreate<TLoginDialog>();
- bool Result;
- try
- {
- LoginDialog->Init(SessionList, Options);
- Result = LoginDialog->Execute(DataList);
- }
- __finally
- {
- delete LoginDialog;
- }
- return Result;
- }
- //---------------------------------------------------------------------
- static const TFSProtocol FSOrder[] = { fsSFTPonly, fsSCPonly, fsFTP, fsWebDAV };
- static const UnicodeString DefaultRecycleBinPath = L"/tmp";
- //---------------------------------------------------------------------
- __fastcall TLoginDialog::TLoginDialog(TComponent* AOwner)
- : TForm(AOwner)
- {
- FSessionData = new TSessionData(L"");
- NoUpdate = 0;
- FLanguagesPopupMenu = NULL;
- FInitialized = false;
- FSavedTab = NULL;
- FSavedSession = -1;
- FOptions = loStartup;
- FLocaleChanging = false;
- FColor = (TColor)0;
- FEditingSessionData = NULL;
- FTreeLabels = new TStringList();
- FHintNode = NULL;
- FScrollOnDragOver = new TTreeViewScrollOnDragOver(SessionTree, true);
- FDataList = NULL;
- FUpdatePortWithProtocol = true;
- FIncrementalSearching = 0;
- FSitesIncrementalSearchHaveNext = false;
- // we need to make sure that window procedure is set asap
- // (so that CM_SHOWINGCHANGED handling is applied)
- UseSystemSettingsPre(this, &FSystemSettings);
- InitControls();
- }
- //---------------------------------------------------------------------
- __fastcall TLoginDialog::~TLoginDialog()
- {
- delete FScrollOnDragOver;
- assert(FSystemSettings);
- DeleteSystemSettings(this, FSystemSettings);
- FSystemSettings = NULL;
- delete FTreeLabels;
- delete FSessionData;
- delete FLanguagesPopupMenu;
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::Init(TStoredSessionList *SessionList,
- int Options)
- {
- FStoredSessions = SessionList;
- LoadSessions();
- FOptions = Options;
- UnicodeString Dummy;
- RunPageantAction->Visible = FindTool(PageantTool, Dummy);
- RunPuttygenAction->Visible = FindTool(PuttygenTool, Dummy);
- UpdateControls();
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::InitControls()
- {
- LoggingFrame->Init();
- ComboAutoSwitchInitialize(UtfCombo);
- ComboAutoSwitchInitialize(BugIgnore1Combo);
- ComboAutoSwitchInitialize(BugPlainPW1Combo);
- ComboAutoSwitchInitialize(BugRSA1Combo);
- ComboAutoSwitchInitialize(BugHMAC2Combo);
- ComboAutoSwitchInitialize(BugDeriveKey2Combo);
- ComboAutoSwitchInitialize(BugRSAPad2Combo);
- ComboAutoSwitchInitialize(BugPKSessID2Combo);
- ComboAutoSwitchInitialize(BugRekey2Combo);
- ComboAutoSwitchInitialize(BugMaxPkt2Combo);
- ComboAutoSwitchInitialize(BugIgnore2Combo);
- ComboAutoSwitchInitialize(SFTPBugSymlinkCombo);
- ComboAutoSwitchInitialize(SFTPBugSignedTSCombo);
- ComboAutoSwitchInitialize(FtpListAllCombo);
- ComboAutoSwitchInitialize(FtpUseMlsdCombo);
- ComboAutoSwitchInitialize(FtpForcePasvIpCombo);
- TunnelLocalPortNumberEdit->Items->BeginUpdate();
- try
- {
- UnicodeString TunnelLocalPortNumberAutoassign = TunnelLocalPortNumberEdit->Items->Strings[0];
- TunnelLocalPortNumberEdit->Items->Clear();
- TunnelLocalPortNumberEdit->Items->Add(TunnelLocalPortNumberAutoassign);
- for (int Index = Configuration->TunnelLocalPortNumberLow;
- Index <= Configuration->TunnelLocalPortNumberHigh; Index++)
- {
- TunnelLocalPortNumberEdit->Items->Add(IntToStr(Index));
- }
- }
- __finally
- {
- TunnelLocalPortNumberEdit->Items->EndUpdate();
- }
- HintLabel(ProxyTelnetCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
- HintLabel(ProxyLocalCommandHintText, LoadStr(LOGIN_PROXY_COMMAND_PATTERNS_HINT));
- if (SessionTree->WindowProc != SessionTreeProc)
- {
- FOldSessionTreeProc = SessionTree->WindowProc;
- SessionTree->WindowProc = SessionTreeProc;
- }
- FtpsCombo->Items->Strings[1] = LoadStr(FTPS_IMPLICIT);
- FtpsCombo->Items->Strings[2] = LoadStr(FTPS_EXPLICIT_SSL);
- FtpsCombo->Items->Strings[3] = LoadStr(FTPS_EXPLICIT_TLS);
- WebDavsCombo->Items->Strings[0] = FtpsCombo->Items->Strings[0];
- WebDavsCombo->Items->Strings[1] = FtpsCombo->Items->Strings[1];
- BasicSshGroup->Top = BasicFtpGroup->Top;
- SitesIncrementalSearchLabel->AutoSize = false;
- SitesIncrementalSearchLabel->Left = SessionTree->Left;
- SitesIncrementalSearchLabel->Width = SessionTree->Width;
- SitesIncrementalSearchLabel->Top = SessionTree->BoundsRect.Bottom - SitesIncrementalSearchLabel->Height;
- SitesIncrementalSearchLabel->Visible = false;
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::Init()
- {
- if (!FInitialized)
- {
- UseSystemSettingsPost(this, FSystemSettings);
- }
- else
- {
- UseSystemSettings(this, &FSystemSettings);
- }
- FInitialized = true;
- InstallPathWordBreakProc(RemoteDirectoryEdit);
- InstallPathWordBreakProc(LocalDirectoryEdit);
- InstallPathWordBreakProc(PrivateKeyEdit);
- InstallPathWordBreakProc(RecycleBinPathEdit);
- Caption = FORMAT(L"%s %s", (AppName, Caption));
- InitControls();
- FTreeLabels->Clear();
- int Index = 0;
- while (Index < PageControl->PageCount)
- {
- FTreeLabels->Add(PageControl->Pages[Index]->Caption);
- PageControl->Pages[Index]->Caption = L"";
- Index++;
- }
- UpdateNavigationTree();
- if ((FOptions & loLocalDirectory) == 0)
- {
- LocalDirectoryLabel->Visible = false;
- LocalDirectoryEdit->Visible = false;
- LocalDirectoryDescLabel->Visible = false;
- DirectoriesGroup->Height = RemoteDirectoryEdit->Top + RemoteDirectoryEdit->Height + 12;
- DirectoryOptionsGroup->Top = DirectoriesGroup->Top + DirectoriesGroup->Height + 8;
- }
- #ifdef NO_FILEZILLA
- assert(TransferProtocolCombo->Items->Count == FSPROTOCOL_COUNT - 2 - 1);
- TransferProtocolCombo->Items->Delete(TransferProtocolCombo->Items->Count - 1);
- #endif
- if ((StoredSessions && StoredSessions->Count &&
- (FSessionData->Name == StoredSessions->DefaultSettings->Name)) ||
- FLAGSET(FOptions, loSiteManager))
- {
- ChangePage(SessionListSheet);
- if (SessionTree->Items->Count > 0)
- {
- ActiveControl = SessionTree;
- SessionTree->Selected = SessionTree->Items->GetFirstNode();
- }
- else
- {
- ActiveControl = NewButton;
- }
- }
- else
- {
- EditSession();
- }
- UpdateControls();
- }
- //---------------------------------------------------------------------
- TTreeNode * __fastcall TLoginDialog::AddSessionPath(UnicodeString Path,
- bool CanCreate, bool IsWorkspace)
- {
- TTreeNode * Parent = NULL;
- while (!Path.IsEmpty())
- {
- UnicodeString Folder = ::CutToChar(Path, L'/', false);
- TTreeNode * Node =
- ((Parent == NULL) ? SessionTree->Items->GetFirstNode() : Parent->getFirstChild());
- // note that we allow folder with the same name as existing session
- // on the same level (see also SessionTreeEdited)
- while ((Node != NULL) && (IsSessionNode(Node) || !AnsiSameText(Node->Text, Folder)))
- {
- Node = Node->getNextSibling();
- }
- if (Node == NULL)
- {
- if (!CanCreate)
- {
- return NULL;
- }
- else
- {
- TTreeNode * AParent = Parent;
- Parent = SessionTree->Items->AddChild(Parent, Folder);
- // once workspace, forever workspace
- if (!IsWorkspaceNode(Parent))
- {
- if (IsWorkspace)
- {
- Parent->StateIndex = WorkspaceStateIndex;
- }
- else
- {
- UpdateFolderNode(Parent);
- }
- }
- // folders seem not to be sorted automatically (not having set the data property)
- if (AParent == NULL)
- {
- SessionTree->Items->AlphaSort();
- }
- else
- {
- AParent->AlphaSort();
- }
- }
- }
- else
- {
- Parent = Node;
- }
- }
- return Parent;
- }
- //---------------------------------------------------------------------
- bool __fastcall TLoginDialog::IsFolderNode(TTreeNode * Node)
- {
- return (Node != NULL) && (Node->Data == NULL) && (Node->StateIndex != WorkspaceStateIndex);
- }
- //---------------------------------------------------------------------
- bool __fastcall TLoginDialog::IsWorkspaceNode(TTreeNode * Node)
- {
- return (Node != NULL) && (Node->Data == NULL) && (Node->StateIndex == WorkspaceStateIndex);
- }
- //---------------------------------------------------------------------
- bool __fastcall TLoginDialog::IsFolderOrWorkspaceNode(TTreeNode * Node)
- {
- return (Node != NULL) && (Node->Data == NULL);
- }
- //---------------------------------------------------------------------
- bool __fastcall TLoginDialog::IsSessionNode(TTreeNode * Node)
- {
- return (Node != NULL) && (Node->Data != NULL);
- }
- //---------------------------------------------------------------------
- TSessionData * __fastcall TLoginDialog::GetNodeSession(TTreeNode * Node)
- {
- TSessionData * Data = static_cast<TSessionData *>(Node->Data);
- assert(Data != NULL);
- return Data;
- }
- //---------------------------------------------------------------------
- TTreeNode * __fastcall TLoginDialog::AddSession(TSessionData * Data)
- {
- TTreeNode * Parent = AddSessionPath(UnixExtractFilePath(Data->Name), true, Data->IsWorkspace);
- TTreeNode * Node = SessionTree->Items->AddChild(Parent, UnixExtractFileName(Data->Name));
- Node->Data = Data;
- return Node;
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::DestroySession(TSessionData * Data)
- {
- if (FEditingSessionData == Data)
- {
- FEditingSessionData = NULL;
- }
- StoredSessions->Remove(Data);
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::LoadSessions()
- {
- SessionTree->Items->BeginUpdate();
- try
- {
- SessionTree->Items->Clear();
- assert(StoredSessions != NULL);
- for (int Index = 0; Index < StoredSessions->Count; Index++)
- {
- AddSession(StoredSessions->Sessions[Index]);
- }
- }
- __finally
- {
- // folders seem not to be sorted automatically (not having set the data property)
- SessionTree->AlphaSort();
- SessionTree->Items->EndUpdate();
- }
- SessionTree->Selected = SessionTree->Items->GetFirstNode();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::UpdateFolderNode(TTreeNode * Node)
- {
- assert((Node->StateIndex == -1) ||
- (Node->StateIndex == OpenFolderStateIndex) || (Node->StateIndex == ClosedFolderStateIndex));
- Node->StateIndex = (Node->Expanded ? OpenFolderStateIndex : ClosedFolderStateIndex);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::Default()
- {
- if (StoredSessions)
- {
- FSessionData->Assign(StoredSessions->DefaultSettings);
- }
- else
- {
- FSessionData->Default();
- }
- FEditingSessionData = NULL;
- LoadSession(FSessionData);
- FCurrentSessionName = "";
- FUpdatePortWithProtocol = true;
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::LoadSession(TSessionData * aSessionData)
- {
- // it was always true
- assert(aSessionData == FSessionData);
- NoUpdate++;
- try
- {
- // Basic tab
- UserNameEdit->Text = aSessionData->UserName;
- PortNumberEdit->AsInteger = aSessionData->PortNumber;
- HostNameEdit->Text = aSessionData->HostName;
- PasswordEdit->Text = aSessionData->Password;
- FtpAccountEdit->Text = aSessionData->FtpAccount;
- PrivateKeyEdit->Text = aSessionData->PublicKeyFile;
- FtpsCombo->ItemIndex = aSessionData->Ftps;
- WebDavsCombo->ItemIndex = aSessionData->Ftps;
- FColor = (TColor)aSessionData->Color;
- bool AllowScpFallback;
- TransferProtocolCombo->ItemIndex =
- FSProtocolToIndex(aSessionData->FSProtocol, AllowScpFallback);
- AllowScpFallbackCheck->Checked = AllowScpFallback;
- FDefaultPort = DefaultPort();
- // Directories tab
- SynchronizeBrowsingCheck->Checked = aSessionData->SynchronizeBrowsing;
- LocalDirectoryEdit->Text = aSessionData->LocalDirectory;
- RemoteDirectoryEdit->Text = aSessionData->RemoteDirectory;
- UpdateDirectoriesCheck->Checked = aSessionData->UpdateDirectories;
- CacheDirectoriesCheck->Checked = aSessionData->CacheDirectories;
- CacheDirectoryChangesCheck->Checked = aSessionData->CacheDirectoryChanges;
- PreserveDirectoryChangesCheck->Checked = aSessionData->PreserveDirectoryChanges;
- ResolveSymlinksCheck->Checked = aSessionData->ResolveSymlinks;
- // Environment tab
- switch (aSessionData->DSTMode)
- {
- case dstmWin:
- DSTModeWinCheck->Checked = true;
- break;
- case dstmKeep:
- DSTModeKeepCheck->Checked = true;
- break;
- default:
- case dstmUnix:
- DSTModeUnixCheck->Checked = true;
- break;
- }
- if (aSessionData->EOLType == eolLF)
- {
- EOLTypeCombo->ItemIndex = 0;
- }
- else
- {
- EOLTypeCombo->ItemIndex = 1;
- }
- switch (aSessionData->NotUtf)
- {
- case asOn:
- UtfCombo->ItemIndex = 1;
- break;
- case asOff:
- UtfCombo->ItemIndex = 2;
- break;
- default:
- UtfCombo->ItemIndex = 0;
- break;
- }
- int TimeDifferenceMin = TimeToMinutes(aSessionData->TimeDifference);
- TimeDifferenceEdit->AsInteger = TimeDifferenceMin / MinsPerHour;
- TimeDifferenceMinutesEdit->AsInteger = TimeDifferenceMin % MinsPerHour;
- // Environment/Recycle bin tab
- DeleteToRecycleBinCheck->Checked = aSessionData->DeleteToRecycleBin;
- OverwrittenToRecycleBinCheck->Checked = aSessionData->OverwrittenToRecycleBin;
- RecycleBinPathEdit->Text =
- !aSessionData->RecycleBinPath.IsEmpty() ?
- aSessionData->RecycleBinPath : DefaultRecycleBinPath;
- // SFTP tab
- if (aSessionData->SftpServer.IsEmpty())
- {
- SftpServerEdit->Text = SftpServerEdit->Items->Strings[0];
- }
- else
- {
- SftpServerEdit->Text = aSessionData->SftpServer;
- }
- // hide selection, which is wrongly shown initially even when the box has not focus
- SftpServerEdit->SelLength = 0;
- SFTPMaxVersionCombo->ItemIndex = aSessionData->SFTPMaxVersion;
- #define LOAD_SFTP_BUG_COMBO(BUG) \
- ComboAutoSwitchLoad(SFTPBug ## BUG ## Combo, aSessionData->SFTPBug[sb ## BUG])
- LOAD_SFTP_BUG_COMBO(Symlink);
- LOAD_SFTP_BUG_COMBO(SignedTS);
- #undef LOAD_SFTP_BUG_COMBO
- // FTP tab
- PostLoginCommandsMemo->Lines->Text = aSessionData->PostLoginCommands;
- ComboAutoSwitchLoad(FtpListAllCombo, aSessionData->FtpListAll);
- ComboAutoSwitchLoad(FtpUseMlsdCombo, aSessionData->FtpUseMlsd);
- ComboAutoSwitchLoad(FtpForcePasvIpCombo, aSessionData->FtpForcePasvIp);
- // Authentication tab
- SshNoUserAuthCheck->Checked = aSessionData->SshNoUserAuth;
- TryAgentCheck->Checked = aSessionData->TryAgent;
- AuthTISCheck->Checked = aSessionData->AuthTIS;
- AuthKICheck->Checked = aSessionData->AuthKI;
- AuthKIPasswordCheck->Checked = aSessionData->AuthKIPassword;
- AuthGSSAPICheck3->Checked = aSessionData->AuthGSSAPI;
- GSSAPIFwdTGTCheck->Checked = aSessionData->GSSAPIFwdTGT;
- AgentFwdCheck->Checked = aSessionData->AgentFwd;
- // SSH tab
- Ssh2LegacyDESCheck->Checked = aSessionData->Ssh2DES;
- CompressionCheck->Checked = aSessionData->Compression;
- switch (aSessionData->SshProt) {
- case ssh1only: SshProt1onlyButton->Checked = true; break;
- case ssh1: SshProt1Button->Checked = true; break;
- case ssh2: SshProt2Button->Checked = true; break;
- case ssh2only: SshProt2onlyButton->Checked = true; break;
- }
- CipherListBox->Items->Clear();
- assert(CIPHER_NAME_WARN+CIPHER_COUNT-1 == CIPHER_NAME_ARCFOUR);
- for (int Index = 0; Index < CIPHER_COUNT; Index++)
- {
- CipherListBox->Items->AddObject(
- LoadStr(CIPHER_NAME_WARN+aSessionData->Cipher[Index]),
- (TObject*)aSessionData->Cipher[Index]);
- }
- // KEX tab
- KexListBox->Items->Clear();
- assert(KEX_NAME_WARN+KEX_COUNT-1 == KEX_NAME_RSA);
- for (int Index = 0; Index < KEX_COUNT; Index++)
- {
- KexListBox->Items->AddObject(
- LoadStr(KEX_NAME_WARN+aSessionData->Kex[Index]),
- (TObject*)aSessionData->Kex[Index]);
- }
- RekeyTimeEdit->AsInteger = aSessionData->RekeyTime;
- RekeyDataEdit->Text = aSessionData->RekeyData;
- // Connection tab
- FtpPasvModeCheck->Checked = aSessionData->FtpPasvMode;
- BufferSizeCheck->Checked = (aSessionData->SendBuf > 0) && aSessionData->SshSimple;
- switch (aSessionData->PingType)
- {
- case ptNullPacket:
- PingNullPacketButton->Checked = true;
- break;
- case ptDummyCommand:
- PingDummyCommandButton->Checked = true;
- break;
- default:
- PingOffButton->Checked = true;
- break;
- }
- PingIntervalSecEdit->AsInteger = aSessionData->PingInterval;
- switch (aSessionData->FtpPingType)
- {
- case ptDummyCommand:
- FtpPingDummyCommandButton->Checked = true;
- break;
- default:
- FtpPingOffButton->Checked = true;
- break;
- }
- FtpPingIntervalSecEdit->AsInteger = aSessionData->FtpPingInterval;
- TimeoutEdit->AsInteger = aSessionData->Timeout;
- switch (aSessionData->AddressFamily)
- {
- case afIPv4:
- IPv4Button->Checked = true;
- break;
- case afIPv6:
- IPv6Button->Checked = true;
- break;
- case afAuto:
- default:
- IPAutoButton->Checked = true;
- break;
- }
- // Shell tab
- if (aSessionData->DefaultShell)
- {
- ShellEdit->Text = ShellEdit->Items->Strings[0];
- }
- else
- {
- ShellEdit->Text = aSessionData->Shell;
- }
- // hide selection, which is wrongly shown initially even when the box has not focus
- ShellEdit->SelLength = 0;
- if (aSessionData->DetectReturnVar)
- {
- ReturnVarEdit->Text = ReturnVarEdit->Items->Strings[0];
- }
- else
- {
- ReturnVarEdit->Text = aSessionData->ReturnVar;
- }
- ReturnVarEdit->SelLength = 0;
- ListingCommandEdit->Text = aSessionData->ListingCommand;
- ListingCommandEdit->SelLength = 0;
- CheckBoxAutoSwitchLoad(LookupUserGroupsCheck, aSessionData->LookupUserGroups);
- ClearAliasesCheck->Checked = aSessionData->ClearAliases;
- IgnoreLsWarningsCheck->Checked = aSessionData->IgnoreLsWarnings;
- Scp1CompatibilityCheck->Checked = aSessionData->Scp1Compatibility;
- UnsetNationalVarsCheck->Checked = aSessionData->UnsetNationalVars;
- SCPLsFullTimeAutoCheck->Checked = (aSessionData->SCPLsFullTime != asOff);
- // Proxy tab
- SshProxyMethodCombo->ItemIndex = aSessionData->ProxyMethod;
- FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(aSessionData->ProxyMethod);
- if (aSessionData->FtpProxyLogonType != 0)
- {
- FtpProxyMethodCombo->ItemIndex = LastSupportedFtpProxyMethod() + aSessionData->FtpProxyLogonType;
- }
- WebDavProxyMethodCombo->ItemIndex = GetSupportedWebDavProxyMethod(aSessionData->ProxyMethod);
- ProxyHostEdit->Text = aSessionData->ProxyHost;
- ProxyPortEdit->AsInteger = aSessionData->ProxyPort;
- ProxyUsernameEdit->Text = aSessionData->ProxyUsername;
- ProxyPasswordEdit->Text = aSessionData->ProxyPassword;
- ProxyTelnetCommandEdit->Text = aSessionData->ProxyTelnetCommand;
- ProxyLocalCommandEdit->Text = aSessionData->ProxyLocalCommand;
- ProxyLocalhostCheck->Checked = aSessionData->ProxyLocalhost;
- ProxyDNSCombo->ItemIndex = 2 - aSessionData->ProxyDNS;
- // Bugs tab
- #define LOAD_BUG_COMBO(BUG) \
- ComboAutoSwitchLoad(Bug ## BUG ## Combo, aSessionData->Bug[sb ## BUG])
- LOAD_BUG_COMBO(Ignore1);
- LOAD_BUG_COMBO(PlainPW1);
- LOAD_BUG_COMBO(RSA1);
- LOAD_BUG_COMBO(HMAC2);
- LOAD_BUG_COMBO(DeriveKey2);
- LOAD_BUG_COMBO(RSAPad2);
- LOAD_BUG_COMBO(PKSessID2);
- LOAD_BUG_COMBO(Rekey2);
- LOAD_BUG_COMBO(MaxPkt2);
- LOAD_BUG_COMBO(Ignore2);
- #undef LOAD_BUG_COMBO
- // Tunnel tab
- TunnelCheck->Checked = aSessionData->Tunnel;
- TunnelUserNameEdit->Text = aSessionData->TunnelUserName;
- TunnelPortNumberEdit->AsInteger = aSessionData->TunnelPortNumber;
- TunnelHostNameEdit->Text = aSessionData->TunnelHostName;
- TunnelPasswordEdit->Text = aSessionData->TunnelPassword;
- TunnelPrivateKeyEdit->Text = aSessionData->TunnelPublicKeyFile;
- if (aSessionData->TunnelAutoassignLocalPortNumber)
- {
- TunnelLocalPortNumberEdit->Text = TunnelLocalPortNumberEdit->Items->Strings[0];
- }
- else
- {
- TunnelLocalPortNumberEdit->Text = IntToStr(aSessionData->TunnelLocalPortNumber);
- }
- // hide selection, which is wrongly shown initially even when the box has not focus
- TunnelLocalPortNumberEdit->SelLength = 0;
- }
- __finally
- {
- NoUpdate--;
- UpdateControls();
- }
- if (UnixExtractFileName(aSessionData->Name) != aSessionData->DefaultSessionName)
- {
- FCurrentSessionName = aSessionData->Name;
- }
- else
- {
- FCurrentSessionName = L"";
- }
- FUpdatePortWithProtocol = true;
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::SaveSession(TSessionData * aSessionData)
- {
- // it was always true
- assert(aSessionData == FSessionData);
- // Basic tab
- aSessionData->UserName = UserNameEdit->Text.Trim();
- aSessionData->PortNumber = PortNumberEdit->AsInteger;
- // must be loaded after UserName, because HostName may be in format user@host
- aSessionData->HostName = HostNameEdit->Text.Trim();
- aSessionData->Password = PasswordEdit->Text;
- aSessionData->FtpAccount = FtpAccountEdit->Text;
- aSessionData->PublicKeyFile = PrivateKeyEdit->Text;
- aSessionData->Ftps = GetFtps();
- aSessionData->Color = FColor;
- aSessionData->FSProtocol = GetFSProtocol();
- // SSH tab
- aSessionData->Compression = CompressionCheck->Checked;
- aSessionData->Ssh2DES = Ssh2LegacyDESCheck->Checked;
- if (SshProt1onlyButton->Checked) aSessionData->SshProt = ssh1only;
- else
- if (SshProt1Button->Checked) aSessionData->SshProt = ssh1;
- else
- if (SshProt2Button->Checked) aSessionData->SshProt = ssh2;
- else aSessionData->SshProt = ssh2only;
- for (int Index = 0; Index < CIPHER_COUNT; Index++)
- {
- aSessionData->Cipher[Index] = (TCipher)CipherListBox->Items->Objects[Index];
- }
- // Kex tab
- for (int Index = 0; Index < KEX_COUNT; Index++)
- {
- aSessionData->Kex[Index] = (TKex)KexListBox->Items->Objects[Index];
- }
- aSessionData->RekeyTime = RekeyTimeEdit->AsInteger;
- aSessionData->RekeyData = RekeyDataEdit->Text;
- // Authentication tab
- aSessionData->SshNoUserAuth = SshNoUserAuthCheck->Checked;
- aSessionData->TryAgent = TryAgentCheck->Checked;
- aSessionData->AuthTIS = AuthTISCheck->Checked;
- aSessionData->AuthKI = AuthKICheck->Checked;
- aSessionData->AuthKIPassword = AuthKIPasswordCheck->Checked;
- aSessionData->AuthGSSAPI = AuthGSSAPICheck3->Checked;
- aSessionData->GSSAPIFwdTGT = GSSAPIFwdTGTCheck->Checked;
- aSessionData->AgentFwd = AgentFwdCheck->Checked;
- // Connection tab
- aSessionData->FtpPasvMode = FtpPasvModeCheck->Checked;
- aSessionData->SendBuf = BufferSizeCheck->Checked ? DefaultSendBuf : 0;
- aSessionData->SshSimple = BufferSizeCheck->Checked;
- if (PingNullPacketButton->Checked)
- {
- aSessionData->PingType = ptNullPacket;
- }
- else if (PingDummyCommandButton->Checked)
- {
- aSessionData->PingType = ptDummyCommand;
- }
- else
- {
- aSessionData->PingType = ptOff;
- }
- aSessionData->PingInterval = PingIntervalSecEdit->AsInteger;
- aSessionData->FtpPingType = (FtpPingDummyCommandButton->Checked ? ptDummyCommand : ptOff);
- aSessionData->FtpPingInterval = FtpPingIntervalSecEdit->AsInteger;
- aSessionData->Timeout = TimeoutEdit->AsInteger;
- if (IPv4Button->Checked)
- {
- aSessionData->AddressFamily = afIPv4;
- }
- else if (IPv6Button->Checked)
- {
- aSessionData->AddressFamily = afIPv6;
- }
- else
- {
- aSessionData->AddressFamily = afAuto;
- }
- // Directories tab
- aSessionData->SynchronizeBrowsing = SynchronizeBrowsingCheck->Checked;
- aSessionData->LocalDirectory = LocalDirectoryEdit->Text;
- aSessionData->RemoteDirectory = RemoteDirectoryEdit->Text;
- aSessionData->UpdateDirectories = UpdateDirectoriesCheck->Checked;
- aSessionData->CacheDirectories = CacheDirectoriesCheck->Checked;
- aSessionData->CacheDirectoryChanges = CacheDirectoryChangesCheck->Checked;
- aSessionData->PreserveDirectoryChanges = PreserveDirectoryChangesCheck->Checked;
- aSessionData->ResolveSymlinks = ResolveSymlinksCheck->Checked;
- // Environment tab
- if (DSTModeUnixCheck->Checked) aSessionData->DSTMode = dstmUnix;
- else
- if (DSTModeKeepCheck->Checked) aSessionData->DSTMode = dstmKeep;
- else aSessionData->DSTMode = dstmWin;
- if (EOLTypeCombo->ItemIndex == 0) aSessionData->EOLType = eolLF;
- else aSessionData->EOLType = eolCRLF;
- switch (UtfCombo->ItemIndex)
- {
- case 1:
- aSessionData->NotUtf = asOn;
- break;
- case 2:
- aSessionData->NotUtf = asOff;
- break;
- default:
- aSessionData->NotUtf = asAuto;
- break;
- }
- aSessionData->TimeDifference =
- (double(TimeDifferenceEdit->AsInteger) / HoursPerDay) +
- (double(TimeDifferenceMinutesEdit->AsInteger) / MinsPerDay);
- // Environment/Recycle bin tab
- aSessionData->DeleteToRecycleBin = DeleteToRecycleBinCheck->Checked;
- aSessionData->OverwrittenToRecycleBin = OverwrittenToRecycleBinCheck->Checked;
- aSessionData->RecycleBinPath =
- aSessionData->DeleteToRecycleBin || aSessionData->OverwrittenToRecycleBin ||
- (RecycleBinPathEdit->Text != DefaultRecycleBinPath) ?
- RecycleBinPathEdit->Text : UnicodeString();
- // SCP tab
- aSessionData->DefaultShell = (ShellEdit->Text == ShellEdit->Items->Strings[0]);
- aSessionData->Shell = (aSessionData->DefaultShell ? UnicodeString() : ShellEdit->Text);
- aSessionData->DetectReturnVar = (ReturnVarEdit->Text == ReturnVarEdit->Items->Strings[0]);
- aSessionData->ReturnVar = (aSessionData->DetectReturnVar ? UnicodeString() : ReturnVarEdit->Text);
- aSessionData->ListingCommand = ListingCommandEdit->Text;
- aSessionData->LookupUserGroups = CheckBoxAutoSwitchSave(LookupUserGroupsCheck);
- aSessionData->ClearAliases = ClearAliasesCheck->Checked;
- aSessionData->IgnoreLsWarnings = IgnoreLsWarningsCheck->Checked;
- aSessionData->Scp1Compatibility = Scp1CompatibilityCheck->Checked;
- aSessionData->UnsetNationalVars = UnsetNationalVarsCheck->Checked;
- aSessionData->SCPLsFullTime = SCPLsFullTimeAutoCheck->Checked ? asAuto : asOff;
- // SFTP tab
- aSessionData->SftpServer =
- ((SftpServerEdit->Text == SftpServerEdit->Items->Strings[0]) ?
- UnicodeString() : SftpServerEdit->Text);
- aSessionData->SFTPMaxVersion = SFTPMaxVersionCombo->ItemIndex;
- #define SAVE_SFTP_BUG_COMBO(BUG) aSessionData->SFTPBug[sb ## BUG] = ComboAutoSwitchSave(SFTPBug ## BUG ## Combo);
- SAVE_SFTP_BUG_COMBO(Symlink);
- SAVE_SFTP_BUG_COMBO(SignedTS);
- #undef SAVE_SFTP_BUG_COMBO
- // FTP tab
- aSessionData->PostLoginCommands = PostLoginCommandsMemo->Lines->Text;
- aSessionData->FtpListAll = ComboAutoSwitchSave(FtpListAllCombo);
- aSessionData->FtpUseMlsd = ComboAutoSwitchSave(FtpUseMlsdCombo);
- aSessionData->FtpForcePasvIp = ComboAutoSwitchSave(FtpForcePasvIpCombo);
- // Proxy tab
- aSessionData->ProxyMethod = GetProxyMethod();
- aSessionData->FtpProxyLogonType = GetFtpProxyLogonType();
- aSessionData->ProxyHost = ProxyHostEdit->Text;
- aSessionData->ProxyPort = ProxyPortEdit->AsInteger;
- aSessionData->ProxyUsername = ProxyUsernameEdit->Text;
- aSessionData->ProxyPassword = ProxyPasswordEdit->Text;
- aSessionData->ProxyTelnetCommand = ProxyTelnetCommandEdit->Text;
- aSessionData->ProxyLocalCommand = ProxyLocalCommandEdit->Text;
- aSessionData->ProxyLocalhost = ProxyLocalhostCheck->Checked;
- aSessionData->ProxyDNS = (TAutoSwitch)(2 - ProxyDNSCombo->ItemIndex);
- // Bugs tab
- #define SAVE_BUG_COMBO(BUG) aSessionData->Bug[sb ## BUG] = ComboAutoSwitchSave(Bug ## BUG ## Combo)
- SAVE_BUG_COMBO(Ignore1);
- SAVE_BUG_COMBO(PlainPW1);
- SAVE_BUG_COMBO(RSA1);
- SAVE_BUG_COMBO(HMAC2);
- SAVE_BUG_COMBO(DeriveKey2);
- SAVE_BUG_COMBO(RSAPad2);
- SAVE_BUG_COMBO(PKSessID2);
- SAVE_BUG_COMBO(Rekey2);
- SAVE_BUG_COMBO(MaxPkt2);
- SAVE_BUG_COMBO(Ignore2);
- #undef SAVE_BUG_COMBO
- // Tunnel tab
- aSessionData->Tunnel = TunnelCheck->Checked;
- aSessionData->TunnelUserName = TunnelUserNameEdit->Text;
- aSessionData->TunnelPortNumber = TunnelPortNumberEdit->AsInteger;
- aSessionData->TunnelHostName = TunnelHostNameEdit->Text;
- aSessionData->TunnelPassword = TunnelPasswordEdit->Text;
- aSessionData->TunnelPublicKeyFile = TunnelPrivateKeyEdit->Text;
- if (TunnelLocalPortNumberEdit->Text == TunnelLocalPortNumberEdit->Items->Strings[0])
- {
- aSessionData->TunnelLocalPortNumber = 0;
- }
- else
- {
- aSessionData->TunnelLocalPortNumber = StrToIntDef(TunnelLocalPortNumberEdit->Text, 0);
- }
- UnicodeString Name = FCurrentSessionName;
- if (Name.IsEmpty())
- {
- Name = UnixIncludeTrailingBackslash(SessionNodePath(CurrentSessionFolderNode())) +
- aSessionData->DefaultSessionName;
- }
- aSessionData->Name = Name;
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::UpdateNavigationTree()
- {
- TTreeNode * ActiveNode = NULL;
- NoUpdate++;
- try
- {
- int Index = 0;
- TTreeNode * PrevNode = NULL;
- while (Index < PageControl->PageCount)
- {
- TTabSheet * Tab = PageControl->Pages[Index];
- if (Tab->Enabled)
- {
- bool Indented = ((Tab->Tag % 100) == 2);
- UnicodeString Label = FTreeLabels->Strings[Index];
- TTreeNode * Node;
- if (PrevNode == NULL)
- {
- assert(!Indented);
- Node = NavigationTree->Items->GetFirstNode();
- }
- else
- {
- if (Indented)
- {
- if (PrevNode->Level == 0)
- {
- Node = PrevNode->getFirstChild();
- if (Node == NULL)
- {
- Node = NavigationTree->Items->AddChild(PrevNode, Label);
- }
- }
- else
- {
- Node = PrevNode->getNextSibling();
- if (Node == NULL)
- {
- Node = NavigationTree->Items->Add(PrevNode, Label);
- }
- }
- }
- else
- {
- if (PrevNode->Level == 0)
- {
- // delete all excess children of previous top level node
- while ((Node = PrevNode->GetNext()) != PrevNode->getNextSibling())
- {
- Node->Delete();
- }
- Node = PrevNode->getNextSibling();
- if (Node == NULL)
- {
- Node = NavigationTree->Items->Add(PrevNode, Label);
- }
- }
- else
- {
- // delete all excess children of previous top level node
- while ((Node = PrevNode->getNextSibling()) != NULL)
- {
- Node->Delete();
- }
- Node = PrevNode->GetNext();
- if (Node == NULL)
- {
- Node = NavigationTree->Items->Add(NULL, Label);
- }
- }
- }
- }
- Node->Text = Label;
- Node->SelectedIndex = reinterpret_cast<int>(Tab);
- PrevNode = Node;
- if (PageControl->ActivePage == Tab)
- {
- Node->Selected = true;
- ActiveNode = Node;
- }
- }
- Index++;
- }
- TTreeNode * Node;
- while ((Node = PrevNode->GetNext()) != NULL)
- {
- Node->Delete();
- }
- NavigationTree->FullExpand();
- }
- __finally
- {
- NoUpdate--;
- }
- // node of active page was hidden
- if (ActiveNode == NULL)
- {
- ChangePage(BasicSheet);
- }
- }
- //---------------------------------------------------------------------
- void __fastcall TLoginDialog::UpdateControls()
- {
- if (Visible && FInitialized)
- {
- NoUpdate++;
- try
- {
- TFSProtocol FSProtocol = GetFSProtocol();
- bool SshProtocol = IsSshProtocol(FSProtocol);
- bool SftpProtocol = (FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP);
- bool ScpProtocol = (FSProtocol == fsSCPonly);
- bool FtpProtocol = (FSProtocol == fsFTP);
- bool WebDavProtocol = (FSProtocol == fsWebDAV);
- bool Advanced = ShowAdvancedLoginOptionsCheck->Checked;
- // basic/session sheet
- FtpsCombo->Visible = FtpProtocol;
- FtpsLabel->Visible = FtpsCombo->Visible;
- WebDavsCombo->Visible = WebDavProtocol;
- WebDavsLabel->Visible = WebDavsCombo->Visible;
- BasicSshGroup->Visible = SshProtocol;
- BasicFtpGroup->Visible = FtpProtocol;
- AnonymousLoginCheck->Checked =
- SameText(UserNameEdit->Text, AnonymousUserName) &&
- SameText(PasswordEdit->Text, AnonymousPassword);
- TGroupBox * BottomGroup =
- (SshProtocol ? BasicSshGroup : (FtpProtocol ? BasicFtpGroup : BasicGroup));
- ColorButton->Top = BottomGroup->Top + BottomGroup->Height + 8;
- // log sheet
- LogSheet->Enabled = Advanced;
- // connection sheet
- ConnSheet->Enabled = Advanced;
- EnableControl(FtpPasvModeCheck, FtpProtocol);
- if (FtpProtocol &&
- (FtpProxyMethodCombo->ItemIndex != ::pmNone) &&
- SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex) &&
- !FtpPasvModeCheck->Checked)
- {
- FtpPasvModeCheck->Checked = true;
- MessageDialog(LoadStr(FTP_PASV_MODE_REQUIRED), qtInformation, qaOK);
- }
- EnableControl(BufferSizeCheck, SshProtocol);
- PingGroup->Visible = !FtpProtocol;
- EnableControl(PingGroup, SshProtocol);
- EnableControl(PingIntervalSecEdit, PingGroup->Enabled && !PingOffButton->Checked);
- EnableControl(PingIntervalLabel, PingGroup->Enabled && PingIntervalSecEdit->Enabled);
- FtpPingGroup->Visible = FtpProtocol;
- EnableControl(FtpPingIntervalSecEdit, !FtpPingOffButton->Checked);
- EnableControl(FtpPingIntervalLabel, FtpPingIntervalSecEdit->Enabled);
- EnableControl(IPvGroup, SshProtocol || FtpProtocol);
- EnableControl(IPAutoButton, IPvGroup->Enabled && SshProtocol);
- // sites sheet
- EnableControl(SessionTree, SessionTree->Items->Count > 0);
- if (SitesIncrementalSearchLabel->Visible != !FSitesIncrementalSearch.IsEmpty())
- {
- if (FSitesIncrementalSearch.IsEmpty())
- {
- SitesIncrementalSearchLabel->Visible = false;
- SessionTree->Height = SitesIncrementalSearchLabel->BoundsRect.Bottom - SessionTree->Top;
- }
- else
- {
- SitesIncrementalSearchLabel->Visible = true;
- SessionTree->Height = SitesIncrementalSearchLabel->BoundsRect.Top - SessionTree->Top;
- }
- }
- if (!FSitesIncrementalSearch.IsEmpty())
- {
- SitesIncrementalSearchLabel->Caption =
- L" " + FMTLOAD(LOGIN_SITES_INC_SEARCH, (FSitesIncrementalSearch)) +
- (FSitesIncrementalSearchHaveNext ? L" " + LoadStr(LOGIN_SITES_NEXT_SEARCH) : UnicodeString());
- }
- // ssh/authentication sheet
- AuthSheet->Enabled = SshProtocol && Advanced;
- EnableControl(SshNoUserAuthCheck, !SshProt1onlyButton->Checked);
- EnableControl(AuthenticationGroup,
- !SshNoUserAuthCheck->Enabled || !SshNoUserAuthCheck->Checked);
- EnableControl(AuthTISCheck, AuthenticationGroup->Enabled && !SshProt2onlyButton->Checked);
- EnableControl(AuthKICheck, AuthenticationGroup->Enabled && !SshProt1onlyButton->Checked);
- EnableControl(AuthKIPasswordCheck,
- AuthenticationGroup->Enabled &&
- ((AuthTISCheck->Enabled && AuthTISCheck->Checked) ||
- (AuthKICheck->Enabled && AuthKICheck->Checked)));
- EnableControl(AuthGSSAPICheck3,
- AuthenticationGroup->Enabled && !SshProt1onlyButton->Checked);
- EnableControl(GSSAPIFwdTGTCheck,
- AuthGSSAPICheck3->Enabled && AuthGSSAPICheck3->Checked);
- // ssh sheet
- AdvancedSheet->Enabled = SshProtocol;
- EnableControl(CipherUpButton, CipherListBox->ItemIndex > 0);
- EnableControl(CipherDownButton, CipherListBox->ItemIndex >= 0 &&
- CipherListBox->ItemIndex < CipherListBox->Items->Count-1);
- EnableControl(Ssh2LegacyDESCheck, !SshProt1onlyButton->Checked);
- // ssh/kex sheet
- KexSheet->Enabled = SshProtocol && Advanced && !SshProt1onlyButton->Checked &&
- (BugRekey2Combo->ItemIndex != 2);
- EnableControl(KexUpButton, KexListBox->ItemIndex > 0);
- EnableControl(KexDownButton, KexListBox->ItemIndex >= 0 &&
- KexListBox->ItemIndex < KexListBox->Items->Count-1);
- // ssh/bugs sheet
- BugsSheet->Enabled = SshProtocol && Advanced;
- EnableControl(BugIgnore1Combo, !SshProt2onlyButton->Checked);
- EnableControl(BugIgnore1Label, BugIgnore1Combo->Enabled);
- EnableControl(BugPlainPW1Combo, !SshProt2onlyButton->Checked);
- EnableControl(BugPlainPW1Label, BugPlainPW1Combo->Enabled);
- EnableControl(BugRSA1Combo, !SshProt2onlyButton->Checked);
- EnableControl(BugRSA1Label, BugRSA1Combo->Enabled);
- EnableControl(BugHMAC2Combo, !SshProt1onlyButton->Checked);
- EnableControl(BugHMAC2Label, BugHMAC2Combo->Enabled);
- EnableControl(BugDeriveKey2Combo, !SshProt1onlyButton->Checked);
- EnableControl(BugDeriveKey2Label, BugDeriveKey2Combo->Enabled);
- EnableControl(BugRSAPad2Combo, !SshProt1onlyButton->Checked);
- EnableControl(BugRSAPad2Label, BugRSAPad2Combo->Enabled);
- EnableControl(BugPKSessID2Combo, !SshProt1onlyButton->Checked);
- EnableControl(BugPKSessID2Label, BugPKSessID2Combo->Enabled);
- EnableControl(BugRekey2Combo, !SshProt1onlyButton->Checked);
- EnableControl(BugRekey2Label, BugRekey2Combo->Enabled);
- EnableControl(BugMaxPkt2Combo, !SshProt1onlyButton->Checked);
- EnableControl(BugMaxPkt2Label, BugMaxPkt2Combo->Enabled);
- EnableControl(BugIgnore2Combo, !SshProt1onlyButton->Checked);
- EnableControl(BugIgnore2Label, BugIgnore2Combo->Enabled);
- // connection/proxy sheet
- TComboBox * ProxyMethodCombo =
- (SshProtocol ? SshProxyMethodCombo : (FtpProtocol ? FtpProxyMethodCombo : WebDavProxyMethodCombo));
- TProxyMethod ProxyMethod = GetProxyMethod();
- ProxyMethodCombo->Visible = true;
- ProxyMethodLabel->FocusControl = ProxyMethodCombo;
- if (!SshProtocol)
- {
- SshProxyMethodCombo->Visible = false;
- SshProxyMethodCombo->ItemIndex = ProxyMethod;
- }
- if (!FtpProtocol)
- {
- FtpProxyMethodCombo->Visible = false;
- FtpProxyMethodCombo->ItemIndex = GetSupportedFtpProxyMethod(ProxyMethod);
- }
- if (!WebDavProtocol)
- {
- WebDavProxyMethodCombo->Visible = false;
- WebDavProxyMethodCombo->ItemIndex = GetSupportedWebDavProxyMethod(ProxyMethod);
- }
- ProxySheet->Enabled = Advanced;
- int FtpProxyLogonType = GetFtpProxyLogonType();
- UnicodeString ProxyCommand =
- ((ProxyMethod == pmCmd) ?
- ProxyLocalCommandEdit->Text : ProxyTelnetCommandEdit->Text);
- EnableControl(ProxyHostEdit,
- (ProxyMethod == pmSocks4) ||
- (ProxyMethod == pmSocks5) ||
- (ProxyMethod == pmHTTP) ||
- (ProxyMethod == pmTelnet) ||
- ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyhost")) ||
- (FtpProxyLogonType > 0));
- EnableControl(ProxyHostLabel, ProxyHostEdit->Enabled);
- EnableControl(ProxyPortEdit,
- (ProxyMethod == pmSocks4) ||
- (ProxyMethod == pmSocks5) ||
- (ProxyMethod == pmHTTP) ||
- (ProxyMethod == pmTelnet) ||
- ((ProxyMethod == pmCmd) && AnsiContainsText(ProxyCommand, L"%proxyport")) ||
- (FtpProxyLogonType > 0));
- EnableControl(ProxyPortLabel, ProxyPortEdit->Enabled);
- EnableControl(ProxyUsernameEdit,
- // FZAPI does not support username for SOCKS4
- ((ProxyMethod == pmSocks4) && (SshProtocol || WebDavProtocol)) ||
- (ProxyMethod == pmSocks5) ||
- (ProxyMethod == pmHTTP) ||
- (((ProxyMethod == pmTelnet) ||
- (ProxyMethod == pmCmd)) &&
- AnsiContainsText(ProxyCommand, L"%user")) ||
- ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
- EnableControl(ProxyUsernameLabel, ProxyUsernameEdit->Enabled);
- EnableControl(ProxyPasswordEdit,
- (ProxyMethod == pmSocks5) ||
- (ProxyMethod == pmHTTP) ||
- (((ProxyMethod == pmTelnet) ||
- (ProxyMethod == pmCmd)) &&
- AnsiContainsText(ProxyCommand, L"%pass")) ||
- ((FtpProxyLogonType > 0) && (FtpProxyLogonType != 3) && (FtpProxyLogonType != 5)));
- EnableControl(ProxyPasswordLabel, ProxyPasswordEdit->Enabled);
- bool ProxySettings = (ProxyMethod != ::pmNone) && SshProtocol;
- EnableControl(ProxySettingsGroup, ProxySettings);
- EnableControl(ProxyTelnetCommandEdit,
- ProxySettings && (ProxyMethod == pmTelnet));
- EnableControl(ProxyTelnetCommandLabel, ProxyTelnetCommandEdit->Enabled);
- EnableControl(ProxyTelnetCommandHintText, ProxyTelnetCommandEdit->Enabled);
- ProxyLocalCommandEdit->Visible = (ProxyMethod == pmCmd);
- ProxyLocalCommandLabel->Visible = ProxyLocalCommandEdit->Visible;
- ProxyLocalCommandBrowseButton->Visible = ProxyLocalCommandEdit->Visible;
- ProxyLocalCommandHintText->Visible = ProxyLocalCommandEdit->Visible;
- ProxyTelnetCommandEdit->Visible = !ProxyLocalCommandEdit->Visible;
- ProxyTelnetCommandLabel->Visible = ProxyTelnetCommandEdit->Visible;
- ProxyTelnetCommandHintText->Visible = ProxyTelnetCommandEdit->Visible;
- // environment/directories sheet
- DirectoryOptionsGroup->Visible = Advanced;
- EnableControl(SynchronizeBrowsingCheck,
- WinConfiguration->PreservePanelState &&
- !WinConfiguration->ScpCommander.PreserveLocalDirectory);
- EnableControl(CacheDirectoryChangesCheck,
- (!ScpProtocol || CacheDirectoriesCheck->Checked) && DirectoriesSheet->Enabled);
- EnableControl(PreserveDirectoryChangesCheck,
- CacheDirectoryChangesCheck->Enabled && CacheDirectoryChangesCheck->Checked &&
- DirectoriesSheet->Enabled);
- EnableControl(ResolveSymlinksCheck, (SftpProtocol || ScpProtocol) && DirectoriesSheet->Enabled);
- // environment sheet
- EnableControl(EOLTypeCombo, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
- EnableControl(EOLTypeLabel, EOLTypeCombo->Enabled);
- EnableControl(DSTModeGroup, (SftpProtocol || ScpProtocol) && EnvironmentSheet->Enabled);
- EnableControl(DSTModeKeepCheck, UsesDaylightHack() && DSTModeGroup->Enabled);
- EnableControl(UtfCombo, (SftpProtocol || FtpProtocol) && EnvironmentSheet->Enabled);
- EnableControl(UtfLabel, UtfCombo->Enabled);
- // should be enabled for fsSFTP (SCP fallback) too, but it would cause confusion
- EnableControl(TimeDifferenceEdit,
- ((FtpProtocol && (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff)) ||
- ScpProtocol) &&
- EnvironmentSheet->Enabled);
- EnableControl(TimeDifferenceLabel, TimeDifferenceEdit->Enabled);
- EnableControl(TimeDifferenceHoursLabel, TimeDifferenceEdit->Enabled);
- EnableControl(TimeDifferenceMinutesEdit, TimeDifferenceEdit->Enabled);
- EnableControl(TimeDifferenceMinutesLabel, TimeDifferenceEdit->Enabled);
- // environment/recycle bin sheet
- RecycleBinSheet->Enabled = Advanced;
- EnableControl(OverwrittenToRecycleBinCheck, SftpProtocol && RecycleBinSheet->Enabled);
- EnableControl(RecycleBinPathEdit,
- (DeleteToRecycleBinCheck->Enabled && DeleteToRecycleBinCheck->Checked) ||
- (OverwrittenToRecycleBinCheck->Enabled && OverwrittenToRecycleBinCheck->Checked) &&
- RecycleBinSheet->Enabled);
- EnableControl(RecycleBinPathLabel, RecycleBinPathEdit->Enabled &&
- RecycleBinSheet->Enabled);
- // environment/sftp sheet
- SftpSheet->Enabled = Advanced && SftpProtocol;
- // environment/scp/shell
- ScpSheet->Enabled = Advanced && SshProtocol;
- // disable also for SFTP with SCP fallback, as if someone wants to configure
- // these he/she probably intends to use SCP and should explicitly select it.
- // (note that these are not used for secondary shell session)
- EnableControl(ScpLsOptionsGroup, ScpProtocol);
- EnableControl(OtherShellOptionsGroup, ScpProtocol);
- // environment/ftp
- FtpSheet->Enabled = Advanced && FtpProtocol;
- EnableControl(FtpListAllCombo,
- (ComboAutoSwitchSave(FtpUseMlsdCombo) == asOff));
- EnableControl(FtpListAllLabel, FtpListAllCombo->Enabled);
- EnableControl(FtpForcePasvIpCombo,
- FtpPasvModeCheck->Checked &&
- (IPAutoButton->Checked || IPv4Button->Checked));
- EnableControl(FtpForcePasvIpLabel, FtpForcePasvIpCombo->Enabled);
- // tunnel sheet
- TunnelSheet->Enabled = Advanced && SshProtocol;
- // probably needless
- EnableControl(TunnelSessionGroup, TunnelCheck->Enabled && TunnelCheck->Checked);
- EnableControl(TunnelOptionsGroup, TunnelSessionGroup->Enabled);
- // preferences sheet
- GeneralSheet->Enabled = FLAGSET(FOptions, loPreferences);
- // this methods saves us from calling GetSessionData,
- // which breaks changing locale (session data are not preserved,
- // as we would overwrite them with non-initialized control data)
- if (PageControl->ActivePage == SessionListSheet)
- {
- LoginButton->Default =
- (SelectedSession != NULL) &&
- FStoredSessions->CanLogin(SelectedSession);
- }
- else
- {
- LoginButton->Default = true;
- }
- LoadButton->Default = !LoginButton->Default;
- SetDefaultSessionButton->Visible = !SupportsSplitButton();
- AboutButton->Visible = (FOptions & loAbout);
- LanguagesButton->Visible = (FOptions & loLanguage);
- ShellIconsButton->Visible = (FOptions & loTools);
- ToolsMenuButton->Visible = (FOptions & loTools);
- LoggingFrame->EnableLogWindow = (FOptions & loLogWindow);
- ColorButton->Visible = (FOptions & loColor);
- UpdateNavigationTree();
- }
- __finally
- {
- NoUpdate--;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::DataChange(TObject * /*Sender*/)
- {
- if (NoUpdate == 0)
- {
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::FormShow(TObject * /*Sender*/)
- {
- if (!FInitialized)
- {
- Init();
- TSessionData * Data = GetSessionData();
- if (Data == FSessionData)
- {
- LoadSession(Data);
- }
- else
- {
- Default();
- }
- }
- if (FLocaleChanging)
- {
- Init();
- LoadSession(FSessionData);
- ChangePage(FSavedTab);
- if (FSavedSession >= 0)
- {
- SessionTree->Selected = SessionTree->Items->Item[FSavedSession];
- SessionTree->Selected->MakeVisible();
- }
- LoadConfiguration();
- }
- // among other this makes the expanded nodes look like expanded,
- // because the LoadState call in Execute is too early,
- // and some stray call to collapsed event during showing process,
- // make the image be set to collapsed
- LoadState();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeChange(TObject * /*Sender*/,
- TTreeNode * /*Node*/)
- {
- if (FIncrementalSearching <= 0)
- {
- // Make sure UpdateControls is called here, no matter what,
- // now it is always called from ResetSitesIncrementalSearch.
- // For the "else" cenarion, UpdateControls is called later from SitesIncrementalSearch.
- ResetSitesIncrementalSearch();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SetSessionData(TSessionData * value)
- {
- FSessionData->Assign(value);
- FSessionData->Special = false;
- FEditingSessionData = value;
- LoadSession(FSessionData);
- }
- //---------------------------------------------------------------------------
- TSessionData * __fastcall TLoginDialog::GetSessionData()
- {
- if (PageControl->ActivePage == SessionListSheet)
- {
- return SelectedSession;
- }
- else
- {
- SaveSession(FSessionData);
- return FSessionData;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeDblClick(TObject * /*Sender*/)
- {
- TPoint P = SessionTree->ScreenToClient(Mouse->CursorPos);
- TTreeNode * Node = SessionTree->GetNodeAt(P.x, P.y);
- if (IsSessionNode(Node))
- {
- TSessionData * Data = GetNodeSession(Node);
- if (ALWAYS_TRUE(Data == SelectedSession))
- {
- if (FStoredSessions->CanLogin(Data))
- {
- ModalResult = mrOk;
- }
- else
- {
- SetSessionData(Data);
- EditSession();
- }
- }
- }
- else if (IsWorkspaceNode(Node))
- {
- if (HasNodeAnySession(Node, true))
- {
- ModalResult = mrOk;
- }
- }
- }
- //---------------------------------------------------------------------------
- TSessionData * __fastcall TLoginDialog::GetSelectedSession()
- {
- if (SessionTree->Selected != NULL)
- {
- return (TSessionData *)SessionTree->Selected->Data;
- }
- else
- {
- return NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeKeyDown(TObject * /*Sender*/,
- WORD & Key, TShiftState /*Shift*/)
- {
- if (!SessionTree->IsEditing())
- {
- if (Key == VK_DELETE)
- {
- DeleteSessionAction->Execute();
- Key = 0;
- }
- else if (Key == VK_F2)
- {
- RenameSessionAction->Execute();
- Key = 0;
- }
- else if (Key == VK_BACK)
- {
- Key = 0;
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeKeyPress(TObject * /*Sender*/, System::WideChar & Key)
- {
- if (!SessionTree->IsEditing())
- {
- // filter control sequences
- if (Key >= VK_SPACE)
- {
- if (!SitesIncrementalSearch(FSitesIncrementalSearch + Key, false, false))
- {
- MessageBeep(0);
- }
- Key = 0;
- }
- else if (Key == VK_BACK)
- {
- if (!FSitesIncrementalSearch.IsEmpty())
- {
- if (FSitesIncrementalSearch.Length() == 1)
- {
- ResetSitesIncrementalSearch();
- }
- else
- {
- UnicodeString NewText =
- FSitesIncrementalSearch.SubString(1, FSitesIncrementalSearch.Length() - 1);
- SitesIncrementalSearch(NewText, false, false);
- }
- Key = 0;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::EditSession()
- {
- ChangePage(BasicSheet);
- HostNameEdit->SetFocus();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::EditSessionActionExecute(TObject * /*Sender*/)
- {
- if (SelectedSession)
- {
- SetSessionData(SelectedSession);
- EditSession();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SaveSessionActionExecute(TObject * /*Sender*/)
- {
- SaveSession(FSessionData);
- bool SavePassword;
- bool * PSavePassword;
- bool NotRecommendedSavingPassword =
- !CustomWinConfiguration->UseMasterPassword &&
- !SameText(UserNameEdit->Text, AnonymousUserName);
- if (Configuration->DisablePasswordStoring ||
- !FSessionData->HasAnyPassword())
- {
- PSavePassword = NULL;
- }
- else
- {
- PSavePassword = &SavePassword;
- SavePassword =
- ((FEditingSessionData != NULL) &&
- (FEditingSessionData->Password == FSessionData->Password)) ||
- !NotRecommendedSavingPassword;
- }
- UnicodeString SessionName = FSessionData->SessionName;
- if (DoSaveSessionDialog(SessionName, PSavePassword, FEditingSessionData, NotRecommendedSavingPassword))
- {
- if ((PSavePassword != NULL) && !*PSavePassword)
- {
- FSessionData->Password = L"";
- }
- TTreeNode * ParentNode = AddSessionPath(UnixExtractFilePath(SessionName), false, false);
- CheckIsSessionFolder(ParentNode);
- TSessionData * NewSession =
- StoredSessions->NewSession(SessionName, FSessionData);
- // modified only, explicit
- StoredSessions->Save(false, true);
- SaveConfiguration();
- TTreeNode * Node = SessionTree->Items->GetFirstNode();
- while ((Node != NULL) && (Node->Data != NewSession))
- {
- Node = Node->GetNext();
- }
- if (Node == NULL)
- {
- Node = AddSession(NewSession);
- }
- SessionTree->Selected = Node;
- SetSessionData(NewSession);
- ChangePage(SessionListSheet);
- SessionTree->SetFocus();
- }
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TLoginDialog::SessionNodePath(TTreeNode * Node)
- {
- UnicodeString Path;
- if (Node != NULL)
- {
- Path = Node->Text;
- Node = Node->Parent;
- while (Node != NULL)
- {
- Path.Insert(UnixIncludeTrailingBackslash(Node->Text), 1);
- Node = Node->Parent;
- }
- }
- return Path;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::DeleteSessionActionExecute(TObject * /*Sender*/)
- {
- assert(SessionTree->Selected != NULL);
- TTreeNode * Node = SessionTree->Selected;
- if (IsSessionNode(Node))
- {
- TSessionData * Session = SelectedSession;
- if (MessageDialog(FMTLOAD(CONFIRM_DELETE_SESSION, (Session->SessionName)),
- qtConfirmation, qaOK | qaCancel, HELP_DELETE_SESSION) == qaOK)
- {
- WinConfiguration->DeleteSessionFromJumpList(Session->SessionName);
- Session->Remove();
- DestroySession(Session);
- SessionTree->Selected->Delete();
- }
- }
- else if (IsFolderNode(Node) || IsWorkspaceNode(Node))
- {
- int Sessions = 0;
- TTreeNode * ANode = Node->GetNext();
- while ((ANode != NULL) && ANode->HasAsParent(Node))
- {
- if (IsSessionNode(ANode))
- {
- TSessionData * Session = GetNodeSession(ANode);
- if (Session->Special)
- {
- SessionTree->Selected = ANode;
- ANode->MakeVisible();
- throw Exception(FMTLOAD(LOGIN_DELETE_SPECIAL_SESSION, (Session->SessionName)));
- }
- Sessions++;
- }
- ANode = ANode->GetNext();
- }
- UnicodeString Path = SessionNodePath(Node);
- int Prompt;
- UnicodeString HelpKeyword;
- if (IsFolderNode(Node))
- {
- Prompt = LOGIN_DELETE_SESSION_FOLDER;
- HelpKeyword = HELP_DELETE_SESSION_FOLDER;
- }
- else
- {
- Prompt = LOGIN_DELETE_WORKSPACE;
- HelpKeyword = HELP_DELETE_WORKSPACE;
- }
- if ((Sessions == 0) ||
- (MessageDialog(FMTLOAD(Prompt, (Path, Sessions)),
- qtConfirmation, qaOK | qaCancel, HelpKeyword) == qaOK))
- {
- if (IsWorkspaceNode(Node))
- {
- WinConfiguration->DeleteWorkspaceFromJumpList(Path);
- }
- Node = SessionTree->Selected;
- TTreeNode * ANode = Node->GetNext();
- while ((ANode != NULL) && ANode->HasAsParent(Node))
- {
- if (IsSessionNode(ANode))
- {
- TSessionData * Session = GetNodeSession(ANode);
- Session->Remove();
- DestroySession(Session);
- }
- ANode = ANode->GetNext();
- }
- SessionTree->Selected->Delete();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ReloadSessions()
- {
- SaveState();
- LoadSessions();
- LoadState();
- if (SessionTree->Items->Count > 0)
- {
- SessionTree->Items->GetFirstNode()->MakeVisible();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ImportSessionsActionExecute(TObject * /*Sender*/)
- {
- if (DoImportSessionsDialog())
- {
- ReloadSessions();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::CleanUpActionExecute(TObject * /*Sender*/)
- {
- if (DoCleanupDialog(StoredSessions, Configuration))
- {
- SaveState();
- LoadSessions();
- LoadState();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::AboutActionExecute(TObject * /*Sender*/)
- {
- DoAboutDialog(Configuration);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ActionListUpdate(TBasicAction *Action,
- bool &Handled)
- {
- bool SessionSelected =
- (PageControl->ActivePage == SessionListSheet) &&
- IsSessionNode(SessionTree->Selected);
- bool FolderOrWorkspaceSelected =
- (PageControl->ActivePage == SessionListSheet) &&
- IsFolderOrWorkspaceNode(SessionTree->Selected);
- if (Action == EditSessionAction)
- {
- EditSessionAction->Enabled = SessionSelected;
- }
- else if (Action == DeleteSessionAction)
- {
- TSessionData * Data = GetSessionData();
- DeleteSessionAction->Enabled =
- (SessionSelected && !Data->Special) ||
- FolderOrWorkspaceSelected;
- }
- else if (Action == RenameSessionAction)
- {
- TSessionData * Data = GetSessionData();
- RenameSessionAction->Enabled =
- (SessionSelected && !Data->Special) ||
- FolderOrWorkspaceSelected;
- }
- else if (Action == DesktopIconAction)
- {
- DesktopIconAction->Enabled =
- SessionSelected ||
- (FolderOrWorkspaceSelected && HasNodeAnySession(SessionTree->Selected));
- }
- else if (Action == SendToHookAction)
- {
- SendToHookAction->Enabled = SessionSelected;
- }
- else if (Action == LoginAction)
- {
- TSessionData * Data = GetSessionData();
- LoginAction->Enabled =
- (Data && FStoredSessions->CanLogin(Data) && (PageControl->ActivePage != GeneralSheet)) ||
- (FolderOrWorkspaceSelected && HasNodeAnySession(SessionTree->Selected, true));
- }
- else if (Action == SaveSessionAction)
- {
- SaveSessionAction->Enabled =
- (PageControl->ActivePage != SessionListSheet) &&
- (PageControl->ActivePage != LogSheet) &&
- (PageControl->ActivePage != GeneralSheet);
- }
- else if (Action == ShellIconSessionAction)
- {
- ShellIconSessionAction->Enabled =
- SessionSelected ||
- (FolderOrWorkspaceSelected && HasNodeAnySession(SessionTree->Selected));
- }
- else if (Action == NewSessionFolderAction)
- {
- NewSessionFolderAction->Enabled = true;
- }
- else if (Action == ImportSessionsAction)
- {
- ImportSessionsAction->Enabled =
- GUIConfiguration->AnyPuttySessionForImport(StoredSessions) ||
- GUIConfiguration->AnyFilezillaSessionForImport(StoredSessions);
- }
- else if (Action == ImportAction)
- {
- ImportAction->Enabled = true;
- }
- else if (Action == ExportAction)
- {
- ExportAction->Enabled = true;
- }
- Handled = true;
- if (!SessionTree->IsEditing())
- {
- // default property setter does not have guard for "the same value"
- if (!LoginButton->Default)
- {
- LoginButton->Default = true;
- }
- CloseButton->Cancel = true;
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TLoginDialog::Execute(TList * DataList)
- {
- FDataList = DataList;
- if (DataList->Count > 0)
- {
- SetSessionData(reinterpret_cast<TSessionData * >(DataList->Items[0]));
- }
- else
- {
- Default();
- }
- LoadConfiguration();
- LoadState();
- bool Result = (ShowModal() == mrOk);
- SaveState();
- if (Result)
- {
- SaveConfiguration();
- // DataList saved already from FormCloseQuery
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SaveDataList(TList * DataList)
- {
- // Normally we would call this from Execute,
- // but at that point the windows is already hidden.
- // Cloning session data may pop up master password dialog:
- // - if it happens between closing and destroyiong login dialog
- // the next window will appear in background for some reason
- // - and its actually even nicer when master password dialog pops up over
- // the login dialog
- DataList->Clear();
- if (PageControl->ActivePage == SessionListSheet)
- {
- TTreeNode * Node = SessionTree->Selected;
- if (IsFolderOrWorkspaceNode(Node))
- {
- UnicodeString Name = SessionNodePath(Node);
- if (IsWorkspaceNode(Node))
- {
- WinConfiguration->AddWorkspaceToJumpList(Name);
- }
- StoredSessions->GetFolderOrWorkspace(Name, DataList);
- }
- else if (IsSessionNode(Node))
- {
- TSessionData * Data2 = new TSessionData(L"");
- Data2->Assign(GetNodeSession(Node));
- DataList->Add(Data2);
- }
- }
- else
- {
- TSessionData * Data = GetSessionData();
- TSessionData * Data2 = new TSessionData(L"");
- Data2->Assign(Data);
- // we carry the name of the edited stored session around while on the dialog,
- // but we do not want it to leave the dialog, so that we can distinguish
- // stored and ad-hoc sessions
- Data2->Name = L"";
- DataList->Add(Data2);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SaveOpenedStoredSessionFolders(
- TTreeNode * Node, TStrings * OpenedStoredSessionFolders)
- {
- if (IsFolderNode(Node))
- {
- if (Node->Expanded)
- {
- OpenedStoredSessionFolders->Add(SessionNodePath(Node));
- }
- for (int Index = 0; Index < Node->Count; Index++)
- {
- SaveOpenedStoredSessionFolders(Node->Item[Index], OpenedStoredSessionFolders);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SaveState()
- {
- assert(WinConfiguration != NULL);
- TStringList * OpenedStoredSessionFolders = new TStringList();
- WinConfiguration->BeginUpdate();
- try
- {
- CustomWinConfiguration->ShowAdvancedLoginOptions = ShowAdvancedLoginOptionsCheck->Checked;
- OpenedStoredSessionFolders->CaseSensitive = false;
- OpenedStoredSessionFolders->Sorted = true;
- for (int Index = 0; Index < SessionTree->Items->Count; Index++)
- {
- SaveOpenedStoredSessionFolders(
- SessionTree->Items->Item[Index], OpenedStoredSessionFolders);
- }
- WinConfiguration->OpenedStoredSessionFolders = OpenedStoredSessionFolders->CommaText;
- }
- __finally
- {
- WinConfiguration->EndUpdate();
- delete OpenedStoredSessionFolders;
- }
- WinConfiguration->LastStoredSession = SessionNodePath(SessionTree->Selected);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::LoadOpenedStoredSessionFolders(
- TTreeNode * Node, TStrings * OpenedStoredSessionFolders)
- {
- if (IsFolderNode(Node))
- {
- UnicodeString Path = SessionNodePath(Node);
- if (OpenedStoredSessionFolders->IndexOf(Path) >= 0)
- {
- Node->Expand(false);
- UpdateFolderNode(Node);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::LoadState()
- {
- ShowAdvancedLoginOptionsCheck->Checked = CustomWinConfiguration->ShowAdvancedLoginOptions;
- TStringList * OpenedStoredSessionFolders = new TStringList();
- try
- {
- OpenedStoredSessionFolders->CaseSensitive = false;
- OpenedStoredSessionFolders->Sorted = true;
- OpenedStoredSessionFolders->CommaText = WinConfiguration->OpenedStoredSessionFolders;
- for (int Index = 0; Index < SessionTree->Items->Count; Index++)
- {
- LoadOpenedStoredSessionFolders(
- SessionTree->Items->Item[Index], OpenedStoredSessionFolders);
- }
- // tree view tried to make expanded node children all visible, what
- // may scroll the selected node (what should be the first one here),
- // out of the view
- if (SessionTree->Selected != NULL)
- {
- SessionTree->Selected->MakeVisible();
- }
- }
- __finally
- {
- delete OpenedStoredSessionFolders;
- }
- if (!WinConfiguration->LastStoredSession.IsEmpty())
- {
- UnicodeString Path = WinConfiguration->LastStoredSession;
- UnicodeString ParentPath = UnixExtractFilePath(Path);
- TTreeNode * Node;
- if (ParentPath.IsEmpty())
- {
- Node = SessionTree->Items->GetFirstNode();
- }
- else
- {
- TTreeNode * Parent = AddSessionPath(ParentPath, false, false);
- Node = (Parent != NULL) ? Parent->getFirstChild() : NULL;
- }
- if (Node != NULL)
- {
- UnicodeString Name = UnixExtractFileName(Path);
- // actually we cannot distinguish folder and session here
- // (note that we allow folder and session with the same name),
- // this is pending for future improvements
- while ((Node != NULL) && !AnsiSameText(Node->Text, Name))
- {
- Node = Node->getNextSibling();
- }
- if (Node != NULL)
- {
- SessionTree->Selected = Node;
- SessionTree->Selected->MakeVisible();
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SaveConfiguration()
- {
- assert(CustomWinConfiguration);
- CustomWinConfiguration->BeginUpdate();
- try
- {
- LoggingFrame->SaveConfiguration();
- GeneralSettingsFrame->SaveConfiguration();
- TTreeNode * Node = SessionTree->Selected;
- if (IsWorkspaceNode(Node))
- {
- WinConfiguration->LastWorkspace = SessionNodePath(Node);
- }
- }
- __finally
- {
- CustomWinConfiguration->EndUpdate();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::LoadConfiguration()
- {
- assert(CustomWinConfiguration);
- LoggingFrame->LoadConfiguration();
- GeneralSettingsFrame->LoadConfiguration();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::PreferencesButtonClick(TObject * /*Sender*/)
- {
- ShowPreferencesDialog();
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::MasterPasswordRecrypt(TObject * /*Sender*/)
- {
- FSessionData->RecryptPasswords();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ShowPreferencesDialog()
- {
- assert(CustomWinConfiguration->OnMasterPasswordRecrypt == NULL);
- CustomWinConfiguration->OnMasterPasswordRecrypt = MasterPasswordRecrypt;
- try
- {
- DoPreferencesDialog(pmLogin);
- }
- __finally
- {
- assert(CustomWinConfiguration->OnMasterPasswordRecrypt == MasterPasswordRecrypt);
- CustomWinConfiguration->OnMasterPasswordRecrypt = NULL;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::NewSessionActionExecute(TObject * /*Sender*/)
- {
- Default();
- EditSession();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::NavigationTreeChange(TObject * /*Sender*/,
- TTreeNode *Node)
- {
- if (NoUpdate == 0)
- {
- TAutoNestingCounter Guard(NoUpdate);
- TTabSheet * Tab = reinterpret_cast<TTabSheet *>(Node->SelectedIndex);
- // should happen only while loading language
- // (UpdateNavigationTree may not be called yet)
- if (Tab != NULL)
- {
- PageControl->ActivePage = Tab;
- // reshow the accelerators, etc
- ResetSystemSettings(this);
- }
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ChangePage(TTabSheet * Tab)
- {
- PageControl->ActivePage = Tab;
- PageControlChange(PageControl);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::PageControlChange(TObject *Sender)
- {
- bool Found = false;
- if (PageControl->ActivePage)
- {
- for (int Index = 0; Index < NavigationTree->Items->Count; Index++)
- {
- if (NavigationTree->Items->Item[Index]->SelectedIndex ==
- reinterpret_cast<int>(PageControl->ActivePage))
- {
- NavigationTree->Items->Item[Index]->Selected = true;
- Found = true;
- }
- }
- }
- if (!Found)
- {
- assert(false);
- ChangePage(BasicSheet);
- }
- else
- {
- DataChange(Sender);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::CMDialogKey(TWMKeyDown & Message)
- {
- if (Message.CharCode == VK_TAB)
- {
- TShiftState Shift = KeyDataToShiftState(Message.KeyData);
- if (Shift.Contains(ssCtrl))
- {
- TTreeNode * Node = NavigationTree->Selected;
- if (!Shift.Contains(ssShift))
- {
- Node = Node->GetNext();
- if (!Node) Node = NavigationTree->Items->GetFirstNode();
- }
- else
- {
- if (Node->GetPrev()) Node = Node->GetPrev();
- else
- while (Node->GetNext()) Node = Node->GetNext();
- }
- Node->Selected = True;
- Message.Result = 1;
- return;
- }
- else
- {
- if (!FSitesIncrementalSearch.IsEmpty())
- {
- bool Reverse = Shift.Contains(ssShift);
- if (!SitesIncrementalSearch(FSitesIncrementalSearch, true, Reverse))
- {
- MessageBeep(0);
- }
- Message.Result = 1;
- return;
- }
- }
- }
- else if (Message.CharCode == VK_ESCAPE)
- {
- if (!FSitesIncrementalSearch.IsEmpty())
- {
- ResetSitesIncrementalSearch();
- Message.Result = 1;
- return;
- }
- }
- TForm::Dispatch(&Message);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::WMHelp(TWMHelp & Message)
- {
- assert(Message.HelpInfo != NULL);
- if (Message.HelpInfo->iContextType == HELPINFO_WINDOW)
- {
- // invoke help for active page (not for whole form), regardless of focus
- // (e.g. even if focus is on control outside pagecontrol)
- Message.HelpInfo->hItemHandle = PageControl->ActivePage->Handle;
- }
- TForm::Dispatch(&Message);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::Dispatch(void * Message)
- {
- TMessage * M = reinterpret_cast<TMessage*>(Message);
- assert(M);
- if (M->Msg == CM_DIALOGKEY)
- {
- CMDialogKey(*((TWMKeyDown *)Message));
- }
- else if (M->Msg == WM_LOCALE_CHANGE)
- {
- if (M->WParam == 0)
- {
- SaveConfiguration();
- SaveState();
- SaveSession(FSessionData);
- FSavedTab = PageControl->ActivePage;
- FSavedSession = ((SessionTree->Selected != NULL) ?
- SessionTree->Selected->AbsoluteIndex : -1);
- assert(FSystemSettings);
- RevokeSystemSettings(this, FSystemSettings);
- FSystemSettings = NULL;
- Hide();
- }
- else
- {
- FLocaleChanging = true;
- try
- {
- Show();
- }
- __finally
- {
- FLocaleChanging = false;
- }
- }
- }
- else if (M->Msg == WM_HELP)
- {
- WMHelp(*((TWMHelp *)Message));
- }
- else
- {
- TForm::Dispatch(Message);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::AlgListBoxStartDrag(TObject * Sender,
- TDragObject *& /*DragObject*/)
- {
- FAlgDragSource = dynamic_cast<TListBox*>(Sender)->ItemIndex;
- FAlgDragDest = -1;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::AlgListBoxDragOver(TObject * Sender,
- TObject *Source, int X, int Y, TDragState /*State*/, bool &Accept)
- {
- if (Source == Sender)
- {
- Accept = AllowAlgDrag(dynamic_cast<TListBox*>(Sender), X, Y);
- }
- else
- {
- Accept = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::AlgListBoxDragDrop(TObject * Sender,
- TObject * Source, int X, int Y)
- {
- if (Source == Sender)
- {
- TListBox * AlgListBox = dynamic_cast<TListBox*>(Sender);
- if (AllowAlgDrag(AlgListBox, X, Y))
- {
- AlgMove(AlgListBox, FAlgDragSource, FAlgDragDest);
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::CipherButtonClick(TObject *Sender)
- {
- AlgMove(CipherListBox, CipherListBox->ItemIndex,
- CipherListBox->ItemIndex + (Sender == CipherUpButton ? -1 : 1));
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::KexButtonClick(TObject *Sender)
- {
- AlgMove(KexListBox, KexListBox->ItemIndex,
- KexListBox->ItemIndex + (Sender == KexUpButton ? -1 : 1));
- }
- //---------------------------------------------------------------------------
- bool __fastcall TLoginDialog::AllowAlgDrag(TListBox * AlgListBox, int X, int Y)
- {
- FAlgDragDest = AlgListBox->ItemAtPos(TPoint(X, Y), true);
- return (FAlgDragDest >= 0) && (FAlgDragDest != FAlgDragSource);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::AlgMove(TListBox * AlgListBox, int Source, int Dest)
- {
- if (Source >= 0 && Source < AlgListBox->Items->Count &&
- Dest >= 0 && Dest < AlgListBox->Items->Count)
- {
- AlgListBox->Items->Move(Source, Dest);
- AlgListBox->ItemIndex = Dest;
- AlgListBox->SetFocus();
- }
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SetDefaultSessionActionExecute(
- TObject * /*Sender*/)
- {
- if (MessageDialog(LoadStr(SET_DEFAULT_SESSION_SETTINGS), qtConfirmation,
- qaOK | qaCancel, HELP_SESSION_SAVE_DEFAULT) == qaOK)
- {
- SaveSession(FSessionData);
- if (!Configuration->DisablePasswordStoring &&
- FSessionData->HasAnyPassword() &&
- CustomWinConfiguration->UseMasterPassword)
- {
- CustomWinConfiguration->AskForMasterPasswordIfNotSet();
- }
- StoredSessions->DefaultSettings = FSessionData;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ToolsMenuButtonClick(TObject * /*Sender*/)
- {
- MenuPopup(ToolsPopupMenu, ToolsMenuButton);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ShellIconSessionActionExecute(
- TObject * /*Sender*/)
- {
- MenuPopup(IconsPopupMenu, ShellIconsButton);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::DesktopIconActionExecute(TObject * /*Sender*/)
- {
- TTreeNode * Node = SessionTree->Selected;
- UnicodeString Message;
- UnicodeString Name;
- UnicodeString AdditionalParams;
- if (IsSessionNode(Node))
- {
- Name = GetNodeSession(Node)->Name;
- Message = FMTLOAD(CONFIRM_CREATE_SHORTCUT, (Name));
- AdditionalParams = L"/UploadIfAny";
- }
- else if (IsFolderNode(Node))
- {
- Name = SessionNodePath(SessionTree->Selected);
- Message = FMTLOAD(CONFIRM_CREATE_SHORTCUT_FOLDER, (Name));
- }
- else if (IsWorkspaceNode(Node))
- {
- Name = SessionNodePath(SessionTree->Selected);
- Message = FMTLOAD(CONFIRM_CREATE_SHORTCUT_WORKSPACE, (Name));
- }
- if (MessageDialog(Message, qtConfirmation, qaYes | qaNo, HELP_CREATE_SHORTCUT) == qaYes)
- {
- CreateDesktopSessionShortCut(Name, L"", AdditionalParams);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SendToHookActionExecute(TObject * /*Sender*/)
- {
- if (MessageDialog(FMTLOAD(CONFIRM_CREATE_SENDTO, (SelectedSession->Name)),
- qtConfirmation, qaYes | qaNo, HELP_CREATE_SENDTO) == qaYes)
- {
- assert(SelectedSession);
- CreateDesktopSessionShortCut(SelectedSession->Name,
- FMTLOAD(SESSION_SENDTO_HOOK_NAME, (SelectedSession->LocalName)),
- L"/Upload", CSIDL_SENDTO);
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TLoginDialog::HasNodeAnySession(TTreeNode * Node, bool NeedCanLogin)
- {
- bool Result = false;
- TTreeNode * ANode = Node->GetNext();
- while (!Result && (ANode != NULL) && ANode->HasAsParent(Node))
- {
- Result =
- IsSessionNode(ANode) &&
- (!NeedCanLogin || FStoredSessions->CanLogin(GetNodeSession(ANode)));
- ANode = ANode->GetNext();
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeCustomDrawItem(
- TCustomTreeView * Sender, TTreeNode * Node, TCustomDrawState State,
- bool & DefaultDraw)
- {
- TFontStyles Styles = Sender->Canvas->Font->Style;
- if (IsSessionNode(Node) && GetNodeSession(Node)->Special)
- {
- Styles = Styles << fsBold << fsUnderline;
- }
- else
- {
- Styles = Styles >> fsBold >> fsUnderline;
- }
- if (State.Empty() && !Node->DropTarget)
- {
- if (IsFolderOrWorkspaceNode(Node))
- {
- if (!HasNodeAnySession(Node))
- {
- Sender->Canvas->Font->Color = clGrayText;
- }
- }
- else if (ALWAYS_TRUE(IsSessionNode(Node)))
- {
- TSessionData * Data = GetNodeSession(Node);
- if (Data->Color != 0)
- {
- Sender->Canvas->Brush->Color = (TColor)Data->Color;
- }
- }
- }
- Sender->Canvas->Font->Style = Styles;
- DefaultDraw = true;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::CheckForUpdatesActionExecute(TObject * /*Sender*/)
- {
- CheckForUpdates(false);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::LanguagesButtonClick(TObject * /*Sender*/)
- {
- delete FLanguagesPopupMenu;
- FLanguagesPopupMenu = new TPopupMenu(this);
- TMenuItem * Item;
- TStrings * Locales = GUIConfiguration->Locales;
- for (int Index = 0; Index < Locales->Count; Index++)
- {
- Item = new TMenuItem(FLanguagesPopupMenu);
- FLanguagesPopupMenu->Items->Add(Item);
- Item->Caption = Locales->Strings[Index];
- Item->Tag = reinterpret_cast<int>(Locales->Objects[Index]);
- Item->OnClick = LocaleClick;
- Item->Checked = (reinterpret_cast<LCID>(Locales->Objects[Index]) ==
- GUIConfiguration->Locale);
- }
- Item = new TMenuItem(FLanguagesPopupMenu);
- FLanguagesPopupMenu->Items->Add(Item);
- Item->Caption = L"-";
- Item = new TMenuItem(FLanguagesPopupMenu);
- FLanguagesPopupMenu->Items->Add(Item);
- Item->Caption = LoadStr(LOGIN_GET_LOCALES);
- Item->OnClick = LocaleGetClick;
- MenuPopup(FLanguagesPopupMenu, LanguagesButton);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::LocaleClick(TObject * Sender)
- {
- assert(Sender);
- GUIConfiguration->Locale =
- static_cast<LCID>(dynamic_cast<TComponent*>(Sender)->Tag);
- LanguagesButton->SetFocus();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::LocaleGetClick(TObject * /*Sender*/)
- {
- OpenBrowser(LoadStr(LOCALES_URL));
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::AuthGSSAPICheck3Click(TObject * /*Sender*/)
- {
- if (NoUpdate)
- {
- UpdateControls();
- if (AuthGSSAPICheck3->Checked && !Configuration->GSSAPIInstalled)
- {
- throw Exception(LoadStr(GSSAPI_NOT_INSTALLED2));
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::HelpButtonClick(TObject * /*Sender*/)
- {
- FormHelp(this);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::VerifyKey(UnicodeString FileName, bool TypeOnly)
- {
- if (!FileName.Trim().IsEmpty())
- {
- FileName = ExpandEnvironmentVariables(FileName);
- TKeyType Type = KeyType(FileName);
- UnicodeString Message;
- switch (Type)
- {
- case ktOpenSSH:
- Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, L"OpenSSH SSH-2"));
- break;
- case ktSSHCom:
- Message = FMTLOAD(KEY_TYPE_UNSUPPORTED, (FileName, L"ssh.com SSH-2"));
- break;
- case ktSSH1:
- case ktSSH2:
- // on file select do not check for SSH version as user may
- // intend to change it only after he/she selects key file
- if (!TypeOnly)
- {
- TSessionData * Data = GetSessionData();
- if ((Type == ktSSH1) !=
- ((Data->SshProt == ssh1only) || (Data->SshProt == ssh1)))
- {
- Message = FMTLOAD(KEY_TYPE_DIFFERENT_SSH,
- (FileName, (Type == ktSSH1 ? L"SSH-1" : L"PuTTY SSH-2")));
- }
- }
- break;
- default:
- assert(false);
- // fallthru
- case ktUnopenable:
- case ktUnknown:
- Message = FMTLOAD(KEY_TYPE_UNKNOWN, (FileName));
- break;
- }
- if (!Message.IsEmpty())
- {
- if (MessageDialog(Message, qtWarning, qaIgnore | qaAbort,
- HELP_LOGIN_KEY_TYPE) == qaAbort)
- {
- Abort();
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::PrivateKeyEditAfterDialog(TObject * Sender,
- UnicodeString & Name, bool & /*Action*/)
- {
- if (CompareFileName(Name, ExpandEnvironmentVariables(FBeforeDialogPath)))
- {
- Name = FBeforeDialogPath;
- }
- TFilenameEdit * Edit = dynamic_cast<TFilenameEdit *>(Sender);
- if (Name != Edit->Text)
- {
- VerifyKey(Name, true);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::FormCloseQuery(TObject * /*Sender*/,
- bool & /*CanClose*/)
- {
- if (ModalResult != mrCancel)
- {
- TSessionData * SessionData = GetSessionData();
- if (SessionData != NULL)
- {
- VerifyKey(SessionData->PublicKeyFile, false);
- // for tunnel key do not check SSH version as it is not configurable
- VerifyKey(SessionData->TunnelPublicKeyFile, true);
- }
- SaveDataList(FDataList);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ColorButtonClick(TObject * /*Sender*/)
- {
- ColorDefaultItem->Checked = (FColor == 0);
- PickColorItem->Checked = (FColor != 0);
- PickColorItem->ImageIndex = (FColor != 0 ? 0 : -1);
- ColorImageList->BkColor = FColor;
- MenuPopup(ColorPopupMenu, ColorButton);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ColorDefaultItemClick(TObject * /*Sender*/)
- {
- FColor = (TColor)0;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::PickColorItemClick(TObject * /*Sender*/)
- {
- TColorDialog * Dialog = new TColorDialog(this);
- try
- {
- Dialog->Options = Dialog->Options << cdFullOpen;
- Dialog->Color = (FColor != 0 ? FColor : clSkyBlue);
- if (Dialog->Execute())
- {
- FColor = Dialog->Color;
- }
- }
- __finally
- {
- delete Dialog;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeEditing(TObject * /*Sender*/,
- TTreeNode * Node, bool & AllowEdit)
- {
- AllowEdit =
- IsFolderOrWorkspaceNode(Node) ||
- (ALWAYS_TRUE(IsSessionNode(Node)) && !GetNodeSession(Node)->Special);
- if (AllowEdit)
- {
- LoginButton->Default = false;
- CloseButton->Cancel = false;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::RenameSessionActionExecute(TObject * /*Sender*/)
- {
- if (SessionTree->Selected != NULL)
- {
- // would be more appropriate in SessionTreeEditing, but it does not work there
- ResetSitesIncrementalSearch();
- SessionTree->Selected->EditText();
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::CheckDuplicateFolder(TTreeNode * Parent,
- UnicodeString Text, TTreeNode * Node)
- {
- TTreeNode * ANode =
- ((Parent == NULL) ? SessionTree->Items->GetFirstNode() :
- Parent->getFirstChild());
- // note that we allow folder with the same name as existing session
- // on the same level (see also AddSession)
- while ((ANode != NULL) &&
- ((ANode == Node) || IsSessionNode(ANode) || !AnsiSameText(ANode->Text, Text)))
- {
- ANode = ANode->getNextSibling();
- }
- if (ANode != NULL)
- {
- throw Exception(FMTLOAD(LOGIN_DUPLICATE_SESSION_FOLDER_WORKSPACE, (Text)));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::CheckIsSessionFolder(TTreeNode * Node)
- {
- if ((Node != NULL) && (Node->Parent != NULL))
- {
- CheckIsSessionFolder(Node->Parent);
- }
- if (IsWorkspaceNode(Node))
- {
- throw Exception(FMTLOAD(WORKSPACE_NOT_FOLDER, (SessionNodePath(Node))));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeEdited(TObject * /*Sender*/,
- TTreeNode * Node, UnicodeString & S)
- {
- if (Node->Text != S)
- {
- TSessionData * Session = SelectedSession;
- TSessionData::ValidateName(S);
- if (Session != NULL)
- {
- UnicodeString Path = UnixExtractFilePath(Session->Name) + S;
- SessionNameValidate(Path, Session);
- // remove from storage
- Session->Remove();
- TSessionData * NewSession = StoredSessions->NewSession(Path, Session);
- // modified, only explicit
- StoredSessions->Save(false, true);
- // the session may be the same, if only letter case has changed
- if (Session != NewSession)
- {
- // if we overwrite existing session, remove the original item
- // (we must not delete the node we are editing)
- TTreeNode * ANode =
- ((Node->Parent == NULL) ? SessionTree->Items->GetFirstNode() :
- Node->Parent->getFirstChild());
- while ((ANode != NULL) && (ANode->Data != NewSession))
- {
- ANode = ANode->getNextSibling();
- }
- if (ANode != NULL)
- {
- ANode->Delete();
- }
- Node->Data = NewSession;
- DestroySession(Session);
- }
- SetSessionData(NewSession);
- }
- else
- {
- CheckDuplicateFolder(Node->Parent, S, Node);
- UnicodeString ParentPath = UnixIncludeTrailingBackslash(SessionNodePath(Node->Parent));
- UnicodeString OldRoot = ParentPath + Node->Text;
- UnicodeString NewRoot = ParentPath + S;
- bool AnySession = false;
- TSortType PrevSortType = SessionTree->SortType;
- // temporarily disable automatic sorting, so that nodes are kept in order
- // while we traverse them. otherwise it may happen that we omit some.
- SessionTree->SortType = Comctrls::stNone;
- try
- {
- TTreeNode * ANode = Node->GetNext();
- while ((ANode != NULL) && ANode->HasAsParent(Node))
- {
- if (IsSessionNode(ANode))
- {
- AnySession = true;
- TSessionData * Session = GetNodeSession(ANode);
- // remove from storage
- Session->Remove();
- UnicodeString Path = Session->Name;
- assert(Path.SubString(1, OldRoot.Length()) == OldRoot);
- Path.Delete(1, OldRoot.Length());
- Path.Insert(NewRoot, 1);
- TSessionData * NewSession = StoredSessions->NewSession(Path, Session);
- // the session may be the same, if only letter case has changed
- if (NewSession != Session)
- {
- ANode->Data = NewSession;
- DestroySession(Session);
- }
- }
- ANode = ANode->GetNext();
- }
- }
- __finally
- {
- SessionTree->SortType = PrevSortType;
- }
- if (AnySession)
- {
- // modified, only explicit
- StoredSessions->Save(false, true);
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::PathEditBeforeDialog(TObject * /*Sender*/,
- UnicodeString & Name, bool & /*Action*/)
- {
- FBeforeDialogPath = Name;
- Name = ExpandEnvironmentVariables(Name);
- }
- //---------------------------------------------------------------------------
- int __fastcall TLoginDialog::FSProtocolToIndex(TFSProtocol FSProtocol,
- bool & AllowScpFallback)
- {
- if (FSProtocol == fsSFTP)
- {
- AllowScpFallback = true;
- bool Dummy;
- return FSProtocolToIndex(fsSFTPonly, Dummy);
- }
- else
- {
- AllowScpFallback = false;
- for (int Index = 0; Index < TransferProtocolCombo->Items->Count; Index++)
- {
- if (FSOrder[Index] == FSProtocol)
- {
- return Index;
- }
- }
- // SFTP is always present
- return FSProtocolToIndex(fsSFTP, AllowScpFallback);
- }
- }
- //---------------------------------------------------------------------------
- TFSProtocol __fastcall TLoginDialog::IndexToFSProtocol(int Index, bool AllowScpFallback)
- {
- bool InBounds = (Index >= 0) && (Index < static_cast<int>(LENOF(FSOrder)));
- // can be temporary "unselected" while new language is being loaded
- assert(InBounds || (Index == -1));
- TFSProtocol Result = fsSFTP;
- if (InBounds)
- {
- Result = FSOrder[Index];
- if ((Result == fsSFTPonly) && AllowScpFallback)
- {
- Result = fsSFTP;
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TLoginDialog::LastSupportedFtpProxyMethod()
- {
- return pmHTTP;
- }
- //---------------------------------------------------------------------------
- bool __fastcall TLoginDialog::SupportedFtpProxyMethod(int Method)
- {
- return (Method >= 0) && (Method <= LastSupportedFtpProxyMethod());
- }
- //---------------------------------------------------------------------------
- int __fastcall TLoginDialog::GetSupportedFtpProxyMethod(int Method)
- {
- if (SupportedFtpProxyMethod(Method))
- {
- return Method;
- }
- else
- {
- return ::pmNone;
- }
- }
- //---------------------------------------------------------------------------
- int __fastcall TLoginDialog::GetSupportedWebDavProxyMethod(int Method)
- {
- if ((Method >= 0) && (Method <= pmHTTP))
- {
- return Method;
- }
- else
- {
- return ::pmNone;
- }
- }
- //---------------------------------------------------------------------------
- TProxyMethod __fastcall TLoginDialog::GetProxyMethod()
- {
- TProxyMethod Result;
- TFSProtocol FSProtocol = GetFSProtocol();
- if (IsSshProtocol(FSProtocol))
- {
- Result = (TProxyMethod)SshProxyMethodCombo->ItemIndex;
- }
- else if (FSProtocol == fsFTP)
- {
- if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
- {
- Result = (TProxyMethod)FtpProxyMethodCombo->ItemIndex;
- }
- else
- {
- Result = ::pmNone;
- }
- }
- else if (FSProtocol == fsWebDAV)
- {
- Result = (TProxyMethod)WebDavProxyMethodCombo->ItemIndex;
- }
- else
- {
- FAIL;
- Result = ::pmNone;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- int __fastcall TLoginDialog::GetFtpProxyLogonType()
- {
- int Result;
- if (GetFSProtocol() != fsFTP)
- {
- Result = 0;
- }
- else
- {
- if (SupportedFtpProxyMethod(FtpProxyMethodCombo->ItemIndex))
- {
- Result = 0;
- }
- else
- {
- Result = FtpProxyMethodCombo->ItemIndex - LastSupportedFtpProxyMethod();
- }
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- TFtps __fastcall TLoginDialog::GetFtps()
- {
- return (TFtps)((GetFSProtocol() == fsWebDAV) ? WebDavsCombo->ItemIndex : FtpsCombo->ItemIndex);
- }
- //---------------------------------------------------------------------------
- TFSProtocol __fastcall TLoginDialog::GetFSProtocol()
- {
- return IndexToFSProtocol(TransferProtocolCombo->ItemIndex, AllowScpFallbackCheck->Checked);
- }
- //---------------------------------------------------------------------------
- bool __fastcall TLoginDialog::IsSshProtocol(TFSProtocol FSProtocol)
- {
- return
- (FSProtocol == fsSFTPonly) || (FSProtocol == fsSFTP) ||
- (FSProtocol == fsSCPonly);
- }
- //---------------------------------------------------------------------------
- int __fastcall TLoginDialog::DefaultPort()
- {
- TFSProtocol FSProtocol = GetFSProtocol();
- TFtps Ftps = GetFtps();
- int Result;
- switch (FSProtocol)
- {
- case fsFTP:
- if (Ftps == ftpsImplicit)
- {
- Result = FtpsImplicitPortNumber;
- }
- else
- {
- Result = FtpPortNumber;
- }
- break;
- case fsWebDAV:
- if (Ftps == ftpsNone)
- {
- Result = HTTPPortNumber;
- }
- else
- {
- Result = HTTPSPortNumber;
- }
- break;
- default:
- if (IsSshProtocol(FSProtocol))
- {
- Result = SshPortNumber;
- }
- else
- {
- FAIL;
- Result = -1;
- }
- break;
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::TransferProtocolComboChange(TObject * Sender)
- {
- int ADefaultPort = DefaultPort();
- if (!NoUpdate && FUpdatePortWithProtocol)
- {
- NoUpdate++;
- try
- {
- if (PortNumberEdit->AsInteger == FDefaultPort)
- {
- PortNumberEdit->AsInteger = ADefaultPort;
- }
- }
- __finally
- {
- NoUpdate--;
- }
- }
- FDefaultPort = ADefaultPort;
- DataChange(Sender);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::NavigationTreeCollapsing(
- TObject * /*Sender*/, TTreeNode * /*Node*/, bool & AllowCollapse)
- {
- AllowCollapse = false;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ProxyLocalCommandBrowseButtonClick(
- TObject * /*Sender*/)
- {
- BrowseForExecutable(ProxyLocalCommandEdit,
- LoadStr(LOGIN_SELECT_LOCAL_PROXY),
- LoadStr(EXECUTABLE_FILTER), false, true);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeExpandedCollapsed(TObject * /*Sender*/,
- TTreeNode * Node)
- {
- UpdateFolderNode(Node);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeCompare(TObject * /*Sender*/,
- TTreeNode * Node1, TTreeNode * Node2, int /*Data*/, int & Compare)
- {
- bool Node1IsWorkspace = IsWorkspaceNode(Node1);
- bool Node2IsWorkspace = IsWorkspaceNode(Node2);
- bool Node1IsFolder = IsFolderNode(Node1);
- bool Node2IsFolder = IsFolderNode(Node2);
- if (Node1IsWorkspace && !Node2IsWorkspace)
- {
- Compare = -1;
- }
- else if (!Node1IsWorkspace && Node2IsWorkspace)
- {
- Compare = 1;
- }
- else if (Node1IsFolder && !Node2IsFolder)
- {
- Compare = -1;
- }
- else if (!Node1IsFolder && Node2IsFolder)
- {
- Compare = 1;
- }
- else if (Node1IsWorkspace || Node1IsFolder)
- {
- Compare = AnsiCompareText(Node1->Text, Node2->Text);
- }
- else
- {
- Compare = NamedObjectSortProc(Node1->Data, Node2->Data);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::NewSessionFolderInputDialogInitialize(
- TObject * /*Sender*/, TInputDialogData * Data)
- {
- TEdit * Edit = Data->Edit;
- int P = Edit->Text.LastDelimiter(L"/");
- if (P > 0)
- {
- Edit->SetFocus();
- Edit->SelStart = P;
- Edit->SelLength = Edit->Text.Length() - P;
- }
- }
- //---------------------------------------------------------------------------
- TTreeNode * __fastcall TLoginDialog::SessionFolderNode(TTreeNode * Node)
- {
- TTreeNode * Parent;
- if (IsSessionNode(Node))
- {
- Parent = Node->Parent;
- }
- else if (IsFolderNode(Node))
- {
- Parent = Node;
- }
- else if (IsWorkspaceNode(Node))
- {
- Parent = NULL;
- }
- else
- {
- assert(Node == NULL);
- Parent = NULL;
- }
- return Parent;
- }
- //---------------------------------------------------------------------------
- TTreeNode * __fastcall TLoginDialog::CurrentSessionFolderNode()
- {
- return SessionFolderNode(SessionTree->Selected);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::NewSessionFolderActionExecute(
- TObject * /*Sender*/)
- {
- UnicodeString Name =
- UnixIncludeTrailingBackslash(SessionNodePath(CurrentSessionFolderNode())) +
- LoadStr(NEW_FOLDER);
- if (InputDialog(LoadStr(LOGIN_NEW_SESSION_FOLDER_CAPTION),
- LoadStr(LOGIN_NEW_SESSION_FOLDER_PROMPT), Name, HELP_NEW_SESSION_FOLDER,
- NULL, true, NewSessionFolderInputDialogInitialize))
- {
- Name = UnixExcludeTrailingBackslash(Name);
- if (!Name.IsEmpty())
- {
- TTreeNode * Parent = AddSessionPath(UnixExtractFilePath(Name), true, false);
- // this does not prevent creation of subfolder under workspace,
- // if user creates more levels at once (but it does not show up anyway)
- CheckIsSessionFolder(Parent);
- CheckDuplicateFolder(Parent, UnixExtractFileName(Name), NULL);
- TTreeNode * Node = AddSessionPath(Name, true, false);
- SessionTree->Selected = Node;
- Node->MakeVisible();
- }
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TLoginDialog::SessionAllowDrop(TTreeNode * DropTarget)
- {
- return
- (SessionTree->Selected != NULL) &&
- (SessionTree->Selected->Parent != DropTarget) &&
- !IsWorkspaceNode(DropTarget);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeProc(TMessage & AMessage)
- {
- if (AMessage.Msg == CM_DRAG)
- {
- TCMDrag & Message = reinterpret_cast<TCMDrag &>(AMessage);
- // reimplement dmDragMove to avoid TCustomTreeView.DoDragOver,
- // which resets DropTarget to pointed-to node
- // (note that this disables OnDragOver event handler)
- if ((Message.DragMessage == dmDragMove) ||
- (Message.DragMessage == dmDragEnter) ||
- (Message.DragMessage == dmDragLeave))
- {
- if (Message.DragMessage != dmDragMove)
- {
- // must call it at least for dmDragLeave, because it does some cleanup,
- // but we need to override result below, as it defaults to "not accepted"
- FOldSessionTreeProc(AMessage);
- }
- TDragControlObject * DragObject = dynamic_cast<TDragControlObject *>(Message.DragRec->Source);
- if ((DragObject != NULL) && (DragObject->Control == SessionTree))
- {
- TPoint P = SessionTree->ScreenToClient(Message.DragRec->Pos);
- TTreeNode * Node = SessionTree->GetNodeAt(P.x, P.y);
- TTreeNode * DropTarget =
- IsWorkspaceNode(Node) ? Node : SessionFolderNode(Node);
- if (!SessionAllowDrop(DropTarget))
- {
- DropTarget = NULL;
- Message.Result = 0;
- }
- else
- {
- Message.Result = 1;
- }
- if (Message.DragMessage == dmDragMove)
- {
- SessionTree->DropTarget = DropTarget;
- }
- FScrollOnDragOver->DragOver(P);
- }
- else
- {
- Message.Result = 0;
- }
- }
- else
- {
- FOldSessionTreeProc(AMessage);
- }
- }
- else
- {
- FOldSessionTreeProc(AMessage);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeStartDrag(TObject * /*Sender*/,
- TDragObject *& /*DragObject*/)
- {
- assert(SessionTree->Selected != NULL);
- // neither session folders/workspaces not special sessions can be dragged
- if ((SessionTree->Selected == NULL) ||
- IsFolderOrWorkspaceNode(SessionTree->Selected) ||
- (IsSessionNode(SessionTree->Selected) && SelectedSession->Special))
- {
- Abort();
- }
- FScrollOnDragOver->StartDrag();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeDragDrop(TObject * Sender,
- TObject * Source, int /*X*/, int /*Y*/)
- {
- TTreeNode * DropTarget = SessionTree->DropTarget;
- if ((Sender == Source) && SessionAllowDrop(DropTarget))
- {
- TSessionData * Session = SelectedSession;
- UnicodeString Path =
- UnixIncludeTrailingBackslash(SessionNodePath(DropTarget)) +
- UnixExtractFileName(Session->SessionName);
- SessionNameValidate(Path, Session);
- // remove from storage
- Session->Remove();
- TSessionData * NewSession = StoredSessions->NewSession(Path, Session);
- // modified, only explicit
- StoredSessions->Save(false, true);
- // this should aways be the case
- if (Session != NewSession)
- {
- TTreeNode * Node = SessionTree->Selected;
- // look for overwritten node (if any)
- TTreeNode * ANode = SessionTree->Items->GetFirstNode();
- while (ANode != NULL)
- {
- if (ANode->Data == NewSession)
- {
- ANode->Delete();
- break;
- }
- ANode = ANode->GetNext();
- }
- Node->MoveTo(DropTarget, naAddChild);
- Node->Data = NewSession;
- // try to make both visible
- if (DropTarget != NULL)
- {
- DropTarget->MakeVisible();
- }
- Node->MakeVisible();
- DestroySession(Session);
- }
- else
- {
- assert(false);
- }
- SetSessionData(NewSession);
- }
- else
- {
- assert(false);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeMouseMove(TObject * /*Sender*/,
- TShiftState /*Shift*/, int X, int Y)
- {
- TTreeNode * Node = SessionTree->GetNodeAt(X, Y);
- THitTests HitTest = SessionTree->GetHitTestInfoAt(X, Y);
- if (Node != FHintNode)
- {
- Application->CancelHint();
- UnicodeString Hint;
- if (HitTest.Contains(htOnItem) || HitTest.Contains(htOnIcon) ||
- HitTest.Contains(htOnLabel) || HitTest.Contains(htOnStateIcon))
- {
- FHintNode = Node;
- if (IsSessionNode(Node))
- {
- Hint = GetNodeSession(Node)->InfoTip;
- }
- else if (IsWorkspaceNode(Node))
- {
- UnicodeString Path = SessionNodePath(Node);
- Hint = FMTLOAD(WORKSPACE_INFO_TIP, (Path));
- std::auto_ptr<TStrings> Names(FStoredSessions->GetFolderOrWorkspaceList(Path));
- for (int Index = 0; Index < Names->Count; Index++)
- {
- Hint += L"\n " + Names->Strings[Index];
- }
- }
- else
- {
- Hint = L"";
- }
- }
- else
- {
- FHintNode = NULL;
- Hint = L"";
- }
- SessionTree->Hint = Hint;
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeEndDrag(TObject * /*Sender*/,
- TObject * /*Target*/, int /*X*/, int /*Y*/)
- {
- FScrollOnDragOver->EndDrag();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::AnonymousLoginCheckClick(TObject * /*Sender*/)
- {
- if (AnonymousLoginCheck->Checked)
- {
- UserNameEdit->Text = AnonymousUserName;
- PasswordEdit->Text = AnonymousPassword;
- }
- UpdateControls();
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SaveButtonDropDownClick(TObject * /*Sender*/)
- {
- MenuPopup(SaveDropDownMenu, SaveButton);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeExpanding(TObject * /*Sender*/,
- TTreeNode * Node, bool & AllowExpansion)
- {
- AllowExpansion = IsFolderNode(Node);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ExecuteTool(const UnicodeString & Name)
- {
- UnicodeString Path;
- if (!FindTool(Name, Path) ||
- !ExecuteShell(Path, L""))
- {
- throw Exception(FMTLOAD(EXECUTE_APP_ERROR, (Name)));
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::RunPageantActionExecute(TObject * /*Sender*/)
- {
- ExecuteTool(PageantTool);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::RunPuttygenActionExecute(TObject * /*Sender*/)
- {
- ExecuteTool(PuttygenTool);
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::PortNumberEditChange(TObject * Sender)
- {
- if (!NoUpdate)
- {
- bool WellKnownPort = false;
- TFSProtocol FSProtocol;
- TFtps Ftps = ftpsNone;
- int PortNumber = PortNumberEdit->AsInteger;
- if (PortNumber == SshPortNumber)
- {
- FSProtocol = fsSFTP;
- WellKnownPort = true;
- }
- else if (PortNumber == FtpPortNumber)
- {
- FSProtocol = fsFTP;
- WellKnownPort = true;
- }
- else if (PortNumber == FtpsImplicitPortNumber)
- {
- FSProtocol = fsFTP;
- Ftps = ftpsImplicit;
- WellKnownPort = true;
- }
- else if (PortNumber == HTTPPortNumber)
- {
- FSProtocol = fsWebDAV;
- WellKnownPort = true;
- }
- else if (PortNumber == HTTPSPortNumber)
- {
- FSProtocol = fsWebDAV;
- Ftps = ftpsImplicit;
- WellKnownPort = true;
- }
- if (WellKnownPort)
- {
- bool AllowScpFallback;
- int ProtocolIndex = FSProtocolToIndex(FSProtocol, AllowScpFallback);
- if ((TransferProtocolCombo->ItemIndex == ProtocolIndex) &&
- (GetFtps() == Ftps))
- {
- FUpdatePortWithProtocol = true;
- }
- else
- {
- FUpdatePortWithProtocol = false;
- NoUpdate++;
- try
- {
- TransferProtocolCombo->ItemIndex = ProtocolIndex;
- FtpsCombo->ItemIndex = Ftps;
- WebDavsCombo->ItemIndex = Ftps;
- }
- __finally
- {
- NoUpdate--;
- }
- }
- }
- }
- DataChange(Sender);
- }
- //---------------------------------------------------------------------------
- UnicodeString __fastcall TLoginDialog::ImportExportIniFilePath()
- {
- UnicodeString PersonalDirectory;
- ::SpecialFolderLocation(CSIDL_PERSONAL, PersonalDirectory);
- UnicodeString FileName = IncludeTrailingBackslash(PersonalDirectory) +
- ExtractFileName(ExpandEnvironmentVariables(Configuration->IniFileStorageName));
- return FileName;
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ExportActionExecute(TObject * /*Sender*/)
- {
- UnicodeString FileName = ImportExportIniFilePath();
- if (SaveDialog(LoadStr(EXPORT_CONF_TITLE), LoadStr(EXPORT_CONF_FILTER), L"ini", FileName))
- {
- Configuration->Export(FileName);
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ImportActionExecute(TObject * /*Sender*/)
- {
- if (MessageDialog(LoadStr(IMPORT_CONFIGURATION),
- qtWarning, qaOK | qaCancel, HELP_IMPORT_CONFIGURATION) == qaOK)
- {
- std::auto_ptr<TOpenDialog> OpenDialog(new TOpenDialog(Application));
- OpenDialog->Title = LoadStr(IMPORT_CONF_TITLE);
- OpenDialog->Filter = LoadStr(EXPORT_CONF_FILTER);
- OpenDialog->DefaultExt = L"ini";
- OpenDialog->FileName = ImportExportIniFilePath();
- if (OpenDialog->Execute())
- {
- // before the session list gets destroyed
- SessionTree->Items->Clear();
- Configuration->Import(OpenDialog->FileName);
- ReloadSessions();
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::ResetSitesIncrementalSearch()
- {
- FSitesIncrementalSearch = L"";
- // this is to prevent active tree node being set back to Sites tab
- // (from UpdateNavigationTree) when we are called from SessionTreeExit,
- // while tab is changing
- if (NoUpdate == 0)
- {
- UpdateControls();
- }
- }
- //---------------------------------------------------------------------------
- bool __fastcall TLoginDialog::SitesIncrementalSearch(const UnicodeString & Text,
- bool SkipCurrent, bool Reverse)
- {
- TTreeNode * Node = SearchSite(Text, false, SkipCurrent, Reverse);
- if (Node == NULL)
- {
- Node = SearchSite(Text, true, SkipCurrent, Reverse);
- if (Node != NULL)
- {
- TTreeNode * Parent = Node->Parent;
- while (Parent != NULL)
- {
- Parent->Expand(false);
- Parent = Parent->Parent;
- }
- }
- }
- bool Result = (Node != NULL);
- if (Result)
- {
- {
- TAutoNestingCounter Guard(FIncrementalSearching);
- SessionTree->Selected = Node;
- }
- FSitesIncrementalSearch = Text;
- // Tab always searches even in collapsed nodes
- TTreeNode * NextNode = SearchSite(Text, true, true, Reverse);
- FSitesIncrementalSearchHaveNext =
- (NextNode != NULL) && (NextNode != Node);
- UpdateControls();
- // make visible only after search panel is shown, what may obscure the node
- Node->MakeVisible();
- }
- return Result;
- }
- //---------------------------------------------------------------------------
- TTreeNode * __fastcall TLoginDialog::GetNextNode(TTreeNode * Node, bool Reverse)
- {
- if (Reverse)
- {
- Node = Node->GetPrev();
- if (Node == NULL)
- {
- // GetLastNode
- // http://stackoverflow.com/questions/6257348/how-should-i-implement-getlastnode-for-ttreenodes
- Node = SessionTree->Items->GetFirstNode();
- TTreeNode * Node2 = Node;
- if (Node2 != NULL)
- {
- do
- {
- Node2 = Node;
- if (Node != NULL)
- {
- Node = Node2->getNextSibling();
- }
- if (Node == NULL)
- {
- Node = Node2->getFirstChild();
- }
- }
- while (Node != NULL);
- }
- Node = Node2;
- }
- }
- else
- {
- Node = Node->GetNext();
- if (Node == NULL)
- {
- Node = SessionTree->Items->GetFirstNode();
- }
- }
- return Node;
- }
- //---------------------------------------------------------------------------
- TTreeNode * __fastcall TLoginDialog::SearchSite(const UnicodeString & Text,
- bool AllowExpanding, bool SkipCurrent, bool Reverse)
- {
- TTreeNode * CurrentNode =
- (SessionTree->Selected != NULL) ? SessionTree->Selected : SessionTree->Items->GetFirstNode();
- if (CurrentNode == NULL)
- {
- return NULL;
- }
- else
- {
- TTreeNode * Node = CurrentNode;
- if (SkipCurrent)
- {
- Node = GetNextNode(Node, Reverse);
- if (Node == NULL)
- {
- return NULL;
- }
- }
- while (true)
- {
- bool Eligible = true;
- TTreeNode * Parent = Node->Parent;
- while (Eligible && (Parent != NULL))
- {
- Eligible =
- IsFolderNode(Parent) &&
- (Parent->Expanded || AllowExpanding);
- Parent = Parent->Parent;
- }
- if (Eligible && ContainsText(Node->Text, Text))
- {
- return Node;
- }
- Node = GetNextNode(Node, Reverse);
- if (Node == CurrentNode)
- {
- return NULL;
- }
- }
- }
- }
- //---------------------------------------------------------------------------
- void __fastcall TLoginDialog::SessionTreeExit(TObject * /*Sender*/)
- {
- ResetSitesIncrementalSearch();
- }
- //---------------------------------------------------------------------------
|