/*
 * AddBlogInfoDlg.cpp : ここうさぎウィザード carot
 *      ブログ情報設定(追加・編集)ダイアログ インプリメンテーション ファイル
 *          written by H.Tsujimura  18 Mar 2005
 *
 * $Log: /makeRSS/carot/AddBlogInfoDlg.cpp $
 * 
 * 46    09/03/23 16:14 Tsujimura543
 * Windows Live Spaces およびウェブリブログの blogID の扱いに関する修正
 * 
 * 45    09/03/20 23:00 Tsujimura543
 * ウェブリブログの XML-RPC API 経由ではない方の諸々を削除
 * 
 * 44    09/03/20 22:27 Tsujimura543
 * はてなダイアリー(の Atom API での投稿)に対応した
 * 
 * 43    09/03/20 18:27 Tsujimura543
 * ウェブリブログの XMLRPC API 対応作業開始
 * 
 * 42    07/11/30 2:52 Tsujimura543
 * (1) Jugem、ヤプログ!、ドリコムブログの XML-RPC API 経由ではない方の
 *     諸々を削除
 * (2) しまにてぃ内日記関連の諸々を削除 (2007年11月30日でサービス終了)
 * 
 * 41    07/10/29 17:55 Tsujimura543
 * ヤプログ! の XML-RPC API に対応
 * 
 * 40    07/10/18 0:03 Tsujimura543
 * 余分なコメントを削除
 * 
 * 39    07/10/17 23:57 Tsujimura543
 * バージョン管理用コメント、IDを入れるようにする
 */

#include "carot.h"
#include "AddBlogInfoDlg.h"
#include "EndPointDlg.h"
#include "BlogIDSelectDlg.h"

#ifndef	lint
static char	*rcs_id =
"$Header: /makeRSS/carot/AddBlogInfoDlg.cpp 46    09/03/23 16:14 Tsujimura543 $";
#endif

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAddBlogInfoDlg ダイアログ

CAddBlogInfoDlg::CAddBlogInfoDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CAddBlogInfoDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CAddBlogInfoDlg)
	m_blogID = _T("");
	m_blogName = _T("");
	m_blogPassword = _T("");
	m_blogUserName = _T("");
	m_endpointURL = _T("");
	m_blogURL = _T("");
	//}}AFX_DATA_INIT

    m_blogInfo = NULL;
    m_blogKind = CCarotDlg::unset;
    m_useCbox  = false;
    m_mode     = true;
}

void CAddBlogInfoDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAddBlogInfoDlg)
	DDX_Control(pDX, IDC_COMBO_BLOG_LIST, m_blogKindList);
	DDX_Text(pDX, IDC_EDIT_BLOGID, m_blogID);
	DDV_MaxChars(pDX, m_blogID, 48);
	DDX_Text(pDX, IDC_EDIT_BLOGNAME, m_blogName);
	DDV_MaxChars(pDX, m_blogName, 127);
	DDX_Text(pDX, IDC_EDIT_BLOGPASSWORD, m_blogPassword);
	DDV_MaxChars(pDX, m_blogPassword, 16);
	DDX_Text(pDX, IDC_EDIT_BLOGUSERNAME, m_blogUserName);
	DDV_MaxChars(pDX, m_blogUserName, 32);
	DDX_Text(pDX, IDC_EDIT_ENDPOINTURL, m_endpointURL);
	DDV_MaxChars(pDX, m_endpointURL, 384);
	DDX_Text(pDX, IDC_EDIT_BLOGURL, m_blogURL);
	DDV_MaxChars(pDX, m_blogURL, 384);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAddBlogInfoDlg, CDialog)
	//{{AFX_MSG_MAP(CAddBlogInfoDlg)
	ON_BN_CLICKED(IDC_BUTTON_MOREINFO, OnButtonMoreInfo)
	ON_WM_SHOWWINDOW()
	ON_CBN_SELCHANGE(IDC_COMBO_BLOG_LIST, OnSelchangeComboBlogList)
	ON_EN_UPDATE(IDC_EDIT_BLOGUSERNAME, OnUpdateEditBlogUserName)
	ON_EN_UPDATE(IDC_EDIT_BLOGPASSWORD, OnUpdateEditBlogPassword)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CAddBlogInfoDlg 追加メソッド

