File indexing completed on 2024-04-28 05:32:11

0001 #ifndef oxygengtkicons_h
0002 #define oxygengtkicons_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 "oxygengtkrc.h"
0016 #include "oxygenpathlist.h"
0017 
0018 #include <string>
0019 #include <map>
0020 #include <vector>
0021 
0022 #include <gtk/gtk.h>
0023 
0024 namespace Oxygen
0025 {
0026 
0027     //! generate translations between kde icon names and gtk icons
0028     class GtkIcons
0029     {
0030         public:
0031 
0032         //! constructor
0033         GtkIcons( void );
0034 
0035         //! destructor
0036         virtual ~GtkIcons( void );
0037 
0038         //! load translations
0039         void loadTranslations( const std::string& filename );
0040 
0041         //! generate rc file
0042         Gtk::RC generate( const PathList& );
0043 
0044         //! set icon size
0045         void setIconSize( const std::string&, unsigned int value );
0046 
0047         //! true if dirty
0048         bool isDirty( void ) const
0049         { return _dirty; }
0050 
0051         protected:
0052 
0053         //! generate iconSet for given option
0054         GtkIconSet* generate( const std::string& gtkIconName, const std::string& kdeIconName, const PathList& pathList ) const;
0055 
0056         //! generate rc code for given option
0057         std::string generateString( const std::string& gtkIconName, const std::string& kdeIconName, const PathList& pathList ) const;
0058 
0059         private:
0060 
0061         //!@name icon map
0062         //@{
0063         typedef std::pair<std::string, std::string> IconPair;
0064         typedef std::map<std::string, std::string> IconMap;
0065 
0066         IconMap _icons;
0067         //@}
0068 
0069         //!@name icon sizes
0070         //@{
0071         typedef std::pair<std::string, unsigned int> SizePair;
0072         typedef std::vector<SizePair> SizeMap;
0073         SizeMap _sizes;
0074 
0075         //! used to find size pair matching given tag
0076         class SameTagFTor
0077         {
0078             public:
0079 
0080             //! constructor
0081             SameTagFTor( const std::string& tag ):
0082                 _tag( tag )
0083                 {}
0084 
0085             //! predicate
0086             bool operator() (const SizePair& pair ) const
0087             { return pair.first == _tag; }
0088 
0089             private:
0090 
0091             //! prediction
0092             std::string _tag;
0093         };
0094 
0095         //@}
0096 
0097         //!@name local storage, to prevent unnecessary reloading
0098         //@{
0099 
0100         //! local translations filename
0101         std::string _filename;
0102 
0103         //! local path list
0104         PathList _pathList;
0105 
0106         //! icon factory
0107         GtkIconFactory* _factory;
0108 
0109         //! local GtkRC
0110         Gtk::RC _rc;
0111 
0112         //! dirty flag. Set to true when options needs update
0113         bool _dirty;
0114 
0115         //@}
0116 
0117     };
0118 
0119 
0120 }
0121 
0122 #endif