Sophie

Sophie

distrib > Scientific%20Linux > 5x > x86_64 > by-pkgid > f56245b36fb217cb826b4585621bb690 > files > 53

kdelibs-3.5.4-26.el5_7.1.src.rpm

Index: kio/kfile/kicondialog.h
===================================================================
--- kio/kfile/kicondialog.h	(Revision 576243)
+++ kio/kfile/kicondialog.h	(Revision 576245)
@@ -222,6 +222,7 @@
 private:
     void init();
     void showIcons();
+    void setContext( KIcon::Context context );
 
     int mGroupOrSize;
     KIcon::Context mContext;
@@ -234,6 +235,8 @@
     KProgress *mpProgress;
     KIconLoader *mpLoader;
     KIconCanvas *mpCanvas;
+    int mNumContext;
+    KIcon::Context mContextMap[ 12 ]; // must match KIcon::Context size, code has assert
 
 protected:
     virtual void virtual_hook( int id, void* data );
Index: kio/kfile/kicondialog.cpp
===================================================================
--- kio/kfile/kicondialog.cpp	(Revision 576243)
+++ kio/kfile/kicondialog.cpp	(Revision 576245)
@@ -15,6 +15,8 @@
 
 #include <config.h>
 
+#include <assert.h>
+
 #include <kiconviewsearchline.h>
 
 #include <kapplication.h>
@@ -324,13 +326,49 @@
     // When pressing Ok or Cancel, stop loading icons
     connect(this, SIGNAL(hidden()), mpCanvas, SLOT(stopLoading()));
 
-    // The order must match the context definitions in KIcon.
-    mpCombo->insertItem(i18n("Actions"));
-    mpCombo->insertItem(i18n("Applications"));
-    mpCombo->insertItem(i18n("Devices"));
-    mpCombo->insertItem(i18n("Filesystems"));
-    mpCombo->insertItem(i18n("Mimetypes"));
+    static const char* const context_text[] = {
+        I18N_NOOP( "Actions" ),
+        I18N_NOOP( "Animations" ),
+        I18N_NOOP( "Applications" ),
+        I18N_NOOP( "Categories" ),
+        I18N_NOOP( "Devices" ),
+        I18N_NOOP( "Emblems" ),
+        I18N_NOOP( "Emotes" ),
+        I18N_NOOP( "Filesystems" ),
+        I18N_NOOP( "International" ),
+        I18N_NOOP( "Mimetypes" ),
+        I18N_NOOP( "Places" ),
+        I18N_NOOP( "Status" ) };
+    static const KIcon::Context context_id[] = {
+        KIcon::Action,
+        KIcon::Animation,
+        KIcon::Application,
+        KIcon::Category,
+        KIcon::Device,
+        KIcon::Emblem,
+        KIcon::Emote,
+        KIcon::FileSystem,
+        KIcon::International,
+        KIcon::MimeType,
+        KIcon::Place,
+        KIcon::StatusIcon };
+    mNumContext = 0;
+    int cnt = sizeof( context_text ) / sizeof( context_text[ 0 ] );
+    // check all 3 arrays have same sizes
+    assert( cnt == sizeof( context_id ) / sizeof( context_id[ 0 ] )
+            && cnt == sizeof( mContextMap ) / sizeof( mContextMap[ 0 ] ));
+    for( int i = 0;
+         i < cnt;
+         ++i )
+    {
+        if( mpLoader->hasContext( context_id[ i ] ))
+        {
+            mpCombo->insertItem(i18n( context_text[ i ] ));
+            mContextMap[ mNumContext++ ] = context_id[ i ];
+        }
+    }
     mpCombo->setFixedSize(mpCombo->sizeHint());
+
     mpBrowseBut->setFixedWidth(mpCombo->width());
 
     // Make the dialog a little taller
@@ -422,8 +460,7 @@
     mpRb2->setChecked(user);
     mpCombo->setEnabled(!user);
     mpBrowseBut->setEnabled(user);
-    mContext = context;
-    mpCombo->setCurrentItem(mContext-1);
+    setContext( context );
 }
 
 void KIconDialog::setup(KIcon::Group group, KIcon::Context context,
@@ -441,8 +478,20 @@
     mpRb2->setEnabled( !lockUser || user );
     mpCombo->setEnabled(!user);
     mpBrowseBut->setEnabled( user && !lockCustomDir );
+    setContext( context );
+}
+
+void KIconDialog::setContext( KIcon::Context context )
+{
     mContext = context;
-    mpCombo->setCurrentItem(mContext-1);
+    for( int i = 0;
+         i < mNumContext;
+         ++i )
+        if( mContextMap[ i ] == context )
+        {
+            mpCombo->setCurrentItem( i );
+            return;
+        }
 }
 
 void KIconDialog::setCustomLocation( const QString& location )
