summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2011-05-31 18:20:17 +0200
committerLuboš Luňák <l.lunak@suse.cz>2011-05-31 18:20:17 +0200
commit2dfbdb6fb008b4d0df4b3fe8da17745c191fee37 (patch)
tree6319474a9d8a58711dbb857cd3f9935b2b76adc0 /vcl
parent4ed61b6dca06705dd4ae6e20f3b1709b26a27081 (diff)
use enum instead of strings for desktop types
welcome to the future! (well, almost)
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/unx/desktops.hxx43
-rw-r--r--vcl/unx/generic/desktopdetect/desktopdetector.cxx147
-rw-r--r--vcl/unx/generic/plugadapt/salplug.cxx74
3 files changed, 145 insertions, 119 deletions
diff --git a/vcl/inc/unx/desktops.hxx b/vcl/inc/unx/desktops.hxx
new file mode 100644
index 000000000000..de4ebb8eab01
--- /dev/null
+++ b/vcl/inc/unx/desktops.hxx
@@ -0,0 +1,43 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*************************************************************************
+ *
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * Copyright 2000, 2010 Oracle and/or its affiliates.
+ *
+ * OpenOffice.org - a multi-platform office productivity suite
+ *
+ * This file is part of OpenOffice.org.
+ *
+ * OpenOffice.org is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License version 3
+ * only, as published by the Free Software Foundation.
+ *
+ * OpenOffice.org is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License version 3 for more details
+ * (a copy is included in the LICENSE file that accompanied this code).
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * version 3 along with OpenOffice.org. If not, see
+ * <http://www.openoffice.org/license.html>
+ * for a copy of the LGPLv3 License.
+ *
+ ************************************************************************/
+
+#ifndef INCLUDED_VCL_DESKTOPS_HXX
+#define INCLUDED_VCL_DESKTOPS_HXX
+
+enum DesktopType {
+ DESKTOP_NONE, // headless, i.e. no X connection at all
+ DESKTOP_UNKNOWN, // unknown desktop, simple WM, etc.
+ DESKTOP_GNOME,
+ DESKTOP_KDE,
+ DESKTOP_KDE4,
+ DESKTOP_CDE
+}; // keep in sync with desktop_strings[] in salplug.cxx
+
+#endif // INCLUDED_VCL_DESKTOPS_HXX
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/vcl/unx/generic/desktopdetect/desktopdetector.cxx b/vcl/unx/generic/desktopdetect/desktopdetector.cxx
index 568507822c1e..77cabc229284 100644
--- a/vcl/unx/generic/desktopdetect/desktopdetector.cxx
+++ b/vcl/unx/generic/desktopdetect/desktopdetector.cxx
@@ -30,6 +30,7 @@
#include "precompiled_vcl.hxx"
#include <unx/svunx.h>
+#include <unx/desktops.hxx>
#include <tools/prex.h>
#include <X11/Xatom.h>
#include <tools/postx.h>
@@ -46,16 +47,6 @@
using ::rtl::OUString;
using ::rtl::OString;
-enum {
- DESKTOP_NONE = 0,
- DESKTOP_UNKNOWN,
- DESKTOP_GNOME,
- DESKTOP_KDE,
- DESKTOP_KDE4,
- DESKTOP_CDE
-};
-
-static const char * desktop_strings[] = { "none", "unknown", "GNOME", "KDE", "KDE4", "CDE" };
static bool is_gnome_desktop( Display* pDisplay )
{
@@ -255,9 +246,8 @@ static bool is_cde_desktop( Display* pDisplay )
extern "C"
{
-DESKTOP_DETECTOR_PUBLIC rtl::OUString get_desktop_environment()
+DESKTOP_DETECTOR_PUBLIC DesktopType get_desktop_environment()
{
- rtl::OUStringBuffer aRet( 8 );
static const char *pOverride = getenv( "OOO_FORCE_DESKTOP" );
if ( pOverride && *pOverride )
@@ -265,90 +255,87 @@ DESKTOP_DETECTOR_PUBLIC rtl::OUString get_desktop_environment()
OString aOver( pOverride );
if ( aOver.equalsIgnoreAsciiCase( "cde" ) )
- aRet.appendAscii( desktop_strings[DESKTOP_CDE] );
+ return DESKTOP_CDE;
if ( aOver.equalsIgnoreAsciiCase( "kde4" ) )
- aRet.appendAscii( desktop_strings[DESKTOP_KDE4] );
+ return DESKTOP_KDE4;
if ( aOver.equalsIgnoreAsciiCase( "gnome" ) )
- aRet.appendAscii( desktop_strings[DESKTOP_GNOME] );
+ return DESKTOP_GNOME;
if ( aOver.equalsIgnoreAsciiCase( "kde" ) )
- aRet.appendAscii( desktop_strings[DESKTOP_KDE] );
+ return DESKTOP_KDE;
if ( aOver.equalsIgnoreAsciiCase( "none" ) )
- aRet.appendAscii( desktop_strings[DESKTOP_UNKNOWN] );
+ return DESKTOP_UNKNOWN;
}
- if( aRet.getLength() == 0 )
- {
- // get display to connect to
- const char* pDisplayStr = getenv( "DISPLAY" );
+ // get display to connect to
+ const char* pDisplayStr = getenv( "DISPLAY" );
- const char* pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );
+ const char* pUsePlugin = getenv( "SAL_USE_VCLPLUGIN" );
- if (pUsePlugin && (strcmp(pUsePlugin, "svp") == 0))
- pDisplayStr = NULL;
- else
+ if (pUsePlugin && (strcmp(pUsePlugin, "svp") == 0))
+ pDisplayStr = NULL;
+ else
+ {
+ int nParams = osl_getCommandArgCount();
+ OUString aParam;
+ OString aBParm;
+ for( int i = 0; i < nParams; i++ )
{
- int nParams = osl_getCommandArgCount();
- OUString aParam;
- OString aBParm;
- for( int i = 0; i < nParams; i++ )
+ osl_getCommandArg( i, &aParam.pData );
+ if( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-headless" ) ) ||
+ aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--headless" ) ) )
{
- osl_getCommandArg( i, &aParam.pData );
- if( aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-headless" ) ) ||
- aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--headless" ) ) )
- {
- pDisplayStr = NULL;
- break;
- }
- if( i < nParams-1 && (aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-display" ) ) || aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--display" ) )) )
- {
- osl_getCommandArg( i+1, &aParam.pData );
- aBParm = OUStringToOString( aParam, osl_getThreadTextEncoding() );
- pDisplayStr = aBParm.getStr();
- break;
- }
+ pDisplayStr = NULL;
+ break;
}
- }
-
- // no server at all
- if( ! pDisplayStr || !*pDisplayStr )
- aRet.appendAscii( desktop_strings[DESKTOP_NONE] );
- else
- {
- /* #i92121# workaround deadlocks in the X11 implementation
- */
- static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
- /* #i90094#
- from now on we know that an X connection will be
- established, so protect X against itself
- */
- if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
- XInitThreads();
-
- Display* pDisplay = XOpenDisplay( pDisplayStr );
- if( pDisplay )
+ if( i < nParams-1 && (aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-display" ) ) || aParam.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "--display" ) )) )
{
- XErrorHandler pOldHdl = XSetErrorHandler( autodect_error_handler );
-
- if ( is_kde4_desktop( pDisplay ) )
- aRet.appendAscii( desktop_strings[DESKTOP_KDE4] );
- else if ( is_gnome_desktop( pDisplay ) )
- aRet.appendAscii( desktop_strings[DESKTOP_GNOME] );
- else if ( is_cde_desktop( pDisplay ) )
- aRet.appendAscii( desktop_strings[DESKTOP_CDE] );
- else if ( is_kde_desktop( pDisplay ) )
- aRet.appendAscii( desktop_strings[DESKTOP_KDE] );
- else
- aRet.appendAscii( desktop_strings[DESKTOP_UNKNOWN] );
-
- // set the default handler again
- XSetErrorHandler( pOldHdl );
-
- XCloseDisplay( pDisplay );
+ osl_getCommandArg( i+1, &aParam.pData );
+ aBParm = OUStringToOString( aParam, osl_getThreadTextEncoding() );
+ pDisplayStr = aBParm.getStr();
+ break;
}
}
}
- return aRet.makeStringAndClear();
+ // no server at all
+ if( ! pDisplayStr || !*pDisplayStr )
+ return DESKTOP_NONE;
+
+ /* #i92121# workaround deadlocks in the X11 implementation
+ */
+ static const char* pNoXInitThreads = getenv( "SAL_NO_XINITTHREADS" );
+ /* #i90094#
+ from now on we know that an X connection will be
+ established, so protect X against itself
+ */
+ if( ! ( pNoXInitThreads && *pNoXInitThreads ) )
+ XInitThreads();
+
+ Display* pDisplay = XOpenDisplay( pDisplayStr );
+ if( pDisplay == NULL )
+ return DESKTOP_NONE;
+
+ DesktopType ret;
+
+ XErrorHandler pOldHdl = XSetErrorHandler( autodect_error_handler );
+
+ if ( is_kde4_desktop( pDisplay ) )
+ ret = DESKTOP_KDE4;
+ else if ( is_gnome_desktop( pDisplay ) )
+ ret = DESKTOP_GNOME;
+ else if ( is_cde_desktop( pDisplay ) )
+ ret = DESKTOP_CDE;
+ else if ( is_kde_desktop( pDisplay ) )
+ ret = DESKTOP_KDE;
+ else
+ ret = DESKTOP_UNKNOWN;
+
+ // set the default handler again
+ XSetErrorHandler( pOldHdl );
+
+ XCloseDisplay( pDisplay );
+
+ return ret;
}
}
diff --git a/vcl/unx/generic/plugadapt/salplug.cxx b/vcl/unx/generic/plugadapt/salplug.cxx
index 649522206cd3..3d92163b75c3 100644
--- a/vcl/unx/generic/plugadapt/salplug.cxx
+++ b/vcl/unx/generic/plugadapt/salplug.cxx
@@ -36,6 +36,7 @@
#include "salinst.hxx"
#include "unx/saldata.hxx"
+#include "unx/desktops.hxx"
#include "vcl/printerinfomanager.hxx"
#include <cstdio>
@@ -49,17 +50,6 @@ typedef SalInstance*(*salFactoryProc)( oslModule pModule);
static oslModule pCloseModule = NULL;
-enum {
- DESKTOP_NONE = 0,
- DESKTOP_UNKNOWN,
- DESKTOP_GNOME,
- DESKTOP_KDE,
- DESKTOP_KDE4,
- DESKTOP_CDE
-};
-
-static const char * desktop_strings[] = { "none", "unknown", "GNOME", "KDE", "KDE4", "CDE" };
-
static SalInstance* tryInstance( const OUString& rModuleBase )
{
SalInstance* pInst = NULL;
@@ -131,29 +121,26 @@ static SalInstance* tryInstance( const OUString& rModuleBase )
return pInst;
}
-static const rtl::OUString& get_desktop_environment()
+static DesktopType get_desktop_environment()
{
- static rtl::OUString aRet;
- if( ! aRet.getLength() )
+ OUStringBuffer aModName( 128 );
+ aModName.appendAscii( SAL_DLLPREFIX"desktop_detector" );
+ aModName.appendAscii( SAL_DLLPOSTFIX );
+ OUString aModule = aModName.makeStringAndClear();
+
+ oslModule aMod = osl_loadModuleRelative(
+ reinterpret_cast< oslGenericFunction >( &tryInstance ), aModule.pData,
+ SAL_LOADMODULE_DEFAULT );
+ DesktopType ret = DESKTOP_UNKNOWN;
+ if( aMod )
{
- OUStringBuffer aModName( 128 );
- aModName.appendAscii( SAL_DLLPREFIX"desktop_detector" );
- aModName.appendAscii( SAL_DLLPOSTFIX );
- OUString aModule = aModName.makeStringAndClear();
-
- oslModule aMod = osl_loadModuleRelative(
- reinterpret_cast< oslGenericFunction >( &tryInstance ), aModule.pData,
- SAL_LOADMODULE_DEFAULT );
- if( aMod )
- {
- rtl::OUString (*pSym)() = (rtl::OUString(*)())
- osl_getAsciiFunctionSymbol( aMod, "get_desktop_environment" );
- if( pSym )
- aRet = pSym();
- }
- osl_unloadModule( aMod );
+ DesktopType (*pSym)() = (DesktopType(*)())
+ osl_getAsciiFunctionSymbol( aMod, "get_desktop_environment" );
+ if( pSym )
+ ret = pSym();
}
- return aRet;
+ osl_unloadModule( aMod );
+ return ret;
}
static SalInstance* autodetect_plugin()
@@ -173,21 +160,21 @@ static SalInstance* autodetect_plugin()
"svp", 0
};
- const rtl::OUString& desktop( get_desktop_environment() );
+ DesktopType desktop = get_desktop_environment();
const char ** pList = pStandardFallbackList;
int nListEntry = 0;
// no server at all: dummy plugin
- if ( desktop.equalsAscii( desktop_strings[DESKTOP_NONE] ) )
+ if ( desktop == DESKTOP_NONE )
pList = pHeadlessFallbackList;
- else if ( desktop.equalsAscii( desktop_strings[DESKTOP_GNOME] ) )
+ else if ( desktop == DESKTOP_GNOME )
pList = pStandardFallbackList;
- else if( desktop.equalsAscii( desktop_strings[DESKTOP_KDE] ) )
+ else if( desktop == DESKTOP_KDE )
{
pList = pKDEFallbackList;
nListEntry = 1;
}
- else if( desktop.equalsAscii( desktop_strings[DESKTOP_KDE4] ) )
+ else if( desktop == DESKTOP_KDE4 )
pList = pKDEFallbackList;
SalInstance* pInst = NULL;
@@ -195,10 +182,10 @@ static SalInstance* autodetect_plugin()
{
rtl::OUString aTry( rtl::OUString::createFromAscii( pList[nListEntry] ) );
pInst = tryInstance( aTry );
- #if OSL_DEBUG_LEVEL > 1
+// #if OSL_DEBUG_LEVEL > 1
if( pInst )
std::fprintf( stderr, "plugin autodetection: %s\n", pList[nListEntry] );
- #endif
+// #endif
nListEntry++;
}
@@ -288,9 +275,18 @@ void SalAbort( const XubString& rErrorText )
exit(-1);
}
+static const char * desktop_strings[] = { "none", "unknown", "GNOME", "KDE", "KDE4", "CDE" };
+
const OUString& SalGetDesktopEnvironment()
{
- return get_desktop_environment();
+ static rtl::OUString aRet;
+ if( aRet.isEmpty())
+ {
+ rtl::OUStringBuffer buf( 8 );
+ buf.appendAscii( desktop_strings[ get_desktop_environment() ] );
+ aRet = buf.makeStringAndClear();
+ }
+ return aRet;
}
SalData::SalData() :