xref: /aoo4110/main/uui/source/cookiedg.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include <svl/httpcook.hxx>
25 #include <tools/urlobj.hxx>
26 #include <vcl/msgbox.hxx>
27 
28 #ifndef UUI_COOKIEDG_HRC
29 #include <cookiedg.hrc>
30 #endif
31 #include <cookiedg.hxx>
32 #ifndef UUI_IDS_HRC
33 #include <ids.hrc>
34 #endif
35 
36 // CookiesDialog ---------------------------------------------------------
37 
IMPL_LINK(CookiesDialog,ButtonHdl_Impl,PushButton *,pBtn)38 IMPL_LINK( CookiesDialog, ButtonHdl_Impl, PushButton *, pBtn )
39 {
40 	short nRet = ( &maSendBtn == pBtn ) ? RET_OK : RET_CANCEL;
41 	EndDialog( nRet );
42 	return 1;
43 }
44 
45 // -----------------------------------------------------------------------
CookiesDialog(Window * pParent,CntHTTPCookieRequest * pRequest,ResMgr * pResMgr)46 CookiesDialog::CookiesDialog( Window* pParent,
47 							  CntHTTPCookieRequest* pRequest,
48 							  ResMgr* pResMgr ) :
49 
50 	ModalDialog( pParent, ResId( DLG_COOKIES, *pResMgr ) ),
51 
52 	maCookieFB				( this, ResId( FB_COOKIES, *pResMgr ) ),
53 	maCookieFT				( this, ResId( FT_COOKIES, *pResMgr ) ),
54 	maInFutureLine			( this, ResId( FL_COOKIES, *pResMgr ) ),
55 	maInFutureSendBtn		( this, ResId( RB_INFUTURE_SEND, *pResMgr ) ),
56 	maInFutureIgnoreBtn		( this, ResId( RB_INFUTURE_IGNORE, *pResMgr ) ),
57 	maInFutureInteractiveBtn( this, ResId( RB_INFUTURE_INTERACTIVE, *pResMgr ) ),
58 	maInFutureGB			( this, ResId( GB_INFUTURE, *pResMgr ) ),
59 	maIgnoreBtn				( this, ResId( BTN_COOKIES_CANCEL, *pResMgr ) ),
60 	maSendBtn				( this, ResId( BTN_COOKIES_OK, *pResMgr ) ),
61 
62 	mpCookieRequest			( pRequest )
63 
64 {
65 	FreeResource();
66 
67 	Link aLink( LINK( this, CookiesDialog, ButtonHdl_Impl ) );
68 	maIgnoreBtn.SetClickHdl( aLink );
69 	maSendBtn.SetClickHdl( aLink );
70 	const Bitmap& rBitmap = maCookieFB.GetBitmap();
71 	Size aSize = rBitmap.GetSizePixel();
72 	SetMapMode( MapMode( MAP_APPFONT ) );
73 	Size aLogicSize = PixelToLogic( aSize );
74 	Point aPoint( 6 ,
75 				  6 + ( 145 - aLogicSize.Height() ) / 2 );
76 	maCookieFB.SetPosSizePixel( LogicToPixel( aPoint ), aSize );
77 	maCookieFB.Show();
78 
79 	sal_uInt16 nOffset = CNTHTTP_COOKIE_REQUEST_RECV == mpCookieRequest->m_eType
80 		? 0 : STR_COOKIES_SEND_START - STR_COOKIES_RECV_START;
81 	INetURLObject aObj( mpCookieRequest->m_rURL );
82 	SetText( String( ResId( STR_COOKIES_RECV_TITLE + nOffset, *pResMgr ) ) );
83 	String aMsg( ResId( STR_COOKIES_RECV_START + nOffset, *pResMgr ) );
84 	aMsg.SearchAndReplaceAscii( "${HOST}", aObj.GetHost() );
85 	aMsg.SearchAndReplaceAscii( "${PATH}", aObj.GetPath() );
86 	String aTemplate( ResId( STR_COOKIES_RECV_COOKIES, *pResMgr ) );
87 	List& rList =mpCookieRequest->m_rCookieList;
88 	String aPair, aCookie;
89 
90 	for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
91 	{
92 		CntHTTPCookie* pCookie = (CntHTTPCookie*)rList.GetObject(i);
93 
94 		if ( CNTHTTP_COOKIE_POLICY_INTERACTIVE == pCookie->m_nPolicy )
95 		{
96 			aCookie = aTemplate;
97 			aCookie.SearchAndReplaceAscii( "${DOMAIN}", pCookie->m_aDomain );
98 			aCookie.SearchAndReplaceAscii( "${PATH}", pCookie->m_aPath );
99 			aPair = pCookie->m_aName;
100 			aPair += '=';
101 			aPair += pCookie->m_aValue;
102 			aCookie.SearchAndReplaceAscii( "${COOKIE}", aPair );
103 			aMsg += aCookie;
104 		}
105 	}
106 	maInFutureInteractiveBtn.Check( sal_True );
107 	maCookieFT.SetText( aMsg );
108 }
109 
110 // -----------------------------------------------------------------------
111 
Execute()112 short CookiesDialog::Execute()
113 {
114 	maSendBtn.GrabFocus();
115 	short nRet = ModalDialog::Execute();
116 	sal_uInt16 nStatus = CNTHTTP_COOKIE_POLICY_INTERACTIVE;
117 
118 	if ( maInFutureSendBtn.IsChecked() )
119 		nStatus = CNTHTTP_COOKIE_POLICY_ACCEPTED;
120 
121 	if ( maInFutureIgnoreBtn.IsChecked() )
122 		nStatus = CNTHTTP_COOKIE_POLICY_BANNED;
123 	List& rList = mpCookieRequest->m_rCookieList;
124 
125 	for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
126 	{
127 		sal_uInt16& rStatus = ( (CntHTTPCookie*)rList.GetObject(i) )->m_nPolicy;
128 
129 		if ( rStatus == CNTHTTP_COOKIE_POLICY_INTERACTIVE )
130 			rStatus = nStatus;
131 	}
132 
133 	if ( nRet == RET_OK )
134 		mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_ACCEPTED;
135 	else
136 		mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_BANNED;
137 
138 	return nRet;
139 }
140 
141