void    CAddBlogInfoDlg::switchEndpointURL()
{
    CEdit   *p = (CEdit *)GetDlgItem( IDC_EDIT_ENDPOINTURL );

    if ( m_mode )
        m_endpointURL = "";

    if ( (m_blogKind == CCarotDlg::bloggerAPI)  ||
         (m_blogKind == CCarotDlg::metaWeblog)  ||
         (m_blogKind == CCarotDlg::mtAPI)       ||
         (m_blogKind == CCarotDlg::atomAPI)     ||
         (m_blogKind == CCarotDlg::newPostOnly)    )
        p->SetReadOnly( FALSE );
    else
        p->SetReadOnly( TRUE );

    if ( (m_blogKind == CCarotDlg::typepad)      ||
         (m_blogKind == CCarotDlg::typepadJapan) ||
         (m_blogKind == CCarotDlg::cocolog)      ||
         (m_blogKind == CCarotDlg::cocologFree)  ||
         (m_blogKind == CCarotDlg::blogzine)     ||
         (m_blogKind == CCarotDlg::newsHandler)  ||
         (m_blogKind == CCarotDlg::ameblo)       ||
         (m_blogKind == CCarotDlg::seesaa)       ||
         (m_blogKind == CCarotDlg::netLaputa)    ||
         (m_blogKind == CCarotDlg::blogG)        ||
         (m_blogKind == CCarotDlg::fc2blog)      ||
         (m_blogKind == CCarotDlg::gooBlog)      ||
         (m_blogKind == CCarotDlg::msnSpaces)    ||
         (m_blogKind == CCarotDlg::drecomX)      ||
         (m_blogKind == CCarotDlg::yaplogX)      ||
         (m_blogKind == CCarotDlg::jugemX)       ||
         (m_blogKind == CCarotDlg::webryX)       ||
         (m_blogKind == CCarotDlg::livedoor)     ||
         (m_blogKind == CCarotDlg::lovelog)      ||
         (m_blogKind == CCarotDlg::sonet)        ||
         (m_blogKind == CCarotDlg::vox)          ||
         (m_blogKind == CCarotDlg::hatena)       ||
         (m_blogKind == CCarotDlg::blogger)      ||
         (m_blogKind == CCarotDlg::movableType)     ) {
        int blogKindIndex = -1;
        int i;

        for ( i = 0; i < m_blogInfo->m_numOfBlogKinds; i++ ) {
            if ( m_blogInfo->m_blogKindInfo[i].blogKind == (CCarotDlg::blogKind)m_blogKind )
                break;
        }
        blogKindIndex = i;
        if ( m_endpointURL.GetLength() == 0 )
            m_endpointURL = m_blogInfo->m_blogKindInfo[blogKindIndex].endpointURL;
    }
    else
        m_endpointURL = "";

    p->SetWindowText( m_endpointURL );
}

void    CAddBlogInfoDlg::switchBlogID()
{
    CEdit   *cp = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );

    if ( m_mode )
        m_blogID = "";
    cp->SetWindowText( m_blogID );

    if ( m_useCbox ) {
        m_blogID = "0";
        cp->SetWindowText( m_blogID );
    }
    else if ( /* (m_blogKind == CCarotDlg::movableType)  || */
                 (m_blogKind == CCarotDlg::bloggerAPI)   ||
                 (m_blogKind == CCarotDlg::metaWeblog)   ||
                 (m_blogKind == CCarotDlg::mtAPI)        ||
                 (m_blogKind == CCarotDlg::atomAPI)         )
        cp->SetReadOnly( FALSE );
    /*
    else if ( (m_blogKind == CCarotDlg::typepad)      ||
              (m_blogKind == CCarotDlg::typepadJapan) ||
              (m_blogKind == CCarotDlg::cocolog)      ||
              (m_blogKind == CCarotDlg::cocologFree)  ||
              (m_blogKind == CCarotDlg::blogzine)     ||
              (m_blogKind == CCarotDlg::newsHandler)  ||
              (m_blogKind == CCarotDlg::ameblo)       ||
              (m_blogKind == CCarotDlg::seesaa)       ||
              (m_blogKind == CCarotDlg::netLaputa)    ||
              (m_blogKind == CCarotDlg::blogG)        ||
              (m_blogKind == CCarotDlg::fc2blog)      ||
              (m_blogKind == CCarotDlg::gooBlog)      ||
              (m_blogKind == CCarotDlg::msnSpaces)    ||
              (m_blogKind == CCarotDlg::drecomX)      ||
              (m_blogKind == CCarotDlg::yaplogX)      ||
              (m_blogKind == CCarotDlg::jugemX)       ||
              (m_blogKind == CCarotDlg::webryX)       ||
              (m_blogKind == CCarotDlg::livedoor)     ||
              (m_blogKind == CCarotDlg::lovelog)      ||
              (m_blogKind == CCarotDlg::sonet)        ||
              (m_blogKind == CCarotDlg::vox)          ||
              (m_blogKind == CCarotDlg::hatena)       ||
              (m_blogKind == CCarotDlg::blogger)         )
        cp->SetReadOnly( TRUE );
    */
    else
        cp->SetReadOnly( TRUE );
}

