forked from tsupo/Chirrup
-
Notifications
You must be signed in to change notification settings - Fork 1
/
JaikuAuthSelectDialog.cpp
225 lines (190 loc) · 5.93 KB
/
JaikuAuthSelectDialog.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
/*
* JaikuAuthSelectDialog.cpp : Jaiku クライアント chirrup
* Jaiku認証方法設定ダイアログ インプリメンテーション ファイル
* written by H.Tsujimura 14 Apr 2009
*
* Copyright (c) 2009 by H.Tsujimura (tsupo@na.rim.or.jp)
* All Rights Reserved.
*
* $Log: /comm/chirrup/JaikuAuthSelectDialog.cpp $
*
* 2 09/05/15 2:34 tsupo
* 「1.140版→1.141版」での変更点を取り込む
*
* 3 09/05/14 14:52 Tsujimura543
* ユーザ名未設定状態で本ダイアログを起動したとき、ユーザ名を入力後、
* ラジオボタンをクリックすると、ユーザ名の欄がクリアされてしまう不具合
* に対処
*
* 1 09/05/14 3:50 tsupo
* (1) ビルド環境のディレクトリ構造を整理
* (2) VSSサーバ拠点を変更
*
* 2 09/04/16 3:40 Tsujimura543
* Jaiku の「発言ID」、「コメントID」の仕様変更に伴う修正を実施
*
* 1 09/04/14 23:36 Tsujimura543
* 最初の版
*/
#include "chirrup.h"
#include "Jaiku.h"
#include "JaikuAuthSelectDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#if (WINVER >= 0x0500)
//#define IDC_HAND MAKEINTRESOURCE(32649)
#ifdef IDC_HAND
#undef IDC_HAND
#endif
#endif /* WINVER >= 0x0500 */
#define IDC_HAND IDC_HAND2
/////////////////////////////////////////////////////////////////////////////
// JaikuAuthSelectDialog ダイアログ
JaikuAuthSelectDialog::JaikuAuthSelectDialog(CWnd* pParent /*=NULL*/)
: CDialog(JaikuAuthSelectDialog::IDD, pParent)
{
//{{AFX_DATA_INIT(JaikuAuthSelectDialog)
m_username = _T("");
m_password = _T("");
//}}AFX_DATA_INIT
m_useOAuth = false;
m_useBASIC = false;
m_oauthToken = _T("");
m_oauthTokenSecret = _T("");
m_hCursor = AfxGetApp()->LoadCursor( IDC_HAND );
}
JaikuAuthSelectDialog::~JaikuAuthSelectDialog()
{
m_cFont.DeleteObject();
}
void JaikuAuthSelectDialog::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(JaikuAuthSelectDialog)
DDX_Text(pDX, IDC_EDIT_USERNAME, m_username);
DDV_MaxChars(pDX, m_username, 32);
DDX_Text(pDX, IDC_EDIT_PASSWORD, m_password);
DDV_MaxChars(pDX, m_password, 64);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(JaikuAuthSelectDialog, CDialog)
//{{AFX_MSG_MAP(JaikuAuthSelectDialog)
ON_BN_CLICKED(IDC_BUTTON_GET_TOKEN, OnButtonGetToken)
ON_BN_CLICKED(IDC_RADIO_BASIC, OnRadioBasic)
ON_BN_CLICKED(IDC_RADIO_OAUTH, OnRadioOauth)
ON_BN_CLICKED(IDC_URL_JAIKU_APIKEY, OnUrlJaikuApiKey)
ON_WM_SHOWWINDOW()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// JaikuAuthSelectDialog 追加メソッド
void JaikuAuthSelectDialog::ShowCurrentStatus( bool rescan /* = FALSE */ )
{
CButton *bp = (CButton *)GetDlgItem( IDC_BUTTON_GET_TOKEN );
bp->EnableWindow( m_useOAuth );
bp = (CButton *)GetDlgItem( IDC_RADIO_OAUTH );
bp->SetCheck( m_useOAuth ? 1 : 0 );
bp = (CButton *)GetDlgItem( IDC_RADIO_BASIC );
bp->SetCheck( m_useBASIC ? 1 : 0 );
CString status;
CStatic *sp = (CStatic *)GetDlgItem( IDC_TOKEN_STATUS );
if ( (m_oauthToken.GetLength() > 0) &&
(m_oauthTokenSecret.GetLength() > 0) )
status.LoadString( IDS_ACCESSTOKEN_ACQUIRED );
else
status.LoadString( IDS_ACCESSTOKEN_UNTAKEN );
sp->SetWindowText( status );
CEdit *p = (CEdit *)GetDlgItem(IDC_EDIT_USERNAME);
if ( rescan )
p->GetWindowText( m_username );
p->SetWindowText( m_username );
p->EnableWindow( TRUE );
p = (CEdit *)GetDlgItem(IDC_EDIT_PASSWORD);
if ( rescan )
p->GetWindowText( m_password );
p->SetWindowText( m_password );
p->EnableWindow( m_useBASIC );
}
/////////////////////////////////////////////////////////////////////////////
// JaikuAuthSelectDialog メッセージ ハンドラ
void JaikuAuthSelectDialog::OnShowWindow(BOOL bShow, UINT nStatus)
{
CDialog::OnShowWindow(bShow, nStatus);
if ( bShow ) {
ShowCurrentStatus();
CString str;
str.LoadString( IDS_URL_JAIKU_APIKEY );
LOGFONT tLogFont;
CFont *cWndFont;
cWndFont = GetFont();
cWndFont->GetLogFont( &tLogFont );
tLogFont.lfUnderline = 1;
m_cFont.CreateFontIndirect( &tLogFont );
CStatic *s = (CStatic *)GetDlgItem( IDC_URL_JAIKU_APIKEY );
s->SetWindowText( str );
s->SetFont( &m_cFont, TRUE );
}
}
void JaikuAuthSelectDialog::OnButtonGetToken()
{
CWaitCursor cur; // マウスカーソルを砂時計表示
CJaiku j;
CChirrupApp *ap = (CChirrupApp *)AfxGetApp();
j.GetAccessToken( ap->m_jcKey, ap->m_jcSecret,
m_oauthToken, m_oauthTokenSecret );
ShowCurrentStatus();
}
void JaikuAuthSelectDialog::OnRadioBasic()
{
if ( m_useBASIC ) {
m_useBASIC = false;
m_useOAuth = true;
}
else {
m_useBASIC = true;
m_useOAuth = false;
}
ShowCurrentStatus( true );
}
void JaikuAuthSelectDialog::OnRadioOauth()
{
if ( m_useOAuth ) {
m_useBASIC = true;
m_useOAuth = false;
}
else {
m_useBASIC = false;
m_useOAuth = true;
}
ShowCurrentStatus( true );
}
void JaikuAuthSelectDialog::OnUrlJaikuApiKey()
{
CString cmd;
cmd.LoadString( IDS_URL_JAIKU_APIKEY );
ShellExecute( NULL, "open", cmd, NULL, NULL, SW_SHOWNORMAL );
}
BOOL JaikuAuthSelectDialog::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
if ( nHitTest == HTCLIENT ) {
// Web の URLかメールアドレスにマウスポインタが来たら、
// 指カーソルを表示する
DWORD dwPos = GetMessagePos();
WORD wX = LOWORD( dwPos );
WORD wY = HIWORD( dwPos );
CPoint poCursor( wX, wY );
CRect rcClient;
CStatic *s = (CStatic *)GetDlgItem( IDC_URL_JAIKU_APIKEY );
s->GetWindowRect( &rcClient );
if ( (wX >= rcClient.left) && (wX <= rcClient.right) &&
(wY >= rcClient.top) && (wY <= rcClient.bottom) ) {
SetCursor( m_hCursor );
return TRUE;
}
}
return CDialog::OnSetCursor(pWnd, nHitTest, message);
}