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 #include "precompiled_desktop.hxx" 23 24 #include "dp_gui_handleversionexception.hxx" 25 #include "dp_gui_dialog2.hxx" 26 #include "dp_version.hxx" 27 #include "dp_gui_shared.hxx" 28 #include "dp_gui.hrc" 29 #include <vcl/msgbox.hxx> 30 31 using namespace dp_gui; 32 using namespace dp_misc; 33 using ::rtl::OUString; 34 35 36 namespace { 37 38 OUString getVersion( OUString const & sVersion ) 39 { 40 return ( sVersion.getLength() == 0 ) ? OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) : sVersion; 41 } 42 43 OUString getVersion( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &rPackage ) 44 { 45 return getVersion( rPackage->getVersion()); 46 } 47 } 48 49 50 51 extern "C" { 52 53 54 bool handleVersionException( 55 com::sun::star::deployment::VersionException verExc, 56 DialogHelper* pDialogHelper ) 57 { 58 bool bApprove = false; 59 60 sal_uInt32 id; 61 switch (dp_misc::compareVersions( 62 verExc.NewVersion, verExc.Deployed->getVersion() )) 63 { 64 case dp_misc::LESS: 65 id = RID_WARNINGBOX_VERSION_LESS; 66 break; 67 case dp_misc::EQUAL: 68 id = RID_WARNINGBOX_VERSION_EQUAL; 69 break; 70 default: // dp_misc::GREATER 71 id = RID_WARNINGBOX_VERSION_GREATER; 72 break; 73 } 74 OSL_ASSERT( verExc.Deployed.is() ); 75 const bool bEqualNames = verExc.NewDisplayName.equals( 76 verExc.Deployed->getDisplayName()); 77 { 78 vos::OGuard guard(Application::GetSolarMutex()); 79 WarningBox box( pDialogHelper ? pDialogHelper->getWindow() : NULL, ResId(id, *DeploymentGuiResMgr::get())); 80 String s; 81 if (bEqualNames) 82 { 83 s = box.GetMessText(); 84 } 85 else if (id == RID_WARNINGBOX_VERSION_EQUAL) 86 { 87 //hypothetical: requires two instances of an extension with the same 88 //version to have different display names. Probably the developer forgot 89 //to change the version. 90 s = String(ResId(RID_STR_WARNINGBOX_VERSION_EQUAL_DIFFERENT_NAMES, *DeploymentGuiResMgr::get())); 91 } 92 else if (id == RID_WARNINGBOX_VERSION_LESS) 93 { 94 s = String(ResId(RID_STR_WARNINGBOX_VERSION_LESS_DIFFERENT_NAMES, *DeploymentGuiResMgr::get())); 95 } 96 else if (id == RID_WARNINGBOX_VERSION_GREATER) 97 { 98 s = String(ResId(RID_STR_WARNINGBOX_VERSION_GREATER_DIFFERENT_NAMES, *DeploymentGuiResMgr::get())); 99 } 100 s.SearchAndReplaceAllAscii( "$NAME", verExc.NewDisplayName); 101 s.SearchAndReplaceAllAscii( "$OLDNAME", verExc.Deployed->getDisplayName()); 102 s.SearchAndReplaceAllAscii( "$NEW", getVersion(verExc.NewVersion) ); 103 s.SearchAndReplaceAllAscii( "$DEPLOYED", getVersion(verExc.Deployed) ); 104 box.SetMessText(s); 105 bApprove = box.Execute() == RET_OK; 106 } 107 108 return bApprove; 109 } 110 111 } // end of extern "C" 112