void    CAddBlogInfoDlg::switchBlogName()
{
    CEdit   *cp = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );

    if ( m_mode )
        m_blogName = "";

    if ( m_useCbox ) {
        m_blogName = "BlogPet 飼育箱";
        cp->SetReadOnly( TRUE );
    }
    else if ( /* (m_blogKind == CCarotDlg::movableType)  || */
                 (m_blogKind == CCarotDlg::bloggerAPI)   ||
                 (m_blogKind == CCarotDlg::metaWeblog)   ||
                 (m_blogKind == CCarotDlg::mtAPI)        ||
                 (m_blogKind == CCarotDlg::atomAPI)         )
        cp->SetReadOnly( FALSE );
    else if ( (m_blogKind == CCarotDlg::typepad)      ||
              (m_blogKind == CCarotDlg::typepadJapan) ||
              (m_blogKind == CCarotDlg::cocolog)      ||
              (m_blogKind == CCarotDlg::cocologFree)  ||
              (m_blogKind == CCarotDlg::blogzine)     ||
              (m_blogKind == CCarotDlg::newsHandler)  ||
              (m_blogKind == CCarotDlg::ameblo)       ||
              (m_blogKind == CCarotDlg::seesaa)       ||
              (m_blogKind == CCarotDlg::netLaputa)    ||
              (m_blogKind == CCarotDlg::blogG)        ||
              (m_blogKind == CCarotDlg::fc2blog)      ||
              (m_blogKind == CCarotDlg::gooBlog)      ||
              (m_blogKind == CCarotDlg::msnSpaces)    ||
              (m_blogKind == CCarotDlg::drecomX)      ||
              (m_blogKind == CCarotDlg::yaplogX)      ||
              (m_blogKind == CCarotDlg::jugemX)       ||
              (m_blogKind == CCarotDlg::webryX)       ||
              (m_blogKind == CCarotDlg::livedoor)     ||
              (m_blogKind == CCarotDlg::lovelog)      ||
              (m_blogKind == CCarotDlg::sonet)        ||
              (m_blogKind == CCarotDlg::vox)          ||
              (m_blogKind == CCarotDlg::hatena)       ||
              (m_blogKind == CCarotDlg::blogger)         ) {
        cp->SetReadOnly( TRUE );
    }
    else if ( m_blogKind == CCarotDlg::kinugasa ) {
        m_blogName = "キヌガサ";
        cp->SetReadOnly( TRUE );
    }
    else if ( m_blogKind == CCarotDlg::mixi ) {
        m_blogName = "mixi";
        cp->SetReadOnly( TRUE );
    }
    else if ( m_blogKind == CCarotDlg::fc2network ) {
        m_blogName = "FC2NETWORK";
        cp->SetReadOnly( TRUE );
    }
    else if ( m_blogKind == CCarotDlg::colors ) {
        m_blogName = "COLORS";
        cp->SetReadOnly( TRUE );
    }
    else if ( m_blogKind == CCarotDlg::openPne ) {
        m_blogName = "OpenPNE";
        cp->SetReadOnly( TRUE );
    }
    else
        cp->SetReadOnly( TRUE );

    cp->SetWindowText( m_blogName );
}

void        CAddBlogInfoDlg::switchBlogURL()
{
    CEdit   *cp = (CEdit *)GetDlgItem( IDC_EDIT_BLOGURL );
    
    if ( m_mode )
        m_blogURL = "";

    if ( m_blogKind == CCarotDlg::kinugasa )
        m_blogURL = "http://kinugasa.cc/diary.php";
    else if ( m_blogKind == CCarotDlg::mixi )
        m_blogURL = "http://mixi.jp/list_diary.pl";
    else if ( m_blogKind == CCarotDlg::fc2network )
        m_blogURL = "http://network.fc2.com/diary/index.php";
    else if ( m_blogKind == CCarotDlg::colors )
        m_blogURL = "http://clrs.jp/list_diary.php";
    else if ( m_blogKind == CCarotDlg::openPne )
        m_blogURL = "http://openpne.jp/?m=pc&a=page_fh_diary_list";

    cp->SetWindowText( m_blogURL );
}

void    CAddBlogInfoDlg::switchMoreInfo()
{
    CButton *bp = (CButton *)GetDlgItem( IDC_BUTTON_MOREINFO );

    if ( (m_blogKind == CCarotDlg::movableType)  ||
         (m_blogKind == CCarotDlg::bloggerAPI)   ||
         (m_blogKind == CCarotDlg::metaWeblog)   ||
         (m_blogKind == CCarotDlg::mtAPI)        ||
         (m_blogKind == CCarotDlg::atomAPI)      ||
         (m_blogKind == CCarotDlg::typepad)      ||
         (m_blogKind == CCarotDlg::typepadJapan) ||
         (m_blogKind == CCarotDlg::cocolog)      ||
         (m_blogKind == CCarotDlg::cocologFree)  ||
         (m_blogKind == CCarotDlg::blogzine)     ||
         (m_blogKind == CCarotDlg::newsHandler)  ||
         (m_blogKind == CCarotDlg::ameblo)       ||
         (m_blogKind == CCarotDlg::seesaa)       ||
         (m_blogKind == CCarotDlg::netLaputa)    ||
         (m_blogKind == CCarotDlg::blogG)        ||
         (m_blogKind == CCarotDlg::fc2blog)      ||
         (m_blogKind == CCarotDlg::gooBlog)      ||
         (m_blogKind == CCarotDlg::msnSpaces)    ||
         (m_blogKind == CCarotDlg::drecomX)      ||
         (m_blogKind == CCarotDlg::yaplogX)      ||
         (m_blogKind == CCarotDlg::jugemX)       ||
         (m_blogKind == CCarotDlg::webryX)       ||
         (m_blogKind == CCarotDlg::livedoor)     ||
         (m_blogKind == CCarotDlg::lovelog)      ||
         (m_blogKind == CCarotDlg::sonet)        ||
         (m_blogKind == CCarotDlg::vox)          ||
         (m_blogKind == CCarotDlg::hatena)       ||
         (m_blogKind == CCarotDlg::blogger)      ||
         (m_blogKind == CCarotDlg::exciteBlog)   ||
         (m_blogKind == CCarotDlg::echoo)        ||
         (m_blogKind == CCarotDlg::rakuten)         ) {
        if ( (m_blogUserName.GetLength() > 0) &&
             (m_blogPassword.GetLength() > 0)    )
            bp->EnableWindow( TRUE );
        else
            bp->EnableWindow( FALSE );
    }
    else
        bp->EnableWindow( FALSE );
}

