1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: cookiedg.cxx,v $
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>
38 #include <cookiedg.hxx>
43 // CookiesDialog ---------------------------------------------------------
45 IMPL_LINK( CookiesDialog
, ButtonHdl_Impl
, PushButton
*, pBtn
)
47 short nRet
= ( &maSendBtn
== pBtn
) ? RET_OK
: RET_CANCEL
;
52 // -----------------------------------------------------------------------
53 CookiesDialog::CookiesDialog( Window
* pParent
,
54 CntHTTPCookieRequest
* pRequest
,
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
)
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
);
82 6 + ( 145 - aLogicSize
.Height() ) / 2 );
83 maCookieFB
.SetPosSizePixel( LogicToPixel( aPoint
), aSize
);
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
)
104 aCookie
.SearchAndReplaceAscii( "${DOMAIN}", pCookie
->m_aDomain
);
105 aCookie
.SearchAndReplaceAscii( "${PATH}", pCookie
->m_aPath
);
106 aPair
= pCookie
->m_aName
;
108 aPair
+= pCookie
->m_aValue
;
109 aCookie
.SearchAndReplaceAscii( "${COOKIE}", aPair
);
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
)
140 if ( nRet
== RET_OK
)
141 mpCookieRequest
->m_nRet
= CNTHTTP_COOKIE_POLICY_ACCEPTED
;
143 mpCookieRequest
->m_nRet
= CNTHTTP_COOKIE_POLICY_BANNED
;