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 #include <vcl/threadex.hxx> 31 #include <boost/bind.hpp> 32 33 using namespace dp_gui; 34 using namespace dp_misc; 35 using ::rtl::OUString; 36 37 38 namespace { 39 40 OUString getVersion( OUString const & sVersion ) 41 { 42 return ( sVersion.getLength() == 0 ) ? OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) : sVersion; 43 } 44 45 OUString getVersion( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &rPackage ) 46 { 47 return getVersion( rPackage->getVersion()); 48 } 49 50 bool solar_showVersionWarning( 51 DialogHelper * pDialogHelper, sal_uInt32 id, bool bEqualNames, 52 OUString const & rNewDisplayName, OUString const & rOldDisplayName, 53 OUString const & rNewVersion, OUString const & rDeployedVersion ) 54 { 55 vos::OGuard guard(Application::GetSolarMutex()); 56 WarningBox box( pDialogHelper ? pDialogHelper->getWindow() : NULL, ResId(id, *DeploymentGuiResMgr::get())); 57 String s; 58 if (bEqualNames) 59 { 60 s = box.GetMessText(); 61 } 62 else if (id == RID_WARNINGBOX_VERSION_EQUAL) 63 { 64 //hypothetical: requires two instances of an extension with the same 65 //version to have different display names. Probably the developer forgot 66 //to change the version. 67 s = String(ResId(RID_STR_WARNINGBOX_VERSION_EQUAL_DIFFERENT_NAMES, *DeploymentGuiResMgr::get())); 68 } 69 else if (id == RID_WARNINGBOX_VERSION_LESS) 70 { 71 s = String(ResId(RID_STR_WARNINGBOX_VERSION_LESS_DIFFERENT_NAMES, *DeploymentGuiResMgr::get())); 72 } 73 else if (id == RID_WARNINGBOX_VERSION_GREATER) 74 { 75 s = String(ResId(RID_STR_WARNINGBOX_VERSION_GREATER_DIFFERENT_NAMES, *DeploymentGuiResMgr::get())); 76 } 77 s.SearchAndReplaceAllAscii( "$NAME", rNewDisplayName); 78 s.SearchAndReplaceAllAscii( "$OLDNAME", rOldDisplayName); 79 s.SearchAndReplaceAllAscii( "$NEW", rNewVersion ); 80 s.SearchAndReplaceAllAscii( "$DEPLOYED", rDeployedVersion ); 81 box.SetMessText(s); 82 return box.Execute() == RET_OK; 83 } 84 } 85 86 87 88 extern "C" { 89 90 91 bool handleVersionException( 92 com::sun::star::deployment::VersionException verExc, 93 DialogHelper* pDialogHelper, 94 const bool bChooseNewestVersion ) 95 { 96 bool bApprove = false; 97 98 sal_uInt32 id; 99 switch (dp_misc::compareVersions( 100 verExc.NewVersion, verExc.Deployed->getVersion() )) 101 { 102 case dp_misc::LESS: 103 id = RID_WARNINGBOX_VERSION_LESS; 104 break; 105 case dp_misc::EQUAL: 106 id = RID_WARNINGBOX_VERSION_EQUAL; 107 break; 108 default: // dp_misc::GREATER 109 id = RID_WARNINGBOX_VERSION_GREATER; 110 break; 111 } 112 OSL_ASSERT( verExc.Deployed.is() ); 113 114 if ( bChooseNewestVersion ) 115 { 116 bApprove = id == RID_WARNINGBOX_VERSION_GREATER; 117 } 118 else 119 { 120 const bool bEqualNames = verExc.NewDisplayName.equals( 121 verExc.Deployed->getDisplayName()); 122 // Reached from the deployment worker thread, where AquaSalInstance::Yield 123 // cannot pump the Cocoa event queue; the dialog must execute on the main 124 // thread or it appears but never receives events. 125 bApprove = vcl::solarthread::syncExecute( 126 boost::bind( &solar_showVersionWarning, pDialogHelper, id, bEqualNames, 127 verExc.NewDisplayName, verExc.Deployed->getDisplayName(), 128 getVersion(verExc.NewVersion), getVersion(verExc.Deployed) ) ); 129 } 130 131 return bApprove; 132 } 133 134 } // end of extern "C" 135