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