/////////////////////////////////////////////////////////////////////////////
// CAddBlogInfoDlg メッセージ ハンドラ

void CAddBlogInfoDlg::OnButtonMoreInfo() 
{
	// 追加情報取得
    CEdit   *p;

#define MAX_BLOGS       30  /* 同一システム内最大設置可能blog数 */

    if ( (m_blogKind == CCarotDlg::movableType) ||
         (m_blogKind == CCarotDlg::metaWeblog)  ||
         (m_blogKind == CCarotDlg::mtAPI)       ||
         (m_blogKind == CCarotDlg::atomAPI)        ) {
        // エンドポイントURLの自動取得を試みる
        //  -- トップページ URL を取得
        char    topPageURL[MAX_URLLENGTH + 1];
        CEndPointDlg    dialog;
        int res = dialog.DoModal();
        if ( (res == IDOK) && (dialog.m_endPointURL.GetLength() > 0) ) {
            strcpy( topPageURL, (const char *)dialog.m_endPointURL );
            m_blogURL = topPageURL;
            p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGURL );
            p->SetWindowText( m_blogURL );

            // -- エンドポイントURL と blog ID を取得
            char    id[MAX_BLOGIDLENGTH + 1];
            char    *url = NULL;

            memset( id, 0x00, MAX_BLOGIDLENGTH + 1 );
            if ( m_blogKind == CCarotDlg::atomAPI ) {
                CWaitCursor cur;    // マウスカーソルを砂時計表示
                url = getEndpointURLbyAutoDiscoveryOnAtomAPI(
                                                     topPageURL, id );
            }
            else {
                CWaitCursor cur;    // マウスカーソルを砂時計表示
                url = getEndpointURLbyAutoDiscovery( topPageURL, id );
            }

            if ( url && *url ) {
                MessageBox( "エンドポイントURLの取得に成功しました。    ",
                            "取得成功", MB_OK|MB_ICONINFORMATION );
                m_endpointURL = url;
                p = (CEdit *)GetDlgItem( IDC_EDIT_ENDPOINTURL );
                p->SetWindowText( m_endpointURL );

                if ( id[0] ) {
                    p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );
                    m_blogID = id;
                    p->SetWindowText( m_blogID );

                    // -- blog名の取得
                    BLOGINF blogInfo[MAX_BLOGS];
                    int     numOfBlogs = MAX_BLOGS;
                    int     r;

                    setTargetURL( m_endpointURL );
                    if ( m_blogKind == CCarotDlg::atomAPI ) {
                        //  --- Atom API 系の場合
                        CWaitCursor cur;    // マウスカーソルを砂時計表示
                        r = getBlogIDsOnAtomAPI( m_blogUserName, m_blogPassword,
                                                 &numOfBlogs, blogInfo );
                    }
                    else {
                        //  --- blogger API 系の場合
                        CWaitCursor cur;    // マウスカーソルを砂時計表示
                        r = getBlogIDs( m_blogUserName, m_blogPassword,
                                        &numOfBlogs, blogInfo );    /* blogger API */
                    }

                    if ( r == 1 ) {
                        MessageBox( "blog名の取得に成功しました。    ",
                                    "取得成功", MB_OK|MB_ICONINFORMATION );
                        m_blogName = utf2sjis( blogInfo[0].blogName );  /* 確定 */
                        p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );
                        p->SetWindowText( (const char *)m_blogName );
                    }
                    else if ( r > 1 ) {
                        for ( int i = 0; i < r; i++ ) {
                            if ( !strcmp( (const char *)m_blogID, blogInfo[i].blogID ) ) {
                                MessageBox( "blog名の取得に成功しました。    ",
                                            "取得成功", MB_OK|MB_ICONINFORMATION );
                                m_blogName = utf2sjis( blogInfo[i].blogName );  /* 確定 */
                                p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );
                                p->SetWindowText( (const char *)m_blogName );
                                break;
                            }
                        }
                    }
                    else {
                        MessageBox( "blog名の取得に失敗しました。\n\n"
                                    "ユーザ名、パスワードが正しいか確認してください。    ",
                                    "設定確認", MB_OK|MB_ICONWARNING );
                    }
                }
            }
            else
                MessageBox( "エンドポイントURLの取得に失敗しました。\n\n"
                            "ユーザ名、パスワードが正しいか確認してください。    ",
                            "設定確認", MB_OK|MB_ICONWARNING );
        }
    }
    else if ( (m_blogKind == CCarotDlg::bloggerAPI)   ||
              (m_blogKind == CCarotDlg::typepad)      ||
              (m_blogKind == CCarotDlg::typepadJapan) ||
              (m_blogKind == CCarotDlg::cocolog)      ||
              (m_blogKind == CCarotDlg::cocologFree)  ||
              (m_blogKind == CCarotDlg::blogzine)     ||
              (m_blogKind == CCarotDlg::newsHandler)  ||
              (m_blogKind == CCarotDlg::ameblo)       ||
              (m_blogKind == CCarotDlg::seesaa)       ||
              (m_blogKind == CCarotDlg::netLaputa)    ||
              (m_blogKind == CCarotDlg::blogG)        ||
              (m_blogKind == CCarotDlg::fc2blog)      ||
              (m_blogKind == CCarotDlg::gooBlog)      ||
              (m_blogKind == CCarotDlg::msnSpaces)    ||
              (m_blogKind == CCarotDlg::drecomX)      ||
              (m_blogKind == CCarotDlg::yaplogX)      ||
              (m_blogKind == CCarotDlg::jugemX)       ||
              (m_blogKind == CCarotDlg::webryX)       ||
              (m_blogKind == CCarotDlg::livedoor)     ||
              (m_blogKind == CCarotDlg::lovelog)      ||
              (m_blogKind == CCarotDlg::sonet)        ||
              (m_blogKind == CCarotDlg::vox)          ||
              (m_blogKind == CCarotDlg::hatena)       ||
              (m_blogKind == CCarotDlg::blogger)         ) {
        // blog ID の自動取得を試みる
        //  -- 複数の blog が存在する場合は一覧表示し、
        //     ユーザに選択してもらう

        if ( m_blogPassword.GetLength() <= 0 ) {
            // blog ID の取得にはパスワード必須
            MessageBox( "blog ID の自動取得を試みます。\n"
                        "blog ID の自動取得には、「blog にloginする"
                        "ときのパスワード」が必要です。    \n"
                        "blog にloginするときのパスワードを設定して"
                        "ください。",
                        "設定確認", MB_OK|MB_ICONWARNING );
            return;
        }

        if ( m_blogKind == CCarotDlg::hatena ) {
            if ( strstr( m_endpointURL, "{hatenaID}" ) ) {
                m_endpointURL =
                    "http://d.hatena.ne.jp/" + m_blogUserName + "/atom/blog";
                p = (CEdit *)GetDlgItem( IDC_EDIT_ENDPOINTURL );
                p->SetWindowText( m_endpointURL );
            }
        }

        BLOGINF blogInfo[MAX_BLOGS];
        int     numOfBlogs = MAX_BLOGS;
        int     r;

        /* --- 投稿可能な blog 一覧の取得 */
        if ( m_blogKind == CCarotDlg::jugemX ) {
            if ( m_blogUserName.GetLength() > 0 ) {
                char    url[MAX_URLLENGTH];
                char    endpointURL[MAX_URLLENGTH];

                strcpy( endpointURL, m_endpointURL );

                const char  *q = strchr( endpointURL, '$' );
                if ( q )
                    q++;
                else
                    q = ".jugem.jp/admin/xmlrpc.php";
                sprintf( url, "http://%s%s",
                         (const char *)m_blogUserName,
                         q );

                m_endpointURL = url;
                p = (CEdit *)GetDlgItem( IDC_EDIT_ENDPOINTURL );
                p->SetWindowText( m_endpointURL );
            }
        }
        blogInfo[0].blogName[0] = NUL;
        setTargetURL( m_endpointURL );
        if ( (m_blogKind == CCarotDlg::livedoor) ||
             (m_blogKind == CCarotDlg::lovelog)  ||
             (m_blogKind == CCarotDlg::sonet)    ||
             (m_blogKind == CCarotDlg::ameblo)   ||
             (m_blogKind == CCarotDlg::vox)      ||
             (m_blogKind == CCarotDlg::hatena)   ||
             (m_blogKind == CCarotDlg::blogger)     ) {
            //  --- Atom API 系の場合
            CWaitCursor cur;    // マウスカーソルを砂時計表示
            r = getBlogIDsOnAtomAPI( m_blogUserName, m_blogPassword,
                                     &numOfBlogs, blogInfo );
                    /* 備考: 本家の blogger.com に対しては blogger API */
                    /*       ではなく Atom API を適用する              */
        }
        else {
            //  --- blogger API 系の場合
            CWaitCursor cur;    // マウスカーソルを砂時計表示
            r = getBlogIDs( m_blogUserName, m_blogPassword,
                            &numOfBlogs, blogInfo );    /* blogger API */
        }
        if ( (r >= 1) && (blogInfo[0].blogName[0] == NUL) ) {
            /* FC2BLOG のように取得に失敗しても r == 1 となる blog 対策 */
            MessageBox( "blog ID の取得に失敗しました。\n"
                        "ユーザ名、パスワードが正しいか確認してください。    ",
                        "取得失敗", MB_OK|MB_ICONWARNING );
        }
        else if ( r == 1 ) {
            MessageBox( "blog ID の取得に成功しました。    ",
                        "取得成功", MB_OK|MB_ICONINFORMATION );
            m_blogName = utf2sjis( blogInfo[0].blogName );  /* 確定 */
            m_blogID   = blogInfo[0].blogID;                /* 確定 */
            m_blogURL  = blogInfo[0].url;                   /* 確定 */

            if ( m_blogID == "" )
                if ( (m_blogKind == CCarotDlg::msnSpaces) ||
                     (m_blogKind == CCarotDlg::webryX)       )
                    m_blogID = "MyBlog";

            p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );
            p->SetWindowText( (const char *)m_blogName );

            p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );
            p->SetWindowText( (const char *)m_blogID );

            if ( !strncmp( m_blogURL, m_endpointURL, strlen(m_endpointURL) ) ) {
                if ( m_blogKind == CCarotDlg::livedoor )
                    m_blogURL = "http://blog.livedoor.jp/" + m_blogUserName + "/";
                if ( m_blogKind == CCarotDlg::lovelog )
                    m_blogURL = "http://blog.dion.ne.jp/" + m_blogUserName + "/";
                if ( m_blogKind == CCarotDlg::ameblo )
                    m_blogURL = "http://ameblo.jp/" + m_blogUserName + "/";
                if ( m_blogKind == CCarotDlg::sonet )
                    m_blogURL = "http://blog.so-net.ne.jp/" + m_blogUserName + "/";
            }
            p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGURL );
            p->SetWindowText( m_blogURL );
        }
        else if ( r > 1 ) {
            /* ---- 投稿先 blog の選択 */
            CBlogIDSelectDlg    dlg;
            dlg.initialize( blogInfo, r );
            int res = dlg.DoModal();
            if ( (res == IDOK) && (dlg.m_blogIDlistIndex != -1) ) {
                if ( (dlg.m_blogIDlistIndex >= 0) && (dlg.m_blogIDlistIndex < r) ) {
                    r = dlg.m_blogIDlistIndex;
                    m_blogName = utf2sjis( blogInfo[r].blogName );  /* 確定 */
                    m_blogID   = blogInfo[r].blogID;                /* 確定 */
                    m_blogURL  = blogInfo[r].url;                   /* 確定 */

                    if ( m_blogID == "" )
                        if ( (m_blogKind == CCarotDlg::msnSpaces) ||
                             (m_blogKind == CCarotDlg::webryX)       )
                            m_blogID = "MyBlog";

                    p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );
                    p->SetWindowText( (const char *)m_blogName );

                    p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );
                    p->SetWindowText( (const char *)m_blogID );

                    p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGURL );
                    p->SetWindowText( m_blogURL );

                    MessageBox( "blog ID の取得に成功しました。    ",
                                "取得成功", MB_OK|MB_ICONINFORMATION );
                }
            }
        }
        else {
            MessageBox( "blog ID の取得に失敗しました。\n"
                        "ユーザ名、パスワードが正しいか確認してください。    ",
                        "取得失敗", MB_OK|MB_ICONWARNING );
        }
    }
    else if ( m_blogKind == CCarotDlg::newPostOnly ) {
        m_blogID = "0";
        p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );
        p->SetWindowText( (const char *)m_blogID );
    }
    else if ( (m_blogKind == CCarotDlg::exciteBlog) ||
              (m_blogKind == CCarotDlg::echoo)      ||
              (m_blogKind == CCarotDlg::rakuten)       ) {
        BLOGINF blogInfo[MAX_BLOGS];
        int     numOfBlogs = MAX_BLOGS;
        int     r = 0;

        CWaitCursor cur;    // マウスカーソルを砂時計表示

        switch ( m_blogKind ) {
        case CCarotDlg::exciteBlog:
            r = getBlogIDsExciteBlog( m_blogUserName, m_blogPassword,
                                      &numOfBlogs, blogInfo );
            break;

        case CCarotDlg::echoo:
            r = getBlogIDsEchoo( m_blogUserName, m_blogPassword,
                                 &numOfBlogs, blogInfo );
            break;

        case CCarotDlg::rakuten:
            r = getBlogIDsRakuten( m_blogUserName, m_blogPassword,
                                   &numOfBlogs, blogInfo );
            break;
        }

        if ( r == 1 ) {
            MessageBox( "blog URL の取得に成功しました。    ",
                        "取得成功", MB_OK|MB_ICONINFORMATION );

            m_blogURL  = blogInfo[0].url;
            m_blogName = blogInfo[0].blogName;

            p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );
            p->SetWindowText( (const char *)m_blogName );

            p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGURL );
            p->SetWindowText( m_blogURL );

            if ( m_blogKind == CCarotDlg::exciteBlog ) {
                m_blogID = blogInfo[0].blogID;
                p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );
                p->SetWindowText( m_blogID );
            }
        }
        else if ( r <= 0 ) {
            MessageBox("blog URL の取得に失敗しました。"
                       "ユーザ名、パスワードが正しいか確認してください。    ",
                       "取得失敗", MB_OK|MB_ICONWARNING );
        }
    }
}

