• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • tdeui
 

tdeui

khelpmenu.cpp

00001 /*
00002  * This file is part of the KDE Libraries
00003  * Copyright (C) 1999-2000 Espen Sand (espen@kde.org)
00004  *
00005  * This library is free software; you can redistribute it and/or
00006  * modify it under the terms of the GNU Library General Public
00007  * License as published by the Free Software Foundation; either
00008  * version 2 of the License, or (at your option) any later version.
00009  *
00010  * This library is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013  * Library General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU Library General Public License
00016  * along with this library; see the file COPYING.LIB.  If not, write to
00017  * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00018  * Boston, MA 02110-1301, USA.
00019  *
00020  */
00021 
00022 // I (espen) prefer that header files are included alphabetically
00023 #include <tqhbox.h>
00024 #include <tqlabel.h>
00025 #include <tqtimer.h>
00026 #include <tqtoolbutton.h>
00027 #include <tqwhatsthis.h>
00028 #include <tqwidget.h>
00029 
00030 #include <tdeaboutapplication.h>
00031 #include <tdeaboutdata.h>
00032 #include <tdeabouttde.h>
00033 #include <tdeaction.h>
00034 #include <tdeapplication.h>
00035 #include <kbugreport.h>
00036 #include <kdialogbase.h>
00037 #include <khelpmenu.h>
00038 #include <kiconloader.h>
00039 #include <tdelocale.h>
00040 #include <tdemessagebox.h>
00041 #include <tdepopupmenu.h>
00042 #include <tdestdaccel.h>
00043 #include <kstdaction.h>
00044 #include <kstandarddirs.h>
00045 
00046 #include "kswitchlanguagedialog.h"
00047 
00048 #include "config.h"
00049 #include <qxembed.h>
00050 
00051 class KHelpMenuPrivate
00052 {
00053 public:
00054     KHelpMenuPrivate():mSwitchApplicationLanguage(NULL)
00055     {
00056     }
00057     ~KHelpMenuPrivate()
00058     {
00059         delete mSwitchApplicationLanguage;
00060     }
00061 
00062     const TDEAboutData *mAboutData;
00063     KSwitchLanguageDialog *mSwitchApplicationLanguage;
00064 };
00065 
00066 KHelpMenu::KHelpMenu( TQWidget *parent, const TQString &aboutAppText,
00067               bool showWhatsThis )
00068   : TQObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
00069     d(new KHelpMenuPrivate)
00070 {
00071   mParent = parent;
00072   mAboutAppText = aboutAppText;
00073   mShowWhatsThis = showWhatsThis;
00074   d->mAboutData = 0;
00075 }
00076 
00077 KHelpMenu::KHelpMenu( TQWidget *parent, const TDEAboutData *aboutData,
00078               bool showWhatsThis, TDEActionCollection *actions )
00079   : TQObject(parent), mMenu(0), mAboutApp(0), mAboutKDE(0), mBugReport(0),
00080     d(new KHelpMenuPrivate)
00081 {
00082   mParent = parent;
00083   mShowWhatsThis = showWhatsThis;
00084 
00085   d->mAboutData = aboutData;
00086 
00087   if (!aboutData)
00088     mAboutAppText = TQString::null;
00089 
00090   if (actions)
00091   {
00092     KStdAction::helpContents(this, TQT_SLOT(appHelpActivated()), actions);
00093     if (showWhatsThis)
00094       KStdAction::whatsThis(this, TQT_SLOT(contextHelpActivated()), actions);
00095     KStdAction::reportBug(this, TQT_SLOT(reportBug()), actions);
00096     KStdAction::aboutApp(this, TQT_SLOT(aboutApplication()), actions);
00097     KStdAction::aboutKDE(this, TQT_SLOT(aboutKDE()), actions);
00098     KStdAction::switchApplicationLanguage(this, TQT_SLOT(switchApplicationLanguage()), actions);
00099   }
00100 }
00101 
00102 KHelpMenu::~KHelpMenu()
00103 {
00104   delete mMenu;
00105   delete mAboutApp;
00106   delete mAboutKDE;
00107   delete mBugReport;
00108   delete d;
00109 }
00110 
00111 
00112 TDEPopupMenu* KHelpMenu::menu()
00113 {
00114   if( !mMenu )
00115   {
00116     //
00117     // 1999-12-02 Espen Sand:
00118     // I use hardcoded menu id's here. Reason is to stay backward
00119     // compatible.
00120     //
00121     const TDEAboutData *aboutData = d->mAboutData ? d->mAboutData : TDEGlobal::instance()->aboutData();
00122     TQString appName = (aboutData)? aboutData->programName() : TQString::fromLatin1(tqApp->name());
00123 
00124     mMenu = new TDEPopupMenu();
00125     connect( mMenu, TQT_SIGNAL(destroyed()), this, TQT_SLOT(menuDestroyed()));
00126 
00127     bool need_separator = false;
00128     if (kapp->authorizeTDEAction("help_contents"))
00129     {
00130       mMenu->insertItem( BarIcon( "contents", TDEIcon::SizeSmall),
00131                      TQString(i18n( "%1 &Handbook" ).arg( appName)) ,menuHelpContents );
00132       mMenu->connectItem( menuHelpContents, this, TQT_SLOT(appHelpActivated()) );
00133       mMenu->setAccel( TDEStdAccel::shortcut(TDEStdAccel::Help), menuHelpContents );
00134       need_separator = true;
00135     }
00136 
00137     if( mShowWhatsThis && kapp->authorizeTDEAction("help_whats_this") )
00138     {
00139       TQToolButton* wtb = TQWhatsThis::whatsThisButton(0);
00140       mMenu->insertItem( wtb->iconSet(),i18n( "What's &This" ), menuWhatsThis);
00141       mMenu->connectItem( menuWhatsThis, this, TQT_SLOT(contextHelpActivated()) );
00142       delete wtb;
00143       mMenu->setAccel( SHIFT + Key_F1, menuWhatsThis );
00144       need_separator = true;
00145     }
00146 
00147     if (kapp->authorizeTDEAction("help_report_bug") && aboutData && !aboutData->bugAddress().isEmpty() )
00148     {
00149       if (need_separator)
00150         mMenu->insertSeparator();
00151       mMenu->insertItem( i18n( "&Report Bug/Request Enhancement..." ), menuReportBug );
00152       mMenu->connectItem( menuReportBug, this, TQT_SLOT(reportBug()) );
00153       need_separator = true;
00154     }
00155 
00156     if (kapp->authorizeTDEAction("switch_application_language"))
00157     {
00158       if (need_separator)
00159         mMenu->insertSeparator();
00160       mMenu->insertItem( i18n( "Switch application &language..." ), menuSwitchLanguage );
00161       mMenu->connectItem( menuSwitchLanguage, this, TQT_SLOT(switchApplicationLanguage()) );
00162       need_separator = true;
00163     }
00164     
00165     if (need_separator)
00166       mMenu->insertSeparator();
00167 
00168     if (kapp->authorizeTDEAction("help_about_app"))
00169     {
00170       mMenu->insertItem( kapp->miniIcon(),
00171         TQString(i18n( "&About %1" ).arg(appName)), menuAboutApp );
00172       mMenu->connectItem( menuAboutApp, this, TQT_SLOT( aboutApplication() ) );
00173     }
00174     
00175     if (kapp->authorizeTDEAction("help_about_kde"))
00176     {
00177       mMenu->insertItem( SmallIcon("about_kde"), i18n( "About &Trinity" ), menuAboutKDE );
00178       mMenu->connectItem( menuAboutKDE, this, TQT_SLOT( aboutKDE() ) );
00179     }
00180   }
00181 
00182   return mMenu;
00183 }
00184 
00185 
00186 
00187 void KHelpMenu::appHelpActivated()
00188 {
00189   kapp->invokeHelp();
00190 }
00191 
00192 
00193 void KHelpMenu::aboutApplication()
00194 {
00195   if (d->mAboutData)
00196   {
00197     if( !mAboutApp )
00198     {
00199       mAboutApp = new TDEAboutApplication( d->mAboutData, mParent, "about", false );
00200       connect( mAboutApp, TQT_SIGNAL(finished()), this, TQT_SLOT( dialogFinished()) );
00201     }
00202     mAboutApp->show();
00203   }
00204   else if( mAboutAppText.isEmpty() )
00205   {
00206     emit showAboutApplication();
00207   }
00208   else
00209   {
00210     if( !mAboutApp )
00211     {
00212       mAboutApp = new KDialogBase( TQString::null, // Caption is defined below
00213                    KDialogBase::Yes, KDialogBase::Yes,
00214                    KDialogBase::Yes, mParent, "about",
00215                    false, true, KStdGuiItem::ok() );
00216       connect( mAboutApp, TQT_SIGNAL(finished()), this, TQT_SLOT( dialogFinished()) );
00217 
00218       TQHBox *hbox = new TQHBox( mAboutApp );
00219       mAboutApp->setMainWidget( hbox );
00220       hbox->setSpacing(KDialog::spacingHint()*3);
00221       hbox->setMargin(KDialog::marginHint()*1);
00222 
00223       TQLabel *label1 = new TQLabel(hbox);
00224       label1->setPixmap( kapp->icon() );
00225       TQLabel *label2 = new TQLabel(hbox);
00226       label2->setText( mAboutAppText );
00227 
00228       mAboutApp->setPlainCaption( i18n("About %1").arg(kapp->caption()) );
00229       mAboutApp->disableResize();
00230     }
00231 
00232     mAboutApp->show();
00233   }
00234 }
00235 
00236 
00237 void KHelpMenu::aboutKDE()
00238 {
00239   if( !mAboutKDE )
00240   {
00241     mAboutKDE = new TDEAboutKDE( mParent, "aboutkde", false );
00242     connect( mAboutKDE, TQT_SIGNAL(finished()), this, TQT_SLOT( dialogFinished()) );
00243   }
00244   mAboutKDE->show();
00245 }
00246 
00247 
00248 void KHelpMenu::reportBug()
00249 {
00250   if( !mBugReport )
00251   {
00252     mBugReport = new KBugReport( mParent, false, d->mAboutData );
00253     connect( mBugReport, TQT_SIGNAL(finished()),this,TQT_SLOT( dialogFinished()) );
00254   }
00255   mBugReport->show();
00256 }
00257 
00258 void KHelpMenu::switchApplicationLanguage()
00259 {
00260   if ( !d->mSwitchApplicationLanguage )
00261   {
00262     d->mSwitchApplicationLanguage = new KSwitchLanguageDialog( mParent, "switchlanguagedialog", false );
00263     connect( d->mSwitchApplicationLanguage, TQT_SIGNAL(finished()), this, TQT_SLOT( dialogFinished()) );
00264   }
00265   d->mSwitchApplicationLanguage->show();
00266 }
00267 
00268 
00269 void KHelpMenu::dialogFinished()
00270 {
00271   TQTimer::singleShot( 0, this, TQT_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   if (d->mSwitchApplicationLanguage && !d->mSwitchApplicationLanguage->isVisible())
00293   {
00294     delete d->mSwitchApplicationLanguage; d->mSwitchApplicationLanguage = 0;
00295   }
00296 }
00297 
00298 
00299 void KHelpMenu::menuDestroyed()
00300 {
00301   mMenu = 0;
00302 }
00303 
00304 
00305 void KHelpMenu::contextHelpActivated()
00306 {
00307   TQWhatsThis::enterWhatsThisMode();
00308   TQWidget* w = TQApplication::widgetAt( TQCursor::pos(), true );
00309   while ( w && !w->isTopLevel() && !w->inherits("QXEmbed")  )
00310       w = w->parentWidget();
00311 #ifdef Q_WS_X11
00312    if ( w && w->inherits("QXEmbed") )
00313       (( QXEmbed*) w )->enterWhatsThisMode();
00314 #endif
00315 }
00316 
00317 void KHelpMenu::virtual_hook( int, void* )
00318 { /*BASE::virtual_hook( id, data );*/ }
00319 
00320 
00321 #include "khelpmenu.moc"

tdeui

Skip menu "tdeui"
  • Main Page
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

tdeui

Skip menu "tdeui"
  • arts
  • dcop
  • dnssd
  • interfaces
  •   kspeech
  •     interface
  •     library
  •   tdetexteditor
  • kate
  • kded
  • kdoctools
  • kimgio
  • kjs
  • libtdemid
  • libtdescreensaver
  • tdeabc
  • tdecmshell
  • tdecore
  • tdefx
  • tdehtml
  • tdeinit
  • tdeio
  •   bookmarks
  •   httpfilter
  •   kpasswdserver
  •   kssl
  •   tdefile
  •   tdeio
  •   tdeioexec
  • tdeioslave
  •   http
  • tdemdi
  •   tdemdi
  • tdenewstuff
  • tdeparts
  • tdeprint
  • tderandr
  • tderesources
  • tdespell2
  • tdesu
  • tdeui
  • tdeunittest
  • tdeutils
  • tdewallet
Generated for tdeui by doxygen 1.6.3
This website is maintained by Timothy Pearson.