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