From 71abba5631126445560d6ab309a51c28745a0b74 Mon Sep 17 00:00:00 2001 From: Timothy Pearson Date: Fri, 15 Feb 2013 23:21:33 -0600 Subject: Fix prior commit --- tdeui/kmenubar.cpp | 571 ----------------------- tdeui/kmenubar.h | 114 ----- tdeui/kmessagebox.cpp | 1071 ------------------------------------------- tdeui/kmessagebox.h | 1166 ----------------------------------------------- tdeui/tdemenubar.cpp | 571 +++++++++++++++++++++++ tdeui/tdemenubar.h | 114 +++++ tdeui/tdemessagebox.cpp | 1071 +++++++++++++++++++++++++++++++++++++++++++ tdeui/tdemessagebox.h | 1166 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 2922 insertions(+), 2922 deletions(-) delete mode 100644 tdeui/kmenubar.cpp delete mode 100644 tdeui/kmenubar.h delete mode 100644 tdeui/kmessagebox.cpp delete mode 100644 tdeui/kmessagebox.h create mode 100644 tdeui/tdemenubar.cpp create mode 100644 tdeui/tdemenubar.h create mode 100644 tdeui/tdemessagebox.cpp create mode 100644 tdeui/tdemessagebox.h (limited to 'tdeui') diff --git a/tdeui/kmenubar.cpp b/tdeui/kmenubar.cpp deleted file mode 100644 index 0a5fe0188..000000000 --- a/tdeui/kmenubar.cpp +++ /dev/null @@ -1,571 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997, 1998, 1999, 2000 Sven Radej (radej@kde.org) - Copyright (C) 1997, 1998, 1999, 2000 Matthias Ettrich (ettrich@kde.org) - Copyright (C) 1999, 2000 Daniel "Mosfet" Duley (mosfet@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. - */ - - -#ifndef INCLUDE_MENUITEM_DEF -#define INCLUDE_MENUITEM_DEF -#endif - -#include "config.h" -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#ifdef Q_WS_X11 -#include -#include -#include - -#include -#include -#include - -#ifndef None -#define None 0L -#endif -#endif - -/* - - Toplevel menubar (not for the fallback size handling done by itself): - - should not alter position or set strut - - every toplevel must have at most one matching topmenu - - embedder won't allow shrinking below a certain size - - must have WM_TRANSIENT_FOR pointing the its mainwindow - - the exception is desktop's menubar, which can be transient for root window - because of using root window as the desktop window - - Fitts' Law - -*/ - -class KMenuBar::KMenuBarPrivate -{ -public: - KMenuBarPrivate() - : forcedTopLevel( false ), - topLevel( false ), - wasTopLevel( false ), -#ifdef Q_WS_X11 - selection( NULL ), -#endif - min_size( 0, 0 ) - { - } - ~KMenuBarPrivate() - { -#ifdef Q_WS_X11 - delete selection; -#endif - } - bool forcedTopLevel; - bool topLevel; - bool wasTopLevel; // when TLW is fullscreen, remember state - int frameStyle; // only valid in toplevel mode - int lineWidth; // dtto - int margin; // dtto - bool fallback_mode; // dtto -#ifdef Q_WS_X11 - TDESelectionWatcher* selection; -#endif - TQTimer selection_timer; - TQSize min_size; - static Atom makeSelectionAtom(); -}; - -#ifdef Q_WS_X11 -static Atom selection_atom = None; -static Atom msg_type_atom = None; - -static -void initAtoms() -{ - char nm[ 100 ]; - sprintf( nm, "_KDE_TOPMENU_OWNER_S%d", DefaultScreen( tqt_xdisplay())); - char nm2[] = "_KDE_TOPMENU_MINSIZE"; - char* names[ 2 ] = { nm, nm2 }; - Atom atoms[ 2 ]; - XInternAtoms( tqt_xdisplay(), names, 2, False, atoms ); - selection_atom = atoms[ 0 ]; - msg_type_atom = atoms[ 1 ]; -} -#endif - -Atom KMenuBar::KMenuBarPrivate::makeSelectionAtom() -{ -#ifdef Q_WS_X11 - if( selection_atom == None ) - initAtoms(); - return selection_atom; -#else - return 0; -#endif -} - -KMenuBar::KMenuBar(TQWidget *parent, const char *name) - : TQMenuBar(parent, name) -{ -#ifdef Q_WS_X11 - QXEmbed::initialize(); -#endif - d = new KMenuBarPrivate; - connect( &d->selection_timer, TQT_SIGNAL( timeout()), - this, TQT_SLOT( selectionTimeout())); - - connect( tqApp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( updateFallbackSize())); - - if ( kapp ) - // toolbarAppearanceChanged(int) is sent when changing macstyle - connect( kapp, TQT_SIGNAL(toolbarAppearanceChanged(int)), - this, TQT_SLOT(slotReadConfig())); - - slotReadConfig(); -} - -KMenuBar::~KMenuBar() -{ - delete d; -} - -void KMenuBar::setTopLevelMenu(bool top_level) -{ - d->forcedTopLevel = top_level; - setTopLevelMenuInternal( top_level ); -} - -void KMenuBar::setTopLevelMenuInternal(bool top_level) -{ - if (d->forcedTopLevel) - top_level = true; - - d->wasTopLevel = top_level; - if( parentWidget() - && parentWidget()->topLevelWidget()->isFullScreen()) - top_level = false; - - if ( isTopLevelMenu() == top_level ) - return; - d->topLevel = top_level; - if ( isTopLevelMenu() ) - { -#ifdef Q_WS_X11 - d->selection = new TDESelectionWatcher( KMenuBarPrivate::makeSelectionAtom(), - DefaultScreen( tqt_xdisplay())); - connect( d->selection, TQT_SIGNAL( newOwner( Window )), - this, TQT_SLOT( updateFallbackSize())); - connect( d->selection, TQT_SIGNAL( lostOwner()), - this, TQT_SLOT( updateFallbackSize())); -#endif - d->frameStyle = frameStyle(); - d->lineWidth = lineWidth(); - d->margin = margin(); - d->fallback_mode = false; - bool wasShown = !isHidden(); - reparent( parentWidget(), (WFlags)(WType_TopLevel | WStyle_Tool | WStyle_Customize | WStyle_NoBorder), TQPoint(0,0), false ); -#ifdef Q_WS_X11 - KWin::setType( winId(), NET::TopMenu ); - if( parentWidget()) - XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId()); -#endif - TQMenuBar::setFrameStyle( NoFrame ); - TQMenuBar::setLineWidth( 0 ); - TQMenuBar::setMargin( 0 ); - updateFallbackSize(); - d->min_size = TQSize( 0, 0 ); - if( parentWidget() && !parentWidget()->isTopLevel()) - setShown( parentWidget()->isVisible()); - else if ( wasShown ) - show(); - } else - { -#ifdef Q_WS_X11 - delete d->selection; - d->selection = NULL; -#endif - setBackgroundMode( PaletteButton ); - setFrameStyle( d->frameStyle ); - setLineWidth( d->lineWidth ); - setMargin( d->margin ); - setMinimumSize( 0, 0 ); - setMaximumSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX ); - updateMenuBarSize(); - if ( parentWidget() ) - reparent( parentWidget(), TQPoint(0,0), !isHidden()); - } -} - -bool KMenuBar::isTopLevelMenu() const -{ - return d->topLevel; -} - -// KDE4 remove -void KMenuBar::show() -{ - TQMenuBar::show(); -} - -void KMenuBar::slotReadConfig() -{ - TDEConfig *config = TDEGlobal::config(); - TDEConfigGroupSaver saver( config, "KDE" ); - setTopLevelMenuInternal( config->readBoolEntry( "macStyle", false ) ); -} - -bool KMenuBar::eventFilter(TQObject *obj, TQEvent *ev) -{ - if ( d->topLevel ) - { - if ( parentWidget() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget()->topLevelWidget()) ) - { - if( ev->type() == TQEvent::Resize ) - return false; // ignore resizing of parent, TQMenuBar would try to adjust size - if ( ev->type() == TQEvent::Accel || ev->type() == TQEvent::AccelAvailable ) - { - if ( TQApplication::sendEvent( topLevelWidget(), ev ) ) - return true; - } - if(ev->type() == TQEvent::ShowFullScreen ) - // will update the state properly - setTopLevelMenuInternal( d->topLevel ); - } - if( parentWidget() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget()) && ev->type() == TQEvent::Reparent ) - { -#ifdef Q_WS_X11 - XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId()); -#else - //TODO: WIN32? -#endif - setShown( parentWidget()->isTopLevel() || parentWidget()->isVisible()); - } - if( parentWidget() && !parentWidget()->isTopLevel() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget())) - { // if the parent is not toplevel, KMenuBar needs to match its visibility status - if( ev->type() == TQEvent::Show ) - { -#ifdef Q_WS_X11 - XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId()); -#else - //TODO: WIN32? -#endif - show(); - } - if( ev->type() == TQEvent::Hide ) - hide(); - } - } - else - { - if( parentWidget() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget()->topLevelWidget())) - { - if( ev->type() == TQEvent::WindowStateChange - && !parentWidget()->topLevelWidget()->isFullScreen() ) - setTopLevelMenuInternal( d->wasTopLevel ); - } - } - return TQMenuBar::eventFilter( obj, ev ); -} - -// KDE4 remove -void KMenuBar::showEvent( TQShowEvent *e ) -{ - TQMenuBar::showEvent(e); -} - -void KMenuBar::updateFallbackSize() -{ - if( !d->topLevel ) - return; -#ifdef Q_WS_X11 - if( d->selection->owner() != None ) -#endif - { // somebody is managing us, don't mess anything, undo changes - // done in fallback mode if needed - d->selection_timer.stop(); - if( d->fallback_mode ) - { - d->fallback_mode = false; - KWin::setStrut( winId(), 0, 0, 0, 0 ); - setMinimumSize( 0, 0 ); - setMaximumSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX ); - updateMenuBarSize(); - } - return; - } - if( d->selection_timer.isActive()) - return; - d->selection_timer.start( 100, true ); -} - -void KMenuBar::selectionTimeout() -{ // nobody is managing us, handle resizing - if ( d->topLevel ) - { - d->fallback_mode = true; // KMenuBar is handling its position itself - TDEConfigGroup xineramaConfig(TDEGlobal::config(),"Xinerama"); - int screen = xineramaConfig.readNumEntry("MenubarScreen", - TQApplication::desktop()->screenNumber(TQPoint(0,0)) ); - TQRect area; - if (kapp->desktop()->numScreens() < 2) - area = kapp->desktop()->geometry(); - else - area = kapp->desktop()->screenGeometry(screen); - int margin = 0; - move(area.left() - margin, area.top() - margin); - setFixedSize(area.width() + 2* margin , heightForWidth( area.width() + 2 * margin ) ); -#ifdef Q_WS_X11 - int strut_height = height() - margin; - if( strut_height < 0 ) - strut_height = 0; - KWin::setStrut( winId(), 0, 0, strut_height, 0 ); -#endif - } -} - -int KMenuBar::block_resize = 0; - -void KMenuBar::resizeEvent( TQResizeEvent *e ) -{ - if( e->spontaneous() && d->topLevel && !d->fallback_mode ) - { - ++block_resize; // do not respond with configure request to ConfigureNotify event - TQMenuBar::resizeEvent(e); // to avoid possible infinite loop - --block_resize; - } - else - TQMenuBar::resizeEvent(e); -} - -void KMenuBar::setGeometry( const TQRect& r ) -{ - setGeometry( r.x(), r.y(), r.width(), r.height() ); -} - -void KMenuBar::setGeometry( int x, int y, int w, int h ) -{ - if( block_resize > 0 ) - { - move( x, y ); - return; - } - checkSize( w, h ); - if( geometry() != TQRect( x, y, w, h )) - TQMenuBar::setGeometry( x, y, w, h ); -} - -void KMenuBar::resize( int w, int h ) -{ - if( block_resize > 0 ) - return; - checkSize( w, h ); - if( size() != TQSize( w, h )) - TQMenuBar::resize( w, h ); -// kdDebug() << "RS:" << w << ":" << h << ":" << width() << ":" << height() << ":" << minimumWidth() << ":" << minimumHeight() << endl; -} - -void KMenuBar::checkSize( int& w, int& h ) -{ - if( !d->topLevel || d->fallback_mode ) - return; - TQSize s = sizeHint(); - w = s.width(); - h = s.height(); - // This is not done as setMinimumSize(), because that would set the minimum - // size in WM_NORMAL_HINTS, and KWin would not allow changing to smaller size - // anymore - w = KMAX( w, d->min_size.width()); - h = KMAX( h, d->min_size.height()); -} - -// QMenuBar's sizeHint() gives wrong size (insufficient width), which causes wrapping in the kicker applet -TQSize KMenuBar::sizeHint() const -{ - if( !d->topLevel || block_resize > 0 ) - return TQMenuBar::sizeHint(); - // Since TQMenuBar::sizeHint() may indirectly call resize(), - // avoid infinite recursion. - ++block_resize; - // find the minimum useful height, and enlarge the width until the menu fits in that height (one row) - int h = heightForWidth( 1000000 ); - int w = TQMenuBar::sizeHint().width(); - // optimization - don't call heightForWidth() too many times - while( heightForWidth( w + 12 ) > h ) - w += 12; - while( heightForWidth( w + 4 ) > h ) - w += 4; - while( heightForWidth( w ) > h ) - ++w; - --block_resize; - return TQSize( w, h ); -} - -#ifdef Q_WS_X11 -bool KMenuBar::x11Event( XEvent* ev ) -{ - if( ev->type == ClientMessage && ev->xclient.message_type == msg_type_atom - && ev->xclient.window == winId()) - { - // TQMenuBar is trying really hard to keep the size it deems right. - // Forcing minimum size and blocking resizing to match parent size - // in checkResizingToParent() seem to be the only way to make - // KMenuBar keep the size it wants - d->min_size = TQSize( ev->xclient.data.l[ 1 ], ev->xclient.data.l[ 2 ] ); -// kdDebug() << "MINSIZE:" << d->min_size << endl; - updateMenuBarSize(); - return true; - } - return TQMenuBar::x11Event( ev ); -} -#endif - -void KMenuBar::updateMenuBarSize() - { - menuContentsChanged(); // trigger invalidating calculated size - resize( sizeHint()); // and resize to preferred size - } - -void KMenuBar::setFrameStyle( int style ) -{ - if( d->topLevel ) - d->frameStyle = style; - else - TQMenuBar::setFrameStyle( style ); -} - -void KMenuBar::setLineWidth( int width ) -{ - if( d->topLevel ) - d->lineWidth = width; - else - TQMenuBar::setLineWidth( width ); -} - -void KMenuBar::setMargin( int margin ) -{ - if( d->topLevel ) - d->margin = margin; - else - TQMenuBar::setMargin( margin ); -} - -void KMenuBar::closeEvent( TQCloseEvent* e ) -{ - if( d->topLevel ) - e->ignore(); // mainly for the fallback mode - else - TQMenuBar::closeEvent( e ); -} - -void KMenuBar::drawContents( TQPainter* p ) -{ - // Closes the BR77113 - // We need to overload this method to paint only the menu items - // This way when the KMenuBar is embedded in the menu applet it - // integrates correctly. - // - // Background mode and origin are set so late because of styles - // using the polish() method to modify these settings. - // - // Of course this hack can safely be removed when real transparency - // will be available - - if( !d->topLevel ) - { - TQMenuBar::drawContents(p); - } - else - { - bool up_enabled = isUpdatesEnabled(); - BackgroundMode bg_mode = backgroundMode(); - BackgroundOrigin bg_origin = backgroundOrigin(); - - setUpdatesEnabled(false); - setBackgroundMode(X11ParentRelative); - setBackgroundOrigin(WindowOrigin); - - p->eraseRect( rect() ); - erase(); - - TQColorGroup g = colorGroup(); - bool e; - - for ( int i=0; i<(int)count(); i++ ) - { - TQMenuItem *mi = findItem( idAt( i ) ); - - if ( !mi->text().isNull() || mi->pixmap() ) - { - TQRect r = itemRect(i); - if(r.isEmpty() || !mi->isVisible()) - continue; - - e = mi->isEnabledAndVisible(); - if ( e ) - g = isEnabled() ? ( isActiveWindow() ? palette().active() : - palette().inactive() ) : palette().disabled(); - else - g = palette().disabled(); - - bool item_active = ( actItem == i ); - - p->setClipRect(r); - - if( item_active ) - { - TQStyle::SFlags flags = TQStyle::Style_Default; - if (isEnabled() && e) - flags |= TQStyle::Style_Enabled; - if ( item_active ) - flags |= TQStyle::Style_Active; - if ( item_active && actItemDown ) - flags |= TQStyle::Style_Down; - flags |= TQStyle::Style_HasFocus; - - style().drawControl(TQStyle::CE_MenuBarItem, p, this, - r, g, flags, TQStyleOption(mi)); - } - else - { - style().drawItem(p, r, AlignCenter | AlignVCenter | ShowPrefix, - g, e, mi->pixmap(), mi->text()); - } - } - } - - setBackgroundOrigin(bg_origin); - setBackgroundMode(bg_mode); - setUpdatesEnabled(up_enabled); - } -} - -void KMenuBar::virtual_hook( int, void* ) -{ /*BASE::virtual_hook( id, data );*/ } - -#include "tdemenubar.moc" diff --git a/tdeui/kmenubar.h b/tdeui/kmenubar.h deleted file mode 100644 index e657671e3..000000000 --- a/tdeui/kmenubar.h +++ /dev/null @@ -1,114 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1997, 1998, 1999, 2000 Sven Radej (radej@kde.org) - Copyright (C) 1997, 1998, 1999, 2000 Matthias Ettrich (ettrich@kde.org) - Copyright (C) 1999, 2000 Daniel "Mosfet" Duley (mosfet@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. -*/ - -//$Id$ - -#ifndef _KMENUBAR_H -#define _KMENUBAR_H - -#include - -#include - -/** - * %KDE Style-able menubar. - * - * This is required since TQMenuBar is currently not handled by - * TQStyle. - * - * @author Daniel "Mosfet" Duley. - * @version $Id$ -*/ - -class TDEUI_EXPORT KMenuBar : public TQMenuBar -{ - Q_OBJECT - -public: - - KMenuBar (TQWidget *parent=0, const char *name=0); - ~KMenuBar (); - - /** - * This controls whether or not this menubar will be a top-level - * bar similar to the way Macintosh handles menubars. This - * overrides any global config settings. - * - * Keep in mind that it is probably a really bad idea to use this - * unless you really know what you're doing. A feature like a - * top-level menubar is one that should really be shared by all - * applications. If your app is the only one with a top-level - * bar, then things might look very... odd. - * - * This is included only for those people that @p do know that - * they need to use it. - * - * @param top_level If set to true, then this menubar will be a - * top-level menu - */ - void setTopLevelMenu(bool top_level = true); - - /** - * Is our menubar a top-level (Macintosh style) menubar? - * - * @return True if it is top-level. - */ - bool isTopLevelMenu() const; - - // TT are overloading virtuals :( - virtual void setGeometry( const TQRect &r ); - virtual void setGeometry( int x, int y, int w, int h ); - virtual void resize( int w, int h ); - void resize( const TQSize& s ) { TQMenuBar::resize( s ); } - - virtual void show(); - virtual void setFrameStyle( int ); - virtual void setLineWidth( int ); - virtual void setMargin( int ); - virtual TQSize sizeHint() const; -protected slots: - void slotReadConfig(); -protected: - virtual void showEvent( TQShowEvent* ); - virtual void resizeEvent( TQResizeEvent* ); - virtual bool eventFilter(TQObject *, TQEvent *); -#ifdef Q_WS_X11 - virtual bool x11Event( XEvent* ); -#endif - virtual void closeEvent( TQCloseEvent* ); - virtual void drawContents( TQPainter* ); -private slots: - void updateFallbackSize(); - void selectionTimeout(); -private: - void setTopLevelMenuInternal(bool top_level); - void updateMenuBarSize(); - void checkSize( int& w, int& h ); - static int block_resize; -protected: - virtual void virtual_hook( int id, void* data ); -private: - class KMenuBarPrivate; - KMenuBarPrivate *d; -}; - -#endif diff --git a/tdeui/kmessagebox.cpp b/tdeui/kmessagebox.cpp deleted file mode 100644 index 3208e94d8..000000000 --- a/tdeui/kmessagebox.cpp +++ /dev/null @@ -1,1071 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Waldo Bastian (bastian@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; version 2 - of the License. - - 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. -*/ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#ifdef Q_WS_X11 -#include -#endif - - /** - * Easy MessageBox Dialog. - * - * Provides convenience functions for some i18n'ed standard dialogs, - * as well as audible notification via @ref KNotifyClient - * - * @author Waldo Bastian (bastian@kde.org) - */ - -static bool KMessageBox_queue = false; - -static TQPixmap themedMessageBoxIcon(TQMessageBox::Icon icon) -{ - TQString icon_name; - - switch(icon) - { - case TQMessageBox::NoIcon: - return TQPixmap(); - break; - case TQMessageBox::Information: - icon_name = "messagebox_info"; - break; - case TQMessageBox::Warning: - icon_name = "messagebox_warning"; - break; - case TQMessageBox::Critical: - icon_name = "messagebox_critical"; - break; - default: - break; - } - - TQPixmap ret = TDEGlobal::iconLoader()->loadIcon(icon_name, TDEIcon::NoGroup, TDEIcon::SizeMedium, TDEIcon::DefaultState, 0, true); - - if (ret.isNull()) - return TQMessageBox::standardIcon(icon); - else - return ret; -} - -static void sendNotification( TQString message, - const TQStringList& strlist, - TQMessageBox::Icon icon, - WId parent_id ) -{ - // create the message for KNotify - TQString messageType; - switch ( icon ) - { - case TQMessageBox::Warning: - messageType = "messageWarning"; - break; - case TQMessageBox::Critical: - messageType = "messageCritical"; - break; - case TQMessageBox::Question: - messageType = "messageQuestion"; - break; - default: - messageType = "messageInformation"; - break; - } - - if ( !strlist.isEmpty() ) - { - for ( TQStringList::ConstIterator it = strlist.begin(); it != strlist.end(); ++it ) - message += "\n" + *it; - } - - if ( !message.isEmpty() ) - KNotifyClient::event( (int)parent_id, messageType, message ); -} - -static TQString qrichtextify( const TQString& text ) -{ - if ( text.isEmpty() || text[0] == '<' ) - return text; - - TQStringList lines = TQStringList::split('\n', text); - for(TQStringList::Iterator it = lines.begin(); it != lines.end(); ++it) - { - *it = TQStyleSheet::convertFromPlainText( *it, TQStyleSheetItem::WhiteSpaceNormal ); - } - - return lines.join(TQString::null); -} - -int KMessageBox::createKMessageBox(KDialogBase *dialog, TQMessageBox::Icon icon, - const TQString &text, const TQStringList &strlist, - const TQString &ask, bool *checkboxReturn, - int options, const TQString &details) -{ - return createKMessageBox(dialog, themedMessageBoxIcon(icon), text, strlist, - ask, checkboxReturn, options, details, icon); -} - -int KMessageBox::createKMessageBox(KDialogBase *dialog, TQPixmap icon, - const TQString &text, const TQStringList &strlist, - const TQString &ask, bool *checkboxReturn, int options, - const TQString &details, TQMessageBox::Icon notifyType) -{ - TQVBox *topcontents = new TQVBox (dialog); - topcontents->setSpacing(KDialog::spacingHint()*2); - topcontents->setMargin(KDialog::marginHint()); - - TQWidget *contents = new TQWidget(topcontents); - TQHBoxLayout * lay = new TQHBoxLayout(contents); - lay->setSpacing(KDialog::spacingHint()); - - TQLabel *label1 = new TQLabel( contents); - - if (!icon.isNull()) - label1->setPixmap(icon); - - lay->addWidget( label1, 0, Qt::AlignCenter ); - lay->addSpacing(KDialog::spacingHint()); - // Enforce

text

otherwise the word-wrap doesn't work well - TQString qt_text = qrichtextify( text ); - - int pref_width = 0; - int pref_height = 0; - // Calculate a proper size for the text. - { - TQSimpleRichText rt(qt_text, dialog->font()); - TQRect d = TDEGlobalSettings::desktopGeometry(dialog); - - pref_width = d.width() / 3; - rt.setWidth(pref_width); - int used_width = rt.widthUsed(); - pref_height = rt.height(); - if (3*pref_height > 2*d.height()) - { - // Very high dialog.. make it wider - pref_width = d.width() / 2; - rt.setWidth(pref_width); - used_width = rt.widthUsed(); - pref_height = rt.height(); - } - if (used_width <= pref_width) - { - while(true) - { - int new_width = (used_width * 9) / 10; - rt.setWidth(new_width); - int new_height = rt.height(); - if (new_height > pref_height) - break; - used_width = rt.widthUsed(); - if (used_width > new_width) - break; - } - pref_width = used_width; - } - else - { - if (used_width > (pref_width *2)) - pref_width = pref_width *2; - else - pref_width = used_width; - } - } - KActiveLabel *label2 = new KActiveLabel( qt_text, contents ); - if (!(options & KMessageBox::AllowLink)) - { - TQObject::disconnect(label2, TQT_SIGNAL(linkClicked(const TQString &)), - label2, TQT_SLOT(openLink(const TQString &))); - } - - // We add 10 pixels extra to compensate for some KActiveLabel margins. - // TODO: find out why this is 10. - label2->setFixedSize(TQSize(pref_width+10, pref_height)); - lay->addWidget( label2 ); - lay->addStretch(); - - TDEListBox *listbox = 0; - if (!strlist.isEmpty()) - { - listbox=new TDEListBox( topcontents ); - listbox->insertStringList( strlist ); - listbox->setSelectionMode( TQListBox::NoSelection ); - topcontents->setStretchFactor(listbox, 1); - } - - TQGuardedPtr checkbox = 0; - if (!ask.isEmpty()) - { - checkbox = new TQCheckBox(ask, topcontents); - if (checkboxReturn) - checkbox->setChecked(*checkboxReturn); - } - - if (!details.isEmpty()) - { - TQVGroupBox *detailsGroup = new TQVGroupBox( i18n("Details"), dialog); - if ( details.length() < 512 ) { - KActiveLabel *label3 = new KActiveLabel(qrichtextify(details), - detailsGroup); - label3->setMinimumSize(label3->sizeHint()); - if (!(options & KMessageBox::AllowLink)) - { - TQObject::disconnect(label3, TQT_SIGNAL(linkClicked(const TQString &)), - label3, TQT_SLOT(openLink(const TQString &))); - } - } else { - TQTextEdit* te = new TQTextEdit(details, TQString::null, detailsGroup); - te->setReadOnly( true ); - te->setMinimumHeight( te->fontMetrics().lineSpacing() * 11 ); - } - dialog->setDetailsWidget(detailsGroup); - } - - dialog->setMainWidget(topcontents); - dialog->enableButtonSeparator(false); - if (!listbox) - dialog->disableResize(); - - const KDialogBase::ButtonCode buttons[] = { - KDialogBase::Help, - KDialogBase::Default, - KDialogBase::Ok, - KDialogBase::Apply, - KDialogBase::Try, - KDialogBase::Cancel, - KDialogBase::Close, - KDialogBase::User1, - KDialogBase::User2, - KDialogBase::User3, - KDialogBase::No, - KDialogBase::Yes, - KDialogBase::Details }; - for( unsigned int i = 0; - i < sizeof( buttons )/sizeof( buttons[ 0 ] ); - ++i ) - if( TQPushButton* btn = dialog->actionButton( buttons[ i ] )) - if( btn->isDefault()) - btn->setFocus(); - - if ( (options & KMessageBox::Notify) ) - sendNotification( text, strlist, notifyType, dialog->topLevelWidget()->winId()); - - if (KMessageBox_queue) - { - KDialogQueue::queueDialog(dialog); - return KMessageBox::Cancel; // We have to return something. - } - - if ( (options & KMessageBox::NoExec) ) - { - return KMessageBox::Cancel; // We have to return something. - } - - // We use a TQGuardedPtr because the dialog may get deleted - // during exec() if the parent of the dialog gets deleted. - // In that case the guarded ptr will reset to 0. - TQGuardedPtr guardedDialog = dialog; - - int result = guardedDialog->exec(); - if (checkbox && checkboxReturn) - *checkboxReturn = checkbox->isChecked(); - delete (KDialogBase *) guardedDialog; - return result; -} - -int -KMessageBox::questionYesNo(TQWidget *parent, const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return questionYesNoList(parent, text, TQStringList(), caption, - buttonYes, buttonNo, dontAskAgainName, options); -} - -int -KMessageBox::questionYesNoWId(WId parent_id, const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return questionYesNoListWId(parent_id, text, TQStringList(), caption, - buttonYes, buttonNo, dontAskAgainName, options); -} - -bool -KMessageBox::shouldBeShownYesNo(const TQString &dontShowAgainName, - ButtonCode &result) -{ - if ( dontShowAgainName.isEmpty() ) return true; - TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); - TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); - TDEConfigGroupSaver saver( config, grpNotifMsgs ); - TQString dontAsk = config->readEntry(dontShowAgainName).lower(); - if (dontAsk == "yes") { - result = Yes; - return false; - } - if (dontAsk == "no") { - result = No; - return false; - } - return true; -} - -bool -KMessageBox::shouldBeShownContinue(const TQString &dontShowAgainName) -{ - if ( dontShowAgainName.isEmpty() ) return true; - TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); - TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); - TDEConfigGroupSaver saver( config, grpNotifMsgs ); - return config->readBoolEntry(dontShowAgainName, true); -} - -void -KMessageBox::saveDontShowAgainYesNo(const TQString &dontShowAgainName, - ButtonCode result) -{ - if ( dontShowAgainName.isEmpty() ) return; - TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); - TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); - TDEConfigGroupSaver saver( config, grpNotifMsgs ); - config->writeEntry( dontShowAgainName, result==Yes ? "yes" : "no", true, (dontShowAgainName[0] == ':')); - config->sync(); -} - -void -KMessageBox::saveDontShowAgainContinue(const TQString &dontShowAgainName) -{ - if ( dontShowAgainName.isEmpty() ) return; - TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); - TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); - TDEConfigGroupSaver saver( config, grpNotifMsgs ); - config->writeEntry( dontShowAgainName, false, true, (dontShowAgainName[0] == ':')); - config->sync(); -} - -TDEConfig* KMessageBox::againConfig = NULL; -void -KMessageBox::setDontShowAskAgainConfig(TDEConfig* cfg) -{ - againConfig = cfg; -} - -int -KMessageBox::questionYesNoList(TQWidget *parent, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ // in order to avoid code duplication, convert to WId, it will be converted back - return questionYesNoListWId( parent ? parent->winId() : 0, text, strlist, - caption, buttonYes, buttonNo, dontAskAgainName, options ); -} - -int -KMessageBox::questionYesNoListWId(WId parent_id, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - ButtonCode res; - if ( !shouldBeShownYesNo(dontAskAgainName, res) ) - return res; - - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Question") : caption, - KDialogBase::Yes | KDialogBase::No, - KDialogBase::Yes, KDialogBase::No, - parent, "questionYesNo", true, true, - buttonYes, buttonNo); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - bool checkboxResult = false; - int result = createKMessageBox(dialog, TQMessageBox::Information, text, strlist, - dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), - &checkboxResult, options); - res = (result==KDialogBase::Yes ? Yes : No); - - if (checkboxResult) - saveDontShowAgainYesNo(dontAskAgainName, res); - return res; -} - -int -KMessageBox::questionYesNoCancel(TQWidget *parent, - const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return questionYesNoCancelWId( parent ? parent->winId() : 0, text, caption, buttonYes, buttonNo, - dontAskAgainName, options ); -} - -int -KMessageBox::questionYesNoCancelWId(WId parent_id, - const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - ButtonCode res; - if ( !shouldBeShownYesNo(dontAskAgainName, res) ) - return res; - - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Question") : caption, - KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel, - KDialogBase::Yes, KDialogBase::Cancel, - parent, "questionYesNoCancel", true, true, - buttonYes, buttonNo); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - bool checkboxResult = false; - int result = createKMessageBox(dialog, TQMessageBox::Information, - text, TQStringList(), - dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), - &checkboxResult, options); - if ( result==KDialogBase::Cancel ) return Cancel; - res = (result==KDialogBase::Yes ? Yes : No); - - if (checkboxResult) - saveDontShowAgainYesNo(dontAskAgainName, res); - return res; -} - -int -KMessageBox::warningYesNo(TQWidget *parent, const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return warningYesNoList(parent, text, TQStringList(), caption, - buttonYes, buttonNo, dontAskAgainName, options); -} - -int -KMessageBox::warningYesNoWId(WId parent_id, const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return warningYesNoListWId(parent_id, text, TQStringList(), caption, - buttonYes, buttonNo, dontAskAgainName, options); -} - -int -KMessageBox::warningYesNoList(TQWidget *parent, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return warningYesNoListWId( parent ? parent->winId() : 0, text, strlist, caption, - buttonYes, buttonNo, dontAskAgainName, options ); -} - -int -KMessageBox::warningYesNoListWId(WId parent_id, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - // warningYesNo and warningYesNoList are always "dangerous" - // ### Remove this line for KDE 4, when the 'options' default parameter - // takes effects. - options |= Dangerous; - - ButtonCode res; - if ( !shouldBeShownYesNo(dontAskAgainName, res) ) - return res; - - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Warning") : caption, - KDialogBase::Yes | KDialogBase::No, - KDialogBase::No, KDialogBase::No, - parent, "warningYesNoList", true, true, - buttonYes, buttonNo); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - bool checkboxResult = false; - int result = createKMessageBox(dialog, TQMessageBox::Warning, text, strlist, - dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), - &checkboxResult, options); - res = (result==KDialogBase::Yes ? Yes : No); - - if (checkboxResult) - saveDontShowAgainYesNo(dontAskAgainName, res); - return res; -} - -int -KMessageBox::warningContinueCancel(TQWidget *parent, - const TQString &text, - const TQString &caption, - const KGuiItem &buttonContinue, - const TQString &dontAskAgainName, - int options) -{ - return warningContinueCancelList(parent, text, TQStringList(), caption, - buttonContinue, dontAskAgainName, options); -} - -int -KMessageBox::warningContinueCancelWId(WId parent_id, - const TQString &text, - const TQString &caption, - const KGuiItem &buttonContinue, - const TQString &dontAskAgainName, - int options) -{ - return warningContinueCancelListWId(parent_id, text, TQStringList(), caption, - buttonContinue, dontAskAgainName, options); -} - -int -KMessageBox::warningContinueCancelList(TQWidget *parent, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonContinue, - const TQString &dontAskAgainName, - int options) -{ - return warningContinueCancelListWId( parent ? parent->winId() : 0, text, strlist, - caption, buttonContinue, dontAskAgainName, options ); -} - -int -KMessageBox::warningContinueCancelListWId(WId parent_id, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonContinue, - const TQString &dontAskAgainName, - int options) -{ - if ( !shouldBeShownContinue(dontAskAgainName) ) - return Continue; - - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Warning") : caption, - KDialogBase::Yes | KDialogBase::No, - KDialogBase::Yes, KDialogBase::No, - parent, "warningYesNo", true, true, - buttonContinue, KStdGuiItem::cancel() ); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - bool checkboxResult = false; - int result = createKMessageBox(dialog, TQMessageBox::Warning, text, strlist, - dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), - &checkboxResult, options); - - if ( result==KDialogBase::No ) - return Cancel; - if (checkboxResult) - saveDontShowAgainContinue(dontAskAgainName); - return Continue; -} - -int -KMessageBox::warningYesNoCancel(TQWidget *parent, const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return warningYesNoCancelList(parent, text, TQStringList(), caption, - buttonYes, buttonNo, dontAskAgainName, options); -} - -int -KMessageBox::warningYesNoCancelWId(WId parent_id, const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return warningYesNoCancelListWId(parent_id, text, TQStringList(), caption, - buttonYes, buttonNo, dontAskAgainName, options); -} - -int -KMessageBox::warningYesNoCancelList(TQWidget *parent, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - return warningYesNoCancelListWId( parent ? parent->winId() : 0, text, strlist, - caption, buttonYes, buttonNo, dontAskAgainName, options ); -} - -int -KMessageBox::warningYesNoCancelListWId(WId parent_id, const TQString &text, - const TQStringList &strlist, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontAskAgainName, - int options) -{ - ButtonCode res; - if ( !shouldBeShownYesNo(dontAskAgainName, res) ) - return res; - - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Warning") : caption, - KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel, - KDialogBase::Yes, KDialogBase::Cancel, - parent, "warningYesNoCancel", true, true, - buttonYes, buttonNo); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - bool checkboxResult = false; - int result = createKMessageBox(dialog, TQMessageBox::Warning, text, strlist, - dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), - &checkboxResult, options); - if ( result==KDialogBase::Cancel ) return Cancel; - res = (result==KDialogBase::Yes ? Yes : No); - - if (checkboxResult) - saveDontShowAgainYesNo(dontAskAgainName, res); - return res; -} - -void -KMessageBox::error(TQWidget *parent, const TQString &text, - const TQString &caption, int options) -{ - return errorListWId( parent ? parent->winId() : 0, text, TQStringList(), caption, options ); -} - -void -KMessageBox::errorWId(WId parent_id, const TQString &text, - const TQString &caption, int options) -{ - errorListWId( parent_id, text, TQStringList(), caption, options ); -} - -void -KMessageBox::errorList(TQWidget *parent, const TQString &text, const TQStringList &strlist, - const TQString &caption, int options) -{ - return errorListWId( parent ? parent->winId() : 0, text, strlist, caption, options ); -} - -void -KMessageBox::errorListWId(WId parent_id, const TQString &text, const TQStringList &strlist, - const TQString &caption, int options) -{ - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Error") : caption, - KDialogBase::Yes, - KDialogBase::Yes, KDialogBase::Yes, - parent, "error", true, true, - KStdGuiItem::ok() ); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - createKMessageBox(dialog, TQMessageBox::Critical, text, strlist, TQString::null, 0, options); -} - -void -KMessageBox::detailedError(TQWidget *parent, const TQString &text, - const TQString &details, - const TQString &caption, int options) -{ - return detailedErrorWId( parent ? parent->winId() : 0, text, details, caption, options ); -} - -void -KMessageBox::detailedErrorWId(WId parent_id, const TQString &text, - const TQString &details, - const TQString &caption, int options) -{ - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Error") : caption, - KDialogBase::Yes | KDialogBase::Details, - KDialogBase::Yes, KDialogBase::Yes, - parent, "error", true, true, - KStdGuiItem::ok() ); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - createKMessageBox(dialog, TQMessageBox::Critical, text, TQStringList(), TQString::null, 0, options, details); -} - -void -KMessageBox::queuedDetailedError(TQWidget *parent, const TQString &text, - const TQString &details, - const TQString &caption) -{ - return queuedDetailedErrorWId( parent ? parent->winId() : 0, text, details, caption ); -} - -void -KMessageBox::queuedDetailedErrorWId(WId parent_id, const TQString &text, - const TQString &details, - const TQString &caption) -{ - KMessageBox_queue = true; - (void) detailedErrorWId(parent_id, text, details, caption); - KMessageBox_queue = false; -} - - -void -KMessageBox::sorry(TQWidget *parent, const TQString &text, - const TQString &caption, int options) -{ - return sorryWId( parent ? parent->winId() : 0, text, caption, options ); -} - -void -KMessageBox::sorryWId(WId parent_id, const TQString &text, - const TQString &caption, int options) -{ - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Sorry") : caption, - KDialogBase::Yes, - KDialogBase::Yes, KDialogBase::Yes, - parent, "sorry", true, true, - KStdGuiItem::ok() ); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - createKMessageBox(dialog, TQMessageBox::Warning, text, TQStringList(), TQString::null, 0, options); -} - -void -KMessageBox::detailedSorry(TQWidget *parent, const TQString &text, - const TQString &details, - const TQString &caption, int options) -{ - return detailedSorryWId( parent ? parent->winId() : 0, text, details, caption, options ); -} - -void -KMessageBox::detailedSorryWId(WId parent_id, const TQString &text, - const TQString &details, - const TQString &caption, int options) -{ - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Sorry") : caption, - KDialogBase::Yes | KDialogBase::Details, - KDialogBase::Yes, KDialogBase::Yes, - parent, "sorry", true, true, - KStdGuiItem::ok() ); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - createKMessageBox(dialog, TQMessageBox::Warning, text, TQStringList(), TQString::null, 0, options, details); -} - -void -KMessageBox::information(TQWidget *parent,const TQString &text, - const TQString &caption, const TQString &dontShowAgainName, int options) -{ - informationList(parent, text, TQStringList(), caption, dontShowAgainName, options); -} - -void -KMessageBox::informationWId(WId parent_id,const TQString &text, - const TQString &caption, const TQString &dontShowAgainName, int options) -{ - informationListWId(parent_id, text, TQStringList(), caption, dontShowAgainName, options); -} - -void -KMessageBox::informationList(TQWidget *parent,const TQString &text, const TQStringList & strlist, - const TQString &caption, const TQString &dontShowAgainName, int options) -{ - return informationListWId( parent ? parent->winId() : 0, text, strlist, caption, - dontShowAgainName, options ); -} - -void -KMessageBox::informationListWId(WId parent_id,const TQString &text, const TQStringList & strlist, - const TQString &caption, const TQString &dontShowAgainName, int options) -{ - if ( !shouldBeShownContinue(dontShowAgainName) ) - return; - - TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); - KDialogBase *dialog= new KDialogBase( - caption.isEmpty() ? i18n("Information") : caption, - KDialogBase::Yes, - KDialogBase::Yes, KDialogBase::Yes, - parent, "information", true, true, - KStdGuiItem::ok() ); - if( options & PlainCaption ) - dialog->setPlainCaption( caption ); -#ifdef Q_WS_X11 - if( parent == NULL && parent_id ) - XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); -#endif - - bool checkboxResult = false; - - createKMessageBox(dialog, TQMessageBox::Information, text, strlist, - dontShowAgainName.isEmpty() ? TQString::null : i18n("Do not show this message again"), - &checkboxResult, options); - - if (checkboxResult) - saveDontShowAgainContinue(dontShowAgainName); -} - -void -KMessageBox::enableAllMessages() -{ - TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); - TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); - if (!config->hasGroup(grpNotifMsgs)) - return; - - TDEConfigGroupSaver saver( config, grpNotifMsgs ); - - typedef TQMap configMap; - - configMap map = config->entryMap(grpNotifMsgs); - - configMap::Iterator it; - for (it = map.begin(); it != map.end(); ++it) - config->deleteEntry( it.key() ); - config->sync(); -} - -void -KMessageBox::enableMessage(const TQString &dontShowAgainName) -{ - TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); - TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); - if (!config->hasGroup(grpNotifMsgs)) - return; - - TDEConfigGroupSaver saver( config, grpNotifMsgs ); - - config->deleteEntry(dontShowAgainName); - config->sync(); -} - -void -KMessageBox::about(TQWidget *parent, const TQString &text, - const TQString &caption, int options) -{ - TQString _caption = caption; - if (_caption.isEmpty()) - _caption = i18n("About %1").arg(kapp->caption()); - - KDialogBase *dialog = new KDialogBase( - caption, - KDialogBase::Yes, - KDialogBase::Yes, KDialogBase::Yes, - parent, "about", true, true, - KStdGuiItem::ok() ); - - TQPixmap ret = TDEApplication::kApplication()->icon(); - if (ret.isNull()) - ret = TQMessageBox::standardIcon(TQMessageBox::Information); - dialog->setIcon(ret); - - createKMessageBox(dialog, ret, text, TQStringList(), TQString::null, 0, options); - - return; -} - -int KMessageBox::messageBox( TQWidget *parent, DialogType type, const TQString &text, - const TQString &caption, const KGuiItem &buttonYes, - const KGuiItem &buttonNo, const TQString &dontShowAskAgainName, - int options ) -{ - return messageBoxWId( parent ? parent->winId() : 0, type, text, caption, - buttonYes, buttonNo, dontShowAskAgainName, options ); -} - -int KMessageBox::messageBox( TQWidget *parent, DialogType type, const TQString &text, - const TQString &caption, const KGuiItem &buttonYes, - const KGuiItem &buttonNo, int options ) -{ - return messageBoxWId( parent ? parent->winId() : 0, type, text, caption, - buttonYes, buttonNo, TQString::null, options ); -} - -int KMessageBox::messageBoxWId( WId parent_id, DialogType type, const TQString &text, - const TQString &caption, const KGuiItem &buttonYes, - const KGuiItem &buttonNo, const TQString &dontShow, - int options ) -{ - switch (type) { - case QuestionYesNo: - return KMessageBox::questionYesNoWId( parent_id, - text, caption, buttonYes, buttonNo, dontShow, options ); - case QuestionYesNoCancel: - return KMessageBox::questionYesNoCancelWId( parent_id, - text, caption, buttonYes, buttonNo, dontShow, options ); - case WarningYesNo: - return KMessageBox::warningYesNoWId( parent_id, - text, caption, buttonYes, buttonNo, dontShow, options ); - case WarningContinueCancel: - return KMessageBox::warningContinueCancelWId( parent_id, - text, caption, buttonYes.text(), dontShow, options ); - case WarningYesNoCancel: - return KMessageBox::warningYesNoCancelWId( parent_id, - text, caption, buttonYes, buttonNo, dontShow, options ); - case Information: - KMessageBox::informationWId( parent_id, - text, caption, dontShow, options ); - return KMessageBox::Ok; - - case Error: - KMessageBox::errorWId( parent_id, text, caption, options ); - return KMessageBox::Ok; - - case Sorry: - KMessageBox::sorryWId( parent_id, text, caption, options ); - return KMessageBox::Ok; - } - return KMessageBox::Cancel; -} - -void KMessageBox::queuedMessageBox( TQWidget *parent, DialogType type, const TQString &text, const TQString &caption, int options ) -{ - return queuedMessageBoxWId( parent ? parent->winId() : 0, type, text, caption, options ); -} - -void KMessageBox::queuedMessageBoxWId( WId parent_id, DialogType type, const TQString &text, const TQString &caption, int options ) -{ - KMessageBox_queue = true; - (void) messageBoxWId(parent_id, type, text, caption, KStdGuiItem::yes(), - KStdGuiItem::no(), TQString::null, options); - KMessageBox_queue = false; -} - -void KMessageBox::queuedMessageBox( TQWidget *parent, DialogType type, const TQString &text, const TQString &caption ) -{ - return queuedMessageBoxWId( parent ? parent->winId() : 0, type, text, caption ); -} - -void KMessageBox::queuedMessageBoxWId( WId parent_id, DialogType type, const TQString &text, const TQString &caption ) -{ - KMessageBox_queue = true; - (void) messageBoxWId(parent_id, type, text, caption); - KMessageBox_queue = false; -} diff --git a/tdeui/kmessagebox.h b/tdeui/kmessagebox.h deleted file mode 100644 index b7724f5ce..000000000 --- a/tdeui/kmessagebox.h +++ /dev/null @@ -1,1166 +0,0 @@ -/* This file is part of the KDE libraries - Copyright (C) 1999 Waldo Bastian (bastian@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; version 2 - of the License. - - 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. -*/ -#ifndef _KMESSAGEBOX_H_ -#define _KMESSAGEBOX_H_ - -#include -#include - -#include -#include - -class TQWidget; -class TQStringList; -class TDEConfig; -class KDialogBase; - - /** - * Easy message dialog box. - * - * Provides convenience functions for some i18n'ed standard dialogs. - * - * The text in message boxes is wrapped automatically. The text may either - * be plaintext or richtext. If the text is plaintext, a newline-character - * may be used to indicate the end of a paragraph. - * - * @author Waldo Bastian (bastian@kde.org) - */ -class TDEUI_EXPORT KMessageBox -{ -public: - /** - * Button types. - **/ - enum ButtonCode - { - Ok = 1, - Cancel = 2, - Yes = 3, - No = 4, - Continue = 5 - }; - - enum DialogType - { - QuestionYesNo = 1, - WarningYesNo = 2, - WarningContinueCancel = 3, - WarningYesNoCancel = 4, - Information = 5, - // Reserved for: SSLMessageBox = 6 - Sorry = 7, - Error = 8, - QuestionYesNoCancel = 9 - }; - - enum OptionsType - { - Notify = 1, ///< Emit a KNotifyClient event - AllowLink = 2, ///< The message may contain links. - Dangerous = 4, ///< The action to be confirmed by the dialog is a potentially destructive one - PlainCaption = 8, /**< Do not use TDEApplication::makeStdCaption() - @since 3.4 - */ - NoExec = 16 /**< Do not call exec() in createKMessageBox() - @since 3.4 - */ - }; - - /** - * Display a simple "question" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Question"). - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontAskAgainName If provided, a checkbox is added with which - * further confirmation can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned - * if the No-button is pressed. - * - * To be used for questions like "Do you have a printer?" - * - * The default button is "Yes". Pressing "Esc" selects "No". - */ - - static int questionYesNo(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int questionYesNoWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - /** - * Display a simple "question" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Question"). - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontAskAgainName If provided, a checkbox is added with which - * further confirmation can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned - * if the No-button is pressed. - * - * To be used for questions like "Do you want to discard the message or save it for later?", - * - * The default button is "Yes". Pressing "Esc" selects "Cancel". - * - * NOTE: The cancel button will always have the i18n'ed text '&Cancel'. - */ - - static int questionYesNoCancel(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int questionYesNoCancelWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * Display a "question" dialog with a listbox to show information to the user - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. If the list is - * empty, it doesn't show any listbox, working as questionYesNo. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Question"). - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontAskAgainName If provided, a checkbox is added with which - * further confirmation can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned - * if the No-button is pressed. - * - * To be used for questions like "Do you really want to delete these files?" - * And show the user exactly which files are going to be deleted in case - * he presses "Yes" - * - * The default button is "Yes". Pressing "Esc" selects "No". - */ - - static int questionYesNoList(TQWidget *parent, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int questionYesNoListWId(WId parent_id, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * Display a "warning" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Warning"). - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontAskAgainName If provided, a checkbox is added with which - * further confirmation can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * @return @p Yes is returned if the Yes-button is pressed. @p No is returned - * if the No-button is pressed. - * - * To be used for questions "Shall I update your configuration?" - * The text should explain the implication of both options. - * - * The default button is "No". Pressing "Esc" selects "No". - */ - static int warningYesNo(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify | Dangerous); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int warningYesNoWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify | Dangerous); - - /** - * Display a "warning" dialog with a listbox to show information to the user - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. If the list is - * empty, it doesn't show any listbox, working as questionYesNo. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Question"). - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontAskAgainName If provided, a checkbox is added with which - * further confirmation can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned - * if the No-button is pressed. - * - * To be used for questions like "Do you really want to delete these files?" - * And show the user exactly which files are going to be deleted in case - * he presses "Yes" - * - * The default button is "No". Pressing "Esc" selects "No". - */ - - static int warningYesNoList(TQWidget *parent, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify | Dangerous); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int warningYesNoListWId(WId parent_id, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify | Dangerous); - - /** - * Display a "warning" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Warning"). - * @param buttonContinue The text for the first button. - * @param dontAskAgainName If provided, a checkbox is added with which - * further confirmation can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * The second button always has the text "Cancel". - * - * @return @p Continue is returned if the Continue-button is pressed. - * @p Cancel is returned if the Cancel-button is pressed. - * - * To be used for questions like "You are about to Print. Are you sure?" - * the continueButton should then be labeled "Print". - * - * The default button is buttonContinue. Pressing "Esc" selects "Cancel". - */ - static int warningContinueCancel(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonContinue = KStdGuiItem::cont(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int warningContinueCancelWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonContinue = KStdGuiItem::cont(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * Display a "warning" dialog with a listbox to show information to the user. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. If the - * list is empty, it doesn't show any listbox, working - * as warningContinueCancel. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Warning"). - * @param buttonContinue The text for the first button. - * @param dontAskAgainName If provided, a checkbox is added with which - * further confirmation can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * - * @param options see OptionsType - * - * The second button always has the text "Cancel". - * - * @return @p Continue is returned if the Continue-button is pressed. - * @p Cancel is returned if the Cancel-button is pressed. - * - * To be used for questions like "You are about to Print. Are you sure?" - * the continueButton should then be labeled "Print". - * - * The default button is buttonContinue. Pressing "Esc" selects "Cancel". - */ - static int warningContinueCancelList(TQWidget *parent, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonContinue = KStdGuiItem::cont(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int warningContinueCancelListWId(WId parent_id, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonContinue = KStdGuiItem::cont(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * Display a Yes/No/Cancel "warning" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Warning"). - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontAskAgainName If provided, a checkbox is added with which - * further questions can be turned off. If turned off - * all questions will be automatically answered with the - * last answer (either Yes or No). - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * @return @p Yes is returned if the Yes-button is pressed. @p No is returned - * if the No-button is pressed. @p Cancel is retunred if the Cancel- - * button is pressed. - * - * To be used for questions "Do you want to save your changes?" - * The text should explain the implication of choosing 'No'. - * - * The default button is "Yes". Pressing "Esc" selects "Cancel" - * - * NOTE: The cancel button will always have the i18n'ed text '&Cancel'. - */ - - static int warningYesNoCancel(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int warningYesNoCancelWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * Display a Yes/No/Cancel "warning" dialog with a listbox to show information - * to the user. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. If the - * list is empty, it doesn't show any listbox, working - * as warningYesNoCancel. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Warning"). - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontAskAgainName If provided, a checkbox is added with which - * further questions can be turned off. If turned off - * all questions will be automatically answered with the - * last answer (either Yes or No). - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * If @p dontAskAgainName starts with a ':' then the setting - * is stored in the global config file. - * @param options see OptionsType - * - * @return @p Yes is returned if the Yes-button is pressed. @p No is returned - * if the No-button is pressed. @p Cancel is retunred if the Cancel- - * button is pressed. - * - * To be used for questions "Do you want to save your changes?" - * The text should explain the implication of choosing 'No'. - * - * The default button is "Yes". Pressing "Esc" selects "Cancel" - * - * NOTE: The cancel button will always have the i18n'ed text '&Cancel'. - * - * @since 3.2 - */ - static int warningYesNoCancelList(TQWidget *parent, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int warningYesNoCancelListWId(WId parent_id, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontAskAgainName = TQString::null, - int options = Notify); - - /** - * Display an "Error" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Error"). - * @param options see OptionsType - * - * Your program messed up and now it's time to inform the user. - * To be used for important things like "Sorry, I deleted your hard disk." - * - * If your program detects the action specified by the user is somehow - * not allowed, this should never be reported with error(). Use sorry() - * instead to explain to the user that this action is not allowed. - * - * The default button is "&OK". Pressing "Esc" selects the OK-button. - * - * NOTE: The OK button will always have the i18n'ed text '&OK'. - */ - - static void error(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * - * @since 3.2 - */ - static void errorWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * Display an "Error" dialog with a listbox. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. If the - * list is empty, it doesn't show any listbox, working - * as error(). - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Error"). - * @param options see OptionsType - * - * Your program messed up and now it's time to inform the user. - * To be used for important things like "Sorry, I deleted your hard disk." - * - * If your program detects the action specified by the user is somehow - * not allowed, this should never be reported with error(). Use sorry() - * instead to explain to the user that this action is not allowed. - * - * The default button is "&OK". Pressing "Esc" selects the OK-button. - * - * NOTE: The OK button will always have the i18n'ed text '&OK'. - * - * @since 3.4 - */ - - static void errorList(TQWidget *parent, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.4 - */ - - static void errorListWId(WId parent_id, - const TQString &text, - const TQStringList &strlist, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * Displays an "Error" dialog with a "Details >>" button. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param details Detailed message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Error"). - * @param options see OptionsType - * - * Your program messed up and now it's time to inform the user. - * To be used for important things like "Sorry, I deleted your hard disk." - * - * The @p details message can conatin additional information about - * the problem and can be shown on request to advanced/interested users. - * - * If your program detects the action specified by the user is somehow - * not allowed, this should never be reported with error(). Use sorry() - * instead to explain to the user that this action is not allowed. - * - * The default button is "&OK". Pressing "Esc" selects the OK-button. - * - * NOTE: The OK button will always have the i18n'ed text '&OK'. - */ - static void detailedError(TQWidget *parent, - const TQString &text, - const TQString &details, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void detailedErrorWId(WId parent_id, - const TQString &text, - const TQString &details, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * Like detailedError - * - * This function will return immediately, the messagebox will be shown - * once the application enters an event loop and no other messagebox - * is being shown. - * - * Note that if the parent gets deleted, the messagebox will not be - * shown. - */ - static void queuedDetailedError( TQWidget *parent, - const TQString &text, - const TQString &details, - const TQString &caption = TQString::null); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void queuedDetailedErrorWId( WId parent_id, - const TQString &text, - const TQString &details, - const TQString &caption = TQString::null); - - /** - * Display an "Sorry" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Sorry"). - * @param options see OptionsType - * - * Either your program messed up and asks for understanding - * or your user did something stupid. - * - * To be used for small problems like - * "Sorry, I can't find the file you specified." - * - * The default button is "&OK". Pressing "Esc" selects the OK-button. - * - * NOTE: The ok button will always have the i18n'ed text '&OK'. - */ - - static void sorry(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void sorryWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * Displays a "Sorry" dialog with a "Details >>" button. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param details Detailed message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Sorry"). - * @param options see OptionsType - * - * Either your program messed up and asks for understanding - * or your user did something stupid. - * - * To be used for small problems like - * "Sorry, I can't find the file you specified." - * - * And then @p details can contain something like - * "foobar.txt was not found in any of - * the following directories: - * /usr/bin,/usr/local/bin,/usr/sbin" - * - * The default button is "&OK". Pressing "Esc" selects the OK-button. - * - * NOTE: The ok button will always have the i18n'ed text '&OK'. - */ - - static void detailedSorry(TQWidget *parent, - const TQString &text, - const TQString &details, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void detailedSorryWId(WId parent_id, - const TQString &text, - const TQString &details, - const TQString &caption = TQString::null, - int options = Notify); - - /** - * Display an "Information" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Information"). - * @param dontShowAgainName If provided, a checkbox is added with which - * further notifications can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * @param options see OptionsType - * - * - * Your program wants to tell the user something. - * To be used for things like: - * "Your bookmarks have been rearranged." - * - * The default button is "&OK". Pressing "Esc" selects the OK-button. - * - * NOTE: The OK button will always have the i18n'ed text '&OK'. - */ - - static void information(TQWidget *parent, - const TQString &text, - const TQString &caption = TQString::null, - const TQString &dontShowAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void informationWId(WId parent_id, - const TQString &text, - const TQString &caption = TQString::null, - const TQString &dontShowAgainName = TQString::null, - int options = Notify); - - /** - * Display an "Information" dialog with a listbox. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. If the - * list is empty, it doesn't show any listbox, working - * as information. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("Information"). - * @param dontShowAgainName If provided, a checkbox is added with which - * further notifications can be turned off. - * The string is used to lookup and store the setting - * in the applications config file. - * The setting is stored in the "Notification Messages" group. - * @param options see OptionsType - * - * - * Your program wants to tell the user something. - * To be used for things like: - * "The following bookmarks have been rearranged:" - * - * The default button is "&OK". Pressing "Esc" selects the OK-button. - * - * NOTE: The OK button will always have the i18n'ed text '&OK'. - * @since 3.1 - */ - - static void informationList(TQWidget *parent, - const TQString &text, - const TQStringList & strlist, - const TQString &caption = TQString::null, - const TQString &dontShowAgainName = TQString::null, - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void informationListWId(WId parent_id, - const TQString &text, - const TQStringList & strlist, - const TQString &caption = TQString::null, - const TQString &dontShowAgainName = TQString::null, - int options = Notify); - - /** - * Enable all messages which have been turned off with the - * @p dontShowAgainName feature. - */ - static void enableAllMessages(); - - /** - * Re-enable a specific @p dontShowAgainName messages that had - * previously been turned off. - * @see saveDontShowAgainYesNo() - * @see saveDontShowAgainContinue() - * @since 3.2 - */ - static void enableMessage(const TQString &dontShowAgainName); - - /** - * Display an "About" dialog. - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param text Message string. - * @param caption Message box title. The application name is added to - * the title. The default title is i18n("About \"). - * @param options see OptionsType - * - * - * Your program wants to show some general information about the application - * like the authors's names and email addresses. - * - * The default button is "&OK". - * - * NOTE: The ok button will always have the i18n'ed text '&OK'. - */ - static void about(TQWidget *parent, - const TQString& text, - const TQString& caption = TQString::null, - int options = Notify); - - /** - * Alternate method to show a messagebox: - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel... - * @param text Message string. - * @param caption Message box title. - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param dontShowAskAgainName If provided, a checkbox is added with which - * further questions/informations can be turned off. If turned off - * all questions will be automatically answered with the - * last answer (either Yes or No), if the message box needs an answer. - * The string is used to lookup and store the setting - * in the applications config file. - * @param options see OptionsType - * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused. - * and for Information, none is used. - * @return a button code, as defined in KMessageBox. - */ - static int messageBox( TQWidget *parent, DialogType type, const TQString &text, - const TQString &caption, - const KGuiItem &buttonYes, - const KGuiItem &buttonNo, - const TQString &dontShowAskAgainName, - int options = Notify); - - /** - * Alternate method to show a messagebox: - * - * @param parent If @p parent is 0, then the message box becomes an - * application-global modal dialog box. If @p parent is a - * widget, the message box becomes modal relative to parent. - * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel... - * @param text Message string. - * @param caption Message box title. - * @param buttonYes The text for the first button. - * The default is i18n("&Yes"). - * @param buttonNo The text for the second button. - * The default is i18n("&No"). - * @param options see OptionsType - * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused. - * and for Information, none is used. - * @return a button code, as defined in KMessageBox. - */ - // KDE4 - merge with above? - static int messageBox( TQWidget *parent, DialogType type, const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - int options = Notify); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static int messageBoxWId( WId parent_id, DialogType type, const TQString &text, - const TQString &caption = TQString::null, - const KGuiItem &buttonYes = KStdGuiItem::yes(), - const KGuiItem &buttonNo = KStdGuiItem::no(), - const TQString &dontShowAskAgainName = TQString::null, - int options = Notify); - - /** - * Like messageBox - * - * Only for message boxes of type Information, Sorry or Error. - * - * This function will return immediately, the messagebox will be shown - * once the application enters an event loop and no other messagebox - * is being shown. - * - * Note that if the parent gets deleted, the messagebox will not be - * shown. - */ - static void queuedMessageBox( TQWidget *parent, - DialogType type, const TQString &text, - const TQString &caption, - int options ); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void queuedMessageBoxWId( WId parent_id, - DialogType type, const TQString &text, - const TQString &caption, - int options ); - - /** - * @overload - * - * This is an overloaded member function, provided for convenience. - * It behaves essentially like the above function. - */ - static void queuedMessageBox( TQWidget *parent, - DialogType type, const TQString &text, - const TQString &caption = TQString::null ); - - /** - * This function accepts the window id of the parent window, instead - * of TQWidget*. It should be used only when necessary. - * @since 3.2 - */ - static void queuedMessageBoxWId( WId parent_id, - DialogType type, const TQString &text, - const TQString &caption = TQString::null ); - - /** - * @return true if the corresponding yes/no message box should be shown. - * @param dontShowAgainName the name that identify the message box. If - * empty, true is always returned. - * @param result is set to the result (Yes or No) that was chosen the last - * time the message box was shown. Only meaningful, if the message box - * should not be shown. - * @since 3.2 - */ - static bool shouldBeShownYesNo(const TQString &dontShowAgainName, - ButtonCode &result); - /** - * @return true if the corresponding continue/cancel message box should be - * shown. - * @param dontShowAgainName the name that identify the message box. If - * empty, true is always returned. - * @since 3.2 - */ - static bool shouldBeShownContinue(const TQString &dontShowAgainName); - - /** - * Save the fact that the yes/no message box should not be shown again. - * @param dontShowAgainName the name that identify the message box. If - * empty, this method does nothing. - * @param result the value (Yes or No) that should be used as the result - * for the message box. - * @since 3.2 - */ - static void saveDontShowAgainYesNo(const TQString &dontShowAgainName, - ButtonCode result); - - /** - * Save the fact that the continue/cancel message box should not be shown - * again. - * @param dontShowAgainName the name that identify the message box. If - * empty, this method does nothing. - * @since 3.2 - */ - static void saveDontShowAgainContinue(const TQString &dontShowAgainName); - - /** - * Use @p cfg for all settings related to the dontShowAgainName feature. - * If @p cfg is 0 (default) TDEGlobal::config() will be used. - * @since 3.2 - */ - static void setDontShowAskAgainConfig(TDEConfig* cfg); - - /** - * Create content and layout of a standard dialog - * - * @param dialog The parent dialog base - * @param icon Which predefined icon the message box shall show. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. - * If the list is empty, it doesn't show any listbox - * @param ask The text of the checkbox. If empty none will be shown. - * @param checkboxReturn The result of the checkbox. If it's initially - * true then the checkbox will be checked by default. - * @param options see OptionsType - * @param details Detailed message string. - * @since 3.3 - * @return A KDialogBase button code, not a KMessageBox button code, - * based on the buttonmask given to the constructor of the - * @p dialog (ie. will return KDialogBase::Yes [256] instead of - * KMessageBox::Yes [3]). Will return KMessageBox::Cancel - * if the message box is queued for display instead of - * exec()ed immediately or if the option NoExec is set. - * @note The @p dialog that is passed in is deleted by this - * function. Do not delete it yourself. - */ - static int createKMessageBox(KDialogBase *dialog, TQMessageBox::Icon icon, - const TQString &text, const TQStringList &strlist, - const TQString &ask, bool *checkboxReturn, - int options, const TQString &details=TQString::null); - - /** - * Create content and layout of a standard dialog - * - * @param dialog The parent dialog base - * @param icon A TQPixmap containing the icon to be displayed in the - * dialog next to the text. - * @param text Message string. - * @param strlist List of strings to be written in the listbox. - * If the list is empty, it doesn't show any listbox - * @param ask The text of the checkbox. If empty none will be shown. - * @param checkboxReturn The result of the checkbox. If it's initially - * true then the checkbox will be checked by default. - * @param options see OptionsType - * @param details Detailed message string. - * @param notifyType The type of notification to send when this message - * is presentend. - * @since 3.3 - * @return A KDialogBase button code, not a KMessageBox button code, - * based on the buttonmask given to the constructor of the - * @p dialog (ie. will return KDialogBase::Yes [256] instead of - * KMessageBox::Yes [3]). Will return KMessageBox::Cancel - * if the message box is queued for display instead of - * exec()ed immediately or if the option NoExec is set. - * @note The @p dialog that is passed in is deleted by this - * function. Do not delete it yourself. - */ - static int createKMessageBox(KDialogBase *dialog, TQPixmap icon, - const TQString &text, const TQStringList &strlist, - const TQString &ask, bool *checkboxReturn, - int options, const TQString &details=TQString::null, - TQMessageBox::Icon notifyType=TQMessageBox::Information); - -private: - static TDEConfig* againConfig; -}; - -#endif diff --git a/tdeui/tdemenubar.cpp b/tdeui/tdemenubar.cpp new file mode 100644 index 000000000..0a5fe0188 --- /dev/null +++ b/tdeui/tdemenubar.cpp @@ -0,0 +1,571 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997, 1998, 1999, 2000 Sven Radej (radej@kde.org) + Copyright (C) 1997, 1998, 1999, 2000 Matthias Ettrich (ettrich@kde.org) + Copyright (C) 1999, 2000 Daniel "Mosfet" Duley (mosfet@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. + */ + + +#ifndef INCLUDE_MENUITEM_DEF +#define INCLUDE_MENUITEM_DEF +#endif + +#include "config.h" +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_WS_X11 +#include +#include +#include + +#include +#include +#include + +#ifndef None +#define None 0L +#endif +#endif + +/* + + Toplevel menubar (not for the fallback size handling done by itself): + - should not alter position or set strut + - every toplevel must have at most one matching topmenu + - embedder won't allow shrinking below a certain size + - must have WM_TRANSIENT_FOR pointing the its mainwindow + - the exception is desktop's menubar, which can be transient for root window + because of using root window as the desktop window + - Fitts' Law + +*/ + +class KMenuBar::KMenuBarPrivate +{ +public: + KMenuBarPrivate() + : forcedTopLevel( false ), + topLevel( false ), + wasTopLevel( false ), +#ifdef Q_WS_X11 + selection( NULL ), +#endif + min_size( 0, 0 ) + { + } + ~KMenuBarPrivate() + { +#ifdef Q_WS_X11 + delete selection; +#endif + } + bool forcedTopLevel; + bool topLevel; + bool wasTopLevel; // when TLW is fullscreen, remember state + int frameStyle; // only valid in toplevel mode + int lineWidth; // dtto + int margin; // dtto + bool fallback_mode; // dtto +#ifdef Q_WS_X11 + TDESelectionWatcher* selection; +#endif + TQTimer selection_timer; + TQSize min_size; + static Atom makeSelectionAtom(); +}; + +#ifdef Q_WS_X11 +static Atom selection_atom = None; +static Atom msg_type_atom = None; + +static +void initAtoms() +{ + char nm[ 100 ]; + sprintf( nm, "_KDE_TOPMENU_OWNER_S%d", DefaultScreen( tqt_xdisplay())); + char nm2[] = "_KDE_TOPMENU_MINSIZE"; + char* names[ 2 ] = { nm, nm2 }; + Atom atoms[ 2 ]; + XInternAtoms( tqt_xdisplay(), names, 2, False, atoms ); + selection_atom = atoms[ 0 ]; + msg_type_atom = atoms[ 1 ]; +} +#endif + +Atom KMenuBar::KMenuBarPrivate::makeSelectionAtom() +{ +#ifdef Q_WS_X11 + if( selection_atom == None ) + initAtoms(); + return selection_atom; +#else + return 0; +#endif +} + +KMenuBar::KMenuBar(TQWidget *parent, const char *name) + : TQMenuBar(parent, name) +{ +#ifdef Q_WS_X11 + QXEmbed::initialize(); +#endif + d = new KMenuBarPrivate; + connect( &d->selection_timer, TQT_SIGNAL( timeout()), + this, TQT_SLOT( selectionTimeout())); + + connect( tqApp->desktop(), TQT_SIGNAL( resized( int )), TQT_SLOT( updateFallbackSize())); + + if ( kapp ) + // toolbarAppearanceChanged(int) is sent when changing macstyle + connect( kapp, TQT_SIGNAL(toolbarAppearanceChanged(int)), + this, TQT_SLOT(slotReadConfig())); + + slotReadConfig(); +} + +KMenuBar::~KMenuBar() +{ + delete d; +} + +void KMenuBar::setTopLevelMenu(bool top_level) +{ + d->forcedTopLevel = top_level; + setTopLevelMenuInternal( top_level ); +} + +void KMenuBar::setTopLevelMenuInternal(bool top_level) +{ + if (d->forcedTopLevel) + top_level = true; + + d->wasTopLevel = top_level; + if( parentWidget() + && parentWidget()->topLevelWidget()->isFullScreen()) + top_level = false; + + if ( isTopLevelMenu() == top_level ) + return; + d->topLevel = top_level; + if ( isTopLevelMenu() ) + { +#ifdef Q_WS_X11 + d->selection = new TDESelectionWatcher( KMenuBarPrivate::makeSelectionAtom(), + DefaultScreen( tqt_xdisplay())); + connect( d->selection, TQT_SIGNAL( newOwner( Window )), + this, TQT_SLOT( updateFallbackSize())); + connect( d->selection, TQT_SIGNAL( lostOwner()), + this, TQT_SLOT( updateFallbackSize())); +#endif + d->frameStyle = frameStyle(); + d->lineWidth = lineWidth(); + d->margin = margin(); + d->fallback_mode = false; + bool wasShown = !isHidden(); + reparent( parentWidget(), (WFlags)(WType_TopLevel | WStyle_Tool | WStyle_Customize | WStyle_NoBorder), TQPoint(0,0), false ); +#ifdef Q_WS_X11 + KWin::setType( winId(), NET::TopMenu ); + if( parentWidget()) + XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId()); +#endif + TQMenuBar::setFrameStyle( NoFrame ); + TQMenuBar::setLineWidth( 0 ); + TQMenuBar::setMargin( 0 ); + updateFallbackSize(); + d->min_size = TQSize( 0, 0 ); + if( parentWidget() && !parentWidget()->isTopLevel()) + setShown( parentWidget()->isVisible()); + else if ( wasShown ) + show(); + } else + { +#ifdef Q_WS_X11 + delete d->selection; + d->selection = NULL; +#endif + setBackgroundMode( PaletteButton ); + setFrameStyle( d->frameStyle ); + setLineWidth( d->lineWidth ); + setMargin( d->margin ); + setMinimumSize( 0, 0 ); + setMaximumSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX ); + updateMenuBarSize(); + if ( parentWidget() ) + reparent( parentWidget(), TQPoint(0,0), !isHidden()); + } +} + +bool KMenuBar::isTopLevelMenu() const +{ + return d->topLevel; +} + +// KDE4 remove +void KMenuBar::show() +{ + TQMenuBar::show(); +} + +void KMenuBar::slotReadConfig() +{ + TDEConfig *config = TDEGlobal::config(); + TDEConfigGroupSaver saver( config, "KDE" ); + setTopLevelMenuInternal( config->readBoolEntry( "macStyle", false ) ); +} + +bool KMenuBar::eventFilter(TQObject *obj, TQEvent *ev) +{ + if ( d->topLevel ) + { + if ( parentWidget() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget()->topLevelWidget()) ) + { + if( ev->type() == TQEvent::Resize ) + return false; // ignore resizing of parent, TQMenuBar would try to adjust size + if ( ev->type() == TQEvent::Accel || ev->type() == TQEvent::AccelAvailable ) + { + if ( TQApplication::sendEvent( topLevelWidget(), ev ) ) + return true; + } + if(ev->type() == TQEvent::ShowFullScreen ) + // will update the state properly + setTopLevelMenuInternal( d->topLevel ); + } + if( parentWidget() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget()) && ev->type() == TQEvent::Reparent ) + { +#ifdef Q_WS_X11 + XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId()); +#else + //TODO: WIN32? +#endif + setShown( parentWidget()->isTopLevel() || parentWidget()->isVisible()); + } + if( parentWidget() && !parentWidget()->isTopLevel() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget())) + { // if the parent is not toplevel, KMenuBar needs to match its visibility status + if( ev->type() == TQEvent::Show ) + { +#ifdef Q_WS_X11 + XSetTransientForHint( tqt_xdisplay(), winId(), parentWidget()->topLevelWidget()->winId()); +#else + //TODO: WIN32? +#endif + show(); + } + if( ev->type() == TQEvent::Hide ) + hide(); + } + } + else + { + if( parentWidget() && TQT_BASE_OBJECT(obj) == TQT_BASE_OBJECT(parentWidget()->topLevelWidget())) + { + if( ev->type() == TQEvent::WindowStateChange + && !parentWidget()->topLevelWidget()->isFullScreen() ) + setTopLevelMenuInternal( d->wasTopLevel ); + } + } + return TQMenuBar::eventFilter( obj, ev ); +} + +// KDE4 remove +void KMenuBar::showEvent( TQShowEvent *e ) +{ + TQMenuBar::showEvent(e); +} + +void KMenuBar::updateFallbackSize() +{ + if( !d->topLevel ) + return; +#ifdef Q_WS_X11 + if( d->selection->owner() != None ) +#endif + { // somebody is managing us, don't mess anything, undo changes + // done in fallback mode if needed + d->selection_timer.stop(); + if( d->fallback_mode ) + { + d->fallback_mode = false; + KWin::setStrut( winId(), 0, 0, 0, 0 ); + setMinimumSize( 0, 0 ); + setMaximumSize( TQWIDGETSIZE_MAX, TQWIDGETSIZE_MAX ); + updateMenuBarSize(); + } + return; + } + if( d->selection_timer.isActive()) + return; + d->selection_timer.start( 100, true ); +} + +void KMenuBar::selectionTimeout() +{ // nobody is managing us, handle resizing + if ( d->topLevel ) + { + d->fallback_mode = true; // KMenuBar is handling its position itself + TDEConfigGroup xineramaConfig(TDEGlobal::config(),"Xinerama"); + int screen = xineramaConfig.readNumEntry("MenubarScreen", + TQApplication::desktop()->screenNumber(TQPoint(0,0)) ); + TQRect area; + if (kapp->desktop()->numScreens() < 2) + area = kapp->desktop()->geometry(); + else + area = kapp->desktop()->screenGeometry(screen); + int margin = 0; + move(area.left() - margin, area.top() - margin); + setFixedSize(area.width() + 2* margin , heightForWidth( area.width() + 2 * margin ) ); +#ifdef Q_WS_X11 + int strut_height = height() - margin; + if( strut_height < 0 ) + strut_height = 0; + KWin::setStrut( winId(), 0, 0, strut_height, 0 ); +#endif + } +} + +int KMenuBar::block_resize = 0; + +void KMenuBar::resizeEvent( TQResizeEvent *e ) +{ + if( e->spontaneous() && d->topLevel && !d->fallback_mode ) + { + ++block_resize; // do not respond with configure request to ConfigureNotify event + TQMenuBar::resizeEvent(e); // to avoid possible infinite loop + --block_resize; + } + else + TQMenuBar::resizeEvent(e); +} + +void KMenuBar::setGeometry( const TQRect& r ) +{ + setGeometry( r.x(), r.y(), r.width(), r.height() ); +} + +void KMenuBar::setGeometry( int x, int y, int w, int h ) +{ + if( block_resize > 0 ) + { + move( x, y ); + return; + } + checkSize( w, h ); + if( geometry() != TQRect( x, y, w, h )) + TQMenuBar::setGeometry( x, y, w, h ); +} + +void KMenuBar::resize( int w, int h ) +{ + if( block_resize > 0 ) + return; + checkSize( w, h ); + if( size() != TQSize( w, h )) + TQMenuBar::resize( w, h ); +// kdDebug() << "RS:" << w << ":" << h << ":" << width() << ":" << height() << ":" << minimumWidth() << ":" << minimumHeight() << endl; +} + +void KMenuBar::checkSize( int& w, int& h ) +{ + if( !d->topLevel || d->fallback_mode ) + return; + TQSize s = sizeHint(); + w = s.width(); + h = s.height(); + // This is not done as setMinimumSize(), because that would set the minimum + // size in WM_NORMAL_HINTS, and KWin would not allow changing to smaller size + // anymore + w = KMAX( w, d->min_size.width()); + h = KMAX( h, d->min_size.height()); +} + +// QMenuBar's sizeHint() gives wrong size (insufficient width), which causes wrapping in the kicker applet +TQSize KMenuBar::sizeHint() const +{ + if( !d->topLevel || block_resize > 0 ) + return TQMenuBar::sizeHint(); + // Since TQMenuBar::sizeHint() may indirectly call resize(), + // avoid infinite recursion. + ++block_resize; + // find the minimum useful height, and enlarge the width until the menu fits in that height (one row) + int h = heightForWidth( 1000000 ); + int w = TQMenuBar::sizeHint().width(); + // optimization - don't call heightForWidth() too many times + while( heightForWidth( w + 12 ) > h ) + w += 12; + while( heightForWidth( w + 4 ) > h ) + w += 4; + while( heightForWidth( w ) > h ) + ++w; + --block_resize; + return TQSize( w, h ); +} + +#ifdef Q_WS_X11 +bool KMenuBar::x11Event( XEvent* ev ) +{ + if( ev->type == ClientMessage && ev->xclient.message_type == msg_type_atom + && ev->xclient.window == winId()) + { + // TQMenuBar is trying really hard to keep the size it deems right. + // Forcing minimum size and blocking resizing to match parent size + // in checkResizingToParent() seem to be the only way to make + // KMenuBar keep the size it wants + d->min_size = TQSize( ev->xclient.data.l[ 1 ], ev->xclient.data.l[ 2 ] ); +// kdDebug() << "MINSIZE:" << d->min_size << endl; + updateMenuBarSize(); + return true; + } + return TQMenuBar::x11Event( ev ); +} +#endif + +void KMenuBar::updateMenuBarSize() + { + menuContentsChanged(); // trigger invalidating calculated size + resize( sizeHint()); // and resize to preferred size + } + +void KMenuBar::setFrameStyle( int style ) +{ + if( d->topLevel ) + d->frameStyle = style; + else + TQMenuBar::setFrameStyle( style ); +} + +void KMenuBar::setLineWidth( int width ) +{ + if( d->topLevel ) + d->lineWidth = width; + else + TQMenuBar::setLineWidth( width ); +} + +void KMenuBar::setMargin( int margin ) +{ + if( d->topLevel ) + d->margin = margin; + else + TQMenuBar::setMargin( margin ); +} + +void KMenuBar::closeEvent( TQCloseEvent* e ) +{ + if( d->topLevel ) + e->ignore(); // mainly for the fallback mode + else + TQMenuBar::closeEvent( e ); +} + +void KMenuBar::drawContents( TQPainter* p ) +{ + // Closes the BR77113 + // We need to overload this method to paint only the menu items + // This way when the KMenuBar is embedded in the menu applet it + // integrates correctly. + // + // Background mode and origin are set so late because of styles + // using the polish() method to modify these settings. + // + // Of course this hack can safely be removed when real transparency + // will be available + + if( !d->topLevel ) + { + TQMenuBar::drawContents(p); + } + else + { + bool up_enabled = isUpdatesEnabled(); + BackgroundMode bg_mode = backgroundMode(); + BackgroundOrigin bg_origin = backgroundOrigin(); + + setUpdatesEnabled(false); + setBackgroundMode(X11ParentRelative); + setBackgroundOrigin(WindowOrigin); + + p->eraseRect( rect() ); + erase(); + + TQColorGroup g = colorGroup(); + bool e; + + for ( int i=0; i<(int)count(); i++ ) + { + TQMenuItem *mi = findItem( idAt( i ) ); + + if ( !mi->text().isNull() || mi->pixmap() ) + { + TQRect r = itemRect(i); + if(r.isEmpty() || !mi->isVisible()) + continue; + + e = mi->isEnabledAndVisible(); + if ( e ) + g = isEnabled() ? ( isActiveWindow() ? palette().active() : + palette().inactive() ) : palette().disabled(); + else + g = palette().disabled(); + + bool item_active = ( actItem == i ); + + p->setClipRect(r); + + if( item_active ) + { + TQStyle::SFlags flags = TQStyle::Style_Default; + if (isEnabled() && e) + flags |= TQStyle::Style_Enabled; + if ( item_active ) + flags |= TQStyle::Style_Active; + if ( item_active && actItemDown ) + flags |= TQStyle::Style_Down; + flags |= TQStyle::Style_HasFocus; + + style().drawControl(TQStyle::CE_MenuBarItem, p, this, + r, g, flags, TQStyleOption(mi)); + } + else + { + style().drawItem(p, r, AlignCenter | AlignVCenter | ShowPrefix, + g, e, mi->pixmap(), mi->text()); + } + } + } + + setBackgroundOrigin(bg_origin); + setBackgroundMode(bg_mode); + setUpdatesEnabled(up_enabled); + } +} + +void KMenuBar::virtual_hook( int, void* ) +{ /*BASE::virtual_hook( id, data );*/ } + +#include "tdemenubar.moc" diff --git a/tdeui/tdemenubar.h b/tdeui/tdemenubar.h new file mode 100644 index 000000000..e657671e3 --- /dev/null +++ b/tdeui/tdemenubar.h @@ -0,0 +1,114 @@ +/* This file is part of the KDE libraries + Copyright (C) 1997, 1998, 1999, 2000 Sven Radej (radej@kde.org) + Copyright (C) 1997, 1998, 1999, 2000 Matthias Ettrich (ettrich@kde.org) + Copyright (C) 1999, 2000 Daniel "Mosfet" Duley (mosfet@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. +*/ + +//$Id$ + +#ifndef _KMENUBAR_H +#define _KMENUBAR_H + +#include + +#include + +/** + * %KDE Style-able menubar. + * + * This is required since TQMenuBar is currently not handled by + * TQStyle. + * + * @author Daniel "Mosfet" Duley. + * @version $Id$ +*/ + +class TDEUI_EXPORT KMenuBar : public TQMenuBar +{ + Q_OBJECT + +public: + + KMenuBar (TQWidget *parent=0, const char *name=0); + ~KMenuBar (); + + /** + * This controls whether or not this menubar will be a top-level + * bar similar to the way Macintosh handles menubars. This + * overrides any global config settings. + * + * Keep in mind that it is probably a really bad idea to use this + * unless you really know what you're doing. A feature like a + * top-level menubar is one that should really be shared by all + * applications. If your app is the only one with a top-level + * bar, then things might look very... odd. + * + * This is included only for those people that @p do know that + * they need to use it. + * + * @param top_level If set to true, then this menubar will be a + * top-level menu + */ + void setTopLevelMenu(bool top_level = true); + + /** + * Is our menubar a top-level (Macintosh style) menubar? + * + * @return True if it is top-level. + */ + bool isTopLevelMenu() const; + + // TT are overloading virtuals :( + virtual void setGeometry( const TQRect &r ); + virtual void setGeometry( int x, int y, int w, int h ); + virtual void resize( int w, int h ); + void resize( const TQSize& s ) { TQMenuBar::resize( s ); } + + virtual void show(); + virtual void setFrameStyle( int ); + virtual void setLineWidth( int ); + virtual void setMargin( int ); + virtual TQSize sizeHint() const; +protected slots: + void slotReadConfig(); +protected: + virtual void showEvent( TQShowEvent* ); + virtual void resizeEvent( TQResizeEvent* ); + virtual bool eventFilter(TQObject *, TQEvent *); +#ifdef Q_WS_X11 + virtual bool x11Event( XEvent* ); +#endif + virtual void closeEvent( TQCloseEvent* ); + virtual void drawContents( TQPainter* ); +private slots: + void updateFallbackSize(); + void selectionTimeout(); +private: + void setTopLevelMenuInternal(bool top_level); + void updateMenuBarSize(); + void checkSize( int& w, int& h ); + static int block_resize; +protected: + virtual void virtual_hook( int id, void* data ); +private: + class KMenuBarPrivate; + KMenuBarPrivate *d; +}; + +#endif diff --git a/tdeui/tdemessagebox.cpp b/tdeui/tdemessagebox.cpp new file mode 100644 index 000000000..3208e94d8 --- /dev/null +++ b/tdeui/tdemessagebox.cpp @@ -0,0 +1,1071 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Waldo Bastian (bastian@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; version 2 + of the License. + + 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. +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef Q_WS_X11 +#include +#endif + + /** + * Easy MessageBox Dialog. + * + * Provides convenience functions for some i18n'ed standard dialogs, + * as well as audible notification via @ref KNotifyClient + * + * @author Waldo Bastian (bastian@kde.org) + */ + +static bool KMessageBox_queue = false; + +static TQPixmap themedMessageBoxIcon(TQMessageBox::Icon icon) +{ + TQString icon_name; + + switch(icon) + { + case TQMessageBox::NoIcon: + return TQPixmap(); + break; + case TQMessageBox::Information: + icon_name = "messagebox_info"; + break; + case TQMessageBox::Warning: + icon_name = "messagebox_warning"; + break; + case TQMessageBox::Critical: + icon_name = "messagebox_critical"; + break; + default: + break; + } + + TQPixmap ret = TDEGlobal::iconLoader()->loadIcon(icon_name, TDEIcon::NoGroup, TDEIcon::SizeMedium, TDEIcon::DefaultState, 0, true); + + if (ret.isNull()) + return TQMessageBox::standardIcon(icon); + else + return ret; +} + +static void sendNotification( TQString message, + const TQStringList& strlist, + TQMessageBox::Icon icon, + WId parent_id ) +{ + // create the message for KNotify + TQString messageType; + switch ( icon ) + { + case TQMessageBox::Warning: + messageType = "messageWarning"; + break; + case TQMessageBox::Critical: + messageType = "messageCritical"; + break; + case TQMessageBox::Question: + messageType = "messageQuestion"; + break; + default: + messageType = "messageInformation"; + break; + } + + if ( !strlist.isEmpty() ) + { + for ( TQStringList::ConstIterator it = strlist.begin(); it != strlist.end(); ++it ) + message += "\n" + *it; + } + + if ( !message.isEmpty() ) + KNotifyClient::event( (int)parent_id, messageType, message ); +} + +static TQString qrichtextify( const TQString& text ) +{ + if ( text.isEmpty() || text[0] == '<' ) + return text; + + TQStringList lines = TQStringList::split('\n', text); + for(TQStringList::Iterator it = lines.begin(); it != lines.end(); ++it) + { + *it = TQStyleSheet::convertFromPlainText( *it, TQStyleSheetItem::WhiteSpaceNormal ); + } + + return lines.join(TQString::null); +} + +int KMessageBox::createKMessageBox(KDialogBase *dialog, TQMessageBox::Icon icon, + const TQString &text, const TQStringList &strlist, + const TQString &ask, bool *checkboxReturn, + int options, const TQString &details) +{ + return createKMessageBox(dialog, themedMessageBoxIcon(icon), text, strlist, + ask, checkboxReturn, options, details, icon); +} + +int KMessageBox::createKMessageBox(KDialogBase *dialog, TQPixmap icon, + const TQString &text, const TQStringList &strlist, + const TQString &ask, bool *checkboxReturn, int options, + const TQString &details, TQMessageBox::Icon notifyType) +{ + TQVBox *topcontents = new TQVBox (dialog); + topcontents->setSpacing(KDialog::spacingHint()*2); + topcontents->setMargin(KDialog::marginHint()); + + TQWidget *contents = new TQWidget(topcontents); + TQHBoxLayout * lay = new TQHBoxLayout(contents); + lay->setSpacing(KDialog::spacingHint()); + + TQLabel *label1 = new TQLabel( contents); + + if (!icon.isNull()) + label1->setPixmap(icon); + + lay->addWidget( label1, 0, Qt::AlignCenter ); + lay->addSpacing(KDialog::spacingHint()); + // Enforce

text

otherwise the word-wrap doesn't work well + TQString qt_text = qrichtextify( text ); + + int pref_width = 0; + int pref_height = 0; + // Calculate a proper size for the text. + { + TQSimpleRichText rt(qt_text, dialog->font()); + TQRect d = TDEGlobalSettings::desktopGeometry(dialog); + + pref_width = d.width() / 3; + rt.setWidth(pref_width); + int used_width = rt.widthUsed(); + pref_height = rt.height(); + if (3*pref_height > 2*d.height()) + { + // Very high dialog.. make it wider + pref_width = d.width() / 2; + rt.setWidth(pref_width); + used_width = rt.widthUsed(); + pref_height = rt.height(); + } + if (used_width <= pref_width) + { + while(true) + { + int new_width = (used_width * 9) / 10; + rt.setWidth(new_width); + int new_height = rt.height(); + if (new_height > pref_height) + break; + used_width = rt.widthUsed(); + if (used_width > new_width) + break; + } + pref_width = used_width; + } + else + { + if (used_width > (pref_width *2)) + pref_width = pref_width *2; + else + pref_width = used_width; + } + } + KActiveLabel *label2 = new KActiveLabel( qt_text, contents ); + if (!(options & KMessageBox::AllowLink)) + { + TQObject::disconnect(label2, TQT_SIGNAL(linkClicked(const TQString &)), + label2, TQT_SLOT(openLink(const TQString &))); + } + + // We add 10 pixels extra to compensate for some KActiveLabel margins. + // TODO: find out why this is 10. + label2->setFixedSize(TQSize(pref_width+10, pref_height)); + lay->addWidget( label2 ); + lay->addStretch(); + + TDEListBox *listbox = 0; + if (!strlist.isEmpty()) + { + listbox=new TDEListBox( topcontents ); + listbox->insertStringList( strlist ); + listbox->setSelectionMode( TQListBox::NoSelection ); + topcontents->setStretchFactor(listbox, 1); + } + + TQGuardedPtr checkbox = 0; + if (!ask.isEmpty()) + { + checkbox = new TQCheckBox(ask, topcontents); + if (checkboxReturn) + checkbox->setChecked(*checkboxReturn); + } + + if (!details.isEmpty()) + { + TQVGroupBox *detailsGroup = new TQVGroupBox( i18n("Details"), dialog); + if ( details.length() < 512 ) { + KActiveLabel *label3 = new KActiveLabel(qrichtextify(details), + detailsGroup); + label3->setMinimumSize(label3->sizeHint()); + if (!(options & KMessageBox::AllowLink)) + { + TQObject::disconnect(label3, TQT_SIGNAL(linkClicked(const TQString &)), + label3, TQT_SLOT(openLink(const TQString &))); + } + } else { + TQTextEdit* te = new TQTextEdit(details, TQString::null, detailsGroup); + te->setReadOnly( true ); + te->setMinimumHeight( te->fontMetrics().lineSpacing() * 11 ); + } + dialog->setDetailsWidget(detailsGroup); + } + + dialog->setMainWidget(topcontents); + dialog->enableButtonSeparator(false); + if (!listbox) + dialog->disableResize(); + + const KDialogBase::ButtonCode buttons[] = { + KDialogBase::Help, + KDialogBase::Default, + KDialogBase::Ok, + KDialogBase::Apply, + KDialogBase::Try, + KDialogBase::Cancel, + KDialogBase::Close, + KDialogBase::User1, + KDialogBase::User2, + KDialogBase::User3, + KDialogBase::No, + KDialogBase::Yes, + KDialogBase::Details }; + for( unsigned int i = 0; + i < sizeof( buttons )/sizeof( buttons[ 0 ] ); + ++i ) + if( TQPushButton* btn = dialog->actionButton( buttons[ i ] )) + if( btn->isDefault()) + btn->setFocus(); + + if ( (options & KMessageBox::Notify) ) + sendNotification( text, strlist, notifyType, dialog->topLevelWidget()->winId()); + + if (KMessageBox_queue) + { + KDialogQueue::queueDialog(dialog); + return KMessageBox::Cancel; // We have to return something. + } + + if ( (options & KMessageBox::NoExec) ) + { + return KMessageBox::Cancel; // We have to return something. + } + + // We use a TQGuardedPtr because the dialog may get deleted + // during exec() if the parent of the dialog gets deleted. + // In that case the guarded ptr will reset to 0. + TQGuardedPtr guardedDialog = dialog; + + int result = guardedDialog->exec(); + if (checkbox && checkboxReturn) + *checkboxReturn = checkbox->isChecked(); + delete (KDialogBase *) guardedDialog; + return result; +} + +int +KMessageBox::questionYesNo(TQWidget *parent, const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return questionYesNoList(parent, text, TQStringList(), caption, + buttonYes, buttonNo, dontAskAgainName, options); +} + +int +KMessageBox::questionYesNoWId(WId parent_id, const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return questionYesNoListWId(parent_id, text, TQStringList(), caption, + buttonYes, buttonNo, dontAskAgainName, options); +} + +bool +KMessageBox::shouldBeShownYesNo(const TQString &dontShowAgainName, + ButtonCode &result) +{ + if ( dontShowAgainName.isEmpty() ) return true; + TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); + TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); + TDEConfigGroupSaver saver( config, grpNotifMsgs ); + TQString dontAsk = config->readEntry(dontShowAgainName).lower(); + if (dontAsk == "yes") { + result = Yes; + return false; + } + if (dontAsk == "no") { + result = No; + return false; + } + return true; +} + +bool +KMessageBox::shouldBeShownContinue(const TQString &dontShowAgainName) +{ + if ( dontShowAgainName.isEmpty() ) return true; + TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); + TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); + TDEConfigGroupSaver saver( config, grpNotifMsgs ); + return config->readBoolEntry(dontShowAgainName, true); +} + +void +KMessageBox::saveDontShowAgainYesNo(const TQString &dontShowAgainName, + ButtonCode result) +{ + if ( dontShowAgainName.isEmpty() ) return; + TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); + TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); + TDEConfigGroupSaver saver( config, grpNotifMsgs ); + config->writeEntry( dontShowAgainName, result==Yes ? "yes" : "no", true, (dontShowAgainName[0] == ':')); + config->sync(); +} + +void +KMessageBox::saveDontShowAgainContinue(const TQString &dontShowAgainName) +{ + if ( dontShowAgainName.isEmpty() ) return; + TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); + TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); + TDEConfigGroupSaver saver( config, grpNotifMsgs ); + config->writeEntry( dontShowAgainName, false, true, (dontShowAgainName[0] == ':')); + config->sync(); +} + +TDEConfig* KMessageBox::againConfig = NULL; +void +KMessageBox::setDontShowAskAgainConfig(TDEConfig* cfg) +{ + againConfig = cfg; +} + +int +KMessageBox::questionYesNoList(TQWidget *parent, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ // in order to avoid code duplication, convert to WId, it will be converted back + return questionYesNoListWId( parent ? parent->winId() : 0, text, strlist, + caption, buttonYes, buttonNo, dontAskAgainName, options ); +} + +int +KMessageBox::questionYesNoListWId(WId parent_id, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + ButtonCode res; + if ( !shouldBeShownYesNo(dontAskAgainName, res) ) + return res; + + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Question") : caption, + KDialogBase::Yes | KDialogBase::No, + KDialogBase::Yes, KDialogBase::No, + parent, "questionYesNo", true, true, + buttonYes, buttonNo); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + bool checkboxResult = false; + int result = createKMessageBox(dialog, TQMessageBox::Information, text, strlist, + dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), + &checkboxResult, options); + res = (result==KDialogBase::Yes ? Yes : No); + + if (checkboxResult) + saveDontShowAgainYesNo(dontAskAgainName, res); + return res; +} + +int +KMessageBox::questionYesNoCancel(TQWidget *parent, + const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return questionYesNoCancelWId( parent ? parent->winId() : 0, text, caption, buttonYes, buttonNo, + dontAskAgainName, options ); +} + +int +KMessageBox::questionYesNoCancelWId(WId parent_id, + const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + ButtonCode res; + if ( !shouldBeShownYesNo(dontAskAgainName, res) ) + return res; + + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Question") : caption, + KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel, + KDialogBase::Yes, KDialogBase::Cancel, + parent, "questionYesNoCancel", true, true, + buttonYes, buttonNo); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + bool checkboxResult = false; + int result = createKMessageBox(dialog, TQMessageBox::Information, + text, TQStringList(), + dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), + &checkboxResult, options); + if ( result==KDialogBase::Cancel ) return Cancel; + res = (result==KDialogBase::Yes ? Yes : No); + + if (checkboxResult) + saveDontShowAgainYesNo(dontAskAgainName, res); + return res; +} + +int +KMessageBox::warningYesNo(TQWidget *parent, const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return warningYesNoList(parent, text, TQStringList(), caption, + buttonYes, buttonNo, dontAskAgainName, options); +} + +int +KMessageBox::warningYesNoWId(WId parent_id, const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return warningYesNoListWId(parent_id, text, TQStringList(), caption, + buttonYes, buttonNo, dontAskAgainName, options); +} + +int +KMessageBox::warningYesNoList(TQWidget *parent, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return warningYesNoListWId( parent ? parent->winId() : 0, text, strlist, caption, + buttonYes, buttonNo, dontAskAgainName, options ); +} + +int +KMessageBox::warningYesNoListWId(WId parent_id, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + // warningYesNo and warningYesNoList are always "dangerous" + // ### Remove this line for KDE 4, when the 'options' default parameter + // takes effects. + options |= Dangerous; + + ButtonCode res; + if ( !shouldBeShownYesNo(dontAskAgainName, res) ) + return res; + + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Warning") : caption, + KDialogBase::Yes | KDialogBase::No, + KDialogBase::No, KDialogBase::No, + parent, "warningYesNoList", true, true, + buttonYes, buttonNo); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + bool checkboxResult = false; + int result = createKMessageBox(dialog, TQMessageBox::Warning, text, strlist, + dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), + &checkboxResult, options); + res = (result==KDialogBase::Yes ? Yes : No); + + if (checkboxResult) + saveDontShowAgainYesNo(dontAskAgainName, res); + return res; +} + +int +KMessageBox::warningContinueCancel(TQWidget *parent, + const TQString &text, + const TQString &caption, + const KGuiItem &buttonContinue, + const TQString &dontAskAgainName, + int options) +{ + return warningContinueCancelList(parent, text, TQStringList(), caption, + buttonContinue, dontAskAgainName, options); +} + +int +KMessageBox::warningContinueCancelWId(WId parent_id, + const TQString &text, + const TQString &caption, + const KGuiItem &buttonContinue, + const TQString &dontAskAgainName, + int options) +{ + return warningContinueCancelListWId(parent_id, text, TQStringList(), caption, + buttonContinue, dontAskAgainName, options); +} + +int +KMessageBox::warningContinueCancelList(TQWidget *parent, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonContinue, + const TQString &dontAskAgainName, + int options) +{ + return warningContinueCancelListWId( parent ? parent->winId() : 0, text, strlist, + caption, buttonContinue, dontAskAgainName, options ); +} + +int +KMessageBox::warningContinueCancelListWId(WId parent_id, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonContinue, + const TQString &dontAskAgainName, + int options) +{ + if ( !shouldBeShownContinue(dontAskAgainName) ) + return Continue; + + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Warning") : caption, + KDialogBase::Yes | KDialogBase::No, + KDialogBase::Yes, KDialogBase::No, + parent, "warningYesNo", true, true, + buttonContinue, KStdGuiItem::cancel() ); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + bool checkboxResult = false; + int result = createKMessageBox(dialog, TQMessageBox::Warning, text, strlist, + dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), + &checkboxResult, options); + + if ( result==KDialogBase::No ) + return Cancel; + if (checkboxResult) + saveDontShowAgainContinue(dontAskAgainName); + return Continue; +} + +int +KMessageBox::warningYesNoCancel(TQWidget *parent, const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return warningYesNoCancelList(parent, text, TQStringList(), caption, + buttonYes, buttonNo, dontAskAgainName, options); +} + +int +KMessageBox::warningYesNoCancelWId(WId parent_id, const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return warningYesNoCancelListWId(parent_id, text, TQStringList(), caption, + buttonYes, buttonNo, dontAskAgainName, options); +} + +int +KMessageBox::warningYesNoCancelList(TQWidget *parent, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + return warningYesNoCancelListWId( parent ? parent->winId() : 0, text, strlist, + caption, buttonYes, buttonNo, dontAskAgainName, options ); +} + +int +KMessageBox::warningYesNoCancelListWId(WId parent_id, const TQString &text, + const TQStringList &strlist, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontAskAgainName, + int options) +{ + ButtonCode res; + if ( !shouldBeShownYesNo(dontAskAgainName, res) ) + return res; + + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Warning") : caption, + KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel, + KDialogBase::Yes, KDialogBase::Cancel, + parent, "warningYesNoCancel", true, true, + buttonYes, buttonNo); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + bool checkboxResult = false; + int result = createKMessageBox(dialog, TQMessageBox::Warning, text, strlist, + dontAskAgainName.isEmpty() ? TQString::null : i18n("Do not ask again"), + &checkboxResult, options); + if ( result==KDialogBase::Cancel ) return Cancel; + res = (result==KDialogBase::Yes ? Yes : No); + + if (checkboxResult) + saveDontShowAgainYesNo(dontAskAgainName, res); + return res; +} + +void +KMessageBox::error(TQWidget *parent, const TQString &text, + const TQString &caption, int options) +{ + return errorListWId( parent ? parent->winId() : 0, text, TQStringList(), caption, options ); +} + +void +KMessageBox::errorWId(WId parent_id, const TQString &text, + const TQString &caption, int options) +{ + errorListWId( parent_id, text, TQStringList(), caption, options ); +} + +void +KMessageBox::errorList(TQWidget *parent, const TQString &text, const TQStringList &strlist, + const TQString &caption, int options) +{ + return errorListWId( parent ? parent->winId() : 0, text, strlist, caption, options ); +} + +void +KMessageBox::errorListWId(WId parent_id, const TQString &text, const TQStringList &strlist, + const TQString &caption, int options) +{ + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Error") : caption, + KDialogBase::Yes, + KDialogBase::Yes, KDialogBase::Yes, + parent, "error", true, true, + KStdGuiItem::ok() ); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + createKMessageBox(dialog, TQMessageBox::Critical, text, strlist, TQString::null, 0, options); +} + +void +KMessageBox::detailedError(TQWidget *parent, const TQString &text, + const TQString &details, + const TQString &caption, int options) +{ + return detailedErrorWId( parent ? parent->winId() : 0, text, details, caption, options ); +} + +void +KMessageBox::detailedErrorWId(WId parent_id, const TQString &text, + const TQString &details, + const TQString &caption, int options) +{ + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Error") : caption, + KDialogBase::Yes | KDialogBase::Details, + KDialogBase::Yes, KDialogBase::Yes, + parent, "error", true, true, + KStdGuiItem::ok() ); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + createKMessageBox(dialog, TQMessageBox::Critical, text, TQStringList(), TQString::null, 0, options, details); +} + +void +KMessageBox::queuedDetailedError(TQWidget *parent, const TQString &text, + const TQString &details, + const TQString &caption) +{ + return queuedDetailedErrorWId( parent ? parent->winId() : 0, text, details, caption ); +} + +void +KMessageBox::queuedDetailedErrorWId(WId parent_id, const TQString &text, + const TQString &details, + const TQString &caption) +{ + KMessageBox_queue = true; + (void) detailedErrorWId(parent_id, text, details, caption); + KMessageBox_queue = false; +} + + +void +KMessageBox::sorry(TQWidget *parent, const TQString &text, + const TQString &caption, int options) +{ + return sorryWId( parent ? parent->winId() : 0, text, caption, options ); +} + +void +KMessageBox::sorryWId(WId parent_id, const TQString &text, + const TQString &caption, int options) +{ + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Sorry") : caption, + KDialogBase::Yes, + KDialogBase::Yes, KDialogBase::Yes, + parent, "sorry", true, true, + KStdGuiItem::ok() ); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + createKMessageBox(dialog, TQMessageBox::Warning, text, TQStringList(), TQString::null, 0, options); +} + +void +KMessageBox::detailedSorry(TQWidget *parent, const TQString &text, + const TQString &details, + const TQString &caption, int options) +{ + return detailedSorryWId( parent ? parent->winId() : 0, text, details, caption, options ); +} + +void +KMessageBox::detailedSorryWId(WId parent_id, const TQString &text, + const TQString &details, + const TQString &caption, int options) +{ + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Sorry") : caption, + KDialogBase::Yes | KDialogBase::Details, + KDialogBase::Yes, KDialogBase::Yes, + parent, "sorry", true, true, + KStdGuiItem::ok() ); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + createKMessageBox(dialog, TQMessageBox::Warning, text, TQStringList(), TQString::null, 0, options, details); +} + +void +KMessageBox::information(TQWidget *parent,const TQString &text, + const TQString &caption, const TQString &dontShowAgainName, int options) +{ + informationList(parent, text, TQStringList(), caption, dontShowAgainName, options); +} + +void +KMessageBox::informationWId(WId parent_id,const TQString &text, + const TQString &caption, const TQString &dontShowAgainName, int options) +{ + informationListWId(parent_id, text, TQStringList(), caption, dontShowAgainName, options); +} + +void +KMessageBox::informationList(TQWidget *parent,const TQString &text, const TQStringList & strlist, + const TQString &caption, const TQString &dontShowAgainName, int options) +{ + return informationListWId( parent ? parent->winId() : 0, text, strlist, caption, + dontShowAgainName, options ); +} + +void +KMessageBox::informationListWId(WId parent_id,const TQString &text, const TQStringList & strlist, + const TQString &caption, const TQString &dontShowAgainName, int options) +{ + if ( !shouldBeShownContinue(dontShowAgainName) ) + return; + + TQWidget* parent = TQT_TQWIDGET(TQWidget::find( parent_id )); + KDialogBase *dialog= new KDialogBase( + caption.isEmpty() ? i18n("Information") : caption, + KDialogBase::Yes, + KDialogBase::Yes, KDialogBase::Yes, + parent, "information", true, true, + KStdGuiItem::ok() ); + if( options & PlainCaption ) + dialog->setPlainCaption( caption ); +#ifdef Q_WS_X11 + if( parent == NULL && parent_id ) + XSetTransientForHint( tqt_xdisplay(), dialog->winId(), parent_id ); +#endif + + bool checkboxResult = false; + + createKMessageBox(dialog, TQMessageBox::Information, text, strlist, + dontShowAgainName.isEmpty() ? TQString::null : i18n("Do not show this message again"), + &checkboxResult, options); + + if (checkboxResult) + saveDontShowAgainContinue(dontShowAgainName); +} + +void +KMessageBox::enableAllMessages() +{ + TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); + TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); + if (!config->hasGroup(grpNotifMsgs)) + return; + + TDEConfigGroupSaver saver( config, grpNotifMsgs ); + + typedef TQMap configMap; + + configMap map = config->entryMap(grpNotifMsgs); + + configMap::Iterator it; + for (it = map.begin(); it != map.end(); ++it) + config->deleteEntry( it.key() ); + config->sync(); +} + +void +KMessageBox::enableMessage(const TQString &dontShowAgainName) +{ + TDEConfig *config = againConfig ? againConfig : TDEGlobal::config(); + TQString grpNotifMsgs = TQString::fromLatin1("Notification Messages"); + if (!config->hasGroup(grpNotifMsgs)) + return; + + TDEConfigGroupSaver saver( config, grpNotifMsgs ); + + config->deleteEntry(dontShowAgainName); + config->sync(); +} + +void +KMessageBox::about(TQWidget *parent, const TQString &text, + const TQString &caption, int options) +{ + TQString _caption = caption; + if (_caption.isEmpty()) + _caption = i18n("About %1").arg(kapp->caption()); + + KDialogBase *dialog = new KDialogBase( + caption, + KDialogBase::Yes, + KDialogBase::Yes, KDialogBase::Yes, + parent, "about", true, true, + KStdGuiItem::ok() ); + + TQPixmap ret = TDEApplication::kApplication()->icon(); + if (ret.isNull()) + ret = TQMessageBox::standardIcon(TQMessageBox::Information); + dialog->setIcon(ret); + + createKMessageBox(dialog, ret, text, TQStringList(), TQString::null, 0, options); + + return; +} + +int KMessageBox::messageBox( TQWidget *parent, DialogType type, const TQString &text, + const TQString &caption, const KGuiItem &buttonYes, + const KGuiItem &buttonNo, const TQString &dontShowAskAgainName, + int options ) +{ + return messageBoxWId( parent ? parent->winId() : 0, type, text, caption, + buttonYes, buttonNo, dontShowAskAgainName, options ); +} + +int KMessageBox::messageBox( TQWidget *parent, DialogType type, const TQString &text, + const TQString &caption, const KGuiItem &buttonYes, + const KGuiItem &buttonNo, int options ) +{ + return messageBoxWId( parent ? parent->winId() : 0, type, text, caption, + buttonYes, buttonNo, TQString::null, options ); +} + +int KMessageBox::messageBoxWId( WId parent_id, DialogType type, const TQString &text, + const TQString &caption, const KGuiItem &buttonYes, + const KGuiItem &buttonNo, const TQString &dontShow, + int options ) +{ + switch (type) { + case QuestionYesNo: + return KMessageBox::questionYesNoWId( parent_id, + text, caption, buttonYes, buttonNo, dontShow, options ); + case QuestionYesNoCancel: + return KMessageBox::questionYesNoCancelWId( parent_id, + text, caption, buttonYes, buttonNo, dontShow, options ); + case WarningYesNo: + return KMessageBox::warningYesNoWId( parent_id, + text, caption, buttonYes, buttonNo, dontShow, options ); + case WarningContinueCancel: + return KMessageBox::warningContinueCancelWId( parent_id, + text, caption, buttonYes.text(), dontShow, options ); + case WarningYesNoCancel: + return KMessageBox::warningYesNoCancelWId( parent_id, + text, caption, buttonYes, buttonNo, dontShow, options ); + case Information: + KMessageBox::informationWId( parent_id, + text, caption, dontShow, options ); + return KMessageBox::Ok; + + case Error: + KMessageBox::errorWId( parent_id, text, caption, options ); + return KMessageBox::Ok; + + case Sorry: + KMessageBox::sorryWId( parent_id, text, caption, options ); + return KMessageBox::Ok; + } + return KMessageBox::Cancel; +} + +void KMessageBox::queuedMessageBox( TQWidget *parent, DialogType type, const TQString &text, const TQString &caption, int options ) +{ + return queuedMessageBoxWId( parent ? parent->winId() : 0, type, text, caption, options ); +} + +void KMessageBox::queuedMessageBoxWId( WId parent_id, DialogType type, const TQString &text, const TQString &caption, int options ) +{ + KMessageBox_queue = true; + (void) messageBoxWId(parent_id, type, text, caption, KStdGuiItem::yes(), + KStdGuiItem::no(), TQString::null, options); + KMessageBox_queue = false; +} + +void KMessageBox::queuedMessageBox( TQWidget *parent, DialogType type, const TQString &text, const TQString &caption ) +{ + return queuedMessageBoxWId( parent ? parent->winId() : 0, type, text, caption ); +} + +void KMessageBox::queuedMessageBoxWId( WId parent_id, DialogType type, const TQString &text, const TQString &caption ) +{ + KMessageBox_queue = true; + (void) messageBoxWId(parent_id, type, text, caption); + KMessageBox_queue = false; +} diff --git a/tdeui/tdemessagebox.h b/tdeui/tdemessagebox.h new file mode 100644 index 000000000..b7724f5ce --- /dev/null +++ b/tdeui/tdemessagebox.h @@ -0,0 +1,1166 @@ +/* This file is part of the KDE libraries + Copyright (C) 1999 Waldo Bastian (bastian@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; version 2 + of the License. + + 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. +*/ +#ifndef _KMESSAGEBOX_H_ +#define _KMESSAGEBOX_H_ + +#include +#include + +#include +#include + +class TQWidget; +class TQStringList; +class TDEConfig; +class KDialogBase; + + /** + * Easy message dialog box. + * + * Provides convenience functions for some i18n'ed standard dialogs. + * + * The text in message boxes is wrapped automatically. The text may either + * be plaintext or richtext. If the text is plaintext, a newline-character + * may be used to indicate the end of a paragraph. + * + * @author Waldo Bastian (bastian@kde.org) + */ +class TDEUI_EXPORT KMessageBox +{ +public: + /** + * Button types. + **/ + enum ButtonCode + { + Ok = 1, + Cancel = 2, + Yes = 3, + No = 4, + Continue = 5 + }; + + enum DialogType + { + QuestionYesNo = 1, + WarningYesNo = 2, + WarningContinueCancel = 3, + WarningYesNoCancel = 4, + Information = 5, + // Reserved for: SSLMessageBox = 6 + Sorry = 7, + Error = 8, + QuestionYesNoCancel = 9 + }; + + enum OptionsType + { + Notify = 1, ///< Emit a KNotifyClient event + AllowLink = 2, ///< The message may contain links. + Dangerous = 4, ///< The action to be confirmed by the dialog is a potentially destructive one + PlainCaption = 8, /**< Do not use TDEApplication::makeStdCaption() + @since 3.4 + */ + NoExec = 16 /**< Do not call exec() in createKMessageBox() + @since 3.4 + */ + }; + + /** + * Display a simple "question" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Question"). + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontAskAgainName If provided, a checkbox is added with which + * further confirmation can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned + * if the No-button is pressed. + * + * To be used for questions like "Do you have a printer?" + * + * The default button is "Yes". Pressing "Esc" selects "No". + */ + + static int questionYesNo(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int questionYesNoWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + /** + * Display a simple "question" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Question"). + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontAskAgainName If provided, a checkbox is added with which + * further confirmation can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned + * if the No-button is pressed. + * + * To be used for questions like "Do you want to discard the message or save it for later?", + * + * The default button is "Yes". Pressing "Esc" selects "Cancel". + * + * NOTE: The cancel button will always have the i18n'ed text '&Cancel'. + */ + + static int questionYesNoCancel(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int questionYesNoCancelWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * Display a "question" dialog with a listbox to show information to the user + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. If the list is + * empty, it doesn't show any listbox, working as questionYesNo. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Question"). + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontAskAgainName If provided, a checkbox is added with which + * further confirmation can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned + * if the No-button is pressed. + * + * To be used for questions like "Do you really want to delete these files?" + * And show the user exactly which files are going to be deleted in case + * he presses "Yes" + * + * The default button is "Yes". Pressing "Esc" selects "No". + */ + + static int questionYesNoList(TQWidget *parent, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int questionYesNoListWId(WId parent_id, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * Display a "warning" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Warning"). + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontAskAgainName If provided, a checkbox is added with which + * further confirmation can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * @return @p Yes is returned if the Yes-button is pressed. @p No is returned + * if the No-button is pressed. + * + * To be used for questions "Shall I update your configuration?" + * The text should explain the implication of both options. + * + * The default button is "No". Pressing "Esc" selects "No". + */ + static int warningYesNo(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify | Dangerous); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int warningYesNoWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify | Dangerous); + + /** + * Display a "warning" dialog with a listbox to show information to the user + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. If the list is + * empty, it doesn't show any listbox, working as questionYesNo. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Question"). + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontAskAgainName If provided, a checkbox is added with which + * further confirmation can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * @return 'Yes' is returned if the Yes-button is pressed. 'No' is returned + * if the No-button is pressed. + * + * To be used for questions like "Do you really want to delete these files?" + * And show the user exactly which files are going to be deleted in case + * he presses "Yes" + * + * The default button is "No". Pressing "Esc" selects "No". + */ + + static int warningYesNoList(TQWidget *parent, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify | Dangerous); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int warningYesNoListWId(WId parent_id, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify | Dangerous); + + /** + * Display a "warning" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Warning"). + * @param buttonContinue The text for the first button. + * @param dontAskAgainName If provided, a checkbox is added with which + * further confirmation can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * The second button always has the text "Cancel". + * + * @return @p Continue is returned if the Continue-button is pressed. + * @p Cancel is returned if the Cancel-button is pressed. + * + * To be used for questions like "You are about to Print. Are you sure?" + * the continueButton should then be labeled "Print". + * + * The default button is buttonContinue. Pressing "Esc" selects "Cancel". + */ + static int warningContinueCancel(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonContinue = KStdGuiItem::cont(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int warningContinueCancelWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonContinue = KStdGuiItem::cont(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * Display a "warning" dialog with a listbox to show information to the user. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. If the + * list is empty, it doesn't show any listbox, working + * as warningContinueCancel. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Warning"). + * @param buttonContinue The text for the first button. + * @param dontAskAgainName If provided, a checkbox is added with which + * further confirmation can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * + * @param options see OptionsType + * + * The second button always has the text "Cancel". + * + * @return @p Continue is returned if the Continue-button is pressed. + * @p Cancel is returned if the Cancel-button is pressed. + * + * To be used for questions like "You are about to Print. Are you sure?" + * the continueButton should then be labeled "Print". + * + * The default button is buttonContinue. Pressing "Esc" selects "Cancel". + */ + static int warningContinueCancelList(TQWidget *parent, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonContinue = KStdGuiItem::cont(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int warningContinueCancelListWId(WId parent_id, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonContinue = KStdGuiItem::cont(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * Display a Yes/No/Cancel "warning" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Warning"). + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontAskAgainName If provided, a checkbox is added with which + * further questions can be turned off. If turned off + * all questions will be automatically answered with the + * last answer (either Yes or No). + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * @return @p Yes is returned if the Yes-button is pressed. @p No is returned + * if the No-button is pressed. @p Cancel is retunred if the Cancel- + * button is pressed. + * + * To be used for questions "Do you want to save your changes?" + * The text should explain the implication of choosing 'No'. + * + * The default button is "Yes". Pressing "Esc" selects "Cancel" + * + * NOTE: The cancel button will always have the i18n'ed text '&Cancel'. + */ + + static int warningYesNoCancel(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int warningYesNoCancelWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * Display a Yes/No/Cancel "warning" dialog with a listbox to show information + * to the user. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. If the + * list is empty, it doesn't show any listbox, working + * as warningYesNoCancel. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Warning"). + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontAskAgainName If provided, a checkbox is added with which + * further questions can be turned off. If turned off + * all questions will be automatically answered with the + * last answer (either Yes or No). + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * If @p dontAskAgainName starts with a ':' then the setting + * is stored in the global config file. + * @param options see OptionsType + * + * @return @p Yes is returned if the Yes-button is pressed. @p No is returned + * if the No-button is pressed. @p Cancel is retunred if the Cancel- + * button is pressed. + * + * To be used for questions "Do you want to save your changes?" + * The text should explain the implication of choosing 'No'. + * + * The default button is "Yes". Pressing "Esc" selects "Cancel" + * + * NOTE: The cancel button will always have the i18n'ed text '&Cancel'. + * + * @since 3.2 + */ + static int warningYesNoCancelList(TQWidget *parent, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int warningYesNoCancelListWId(WId parent_id, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontAskAgainName = TQString::null, + int options = Notify); + + /** + * Display an "Error" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Error"). + * @param options see OptionsType + * + * Your program messed up and now it's time to inform the user. + * To be used for important things like "Sorry, I deleted your hard disk." + * + * If your program detects the action specified by the user is somehow + * not allowed, this should never be reported with error(). Use sorry() + * instead to explain to the user that this action is not allowed. + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * NOTE: The OK button will always have the i18n'ed text '&OK'. + */ + + static void error(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * + * @since 3.2 + */ + static void errorWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * Display an "Error" dialog with a listbox. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. If the + * list is empty, it doesn't show any listbox, working + * as error(). + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Error"). + * @param options see OptionsType + * + * Your program messed up and now it's time to inform the user. + * To be used for important things like "Sorry, I deleted your hard disk." + * + * If your program detects the action specified by the user is somehow + * not allowed, this should never be reported with error(). Use sorry() + * instead to explain to the user that this action is not allowed. + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * NOTE: The OK button will always have the i18n'ed text '&OK'. + * + * @since 3.4 + */ + + static void errorList(TQWidget *parent, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.4 + */ + + static void errorListWId(WId parent_id, + const TQString &text, + const TQStringList &strlist, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * Displays an "Error" dialog with a "Details >>" button. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param details Detailed message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Error"). + * @param options see OptionsType + * + * Your program messed up and now it's time to inform the user. + * To be used for important things like "Sorry, I deleted your hard disk." + * + * The @p details message can conatin additional information about + * the problem and can be shown on request to advanced/interested users. + * + * If your program detects the action specified by the user is somehow + * not allowed, this should never be reported with error(). Use sorry() + * instead to explain to the user that this action is not allowed. + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * NOTE: The OK button will always have the i18n'ed text '&OK'. + */ + static void detailedError(TQWidget *parent, + const TQString &text, + const TQString &details, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void detailedErrorWId(WId parent_id, + const TQString &text, + const TQString &details, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * Like detailedError + * + * This function will return immediately, the messagebox will be shown + * once the application enters an event loop and no other messagebox + * is being shown. + * + * Note that if the parent gets deleted, the messagebox will not be + * shown. + */ + static void queuedDetailedError( TQWidget *parent, + const TQString &text, + const TQString &details, + const TQString &caption = TQString::null); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void queuedDetailedErrorWId( WId parent_id, + const TQString &text, + const TQString &details, + const TQString &caption = TQString::null); + + /** + * Display an "Sorry" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Sorry"). + * @param options see OptionsType + * + * Either your program messed up and asks for understanding + * or your user did something stupid. + * + * To be used for small problems like + * "Sorry, I can't find the file you specified." + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * NOTE: The ok button will always have the i18n'ed text '&OK'. + */ + + static void sorry(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void sorryWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * Displays a "Sorry" dialog with a "Details >>" button. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param details Detailed message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Sorry"). + * @param options see OptionsType + * + * Either your program messed up and asks for understanding + * or your user did something stupid. + * + * To be used for small problems like + * "Sorry, I can't find the file you specified." + * + * And then @p details can contain something like + * "foobar.txt was not found in any of + * the following directories: + * /usr/bin,/usr/local/bin,/usr/sbin" + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * NOTE: The ok button will always have the i18n'ed text '&OK'. + */ + + static void detailedSorry(TQWidget *parent, + const TQString &text, + const TQString &details, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void detailedSorryWId(WId parent_id, + const TQString &text, + const TQString &details, + const TQString &caption = TQString::null, + int options = Notify); + + /** + * Display an "Information" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Information"). + * @param dontShowAgainName If provided, a checkbox is added with which + * further notifications can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * @param options see OptionsType + * + * + * Your program wants to tell the user something. + * To be used for things like: + * "Your bookmarks have been rearranged." + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * NOTE: The OK button will always have the i18n'ed text '&OK'. + */ + + static void information(TQWidget *parent, + const TQString &text, + const TQString &caption = TQString::null, + const TQString &dontShowAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void informationWId(WId parent_id, + const TQString &text, + const TQString &caption = TQString::null, + const TQString &dontShowAgainName = TQString::null, + int options = Notify); + + /** + * Display an "Information" dialog with a listbox. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. If the + * list is empty, it doesn't show any listbox, working + * as information. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("Information"). + * @param dontShowAgainName If provided, a checkbox is added with which + * further notifications can be turned off. + * The string is used to lookup and store the setting + * in the applications config file. + * The setting is stored in the "Notification Messages" group. + * @param options see OptionsType + * + * + * Your program wants to tell the user something. + * To be used for things like: + * "The following bookmarks have been rearranged:" + * + * The default button is "&OK". Pressing "Esc" selects the OK-button. + * + * NOTE: The OK button will always have the i18n'ed text '&OK'. + * @since 3.1 + */ + + static void informationList(TQWidget *parent, + const TQString &text, + const TQStringList & strlist, + const TQString &caption = TQString::null, + const TQString &dontShowAgainName = TQString::null, + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void informationListWId(WId parent_id, + const TQString &text, + const TQStringList & strlist, + const TQString &caption = TQString::null, + const TQString &dontShowAgainName = TQString::null, + int options = Notify); + + /** + * Enable all messages which have been turned off with the + * @p dontShowAgainName feature. + */ + static void enableAllMessages(); + + /** + * Re-enable a specific @p dontShowAgainName messages that had + * previously been turned off. + * @see saveDontShowAgainYesNo() + * @see saveDontShowAgainContinue() + * @since 3.2 + */ + static void enableMessage(const TQString &dontShowAgainName); + + /** + * Display an "About" dialog. + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param text Message string. + * @param caption Message box title. The application name is added to + * the title. The default title is i18n("About \"). + * @param options see OptionsType + * + * + * Your program wants to show some general information about the application + * like the authors's names and email addresses. + * + * The default button is "&OK". + * + * NOTE: The ok button will always have the i18n'ed text '&OK'. + */ + static void about(TQWidget *parent, + const TQString& text, + const TQString& caption = TQString::null, + int options = Notify); + + /** + * Alternate method to show a messagebox: + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel... + * @param text Message string. + * @param caption Message box title. + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param dontShowAskAgainName If provided, a checkbox is added with which + * further questions/informations can be turned off. If turned off + * all questions will be automatically answered with the + * last answer (either Yes or No), if the message box needs an answer. + * The string is used to lookup and store the setting + * in the applications config file. + * @param options see OptionsType + * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused. + * and for Information, none is used. + * @return a button code, as defined in KMessageBox. + */ + static int messageBox( TQWidget *parent, DialogType type, const TQString &text, + const TQString &caption, + const KGuiItem &buttonYes, + const KGuiItem &buttonNo, + const TQString &dontShowAskAgainName, + int options = Notify); + + /** + * Alternate method to show a messagebox: + * + * @param parent If @p parent is 0, then the message box becomes an + * application-global modal dialog box. If @p parent is a + * widget, the message box becomes modal relative to parent. + * @param type type of message box: QuestionYesNo, WarningYesNo, WarningContinueCancel... + * @param text Message string. + * @param caption Message box title. + * @param buttonYes The text for the first button. + * The default is i18n("&Yes"). + * @param buttonNo The text for the second button. + * The default is i18n("&No"). + * @param options see OptionsType + * Note: for ContinueCancel, buttonYes is the continue button and buttonNo is unused. + * and for Information, none is used. + * @return a button code, as defined in KMessageBox. + */ + // KDE4 - merge with above? + static int messageBox( TQWidget *parent, DialogType type, const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + int options = Notify); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static int messageBoxWId( WId parent_id, DialogType type, const TQString &text, + const TQString &caption = TQString::null, + const KGuiItem &buttonYes = KStdGuiItem::yes(), + const KGuiItem &buttonNo = KStdGuiItem::no(), + const TQString &dontShowAskAgainName = TQString::null, + int options = Notify); + + /** + * Like messageBox + * + * Only for message boxes of type Information, Sorry or Error. + * + * This function will return immediately, the messagebox will be shown + * once the application enters an event loop and no other messagebox + * is being shown. + * + * Note that if the parent gets deleted, the messagebox will not be + * shown. + */ + static void queuedMessageBox( TQWidget *parent, + DialogType type, const TQString &text, + const TQString &caption, + int options ); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void queuedMessageBoxWId( WId parent_id, + DialogType type, const TQString &text, + const TQString &caption, + int options ); + + /** + * @overload + * + * This is an overloaded member function, provided for convenience. + * It behaves essentially like the above function. + */ + static void queuedMessageBox( TQWidget *parent, + DialogType type, const TQString &text, + const TQString &caption = TQString::null ); + + /** + * This function accepts the window id of the parent window, instead + * of TQWidget*. It should be used only when necessary. + * @since 3.2 + */ + static void queuedMessageBoxWId( WId parent_id, + DialogType type, const TQString &text, + const TQString &caption = TQString::null ); + + /** + * @return true if the corresponding yes/no message box should be shown. + * @param dontShowAgainName the name that identify the message box. If + * empty, true is always returned. + * @param result is set to the result (Yes or No) that was chosen the last + * time the message box was shown. Only meaningful, if the message box + * should not be shown. + * @since 3.2 + */ + static bool shouldBeShownYesNo(const TQString &dontShowAgainName, + ButtonCode &result); + /** + * @return true if the corresponding continue/cancel message box should be + * shown. + * @param dontShowAgainName the name that identify the message box. If + * empty, true is always returned. + * @since 3.2 + */ + static bool shouldBeShownContinue(const TQString &dontShowAgainName); + + /** + * Save the fact that the yes/no message box should not be shown again. + * @param dontShowAgainName the name that identify the message box. If + * empty, this method does nothing. + * @param result the value (Yes or No) that should be used as the result + * for the message box. + * @since 3.2 + */ + static void saveDontShowAgainYesNo(const TQString &dontShowAgainName, + ButtonCode result); + + /** + * Save the fact that the continue/cancel message box should not be shown + * again. + * @param dontShowAgainName the name that identify the message box. If + * empty, this method does nothing. + * @since 3.2 + */ + static void saveDontShowAgainContinue(const TQString &dontShowAgainName); + + /** + * Use @p cfg for all settings related to the dontShowAgainName feature. + * If @p cfg is 0 (default) TDEGlobal::config() will be used. + * @since 3.2 + */ + static void setDontShowAskAgainConfig(TDEConfig* cfg); + + /** + * Create content and layout of a standard dialog + * + * @param dialog The parent dialog base + * @param icon Which predefined icon the message box shall show. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. + * If the list is empty, it doesn't show any listbox + * @param ask The text of the checkbox. If empty none will be shown. + * @param checkboxReturn The result of the checkbox. If it's initially + * true then the checkbox will be checked by default. + * @param options see OptionsType + * @param details Detailed message string. + * @since 3.3 + * @return A KDialogBase button code, not a KMessageBox button code, + * based on the buttonmask given to the constructor of the + * @p dialog (ie. will return KDialogBase::Yes [256] instead of + * KMessageBox::Yes [3]). Will return KMessageBox::Cancel + * if the message box is queued for display instead of + * exec()ed immediately or if the option NoExec is set. + * @note The @p dialog that is passed in is deleted by this + * function. Do not delete it yourself. + */ + static int createKMessageBox(KDialogBase *dialog, TQMessageBox::Icon icon, + const TQString &text, const TQStringList &strlist, + const TQString &ask, bool *checkboxReturn, + int options, const TQString &details=TQString::null); + + /** + * Create content and layout of a standard dialog + * + * @param dialog The parent dialog base + * @param icon A TQPixmap containing the icon to be displayed in the + * dialog next to the text. + * @param text Message string. + * @param strlist List of strings to be written in the listbox. + * If the list is empty, it doesn't show any listbox + * @param ask The text of the checkbox. If empty none will be shown. + * @param checkboxReturn The result of the checkbox. If it's initially + * true then the checkbox will be checked by default. + * @param options see OptionsType + * @param details Detailed message string. + * @param notifyType The type of notification to send when this message + * is presentend. + * @since 3.3 + * @return A KDialogBase button code, not a KMessageBox button code, + * based on the buttonmask given to the constructor of the + * @p dialog (ie. will return KDialogBase::Yes [256] instead of + * KMessageBox::Yes [3]). Will return KMessageBox::Cancel + * if the message box is queued for display instead of + * exec()ed immediately or if the option NoExec is set. + * @note The @p dialog that is passed in is deleted by this + * function. Do not delete it yourself. + */ + static int createKMessageBox(KDialogBase *dialog, TQPixmap icon, + const TQString &text, const TQStringList &strlist, + const TQString &ask, bool *checkboxReturn, + int options, const TQString &details=TQString::null, + TQMessageBox::Icon notifyType=TQMessageBox::Information); + +private: + static TDEConfig* againConfig; +}; + +#endif -- cgit v1.2.1