void CAddBlogInfoDlg::OnShowWindow(BOOL bShow, UINT nStatus) 
{
	CDialog::OnShowWindow(bShow, nStatus);
	
    if ( bShow ) {
        if ( m_blogInfo ) {
            m_blogKindList.InitStorage( CAROT_NUM_OF_BLOG_KINDS,
                                        CAROT_MAX_BLOG_NAME_LENGTH );
            m_blogKindList.ResetContent();
            for ( int i = 0; i < m_blogInfo->m_numOfBlogKinds; i++ ) {
                m_blogKindList.AddString( m_blogInfo->m_blogKindInfo[i].blogKindString );
            }
        }

        CEdit   *p;
        p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );
        p->SetReadOnly( TRUE );
        p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGURL );
        p->SetReadOnly( TRUE );
        p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );
        p->SetReadOnly( TRUE );
        p = (CEdit *)GetDlgItem( IDC_EDIT_ENDPOINTURL );
        p->SetReadOnly( TRUE );

        CButton *bp = (CButton *)GetDlgItem( IDC_BUTTON_MOREINFO );
        bp->EnableWindow( FALSE );

        if ( m_mode == false ) {
            long    location = -1;

            if ( (m_blogKind == CCarotDlg::newPostOnly) && (m_useCbox == true) ) {
                // 「BlogPet 飼育箱」のための特別処理
                for ( location = 0; location < m_blogInfo->m_numOfBlogKinds; location++ ) {
                    if ( !strcmp( m_blogInfo->m_blogKindInfo[location].blogKindString,
                                  "BlogPet 飼育箱" ) )
                        break;
                }
            }
            else {
                for ( location = 0; location < m_blogInfo->m_numOfBlogKinds; location++ ) {
                    if ( m_blogKind == m_blogInfo->m_blogKindInfo[location].blogKind )
                        break;
                }
            }

            if ( (location >= 0) && (location < m_blogInfo->m_numOfBlogKinds) )
                m_blogKindList.SetCurSel( location );

            OnSelchangeComboBlogList();
            SetWindowText( "登録情報修正" );
        }
    }
}