@@ -562,7 +611,7 @@
 
 void KIconDialog::slotContext(int id)
 {
-    mContext = static_cast<KIcon::Context>(id+1);
+    mContext = static_cast<KIcon::Context>( mContextMap[ id ] );
     showIcons();
 }
 
Index: kdecore/kicontheme.h
===================================================================
--- kdecore/kicontheme.h	(Revision 576243)
+++ kdecore/kicontheme.h	(Revision 576245)
@@ -51,7 +51,14 @@
       Application, ///< An icon that represents an application.
       Device, ///< An icon that represents a device.
       FileSystem, ///< An icon that represents a file system.
-      MimeType ///< An icon that represents a mime type (or file type).
+      MimeType, ///< An icon that represents a mime type (or file type).
+      Animation, ///< An icon that is animated.
+      Category, ///< An icon that represents a category.
+      Emblem, ///< An icon that adds information to an existing icon.
+      Emote, ///< An icon that expresses an emotion.
+      International, ///< An icon that represents a country's flag.
+      Place, ///< An icon that represents a location (e.g. 'home', 'trash').
+      StatusIcon ///< An icon that represents an event.
     };
 
     /**
@@ -313,6 +320,12 @@
      * @see KIcon::isValid will return true, and false otherwise.
      */
     KIcon iconPath(const QString& name, int size, KIcon::MatchType match) const;
+    
+    /**
+     * Returns true if the theme has any icons for the given context.
+     * @since 3.5.5
+     */
+    bool hasContext( KIcon::Context context ) const;
 
     /**
      * List all icon themes installed on the system, global and local.
Index: kdecore/kicontheme.cpp
===================================================================
--- kdecore/kicontheme.cpp	(Revision 576243)
+++ kdecore/kicontheme.cpp	(Revision 576245)
@@ -340,6 +340,20 @@
     return iconlistResult;
 }
 
+bool KIconTheme::hasContext(KIcon::Context context) const
+{
+    QPtrListIterator<KIconThemeDir> dirs(mDirs);
+    KIconThemeDir *dir;
+
+    for ( ; dirs.current(); ++dirs)
+    {
+        dir = dirs.current();
+        if ((context == KIcon::Any) || (context == dir->context()))
+            return true;
+    }
+    return false;
+}
+
 KIcon KIconTheme::iconPath(const QString& name, int size, KIcon::MatchType match) const
 {
     KIcon icon;
@@ -517,6 +531,20 @@
         mContext = KIcon::Application;
     else if (tmp == "Actions")
         mContext = KIcon::Action;
+    else if (tmp == "Animations")
+        mContext = KIcon::Animation;
+    else if (tmp == "Categories")
+        mContext = KIcon::Category;
+    else if (tmp == "Emblems")
+        mContext = KIcon::Emblem;
+    else if (tmp == "Emotes")
+        mContext = KIcon::Emote;
+    else if (tmp == "International")
+        mContext = KIcon::International;
+    else if (tmp == "Places")
+        mContext = KIcon::Place;
+    else if (tmp == "Status")
+        mContext = KIcon::StatusIcon;
     else {
         kdDebug(264) << "Invalid Context= line for icon theme: " << mDir << "\n";
         return;
Index: kdecore/kiconloader.cpp
===================================================================
--- kdecore/kiconloader.cpp	(Revision 576243)
+++ kdecore/kiconloader.cpp	(Revision 576245)
@@ -1131,6 +1131,16 @@
     return res2;
 }
 
+// used by KIconDialog to find out which contexts to offer in a combobox
+bool KIconLoader::hasContext(KIcon::Context context) const
+{
+    for ( KIconThemeNode *themeNode = d->links.first() ; themeNode ;
+            themeNode = d->links.next() )
+       if( themeNode->theme->hasContext( context ))
+           return true;
+    return false;
+}
+
 KIconEffect * KIconLoader::iconEffect() const
 {
     return &d->mpEffect;
Index: kdecore/kiconloader.h
===================================================================
--- kdecore/kiconloader.h	(Revision 576243)
+++ kdecore/kiconloader.h	(Revision 576245)
@@ -262,6 +262,11 @@
 				    KIcon::Context context=KIcon::Any) const;
 
     /**
+     * @internal
+     */
+    bool hasContext( KIcon::Context context ) const;
+
+    /**
      * Returns a list of all icons (*.png or *.xpm extension) in the
      * given directory.
      * @param iconsDir the directory to search in