1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski // MARKER(update_precomp.py): autogen include statement, do not remove
25*b1cdbd2cSJim Jagielski #include "precompiled_connectivity.hxx"
26*b1cdbd2cSJim Jagielski #include "KDEInit.h"
27*b1cdbd2cSJim Jagielski #include <osl/diagnose.h>
28*b1cdbd2cSJim Jagielski #include <osl/process.h>
29*b1cdbd2cSJim Jagielski #include <shell/kde_headers.h>
30*b1cdbd2cSJim Jagielski
31*b1cdbd2cSJim Jagielski namespace connectivity
32*b1cdbd2cSJim Jagielski {
33*b1cdbd2cSJim Jagielski namespace kab
34*b1cdbd2cSJim Jagielski {
35*b1cdbd2cSJim Jagielski // ===============================================================
36*b1cdbd2cSJim Jagielski // = KDEInit
37*b1cdbd2cSJim Jagielski // ===============================================================
38*b1cdbd2cSJim Jagielski class KDEInit
39*b1cdbd2cSJim Jagielski {
40*b1cdbd2cSJim Jagielski private:
41*b1cdbd2cSJim Jagielski /// KDE application if we own it
42*b1cdbd2cSJim Jagielski static KApplication* s_pKApplication;
43*b1cdbd2cSJim Jagielski static bool s_bDidInsertCatalogue;
44*b1cdbd2cSJim Jagielski
45*b1cdbd2cSJim Jagielski public:
46*b1cdbd2cSJim Jagielski static void Init();
47*b1cdbd2cSJim Jagielski static void Shutdown();
48*b1cdbd2cSJim Jagielski };
49*b1cdbd2cSJim Jagielski
50*b1cdbd2cSJim Jagielski // ---------------------------------------------------------------
51*b1cdbd2cSJim Jagielski KApplication* KDEInit::s_pKApplication = NULL;
52*b1cdbd2cSJim Jagielski bool KDEInit::s_bDidInsertCatalogue = false;
53*b1cdbd2cSJim Jagielski
54*b1cdbd2cSJim Jagielski // ---------------------------------------------------------------
Init()55*b1cdbd2cSJim Jagielski void KDEInit::Init()
56*b1cdbd2cSJim Jagielski {
57*b1cdbd2cSJim Jagielski // TODO: All this is not thread-safe
58*b1cdbd2cSJim Jagielski
59*b1cdbd2cSJim Jagielski // we create a KDE application only if it is not already done
60*b1cdbd2cSJim Jagielski if (KApplication::kApplication() == NULL)
61*b1cdbd2cSJim Jagielski {
62*b1cdbd2cSJim Jagielski OSL_ENSURE(s_pKApplication == NULL, "KDEInit::Init: inconsistency in the application pointers!");
63*b1cdbd2cSJim Jagielski
64*b1cdbd2cSJim Jagielski char *kabargs[1] = {(char*)"libkab1"};
65*b1cdbd2cSJim Jagielski KCmdLineArgs::init(1, kabargs, "KAddressBook", *kabargs, "Address Book driver", KAB_DRIVER_VERSION);
66*b1cdbd2cSJim Jagielski
67*b1cdbd2cSJim Jagielski s_pKApplication = new KApplication(false, false);
68*b1cdbd2cSJim Jagielski }
69*b1cdbd2cSJim Jagielski
70*b1cdbd2cSJim Jagielski // set language
71*b1cdbd2cSJim Jagielski rtl_Locale *pProcessLocale;
72*b1cdbd2cSJim Jagielski osl_getProcessLocale(&pProcessLocale);
73*b1cdbd2cSJim Jagielski // sal_Unicode and QChar are (currently) both 16 bits characters
74*b1cdbd2cSJim Jagielski QString aLanguage(
75*b1cdbd2cSJim Jagielski (const QChar *) pProcessLocale->Language->buffer,
76*b1cdbd2cSJim Jagielski (int) pProcessLocale->Language->length);
77*b1cdbd2cSJim Jagielski KGlobal::locale()->setLanguage(aLanguage);
78*b1cdbd2cSJim Jagielski
79*b1cdbd2cSJim Jagielski // load KDE address book's localized messages
80*b1cdbd2cSJim Jagielski KGlobal::locale()->insertCatalogue("kaddressbook");
81*b1cdbd2cSJim Jagielski s_bDidInsertCatalogue = true;
82*b1cdbd2cSJim Jagielski }
83*b1cdbd2cSJim Jagielski
84*b1cdbd2cSJim Jagielski // ---------------------------------------------------------------
Shutdown()85*b1cdbd2cSJim Jagielski void KDEInit::Shutdown()
86*b1cdbd2cSJim Jagielski {
87*b1cdbd2cSJim Jagielski if ( s_bDidInsertCatalogue )
88*b1cdbd2cSJim Jagielski // this guard is necessary, since KDE 3.3 seems to crash if we remove a catalogue
89*b1cdbd2cSJim Jagielski // which we did not previously insert
90*b1cdbd2cSJim Jagielski KGlobal::locale()->removeCatalogue("kaddressbook");
91*b1cdbd2cSJim Jagielski
92*b1cdbd2cSJim Jagielski if ( s_pKApplication != NULL )
93*b1cdbd2cSJim Jagielski {
94*b1cdbd2cSJim Jagielski delete s_pKApplication;
95*b1cdbd2cSJim Jagielski s_pKApplication = NULL;
96*b1cdbd2cSJim Jagielski }
97*b1cdbd2cSJim Jagielski }
98*b1cdbd2cSJim Jagielski }
99*b1cdbd2cSJim Jagielski }
100*b1cdbd2cSJim Jagielski
101*b1cdbd2cSJim Jagielski // =======================================================================
102*b1cdbd2cSJim Jagielski namespace
103*b1cdbd2cSJim Jagielski {
normalizeVersion(unsigned int major,unsigned int minor)104*b1cdbd2cSJim Jagielski double normalizeVersion( unsigned int major, unsigned int minor )
105*b1cdbd2cSJim Jagielski {
106*b1cdbd2cSJim Jagielski return major + 1.0 * minor / 1000;
107*b1cdbd2cSJim Jagielski }
108*b1cdbd2cSJim Jagielski }
109*b1cdbd2cSJim Jagielski
110*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------
initKApplication()111*b1cdbd2cSJim Jagielski extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL initKApplication()
112*b1cdbd2cSJim Jagielski {
113*b1cdbd2cSJim Jagielski ::connectivity::kab::KDEInit::Init();
114*b1cdbd2cSJim Jagielski }
115*b1cdbd2cSJim Jagielski
116*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------
shutdownKApplication()117*b1cdbd2cSJim Jagielski extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL shutdownKApplication()
118*b1cdbd2cSJim Jagielski {
119*b1cdbd2cSJim Jagielski ::connectivity::kab::KDEInit::Shutdown();
120*b1cdbd2cSJim Jagielski }
121*b1cdbd2cSJim Jagielski // -----------------------------------------------------------------------
122*b1cdbd2cSJim Jagielski /** checks whether the KDE version on the system we're running at is supported
123*b1cdbd2cSJim Jagielski by the driver
124*b1cdbd2cSJim Jagielski
125*b1cdbd2cSJim Jagielski Has to be called before any other code from this library, in particular,
126*b1cdbd2cSJim Jagielski it has to be called before initKApplication()
127*b1cdbd2cSJim Jagielski
128*b1cdbd2cSJim Jagielski If this function returns <code>0</code>, then no other code from this library
129*b1cdbd2cSJim Jagielski has to be called, else the results are unpredictable.
130*b1cdbd2cSJim Jagielski
131*b1cdbd2cSJim Jagielski @return
132*b1cdbd2cSJim Jagielski <ul><li><code>0</code> if the KDE version is supportednon</li>
133*b1cdbd2cSJim Jagielski <li>a negative value if the version is too old</li>
134*b1cdbd2cSJim Jagielski <li>a positive value if the version is too new to know whether it works with this driver</li>
135*b1cdbd2cSJim Jagielski </ul>
136*b1cdbd2cSJim Jagielski
137*b1cdbd2cSJim Jagielski #i60062# / 2006-01-06 / frank.schoenheit@sun.com
138*b1cdbd2cSJim Jagielski */
matchKDEVersion()139*b1cdbd2cSJim Jagielski extern "C" SAL_DLLPUBLIC_EXPORT int SAL_CALL matchKDEVersion()
140*b1cdbd2cSJim Jagielski {
141*b1cdbd2cSJim Jagielski double nMinVersion = normalizeVersion( MIN_KDE_VERSION_MAJOR, MIN_KDE_VERSION_MINOR );
142*b1cdbd2cSJim Jagielski double nCurVersion = normalizeVersion( ::KDE::versionMajor(), ::KDE::versionMinor() );
143*b1cdbd2cSJim Jagielski double nMaxVersion = normalizeVersion( MAX_KDE_VERSION_MAJOR, MAX_KDE_VERSION_MINOR );
144*b1cdbd2cSJim Jagielski
145*b1cdbd2cSJim Jagielski if ( nCurVersion < nMinVersion )
146*b1cdbd2cSJim Jagielski return -1;
147*b1cdbd2cSJim Jagielski if ( nCurVersion > nMaxVersion )
148*b1cdbd2cSJim Jagielski return 1;
149*b1cdbd2cSJim Jagielski
150*b1cdbd2cSJim Jagielski return 0;
151*b1cdbd2cSJim Jagielski }
152