xref: /AOO41X/main/vcl/unx/kde4/KDEXLib.cxx (revision bf121af8c1f7c0dd9de1f4f4a4718a7d889f0e41)
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 
23 
24 #include <vos/process.hxx>
25 
26 #include "VCLKDEApplication.hxx"
27 
28 #define Region QtXRegion
29 
30 #include <kapplication.h>
31 #include <klocale.h>
32 #include <kaboutdata.h>
33 #include <kcmdlineargs.h>
34 #include <kstartupinfo.h>
35 
36 #undef Region
37 
38 #include "KDEXLib.hxx"
39 
40 #include <unx/i18n_im.hxx>
41 #include <unx/i18n_xkb.hxx>
42 
43 #include <unx/saldata.hxx>
44 
45 #include "KDESalDisplay.hxx"
46 
47 #if OSL_DEBUG_LEVEL > 1
48 #include <stdio.h>
49 #endif
50 
KDEXLib()51 KDEXLib::KDEXLib() :
52     SalXLib(),  m_bStartupDone(false), m_pApplication(0),
53     m_pFreeCmdLineArgs(0), m_pAppCmdLineArgs(0), m_nFakeCmdLineArgs( 0 )
54 {
55 }
56 
~KDEXLib()57 KDEXLib::~KDEXLib()
58 {
59     delete (VCLKDEApplication*)m_pApplication;
60 
61     // free the faked cmdline arguments no longer needed by KApplication
62     for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
63     {
64         free( m_pFreeCmdLineArgs[i] );
65     }
66 
67     delete [] m_pFreeCmdLineArgs;
68     delete [] m_pAppCmdLineArgs;
69 }
70 
Init()71 void KDEXLib::Init()
72 {
73     SalI18N_InputMethod* pInputMethod = new SalI18N_InputMethod;
74     pInputMethod->SetLocale();
75     XrmInitialize();
76 
77     KAboutData *kAboutData = new KAboutData("Apache OpenOffice",
78             "kdelibs4",
79             ki18n( "Apache OpenOffice" ),
80             "3.4.0",
81             ki18n( "Apache OpenOffice with KDE Native Widget Support." ),
82             KAboutData::License_File,
83             ki18n( "Joint Copyright (c) 2003, 2004, 2005, 2006, 2007, 2008, 2009 Novell, Inc and Apache Software Foundation"),
84             ki18n( "Apache OpenOffice is an office suite.\n" ),
85             "http://openoffice.apache.org/",
86             "ooo-issues@incubator.apache.org" );
87 
88     kAboutData->addAuthor( ki18n( "Jan Holesovsky" ),
89             ki18n( "Original author and maintainer of the KDE NWF." ),
90             "kendy@artax.karlin.mff.cuni.cz",
91             "http://artax.karlin.mff.cuni.cz/~kendy" );
92     kAboutData->addAuthor( ki18n("Roman Shtylman"),
93             ki18n( "Porting to KDE 4." ),
94             "shtylman@gmail.com", "http://shtylman.com" );
95     kAboutData->addAuthor( ki18n("Eric Bischoff"),
96             ki18n( "Accessibility fixes, porting to KDE 4." ),
97             "bischoff@kde.org" );
98 
99     //kAboutData->setProgramIconName("OpenOffice");
100 
101     m_nFakeCmdLineArgs = 1;
102     int nIdx;
103     vos::OExtCommandLine aCommandLine;
104     int nParams = aCommandLine.getCommandArgCount();
105     rtl::OString aDisplay;
106     rtl::OUString aParam, aBin;
107 
108     for ( nIdx = 0; nIdx < nParams; ++nIdx )
109     {
110         aCommandLine.getCommandArg( nIdx, aParam );
111         if ( !m_pFreeCmdLineArgs && aParam.equalsAscii( "-display" ) && nIdx + 1 < nParams )
112         {
113             aCommandLine.getCommandArg( nIdx + 1, aParam );
114             aDisplay = rtl::OUStringToOString( aParam, osl_getThreadTextEncoding() );
115 
116             m_nFakeCmdLineArgs = 3;
117             m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
118             m_pFreeCmdLineArgs[ 1 ] = strdup( "-display" );
119             m_pFreeCmdLineArgs[ 2 ] = strdup( aDisplay.getStr() );
120         }
121     }
122     if ( !m_pFreeCmdLineArgs )
123         m_pFreeCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
124 
125     osl_getExecutableFile( &aParam.pData );
126     osl_getSystemPathFromFileURL( aParam.pData, &aBin.pData );
127     rtl::OString aExec = rtl::OUStringToOString( aBin, osl_getThreadTextEncoding() );
128     m_pFreeCmdLineArgs[0] = strdup( aExec.getStr() );
129 
130     // make a copy of the string list for freeing it since
131     // KApplication manipulates the pointers inside the argument vector
132     // note: KApplication bad !
133     m_pAppCmdLineArgs = new char*[ m_nFakeCmdLineArgs ];
134     for( int i = 0; i < m_nFakeCmdLineArgs; i++ )
135         m_pAppCmdLineArgs[i] = m_pFreeCmdLineArgs[i];
136 
137     KCmdLineArgs::init( m_nFakeCmdLineArgs, m_pAppCmdLineArgs, kAboutData );
138 
139     m_pApplication = new VCLKDEApplication();
140     kapp->disableSessionManagement();
141     KApplication::setQuitOnLastWindowClosed(false);
142 
143     Display* pDisp = QX11Info::display();
144     SalKDEDisplay *pSalDisplay = new SalKDEDisplay(pDisp);
145 
146     ((VCLKDEApplication*)m_pApplication)->disp = pSalDisplay;
147 
148     pInputMethod->CreateMethod( pDisp );
149     pInputMethod->AddConnectionWatch( pDisp, (void*)this );
150     pSalDisplay->SetInputMethod( pInputMethod );
151 
152     PushXErrorLevel( true );
153     SalI18N_KeyboardExtension *pKbdExtension = new SalI18N_KeyboardExtension( pDisp );
154     XSync( pDisp, False );
155 
156     pKbdExtension->UseExtension( ! HasXErrorOccured() );
157     PopXErrorLevel();
158 
159     pSalDisplay->SetKbdExtension( pKbdExtension );
160 }
161 
doStartup()162 void KDEXLib::doStartup()
163 {
164     if( ! m_bStartupDone )
165     {
166         KStartupInfo::appStarted();
167         m_bStartupDone = true;
168         #if OSL_DEBUG_LEVEL > 1
169         fprintf( stderr, "called KStartupInfo::appStarted()\n" );
170         #endif
171     }
172 }
173