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