summaryrefslogtreecommitdiffstats
path: root/kdialog
diff options
context:
space:
mode:
Diffstat (limited to 'kdialog')
-rw-r--r--kdialog/Makefile.am13
-rw-r--r--kdialog/README14
-rw-r--r--kdialog/kdialog.cpp687
-rw-r--r--kdialog/klistboxdialog.cpp60
-rw-r--r--kdialog/klistboxdialog.h49
-rwxr-xr-xkdialog/progresscanceldemo11
-rwxr-xr-xkdialog/progressdemo18
-rw-r--r--kdialog/progressdialog.cpp92
-rw-r--r--kdialog/progressdialog.h50
-rw-r--r--kdialog/progressdialogiface.h28
-rwxr-xr-xkdialog/test74
-rw-r--r--kdialog/widgets.cpp282
-rw-r--r--kdialog/widgets.h43
13 files changed, 1421 insertions, 0 deletions
diff --git a/kdialog/Makefile.am b/kdialog/Makefile.am
new file mode 100644
index 000000000..35980187e
--- /dev/null
+++ b/kdialog/Makefile.am
@@ -0,0 +1,13 @@
+KDE_CXXFLAGS = -DQT_NO_CAST_ASCII -DQT_NO_ASCII_CAST
+INCLUDES = $(all_includes)
+
+bin_PROGRAMS = kdialog
+
+kdialog_SOURCES = kdialog.cpp widgets.cpp klistboxdialog.cpp progressdialog.cpp progressdialogiface.skel
+kdialog_LDADD = $(LIB_KIO)
+kdialog_LDFLAGS = $(all_libraries) $(KDE_RPATH)
+
+METASOURCES = AUTO
+
+messages:
+ $(XGETTEXT) *.cpp -o $(podir)/kdialog.pot
diff --git a/kdialog/README b/kdialog/README
new file mode 100644
index 000000000..d029419c0
--- /dev/null
+++ b/kdialog/README
@@ -0,0 +1,14 @@
+kdialog allows you to display dialog boxes from shell scripts.
+The syntax is very much inspired from the "dialog" command
+(which shows text mode dialogs).
+
+However the width and height attributes have been removed for
+most dialogs - Qt/KDE have layouts ;)
+
+A tutorial on using kdialog is available at
+http://developer.kde.org/documentation/tutorials/kdialog/t1.html
+If you change or add any functionality, please contact Brad
+Hards <bradh@frogmouth.net> to ensure it is reflected in the
+tutorial.
+
+Current maintainer: David Faure <faure@kde.org>
diff --git a/kdialog/kdialog.cpp b/kdialog/kdialog.cpp
new file mode 100644
index 000000000..2dafb5789
--- /dev/null
+++ b/kdialog/kdialog.cpp
@@ -0,0 +1,687 @@
+//
+// Copyright (C) 1998 Matthias Hoelzer <hoelzer@kde.org>
+// Copyright (C) 2002 David Faure <faure@kde.org>
+// Copyright (C) 2005 Brad Hards <bradh@frogmouth.net>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the7 implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+
+#include <fcntl.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <iostream>
+
+#include <qptrlist.h>
+#include <qfile.h>
+#include <qdatastream.h>
+#include <qregexp.h>
+#include <qtimer.h>
+#include <kmessagebox.h>
+#include <kapplication.h>
+#include <kdebug.h>
+//#include <ktopwidget.h>
+#include <kmainwindow.h>
+#include <kpassivepopup.h>
+#include <krecentdocument.h>
+#include <kapplication.h>
+
+#include "widgets.h"
+
+#include <klocale.h>
+#include <qdialog.h>
+#include <kcmdlineargs.h>
+#include <kaboutdata.h>
+#include <kfiledialog.h>
+#include <kicondialog.h>
+#include <kdirselectdialog.h>
+
+#if defined Q_WS_X11 && ! defined K_WS_QTONLY
+#include <netwm.h>
+#endif
+
+#include <assert.h>
+
+using namespace std;
+
+#if defined(Q_WS_X11)
+extern "C" { int XSetTransientForHint( Display *, unsigned long, unsigned long ); }
+#endif // Q_WS_X11
+
+static KCmdLineOptions options[] =
+{
+ { "yesno <text>", I18N_NOOP("Question message box with yes/no buttons"), 0 },
+ { "yesnocancel <text>", I18N_NOOP("Question message box with yes/no/cancel buttons"), 0 },
+ { "warningyesno <text>", I18N_NOOP("Warning message box with yes/no buttons"), 0 },
+ { "warningcontinuecancel <text>", I18N_NOOP("Warning message box with continue/cancel buttons"), 0 },
+ { "warningyesnocancel <text>", I18N_NOOP("Warning message box with yes/no/cancel buttons"), 0 },
+ { "sorry <text>", I18N_NOOP("'Sorry' message box"), 0 },
+ { "error <text>", I18N_NOOP("'Error' message box"), 0 },
+ { "msgbox <text>", I18N_NOOP("Message Box dialog"), 0 },
+ { "inputbox <text> <init>", I18N_NOOP("Input Box dialog"), 0 },
+ { "password <text>", I18N_NOOP("Password dialog"), 0 },
+ { "textbox <file> [width] [height]", I18N_NOOP("Text Box dialog"), 0 },
+ { "textinputbox <text> <init> [width] [height]", I18N_NOOP("Text Input Box dialog"), 0 },
+ { "combobox <text> [tag item] [tag item] ...", I18N_NOOP("ComboBox dialog"), 0 },
+ { "menu <text> [tag item] [tag item] ...", I18N_NOOP("Menu dialog"), 0 },
+ { "checklist <text> [tag item status] ...", I18N_NOOP("Check List dialog"), 0 },
+ { "radiolist <text> [tag item status] ...", I18N_NOOP("Radio List dialog"), 0 },
+ { "passivepopup <text> <timeout>", I18N_NOOP("Passive Popup"), 0 },
+ { "getopenfilename [startDir] [filter]", I18N_NOOP("File dialog to open an existing file"), 0 },
+ { "getsavefilename [startDir] [filter]", I18N_NOOP("File dialog to save a file"), 0 },
+ { "getexistingdirectory [startDir]", I18N_NOOP("File dialog to select an existing directory"), 0 },
+ { "getopenurl [startDir] [filter]", I18N_NOOP("File dialog to open an existing URL"), 0 },
+ { "getsaveurl [startDir] [filter]", I18N_NOOP("File dialog to save a URL"), 0 },
+ { "geticon [group] [context]", I18N_NOOP("Icon chooser dialog"), 0 },
+ { "progressbar <text> [totalsteps]", I18N_NOOP("Progress bar dialog, returns a DCOP reference for communication"), 0},
+
+ // TODO gauge stuff, reading values from stdin
+
+ { "title <text>", I18N_NOOP("Dialog title"), 0 },
+ { "default <text>", I18N_NOOP("Default entry to use for combobox and menu"), 0 },
+ { "multiple", I18N_NOOP("Allows the --getopenurl and --getopenfilename options to return multiple files"), 0 },
+ { "separate-output", I18N_NOOP("Return list items on separate lines (for checklist option and file open with --multiple)"), 0 },
+ { "print-winid", I18N_NOOP("Outputs the winId of each dialog"), 0 },
+ { "embed <winid>", I18N_NOOP("Makes the dialog transient for an X app specified by winid"), 0 },
+ { "dontagain <file:entry>", I18N_NOOP("Config file and option name for saving the \"dont-show/ask-again\" state"), 0 },
+
+ { "+[arg]", I18N_NOOP("Arguments - depending on main option"), 0 },
+ KCmdLineLastOption
+};
+
+// this class hooks into the eventloop and outputs the id
+// of shown dialogs or makes the dialog transient for other winids.
+// Will destroy itself on app exit.
+class WinIdEmbedder: public QObject
+{
+public:
+ WinIdEmbedder(bool printID, WId winId):
+ QObject(qApp), print(printID), id(winId)
+ {
+ if (qApp)
+ qApp->installEventFilter(this);
+ }
+protected:
+ bool eventFilter(QObject *o, QEvent *e);
+private:
+ bool print;
+ WId id;
+};
+
+bool WinIdEmbedder::eventFilter(QObject *o, QEvent *e)
+{
+ if (e->type() == QEvent::Show && o->isWidgetType()
+ && o->inherits("KDialog"))
+ {
+ QWidget *w = static_cast<QWidget*>(o);
+ if (print)
+ cout << "winId: " << w->winId() << endl;
+#ifdef Q_WS_X11
+ if (id)
+ XSetTransientForHint(w->x11Display(), w->winId(), id);
+#endif
+ deleteLater(); // WinIdEmbedder is not needed anymore after the first dialog was shown
+ return false;
+ }
+ return QObject::eventFilter(o, e);
+}
+
+static void outputStringList(QStringList list, bool separateOutput)
+{
+ if ( separateOutput) {
+ for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
+ cout << (*it).local8Bit().data() << endl;
+ }
+ } else {
+ for ( QStringList::Iterator it = list.begin(); it != list.end(); ++it ) {
+ cout << (*it).local8Bit().data() << " ";
+ }
+ cout << endl;
+ }
+}
+
+static int directCommand(KCmdLineArgs *args)
+{
+ QString title;
+ bool separateOutput = FALSE;
+ bool printWId = args->isSet("print-winid");
+ bool embed = args->isSet("embed");
+ QString defaultEntry;
+
+ // --title text
+ KCmdLineArgs *qtargs = KCmdLineArgs::parsedArgs("qt"); // --title is a qt option
+ if(qtargs->isSet("title")) {
+ title = QFile::decodeName(qtargs->getOption("title"));
+ }
+
+ // --separate-output
+ if (args->isSet("separate-output"))
+ {
+ separateOutput = TRUE;
+ }
+ if (printWId || embed)
+ {
+ WId id = 0;
+ if (embed) {
+ bool ok;
+ long l = args->getOption("embed").toLong(&ok);
+ if (ok)
+ id = (WId)l;
+ }
+ (void)new WinIdEmbedder(printWId, id);
+ }
+
+ // --yesno and other message boxes
+ KMessageBox::DialogType type = (KMessageBox::DialogType) 0;
+ QCString option;
+ if (args->isSet("yesno")) {
+ option = "yesno";
+ type = KMessageBox::QuestionYesNo;
+ }
+ else if (args->isSet("yesnocancel")) {
+ option = "yesnocancel";
+ type = KMessageBox::QuestionYesNoCancel;
+ }
+ else if (args->isSet("warningyesno")) {
+ option = "warningyesno";
+ type = KMessageBox::WarningYesNo;
+ }
+ else if (args->isSet("warningcontinuecancel")) {
+ option = "warningcontinuecancel";
+ type = KMessageBox::WarningContinueCancel;
+ }
+ else if (args->isSet("warningyesnocancel")) {
+ option = "warningyesnocancel";
+ type = KMessageBox::WarningYesNoCancel;
+ }
+ else if (args->isSet("sorry")) {
+ option = "sorry";
+ type = KMessageBox::Sorry;
+ }
+ else if (args->isSet("error")) {
+ option = "error";
+ type = KMessageBox::Error;
+ }
+ else if (args->isSet("msgbox")) {
+ option = "msgbox";
+ type = KMessageBox::Information;
+ }
+
+ if ( !option.isEmpty() )
+ {
+ KConfig* dontagaincfg = NULL;
+ // --dontagain
+ QString dontagain; // QString::null
+ if (args->isSet("dontagain"))
+ {
+ QString value = args->getOption("dontagain");
+ QStringList values = QStringList::split( ':', value );
+ if( values.count() == 2 )
+ {
+ dontagaincfg = new KConfig( values[ 0 ] );
+ KMessageBox::setDontShowAskAgainConfig( dontagaincfg );
+ dontagain = values[ 1 ];
+ }
+ else
+ qDebug( "Incorrect --dontagain!" );
+ }
+ int ret;
+
+ QString text = QString::fromLocal8Bit(args->getOption( option ));
+ int pos;
+ while ((pos = text.find( QString::fromLatin1("\\n") )) >= 0)
+ {
+ text.replace(pos, 2, QString::fromLatin1("\n"));
+ }
+
+ if ( type == KMessageBox::WarningContinueCancel ) {
+ /* TODO configurable button texts*/
+ ret = KMessageBox::messageBox( 0, type, text, title, KStdGuiItem::cont(),
+ KStdGuiItem::no(), dontagain );
+ } else {
+ ret = KMessageBox::messageBox( 0, type, text, title /*, TODO configurable button texts*/,
+ KStdGuiItem::yes(), KStdGuiItem::no(), dontagain );
+ }
+ delete dontagaincfg;
+ // ret is 1 for Ok, 2 for Cancel, 3 for Yes, 4 for No and 5 for Continue.
+ // We want to return 0 for ok, yes and continue, 1 for no and 2 for cancel
+ return (ret == KMessageBox::Ok || ret == KMessageBox::Yes || ret == KMessageBox::Continue) ? 0
+ : ( ret == KMessageBox::No ? 1 : 2 );
+ }
+
+ // --inputbox text [init]
+ if (args->isSet("inputbox"))
+ {
+ QString result;
+ QString init;
+
+ if (args->count() > 0)
+ init = QString::fromLocal8Bit(args->arg(0));
+
+ bool retcode = Widgets::inputBox(0, title, QString::fromLocal8Bit(args->getOption("inputbox")), init, result);
+ cout << result.local8Bit().data() << endl;
+ return retcode ? 0 : 1;
+ }
+
+
+ // --password text
+ if (args->isSet("password"))
+ {
+ QCString result;
+ bool retcode = Widgets::passwordBox(0, title, QString::fromLocal8Bit(args->getOption("password")), result);
+ cout << result.data() << endl;
+ return retcode ? 0 : 1;
+ }
+
+ // --passivepopup
+ if (args->isSet("passivepopup"))
+ {
+ int duration = 0;
+ if (args->count() > 0)
+ duration = 1000 * QString::fromLocal8Bit(args->arg(0)).toInt();
+ if (duration == 0)
+ duration = 10000;
+ KPassivePopup *popup = KPassivePopup::message( KPassivePopup::Balloon, // style
+ title,
+ QString::fromLocal8Bit( args->getOption("passivepopup") ),
+ 0, // icon
+ (QWidget*)0UL, // parent
+ 0, // name
+ duration );
+ QTimer *timer = new QTimer();
+ QObject::connect( timer, SIGNAL( timeout() ), kapp, SLOT( quit() ) );
+ QObject::connect( popup, SIGNAL( clicked() ), kapp, SLOT( quit() ) );
+ timer->start( duration, TRUE );
+
+#ifdef Q_WS_X11
+ if ( ! kapp->geometryArgument().isEmpty()) {
+ int x, y;
+ int w, h;
+ int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h);
+ if ( (m & XNegative) )
+ x = KApplication::desktop()->width() + x - w;
+ if ( (m & YNegative) )
+ y = KApplication::desktop()->height() + y - h;
+ popup->setAnchor( QPoint(x, y) );
+ }
+#endif
+ kapp->exec();
+ return 0;
+ }
+
+ // --textbox file [width] [height]
+ if (args->isSet("textbox"))
+ {
+ int w = 0;
+ int h = 0;
+
+ if (args->count() == 2) {
+ w = QString::fromLocal8Bit(args->arg(0)).toInt();
+ h = QString::fromLocal8Bit(args->arg(1)).toInt();
+ }
+
+ return Widgets::textBox(0, w, h, title, QString::fromLocal8Bit(args->getOption("textbox")));
+ }
+
+ // --textinputbox file [width] [height]
+ if (args->isSet("textinputbox"))
+ {
+ int w = 400;
+ int h = 200;
+
+ if (args->count() == 4) {
+ w = QString::fromLocal8Bit(args->arg(2)).toInt();
+ h = QString::fromLocal8Bit(args->arg(3)).toInt();
+ }
+
+ QStringList list;
+ list.append(QString::fromLocal8Bit(args->getOption("textinputbox")));
+
+ if (args->count() >= 1) {
+ for (int i = 0; i < args->count(); i++)
+ list.append(QString::fromLocal8Bit(args->arg(i)));
+ }
+
+ QCString result;
+ int ret = Widgets::textInputBox(0, w, h, title, list, result);
+ cout << result.data() << endl;
+ return ret;
+ }
+
+ // --combobox <text> [tag item] [tag item] ..."
+ if (args->isSet("combobox")) {
+ QStringList list;
+ if (args->count() >= 2) {
+ for (int i = 0; i < args->count(); i++) {
+ list.append(QString::fromLocal8Bit(args->arg(i)));
+ }
+ QString text = QString::fromLocal8Bit(args->getOption("combobox"));
+ if (args->isSet("default")) {
+ defaultEntry = args->getOption("default");
+ }
+ QString result;
+ bool retcode = Widgets::comboBox(0, title, text, list, defaultEntry, result);
+ cout << result.local8Bit().data() << endl;
+ return retcode ? 0 : 1;
+ }
+ return -1;
+ }
+
+ // --menu text [tag item] [tag item] ...
+ if (args->isSet("menu")) {
+ QStringList list;
+ if (args->count() >= 2) {
+ for (int i = 0; i < args->count(); i++) {
+ list.append(QString::fromLocal8Bit(args->arg(i)));
+ }
+ QString text = QString::fromLocal8Bit(args->getOption("menu"));
+ if (args->isSet("default")) {
+ defaultEntry = args->getOption("default");
+ }
+ QString result;
+ bool retcode = Widgets::listBox(0, title, text, list, defaultEntry, result);
+ if (1 == retcode) { // OK was selected
+ cout << result.local8Bit().data() << endl;
+ }
+ return retcode ? 0 : 1;
+ }
+ return -1;
+ }
+
+ // --checklist text [tag item status] [tag item status] ...
+ if (args->isSet("checklist")) {
+ QStringList list;
+ if (args->count() >= 3) {
+ for (int i = 0; i < args->count(); i++) {
+ list.append(QString::fromLocal8Bit(args->arg(i)));
+ }
+
+ QString text = QString::fromLocal8Bit(args->getOption("checklist"));
+ QStringList result;
+
+ bool retcode = Widgets::checkList(0, title, text, list, separateOutput, result);
+
+ unsigned int i;
+ for (i=0; i<result.count(); i++)
+ if (!result[i].local8Bit().isEmpty()) {
+ cout << result[i].local8Bit().data() << endl;
+ }
+ exit( retcode ? 0 : 1 );
+ }
+ return -1;
+ }
+
+ // --radiolist text width height menuheight [tag item status]
+ if (args->isSet("radiolist")) {
+ QStringList list;
+ if (args->count() >= 3) {
+ for (int i = 0; i < args->count(); i++) {
+ list.append(QString::fromLocal8Bit(args->arg(i)));
+ }
+
+ QString text = QString::fromLocal8Bit(args->getOption("radiolist"));
+ QString result;
+ bool retcode = Widgets::radioBox(0, title, text, list, result);
+ cout << result.local8Bit().data() << endl;
+ exit( retcode ? 0 : 1 );
+ }
+ return -1;
+ }
+
+ // getopenfilename [startDir] [filter]
+ if (args->isSet("getopenfilename")) {
+ QString startDir;
+ QString filter;
+ startDir = QString::fromLocal8Bit(args->getOption("getopenfilename"));
+ if (args->count() >= 1) {
+ filter = QString::fromLocal8Bit(args->arg(0));
+ }
+ KFileDialog dlg(startDir, filter, 0, "filedialog", true);
+ dlg.setOperationMode( KFileDialog::Opening );
+
+ if (args->isSet("multiple")) {
+ dlg.setMode(KFile::Files | KFile::LocalOnly);
+ } else {
+ dlg.setMode(KFile::File | KFile::LocalOnly);
+ }
+ Widgets::handleXGeometry(&dlg);
+ kapp->setTopWidget( &dlg );
+ dlg.setCaption(title.isNull() ? i18n("Open") : title);
+ dlg.exec();
+
+ if (args->isSet("multiple")) {
+ QStringList result = dlg.selectedFiles();
+ if ( !result.isEmpty() ) {
+ outputStringList( result, separateOutput );
+ return 0;
+ }
+ } else {
+ QString result = dlg.selectedFile();
+ if (!result.isEmpty()) {
+ cout << result.local8Bit().data() << endl;
+ return 0;
+ }
+ }
+ return 1; // cancelled
+ }
+
+
+ // getsaveurl [startDir] [filter]
+ // getsavefilename [startDir] [filter]
+ if ( (args->isSet("getsavefilename") ) || (args->isSet("getsaveurl") ) ) {
+ QString startDir;
+ QString filter;
+ if ( args->isSet("getsavefilename") ) {
+ startDir = QString::fromLocal8Bit(args->getOption("getsavefilename"));
+ } else {
+ startDir = QString::fromLocal8Bit(args->getOption("getsaveurl"));
+ }
+ if (args->count() >= 1) {
+ filter = QString::fromLocal8Bit(args->arg(0));
+ }
+ // copied from KFileDialog::getSaveFileName(), so we can add geometry
+ bool specialDir = ( startDir.at(0) == ':' );
+ KFileDialog dlg( specialDir ? startDir : QString::null, filter, 0, "filedialog", true );
+ if ( !specialDir )
+ dlg.setSelection( startDir );
+ dlg.setOperationMode( KFileDialog::Saving );
+ Widgets::handleXGeometry(&dlg);
+ kapp->setTopWidget( &dlg );
+ dlg.setCaption(title.isNull() ? i18n("Save As") : title);
+ dlg.exec();
+
+ if ( args->isSet("getsaveurl") ) {
+ KURL result = dlg.selectedURL();
+ if ( result.isValid()) {
+
+ cout << result.url().local8Bit().data() << endl;
+ return 0;
+ }
+ } else { // getsavefilename
+ QString result = dlg.selectedFile();
+ if (!result.isEmpty()) {
+ KRecentDocument::add(result);
+ cout << result.local8Bit().data() << endl;
+ return 0;
+ }
+ }
+ return 1; // cancelled
+ }
+
+ // getexistingdirectory [startDir]
+ if (args->isSet("getexistingdirectory")) {
+ QString startDir;
+ startDir = QString::fromLocal8Bit(args->getOption("getexistingdirectory"));
+ QString result;
+#ifdef Q_WS_WIN
+ result = QFileDialog::getExistingDirectory(startDir, 0, "getExistingDirectory",
+ title, true, true);
+#else
+ KURL url;
+ KDirSelectDialog myDialog( startDir, true, 0,
+ "kdirselect dialog", true );
+
+ kapp->setTopWidget( &myDialog );
+
+ Widgets::handleXGeometry(&myDialog);
+ if ( !title.isNull() )
+ myDialog.setCaption( title );
+
+ if ( myDialog.exec() == QDialog::Accepted )
+ url = myDialog.url();
+
+ if ( url.isValid() )
+ result = url.path();
+#endif
+ if (!result.isEmpty()) {
+ cout << result.local8Bit().data() << endl;
+ return 0;
+ }
+ return 1; // cancelled
+ }
+
+ // getopenurl [startDir] [filter]
+ if (args->isSet("getopenurl")) {
+ QString startDir;
+ QString filter;
+ startDir = QString::fromLocal8Bit(args->getOption("getopenurl"));
+ if (args->count() >= 1) {
+ filter = QString::fromLocal8Bit(args->arg(0));
+ }
+ KFileDialog dlg(startDir, filter, 0, "filedialog", true);
+ dlg.setOperationMode( KFileDialog::Opening );
+
+ if (args->isSet("multiple")) {
+ dlg.setMode(KFile::Files);
+ } else {
+ dlg.setMode(KFile::File);
+ }
+ Widgets::handleXGeometry(&dlg);
+ kapp->setTopWidget( &dlg );
+ dlg.setCaption(title.isNull() ? i18n("Open") : title);
+ dlg.exec();
+
+ if (args->isSet("multiple")) {
+ KURL::List result = dlg.selectedURLs();
+ if ( !result.isEmpty() ) {
+ outputStringList( result.toStringList(), separateOutput );
+ return 0;
+ }
+ } else {
+ KURL result = dlg.selectedURL();
+ if (!result.isEmpty()) {
+ cout << result.url().local8Bit().data() << endl;
+ return 0;
+ }
+ }
+ return 1; // cancelled
+ }
+
+ // geticon [group] [context]
+ if (args->isSet("geticon")) {
+ QString groupStr, contextStr;
+ groupStr = QString::fromLocal8Bit(args->getOption("geticon"));
+ if (args->count() >= 1) {
+ contextStr = QString::fromLocal8Bit(args->arg(0));
+ }
+ KIcon::Group group = KIcon::NoGroup;
+ if ( groupStr == QString::fromLatin1( "Desktop" ) )
+ group = KIcon::Desktop;
+ else if ( groupStr == QString::fromLatin1( "Toolbar" ) )
+ group = KIcon::Toolbar;
+ else if ( groupStr == QString::fromLatin1( "MainToolbar" ) )
+ group = KIcon::MainToolbar;
+ else if ( groupStr == QString::fromLatin1( "Small" ) )
+ group = KIcon::Small;
+ else if ( groupStr == QString::fromLatin1( "Panel" ) )
+ group = KIcon::Panel;
+ else if ( groupStr == QString::fromLatin1( "User" ) )
+ group = KIcon::User;
+ KIcon::Context context = KIcon::Any;
+ // From kicontheme.cpp
+ if ( contextStr == QString::fromLatin1( "Devices" ) )
+ context = KIcon::Device;
+ else if ( contextStr == QString::fromLatin1( "MimeTypes" ) )
+ context = KIcon::MimeType;
+ else if ( contextStr == QString::fromLatin1( "FileSystems" ) )
+ context = KIcon::FileSystem;
+ else if ( contextStr == QString::fromLatin1( "Applications" ) )
+ context = KIcon::Application;
+ else if ( contextStr == QString::fromLatin1( "Actions" ) )
+ context = KIcon::Action;
+
+ KIconDialog dlg(0, "icon dialog");
+ kapp->setTopWidget( &dlg );
+ dlg.setup( group, context);
+ if (!title.isNull())
+ dlg.setCaption(title);
+ Widgets::handleXGeometry(&dlg);
+
+ QString result = dlg.openDialog();
+
+ if (!result.isEmpty()) {
+ cout << result.local8Bit().data() << endl;
+ return 0;
+ }
+ return 1; // cancelled
+ }
+
+ // --progressbar text totalsteps
+ if (args->isSet("progressbar"))
+ {
+ cout << "DCOPRef(kdialog-" << getpid() << ",ProgressDialog)" << endl;
+ if (fork())
+ exit(0);
+ close(1);
+
+ int totalsteps = 100;
+ QString text = QString::fromLocal8Bit(args->getOption("progressbar"));
+
+ if (args->count() == 1)
+ totalsteps = QString::fromLocal8Bit(args->arg(0)).toInt();
+
+ return Widgets::progressBar(0, title, text, totalsteps) ? 1 : 0;
+ }
+
+ KCmdLineArgs::usage();
+ return -2; // NOTREACHED
+}
+
+
+int main(int argc, char *argv[])
+{
+ KAboutData aboutData( "kdialog", I18N_NOOP("KDialog"),
+ "1.0", I18N_NOOP( "KDialog can be used to show nice dialog boxes from shell scripts" ),
+ KAboutData::License_GPL,
+ "(C) 2000, Nick Thompson");
+ aboutData.addAuthor("David Faure", I18N_NOOP("Current maintainer"),"faure@kde.org");
+ aboutData.addAuthor("Brad Hards", 0, "bradh@frogmouth.net");
+ aboutData.addAuthor("Nick Thompson",0, 0/*"nickthompson@lucent.com" bounces*/);
+ aboutData.addAuthor("Matthias Hölzer",0,"hoelzer@kde.org");
+ aboutData.addAuthor("David Gümbel",0,"david.guembel@gmx.net");
+ aboutData.addAuthor("Richard Moore",0,"rich@kde.org");
+ aboutData.addAuthor("Dawit Alemayehu",0,"adawit@kde.org");
+
+ KCmdLineArgs::init(argc, argv, &aboutData);
+ KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
+
+ KApplication app;
+
+ KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
+
+ // execute direct kdialog command
+ return directCommand(args);
+}
+
diff --git a/kdialog/klistboxdialog.cpp b/kdialog/klistboxdialog.cpp
new file mode 100644
index 000000000..7ddbf509c
--- /dev/null
+++ b/kdialog/klistboxdialog.cpp
@@ -0,0 +1,60 @@
+//
+// Copyright (C) 1998 Matthias Hoelzer
+// email: hoelzer@physik.uni-wuerzburg.de
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the7 implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#include <qlabel.h>
+#include <qlistbox.h>
+#include <qvbox.h>
+
+#include "klistboxdialog.h"
+#include "klistboxdialog.moc"
+
+#include "klocale.h"
+
+KListBoxDialog::KListBoxDialog(QString text, QWidget *parent)
+ : KDialogBase( parent, 0, true, QString::null, Ok|Cancel, Ok, true )
+{
+ QVBox *page = makeVBoxMainWidget();
+
+ label = new QLabel(text, page);
+ label->setAlignment(AlignCenter);
+
+ table = new QListBox(page);
+ table->setFocus();
+}
+
+void KListBoxDialog::insertItem(const QString& item)
+{
+ table->insertItem(item);
+ table->setCurrentItem(0);
+}
+
+void KListBoxDialog::setCurrentItem(const QString& item)
+{
+ for ( int i=0; i < (int) table->count(); i++ ) {
+ if ( table->text(i) == item ) {
+ table->setCurrentItem(i);
+ break;
+ }
+ }
+}
+
+int KListBoxDialog::currentItem()
+{
+ return table->currentItem();
+}
diff --git a/kdialog/klistboxdialog.h b/kdialog/klistboxdialog.h
new file mode 100644
index 000000000..35a326da7
--- /dev/null
+++ b/kdialog/klistboxdialog.h
@@ -0,0 +1,49 @@
+//
+// Copyright (C) 1998 Matthias Hoelzer
+// email: hoelzer@physik.uni-wuerzburg.de
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the7 implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+
+#ifndef _KLISTBOXDIALOG_H_
+#define _KLISTBOXDIALOG_H_
+
+#include <kdialogbase.h>
+
+class KListBoxDialog : public KDialogBase
+{
+ Q_OBJECT
+
+public:
+
+ KListBoxDialog(QString text, QWidget *parent=0);
+ ~KListBoxDialog() {};
+
+ QListBox &getTable() { return *table; };
+
+ void insertItem( const QString& text );
+ void setCurrentItem ( const QString& text );
+ int currentItem();
+
+protected:
+
+ QListBox *table;
+ QLabel *label;
+
+};
+
+
+#endif
diff --git a/kdialog/progresscanceldemo b/kdialog/progresscanceldemo
new file mode 100755
index 000000000..358ee54bd
--- /dev/null
+++ b/kdialog/progresscanceldemo
@@ -0,0 +1,11 @@
+#!/bin/sh
+dcopRef=`./kdialog --progressbar "Press Cancel at Any time" 10`
+dcop $dcopRef showCancelButton true
+
+until test "true" == `dcop $dcopRef wasCancelled`; do
+ sleep 1
+ inc=$((`dcop $dcopRef progress` + 1))
+ dcop $dcopRef setProgress $inc;
+done
+
+dcop $dcopRef close
diff --git a/kdialog/progressdemo b/kdialog/progressdemo
new file mode 100755
index 000000000..e6f4bb48c
--- /dev/null
+++ b/kdialog/progressdemo
@@ -0,0 +1,18 @@
+#!/bin/sh
+dcopRef=`./kdialog --geometry 300x200+100-100 --progressbar "Initialising" 6`
+dcop $dcopRef setProgress 1
+dcop $dcopRef setLabel "Thinking really hard"
+sleep 2
+dcop $dcopRef setProgress 2
+sleep 2
+dcop $dcopRef setLabel "Thinking some more"
+dcop $dcopRef setProgress 3
+sleep 2
+dcop $dcopRef setProgress 4
+sleep 2
+dcop $dcopRef setLabel "Finishing up"
+dcop $dcopRef setProgress 5
+sleep 1
+dcop $dcopRef setProgress 6
+sleep 1
+dcop $dcopRef close
diff --git a/kdialog/progressdialog.cpp b/kdialog/progressdialog.cpp
new file mode 100644
index 000000000..fa145f83e
--- /dev/null
+++ b/kdialog/progressdialog.cpp
@@ -0,0 +1,92 @@
+//
+// Copyright (C) 2004 Stephan Binner <binner@kde.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the7 implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#include <dcopclient.h>
+#include "progressdialog.h"
+#include "kdebug.h"
+#include "widgets.h"
+
+ProgressDialog::ProgressDialog(QWidget* parent, const QString& caption, const QString& text, int totalSteps)
+ : DCOPObject( "ProgressDialog" ), KProgressDialog(parent, 0, caption, text, false)
+{
+ setAutoClose( false );
+ setTotalSteps( totalSteps );
+ showCancelButton( false );
+ Widgets::handleXGeometry(this);
+}
+
+void ProgressDialog::setTotalSteps( int totalSteps )
+{
+ progressBar()->setTotalSteps( totalSteps );
+ if ( progress()>=totalSteps )
+ showCancelButton( false );
+}
+
+int ProgressDialog::totalSteps() const
+{
+ return progressBar()->totalSteps();
+}
+
+void ProgressDialog::setProgress( int progress )
+{
+ progressBar()->setProgress( progress );
+ if (progress>=totalSteps() )
+ showCancelButton( false );
+}
+
+int ProgressDialog::progress() const
+{
+ return progressBar()->progress();
+}
+
+void ProgressDialog::setLabel(const QString& label)
+{
+ KProgressDialog::setLabel( label );
+}
+
+void ProgressDialog::showCancelButton( bool show )
+{
+ setAllowCancel( false );
+ KProgressDialog::showCancelButton( show );
+}
+
+bool ProgressDialog::wasCancelled() const
+{
+ return KProgressDialog::wasCancelled();
+}
+
+void ProgressDialog::setAutoClose( bool close )
+{
+ KProgressDialog::setAutoClose( close );
+}
+
+bool ProgressDialog::autoClose() const
+{
+ return KProgressDialog::autoClose();
+}
+
+void ProgressDialog::close()
+{
+ slotClose();
+}
+
+void ProgressDialog::ignoreCancel()
+{
+ KProgressDialog::ignoreCancel();
+}
+#include "progressdialog.moc"
diff --git a/kdialog/progressdialog.h b/kdialog/progressdialog.h
new file mode 100644
index 000000000..4b7d90754
--- /dev/null
+++ b/kdialog/progressdialog.h
@@ -0,0 +1,50 @@
+//
+// Copyright (C) 2004 Stephan Binner <binner@kde.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the7 implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+#ifndef PROGRESSDIALOG_H
+#define PROGRESSDIALOG_H
+
+#include <kprogress.h>
+#include "progressdialogiface.h"
+
+class ProgressDialog : public KProgressDialog, virtual public ProgressDialogIface
+{
+ Q_OBJECT
+
+ public:
+ ProgressDialog(QWidget* parent = 0, const QString& caption = QString::null, const QString& text = QString::null, int totalSteps = 100);
+
+ void setTotalSteps( int );
+ int totalSteps() const;
+
+ void setProgress( int );
+ int progress() const;
+
+ void setLabel(const QString&);
+
+ void showCancelButton(bool show);
+ bool wasCancelled() const;
+ void ignoreCancel();
+
+ void setAutoClose( bool );
+ bool autoClose() const;
+
+ void close();
+};
+
+#endif // PROGRESSDIALOG_H
diff --git a/kdialog/progressdialogiface.h b/kdialog/progressdialogiface.h
new file mode 100644
index 000000000..2974cb9a9
--- /dev/null
+++ b/kdialog/progressdialogiface.h
@@ -0,0 +1,28 @@
+#ifndef PROGRESSDIALOGIFACE_H
+#define PROGRESSDIALOGIFACE_H
+
+#include <dcopobject.h>
+
+class ProgressDialogIface : virtual public DCOPObject
+{
+ K_DCOP
+ k_dcop:
+
+ virtual void setTotalSteps( int ) =0;
+ virtual int totalSteps() const =0;
+
+ virtual void setProgress( int ) =0;
+ virtual int progress() const =0;
+
+ virtual void setLabel( const QString& ) =0;
+
+ virtual void showCancelButton ( bool ) =0;
+ virtual bool wasCancelled() const =0;
+ virtual void ignoreCancel() =0;
+
+ virtual void setAutoClose( bool ) =0;
+ virtual bool autoClose() const =0;
+ virtual void close() =0;
+};
+
+#endif // PROGRESSDIALOGIFACE_H
diff --git a/kdialog/test b/kdialog/test
new file mode 100755
index 000000000..0d41dbb0a
--- /dev/null
+++ b/kdialog/test
@@ -0,0 +1,74 @@
+#!/bin/sh
+echo "yesno box:"
+./kdialog --geometry 400x300+100+50 --title "This is a yesno box" --yesno "Choose: yes or no"
+if [ $? = 0 ]; then
+ echo " your choice was: yes"
+else
+ echo " your choice was: no"
+fi
+
+echo "continue or cancel warning box:"
+./kdialog --geometry 200x300+100-50 --title "This is a warningcontinuecancel box" --warningcontinuecancel "Choose: continue or cancel"
+if [ $? = 0 ]; then
+ echo " your choice was: continue"
+else
+ echo " your choice was: cancel"
+fi
+
+echo "message box:"
+./kdialog --geometry 300x400-100-50 --title "This is a message" --msgbox "Well, this is it:\nthe message"
+
+echo "input box:"
+./kdialog --title "This is a input box" --inputbox "What is your name" "Joe User"
+if [ $? = 0 ]; then
+ echo " you accepted"
+else
+ echo " you did not accept"
+fi
+
+echo "input box, with geometry:"
+./kdialog --geometry 300x400-100-50 --title "This is a input box" --inputbox "What is your name" "Joe User"
+if [ $? = 0 ]; then
+ echo " you accepted"
+else
+ echo " you did not accept"
+fi
+
+echo "text box:"
+./kdialog --geometry 300x400-100-50 --miniicon "about_kde" --title "This is a text box" --textbox widgets.h 400 300
+
+echo "menu:"
+./kdialog --miniicon "about_kde" --geometry 300x400-100-50 --title "This is a menu" --default "French" --menu "Choose one of these" a English b German c French d Spanish
+
+echo "checklist:"
+./kdialog --geometry 400x300+100+50 --miniicon "about_kde" --title "This is a checklist" --checklist "Choose some of these" a English on b German off c French off d Spanish on
+
+echo "radiolist:"
+./kdialog --geometry 400x300+100+50 --miniicon "about_kde" --title "This is a radiolist" --radiolist "Choose one of these" a English off b German off c French on d Spanish off
+
+echo "combobox:"
+./kdialog --geometry 400x300+100+50 --miniicon "about_kde" --default "Chocolate" --title "This is a combobox" --combobox "Pick your favorite ice-cream flavor:" "Vanilla" "Chocolate" "Strawberry" "Fudge"
+
+echo "passivepopup:"
+./kdialog --geometry 1x1+200+350 --title "This is a passive popup" --passivepopup "It will disappear in about 10 seconds" 10
+
+echo "password:"
+./kdialog --title "This is a password dialog" --geometry 400x300+100+50 --icon "desktop" --miniicon "about_kde" --password "Enter the password:"
+
+echo "Open File:"
+./kdialog --getopenfilename . "*.cpp *.cc *.c |C and C++ Source Files"
+
+echo "Open multiple files:"
+./kdialog --multiple --getopenfilename . "*.cpp *.cc *.c |C and C++ Source Files"
+
+echo "Open multiple files, output on separate lines:"
+./kdialog --multiple --separate-output --getopenfilename . "*.cpp *.cc *.c |C and C++ Source Files"
+
+echo "Open URL:"
+./kdialog --getopenurl . "*.cpp *.cc *.c |C and C++ Source Files"
+
+echo "Open multiple URLs:"
+./kdialog --multiple --getopenurl . "*.cpp *.cc *.c |C and C++ Source Files"
+
+echo "Open multiple URLs, output on separate lines:"
+./kdialog --multiple --separate-output --getopenurl . "*.cpp *.cc *.c |C and C++ Source Files"
diff --git a/kdialog/widgets.cpp b/kdialog/widgets.cpp
new file mode 100644
index 000000000..41f5e452f
--- /dev/null
+++ b/kdialog/widgets.cpp
@@ -0,0 +1,282 @@
+//
+// Copyright (C) 1998 Matthias Hoelzer <hoelzer@kde.org>
+// Copyright (C) 2002 David Faure <faure@kde.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the7 implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+
+#include <klocale.h>
+#include <kmessagebox.h>
+
+#include "widgets.h"
+#include "klistboxdialog.h"
+#include "progressdialog.h"
+#include <kinputdialog.h>
+#include <kpassdlg.h>
+#include <kcombobox.h>
+#include <kdebug.h>
+#include <kapplication.h>
+
+#include <qlabel.h>
+#include <ktextedit.h>
+#include <qvbox.h>
+#include <qfile.h>
+
+#if defined Q_WS_X11 && ! defined K_WS_QTONLY
+#include <netwm.h>
+#endif
+
+void Widgets::handleXGeometry(QWidget * dlg)
+{
+#ifdef Q_WS_X11
+ if ( ! kapp->geometryArgument().isEmpty()) {
+ int x, y;
+ int w, h;
+ int m = XParseGeometry( kapp->geometryArgument().latin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h);
+ if ( (m & XNegative) )
+ x = KApplication::desktop()->width() + x - w;
+ if ( (m & YNegative) )
+ y = KApplication::desktop()->height() + y - h;
+ dlg->setGeometry(x, y, w, h);
+ // kdDebug() << "x: " << x << " y: " << y << " w: " << w << " h: " << h << endl;
+ }
+#endif
+}
+
+bool Widgets::inputBox(QWidget *parent, const QString& title, const QString& text, const QString& init, QString &result)
+{
+ bool ok;
+ QString str = KInputDialog::text( title, text, init, &ok, parent, 0, 0, QString::null );
+ if ( ok )
+ result = str;
+ return ok;
+}
+
+bool Widgets::passwordBox(QWidget *parent, const QString& title, const QString& text, QCString &result)
+{
+ KPasswordDialog dlg( KPasswordDialog::Password, false, 0, parent );
+
+ kapp->setTopWidget( &dlg );
+ dlg.setCaption(title);
+ dlg.setPrompt(text);
+
+ handleXGeometry(&dlg);
+
+ bool retcode = (dlg.exec() == QDialog::Accepted);
+ if ( retcode )
+ result = dlg.password();
+ return retcode;
+}
+
+int Widgets::textBox(QWidget *parent, int width, int height, const QString& title, const QString& file)
+{
+// KTextBox dlg(parent, 0, TRUE, width, height, file);
+ KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok, KDialogBase::Ok );
+
+ kapp->setTopWidget( &dlg );
+ KTextEdit *edit = new KTextEdit( dlg.makeVBoxMainWidget() );
+ edit->setReadOnly(TRUE);
+
+ QFile f(file);
+ if (!f.open(IO_ReadOnly))
+ {
+ kdError() << i18n("kdialog: could not open file ") << file << endl;
+ return -1;
+ }
+ QTextStream s(&f);
+
+ while (!s.eof())
+ edit->append(s.readLine());
+
+ edit->moveCursor(QTextEdit::MoveHome, false);
+
+ f.close();
+
+ if ( width > 0 && height > 0 )
+ dlg.setInitialSize( QSize( width, height ) );
+
+ handleXGeometry(&dlg);
+ dlg.setCaption(title);
+ dlg.exec();
+ return 0;
+}
+
+int Widgets::textInputBox(QWidget *parent, int width, int height, const QString& title, const QStringList& args, QCString &result)
+{
+// KTextBox dlg(parent, 0, TRUE, width, height, file);
+ KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok, KDialogBase::Ok );
+
+ kapp->setTopWidget( &dlg );
+ QVBox* vbox = dlg.makeVBoxMainWidget();
+
+ if( args.count() > 0 )
+ {
+ QLabel *label = new QLabel(vbox);
+ label->setText(args[0]);
+ }
+
+ KTextEdit *edit = new KTextEdit( vbox );
+ edit->setReadOnly(FALSE);
+ edit->setTextFormat( Qt::PlainText );
+ edit->setFocus();
+
+ if( args.count() > 1 )
+ edit->setText( args[1] );
+
+ if ( width > 0 && height > 0 )
+ dlg.setInitialSize( QSize( width, height ) );
+
+ handleXGeometry(&dlg);
+ dlg.setCaption(title);
+ dlg.exec();
+ result = edit->text().local8Bit();
+ return 0;
+}
+
+bool Widgets::comboBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args,
+ const QString& defaultEntry, QString &result)
+{
+ KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok|KDialogBase::Cancel,
+ KDialogBase::Ok );
+
+ kapp->setTopWidget( &dlg );
+ dlg.setCaption(title);
+ QVBox* vbox = dlg.makeVBoxMainWidget();
+
+ QLabel label (vbox);
+ label.setText (text);
+ KComboBox combo (vbox);
+ combo.insertStringList (args);
+ combo.setCurrentItem( defaultEntry, false );
+
+ handleXGeometry(&dlg);
+
+ bool retcode = (dlg.exec() == QDialog::Accepted);
+
+ if (retcode)
+ result = combo.currentText();
+
+ return retcode;
+}
+
+bool Widgets::listBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args,
+ const QString& defaultEntry, QString &result)
+{
+ KListBoxDialog box(text,parent);
+
+ kapp->setTopWidget( &box );
+ box.setCaption(title);
+
+ for (unsigned int i = 0; i+1<args.count(); i += 2) {
+ box.insertItem(args[i+1]);
+ }
+ box.setCurrentItem( defaultEntry );
+
+ handleXGeometry(&box);
+
+ bool retcode = (box.exec() == QDialog::Accepted);
+ if ( retcode )
+ result = args[ box.currentItem()*2 ];
+ return retcode;
+}
+
+
+bool Widgets::checkList(QWidget *parent, const QString& title, const QString& text, const QStringList& args, bool separateOutput, QStringList &result)
+{
+ QStringList entries, tags;
+ QString rs;
+
+ result.clear();
+
+ KListBoxDialog box(text,parent);
+
+ QListBox &table = box.getTable();
+
+ kapp->setTopWidget( &box );
+ box.setCaption(title);
+
+ for (unsigned int i=0; i+2<args.count(); i += 3) {
+ tags.append(args[i]);
+ entries.append(args[i+1]);
+ }
+
+ table.insertStringList(entries);
+ table.setMultiSelection(TRUE);
+ table.setCurrentItem(0); // This is to circumvent a Qt bug
+
+ for (unsigned int i=0; i+2<args.count(); i += 3) {
+ table.setSelected( i/3, args[i+2] == QString::fromLatin1("on") );
+ }
+
+ handleXGeometry(&box);
+
+ bool retcode = (box.exec() == QDialog::Accepted);
+
+ if ( retcode ) {
+ if (separateOutput) {
+ for (unsigned int i=0; i<table.count(); i++)
+ if (table.isSelected(i))
+ result.append(tags[i]);
+ } else {
+ for (unsigned int i=0; i<table.count(); i++)
+ if (table.isSelected(i))
+ rs += QString::fromLatin1("\"") + tags[i] + QString::fromLatin1("\" ");
+ result.append(rs);
+ }
+ }
+ return retcode;
+}
+
+
+bool Widgets::radioBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, QString &result)
+{
+ QStringList entries, tags;
+
+ KListBoxDialog box(text,parent);
+
+ QListBox &table = box.getTable();
+
+ kapp->setTopWidget( &box );
+ box.setCaption(title);
+
+ for (unsigned int i=0; i+2<args.count(); i += 3) {
+ tags.append(args[i]);
+ entries.append(args[i+1]);
+ }
+
+ table.insertStringList(entries);
+
+ for (unsigned int i=0; i+2<args.count(); i += 3) {
+ table.setSelected( i/3, args[i+2] == QString::fromLatin1("on") );
+ }
+
+ handleXGeometry(&box);
+
+ bool retcode = (box.exec() == QDialog::Accepted);
+ if ( retcode )
+ result = tags[ table.currentItem() ];
+ return retcode;
+}
+
+bool Widgets::progressBar(QWidget *parent, const QString& title, const QString& text, int totalSteps)
+{
+ ProgressDialog dlg( parent, title, text, totalSteps );
+ kapp->setTopWidget( &dlg );
+ dlg.setCaption( title );
+ handleXGeometry(&dlg);
+ dlg.exec();
+ return dlg.wasCancelled();
+}
diff --git a/kdialog/widgets.h b/kdialog/widgets.h
new file mode 100644
index 000000000..8808b810c
--- /dev/null
+++ b/kdialog/widgets.h
@@ -0,0 +1,43 @@
+//
+// Copyright (C) 1998 Matthias Hoelzer <hoelzer@kde.org>
+// Copyright (C) 2002 David Faure <faure@kde.org>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the7 implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+//
+
+
+#ifndef _WIDGETS_H_
+#define _WIDGETS_H_
+
+#include <qwidget.h>
+#include <qstring.h>
+
+namespace Widgets
+{
+ bool inputBox(QWidget *parent, const QString& title, const QString& text, const QString& init, QString &result);
+ bool passwordBox(QWidget *parent, const QString& title, const QString& text, QCString &result);
+ int textBox(QWidget *parent, int width, int height, const QString& title, const QString& file);
+ int textInputBox(QWidget *parent, int width, int height, const QString& title, const QStringList& args, QCString &result);
+ bool listBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, const QString &defaultEntry, QString &result);
+ bool checkList(QWidget *parent, const QString& title, const QString& text, const QStringList& args, bool separateOutput, QStringList &result);
+ bool radioBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, QString &result);
+ bool comboBox(QWidget *parent, const QString& title, const QString& text, const QStringList& args, const QString& defaultEntry, QString &result);
+ bool progressBar(QWidget *parent, const QString& title, const QString& text, int totalSteps);
+
+ void handleXGeometry(QWidget * dlg);
+
+}
+
+#endif