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