xref: /trunk/main/vcl/unx/kde4/KDEXLib.cxx (revision cf8e6a53ed981a205d7700be9a04dd40a005f9f6)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 #include <vos/process.hxx>
23 
24 #include "VCLKDEApplication.hxx"
25 
26 #define Region QtXRegion
27 
28 #include <kapplication.h>
29 #include <klocale.h>
30 #include <kaboutdata.h>
31 #include <kcmdlineargs.h>
32 #include <kstartupinfo.h>
33 
34 #undef Region
35 
36 #include "KDEXLib.hxx"
37 
38 #include <unx/i18n_im.hxx>
39 #include <unx/i18n_xkb.hxx>
40 
41 #include <unx/saldata.hxx>
42 
43 #include "KDESalDisplay.hxx"
44 
45 #if OSL_DEBUG_LEVEL > 1
46 #include <stdio.h>
47 #endif
48 
49 KDEXLib::KDEXLib() :
50     SalXLib(),  m_bStartupDone(false), m_pApplication(0),
51     m_pFreeCmdLineArgs(0), m_pAppCmdLineArgs(0), m_nFakeCmdLineArgs( 0 )
52 {
53 }
54 
55 KDEXLib::~KDEXLib()
56 {
57     delete (VCLKDEApplication*)m_pApplication;
58 
59     // free the faked cmdline arguments no longer needed by KApplication
60     for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
61     {
62         free( m_pFreeCmdLineArgs[i] );
63     }
64 
65     delete [] m_pFreeCmdLineArgs;
66     delete [] m_pAppCmdLineArgs;
67 }
68 
69 void KDEXLib::Init()
70 {
71     SalI18N_InputMethod* pInputMethod = new SalI18N_InputMethod;
72     pInputMethod->SetLocale();
73     XrmInitialize();
74 
75     KAboutData *kAboutData = new KAboutData("OpenOffice",
76             "kdelibs4",
77             ki18n( "Apache OpenOffice" ),
78             "4.2.0",
79             ki18n( "Apache OpenOffice with KDE Native Widget Support." ),
80             KAboutData::License_File,
81             ki18n( "Joint Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Novell, Inc and Apache Software Foundation"),
82             ki18n( "Apache OpenOffice is an office suite.\n" ),
83             "http://openoffice.apache.org/",
84             "issues@openoffice.apache.org" );
85 
86     kAboutData->addAuthor( ki18n( "Jan Holesovsky" ),
87             ki18n( "Original author and maintainer of the KDE NWF." ),
88             "kendy@artax.karlin.mff.cuni.cz",
89             "http://artax.karlin.mff.cuni.cz/~kendy" );
90     kAboutData->addAuthor( ki18n("Roman Shtylman"),
91             ki18n( "Porting to KDE 4." ),
92             "shtylman@gmail.com", "http://shtylman.com" );
93     kAboutData->addAuthor( ki18n("Eric Bischoff"),
94             ki18n( "Accessibility fixes, porting to KDE 4." ),
95             "bischoff@kde.org" );
96 
97     //kAboutData->setProgramIconName("OpenOffice");
98 
99     m_nFakeCmdLineArgs = 1;
100     int nIdx;
101     vos::OExtCommandLine aCommandLine;
102     int nParams = aCommandLine.getCommandArgCount();
103     rtl::OString aDisplay;
104     rtl::OUString aParam, aBin;
105 
106     for ( nIdx = 0; nIdx < nParams; ++nIdx )
107     {
108         aCommandLine.getCommandArg( nIdx, aParam );
109         if ( !m_pFreeCmdLineArgs && aParam.equalsAscii( "-display" ) && nIdx + 1 < nParams )
110         {
111             aCommandLine.getCommandArg( nIdx + 1, aParam );
112             aDisplay = rtl::OUStringToOString( aParam, osl_getThreadTextEncoding() );
113 
114             m_nFakeCmdLineArgs = 3;
115             m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
116             m_pFreeCmdLineArgs[ 1 ] = strdup( "-display" );
117             m_pFreeCmdLineArgs[ 2 ] = strdup( aDisplay.getStr() );
118         }
119     }
120     if ( !m_pFreeCmdLineArgs )
121         m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
122 
123     osl_getExecutableFile( &aParam.pData );
124     osl_getSystemPathFromFileURL( aParam.pData, &aBin.pData );
125     rtl::OString aExec = rtl::OUStringToOString( aBin, osl_getThreadTextEncoding() );
126     m_pFreeCmdLineArgs[0] = strdup( aExec.getStr() );
127 
128     // make a copy of the string list for freeing it since
129     // KApplication manipulates the pointers inside the argument vector
130     // note: KApplication bad !
131     m_pAppCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
132     for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
133         m_pAppCmdLineArgs[i] = m_pFreeCmdLineArgs[i];
134 
135     KCmdLineArgs::init( m_nFakeCmdLineArgs, m_pAppCmdLineArgs, kAboutData );
136 
137     m_pApplication = new VCLKDEApplication();
138     kapp->disableSessionManagement();
139     KApplication::setQuitOnLastWindowClosed(false);
140 
141     Display* pDisp = QX11Info::display();
142     SalKDEDisplay *pSalDisplay = new SalKDEDisplay(pDisp);
143 
144     ((VCLKDEApplication*)m_pApplication)->disp = pSalDisplay;
145 
146     pInputMethod->CreateMethod( pDisp );
147     pInputMethod->AddConnectionWatch( pDisp, (void*)this );
148     pSalDisplay->SetInputMethod( pInputMethod );
149 
150     PushXErrorLevel( true );
151     SalI18N_KeyboardExtension *pKbdExtension = new SalI18N_KeyboardExtension( pDisp );
152     XSync( pDisp, False );
153 
154     pKbdExtension->UseExtension( ! HasXErrorOccured() );
155     PopXErrorLevel();
156 
157     pSalDisplay->SetKbdExtension( pKbdExtension );
158 }
159 
160 void KDEXLib::doStartup()
161 {
162     if( ! m_bStartupDone )
163     {
164         KStartupInfo::appStarted();
165         m_bStartupDone = true;
166         #if OSL_DEBUG_LEVEL > 1
167         fprintf( stderr, "called KStartupInfo::appStarted()\n" );
168         #endif
169     }
170 }
171 
172 /* vim: set noet sw=4 ts=4: */
173