2014-11-13 01:04:59 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the KDE Libraries
|
|
|
|
* Copyright (C) 1999-2000 Espen Sand (espen@kde.org)
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Library General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Library General Public License
|
|
|
|
* along with this library; see the file COPYING.LIB. If not, write to
|
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// I (espen) prefer that header files are included alphabetically
|
|
|
|
|
|
|
|
#include "khelpmenu.h"
|
2023-08-29 08:18:25 +03:00
|
|
|
#include "kaboutapplicationdialog.h"
|
|
|
|
#include "kaboutdata.h"
|
|
|
|
#include "kaboutkdedialog_p.h"
|
|
|
|
#include "kaction.h"
|
|
|
|
#include "kactioncollection.h"
|
|
|
|
#include "kapplication.h"
|
|
|
|
#include "kdialog.h"
|
|
|
|
#include "kguiitem.h"
|
|
|
|
#include "khbox.h"
|
|
|
|
#include "kiconloader.h"
|
|
|
|
#include "klocale.h"
|
|
|
|
#include "kmenu.h"
|
|
|
|
#include "kstandardshortcut.h"
|
|
|
|
#include "kstandardaction.h"
|
|
|
|
#include "kstandardguiitem.h"
|
|
|
|
#include "kswitchlanguagedialog_p.h"
|
|
|
|
#include "ktoolinvocation.h"
|
|
|
|
#include "kstandarddirs.h"
|
|
|
|
#include "kpixmapwidget.h"
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
#include <QtCore/QTimer>
|
|
|
|
#include <QtGui/QLabel>
|
|
|
|
#include <QtGui/QWidget>
|
|
|
|
#include <QtGui/QWhatsThis>
|
|
|
|
|
|
|
|
#include <config.h>
|
|
|
|
#ifdef Q_WS_X11
|
2015-08-11 05:56:07 +03:00
|
|
|
#include <QtGui/qx11embed_x11.h>
|
2014-11-13 01:04:59 +02:00
|
|
|
#endif
|
|
|
|
|
2014-11-29 23:03:51 +00:00
|
|
|
#include <kglobalsettings.h>
|
2014-11-25 23:25:27 +00:00
|
|
|
|
2014-11-13 01:04:59 +02:00
|
|
|
using namespace KDEPrivate;
|
|
|
|
|
|
|
|
class KHelpMenuPrivate
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
KHelpMenuPrivate()
|
2022-11-21 04:37:27 +02:00
|
|
|
: mSwitchApplicationLanguage(0),
|
|
|
|
mActionsCreated(false),
|
2014-11-13 01:04:59 +02:00
|
|
|
mSwitchApplicationLanguageAction(0)
|
|
|
|
{
|
|
|
|
mMenu = 0;
|
|
|
|
mAboutApp = 0;
|
|
|
|
mAboutKDE = 0;
|
|
|
|
mWhatsThisAction = 0;
|
|
|
|
mReportBugAction = 0;
|
|
|
|
mAboutAppAction = 0;
|
|
|
|
mAboutKDEAction = 0;
|
|
|
|
}
|
|
|
|
~KHelpMenuPrivate()
|
|
|
|
{
|
|
|
|
delete mMenu;
|
|
|
|
delete mAboutApp;
|
|
|
|
delete mAboutKDE;
|
|
|
|
delete mSwitchApplicationLanguage;
|
|
|
|
}
|
|
|
|
|
|
|
|
void createActions(KHelpMenu* q);
|
|
|
|
|
|
|
|
KMenu *mMenu;
|
|
|
|
KDialog *mAboutApp;
|
|
|
|
KAboutKdeDialog *mAboutKDE;
|
|
|
|
KSwitchLanguageDialog *mSwitchApplicationLanguage;
|
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
// TODO evaluate if we use static_cast<QWidget*>(parent()) instead of mParent to win that bit of memory
|
2014-11-13 01:04:59 +02:00
|
|
|
QWidget *mParent;
|
|
|
|
QString mAboutAppText;
|
|
|
|
|
|
|
|
bool mShowWhatsThis;
|
|
|
|
bool mActionsCreated;
|
|
|
|
|
2014-11-18 17:27:55 +00:00
|
|
|
KAction *mWhatsThisAction;
|
2014-11-13 01:04:59 +02:00
|
|
|
QAction *mReportBugAction, *mSwitchApplicationLanguageAction, *mAboutAppAction, *mAboutKDEAction;
|
|
|
|
|
|
|
|
const KAboutData *mAboutData;
|
|
|
|
};
|
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
KHelpMenu::KHelpMenu(QWidget *parent, const QString &aboutAppText,
|
|
|
|
bool showWhatsThis)
|
|
|
|
: QObject(parent),
|
|
|
|
d(new KHelpMenuPrivate)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
d->mAboutAppText = aboutAppText;
|
|
|
|
d->mShowWhatsThis = showWhatsThis;
|
|
|
|
d->mParent = parent;
|
|
|
|
d->mAboutData = 0;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
KHelpMenu::KHelpMenu(QWidget *parent, const KAboutData *aboutData,
|
|
|
|
bool showWhatsThis, KActionCollection *actions)
|
|
|
|
: QObject(parent),
|
|
|
|
d(new KHelpMenuPrivate)
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
d->mShowWhatsThis = showWhatsThis;
|
|
|
|
d->mParent = parent;
|
|
|
|
d->mAboutData = aboutData;
|
2014-11-13 01:04:59 +02:00
|
|
|
|
|
|
|
if (actions) {
|
|
|
|
d->createActions(this);
|
2022-11-21 04:37:27 +02:00
|
|
|
if (d->mWhatsThisAction) {
|
2014-11-13 01:04:59 +02:00
|
|
|
actions->addAction(d->mWhatsThisAction->objectName(), d->mWhatsThisAction);
|
2022-11-21 04:37:27 +02:00
|
|
|
}
|
|
|
|
if (d->mReportBugAction) {
|
2014-11-13 01:04:59 +02:00
|
|
|
actions->addAction(d->mReportBugAction->objectName(), d->mReportBugAction);
|
2022-11-21 04:37:27 +02:00
|
|
|
}
|
|
|
|
if (d->mSwitchApplicationLanguageAction) {
|
2014-11-13 01:04:59 +02:00
|
|
|
actions->addAction(d->mSwitchApplicationLanguageAction->objectName(), d->mSwitchApplicationLanguageAction);
|
2022-11-21 04:37:27 +02:00
|
|
|
}
|
|
|
|
if (d->mAboutAppAction) {
|
2014-11-13 01:04:59 +02:00
|
|
|
actions->addAction(d->mAboutAppAction->objectName(), d->mAboutAppAction);
|
2022-11-21 04:37:27 +02:00
|
|
|
}
|
|
|
|
if (d->mAboutKDEAction) {
|
2014-11-13 01:04:59 +02:00
|
|
|
actions->addAction(d->mAboutKDEAction->objectName(), d->mAboutKDEAction);
|
2022-11-21 04:37:27 +02:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
KHelpMenu::~KHelpMenu()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
delete d;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KHelpMenuPrivate::createActions(KHelpMenu* q)
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
if (mActionsCreated) {
|
2014-11-13 01:04:59 +02:00
|
|
|
return;
|
2022-11-21 04:37:27 +02:00
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
mActionsCreated = true;
|
|
|
|
|
2015-05-19 05:23:35 +00:00
|
|
|
if (mShowWhatsThis) {
|
2014-11-13 01:04:59 +02:00
|
|
|
mWhatsThisAction = KStandardAction::whatsThis(q, SLOT(contextHelpActivated()), q);
|
|
|
|
}
|
|
|
|
|
|
|
|
const KAboutData *aboutData = mAboutData ? mAboutData : KGlobal::mainComponent().aboutData();
|
2015-05-19 05:23:35 +00:00
|
|
|
if (aboutData && !aboutData->bugAddress().isEmpty()) {
|
2014-11-13 01:04:59 +02:00
|
|
|
mReportBugAction = KStandardAction::reportBug(q, SLOT(reportBug()), q);
|
|
|
|
}
|
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
if ((KGlobal::dirs()->findAllResources("locale", QString::fromLatin1("l10n/*/entry.desktop"))).count() > 0) {
|
2015-05-19 05:23:35 +00:00
|
|
|
mSwitchApplicationLanguageAction = KStandardAction::create(KStandardAction::SwitchApplicationLanguage, q, SLOT(switchApplicationLanguage()), q);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2015-05-19 05:23:35 +00:00
|
|
|
mAboutAppAction = KStandardAction::aboutApp(q, SLOT(aboutApplication()), q);
|
|
|
|
mAboutKDEAction = KStandardAction::aboutKDE(q, SLOT(aboutKDE()), q);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Used in the non-xml-gui case, like kfind or ksnapshot's help button.
|
|
|
|
KMenu* KHelpMenu::menu()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
if (!d->mMenu) {
|
|
|
|
d->mMenu = new KMenu();
|
|
|
|
connect(d->mMenu, SIGNAL(destroyed()), this, SLOT(menuDestroyed()));
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
d->mMenu->setTitle(i18n("&Help"));
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
d->createActions(this);
|
2014-11-13 01:04:59 +02:00
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
bool need_separator = false;
|
|
|
|
if (d->mWhatsThisAction) {
|
|
|
|
d->mMenu->addAction(d->mWhatsThisAction);
|
|
|
|
need_separator = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mReportBugAction) {
|
|
|
|
if (need_separator) {
|
|
|
|
d->mMenu->addSeparator();
|
|
|
|
}
|
|
|
|
d->mMenu->addAction(d->mReportBugAction);
|
2014-11-13 01:04:59 +02:00
|
|
|
need_separator = true;
|
2022-11-21 04:37:27 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mSwitchApplicationLanguageAction) {
|
|
|
|
if (need_separator) {
|
|
|
|
d->mMenu->addSeparator();
|
|
|
|
}
|
|
|
|
d->mMenu->addAction(d->mSwitchApplicationLanguageAction);
|
|
|
|
need_separator = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (need_separator) {
|
|
|
|
d->mMenu->addSeparator();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mAboutAppAction) {
|
|
|
|
d->mMenu->addAction(d->mAboutAppAction);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mAboutKDEAction) {
|
|
|
|
d->mMenu->addAction(d->mAboutKDEAction);
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
return d->mMenu;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
2022-11-21 04:37:27 +02:00
|
|
|
QAction *KHelpMenu::action(MenuId id) const
|
2014-11-13 01:04:59 +02:00
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
switch (id) {
|
|
|
|
case menuWhatsThis: {
|
|
|
|
return d->mWhatsThisAction;
|
|
|
|
}
|
|
|
|
case menuReportBug: {
|
|
|
|
return d->mReportBugAction;
|
|
|
|
}
|
|
|
|
case menuSwitchLanguage: {
|
|
|
|
return d->mSwitchApplicationLanguageAction;
|
|
|
|
}
|
|
|
|
case menuAboutApp: {
|
|
|
|
return d->mAboutAppAction;
|
|
|
|
}
|
|
|
|
case menuAboutKDE: {
|
|
|
|
return d->mAboutKDEAction;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KHelpMenu::appHelpActivated()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
KToolInvocation::invokeHelp();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KHelpMenu::aboutApplication()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
if (receivers(SIGNAL(showAboutApplication())) > 0) {
|
|
|
|
emit showAboutApplication();
|
|
|
|
} else if (d->mAboutData) {
|
|
|
|
if (!d->mAboutApp) {
|
|
|
|
d->mAboutApp = new KAboutApplicationDialog(d->mAboutData, d->mParent);
|
|
|
|
connect(d->mAboutApp, SIGNAL(finished()), this, SLOT(dialogFinished()));
|
|
|
|
}
|
|
|
|
d->mAboutApp->show();
|
|
|
|
} else {
|
|
|
|
if (!d->mAboutApp) {
|
|
|
|
d->mAboutApp = new KDialog(d->mParent, Qt::Dialog);
|
|
|
|
d->mAboutApp->setCaption(i18n("About %1", KGlobal::caption()));
|
|
|
|
d->mAboutApp->setButtons(KDialog::Yes);
|
|
|
|
d->mAboutApp->setObjectName("about");
|
|
|
|
d->mAboutApp->setButtonText( KDialog::Yes, KStandardGuiItem::ok().text());
|
|
|
|
d->mAboutApp->setDefaultButton( KDialog::Yes );
|
|
|
|
d->mAboutApp->setEscapeButton( KDialog::Yes );
|
|
|
|
connect(d->mAboutApp, SIGNAL(finished()), this, SLOT(dialogFinished()));
|
|
|
|
|
|
|
|
KHBox *hbox = new KHBox(d->mAboutApp);
|
|
|
|
d->mAboutApp->setMainWidget(hbox);
|
|
|
|
hbox->setSpacing(KDialog::spacingHint() * 3);
|
|
|
|
hbox->setMargin(KDialog::marginHint() * 1);
|
|
|
|
|
2023-08-29 08:18:25 +03:00
|
|
|
KPixmapWidget *pixmap1 = new KPixmapWidget(hbox);
|
2022-11-21 04:37:27 +02:00
|
|
|
|
|
|
|
int size = IconSize(KIconLoader::Dialog);
|
2023-08-29 08:18:25 +03:00
|
|
|
pixmap1->setPixmap(qApp->windowIcon().pixmap(size,size));
|
2022-11-21 04:37:27 +02:00
|
|
|
QLabel *label2 = new QLabel(hbox);
|
|
|
|
label2->setText(d->mAboutAppText);
|
|
|
|
}
|
|
|
|
d->mAboutApp->show();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void KHelpMenu::aboutKDE()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
if (!d->mAboutKDE) {
|
|
|
|
d->mAboutKDE = new KAboutKdeDialog(d->mParent);
|
|
|
|
connect(d->mAboutKDE, SIGNAL(finished()), this, SLOT(dialogFinished()));
|
|
|
|
}
|
|
|
|
d->mAboutKDE->show();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KHelpMenu::reportBug()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
KToolInvocation::invokeBrowser(KDE_BUG_REPORT_URL);
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KHelpMenu::switchApplicationLanguage()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
if (!d->mSwitchApplicationLanguage) {
|
|
|
|
d->mSwitchApplicationLanguage = new KSwitchLanguageDialog(d->mParent);
|
|
|
|
connect(d->mSwitchApplicationLanguage, SIGNAL(finished()), this, SLOT(dialogFinished()));
|
|
|
|
}
|
|
|
|
d->mSwitchApplicationLanguage->show();
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void KHelpMenu::dialogFinished()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
QTimer::singleShot(0, this, SLOT(timerExpired()));
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KHelpMenu::timerExpired()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
if (d->mAboutKDE && !d->mAboutKDE->isVisible()) {
|
|
|
|
delete d->mAboutKDE;
|
|
|
|
d->mAboutKDE = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mSwitchApplicationLanguage && !d->mSwitchApplicationLanguage->isVisible()) {
|
|
|
|
delete d->mSwitchApplicationLanguage;
|
|
|
|
d->mSwitchApplicationLanguage = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (d->mAboutApp && !d->mAboutApp->isVisible()) {
|
|
|
|
delete d->mAboutApp;
|
|
|
|
d->mAboutApp = 0;
|
|
|
|
}
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KHelpMenu::menuDestroyed()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
d->mMenu = 0;
|
2014-11-13 01:04:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void KHelpMenu::contextHelpActivated()
|
|
|
|
{
|
2022-11-21 04:37:27 +02:00
|
|
|
QWhatsThis::enterWhatsThisMode();
|
|
|
|
QWidget* w = QApplication::widgetAt( QCursor::pos() );
|
2014-11-13 01:04:59 +02:00
|
|
|
#ifdef Q_WS_X11
|
2022-11-21 04:37:27 +02:00
|
|
|
while ( w && !w->isTopLevel() && !qobject_cast<QX11EmbedWidget*>(w) )
|
|
|
|
w = w->parentWidget();
|
2014-11-13 01:04:59 +02:00
|
|
|
#warning how to enter whats this mode for a QX11EmbedWidget?
|
2022-11-21 04:37:27 +02:00
|
|
|
// if ( w && qobject_cast<QX11EmbedWidget*>(w) )
|
|
|
|
// (( QX11EmbedWidget*) w )->enterWhatsThisMode();
|
2014-11-13 01:04:59 +02:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2015-02-27 07:40:26 +00:00
|
|
|
#include "moc_khelpmenu.cpp"
|