Ticket #44944: correct-PreferencesAndSysTray-Menu.patch

File correct-PreferencesAndSysTray-Menu.patch, 7.3 KB (added by RJVB (René Bertin), 10 years ago)

replaces the previously attached patch

  • kdelibs-git/kdeui/actions/kaction.cpp

    diff --git kdeui/actions/kaction.cpp kdeui/actions/kaction.cpp
    index 9e8f7fb..d09aeac 100644
    KAction::KAction(QObject *parent) 
    142142  d->init(this);
    143143}
    144144
     145#ifdef Q_OS_MAC
     146
     147#include <kaboutdata.h>
     148
     149static void setTextWithCorrectMenuRole( KAction *action, const QString &text )
     150{
     151    // texts containing "config, options, setup, settings or preferences" will get PreferencesRole
     152    // from Qt unless they have a role set. We prevent that, because KDE has its own way of
     153    // defining a the application preferences menu ("Configure <appName>") which should go under the OS X Preferences menu.
     154    // But when a KAction is created with the standard preferences title ("Configure <appName>..."), this action
     155    // is set to PreferencesRole .
     156    action->setText(text);
     157    if( text.contains("config", Qt::CaseInsensitive)
     158        || text.contains("options", Qt::CaseInsensitive)
     159        || text.contains("setup", Qt::CaseInsensitive)
     160        || text.contains("settings", Qt::CaseInsensitive)
     161        || text.contains("preferences", Qt::CaseInsensitive)
     162    ){
     163        const KAboutData *aboutData = KGlobal::mainComponent().aboutData();
     164        QString prefsText = i18n( "Configure %1...", (aboutData) ? aboutData->programName() : qApp->applicationName() );
     165        if( text == prefsText || text == "&" % prefsText ){
     166            kDebug() << "### Setting QAction::PreferencesRole from" << action->menuRole() << "for menuAction with text" << text;
     167            action->setMenuRole(QAction::PreferencesRole);
     168        }
     169        else{
     170            kDebug() << "### Setting QAction::NoRole from" << action->menuRole() << "for menuAction with text" << text;
     171            action->setMenuRole(QAction::NoRole);
     172        }
     173    }
     174}
     175#endif //Q_OS_MAC
     176
    145177KAction::KAction(const QString &text, QObject *parent)
    146178  : QWidgetAction(parent), d(new KActionPrivate)
    147179{
    148180  d->init(this);
     181#ifdef Q_OS_MAC
     182  setTextWithCorrectMenuRole(this, text);
     183#else
    149184  setText(text);
     185#endif
    150186}
    151187
    152188KAction::KAction(const KIcon &icon, const QString &text, QObject *parent)
    KAction::KAction(const KIcon &icon, const QString &text, QObject *parent) 
    154190{
    155191  d->init(this);
    156192  setIcon(icon);
     193#ifdef Q_OS_MAC
     194  setTextWithCorrectMenuRole(this, text);
     195#else
    157196  setText(text);
     197#endif
    158198}
    159199
    160200KAction::~KAction()
  • kdelibs-git/kdeui/actions/kstandardaction.cpp

    diff --git kdeui/actions/kstandardaction.cpp kdeui/actions/kstandardaction.cpp
    index 7de0c6f..df61bff 100644
    KAction *create(StandardAction id, const QObject *recvr, const char *slot, QObje 
    170170      break;
    171171    }
    172172
     173    // Set the text before setting the MenuRole, as on OS X setText will do some heuristic setting of itself,
     174    // to prevent user menu items to get promoted to one of the following special roles.
     175    pAction->setText(sLabel);
     176
    173177    switch ( id ) {
    174178    case Quit:
    175179      pAction->setMenuRole(QAction::QuitRole);
    KAction *create(StandardAction id, const QObject *recvr, const char *slot, QObje 
    188192      break;
    189193    }
    190194
    191     pAction->setText(sLabel);
    192195    if (pInfo->psToolTip) {
    193196        pAction->setToolTip(i18n(pInfo->psToolTip));
    194197    }
  • kdelibs-git/kdeui/notifications/kstatusnotifieritem.cpp

    diff --git kdeui/notifications/kstatusnotifieritem.cpp kdeui/notifications/kstatusnotifieritem.cpp
    index 1b15d40..920ba27 100644
    bool KStatusNotifierItemPrivate::checkVisibility(QPoint pos, bool perform) 
    683683
    684684        return false;
    685685    }
     686#else
     687    Q_UNUSED(pos);
     688    Q_UNUSED(perform);
    686689#endif
    687690
    688691    return true;
    KStatusNotifierItemPrivate::KStatusNotifierItemPrivate(KStatusNotifierItem *item 
    722725{
    723726}
    724727
     728#ifdef Q_OS_MAC
     729#   include <kconfiggroup.h>
     730#endif
     731
    725732void KStatusNotifierItemPrivate::init(const QString &extraId)
    726733{
    727734    // Ensure that closing the last KMainWindow doesn't exit the application
    void KStatusNotifierItemPrivate::init(const QString &extraId) 
    745752
    746753    //create a default menu, just like in KSystemtrayIcon
    747754    KMenu *m = new KMenu(associatedWidget);
     755#ifdef Q_OS_MAC
     756    // emulate addTitle/setTitle by adding an inactive menu item.
     757    titleAction = new QAction( KGlobal::mainComponent().aboutData()->programName(), NULL );
     758    titleAction->setEnabled(false);
     759    titleAction->setIcon(qApp->windowIcon());
     760    titleAction->setIconVisibleInMenu(true);
     761    m->addAction( titleAction );
     762    m->addSeparator();
     763//     qDebug() << "### Added SystemTray titleAction=" << titleAction;
     764//     qDebug() << "### SystemTray for app" << qApp << "=" << KGlobal::mainComponent().aboutData()->programName()
     765//         << "/" << KGlobal::caption() << "with icon" << qApp->windowIcon().name();
     766#else
    748767    titleAction = m->addTitle(qApp->windowIcon(), KGlobal::caption());
    749768    m->setTitle(KGlobal::mainComponent().aboutData()->programName());
     769#endif
    750770    q->setContextMenu(m);
    751771
    752772    KStandardAction::quit(q, SLOT(maybeQuit()), actionCollection);
  • kdelibs-git/kdeui/widgets/kmenu.cpp

    diff --git kdeui/widgets/kmenu.cpp kdeui/widgets/kmenu.cpp
    index 7dab149..94a7751 100644
    KMenu::~KMenu() 
    167167    delete d;
    168168}
    169169
     170#ifdef Q_OS_MAC
     171void KMenu::addAction(QAction *action)
     172{
     173    if( action ){
     174        if( !action->isIconVisibleInMenu() ){
     175            action->setIcon(QIcon());
     176        }
     177        QMenu::addAction(action);
     178    }
     179}
     180
     181#   ifdef Q_NO_USING_KEYWORD
     182QAction *KMenu::addAction(const QString &text)
     183{
     184    return QMenu::addAction(text);
     185}
     186
     187QAction *KMenu::addAction(const QIcon &icon, const QString &text)
     188{
     189    return QMenu::addAction(icon,text);
     190}
     191
     192QAction *KMenu::addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut)
     193{
     194    return QMenu::addAction(text, receiver, member, shortcut);
     195}
     196
     197QAction *KMenu::addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut)
     198{
     199    return QMenu::addAction(icon, text, receiver, member, shortcut);
     200}
     201#   endif // Q_NO_USING_KEYWORD
     202#endif // Q_OS_MAC
     203
    170204QAction* KMenu::addTitle(const QString &text, QAction* before)
    171205{
    172206    return addTitle(QIcon(), text, before);
  • kdelibs-git/kdeui/widgets/kmenu.h

    diff --git kdeui/widgets/kmenu.h kdeui/widgets/kmenu.h
    index f96e263..79be594 100644
    public: 
    6060     */
    6161    ~KMenu();
    6262
     63#ifdef Q_OS_MAC
     64#   ifndef Q_NO_USING_KEYWORD
     65    using QMenu::addAction;
     66#   endif
     67    /**
     68     * Appends the action action to the menu's list of actions.
     69     * Overloaded from QMenu to force Qt to honour action->isIconVisibleInMenu().
     70     */
     71    void addAction(QAction *action);
     72#   ifdef Q_NO_USING_KEYWORD
     73    QAction *addAction(const QString &text);
     74    QAction *addAction(const QIcon &icon, const QString &text);
     75    QAction *addAction(const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
     76    QAction *addAction(const QIcon &icon, const QString &text, const QObject *receiver, const char* member, const QKeySequence &shortcut = 0);
     77#   endif //Q_NO_USING_KEYWORD
     78#endif //Q_OS_MAC
    6379    /**
    6480     * Inserts a title item with no icon.
    6581     */