xref: /aoo42x/main/uui/source/cookiedg.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include <svl/httpcook.hxx>
29 #include <tools/urlobj.hxx>
30 #include <vcl/msgbox.hxx>
31 
32 #ifndef UUI_COOKIEDG_HRC
33 #include <cookiedg.hrc>
34 #endif
35 #include <cookiedg.hxx>
36 #ifndef UUI_IDS_HRC
37 #include <ids.hrc>
38 #endif
39 
40 // CookiesDialog ---------------------------------------------------------
41 
42 IMPL_LINK( CookiesDialog, ButtonHdl_Impl, PushButton *, pBtn )
43 {
44 	short nRet = ( &maSendBtn == pBtn ) ? RET_OK : RET_CANCEL;
45 	EndDialog( nRet );
46 	return 1;
47 }
48 
49 // -----------------------------------------------------------------------
50 CookiesDialog::CookiesDialog( Window* pParent,
51 							  CntHTTPCookieRequest* pRequest,
52 							  ResMgr* pResMgr ) :
53 
54 	ModalDialog( pParent, ResId( DLG_COOKIES, *pResMgr ) ),
55 
56 	maCookieFB				( this, ResId( FB_COOKIES, *pResMgr ) ),
57 	maCookieFT				( this, ResId( FT_COOKIES, *pResMgr ) ),
58 	maInFutureLine			( this, ResId( FL_COOKIES, *pResMgr ) ),
59 	maInFutureSendBtn		( this, ResId( RB_INFUTURE_SEND, *pResMgr ) ),
60 	maInFutureIgnoreBtn		( this, ResId( RB_INFUTURE_IGNORE, *pResMgr ) ),
61 	maInFutureInteractiveBtn( this, ResId( RB_INFUTURE_INTERACTIVE, *pResMgr ) ),
62 	maInFutureGB			( this, ResId( GB_INFUTURE, *pResMgr ) ),
63 	maIgnoreBtn				( this, ResId( BTN_COOKIES_CANCEL, *pResMgr ) ),
64 	maSendBtn				( this, ResId( BTN_COOKIES_OK, *pResMgr ) ),
65 
66 	mpCookieRequest			( pRequest )
67 
68 {
69 	FreeResource();
70 
71 	Link aLink( LINK( this, CookiesDialog, ButtonHdl_Impl ) );
72 	maIgnoreBtn.SetClickHdl( aLink );
73 	maSendBtn.SetClickHdl( aLink );
74 	const Bitmap& rBitmap = maCookieFB.GetBitmap();
75 	Size aSize = rBitmap.GetSizePixel();
76 	SetMapMode( MapMode( MAP_APPFONT ) );
77 	Size aLogicSize = PixelToLogic( aSize );
78 	Point aPoint( 6 ,
79 				  6 + ( 145 - aLogicSize.Height() ) / 2 );
80 	maCookieFB.SetPosSizePixel( LogicToPixel( aPoint ), aSize );
81 	maCookieFB.Show();
82 
83 	sal_uInt16 nOffset = CNTHTTP_COOKIE_REQUEST_RECV == mpCookieRequest->m_eType
84 		? 0 : STR_COOKIES_SEND_START - STR_COOKIES_RECV_START;
85 	INetURLObject aObj( mpCookieRequest->m_rURL );
86 	SetText( String( ResId( STR_COOKIES_RECV_TITLE + nOffset, *pResMgr ) ) );
87 	String aMsg( ResId( STR_COOKIES_RECV_START + nOffset, *pResMgr ) );
88 	aMsg.SearchAndReplaceAscii( "${HOST}", aObj.GetHost() );
89 	aMsg.SearchAndReplaceAscii( "${PATH}", aObj.GetPath() );
90 	String aTemplate( ResId( STR_COOKIES_RECV_COOKIES, *pResMgr ) );
91 	List& rList =mpCookieRequest->m_rCookieList;
92 	String aPair, aCookie;
93 
94 	for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
95 	{
96 		CntHTTPCookie* pCookie = (CntHTTPCookie*)rList.GetObject(i);
97 
98 		if ( CNTHTTP_COOKIE_POLICY_INTERACTIVE == pCookie->m_nPolicy )
99 		{
100 			aCookie = aTemplate;
101 			aCookie.SearchAndReplaceAscii( "${DOMAIN}", pCookie->m_aDomain );
102 			aCookie.SearchAndReplaceAscii( "${PATH}", pCookie->m_aPath );
103 			aPair = pCookie->m_aName;
104 			aPair += '=';
105 			aPair += pCookie->m_aValue;
106 			aCookie.SearchAndReplaceAscii( "${COOKIE}", aPair );
107 			aMsg += aCookie;
108 		}
109 	}
110 	maInFutureInteractiveBtn.Check( sal_True );
111 	maCookieFT.SetText( aMsg );
112 }
113 
114 // -----------------------------------------------------------------------
115 
116 short CookiesDialog::Execute()
117 {
118 	maSendBtn.GrabFocus();
119 	short nRet = ModalDialog::Execute();
120 	sal_uInt16 nStatus = CNTHTTP_COOKIE_POLICY_INTERACTIVE;
121 
122 	if ( maInFutureSendBtn.IsChecked() )
123 		nStatus = CNTHTTP_COOKIE_POLICY_ACCEPTED;
124 
125 	if ( maInFutureIgnoreBtn.IsChecked() )
126 		nStatus = CNTHTTP_COOKIE_POLICY_BANNED;
127 	List& rList = mpCookieRequest->m_rCookieList;
128 
129 	for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
130 	{
131 		sal_uInt16& rStatus = ( (CntHTTPCookie*)rList.GetObject(i) )->m_nPolicy;
132 
133 		if ( rStatus == CNTHTTP_COOKIE_POLICY_INTERACTIVE )
134 			rStatus = nStatus;
135 	}
136 
137 	if ( nRet == RET_OK )
138 		mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_ACCEPTED;
139 	else
140 		mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_BANNED;
141 
142 	return nRet;
143 }
144 
145