Author: kmachalkova
Date: Mon Jul 27 17:53:44 2009
New Revision: 58180
URL: http://svn.opensuse.org/viewcvs/yast?rev=58180&view=rev
Log:
Icon search class added ( FaTE #306356 )
Added:
trunk/libyui/src/YIconLoader.cc
trunk/libyui/src/YIconLoader.h
Added: trunk/libyui/src/YIconLoader.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YIconLoader.cc?rev=58180&view=auto
==============================================================================
--- trunk/libyui/src/YIconLoader.cc (added)
+++ trunk/libyui/src/YIconLoader.cc Mon Jul 27 17:53:44 2009
@@ -0,0 +1,80 @@
+#define YUILogComponent "ui"
+#include "YUILog.h"
+
+#include
+#include <sstream>
+
+#include "YIconLoader.h"
+
+#define FALLBACK_ICON_PATH "/usr/share/icons/hicolor/"
+
+YIconLoader::YIconLoader()
+{
+ addIconPath(FALLBACK_ICON_PATH);
+}
+
+YIconLoader::~YIconLoader()
+{
+}
+
+void YIconLoader::addBasePath( string path)
+{
+ iconBasePath = path;
+}
+
+void YIconLoader::addIconPath( string path )
+{
+ icon_dirs.push_front( path );
+}
+
+string YIconLoader::findIcon( string name )
+{
+ // No extension -> add some
+ string::size_type loc = name.find(".png");
+ if ( loc == string::npos )
+ name += ".png";
+
+ // Absolute path -> return it
+ if (name[0] == '/')
+ return name;
+
+ // Look in global search path
+ string fullPath = iconBasePath + name;
+ if ( fileExists ( fullPath ) )
+ {
+ yuiMilestone() << "Found " << name << " in global search path" << endl;
+ return fullPath;
+ }
+
+ // Now search the fallback dirs
+ list<string>::iterator listIt = icon_dirs.begin();
+
+ while( listIt != icon_dirs.end() )
+ {
+ // Something like relative path
+ if ( name.find('/') != string::npos )
+ fullPath = *listIt + name;
+ // No '/' chars, just the name -> use '22x22/apps' fallback
+ else
+ fullPath = *listIt + "22x22/apps/" + name;
+
+ if ( fileExists( fullPath ) )
+ {
+ yuiMilestone() << "Found " << name << " in " << *listIt << " search path" << endl;
+ return fullPath;
+ }
+
+ yuiMilestone() << name << " not found in " << *listIt << " search path, skipping" << endl;
+ listIt++;
+ }
+
+ return "";
+}
+
+bool YIconLoader::fileExists( string fname )
+{
+ struct stat fileInfo;
+ int ret = stat (fname.c_str(), &fileInfo);
+
+ return ( ret == 0 );
+}
Added: trunk/libyui/src/YIconLoader.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/libyui/src/YIconLoader.h?rev=58180&view=auto
==============================================================================
--- trunk/libyui/src/YIconLoader.h (added)
+++ trunk/libyui/src/YIconLoader.h Mon Jul 27 17:53:44 2009
@@ -0,0 +1,30 @@
+#ifndef YIconLoader_H
+#define YIconLoader_H
+
+#include <string>
+#include <list>
+
+
+using namespace std;
+
+class YIconLoader
+{
+public:
+
+ YIconLoader();
+ ~YIconLoader();
+
+ string findIcon( string name );
+
+ void addBasePath( string path );
+ void addIconPath( string path );
+
+private:
+
+ string iconBasePath;
+ list <string> icon_dirs;
+
+ bool fileExists( string fname );
+};
+
+#endif
--
To unsubscribe, e-mail: yast-commit+unsubscribe@opensuse.org
For additional commands, e-mail: yast-commit+help@opensuse.org