update dev300-m58
[ooovba.git] / connectivity / source / drivers / kab / KDEInit.cxx
blob813e79081a581ce0b3fbfa26a25a5d956425b355
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: KDEInit.cxx,v $
10 * $Revision: 1.7 $
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 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_connectivity.hxx"
33 #include "KDEInit.h"
34 #include <osl/diagnose.h>
35 #include <osl/process.h>
36 #include <vcl/kde_headers.h>
38 namespace connectivity
40 namespace kab
42 // ===============================================================
43 // = KDEInit
44 // ===============================================================
45 class KDEInit
47 private:
48 /// KDE application if we own it
49 static KApplication* s_pKApplication;
50 static bool s_bDidInsertCatalogue;
52 public:
53 static void Init();
54 static void Shutdown();
57 // ---------------------------------------------------------------
58 KApplication* KDEInit::s_pKApplication = NULL;
59 bool KDEInit::s_bDidInsertCatalogue = false;
61 // ---------------------------------------------------------------
62 void KDEInit::Init()
64 // TODO: All this is not thread-safe
66 // we create a KDE application only if it is not already done
67 if (KApplication::kApplication() == NULL)
69 OSL_ENSURE(s_pKApplication == NULL, "KDEInit::Init: inconsistency in the application pointers!");
71 char *kabargs[1] = {(char*)"libkab1"};
72 KCmdLineArgs::init(1, kabargs, "KAddressBook", *kabargs, "Address Book driver", KAB_DRIVER_VERSION);
74 s_pKApplication = new KApplication(false, false);
77 // set language
78 rtl_Locale *pProcessLocale;
79 osl_getProcessLocale(&pProcessLocale);
80 // sal_Unicode and QChar are (currently) both 16 bits characters
81 QString aLanguage(
82 (const QChar *) pProcessLocale->Language->buffer,
83 (int) pProcessLocale->Language->length);
84 KGlobal::locale()->setLanguage(aLanguage);
86 // load KDE address book's localized messages
87 KGlobal::locale()->insertCatalogue("kaddressbook");
88 s_bDidInsertCatalogue = true;
91 // ---------------------------------------------------------------
92 void KDEInit::Shutdown()
94 if ( s_bDidInsertCatalogue )
95 // this guard is necessary, since KDE 3.3 seems to crash if we remove a catalogue
96 // which we did not previously insert
97 KGlobal::locale()->removeCatalogue("kaddressbook");
99 if ( s_pKApplication != NULL )
101 delete s_pKApplication;
102 s_pKApplication = NULL;
108 // =======================================================================
109 namespace
111 double normalizeVersion( unsigned int major, unsigned int minor )
113 return major + 1.0 * minor / 1000;
117 // -----------------------------------------------------------------------
118 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL initKApplication()
120 ::connectivity::kab::KDEInit::Init();
123 // -----------------------------------------------------------------------
124 extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL shutdownKApplication()
126 ::connectivity::kab::KDEInit::Shutdown();
128 // -----------------------------------------------------------------------
129 /** checks whether the KDE version on the system we're running at is supported
130 by the driver
132 Has to be called before any other code from this library, in particular,
133 it has to be called before initKApplication()
135 If this function returns <code>0</code>, then no other code from this library
136 has to be called, else the results are unpredictable.
138 @return
139 <ul><li><code>0</code> if the KDE version is supportednon</li>
140 <li>a negative value if the version is too old</li>
141 <li>a positive value if the version is too new to know whether it works with this driver</li>
142 </ul>
144 #i60062# / 2006-01-06 / frank.schoenheit@sun.com
146 extern "C" SAL_DLLPUBLIC_EXPORT int SAL_CALL matchKDEVersion()
148 double nMinVersion = normalizeVersion( MIN_KDE_VERSION_MAJOR, MIN_KDE_VERSION_MINOR );
149 double nCurVersion = normalizeVersion( ::KDE::versionMajor(), ::KDE::versionMinor() );
150 double nMaxVersion = normalizeVersion( MAX_KDE_VERSION_MAJOR, MAX_KDE_VERSION_MINOR );
152 if ( nCurVersion < nMinVersion )
153 return -1;
154 if ( nCurVersion > nMaxVersion )
155 return 1;
157 return 0;