void CAddBlogInfoDlg::OnSelchangeComboBlogList() 
{
	int location = m_blogKindList.GetCurSel();

    m_blogKind = m_blogInfo->m_blogKindInfo[location].blogKind;

    if ( !strcmp( m_blogInfo->m_blogKindInfo[location].blogKindString, "BlogPet 飼育箱" ) )
        m_useCbox = true;
    else
        m_useCbox = false;

    switchBlogName();
    switchBlogURL();
    switchBlogID();
    switchEndpointURL();
    switchMoreInfo();
}

void CAddBlogInfoDlg::OnUpdateEditBlogUserName() 
{
    CEdit   *p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGUSERNAME );
    p->GetWindowText( m_blogUserName );

    switchMoreInfo();
}

void CAddBlogInfoDlg::OnUpdateEditBlogPassword() 
{
    CEdit   *p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGPASSWORD );
    p->GetWindowText( m_blogPassword );

    switchMoreInfo();
}

void CAddBlogInfoDlg::OnOK() 
{
    // 入力内容チェック
    CEdit   *p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGUSERNAME );
    p->GetWindowText( m_blogUserName );
    if ( m_blogUserName.GetLength() == 0 ) {
        MessageBox( "「ユーザ名、または ID」を設定してください    ",
                    "設定確認", MB_OK|MB_ICONWARNING );
        return;
    }

    p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGPASSWORD );
    p->GetWindowText( m_blogPassword );
    if ( m_blogPassword.GetLength() == 0 ) {
        MessageBox( "「パスワード」を設定してください    ",
                    "設定確認", MB_OK|MB_ICONWARNING );
        return;
    }

    if ( m_blogKind == CCarotDlg::unset ) {
        MessageBox( "「blog の種類」を設定してください    ",
                    "設定確認", MB_OK|MB_ICONWARNING );
        return;
    }

    p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGNAME );
    p->GetWindowText( m_blogName );
    if ( m_blogName.GetLength() == 0 ) {
        if ( (m_blogKind == CCarotDlg::movableType)  ||
             (m_blogKind == CCarotDlg::bloggerAPI)   ||
             (m_blogKind == CCarotDlg::metaWeblog)   ||
             (m_blogKind == CCarotDlg::mtAPI)        ||
             (m_blogKind == CCarotDlg::atomAPI)      ||
             (m_blogKind == CCarotDlg::newPostOnly)  ||   
             (m_blogKind == CCarotDlg::typepad)      ||
             (m_blogKind == CCarotDlg::typepadJapan) ||
             (m_blogKind == CCarotDlg::cocolog)      ||
             (m_blogKind == CCarotDlg::cocologFree)  ||
             (m_blogKind == CCarotDlg::blogzine)     ||
             (m_blogKind == CCarotDlg::newsHandler)  ||
             (m_blogKind == CCarotDlg::ameblo)       ||
             (m_blogKind == CCarotDlg::seesaa)       ||
             (m_blogKind == CCarotDlg::netLaputa)    ||
             (m_blogKind == CCarotDlg::blogG)        ||
             (m_blogKind == CCarotDlg::fc2blog)      ||
             (m_blogKind == CCarotDlg::gooBlog)      ||
             (m_blogKind == CCarotDlg::msnSpaces)    ||
             (m_blogKind == CCarotDlg::drecomX)      ||
             (m_blogKind == CCarotDlg::yaplogX)      ||
             (m_blogKind == CCarotDlg::jugemX)       ||
             (m_blogKind == CCarotDlg::webryX)       ||
             (m_blogKind == CCarotDlg::livedoor)     ||
             (m_blogKind == CCarotDlg::lovelog)      ||
             (m_blogKind == CCarotDlg::sonet)        ||
             (m_blogKind == CCarotDlg::vox)          ||
             (m_blogKind == CCarotDlg::hatena)       ||
             (m_blogKind == CCarotDlg::blogger)      ||
             (m_blogKind == CCarotDlg::exciteBlog)   ||
             (m_blogKind == CCarotDlg::echoo)        ||
             (m_blogKind == CCarotDlg::rakuten)         ) {
            // 追加情報取得
            OnButtonMoreInfo();
        }

        if ( m_blogName.GetLength() == 0 ) {
            MessageBox( "「blog 名」を設定してください    ",
                        "設定確認", MB_OK|MB_ICONWARNING );
            return;
        }
    }

    if ( (m_blogKind == CCarotDlg::movableType)  ||
         (m_blogKind == CCarotDlg::bloggerAPI)   ||
         (m_blogKind == CCarotDlg::metaWeblog)   ||
         (m_blogKind == CCarotDlg::mtAPI)        ||
         (m_blogKind == CCarotDlg::atomAPI)      ||
         (m_blogKind == CCarotDlg::newPostOnly)  ||   
         (m_blogKind == CCarotDlg::typepad)      ||
         (m_blogKind == CCarotDlg::typepadJapan) ||
         (m_blogKind == CCarotDlg::cocolog)      ||
         (m_blogKind == CCarotDlg::cocologFree)  ||
         (m_blogKind == CCarotDlg::blogzine)     ||
         (m_blogKind == CCarotDlg::newsHandler)  ||
         (m_blogKind == CCarotDlg::ameblo)       ||
         (m_blogKind == CCarotDlg::seesaa)       ||
         (m_blogKind == CCarotDlg::netLaputa)    ||
         (m_blogKind == CCarotDlg::blogG)        ||
         (m_blogKind == CCarotDlg::fc2blog)      ||
         (m_blogKind == CCarotDlg::gooBlog)      ||
      /* (m_blogKind == CCarotDlg::msnSpaces)    || */
         (m_blogKind == CCarotDlg::drecomX)      ||
         (m_blogKind == CCarotDlg::yaplogX)      ||
         (m_blogKind == CCarotDlg::jugemX)       ||
      /* (m_blogKind == CCarotDlg::webryX)       || */
         (m_blogKind == CCarotDlg::livedoor)     ||
         (m_blogKind == CCarotDlg::lovelog)      ||
         (m_blogKind == CCarotDlg::sonet)        ||
         (m_blogKind == CCarotDlg::vox)          ||
         (m_blogKind == CCarotDlg::hatena)       ||
         (m_blogKind == CCarotDlg::blogger)         ) {
        if ( m_blogID.GetLength() == 0 ) {
            p = (CEdit *)GetDlgItem( IDC_EDIT_BLOGID );
            p->GetWindowText( m_blogID );
            if ( m_blogID.GetLength() == 0 ) {
                MessageBox( "「blog ID」を設定してください    ",
                            "設定確認", MB_OK|MB_ICONWARNING );
                return;
            }
        }

        if ( m_useCbox ) {
            p = (CEdit *)GetDlgItem( IDC_EDIT_ENDPOINTURL );
            p->GetWindowText( m_endpointURL );
        }
        if ( m_endpointURL.GetLength() == 0 ) {
            p = (CEdit *)GetDlgItem( IDC_EDIT_ENDPOINTURL );
            p->GetWindowText( m_endpointURL );
            if ( m_endpointURL.GetLength() == 0 ) {
                MessageBox( "「エンドポイントURL」を設定してください    ",
                            "設定確認", MB_OK|MB_ICONWARNING );
                return;
            }
        }
    }

	CDialog::OnOK();
}
