merged tag ooo/DEV300_m102
[LibreOffice.git] / uui / source / cookiedg.cxx
blobc75d32699a736236c5ad31ecfc72154d491b8f96
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 #include <svl/httpcook.hxx>
29 #include <tools/urlobj.hxx>
30 #include <vcl/msgbox.hxx>
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
40 // CookiesDialog ---------------------------------------------------------
42 IMPL_LINK( CookiesDialog, ButtonHdl_Impl, PushButton *, pBtn )
44 short nRet = ( &maSendBtn == pBtn ) ? RET_OK : RET_CANCEL;
45 EndDialog( nRet );
46 return 1;
49 // -----------------------------------------------------------------------
50 CookiesDialog::CookiesDialog( Window* pParent,
51 CntHTTPCookieRequest* pRequest,
52 ResMgr* pResMgr ) :
54 ModalDialog( pParent, ResId( DLG_COOKIES, *pResMgr ) ),
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 ) ),
66 mpCookieRequest ( pRequest )
69 FreeResource();
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();
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;
94 for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
96 CntHTTPCookie* pCookie = (CntHTTPCookie*)rList.GetObject(i);
98 if ( CNTHTTP_COOKIE_POLICY_INTERACTIVE == pCookie->m_nPolicy )
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;
110 maInFutureInteractiveBtn.Check( sal_True );
111 maCookieFT.SetText( aMsg );
114 // -----------------------------------------------------------------------
116 short CookiesDialog::Execute()
118 maSendBtn.GrabFocus();
119 short nRet = ModalDialog::Execute();
120 sal_uInt16 nStatus = CNTHTTP_COOKIE_POLICY_INTERACTIVE;
122 if ( maInFutureSendBtn.IsChecked() )
123 nStatus = CNTHTTP_COOKIE_POLICY_ACCEPTED;
125 if ( maInFutureIgnoreBtn.IsChecked() )
126 nStatus = CNTHTTP_COOKIE_POLICY_BANNED;
127 List& rList = mpCookieRequest->m_rCookieList;
129 for ( sal_uInt16 i = (sal_uInt16)rList.Count(); i--; )
131 sal_uInt16& rStatus = ( (CntHTTPCookie*)rList.GetObject(i) )->m_nPolicy;
133 if ( rStatus == CNTHTTP_COOKIE_POLICY_INTERACTIVE )
134 rStatus = nStatus;
137 if ( nRet == RET_OK )
138 mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_ACCEPTED;
139 else
140 mpCookieRequest->m_nRet = CNTHTTP_COOKIE_POLICY_BANNED;
142 return nRet;