00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include <qhbox.h>
00024 #include <qlabel.h>
00025 #include <qtimer.h>
00026 #include <qtoolbutton.h>
00027 #include <qwhatsthis.h>
00028 #include <qwidget.h>
00029
00030 #include <kaboutapplication.h>
00031 #include <kaboutdata.h>
00032 #include <kaboutkde.h>
00033 #include <kaction.h>
00034 #include <kapplication.h>
00035 #include <kbugreport.h>
00036 #include <kdialogbase.h>
00037 #include <khelpmenu.h>
00038 #include <kiconloader.h>
00039 #include <klocale.h>
00040 #include <kmessagebox.h>
00041 #include <kpopupmenu.h>
00042 #include <kstdaccel.h>
00043 #include <kstdaction.h>
00044 #include <kprocess.h>
00045
00046 #include "config.h"
00047 #include <qxembed.h>
00048
00049 class KHelpMenuPrivate
00050 {
00051 public:
00052 KHelpMenuPrivate()
00053 {
00054 }
00055 ~KHelpMenuPrivate()
00056 {
00057 }
00058
00059 const KAboutData *mAboutData;
00060 };
00061
00062 KHelpMenu::KHelpMenu( QWidget *parent, const QString &aboutAppText,
00063 bool showWhatsThis )
00064 : QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
00065 d(new KHelpMenuPrivate)
00066 {
00067 mParent = parent;
00068 mAboutAppText = aboutAppText;
00069 mShowWhatsThis = showWhatsThis;
00070 d->mAboutData = 0;
00071 }
00072
00073 KHelpMenu::KHelpMenu( QWidget *parent, const KAboutData *aboutData,
00074 bool showWhatsThis, KActionCollection *actions )
00075 : QObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
00076 d(new KHelpMenuPrivate)
00077 {
00078 mParent = parent;
00079 mShowWhatsThis = showWhatsThis;
00080
00081 d->mAboutData = aboutData;
00082
00083 if (!aboutData)
00084 mAboutAppText = QString::null;
00085
00086 if (actions)
00087 {
00088 KStdAction::helpContents(this, SLOT(appHelpActivated()), actions);
00089 if (showWhatsThis)
00090 KStdAction::whatsThis(this, SLOT(contextHelpActivated()), actions);
00091 KStdAction::reportBug(this, SLOT(reportBug()), actions);
00092 KStdAction::aboutApp(this, SLOT(aboutApplication()), actions);
00093 KStdAction::aboutKDE(this, SLOT(aboutKDE()), actions);
00094 KStdAction::kubuntuTranslate(this, SLOT(kubuntuTranslate()), actions);
00095 KStdAction::kubuntuGetHelpOnline(this, SLOT(kubuntuGetHelpOnline()), actions);
00096 }
00097 }
00098
00099 KHelpMenu::~KHelpMenu()
00100 {
00101 delete mMenu;
00102 delete mAboutApp;
00103 delete mAboutKDE;
00104 delete mBugReport;
00105 delete d;
00106 }
00107
00108
00109 KPopupMenu* KHelpMenu::menu()
00110 {
00111 if( !mMenu )
00112 {
00113
00114
00115
00116
00117
00118 const KAboutData *aboutData = d->mAboutData ? d->mAboutData : KGlobal::instance()->aboutData();
00119 QString appName = (aboutData)? aboutData->programName() : QString::fromLatin1(qApp->name());
00120
00121 mMenu = new KPopupMenu();
00122 connect( mMenu, SIGNAL(destroyed()), this, SLOT(menuDestroyed()));
00123
00124 bool need_separator = false;
00125 if (kapp->authorizeKAction("help_contents"))
00126 {
00127 mMenu->insertItem( BarIcon( "contents", KIcon::SizeSmall),
00128 i18n( "%1 &Handbook" ).arg( appName) ,menuHelpContents );
00129 mMenu->connectItem( menuHelpContents, this, SLOT(appHelpActivated()) );
00130 mMenu->setAccel( KStdAccel::shortcut(KStdAccel::Help), menuHelpContents );
00131 need_separator = true;
00132 }
00133
00134 if( mShowWhatsThis && kapp->authorizeKAction("help_whats_this") )
00135 {
00136 QToolButton* wtb = QWhatsThis::whatsThisButton(0);
00137 mMenu->insertItem( wtb->iconSet(),i18n( "What's &This" ), menuWhatsThis);
00138 mMenu->connectItem( menuWhatsThis, this, SLOT(contextHelpActivated()) );
00139 delete wtb;
00140 mMenu->setAccel( SHIFT + Key_F1, menuWhatsThis );
00141 need_separator = true;
00142 }
00143
00144 if (kapp->authorizeKAction("help_report_bug") && aboutData && !aboutData->bugAddress().isEmpty() )
00145 {
00146 if (need_separator)
00147 mMenu->insertSeparator();
00148 mMenu->insertItem( i18n( "&Report Bug..." ), menuReportBug );
00149 mMenu->connectItem( menuReportBug, this, SLOT(reportBug()) );
00150 need_separator = true;
00151 }
00152
00153 if (need_separator)
00154 mMenu->insertSeparator();
00155
00156 mMenu->insertItem( SmallIcon("launchpad"), i18n( "&Get Help Online" ), this, SLOT(kubuntuGetHelpOnline()) );
00157 mMenu->insertItem( SmallIcon("locale"), i18n( "&Translate this Application" ), this, SLOT(kubuntuTranslate()) );
00158 mMenu->insertSeparator();
00159
00160 if (kapp->authorizeKAction("help_about_app"))
00161 {
00162 mMenu->insertItem( kapp->miniIcon(),
00163 i18n( "&About %1" ).arg(appName), menuAboutApp );
00164 mMenu->connectItem( menuAboutApp, this, SLOT( aboutApplication() ) );
00165 }
00166
00167 if (kapp->authorizeKAction("help_about_kde"))
00168 {
00169 mMenu->insertItem( SmallIcon("about_kde"), i18n( "About &KDE" ), menuAboutKDE );
00170 mMenu->connectItem( menuAboutKDE, this, SLOT( aboutKDE() ) );
00171 }
00172 }
00173
00174 return mMenu;
00175 }
00176
00177
00178
00179 void KHelpMenu::appHelpActivated()
00180 {
00181 kapp->invokeHelp();
00182 }
00183
00184
00185 void KHelpMenu::aboutApplication()
00186 {
00187 if (d->mAboutData)
00188 {
00189 if( !mAboutApp )
00190 {
00191 mAboutApp = new KAboutApplication( d->mAboutData, mParent, "about", false );
00192 connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
00193 }
00194 mAboutApp->show();
00195 }
00196 else if( mAboutAppText.isEmpty() )
00197 {
00198 emit showAboutApplication();
00199 }
00200 else
00201 {
00202 if( !mAboutApp )
00203 {
00204 mAboutApp = new KDialogBase( QString::null,
00205 KDialogBase::Yes, KDialogBase::Yes,
00206 KDialogBase::Yes, mParent, "about",
00207 false, true, KStdGuiItem::ok() );
00208 connect( mAboutApp, SIGNAL(finished()), this, SLOT( dialogFinished()) );
00209
00210 QHBox *hbox = new QHBox( mAboutApp );
00211 mAboutApp->setMainWidget( hbox );
00212 hbox->setSpacing(KDialog::spacingHint()*3);
00213 hbox->setMargin(KDialog::marginHint()*1);
00214
00215 QLabel *label1 = new QLabel(hbox);
00216 label1->setPixmap( kapp->icon() );
00217 QLabel *label2 = new QLabel(hbox);
00218 label2->setText( mAboutAppText );
00219
00220 mAboutApp->setPlainCaption( i18n("About %1").arg(kapp->caption()) );
00221 mAboutApp->disableResize();
00222 }
00223
00224 mAboutApp->show();
00225 }
00226 }
00227
00228
00229 void KHelpMenu::kubuntuGetHelpOnline()
00230 {
00231 const KAboutData *aboutData = KGlobal::instance()->aboutData();
00232 QString path = KStandardDirs::findExe( aboutData->appName() );
00233 KProcess *proc = new KProcess;
00234 *proc << "launchpad-integration" << "--file" << path << "--info";
00235 proc->start(KProcess::DontCare);
00236 }
00237
00238 void KHelpMenu::kubuntuTranslate()
00239 {
00240 const KAboutData *aboutData = KGlobal::instance()->aboutData();
00241 QString path = KStandardDirs::findExe( aboutData->appName() );
00242 KProcess *proc = new KProcess;
00243 *proc << "launchpad-integration" << "--file" << path << "--translate";
00244 proc->start(KProcess::DontCare);
00245 }
00246
00247 void KHelpMenu::aboutKDE()
00248 {
00249 if( !mAboutKDE )
00250 {
00251 mAboutKDE = new KAboutKDE( mParent, "aboutkde", false );
00252 connect( mAboutKDE, SIGNAL(finished()), this, SLOT( dialogFinished()) );
00253 }
00254 mAboutKDE->show();
00255 }
00256
00257
00258 void KHelpMenu::reportBug()
00259 {
00260 if( !mBugReport )
00261 {
00262 mBugReport = new KBugReport( mParent, false, d->mAboutData );
00263 connect( mBugReport, SIGNAL(finished()),this,SLOT( dialogFinished()) );
00264 }
00265 mBugReport->show();
00266 }
00267
00268
00269 void KHelpMenu::dialogFinished()
00270 {
00271 QTimer::singleShot( 0, this, SLOT(timerExpired()) );
00272 }
00273
00274
00275 void KHelpMenu::timerExpired()
00276 {
00277 if( mAboutKDE && !mAboutKDE->isVisible() )
00278 {
00279 delete mAboutKDE; mAboutKDE = 0;
00280 }
00281
00282 if( mBugReport && !mBugReport->isVisible() )
00283 {
00284 delete mBugReport; mBugReport = 0;
00285 }
00286
00287 if( mAboutApp && !mAboutApp->isVisible() )
00288 {
00289 delete mAboutApp; mAboutApp = 0;
00290 }
00291 }
00292
00293
00294 void KHelpMenu::menuDestroyed()
00295 {
00296 mMenu = 0;
00297 }
00298
00299
00300 void KHelpMenu::contextHelpActivated()
00301 {
00302 QWhatsThis::enterWhatsThisMode();
00303 QWidget* w = QApplication::widgetAt( QCursor::pos(), true );
00304 while ( w && !w->isTopLevel() && !w->inherits("QXEmbed") )
00305 w = w->parentWidget();
00306 #ifdef Q_WS_X11
00307 if ( w && w->inherits("QXEmbed") )
00308 (( QXEmbed*) w )->enterWhatsThisMode();
00309 #endif
00310 }
00311
00312 void KHelpMenu::virtual_hook( int, void* )
00313 { }
00314
00315
00316 #include "khelpmenu.moc"