1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: appfirststart.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 // MARKER(update_precomp.py): autogen include statement, do not remove
31 #include "precompiled_desktop.hxx"
33 #include <osl/file.hxx>
34 #include <rtl/bootstrap.hxx>
35 #include <rtl/ustring.hxx>
36 #include <tools/datetime.hxx>
37 #include <unotools/configmgr.hxx>
39 #include <comphelper/processfactory.hxx>
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/beans/NamedValue.hpp>
46 using namespace desktop
;
47 using namespace com::sun::star::beans
;
49 static const OUString
sConfigSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationProvider" ) );
50 static const OUString
sAccessSrvc( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.configuration.ConfigurationUpdateAccess" ) );
52 /* Path of the license. */
53 OUString
Desktop::GetLicensePath()
56 static const char *szLicensePath
= "/share/readme";
57 #if defined(WNT) || defined(OS2)
58 static const char *szWNTLicenseName
= "/license";
59 static const char *szWNTLicenseExt
= ".txt";
61 static const char *szUNXLicenseName
= "/LICENSE";
62 static const char *szUNXLicenseExt
= "";
64 static OUString aLicensePath
;
66 if (aLicensePath
.getLength() > 0)
69 OUString
aBaseInstallPath(RTL_CONSTASCII_USTRINGPARAM("$BRAND_BASE_DIR"));
70 rtl::Bootstrap::expandMacros(aBaseInstallPath
);
72 // determine the filename of the license to show
74 ::com::sun::star::lang::Locale aLocale
;
75 OString aMgrName
= OString("dkt");
77 AllSettings
aSettings(Application::GetSettings());
78 aLocale
= aSettings
.GetUILocale();
79 ResMgr
* pLocalResMgr
= ResMgr::SearchCreateResMgr(aMgrName
, aLocale
);
81 aLangString
= aLocale
.Language
;
82 if ( aLocale
.Country
.getLength() != 0 )
84 aLangString
+= OUString::createFromAscii("-");
85 aLangString
+= aLocale
.Country
;
86 if ( aLocale
.Variant
.getLength() != 0 )
88 aLangString
+= OUString::createFromAscii("-");
89 aLangString
+= aLocale
.Variant
;
92 #if defined(WNT) || defined(OS2)
94 aBaseInstallPath
+ OUString::createFromAscii(szLicensePath
)
95 + OUString::createFromAscii(szWNTLicenseName
)
96 + OUString::createFromAscii("_")
98 + OUString::createFromAscii(szWNTLicenseExt
);
101 aBaseInstallPath
+ OUString::createFromAscii(szLicensePath
)
102 + OUString::createFromAscii(szUNXLicenseName
)
103 + OUString::createFromAscii("_")
105 + OUString::createFromAscii(szUNXLicenseExt
);
111 /* Check if we need to accept license. */
112 sal_Bool
Desktop::LicenseNeedsAcceptance()
114 sal_Bool bShowLicense
= sal_True
;
115 sal_Int32 nOpenSourceContext
= 0;
118 ::utl::ConfigManager::GetDirectConfigProperty(
119 ::utl::ConfigManager::OPENSOURCECONTEXT
) >>= nOpenSourceContext
;
121 catch( const ::com::sun::star::uno::Exception
& ) {}
123 // open source needs no license
124 if ( nOpenSourceContext
> 0 )
125 bShowLicense
= sal_False
;
130 /* Local function - was the wizard completed already? */
131 static sal_Bool
impl_isFirstStart()
134 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
136 // get configuration provider
137 Reference
< XMultiServiceFactory
> theConfigProvider
= Reference
< XMultiServiceFactory
>(
138 xFactory
->createInstance(sConfigSrvc
), UNO_QUERY_THROW
);
140 Sequence
< Any
> theArgs(1);
141 NamedValue
v(OUString::createFromAscii("NodePath"), makeAny(OUString::createFromAscii("org.openoffice.Setup/Office")));
144 Reference
< XPropertySet
> pset
= Reference
< XPropertySet
>(
145 theConfigProvider
->createInstanceWithArguments(sAccessSrvc
, theArgs
), UNO_QUERY_THROW
);
147 Any result
= pset
->getPropertyValue(OUString::createFromAscii("FirstStartWizardCompleted"));
148 sal_Bool bCompleted
= sal_False
;
149 if ((result
>>= bCompleted
) && bCompleted
)
150 return sal_False
; // wizard was already completed
153 } catch (const Exception
&)
159 /* Local function - convert oslDateTime to tools DateTime */
160 static DateTime
impl_oslDateTimeToDateTime(const oslDateTime
& aDateTime
)
163 Date(aDateTime
.Day
, aDateTime
.Month
, aDateTime
.Year
),
164 Time(aDateTime
.Hours
, aDateTime
.Minutes
, aDateTime
.Seconds
));
167 /* Local function - get DateTime from a string */
168 static sal_Bool
impl_parseDateTime(const OUString
& aString
, DateTime
& aDateTime
)
170 // take apart a canonical literal xsd:dateTime string
171 //CCYY-MM-DDThh:mm:ss(Z)
173 OUString aDateTimeString
= aString
.trim();
176 if (aDateTimeString
.getLength() < 19 || aDateTimeString
.getLength() > 20)
179 sal_Int32 nDateLength
= 10;
180 sal_Int32 nTimeLength
= 8;
182 OUString aDateTimeSep
= OUString::createFromAscii("T");
183 OUString aDateSep
= OUString::createFromAscii("-");
184 OUString aTimeSep
= OUString::createFromAscii(":");
185 OUString aUTCString
= OUString::createFromAscii("Z");
187 OUString aDateString
= aDateTimeString
.copy(0, nDateLength
);
188 OUString aTimeString
= aDateTimeString
.copy(nDateLength
+1, nTimeLength
);
190 sal_Int32 nIndex
= 0;
191 sal_Int32 nYear
= aDateString
.getToken(0, '-', nIndex
).toInt32();
192 sal_Int32 nMonth
= aDateString
.getToken(0, '-', nIndex
).toInt32();
193 sal_Int32 nDay
= aDateString
.getToken(0, '-', nIndex
).toInt32();
195 sal_Int32 nHour
= aTimeString
.getToken(0, ':', nIndex
).toInt32();
196 sal_Int32 nMinute
= aTimeString
.getToken(0, ':', nIndex
).toInt32();
197 sal_Int32 nSecond
= aTimeString
.getToken(0, ':', nIndex
).toInt32();
199 Date
tmpDate((USHORT
)nDay
, (USHORT
)nMonth
, (USHORT
)nYear
);
200 Time
tmpTime(nHour
, nMinute
, nSecond
);
201 DateTime
tmpDateTime(tmpDate
, tmpTime
);
202 if (aString
.indexOf(aUTCString
) < 0)
203 tmpDateTime
.ConvertToUTC();
205 aDateTime
= tmpDateTime
;
209 /* Local function - was the license accepted already? */
210 static sal_Bool
impl_isLicenseAccepted()
212 // If no license will be shown ... it must not be accepted.
213 // So it was accepted "hardly" by the outside installer.
214 // But if the configuration entry "HideEula" will be removed afterwards ..
215 // we have to show the licese page again and user has to accept it here .-)
216 if ( ! Desktop::LicenseNeedsAcceptance() )
221 Reference
< XMultiServiceFactory
> xFactory
= ::comphelper::getProcessServiceFactory();
223 // get configuration provider
224 Reference
< XMultiServiceFactory
> theConfigProvider
= Reference
< XMultiServiceFactory
>(
225 xFactory
->createInstance(sConfigSrvc
), UNO_QUERY_THROW
);
227 Sequence
< Any
> theArgs(1);
228 NamedValue
v(OUString::createFromAscii("NodePath"),
229 makeAny(OUString::createFromAscii("org.openoffice.Setup/Office")));
231 Reference
< XPropertySet
> pset
= Reference
< XPropertySet
>(
232 theConfigProvider
->createInstanceWithArguments(sAccessSrvc
, theArgs
), UNO_QUERY_THROW
);
234 Any result
= pset
->getPropertyValue(OUString::createFromAscii("LicenseAcceptDate"));
236 OUString aAcceptDate
;
237 if (result
>>= aAcceptDate
)
239 // compare to date of license file
240 OUString aLicenseURL
= Desktop::GetLicensePath();
241 osl::DirectoryItem aDirItem
;
242 if (osl::DirectoryItem::get(aLicenseURL
, aDirItem
) != osl::FileBase::E_None
)
244 osl::FileStatus
aStatus(FileStatusMask_All
);
245 if (aDirItem
.getFileStatus(aStatus
) != osl::FileBase::E_None
)
247 TimeValue aTimeVal
= aStatus
.getModifyTime();
248 oslDateTime aDateTimeVal
;
249 if (!osl_getDateTimeFromTimeValue(&aTimeVal
, &aDateTimeVal
))
253 DateTime aLicenseDateTime
= impl_oslDateTimeToDateTime(aDateTimeVal
);
254 DateTime aAcceptDateTime
;
255 if (!impl_parseDateTime(aAcceptDate
, aAcceptDateTime
))
258 if ( aAcceptDateTime
> aLicenseDateTime
)
262 } catch (const Exception
&)
268 /* Check if we need the first start wizard. */
269 sal_Bool
Desktop::IsFirstStartWizardNeeded()
271 return impl_isFirstStart() || !impl_isLicenseAccepted();