File indexing completed on 2024-04-28 05:32:09
0001 #ifndef oxygenapplicationname_h 0002 #define oxygenapplicationname_h 0003 /* 0004 * this file is part of the oxygen gtk engine 0005 * SPDX-FileCopyrightText: 2010 Hugo Pereira Da Costa <hugo.pereira@free.fr> 0006 * 0007 * inspired notably from kdelibs/kdeui/color/kcolorutils.h 0008 * SPDX-FileCopyrightText: 2007 Matthew Woehlke <mw_triad@users.sourceforge.net> 0009 * SPDX-FileCopyrightText: 2007 Thomas Zander <zander@kde.org> 0010 * SPDX-FileCopyrightText: 2007 Zack Rusin <zack@kde.org> 0011 * 0012 * SPDX-License-Identifier: LGPL-2.0-or-later 0013 */ 0014 0015 #include <gtk/gtk.h> 0016 #include <iostream> 0017 #include <string> 0018 0019 namespace Oxygen 0020 { 0021 0022 //! application name enumeration 0023 enum AppName 0024 { 0025 Unknown, 0026 Acrobat, 0027 XUL, 0028 Gimp, 0029 OpenOffice, 0030 GoogleChrome, 0031 Opera, 0032 Java, 0033 JavaSwt, 0034 Eclipse, 0035 }; 0036 0037 //! stores application name and provides some utility functions 0038 class ApplicationName 0039 { 0040 0041 public: 0042 0043 //! constructor 0044 ApplicationName( AppName name = Unknown ): 0045 _name( name ), 0046 _version( NULL ) 0047 {} 0048 0049 //! assignment 0050 ApplicationName& operator = ( const AppName& name ) 0051 { 0052 _name = name; 0053 return *this; 0054 } 0055 0056 //! cast 0057 operator const AppName& ( void ) const 0058 { return _name; } 0059 0060 const char* versionString( void ) const 0061 { return _version; } 0062 0063 //! initialize 0064 /*! try derive AppName from gtk program name */ 0065 void initialize( void ); 0066 0067 //!@name utilities 0068 //@{ 0069 0070 bool isAcrobat( void ) const { return _name == Acrobat; } 0071 bool isXul( void ) const { return _name == XUL; } 0072 bool isGimp( void ) const { return _name == Gimp; } 0073 bool isOpenOffice( void ) const { return _name == OpenOffice; } 0074 bool isGoogleChrome( void ) const { return _name == GoogleChrome; } 0075 bool isUnknown( void ) const { return _name == Unknown; } 0076 0077 bool isJava( void ) const { return _name == Java; } 0078 bool isJavaSwt( void ) const { return _name == JavaSwt; } 0079 bool isOpera( void ) const { return _name == Opera; } 0080 bool isEclipse( void ) const { return _name == Eclipse; } 0081 0082 //! special case for mozilla and acrobat that also check the type of the top level widget 0083 /*! this allows to prevent false positive for open and print dialogs */ 0084 bool isAcrobat( GtkWidget* widget ) const { return isAcrobat() && !isGtkDialogWidget( widget ); } 0085 bool isXul( GtkWidget* widget ) const { return isXul() && !isGtkDialogWidget( widget ); } 0086 bool isJavaSwt( GtkWidget* widget ) const { return isJavaSwt() && !isGtkDialogWidget( widget ); } 0087 bool isOpenOffice( GtkWidget* widget ) const { return isOpenOffice() && !isGtkDialogWidget( widget ); } 0088 0089 // true for all applications that requires a flat background to be used 0090 bool useFlatBackground( GtkWidget* ) const; 0091 0092 //@} 0093 0094 protected: 0095 0096 //! determine if widget is on a GtkDialog 0097 bool isGtkDialogWidget( GtkWidget* ) const; 0098 0099 //! get application name from Gtk 0100 std::string fromGtk( void ) const; 0101 0102 //! get application name from pid 0103 std::string fromPid( int ) const; 0104 0105 private: 0106 0107 //! name 0108 AppName _name; 0109 0110 const char* _version; 0111 0112 //! streamer (for debugging) 0113 friend std::ostream& operator << ( std::ostream&, const ApplicationName& ); 0114 0115 0116 }; 0117 0118 0119 } 0120 0121 #endif