LogoopenSUSE Build Service > Projects
Sign Up | Log In

View File clever-menu.diff of Package kdelibs4 (Project KDE:Distro:Factory)

diff --git a/kdecore/services/kservice.cpp b/kdecore/services/kservice.cpp
index eb35a15..097186f 100644
--- a/kdecore/services/kservice.cpp
+++ b/kdecore/services/kservice.cpp
@@ -741,6 +741,11 @@ QString KService::untranslatedGenericName() const {
     return v.isValid() ? v.toString() : QString();
 }
 
+bool KService::SuSEunimportant() const {
+    QVariant v = property(QString::fromLatin1("X-SuSE-Unimportant"), QVariant::Bool);
+    return v.isValid() && v.toBool();
+}
+
 QString KService::parentApp() const {
     Q_D(const KService);
     QMap<QString,QVariant>::ConstIterator it = d->m_mapProps.find(QLatin1String("X-KDE-ParentApp"));
diff --git a/kdecore/services/kservice.h b/kdecore/services/kservice.h
index 3843bad..022c915 100644
--- a/kdecore/services/kservice.h
+++ b/kdecore/services/kservice.h
@@ -358,6 +358,12 @@ public:
     bool noDisplay() const;
 
     /**
+     * check if the application entry is important
+     * SuSE special, not part of KDE API
+     */
+    bool SuSEunimportant() const;
+
+    /**
      * Whether the service should be shown in KDE at all
      * (including in context menus).
      * @return true if the service should be shown.
diff --git a/kdecore/services/kservicegroup.cpp b/kdecore/services/kservicegroup.cpp
index 08bc587..70f4ab3 100644
--- a/kdecore/services/kservicegroup.cpp
+++ b/kdecore/services/kservicegroup.cpp
@@ -29,7 +29,7 @@
 #include <ksortablelist.h>
 #include <kdesktopfile.h>
 #include <kconfiggroup.h>
-
+#include <QDir>
 
 KServiceGroup::KServiceGroup( const QString & name )
  : KSycocaEntry(*new KServiceGroupPrivate(name))
@@ -61,6 +61,11 @@ void KServiceGroupPrivate::load(const QString &cfg)
   m_strComment = config.readEntry( "Comment" );
   deleted = config.readEntry("Hidden", false );
   m_bNoDisplay = desktopFile.noDisplay();
+  if (directoryEntryPath.startsWith(QDir::homePath()))
+      m_bShortMenu = false;
+  else
+      m_bShortMenu = config.readEntry( QString::fromLatin1("X-SuSE-AutoShortMenu"), true );
+  m_bGeneralDescription = config.readEntry( QString::fromLatin1("X-SuSE-GeneralDescription"), false );
   m_strBaseGroupName = config.readEntry( "X-KDE-BaseGroup" );
   suppressGenericNames = config.readEntry( "X-KDE-SuppressGenericNames", QStringList() );
 //  d->sortOrder = config.readEntry("SortOrder", QStringList());
@@ -124,6 +129,10 @@ int KServiceGroupPrivate::childCount() const
 {
   if (m_childCount == -1)
   {
+     KConfig cfg(QString::fromLatin1("kdeglobals"));
+     KConfigGroup global = cfg.group(QString::fromLatin1("KDE"));
+     bool showUnimportant = global.readEntry(QString::fromLatin1("showUnimportant"), false);
+
      m_childCount = 0;
 
      for( KServiceGroup::List::ConstIterator it = m_serviceList.begin();
@@ -134,7 +143,8 @@ int KServiceGroupPrivate::childCount() const
         {
             KService::Ptr service = KService::Ptr::staticCast( p );
            if (!service->noDisplay())
-              m_childCount++;
+               if ( showUnimportant || !service->SuSEunimportant() )
+                   m_childCount++;
         }
         else if (p->isType(KST_KServiceGroup))
         {
@@ -219,6 +229,18 @@ QStringList KServiceGroup::suppressGenericNames() const
   return d->suppressGenericNames;
 }
 
+bool KServiceGroup::SuSEgeneralDescription() const
+{
+    Q_D(const KServiceGroup);
+  return d->m_bGeneralDescription;
+}
+
+bool KServiceGroup::SuSEshortMenu() const
+{
+    Q_D(const KServiceGroup);
+  return d->m_bShortMenu;
+}
+
 void KServiceGroupPrivate::load( QDataStream& s )
 {
   QStringList groupList;
@@ -227,16 +249,21 @@ void KServiceGroupPrivate::load( QDataStream& s )
   qint8 inlineHeader;
   qint8 _inlineAlias;
   qint8 _allowInline;
+  qint8 _shortMenu;
+  qint8 _generalDescription;
   s >> m_strCaption >> m_strIcon >>
       m_strComment >> groupList >> m_strBaseGroupName >> m_childCount >>
       noDisplay >> suppressGenericNames >> directoryEntryPath >>
-      sortOrder >> _showEmptyMenu >> inlineHeader >> _inlineAlias >> _allowInline;
+      sortOrder >> _showEmptyMenu >> inlineHeader >> _inlineAlias >> _allowInline >>
+      _shortMenu >> _generalDescription;
 
   m_bNoDisplay = (noDisplay != 0);
   m_bShowEmptyMenu = ( _showEmptyMenu != 0 );
   m_bShowInlineHeader = ( inlineHeader != 0 );
   m_bInlineAlias = ( _inlineAlias != 0 );
   m_bAllowInline = ( _allowInline != 0 );
+  m_bShortMenu = (_shortMenu != 0);
+  m_bGeneralDescription = (_generalDescription != 0);
 
   if (m_bDeep)
   {
@@ -296,10 +323,12 @@ void KServiceGroupPrivate::save( QDataStream& s )
   qint8 inlineHeader = m_bShowInlineHeader ? 1 : 0;
   qint8 _inlineAlias = m_bInlineAlias ? 1 : 0;
   qint8 _allowInline = m_bAllowInline ? 1 : 0;
+  qint8 _shortMenu = m_bShortMenu ? 1 : 0;
   s << m_strCaption << m_strIcon <<
       m_strComment << groupList << m_strBaseGroupName << m_childCount <<
       noDisplay << suppressGenericNames << directoryEntryPath <<
-      sortOrder <<_showEmptyMenu <<inlineHeader<<_inlineAlias<<_allowInline;
+      sortOrder <<_showEmptyMenu <<inlineHeader<<_inlineAlias<<_allowInline <<
+      _shortMenu << m_bGeneralDescription;
 }
 
 QList<KServiceGroup::Ptr> KServiceGroup::groupEntries(EntriesOptions options)
@@ -359,6 +388,21 @@ KServiceGroup::entries(bool sort, bool excludeNoDisplay, bool allowSeparators, b
     return d->entries(this, sort, excludeNoDisplay, allowSeparators, sortByGenericName);
 }
 
+void KServiceGroup::addSortOrderEntry( const char *entry )
+{
+    Q_D(KServiceGroup);
+    const QString s = QString::fromLatin1(entry);
+    if (!d->sortOrder.contains(s))
+       d->sortOrder << s;
+}
+
+KServiceGroup::List
+KServiceGroup::SuSEsortEntries( KSortableList<KServiceGroup::SPtr,QByteArray> slist, KSortableList<KServiceGroup::SPtr,QByteArray> glist, bool excludeNoDisplay, bool allowSeparators )
+{
+    Q_D(KServiceGroup);
+    return d->SuSEsortEntries( this, slist, glist, excludeNoDisplay, allowSeparators );
+}
+
 static void addItem(KServiceGroup::List &sorted, const KSycocaEntry::Ptr &p, bool &addSeparator)
 {
    if (addSeparator && !sorted.isEmpty())
@@ -370,6 +414,12 @@ static void addItem(KServiceGroup::List &sorted, const KSycocaEntry::Ptr &p, boo
 KServiceGroup::List
 KServiceGroupPrivate::entries(KServiceGroup *group, bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName)
 {
+    return SuSEentries(group, sort, excludeNoDisplay, allowSeparators, sortByGenericName);
+}
+
+KServiceGroup::List
+KServiceGroupPrivate::SuSEentries(KServiceGroup *group, bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName, bool excludeSuSEunimportant)
+{
     KServiceGroup::Ptr grp;
 
     // If the entries haven't been loaded yet, we have to reload ourselves
@@ -395,11 +445,20 @@ KServiceGroupPrivate::entries(KServiceGroup *group, bool sort, bool excludeNoDis
     KSortableList<KServiceGroup::SPtr,QByteArray> glist;
     Q_FOREACH (KSycocaEntry::Ptr p, group->d_func()->m_serviceList)
     {
+        if ( !p->isType(KST_KServiceGroup) && !p->isType(KST_KService))
+            continue;
+
         bool noDisplay = p->isType(KST_KServiceGroup) ?
                                    static_cast<KServiceGroup *>(p.data())->noDisplay() :
                                    static_cast<KService *>(p.data())->noDisplay();
         if (excludeNoDisplay && noDisplay)
            continue;
+
+        bool SuSEunimportant = p->isType(KST_KService) &&
+            static_cast<KService *>(p.data())->SuSEunimportant();
+        if (excludeSuSEunimportant && SuSEunimportant)
+            continue;
+
         // Choose the right list
         KSortableList<KServiceGroup::SPtr,QByteArray> & list = p->isType(KST_KServiceGroup) ? glist : slist;
         QString name;
@@ -435,6 +494,12 @@ KServiceGroupPrivate::entries(KServiceGroup *group, bool sort, bool excludeNoDis
         }
         list.insert(key,KServiceGroup::SPtr(p));
     }
+    return SuSEsortEntries( group, slist, glist, excludeNoDisplay, allowSeparators );
+}
+
+KServiceGroup::List
+KServiceGroupPrivate::SuSEsortEntries( KServiceGroup *group, KSortableList<KServiceGroup::SPtr,QByteArray> slist, KSortableList<KServiceGroup::SPtr,QByteArray> glist, bool excludeNoDisplay, bool allowSeparators )
+{
     // Now sort
     slist.sort();
     glist.sort();
@@ -475,6 +540,8 @@ KServiceGroupPrivate::entries(KServiceGroup *group, bool sort, bool excludeNoDis
            // TODO: This prevents duplicates
           for(KSortableList<KServiceGroup::SPtr,QByteArray>::Iterator it2 = slist.begin(); it2 != slist.end(); ++it2)
           {
+             if (!(*it2).value()->isType(KST_KService))
+                continue;
              const KService::Ptr service = KService::Ptr::staticCast( (*it2).value() );
              if (service->menuId() == item)
              {
diff --git a/kdecore/services/kservicegroup.h b/kdecore/services/kservicegroup.h
index 9fdf2b0..ee2da88 100644
--- a/kdecore/services/kservicegroup.h
+++ b/kdecore/services/kservicegroup.h
@@ -22,6 +22,7 @@
 #include <kdecore_export.h>
 #include <ksycocaentry.h>
 #include <kservice.h>
+#include <ksortablelist.h>
 
 class KBuildServiceGroupFactory;
 
@@ -174,6 +175,12 @@ public:
   void setLayoutInfo(const QStringList &layout);
 
   /**
+   * SuSE special, not part of KDE API
+   */
+  bool SuSEshortMenu() const;
+  bool SuSEgeneralDescription() const;
+
+  /**
    * @internal
    * Returns information related to the layout of services in this group.
    */
@@ -200,6 +207,13 @@ public:
   List entries(bool sorted = false);
 
   /**
+   * UNOFFICIAL SuSE special
+   */
+  void addSortOrderEntry( const char *entry );
+  KServiceGroup::List SuSEsortEntries( KSortableList<KServiceGroup::SPtr,QByteArray> slist, KSortableList<KServiceGroup::SPtr,QByteArray> glist, bool excludeNoDisplay, bool allowSeparators );
+
+
+  /**
    * options for groupEntries and serviceEntries
    */
     enum EntriesOption
diff --git a/kdecore/services/kservicegroup_p.h b/kdecore/services/kservicegroup_p.h
index 5f21497..c67b984 100644
--- a/kdecore/services/kservicegroup_p.h
+++ b/kdecore/services/kservicegroup_p.h
@@ -31,7 +31,8 @@ public:
 
     KServiceGroupPrivate(const QString &path) 
         : KSycocaEntryPrivate(path),
-          m_bNoDisplay(false), m_bShowEmptyMenu(false), m_bShowInlineHeader(false), m_bInlineAlias(false),
+          m_bNoDisplay(false), m_bShortMenu(false), m_bGeneralDescription(false),
+          m_bShowEmptyMenu(false), m_bShowInlineHeader(false), m_bInlineAlias(false),
           m_bAllowInline(false), m_inlineValue(4), m_bDeep(false), m_childCount(-1)
     {
     }
@@ -58,6 +59,13 @@ public:
 
     KServiceGroup::List
     entries(KServiceGroup *group, bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName);
+
+    /**
+     * UNOFFICIAL SuSE special
+     */
+    KServiceGroup::List SuSEentries(KServiceGroup *group, bool sort, bool excludeNoDisplay, bool allowSeparators, bool sortByGenericName, bool excludeSuSEunimportant = true);
+    KServiceGroup::List SuSEsortEntries( KServiceGroup *group, KSortableList<KServiceGroup::SPtr,QByteArray> slist, KSortableList<KServiceGroup::SPtr,QByteArray> glist, bool excludeNoDisplay, bool allowSeparators );
+
   /**
    * This function parse attributes into menu
    */
@@ -65,6 +73,8 @@ public:
 
 
     bool m_bNoDisplay : 1;
+    bool m_bShortMenu : 1;
+    bool m_bGeneralDescription : 1;
     bool m_bShowEmptyMenu : 1;
     bool m_bShowInlineHeader : 1;
     bool m_bInlineAlias : 1;