# kdeui Library API Documentation

Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# kmessagebox.cpp

    00001 /*  This file is part of the KDE libraries
    00002     Copyright (C) 1999 Waldo Bastian (bastian@kde.org)
    00003
    00004     This library is free software; you can redistribute it and/or
    00005     modify it under the terms of the GNU Library General Public
    00006     License as published by the Free Software Foundation; version 2
    00007     of the License.
    00008
    00009     This library is distributed in the hope that it will be useful,
    00010     but WITHOUT ANY WARRANTY; without even the implied warranty of
    00011     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    00012     Library General Public License for more details.
    00013
    00014     You should have received a copy of the GNU Library General Public License
    00015     along with this library; see the file COPYING.LIB.  If not, write to
    00016     the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
    00017     Boston, MA 02111-1307, USA.
    00018 */
    00019
    00020 #include <qcheckbox.h>
    00021 #include <qguardedptr.h>
    00022 #include <qhbox.h>
    00023 #include <qlabel.h>
    00024 #include <qlineedit.h>
    00025 #include <qmessagebox.h>
    00026 #include <qstringlist.h>
    00027 #include <qvbox.h>
    00028 #include <qvgroupbox.h>
    00029 #include <qstylesheet.h>
    00030 #include <qsimplerichtext.h>
    00031 #include <qpushbutton.h>
    00032 #include <qlayout.h>
    00033
    00034 #include <kapplication.h>
    00035 #include <kconfig.h>
    00036 #include <kdebug.h>
    00037 #include <kdialogbase.h>
    00038 #include <kguiitem.h>
    00039 #include <klistbox.h>
    00040 #include <klocale.h>
    00041 #include <kmessagebox.h>
    00042 #include <knotifyclient.h>
    00043 #include <kstdguiitem.h>
    00044 #include <kactivelabel.h>
    00045 #include <kiconloader.h>
    00046 #include <kglobalsettings.h>
    00047
    00048 #ifdef Q_WS_X11
    00049 #include <X11/Xlib.h>
    00050 #endif
    00051
    00061 static bool KMessageBox_queue = false;
    00062
    00063 static QPixmap themedMessageBoxIcon(QMessageBox::Icon icon)
    00064 {
    00065     QString icon_name;
    00066
    00067     switch(icon)
    00068     {
    00069     case QMessageBox::NoIcon:
    00070         return QPixmap();
    00071         break;
    00072     case QMessageBox::Information:
    00073         icon_name = "messagebox_info";
    00074         break;
    00075     case QMessageBox::Warning:
    00076         icon_name = "messagebox_warning";
    00077         break;
    00078     case QMessageBox::Critical:
    00079         icon_name = "messagebox_critical";
    00080         break;
    00081     default:
    00082         break;
    00083     }
    00084
    00085    QPixmap ret = KApplication::kApplication()->iconLoader()->loadIcon(icon_name, KIcon::NoGroup, KIcon::SizeMedium, KIcon::DefaultState, 0, true);
    00086
    00087    if (ret.isNull())
    00088        return QMessageBox::standardIcon(icon);
    00089    else
    00090        return ret;
    00091 }
    00092
    00093 static void sendNotification( QString message,
    00094                               const QStringList& strlist,
    00095                               QMessageBox::Icon icon,
    00096                               WId parent_id )
    00097 {
    00098     // create the message for KNotify
    00099     QString messageType;
    00100     switch ( icon )
    00101     {
    00102         case QMessageBox::Warning:
    00103             messageType = "messageWarning";
    00104             break;
    00105         case QMessageBox::Critical:
    00106             messageType = "messageCritical";
    00107             break;
    00108 #if QT_VERSION >= 0x030200
    00109         case QMessageBox::Question:
    00110             messageType = "messageQuestion";
    00111             break;
    00112 #endif
    00113         default:
    00114             messageType = "messageInformation";
    00115             break;
    00116     }
    00117
    00118     if ( !strlist.isEmpty() )
    00119     {
    00120         for ( QStringList::ConstIterator it = strlist.begin(); it != strlist.end(); ++it )
    00121             message += "\n" + *it;
    00122     }
    00123
    00124     if ( !message.isEmpty() )
    00125         KNotifyClient::event( (int)parent_id, messageType, message );
    00126 }
    00127
    00128 static QString qrichtextify( const QString& text )
    00129 {
    00130   if ( text.isEmpty() || text[0] == '<' )
    00131     return text;
    00132
    00133   QStringList lines = QStringList::split('\n', text);
    00134   for(QStringList::Iterator it = lines.begin(); it != lines.end(); ++it)
    00135   {
    00136     *it = QStyleSheet::convertFromPlainText( *it, QStyleSheetItem::WhiteSpaceNormal );
    00137   }
    00138
    00139   return lines.join(QString::null);
    00140 }
    00141
    00142 int KMessageBox::createKMessageBox(KDialogBase *dialog, QMessageBox::Icon icon,
    00143                              const QString &text, const QStringList &strlist,
    00144                              const QString &ask, bool *checkboxReturn,
    00145                              int options, const QString &details)
    00146 {
    00147     return createKMessageBox(dialog, themedMessageBoxIcon(icon), text, strlist,
    00148                       ask, checkboxReturn, options, details, icon);
    00149 }
    00150
    00151 int KMessageBox::createKMessageBox(KDialogBase *dialog, QPixmap icon,
    00152                              const QString &text, const QStringList &strlist,
    00153                              const QString &ask, bool *checkboxReturn, int options,
    00154                              const QString &details, QMessageBox::Icon notifyType)
    00155 {
    00156     QVBox *topcontents = new QVBox (dialog);
    00157     topcontents->setSpacing(KDialog::spacingHint()*2);
    00158     topcontents->setMargin(KDialog::marginHint());
    00159
    00160     QWidget *contents = new QWidget(topcontents);
    00161     QHBoxLayout * lay = new QHBoxLayout(contents);
    00162     lay->setSpacing(KDialog::spacingHint());
    00163
    00164     QLabel *label1 = new QLabel( contents);
    00165
    00166     if (!icon.isNull())
    00167        label1->setPixmap(icon);
    00168
    00169     lay->addWidget( label1, 0, Qt::AlignCenter );
    00170     lay->addSpacing(KDialog::spacingHint());
    00171     // Enforce <p>text</p> otherwise the word-wrap doesn't work well
    00172     QString qt_text = qrichtextify( text );
    00173
    00174     int pref_width = 0;
    00175     int pref_height = 0;
    00176     // Calculate a proper size for the text.
    00177     {
    00178        QSimpleRichText rt(qt_text, dialog->font());
    00179        QRect d = KGlobalSettings::desktopGeometry(dialog);
    00180
    00181        pref_width = d.width() / 3;
    00182        rt.setWidth(pref_width);
    00183        int used_width = rt.widthUsed();
    00184        pref_height = rt.height();
    00185        if (3*pref_height > 2*d.height())
    00186        {
    00187           // Very high dialog.. make it wider
    00188           pref_width = d.width() / 2;
    00189           rt.setWidth(pref_width);
    00190           used_width = rt.widthUsed();
    00191           pref_height = rt.height();
    00192        }
    00193        if (used_width <= pref_width)
    00194        {
    00195           while(true)
    00196           {
    00197              int new_width = (used_width * 9) / 10;
    00198              rt.setWidth(new_width);
    00199              int new_height = rt.height();
    00200              if (new_height > pref_height)
    00201                 break;
    00202              used_width = rt.widthUsed();
    00203              if (used_width > new_width)
    00204                 break;
    00205           }
    00206           pref_width = used_width;
    00207        }
    00208        else
    00209        {
    00210           if (used_width > (pref_width *2))
    00211              pref_width = pref_width *2;
    00212           else
    00213              pref_width = used_width;
    00214        }
    00215     }
    00216     KActiveLabel *label2 = new KActiveLabel( qt_text, contents );
    00217     if (!(options & KMessageBox::AllowLink))
    00218     {
    00219        QObject::disconnect(label2, SIGNAL(linkClicked(const QString &)),
    00220                   label2, SLOT(openLink(const QString &)));
    00221     }
    00222
    00223     // We add 10 pixels extra to compensate for some KActiveLabel margins.
    00224     // TODO: find out why this is 10.
    00225     label2->setFixedSize(QSize(pref_width+10, pref_height));
    00226     lay->addWidget( label2 );
    00227     lay->addStretch();
    00228
    00229     KListBox *listbox = 0;
    00230     if (!strlist.isEmpty())
    00231     {
    00232        listbox=new KListBox( topcontents );
    00233        listbox->insertStringList( strlist );
    00234        listbox->setSelectionMode( QListBox::NoSelection );
    00235        topcontents->setStretchFactor(listbox, 1);
    00236     }
    00237
    00238     QGuardedPtr<QCheckBox> checkbox = 0;
    00239     if (!ask.isEmpty())
    00240     {
    00241        checkbox = new QCheckBox(ask, topcontents);
    00242        if (checkboxReturn)
    00243          checkbox->setChecked(*checkboxReturn);
    00244     }
    00245
    00246     if (!details.isEmpty())
    00247     {
    00248        QVGroupBox *detailsGroup = new QVGroupBox( i18n("Details"), dialog);
    00249        if ( details.length() < 512 ) {
    00250          KActiveLabel *label3 = new KActiveLabel(qrichtextify(details),
    00251                                                  detailsGroup);
    00252          label3->setMinimumSize(label3->sizeHint());
    00253          if (!(options & KMessageBox::AllowLink))
    00254          {
    00255            QObject::disconnect(label3, SIGNAL(linkClicked(const QString &)),
    00256                                label3, SLOT(openLink(const QString &)));
    00257          }
    00258        } else {
    00259          QTextEdit* te = new QTextEdit(details, QString::null, detailsGroup);
    00260          te->setReadOnly( true );
    00261          te->setMinimumHeight( te->fontMetrics().lineSpacing() * 11 );
    00262        }
    00263        dialog->setDetailsWidget(detailsGroup);
    00264     }
    00265
    00266     dialog->setMainWidget(topcontents);
    00267     dialog->enableButtonSeparator(false);
    00268     if (!listbox)
    00269        dialog->disableResize();
    00270
    00271     const KDialogBase::ButtonCode buttons[] = {
    00272         KDialogBase::Help,
    00273         KDialogBase::Default,
    00274         KDialogBase::Ok,
    00275         KDialogBase::Apply,
    00276         KDialogBase::Try,
    00277         KDialogBase::Cancel,
    00278         KDialogBase::Close,
    00279         KDialogBase::User1,
    00280         KDialogBase::User2,
    00281         KDialogBase::User3,
    00282         KDialogBase::No,
    00283         KDialogBase::Yes,
    00284         KDialogBase::Details };
    00285     for( unsigned int i = 0;
    00286      i < sizeof( buttons )/sizeof( buttons[ 0 ] );
    00287      ++i )
    00288     if( QPushButton* btn = dialog->actionButton( buttons[ i ] ))
    00289         if( btn->isDefault())
    00290         btn->setFocus();
    00291
    00292     if ( (options & KMessageBox::Notify) )
    00293         sendNotification( text, strlist, notifyType, dialog->topLevelWidget()->winId());
    00294
    00295     if (KMessageBox_queue)
    00296     {
    00297        KDialogQueue::queueDialog(dialog);
    00298        return KMessageBox::Cancel; // We have to return something.
    00299     }
    00300
    00301     if ( (options & KMessageBox::NoExec) )
    00302     {
    00303        return KMessageBox::Cancel; // We have to return something.
    00304     }
    00305
    00306     // We use a QGuardedPtr because the dialog may get deleted
    00307     // during exec() if the parent of the dialog gets deleted.
    00308     // In that case the guarded ptr will reset to 0.
    00309     QGuardedPtr<KDialogBase> guardedDialog = dialog;
    00310
    00311     int result = guardedDialog->exec();
    00312     if (checkbox && checkboxReturn)
    00313        *checkboxReturn = checkbox->isChecked();
    00314     delete (KDialogBase *) guardedDialog;
    00315     return result;
    00316 }
    00317
    00318 int
    00319 KMessageBox::questionYesNo(QWidget *parent, const QString &text,
    00320                            const QString &caption,
    00321                            const KGuiItem &buttonYes,
    00322                            const KGuiItem &buttonNo,
    00323                            const QString &dontAskAgainName,
    00324                            int options)
    00325 {
    00326    return questionYesNoList(parent, text, QStringList(), caption,
    00327                             buttonYes, buttonNo, dontAskAgainName, options);
    00328 }
    00329
    00330 int
    00331 KMessageBox::questionYesNoWId(WId parent_id, const QString &text,
    00332                            const QString &caption,
    00333                            const KGuiItem &buttonYes,
    00334                            const KGuiItem &buttonNo,
    00335                            const QString &dontAskAgainName,
    00336                            int options)
    00337 {
    00338    return questionYesNoListWId(parent_id, text, QStringList(), caption,
    00339                             buttonYes, buttonNo, dontAskAgainName, options);
    00340 }
    00341
    00342 bool
    00343 KMessageBox::shouldBeShownYesNo(const QString &dontShowAgainName,
    00344                                 ButtonCode &result)
    00345 {
    00346     if ( dontShowAgainName.isEmpty() ) return true;
    00347     QString grpNotifMsgs = QString::fromLatin1("Notification Messages");
    00348     KConfig *config = againConfig ? againConfig : KGlobal::config();
    00349     KConfigGroupSaver saver( config, grpNotifMsgs );
    00350     QString dontAsk = config->readEntry(dontShowAgainName).lower();
    00351     if (dontAsk == "yes") {
    00352         result = Yes;
    00353         return false;
    00354     }
    00355     if (dontAsk == "no") {
    00356         result = No;
    00357         return false;
    00358     }
    00359     return true;
    00360 }
    00361
    00362 bool
    00363 KMessageBox::shouldBeShownContinue(const QString &dontShowAgainName)
    00364 {
    00365     if ( dontShowAgainName.isEmpty() ) return true;
    00366     QString grpNotifMsgs = QString::fromLatin1("Notification Messages");
    00367     KConfig *config = againConfig ? againConfig : KGlobal::config();
    00368     KConfigGroupSaver saver( config, grpNotifMsgs );
    00369     return config->readBoolEntry(dontShowAgainName,  true);
    00370 }
    00371
    00372 void
    00373 KMessageBox::saveDontShowAgainYesNo(const QString &dontShowAgainName,
    00374                                     ButtonCode result)
    00375 {
    00376     if ( dontShowAgainName.isEmpty() ) return;
    00377     QString grpNotifMsgs = QString::fromLatin1("Notification Messages");
    00378     KConfig *config = againConfig ? againConfig : KGlobal::config();
    00379     KConfigGroupSaver saver( config, grpNotifMsgs );
    00380     config->writeEntry( dontShowAgainName, result==Yes ? "yes" : "no", true, (dontShowAgainName[0] == ':'));
    00381     config->sync();
    00382 }
    00383
    00384 void
    00385 KMessageBox::saveDontShowAgainContinue(const QString &dontShowAgainName)
    00386 {
    00387     if ( dontShowAgainName.isEmpty() ) return;
    00388     QString grpNotifMsgs = QString::fromLatin1("Notification Messages");
    00389     KConfig *config = againConfig ? againConfig : KGlobal::config();
    00390     KConfigGroupSaver saver( config, grpNotifMsgs );
    00391     config->writeEntry( dontShowAgainName, false, true, (dontShowAgainName[0] == ':'));
    00392     config->sync();
    00393 }
    00394
    00395 KConfig* KMessageBox::againConfig = NULL;
    00396 void
    00397 KMessageBox::setDontShowAskAgainConfig(KConfig* cfg)
    00398 {
    00399   againConfig = cfg;
    00400 }
    00401
    00402 int
    00403 KMessageBox::questionYesNoList(QWidget *parent, const QString &text,
    00404                            const QStringList &strlist,
    00405                            const QString &caption,
    00406                            const KGuiItem &buttonYes,
    00407                            const KGuiItem &buttonNo,
    00408                            const QString &dontAskAgainName,
    00409                            int options)
    00410 { // in order to avoid code duplication, convert to WId, it will be converted back
    00411     return questionYesNoListWId( parent ? parent->winId() : 0, text, strlist,
    00412         caption, buttonYes, buttonNo, dontAskAgainName, options );
    00413 }
    00414
    00415 int
    00416 KMessageBox::questionYesNoListWId(WId parent_id, const QString &text,
    00417                            const QStringList &strlist,
    00418                            const QString &caption,
    00419                            const KGuiItem &buttonYes,
    00420                            const KGuiItem &buttonNo,
    00421                            const QString &dontAskAgainName,
    00422                            int options)
    00423 {
    00424     ButtonCode res;
    00425     if ( !shouldBeShownYesNo(dontAskAgainName, res) )
    00426         return res;
    00427
    00428     QWidget* parent = QWidget::find( parent_id );
    00429     KDialogBase *dialog= new KDialogBase(
    00430                        caption.isEmpty() ? i18n("Question") : caption,
    00431                        KDialogBase::Yes | KDialogBase::No,
    00432                        KDialogBase::Yes, KDialogBase::No,
    00433                        parent, "questionYesNo", true, true,
    00434                        buttonYes, buttonNo);
    00435     if( options & PlainCaption )
    00436         dialog->setPlainCaption( caption );
    00437 #ifdef Q_WS_X11
    00438     if( parent == NULL && parent_id )
    00439         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00440 #endif
    00441
    00442     bool checkboxResult = false;
    00443     int result = createKMessageBox(dialog, QMessageBox::Information, text, strlist,
    00444                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask again"),
    00445                        &checkboxResult, options);
    00446     res = (result==KDialogBase::Yes ? Yes : No);
    00447
    00448     if (checkboxResult)
    00449         saveDontShowAgainYesNo(dontAskAgainName, res);
    00450     return res;
    00451 }
    00452
    00453 int
    00454 KMessageBox::questionYesNoCancel(QWidget *parent,
    00455                           const QString &text,
    00456                           const QString &caption,
    00457                           const KGuiItem &buttonYes,
    00458                           const KGuiItem &buttonNo,
    00459                           const QString &dontAskAgainName,
    00460                           int options)
    00461 {
    00462     return questionYesNoCancelWId( parent ? parent->winId() : 0, text, caption, buttonYes, buttonNo,
    00463         dontAskAgainName, options );
    00464 }
    00465
    00466 int
    00467 KMessageBox::questionYesNoCancelWId(WId parent_id,
    00468                           const QString &text,
    00469                           const QString &caption,
    00470                           const KGuiItem &buttonYes,
    00471                           const KGuiItem &buttonNo,
    00472                           const QString &dontAskAgainName,
    00473                           int options)
    00474 {
    00475     ButtonCode res;
    00476     if ( !shouldBeShownYesNo(dontAskAgainName, res) )
    00477         return res;
    00478
    00479     QWidget* parent = QWidget::find( parent_id );
    00480     KDialogBase *dialog= new KDialogBase(
    00481                        caption.isEmpty() ? i18n("Question") : caption,
    00482                        KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
    00483                        KDialogBase::Yes, KDialogBase::Cancel,
    00484                        parent, "questionYesNoCancel", true, true,
    00485                        buttonYes, buttonNo);
    00486     if( options & PlainCaption )
    00487         dialog->setPlainCaption( caption );
    00488 #ifdef Q_WS_X11
    00489     if( parent == NULL && parent_id )
    00490         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00491 #endif
    00492
    00493     bool checkboxResult = false;
    00494     int result = createKMessageBox(dialog, QMessageBox::Information,
    00495                        text, QStringList(),
    00496                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask again"),
    00497                        &checkboxResult, options);
    00498     if ( result==KDialogBase::Cancel ) return Cancel;
    00499     res = (result==KDialogBase::Yes ? Yes : No);
    00500
    00501     if (checkboxResult)
    00502         saveDontShowAgainYesNo(dontAskAgainName, res);
    00503     return res;
    00504 }
    00505
    00506 int
    00507 KMessageBox::warningYesNo(QWidget *parent, const QString &text,
    00508                           const QString &caption,
    00509                           const KGuiItem &buttonYes,
    00510                           const KGuiItem &buttonNo,
    00511                           const QString &dontAskAgainName,
    00512                           int options)
    00513 {
    00514    return warningYesNoList(parent, text, QStringList(), caption,
    00515                        buttonYes, buttonNo, dontAskAgainName, options);
    00516 }
    00517
    00518 int
    00519 KMessageBox::warningYesNoWId(WId parent_id, const QString &text,
    00520                           const QString &caption,
    00521                           const KGuiItem &buttonYes,
    00522                           const KGuiItem &buttonNo,
    00523                           const QString &dontAskAgainName,
    00524                           int options)
    00525 {
    00526    return warningYesNoListWId(parent_id, text, QStringList(), caption,
    00527                        buttonYes, buttonNo, dontAskAgainName, options);
    00528 }
    00529
    00530 int
    00531 KMessageBox::warningYesNoList(QWidget *parent, const QString &text,
    00532                               const QStringList &strlist,
    00533                               const QString &caption,
    00534                               const KGuiItem &buttonYes,
    00535                               const KGuiItem &buttonNo,
    00536                               const QString &dontAskAgainName,
    00537                               int options)
    00538 {
    00539     return warningYesNoListWId( parent ? parent->winId() : 0, text, strlist, caption,
    00540         buttonYes, buttonNo, dontAskAgainName, options );
    00541 }
    00542
    00543 int
    00544 KMessageBox::warningYesNoListWId(WId parent_id, const QString &text,
    00545                               const QStringList &strlist,
    00546                               const QString &caption,
    00547                               const KGuiItem &buttonYes,
    00548                               const KGuiItem &buttonNo,
    00549                               const QString &dontAskAgainName,
    00550                               int options)
    00551 {
    00552     // warningYesNo and warningYesNoList are always "dangerous"
    00553     // ### Remove this line for KDE 4, when the 'options' default parameter
    00554     // takes effects.
    00555     options |= Dangerous;
    00556
    00557     ButtonCode res;
    00558     if ( !shouldBeShownYesNo(dontAskAgainName, res) )
    00559         return res;
    00560
    00561     QWidget* parent = QWidget::find( parent_id );
    00562     KDialogBase *dialog= new KDialogBase(
    00563                        caption.isEmpty() ? i18n("Warning") : caption,
    00564                        KDialogBase::Yes | KDialogBase::No,
    00565                        KDialogBase::No, KDialogBase::No,
    00566                        parent, "warningYesNoList", true, true,
    00567                        buttonYes, buttonNo);
    00568     if( options & PlainCaption )
    00569         dialog->setPlainCaption( caption );
    00570 #ifdef Q_WS_X11
    00571     if( parent == NULL && parent_id )
    00572         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00573 #endif
    00574
    00575     bool checkboxResult = false;
    00576     int result = createKMessageBox(dialog, QMessageBox::Warning, text, strlist,
    00577                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask again"),
    00578                        &checkboxResult, options);
    00579     res = (result==KDialogBase::Yes ? Yes : No);
    00580
    00581     if (checkboxResult)
    00582         saveDontShowAgainYesNo(dontAskAgainName, res);
    00583     return res;
    00584 }
    00585
    00586 int
    00587 KMessageBox::warningContinueCancel(QWidget *parent,
    00588                                    const QString &text,
    00589                                    const QString &caption,
    00590                                    const KGuiItem &buttonContinue,
    00591                                    const QString &dontAskAgainName,
    00592                                    int options)
    00593 {
    00594    return warningContinueCancelList(parent, text, QStringList(), caption,
    00595                                 buttonContinue, dontAskAgainName, options);
    00596 }
    00597
    00598 int
    00599 KMessageBox::warningContinueCancelWId(WId parent_id,
    00600                                    const QString &text,
    00601                                    const QString &caption,
    00602                                    const KGuiItem &buttonContinue,
    00603                                    const QString &dontAskAgainName,
    00604                                    int options)
    00605 {
    00606    return warningContinueCancelListWId(parent_id, text, QStringList(), caption,
    00607                                 buttonContinue, dontAskAgainName, options);
    00608 }
    00609
    00610 int
    00611 KMessageBox::warningContinueCancelList(QWidget *parent, const QString &text,
    00612                              const QStringList &strlist,
    00613                              const QString &caption,
    00614                              const KGuiItem &buttonContinue,
    00615                              const QString &dontAskAgainName,
    00616                              int options)
    00617 {
    00618     return warningContinueCancelListWId( parent ? parent->winId() : 0, text, strlist,
    00619         caption, buttonContinue, dontAskAgainName, options );
    00620 }
    00621
    00622 int
    00623 KMessageBox::warningContinueCancelListWId(WId parent_id, const QString &text,
    00624                              const QStringList &strlist,
    00625                              const QString &caption,
    00626                              const KGuiItem &buttonContinue,
    00627                              const QString &dontAskAgainName,
    00628                              int options)
    00629 {
    00630     if ( !shouldBeShownContinue(dontAskAgainName) )
    00631         return Continue;
    00632
    00633     QWidget* parent = QWidget::find( parent_id );
    00634     KDialogBase *dialog= new KDialogBase(
    00635                        caption.isEmpty() ? i18n("Warning") : caption,
    00636                        KDialogBase::Yes | KDialogBase::No,
    00637                        KDialogBase::Yes, KDialogBase::No,
    00638                        parent, "warningYesNo", true, true,
    00639                        buttonContinue, KStdGuiItem::cancel() );
    00640     if( options & PlainCaption )
    00641         dialog->setPlainCaption( caption );
    00642 #ifdef Q_WS_X11
    00643     if( parent == NULL && parent_id )
    00644         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00645 #endif
    00646
    00647     bool checkboxResult = false;
    00648     int result = createKMessageBox(dialog, QMessageBox::Warning, text, strlist,
    00649                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask again"),
    00650                        &checkboxResult, options);
    00651
    00652     if ( result==KDialogBase::No )
    00653         return Cancel;
    00654     if (checkboxResult)
    00655         saveDontShowAgainContinue(dontAskAgainName);
    00656     return Continue;
    00657 }
    00658
    00659 int
    00660 KMessageBox::warningYesNoCancel(QWidget *parent, const QString &text,
    00661                                 const QString &caption,
    00662                                 const KGuiItem &buttonYes,
    00663                                 const KGuiItem &buttonNo,
    00664                                 const QString &dontAskAgainName,
    00665                                 int options)
    00666 {
    00667    return warningYesNoCancelList(parent, text, QStringList(), caption,
    00668                       buttonYes, buttonNo, dontAskAgainName, options);
    00669 }
    00670
    00671 int
    00672 KMessageBox::warningYesNoCancelWId(WId parent_id, const QString &text,
    00673                                 const QString &caption,
    00674                                 const KGuiItem &buttonYes,
    00675                                 const KGuiItem &buttonNo,
    00676                                 const QString &dontAskAgainName,
    00677                                 int options)
    00678 {
    00679    return warningYesNoCancelListWId(parent_id, text, QStringList(), caption,
    00680                       buttonYes, buttonNo, dontAskAgainName, options);
    00681 }
    00682
    00683 int
    00684 KMessageBox::warningYesNoCancelList(QWidget *parent, const QString &text,
    00685                                     const QStringList &strlist,
    00686                                     const QString &caption,
    00687                                     const KGuiItem &buttonYes,
    00688                                     const KGuiItem &buttonNo,
    00689                                     const QString &dontAskAgainName,
    00690                                     int options)
    00691 {
    00692     return warningYesNoCancelListWId( parent ? parent->winId() : 0, text, strlist,
    00693         caption, buttonYes, buttonNo, dontAskAgainName, options );
    00694 }
    00695
    00696 int
    00697 KMessageBox::warningYesNoCancelListWId(WId parent_id, const QString &text,
    00698                                     const QStringList &strlist,
    00699                                     const QString &caption,
    00700                                     const KGuiItem &buttonYes,
    00701                                     const KGuiItem &buttonNo,
    00702                                     const QString &dontAskAgainName,
    00703                                     int options)
    00704 {
    00705     ButtonCode res;
    00706     if ( !shouldBeShownYesNo(dontAskAgainName, res) )
    00707         return res;
    00708
    00709     QWidget* parent = QWidget::find( parent_id );
    00710     KDialogBase *dialog= new KDialogBase(
    00711                        caption.isEmpty() ? i18n("Warning") : caption,
    00712                        KDialogBase::Yes | KDialogBase::No | KDialogBase::Cancel,
    00713                        KDialogBase::Yes, KDialogBase::Cancel,
    00714                        parent, "warningYesNoCancel", true, true,
    00715                        buttonYes, buttonNo);
    00716     if( options & PlainCaption )
    00717         dialog->setPlainCaption( caption );
    00718 #ifdef Q_WS_X11
    00719     if( parent == NULL && parent_id )
    00720         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00721 #endif
    00722
    00723     bool checkboxResult = false;
    00724     int result = createKMessageBox(dialog, QMessageBox::Warning, text, strlist,
    00725                        dontAskAgainName.isEmpty() ? QString::null : i18n("Do not ask again"),
    00726                        &checkboxResult, options);
    00727     if ( result==KDialogBase::Cancel ) return Cancel;
    00728     res = (result==KDialogBase::Yes ? Yes : No);
    00729
    00730     if (checkboxResult)
    00731         saveDontShowAgainYesNo(dontAskAgainName, res);
    00732     return res;
    00733 }
    00734
    00735 void
    00736 KMessageBox::error(QWidget *parent,  const QString &text,
    00737                    const QString &caption, int options)
    00738 {
    00739     return errorListWId( parent ? parent->winId() : 0, text, QStringList(), caption, options );
    00740 }
    00741
    00742 void
    00743 KMessageBox::errorWId(WId parent_id, const QString &text,
    00744                       const QString &caption, int options)
    00745 {
    00746     errorListWId( parent_id, text, QStringList(), caption, options );
    00747 }
    00748
    00749 void
    00750 KMessageBox::errorList(QWidget *parent, const QString &text, const QStringList &strlist,
    00751                        const QString &caption, int options)
    00752 {
    00753     return errorListWId( parent ? parent->winId() : 0, text, strlist, caption, options );
    00754 }
    00755
    00756 void
    00757 KMessageBox::errorListWId(WId parent_id,  const QString &text, const QStringList &strlist,
    00758                    const QString &caption, int options)
    00759 {
    00760     QWidget* parent = QWidget::find( parent_id );
    00761     KDialogBase *dialog= new KDialogBase(
    00762                        caption.isEmpty() ? i18n("Error") : caption,
    00763                        KDialogBase::Yes,
    00764                        KDialogBase::Yes, KDialogBase::Yes,
    00765                        parent, "error", true, true,
    00766                        KStdGuiItem::ok() );
    00767     if( options & PlainCaption )
    00768         dialog->setPlainCaption( caption );
    00769 #ifdef Q_WS_X11
    00770     if( parent == NULL && parent_id )
    00771         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00772 #endif
    00773
    00774     createKMessageBox(dialog, QMessageBox::Critical, text, strlist, QString::null, 0, options);
    00775 }
    00776
    00777 void
    00778 KMessageBox::detailedError(QWidget *parent,  const QString &text,
    00779                    const QString &details,
    00780                    const QString &caption, int options)
    00781 {
    00782     return detailedErrorWId( parent ? parent->winId() : 0, text, details, caption, options );
    00783 }
    00784
    00785 void
    00786 KMessageBox::detailedErrorWId(WId parent_id,  const QString &text,
    00787                    const QString &details,
    00788                    const QString &caption, int options)
    00789 {
    00790     QWidget* parent = QWidget::find( parent_id );
    00791     KDialogBase *dialog= new KDialogBase(
    00792                        caption.isEmpty() ? i18n("Error") : caption,
    00793                        KDialogBase::Yes | KDialogBase::Details,
    00794                        KDialogBase::Yes, KDialogBase::Yes,
    00795                        parent, "error", true, true,
    00796                        KStdGuiItem::ok() );
    00797     if( options & PlainCaption )
    00798         dialog->setPlainCaption( caption );
    00799 #ifdef Q_WS_X11
    00800     if( parent == NULL && parent_id )
    00801         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00802 #endif
    00803
    00804     createKMessageBox(dialog, QMessageBox::Critical, text, QStringList(), QString::null, 0, options, details);
    00805 }
    00806
    00807 void
    00808 KMessageBox::queuedDetailedError(QWidget *parent,  const QString &text,
    00809                    const QString &details,
    00810                    const QString &caption)
    00811 {
    00812     return queuedDetailedErrorWId( parent ? parent->winId() : 0, text, details, caption );
    00813 }
    00814
    00815 void
    00816 KMessageBox::queuedDetailedErrorWId(WId parent_id,  const QString &text,
    00817                    const QString &details,
    00818                    const QString &caption)
    00819 {
    00820    KMessageBox_queue = true;
    00821    (void) detailedErrorWId(parent_id, text, details, caption);
    00822    KMessageBox_queue = false;
    00823 }
    00824
    00825
    00826 void
    00827 KMessageBox::sorry(QWidget *parent, const QString &text,
    00828                    const QString &caption, int options)
    00829 {
    00830     return sorryWId( parent ? parent->winId() : 0, text, caption, options );
    00831 }
    00832
    00833 void
    00834 KMessageBox::sorryWId(WId parent_id, const QString &text,
    00835                    const QString &caption, int options)
    00836 {
    00837     QWidget* parent = QWidget::find( parent_id );
    00838     KDialogBase *dialog= new KDialogBase(
    00839                        caption.isEmpty() ? i18n("Sorry") : caption,
    00840                        KDialogBase::Yes,
    00841                        KDialogBase::Yes, KDialogBase::Yes,
    00842                        parent, "sorry", true, true,
    00843                        KStdGuiItem::ok() );
    00844     if( options & PlainCaption )
    00845         dialog->setPlainCaption( caption );
    00846 #ifdef Q_WS_X11
    00847     if( parent == NULL && parent_id )
    00848         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00849 #endif
    00850
    00851     createKMessageBox(dialog, QMessageBox::Warning, text, QStringList(), QString::null, 0, options);
    00852 }
    00853
    00854 void
    00855 KMessageBox::detailedSorry(QWidget *parent, const QString &text,
    00856                    const QString &details,
    00857                    const QString &caption, int options)
    00858 {
    00859     return detailedSorryWId( parent ? parent->winId() : 0, text, details, caption, options );
    00860 }
    00861
    00862 void
    00863 KMessageBox::detailedSorryWId(WId parent_id, const QString &text,
    00864                    const QString &details,
    00865                    const QString &caption, int options)
    00866 {
    00867     QWidget* parent = QWidget::find( parent_id );
    00868     KDialogBase *dialog= new KDialogBase(
    00869                        caption.isEmpty() ? i18n("Sorry") : caption,
    00870                        KDialogBase::Yes | KDialogBase::Details,
    00871                        KDialogBase::Yes, KDialogBase::Yes,
    00872                        parent, "sorry", true, true,
    00873                        KStdGuiItem::ok() );
    00874     if( options & PlainCaption )
    00875         dialog->setPlainCaption( caption );
    00876 #ifdef Q_WS_X11
    00877     if( parent == NULL && parent_id )
    00878         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00879 #endif
    00880
    00881     createKMessageBox(dialog, QMessageBox::Warning, text, QStringList(), QString::null, 0, options, details);
    00882 }
    00883
    00884 void
    00885 KMessageBox::information(QWidget *parent,const QString &text,
    00886              const QString &caption, const QString &dontShowAgainName, int options)
    00887 {
    00888   informationList(parent, text, QStringList(), caption, dontShowAgainName, options);
    00889 }
    00890
    00891 void
    00892 KMessageBox::informationWId(WId parent_id,const QString &text,
    00893              const QString &caption, const QString &dontShowAgainName, int options)
    00894 {
    00895   informationListWId(parent_id, text, QStringList(), caption, dontShowAgainName, options);
    00896 }
    00897
    00898 void
    00899 KMessageBox::informationList(QWidget *parent,const QString &text, const QStringList & strlist,
    00900                          const QString &caption, const QString &dontShowAgainName, int options)
    00901 {
    00902     return informationListWId( parent ? parent->winId() : 0, text, strlist, caption,
    00903         dontShowAgainName, options );
    00904 }
    00905
    00906 void
    00907 KMessageBox::informationListWId(WId parent_id,const QString &text, const QStringList & strlist,
    00908                          const QString &caption, const QString &dontShowAgainName, int options)
    00909 {
    00910     if ( !shouldBeShownContinue(dontShowAgainName) )
    00911         return;
    00912
    00913     QWidget* parent = QWidget::find( parent_id );
    00914     KDialogBase *dialog= new KDialogBase(
    00915                        caption.isEmpty() ? i18n("Information") : caption,
    00916                        KDialogBase::Yes,
    00917                        KDialogBase::Yes, KDialogBase::Yes,
    00918                        parent, "information", true, true,
    00919                        KStdGuiItem::ok() );
    00920     if( options & PlainCaption )
    00921         dialog->setPlainCaption( caption );
    00922 #ifdef Q_WS_X11
    00923     if( parent == NULL && parent_id )
    00924         XSetTransientForHint( qt_xdisplay(), dialog->winId(), parent_id );
    00925 #endif
    00926
    00927     bool checkboxResult = false;
    00928
    00929     createKMessageBox(dialog, QMessageBox::Information, text, strlist,
    00930         dontShowAgainName.isEmpty() ? QString::null : i18n("Do not show this message again"),
    00931                 &checkboxResult, options);
    00932
    00933     if (checkboxResult)
    00934         saveDontShowAgainContinue(dontShowAgainName);
    00935 }
    00936
    00937 void
    00938 KMessageBox::enableAllMessages()
    00939 {
    00940    KConfig *config = againConfig ? againConfig : KGlobal::config();
    00941    QString grpNotifMsgs = QString::fromLatin1("Notification Messages");
    00942    if (!config->hasGroup(grpNotifMsgs))
    00943       return;
    00944
    00945    KConfigGroupSaver saver( config, grpNotifMsgs );
    00946
    00947    typedef QMap<QString, QString> configMap;
    00948
    00949    configMap map = config->entryMap(grpNotifMsgs);
    00950
    00951    configMap::Iterator it;
    00952    for (it = map.begin(); it != map.end(); ++it)
    00953       config->deleteEntry( it.key() );
    00954    config->sync();
    00955 }
    00956
    00957 void
    00958 KMessageBox::enableMessage(const QString &dontShowAgainName)
    00959 {
    00960    KConfig *config = againConfig ? againConfig : KGlobal::config();
    00961    QString grpNotifMsgs = QString::fromLatin1("Notification Messages");
    00962    if (!config->hasGroup(grpNotifMsgs))
    00963       return;
    00964
    00965    KConfigGroupSaver saver( config, grpNotifMsgs );
    00966
    00967    config->deleteEntry(dontShowAgainName);
    00968    config->sync();
    00969 }
    00970
    00971 void
    00972 KMessageBox::about(QWidget *parent, const QString &text,
    00973                    const QString &caption, int options)
    00974 {
    00975     QString _caption = caption;
    00976     if (_caption.isEmpty())
    00977         _caption = i18n("About %1").arg(kapp->caption());
    00978
    00979     KDialogBase *dialog = new KDialogBase(
    00980                                 caption,
    00981                                 KDialogBase::Yes,
    00982                                 KDialogBase::Yes, KDialogBase::Yes,
    00983                                 parent, "about", true, true,
    00984                                 KStdGuiItem::ok() );
    00985
    00986     QPixmap ret = KApplication::kApplication()->icon();
    00987     if (ret.isNull())
    00988         ret = QMessageBox::standardIcon(QMessageBox::Information);
    00989     dialog->setIcon(ret);
    00990
    00991     createKMessageBox(dialog, ret, text, QStringList(), QString::null, 0, options);
    00992
    00993     return;
    00994 }
    00995
    00996 int KMessageBox::messageBox( QWidget *parent, DialogType type, const QString &text,
    00997                              const QString &caption, const KGuiItem &buttonYes,
    00998                              const KGuiItem &buttonNo, const QString &dontShowAskAgainName,
    00999                              int options )
    01000 {
    01001     return messageBoxWId( parent ? parent->winId() : 0, type, text, caption,
    01002         buttonYes, buttonNo, dontShowAskAgainName, options );
    01003 }
    01004
    01005 int KMessageBox::messageBox( QWidget *parent, DialogType type, const QString &text,
    01006                              const QString &caption, const KGuiItem &buttonYes,
    01007                              const KGuiItem &buttonNo, int options )
    01008 {
    01009     return messageBoxWId( parent ? parent->winId() : 0, type, text, caption,
    01010         buttonYes, buttonNo, QString::null, options );
    01011 }
    01012
    01013 int KMessageBox::messageBoxWId( WId parent_id, DialogType type, const QString &text,
    01014                              const QString &caption, const KGuiItem &buttonYes,
    01015                              const KGuiItem &buttonNo, const QString &dontShow,
    01016                              int options )
    01017 {
    01018     switch (type) {
    01019         case QuestionYesNo:
    01020             return KMessageBox::questionYesNoWId( parent_id,
    01021                                                text, caption, buttonYes, buttonNo, dontShow, options );
    01022         case QuestionYesNoCancel:
    01023             return KMessageBox::questionYesNoCancelWId( parent_id,
    01024                                                text, caption, buttonYes, buttonNo, dontShow, options );
    01025         case WarningYesNo:
    01026             return KMessageBox::warningYesNoWId( parent_id,
    01027                                               text, caption, buttonYes, buttonNo, dontShow, options );
    01028         case WarningContinueCancel:
    01029             return KMessageBox::warningContinueCancelWId( parent_id,
    01030                                               text, caption, buttonYes.text(), dontShow, options );
    01031         case WarningYesNoCancel:
    01032             return KMessageBox::warningYesNoCancelWId( parent_id,
    01033                                               text, caption, buttonYes, buttonNo, dontShow, options );
    01034         case Information:
    01035             KMessageBox::informationWId( parent_id,
    01036                                       text, caption, dontShow, options );
    01037             return KMessageBox::Ok;
    01038
    01039         case Error:
    01040             KMessageBox::errorWId( parent_id, text, caption, options );
    01041             return KMessageBox::Ok;
    01042
    01043         case Sorry:
    01044             KMessageBox::sorryWId( parent_id, text, caption, options );
    01045             return KMessageBox::Ok;
    01046     }
    01047     return KMessageBox::Cancel;
    01048 }
    01049
    01050 void KMessageBox::queuedMessageBox( QWidget *parent, DialogType type, const QString &text, const QString &caption, int options )
    01051 {
    01052     return queuedMessageBoxWId( parent ? parent->winId() : 0, type, text, caption, options );
    01053 }
    01054
    01055 void KMessageBox::queuedMessageBoxWId( WId parent_id, DialogType type, const QString &text, const QString &caption, int options )
    01056 {
    01057    KMessageBox_queue = true;
    01058    (void) messageBoxWId(parent_id, type, text, caption, KStdGuiItem::yes(),
    01059                      KStdGuiItem::no(), QString::null, options);
    01060    KMessageBox_queue = false;
    01061 }
    01062
    01063 void KMessageBox::queuedMessageBox( QWidget *parent, DialogType type, const QString &text, const QString &caption )
    01064 {
    01065     return queuedMessageBoxWId( parent ? parent->winId() : 0, type, text, caption );
    01066 }
    01067
    01068 void KMessageBox::queuedMessageBoxWId( WId parent_id, DialogType type, const QString &text, const QString &caption )
    01069 {
    01070    KMessageBox_queue = true;
    01071    (void) messageBoxWId(parent_id, type, text, caption);
    01072    KMessageBox_queue = false;
    01073 }

This file is part of the documentation for kdeui Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:20:19 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003