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 
getVersion(OUString const & sVersion)38 OUString getVersion( OUString const & sVersion )
39 {
40     return ( sVersion.getLength() == 0 ) ? OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) : sVersion;
41 }
42 
getVersion(const::com::sun::star::uno::Reference<::com::sun::star::deployment::XPackage> & rPackage)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 
handleVersionException(com::sun::star::deployment::VersionException verExc,DialogHelper * pDialogHelper,const bool bChooseNewestVersion)54 bool handleVersionException(
55     com::sun::star::deployment::VersionException verExc,
56     DialogHelper* pDialogHelper,
57     const bool bChooseNewestVersion )
58 {
59     bool bApprove = false;
60 
61     sal_uInt32 id;
62     switch (dp_misc::compareVersions(
63         verExc.NewVersion, verExc.Deployed->getVersion() ))
64     {
65     case dp_misc::LESS:
66         id = RID_WARNINGBOX_VERSION_LESS;
67         break;
68     case dp_misc::EQUAL:
69         id = RID_WARNINGBOX_VERSION_EQUAL;
70         break;
71     default: // dp_misc::GREATER
72         id = RID_WARNINGBOX_VERSION_GREATER;
73         break;
74     }
75     OSL_ASSERT( verExc.Deployed.is() );
76 
77     if ( bChooseNewestVersion )
78     {
79         bApprove = id == RID_WARNINGBOX_VERSION_GREATER;
80     }
81     else
82     {
83         const bool bEqualNames = verExc.NewDisplayName.equals(
84             verExc.Deployed->getDisplayName());
85         {
86             vos::OGuard guard(Application::GetSolarMutex());
87             WarningBox box( pDialogHelper ? pDialogHelper->getWindow() : NULL, ResId(id, *DeploymentGuiResMgr::get()));
88             String s;
89             if (bEqualNames)
90             {
91                 s = box.GetMessText();
92             }
93             else if (id == RID_WARNINGBOX_VERSION_EQUAL)
94             {
95                 //hypothetical: requires two instances of an extension with the same
96                 //version to have different display names. Probably the developer forgot
97                 //to change the version.
98                 s = String(ResId(RID_STR_WARNINGBOX_VERSION_EQUAL_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
99             }
100             else if (id == RID_WARNINGBOX_VERSION_LESS)
101             {
102                 s = String(ResId(RID_STR_WARNINGBOX_VERSION_LESS_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
103             }
104             else if (id == RID_WARNINGBOX_VERSION_GREATER)
105             {
106                 s = String(ResId(RID_STR_WARNINGBOX_VERSION_GREATER_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
107             }
108             s.SearchAndReplaceAllAscii( "$NAME", verExc.NewDisplayName);
109             s.SearchAndReplaceAllAscii( "$OLDNAME", verExc.Deployed->getDisplayName());
110             s.SearchAndReplaceAllAscii( "$NEW", getVersion(verExc.NewVersion) );
111             s.SearchAndReplaceAllAscii( "$DEPLOYED", getVersion(verExc.Deployed) );
112             box.SetMessText(s);
113             bApprove = box.Execute() == RET_OK;
114         }
115     }
116 
117     return bApprove;
118 }
119 
120 } // end of extern "C"
121