Author: sh-sh-sh
Date: Fri Aug 22 18:06:41 2008
New Revision: 50342
URL: http://svn.opensuse.org/viewcvs/yast?rev=50342&view=rev
Log:
check environment variables for button order
Added:
trunk/libyui/src/YEnvVar.cc
trunk/libyui/src/YEnvVar.h
Modified:
trunk/libyui/src/Makefile.am
trunk/libyui/src/YUI.cc
trunk/libyui/src/YUI.h
Modified: trunk/libyui/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/Makefile.am?rev=50342&r1=50341&r2=50342&view=diff
==============================================================================
--- trunk/libyui/src/Makefile.am (original)
+++ trunk/libyui/src/Makefile.am Fri Aug 22 18:06:41 2008
@@ -26,6 +26,7 @@
YCommandLine.cc \
YEvent.cc \
YEventFilter.cc \
+ YEnvVar.cc \
YItem.cc \
YMacro.cc \
YProperty.cc \
@@ -108,6 +109,7 @@
YCommandLine.h \
YEvent.h \
YEventFilter.h \
+ YEnvVar.h \
YItem.h \
YMenuItem.h \
YMacro.h \
Added: trunk/libyui/src/YEnvVar.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YEnvVar.cc?rev=50342&view=auto
==============================================================================
--- trunk/libyui/src/YEnvVar.cc (added)
+++ trunk/libyui/src/YEnvVar.cc Fri Aug 22 18:06:41 2008
@@ -0,0 +1,108 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YEnvVar.cc
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+
+#include // getenv()
+#include // strcmp(), strcasecmp()
+#include // tolower()
+
+#define YUILogComponent "ui"
+#include "YUILog.h"
+
+#include
+
+
+YEnvVar::YEnvVar( const string & name )
+ : _name( name )
+ , _isSet( false )
+{
+ if ( ! _name.empty() )
+ {
+ const char * val = getenv( _name.c_str() );
+
+ if ( val )
+ {
+ _isSet = true;
+ _value = val;
+ }
+ }
+}
+
+
+bool
+YEnvVar::isEqual( const string & str, bool caseSensitive ) const
+{
+ if ( ! _isSet )
+ return false;
+
+ if ( caseSensitive )
+ return strcmp( _value.c_str(), str.c_str() ) == 0;
+ else
+ return strcasecmp( _value.c_str(), str.c_str() ) == 0;
+}
+
+bool
+YEnvVar::contains( const string & str, bool caseSensitive ) const
+{
+ if ( ! _isSet )
+ return false;
+
+ if ( caseSensitive )
+ {
+ return _value.find( str ) != string::npos;
+ }
+ else
+ {
+ return tolower( _value ).find( tolower( str ) ) != string::npos;
+ }
+}
+
+
+string tolower( const string & str )
+{
+ string lowStr;
+ lowStr.reserve( str.size() );
+
+ for ( string::const_iterator it = str.begin();
+ it != str.end();
+ ++it )
+ {
+ lowStr += ::tolower( *it );
+ }
+
+ return lowStr;
+}
+
+
+std::ostream &
+operator<<( std::ostream & stream, const YEnvVar env )
+{
+ if ( env.name().empty() )
+ {
+ stream << "<unnamed environment variable>";
+ }
+ else
+ {
+ if ( env.isSet() )
+ stream << "$" << env.name() << "=\"" << env.value() << "\"";
+ else
+ stream << "$" << env.name() << ": <not set>";
+ }
+
+ return stream;
+}
Added: trunk/libyui/src/YEnvVar.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YEnvVar.h?rev=50342&view=auto
==============================================================================
--- trunk/libyui/src/YEnvVar.h (added)
+++ trunk/libyui/src/YEnvVar.h Fri Aug 22 18:06:41 2008
@@ -0,0 +1,97 @@
+/*---------------------------------------------------------------------\
+| |
+| __ __ ____ _____ ____ |
+| \ \ / /_ _/ ___|_ _|___ \ |
+| \ V / _` \___ \ | | __) | |
+| | | (_| |___) || | / __/ |
+| |_|\__,_|____/ |_| |_____| |
+| |
+| core system |
+| (C) SuSE GmbH |
+\----------------------------------------------------------------------/
+
+ File: YEnvVar.h
+
+ Author: Stefan Hundhammer
+
+/-*/
+
+#ifndef YEnvVar_h
+#define YEnvVar_h
+
+#include <string>
+#include <iosfwd>
+
+using std::string;
+
+
+/**
+ * Helper class to represent an environment variable and its value.
+ **/
+class YEnvVar
+{
+public:
+ /**
+ * Constructor:
+ * Retrieve the environment variable 'name' and store the value
+ * (unless 'name' is empty).
+ **/
+ YEnvVar( const string & name = string() );
+
+ /**
+ * Return the name of the environment variable.
+ **/
+ string name() const { return _name; }
+
+ /**
+ * Return 'true' if the environment variable is set.
+ **/
+ bool isSet() const { return _isSet; }
+
+ /**
+ * Return the value of the environment variable.
+ **/
+ string value() const { return _value; }
+
+ /**
+ * Return 'true' if the environment variable is set and the value is
+ * 'str'.
+ **/
+ bool isEqual( const string & str, bool caseSensitive = false ) const;
+
+ /**
+ * Case-insensitive comparison (shortcut for isEqual() ):
+ * Return 'true' if the environment variable is set and the value is
+ * 'str'.
+ **/
+ bool operator==( const string & str ) const
+ { return isEqual( str ); }
+
+ /**
+ * Return 'true' if the environment variable is set and the value contains
+ * 'str'.
+ **/
+ bool contains( const string & str, bool caseSensitive = false ) const;
+
+
+private:
+
+ string _name;
+ string _value;
+ bool _isSet;
+};
+
+
+/**
+ * Stream output for YEnvVar
+ **/
+std::ostream & operator<<( std::ostream & stream, const YEnvVar env );
+
+
+/**
+ * Return 'str' converted to lower case.
+ **/
+string tolower( const string & str );
+
+
+#endif // YEnvVar_h
Modified: trunk/libyui/src/YUI.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YUI.cc?rev=50342&r1=50341&r2=50342&view=diff
==============================================================================
--- trunk/libyui/src/YUI.cc (original)
+++ trunk/libyui/src/YUI.cc Fri Aug 22 18:06:41 2008
@@ -25,6 +25,7 @@
#include // fcntl()
#include
#include
+#include // getenv()
#define YUILogComponent "ui"
#include "YUILog.h"
@@ -35,8 +36,14 @@
#include "YDialog.h"
#include "YApplication.h"
#include "YMacro.h"
+#include "YButtonBox.h"
+#include "YEnvVar.h"
#include "YBuiltinCaller.h"
+// Environment variable to determine button order
+// (set to "KDE" or "GNOME" - case insensitive)
+#define ENV_BUTTON_ORDER "Y2_BUTTON_ORDER"
+
YUI * YUI::_ui = 0;
@@ -54,6 +61,8 @@
{
yuiMilestone() << "Creating UI " << ( withThreads ? "with" : "without" ) << " threads" << endl;
_ui = this;
+
+ setButtonOrderFromEnvironment();
}
@@ -359,6 +368,100 @@
}
+void YUI::setButtonOrderFromEnvironment()
+{
+ YButtonOrder buttonOrder = YButtonBox::layoutPolicy().buttonOrder;
+ YButtonOrder oldButtonOrder = buttonOrder;
+
+ YEnvVar lastEnv;
+
+ //
+ // $DESKTOP_SESSION
+ //
+
+ YEnvVar env( "DESKTOP_SESSION" );
+ yuiDebug() << env << endl;
+
+ if ( env == "kde" ||
+ env == "xfce" )
+ {
+ buttonOrder = YKDEButtonOrder;
+ lastEnv = env;
+ }
+ else if ( env == "gnome" )
+ {
+ buttonOrder = YGnomeButtonOrder;
+ lastEnv = env;
+ }
+
+ //
+ // $WINDOWMANAGER
+ //
+
+ env = YEnvVar( "WINDOWMANAGER" );
+ yuiDebug() << env << endl;
+
+ if ( env.contains( "gnome" ) )
+ {
+ buttonOrder = YGnomeButtonOrder;
+ lastEnv = env;
+ }
+ else if ( env.contains( "kde" ) )
+ {
+ buttonOrder = YKDEButtonOrder;
+ lastEnv = env;
+ }
+
+
+ //
+ // $Y2_BUTTON_ORDER
+ //
+
+ env = YEnvVar( ENV_BUTTON_ORDER );
+ yuiDebug() << env << endl;
+
+ if ( env == "gnome" )
+ {
+ buttonOrder = YGnomeButtonOrder;
+ lastEnv = env;
+ }
+ else if ( env == "kde" )
+ {
+ buttonOrder = YKDEButtonOrder;
+ lastEnv = env;
+ }
+ else if ( ! env.value().empty() )
+ {
+ yuiWarning() << "Ignoring unknown value of " << env << endl;
+ }
+
+
+ if ( buttonOrder != oldButtonOrder )
+ {
+ string buttonOrderStr;
+
+ switch ( buttonOrder )
+ {
+ case YKDEButtonOrder:
+ buttonOrderStr = "KDE";
+ YButtonBox::setLayoutPolicy( YButtonBox::kdeLayoutPolicy() );
+ break;
+
+ case YGnomeButtonOrder:
+ buttonOrderStr = "GNOME";
+ YButtonBox::setLayoutPolicy( YButtonBox::gnomeLayoutPolicy() );
+ break;
+
+ // Intentionally omitting "default" branch so GCC can catch unhandled enums
+ }
+
+ yuiMilestone() << "Switching to " << buttonOrderStr
+ << " button order because of " << lastEnv
+ << endl;
+ }
+}
+
+
//
// ----------------------------------------------------------------------
//
Modified: trunk/libyui/src/YUI.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YUI.h?rev=50342&r1=50341&r2=50342&view=diff
==============================================================================
--- trunk/libyui/src/YUI.h (original)
+++ trunk/libyui/src/YUI.h Fri Aug 22 18:06:41 2008
@@ -280,6 +280,17 @@
**/
bool waitForYCPThread();
+ /**
+ * Set the button order (in YButtonBox widgets) from environment
+ * variables:
+ *
+ * $Y2_BUTTON_ORDER="KDE"
+ * $Y2_BUTTON_ORDER="Gnome"
+ *
+ * (all case insensitive)
+ **/
+ void setButtonOrderFromEnvironment();
+
//
// Data members
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org