⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 opencftpclientappui.cpp

📁 在SYMBIAN平台上用OPEN C实现的一个FTP客户程序
💻 CPP
字号:
/***************************************************************************/
/*                                                                         */
/* OpenCFTPClientAppUi.cpp - Part of Open C FTP Client                     */
/*                                                                         */
/* Copyright (C) 2007 Nokia Corporation                                    */
/*                                                                         */
/* Open C FTP Client is based on ftplib and qftp by Thomas Pfau.           */
/*                                                                         */
/* Copyright (C) 1996-2001 Thomas Pfau, pfau@eclipse.net                   */
/* 1407 Thomas Ave, North Brunswick, NJ, 08902                             */
/*                                                                         */
/* This program is free software; you can redistribute it and/or           */
/* modify it under the terms of the GNU Library General Public             */
/* License as published by the Free Software Foundation; either            */
/* version 2 of the License, or (at your option) any later version.        */
/*                                                                         */
/* This program is distributed in the hope that it will be useful,         */
/* but WITHOUT ANY WARRANTY; without even the implied warranty of          */
/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU       */
/* Library General Public License for more details.                        */
/*                                                                         */
/* You should have received a copy of the GNU Library General Public       */
/* License along with this program; if not, write to the                   */
/* Free Software Foundation, Inc., 59 Temple Place - Suite 330,            */
/* Boston, MA 02111-1307, USA.                                             */
/*                                                                         */
/***************************************************************************/
 
/*
 * ============================================================================
 *  Name     : OpenCFTPClientAppUi from OpenCFTPClientAppUi.cpp
 *  Part of  : Open C FTP Client
 *  Created  : 03/12/2007 by Forum Nokia
 *  Version  : 1.0
 * ============================================================================
*/

#include <avkon.hrh>
#include <avkon.rsg>
#include <aknglobalnote.h>
#include <aknnotewrappers.h>
#include <barsread.h>
#include <OpenCFTPClient.rsg>
#include <stdlib.h>
#include <stringloader.h>

#include "ListControl.h"
#include "ListView.h"
#include "OpenCFTPClient.pan"
#include "OpenCFTPClient.hrh"
#include "OpenCFTPClientAppUi.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void COpenCFTPClientAppUi::ConstructL()
{
	_LIT(KDefaultLineEnd, "\0");
	lineEnd = KDefaultLineEnd;

    BaseConstructL(CAknAppUi::EAknEnableSkin);

    view = CListView::NewLC();
    AddViewL(view);
    CleanupStack::Pop(view);

    LoadConnectionSettings();
}
// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::COpenCFTPClientAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
COpenCFTPClientAppUi::COpenCFTPClientAppUi()
{
    // No implementation required
}

// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::~COpenCFTPClientAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
COpenCFTPClientAppUi::~COpenCFTPClientAppUi()
{

}

// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::HandleCommandL()
// Takes care of command handling.
// -----------------------------------------------------------------------------
//
void COpenCFTPClientAppUi::HandleCommandL( TInt aCommand )
{
    switch( aCommand )
    {
        case EEikCmdExit:
        case EAknSoftkeyExit:
            Exit();
            break;

        case ECommand1:
        {
        	const TInt argumentCount = 7;

            TBuf8<maxLength> aBuffer;
            aBuffer.Fill('\0');
            aBuffer.Copy(address);
            aBuffer.Append(lineEnd);
            TBuf8<maxLength> uBuffer;
            uBuffer.Fill('\0');
            uBuffer.Copy(username);
            uBuffer.Append(lineEnd);
            TBuf8<maxLength> pBuffer;
            pBuffer.Fill('\0');
            pBuffer.Copy(password);
            pBuffer.Append(lineEnd);

            char *command[] = {"dir",
            				   (char *)aBuffer.Ptr(),
            				   "-l",
            				   (char *)uBuffer.Ptr(),
            				   "-p",
            				   (char *)pBuffer.Ptr(),
            				   "\n"};

            view->iContainer->SetConnectionOptions(aBuffer, uBuffer, pBuffer);

            TRAPD(error, view->iContainer->DownloadFileListL(argumentCount, command));

            if (error != -1)
            {
                view->iContainer->ShowNoteL(R_COMPLETED_TEXT);
            }
            else
            {
                view->iContainer->ShowNoteL(R_ERROR_TEXT);
			}
        }
            break;
            
        case ECommand2:
        {
            TBuf<maxLength> inputBuffer;
            TBuf<maxLength> portBuffer; // we have to save port setting before continuing
           	_LIT(KColon, ":");
            inputBuffer = address.Left(address.Find(KColon));
            portBuffer = address.Mid(address.Find(KColon)+1, 2);
            CAknTextQueryDialog* addressDialog = new ( ELeave ) CAknTextQueryDialog(inputBuffer);
            addressDialog->PrepareLC( R_ADDRESS_QUERY );
            addressDialog->SetMaxLength(maxLength);
            if (addressDialog->RunLD())
            {
                address = inputBuffer;
            }
            CAknTextQueryDialog* portDialog = new ( ELeave ) CAknTextQueryDialog(portBuffer);
            portDialog->PrepareLC( R_PORT_QUERY );
            portDialog->SetMaxLength(maxLength);
            if (portDialog->RunLD())
            {
                address.Append(KColon);
                address.Append(portBuffer);
            }
            SaveConnectionSettings();
        }
            break;

        case ECommand3:
        {
            TBuf<maxLength> inputBuffer;
            inputBuffer = username;
            CAknTextQueryDialog* userDialog = new ( ELeave ) CAknTextQueryDialog(inputBuffer);
            userDialog->PrepareLC( R_USERNAME_QUERY );
            userDialog->SetMaxLength(maxLength);
            if (userDialog->RunLD())
            {
                username = inputBuffer;
            }
            inputBuffer = password;
            CAknTextQueryDialog* passwordDialog = new ( ELeave ) CAknTextQueryDialog(inputBuffer);
            passwordDialog->PrepareLC( R_PASSWORD_QUERY );
            passwordDialog->SetMaxLength(maxLength);
            if (passwordDialog->RunLD())
            {
                password = inputBuffer;
            }
            SaveConnectionSettings();
        }
            break;

        default:
            Panic( EOpenCFTPClientUi );
            break;
    }
}

// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::SaveConnectionSettings()
// Saves changed connection settings
// -----------------------------------------------------------------------------
//
void COpenCFTPClientAppUi::SaveConnectionSettings()
{
    RFs aFs;
    aFs.Connect();

    _LIT(KFileName,"C:\\Data\\Others\\OpenCFTPClientSettings.cfg");

    //delete the old file before new one can be written over
    aFs.Delete(KFileName);
  
    RFile file;
    file.Create(aFs,KFileName,EFileWrite|EFileShareAny);
  
    TFileText fileText;
    fileText.Set(file);
    fileText.Seek(ESeekStart);

    TBuf<maxLength> settings;
    settings.Fill('\0');
    settings.Append(address);
    settings.Append('\n');
    settings.Append(username);
    settings.Append('\n');
    settings.Append(password);

    fileText.Write(settings);
         
    file.Close();
    aFs.Close();
}

// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::LoadConnectionSettings()
// Loads connection settings at start
// -----------------------------------------------------------------------------
//
void COpenCFTPClientAppUi::LoadConnectionSettings()
{
    RFs aFs;
    aFs.Connect();

    _LIT(KFileName,"C:\\Data\\Others\\OpenCFTPClientSettings.cfg");
    RFile file;
    TInt error;
    error = file.Open(aFs, KFileName, EFileRead|EFileShareAny);
    if (error == KErrNotFound)
    {
        CreateSettingsFile();
        file.Open(aFs, KFileName, EFileRead|EFileShareAny);
    }

    TFileText fileText;
    fileText.Set(file);
    fileText.Seek(ESeekStart);

    TBuf<50> buf;

    fileText.Read(buf);
    address = buf;
    fileText.Read(buf);
    username = buf;
    fileText.Read(buf);
    password = buf;

    file.Close();
    aFs.Close();
}

// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::CreateSettingsFile()
// Creates a new default connection settings file
// -----------------------------------------------------------------------------
//
void COpenCFTPClientAppUi::CreateSettingsFile()
{
    RFs aFs;
    aFs.Connect();

    _LIT(KFileName,"C:\\Data\\Others\\OpenCFTPClientSettings.cfg");

    RFile file;
    file.Create(aFs,KFileName,EFileWrite|EFileShareAny);
  
    TFileText fileText;
    fileText.Set(file);
    fileText.Seek(ESeekStart);

	_LIT(KDefaultSettings, "ftp.funet.fi:21\nanonymous\npassword");
    fileText.Write(KDefaultSettings);
         
    file.Close();
    aFs.Close();
}

// -----------------------------------------------------------------------------
// COpenCFTPClientAppUi::HandleStatusPaneSizeChange()
// Called by the framework when the application status pane
// size is changed.  Passes the new client rectangle to the
// AppView
// -----------------------------------------------------------------------------
//
void COpenCFTPClientAppUi::HandleStatusPaneSizeChange()
{

} 

// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -