1*fd6d8138SAndre Fischer /**************************************************************
2*fd6d8138SAndre Fischer  *
3*fd6d8138SAndre Fischer  * Licensed to the Apache Software Foundation (ASF) under one
4*fd6d8138SAndre Fischer  * or more contributor license agreements.  See the NOTICE file
5*fd6d8138SAndre Fischer  * distributed with this work for additional information
6*fd6d8138SAndre Fischer  * regarding copyright ownership.  The ASF licenses this file
7*fd6d8138SAndre Fischer  * to you under the Apache License, Version 2.0 (the
8*fd6d8138SAndre Fischer  * "License"); you may not use this file except in compliance
9*fd6d8138SAndre Fischer  * with the License.  You may obtain a copy of the License at
10*fd6d8138SAndre Fischer  *
11*fd6d8138SAndre Fischer  *   http://www.apache.org/licenses/LICENSE-2.0
12*fd6d8138SAndre Fischer  *
13*fd6d8138SAndre Fischer  * Unless required by applicable law or agreed to in writing,
14*fd6d8138SAndre Fischer  * software distributed under the License is distributed on an
15*fd6d8138SAndre Fischer  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*fd6d8138SAndre Fischer  * KIND, either express or implied.  See the License for the
17*fd6d8138SAndre Fischer  * specific language governing permissions and limitations
18*fd6d8138SAndre Fischer  * under the License.
19*fd6d8138SAndre Fischer  *
20*fd6d8138SAndre Fischer  *************************************************************/
21*fd6d8138SAndre Fischer 
22*fd6d8138SAndre Fischer #include "precompiled_desktop.hxx"
23*fd6d8138SAndre Fischer 
24*fd6d8138SAndre Fischer #include "dp_gui_handleversionexception.hxx"
25*fd6d8138SAndre Fischer #include "dp_gui_dialog2.hxx"
26*fd6d8138SAndre Fischer #include "dp_version.hxx"
27*fd6d8138SAndre Fischer #include "dp_gui_shared.hxx"
28*fd6d8138SAndre Fischer #include "dp_gui.hrc"
29*fd6d8138SAndre Fischer #include <vcl/msgbox.hxx>
30*fd6d8138SAndre Fischer 
31*fd6d8138SAndre Fischer using namespace dp_gui;
32*fd6d8138SAndre Fischer using namespace dp_misc;
33*fd6d8138SAndre Fischer using ::rtl::OUString;
34*fd6d8138SAndre Fischer 
35*fd6d8138SAndre Fischer 
36*fd6d8138SAndre Fischer namespace {
37*fd6d8138SAndre Fischer 
38*fd6d8138SAndre Fischer OUString getVersion( OUString const & sVersion )
39*fd6d8138SAndre Fischer {
40*fd6d8138SAndre Fischer     return ( sVersion.getLength() == 0 ) ? OUString( RTL_CONSTASCII_USTRINGPARAM( "0" ) ) : sVersion;
41*fd6d8138SAndre Fischer }
42*fd6d8138SAndre Fischer 
43*fd6d8138SAndre Fischer OUString getVersion( const ::com::sun::star::uno::Reference< ::com::sun::star::deployment::XPackage > &rPackage )
44*fd6d8138SAndre Fischer {
45*fd6d8138SAndre Fischer     return getVersion( rPackage->getVersion());
46*fd6d8138SAndre Fischer }
47*fd6d8138SAndre Fischer }
48*fd6d8138SAndre Fischer 
49*fd6d8138SAndre Fischer 
50*fd6d8138SAndre Fischer 
51*fd6d8138SAndre Fischer extern "C" {
52*fd6d8138SAndre Fischer 
53*fd6d8138SAndre Fischer 
54*fd6d8138SAndre Fischer bool handleVersionException(
55*fd6d8138SAndre Fischer     com::sun::star::deployment::VersionException verExc,
56*fd6d8138SAndre Fischer     DialogHelper* pDialogHelper )
57*fd6d8138SAndre Fischer {
58*fd6d8138SAndre Fischer     bool bApprove = false;
59*fd6d8138SAndre Fischer 
60*fd6d8138SAndre Fischer     sal_uInt32 id;
61*fd6d8138SAndre Fischer     switch (dp_misc::compareVersions(
62*fd6d8138SAndre Fischer         verExc.NewVersion, verExc.Deployed->getVersion() ))
63*fd6d8138SAndre Fischer     {
64*fd6d8138SAndre Fischer     case dp_misc::LESS:
65*fd6d8138SAndre Fischer         id = RID_WARNINGBOX_VERSION_LESS;
66*fd6d8138SAndre Fischer         break;
67*fd6d8138SAndre Fischer     case dp_misc::EQUAL:
68*fd6d8138SAndre Fischer         id = RID_WARNINGBOX_VERSION_EQUAL;
69*fd6d8138SAndre Fischer         break;
70*fd6d8138SAndre Fischer     default: // dp_misc::GREATER
71*fd6d8138SAndre Fischer         id = RID_WARNINGBOX_VERSION_GREATER;
72*fd6d8138SAndre Fischer         break;
73*fd6d8138SAndre Fischer     }
74*fd6d8138SAndre Fischer     OSL_ASSERT( verExc.Deployed.is() );
75*fd6d8138SAndre Fischer     const bool bEqualNames = verExc.NewDisplayName.equals(
76*fd6d8138SAndre Fischer         verExc.Deployed->getDisplayName());
77*fd6d8138SAndre Fischer     {
78*fd6d8138SAndre Fischer         vos::OGuard guard(Application::GetSolarMutex());
79*fd6d8138SAndre Fischer         WarningBox box( pDialogHelper ? pDialogHelper->getWindow() : NULL, ResId(id, *DeploymentGuiResMgr::get()));
80*fd6d8138SAndre Fischer         String s;
81*fd6d8138SAndre Fischer         if (bEqualNames)
82*fd6d8138SAndre Fischer         {
83*fd6d8138SAndre Fischer             s = box.GetMessText();
84*fd6d8138SAndre Fischer         }
85*fd6d8138SAndre Fischer         else if (id == RID_WARNINGBOX_VERSION_EQUAL)
86*fd6d8138SAndre Fischer         {
87*fd6d8138SAndre Fischer             //hypothetical: requires two instances of an extension with the same
88*fd6d8138SAndre Fischer             //version to have different display names. Probably the developer forgot
89*fd6d8138SAndre Fischer             //to change the version.
90*fd6d8138SAndre Fischer             s = String(ResId(RID_STR_WARNINGBOX_VERSION_EQUAL_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
91*fd6d8138SAndre Fischer         }
92*fd6d8138SAndre Fischer         else if (id == RID_WARNINGBOX_VERSION_LESS)
93*fd6d8138SAndre Fischer         {
94*fd6d8138SAndre Fischer             s = String(ResId(RID_STR_WARNINGBOX_VERSION_LESS_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
95*fd6d8138SAndre Fischer         }
96*fd6d8138SAndre Fischer         else if (id == RID_WARNINGBOX_VERSION_GREATER)
97*fd6d8138SAndre Fischer         {
98*fd6d8138SAndre Fischer             s = String(ResId(RID_STR_WARNINGBOX_VERSION_GREATER_DIFFERENT_NAMES, *DeploymentGuiResMgr::get()));
99*fd6d8138SAndre Fischer         }
100*fd6d8138SAndre Fischer         s.SearchAndReplaceAllAscii( "$NAME", verExc.NewDisplayName);
101*fd6d8138SAndre Fischer         s.SearchAndReplaceAllAscii( "$OLDNAME", verExc.Deployed->getDisplayName());
102*fd6d8138SAndre Fischer         s.SearchAndReplaceAllAscii( "$NEW", getVersion(verExc.NewVersion) );
103*fd6d8138SAndre Fischer         s.SearchAndReplaceAllAscii( "$DEPLOYED", getVersion(verExc.Deployed) );
104*fd6d8138SAndre Fischer         box.SetMessText(s);
105*fd6d8138SAndre Fischer         bApprove = box.Execute() == RET_OK;
106*fd6d8138SAndre Fischer     }
107*fd6d8138SAndre Fischer 
108*fd6d8138SAndre Fischer     return bApprove;
109*fd6d8138SAndre Fischer }
110*fd6d8138SAndre Fischer 
111*fd6d8138SAndre Fischer } // end of extern "C"
112