diff options
Diffstat (limited to 'kdialog')
-rw-r--r-- | kdialog/CMakeLists.txt | 31 | ||||
-rw-r--r-- | kdialog/Makefile.am | 13 | ||||
-rw-r--r-- | kdialog/README | 14 | ||||
-rw-r--r-- | kdialog/kdialog.cpp | 701 | ||||
-rwxr-xr-x | kdialog/progresscanceldemo | 11 | ||||
-rwxr-xr-x | kdialog/progressdemo | 18 | ||||
-rw-r--r-- | kdialog/progressdialog.cpp | 92 | ||||
-rw-r--r-- | kdialog/progressdialog.h | 50 | ||||
-rw-r--r-- | kdialog/progressdialogiface.h | 28 | ||||
-rw-r--r-- | kdialog/tdelistboxdialog.cpp | 60 | ||||
-rw-r--r-- | kdialog/tdelistboxdialog.h | 49 | ||||
-rwxr-xr-x | kdialog/test | 74 | ||||
-rw-r--r-- | kdialog/widgets.cpp | 282 | ||||
-rw-r--r-- | kdialog/widgets.h | 43 |
14 files changed, 1466 insertions, 0 deletions
diff --git a/kdialog/CMakeLists.txt b/kdialog/CMakeLists.txt new file mode 100644 index 000000000..6620430d4 --- /dev/null +++ b/kdialog/CMakeLists.txt @@ -0,0 +1,31 @@ +################################################# +# +# (C) 2010-2011 Serghei Amelian +# serghei (DOT) amelian (AT) gmail.com +# +# Improvements and feedback are welcome +# +# This file is released under GPL >= 2 +# +################################################# + +include_directories( + ${CMAKE_CURRENT_BINARY_DIR} + ${TDE_INCLUDE_DIR} + ${TQT_INCLUDE_DIRS} +) + +link_directories( + ${TQT_LIBRARY_DIRS} +) + + +##### kdialog (executable) ###################### + +tde_add_executable( kdialog AUTOMOC + SOURCES + kdialog.cpp widgets.cpp tdelistboxdialog.cpp + progressdialog.cpp progressdialogiface.skel + LINK tdeio-shared + DESTINATION ${BIN_INSTALL_DIR} +) diff --git a/kdialog/Makefile.am b/kdialog/Makefile.am new file mode 100644 index 000000000..05f22af35 --- /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 tdelistboxdialog.cpp progressdialog.cpp progressdialogiface.skel +kdialog_LDADD = $(LIB_TDEIO) +kdialog_LDFLAGS = $(all_libraries) $(KDE_RPATH) $(LIB_QT) -lDCOP $(LIB_TDECORE) $(LIB_TDEUI) -ltdefx $(LIB_TDEIO) -ltdetexteditor + +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..19dd197e6 --- /dev/null +++ b/kdialog/kdialog.cpp @@ -0,0 +1,701 @@ +// +// 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 <tqptrlist.h> +#include <tqfile.h> +#include <tqdatastream.h> +#include <tqregexp.h> +#include <tqtimer.h> +#include <tdemessagebox.h> +#include <tdeapplication.h> +#include <kdebug.h> +//#include <ktopwidget.h> +#include <tdemainwindow.h> +#include <kpassivepopup.h> +#include <tderecentdocument.h> +#include <tdeapplication.h> + +#include "widgets.h" + +#include <tdelocale.h> +#include <tqdialog.h> +#include <tdecmdlineargs.h> +#include <tdeaboutdata.h> +#include <tdefiledialog.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 TDECmdLineOptions 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 }, + TDECmdLineLastOption +}; + +// 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 TQObject +{ +public: + WinIdEmbedder(bool printID, WId winId): + TQObject(tqApp), print(printID), id(winId) + { + if (tqApp) + tqApp->installEventFilter(this); + } +protected: + bool eventFilter(TQObject *o, TQEvent *e); +private: + bool print; + WId id; +}; + +bool WinIdEmbedder::eventFilter(TQObject *o, TQEvent *e) +{ + if (e->type() == TQEvent::Show && o->isWidgetType() + && o->inherits("KDialog")) + { + TQWidget *w = TQT_TQWIDGET(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 TQObject::eventFilter(o, e); +} + +static void outputStringList(TQStringList list, bool separateOutput) +{ + if ( separateOutput) { + for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + cout << (*it).local8Bit().data() << endl; + } + } else { + for ( TQStringList::Iterator it = list.begin(); it != list.end(); ++it ) { + cout << (*it).local8Bit().data() << " "; + } + cout << endl; + } +} + +static int directCommand(TDECmdLineArgs *args) +{ + TQString title; + bool separateOutput = FALSE; + bool printWId = args->isSet("print-winid"); + bool embed = args->isSet("embed"); + TQString defaultEntry; + + // --title text + TDECmdLineArgs *qtargs = TDECmdLineArgs::parsedArgs("qt"); // --title is a qt option + if(qtargs->isSet("title")) { + title = TQFile::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; + TQCString 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() ) + { + TDEConfig* dontagaincfg = NULL; + // --dontagain + TQString dontagain; // TQString::null + if (args->isSet("dontagain")) + { + TQString value = args->getOption("dontagain"); + TQStringList values = TQStringList::split( ':', value ); + if( values.count() == 2 ) + { + dontagaincfg = new TDEConfig( values[ 0 ] ); + KMessageBox::setDontShowAskAgainConfig( dontagaincfg ); + dontagain = values[ 1 ]; + } + else + tqDebug( "Incorrect --dontagain!" ); + } + int ret; + + TQString text = TQString::fromLocal8Bit(args->getOption( option )); + int pos; + while ((pos = text.find( TQString::fromLatin1("\\n") )) >= 0) + { + text.replace(pos, 2, TQString::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")) + { + TQString result; + TQString init; + + if (args->count() > 0) + init = TQString::fromLocal8Bit(args->arg(0)); + + bool retcode = Widgets::inputBox(0, title, TQString::fromLocal8Bit(args->getOption("inputbox")), init, result); + cout << result.local8Bit().data() << endl; + return retcode ? 0 : 1; + } + + + // --password text + if (args->isSet("password")) + { + TQCString result; + bool retcode = Widgets::passwordBox(0, title, TQString::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 * TQString::fromLocal8Bit(args->arg(0)).toInt(); + if (duration == 0) + duration = 10000; + KPassivePopup *popup = KPassivePopup::message( KPassivePopup::Balloon, // style + title, + TQString::fromLocal8Bit( args->getOption("passivepopup") ), + 0, // icon + (TQWidget*)0UL, // parent + 0, // name + duration ); + TQTimer *timer = new TQTimer(); + TQObject::connect( timer, TQT_SIGNAL( timeout() ), kapp, TQT_SLOT( quit() ) ); + TQObject::connect( popup, TQT_SIGNAL( clicked() ), kapp, TQT_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 = TDEApplication::desktop()->width() + x - w; + if ( (m & YNegative) ) + y = TDEApplication::desktop()->height() + y - h; + popup->setAnchor( TQPoint(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 = TQString::fromLocal8Bit(args->arg(0)).toInt(); + h = TQString::fromLocal8Bit(args->arg(1)).toInt(); + } + + return Widgets::textBox(0, w, h, title, TQString::fromLocal8Bit(args->getOption("textbox"))); + } + + // --textinputbox file [width] [height] + if (args->isSet("textinputbox")) + { + int w = 400; + int h = 200; + + if (args->count() == 4) { + w = TQString::fromLocal8Bit(args->arg(2)).toInt(); + h = TQString::fromLocal8Bit(args->arg(3)).toInt(); + } + + TQStringList list; + list.append(TQString::fromLocal8Bit(args->getOption("textinputbox"))); + + if (args->count() >= 1) { + for (int i = 0; i < args->count(); i++) + list.append(TQString::fromLocal8Bit(args->arg(i))); + } + + TQCString 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")) { + TQStringList list; + if (args->count() >= 2) { + for (int i = 0; i < args->count(); i++) { + list.append(TQString::fromLocal8Bit(args->arg(i))); + } + TQString text = TQString::fromLocal8Bit(args->getOption("combobox")); + if (args->isSet("default")) { + defaultEntry = args->getOption("default"); + } + TQString 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")) { + TQStringList list; + if (args->count() >= 2) { + for (int i = 0; i < args->count(); i++) { + list.append(TQString::fromLocal8Bit(args->arg(i))); + } + TQString text = TQString::fromLocal8Bit(args->getOption("menu")); + if (args->isSet("default")) { + defaultEntry = args->getOption("default"); + } + TQString 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")) { + TQStringList list; + if (args->count() >= 3) { + for (int i = 0; i < args->count(); i++) { + list.append(TQString::fromLocal8Bit(args->arg(i))); + } + + TQString text = TQString::fromLocal8Bit(args->getOption("checklist")); + TQStringList 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")) { + TQStringList list; + if (args->count() >= 3) { + for (int i = 0; i < args->count(); i++) { + list.append(TQString::fromLocal8Bit(args->arg(i))); + } + + TQString text = TQString::fromLocal8Bit(args->getOption("radiolist")); + TQString 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")) { + TQString startDir; + TQString filter; + startDir = TQString::fromLocal8Bit(args->getOption("getopenfilename")); + if (args->count() >= 1) { + filter = TQString::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")) { + TQStringList result = dlg.selectedFiles(); + if ( !result.isEmpty() ) { + outputStringList( result, separateOutput ); + return 0; + } + } else { + TQString 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") ) ) { + TQString startDir; + TQString filter; + if ( args->isSet("getsavefilename") ) { + startDir = TQString::fromLocal8Bit(args->getOption("getsavefilename")); + } else { + startDir = TQString::fromLocal8Bit(args->getOption("getsaveurl")); + } + if (args->count() >= 1) { + filter = TQString::fromLocal8Bit(args->arg(0)); + } + // copied from KFileDialog::getSaveFileName(), so we can add geometry + bool specialDir = ( startDir.at(0) == ':' ); + KFileDialog dlg( specialDir ? startDir : TQString::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 + TQString result = dlg.selectedFile(); + if (!result.isEmpty()) { + TDERecentDocument::add(result); + cout << result.local8Bit().data() << endl; + return 0; + } + } + return 1; // cancelled + } + + // getexistingdirectory [startDir] + if (args->isSet("getexistingdirectory")) { + TQString startDir; + startDir = TQString::fromLocal8Bit(args->getOption("getexistingdirectory")); + TQString result; +#ifdef Q_WS_WIN + result = TQFileDialog::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() == TQDialog::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")) { + TQString startDir; + TQString filter; + startDir = TQString::fromLocal8Bit(args->getOption("getopenurl")); + if (args->count() >= 1) { + filter = TQString::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")) { + TQString groupStr, contextStr; + groupStr = TQString::fromLocal8Bit(args->getOption("geticon")); + if (args->count() >= 1) { + contextStr = TQString::fromLocal8Bit(args->arg(0)); + } + TDEIcon::Group group = TDEIcon::NoGroup; + if ( groupStr == TQString::fromLatin1( "Desktop" ) ) + group = TDEIcon::Desktop; + else if ( groupStr == TQString::fromLatin1( "Toolbar" ) ) + group = TDEIcon::Toolbar; + else if ( groupStr == TQString::fromLatin1( "MainToolbar" ) ) + group = TDEIcon::MainToolbar; + else if ( groupStr == TQString::fromLatin1( "Small" ) ) + group = TDEIcon::Small; + else if ( groupStr == TQString::fromLatin1( "Panel" ) ) + group = TDEIcon::Panel; + else if ( groupStr == TQString::fromLatin1( "User" ) ) + group = TDEIcon::User; + TDEIcon::Context context = TDEIcon::Any; + // From kicontheme.cpp + if ( contextStr == TQString::fromLatin1( "Devices" ) ) + context = TDEIcon::Device; + else if ( contextStr == TQString::fromLatin1( "MimeTypes" ) ) + context = TDEIcon::MimeType; + else if ( contextStr == TQString::fromLatin1( "FileSystems" ) ) + context = TDEIcon::FileSystem; + else if ( contextStr == TQString::fromLatin1( "Applications" ) ) + context = TDEIcon::Application; + else if ( contextStr == TQString::fromLatin1( "Actions" ) ) + context = TDEIcon::Action; + else if ( contextStr == TQString::fromLatin1( "Animations" ) ) + context = TDEIcon::Animation; + else if ( contextStr == TQString::fromLatin1( "Categories" ) ) + context = TDEIcon::Category; + else if ( contextStr == TQString::fromLatin1( "Emblems" ) ) + context = TDEIcon::Emblem; + else if ( contextStr == TQString::fromLatin1( "Emotes" ) ) + context = TDEIcon::Emote; + else if ( contextStr == TQString::fromLatin1( "International" ) ) + context = TDEIcon::International; + else if ( contextStr == TQString::fromLatin1( "Places" ) ) + context = TDEIcon::Place; + else if ( contextStr == TQString::fromLatin1( "Status" ) ) + context = TDEIcon::StatusIcon; + + TDEIconDialog dlg(0, "icon dialog"); + kapp->setTopWidget( &dlg ); + dlg.setup( group, context); + if (!title.isNull()) + dlg.setCaption(title); + Widgets::handleXGeometry(&dlg); + + TQString 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; + TQString text = TQString::fromLocal8Bit(args->getOption("progressbar")); + + if (args->count() == 1) + totalsteps = TQString::fromLocal8Bit(args->arg(0)).toInt(); + + return Widgets::progressBar(0, title, text, totalsteps) ? 1 : 0; + } + + TDECmdLineArgs::usage(); + return -2; // NOTREACHED +} + + +int main(int argc, char *argv[]) +{ + TDEAboutData aboutData( "kdialog", I18N_NOOP("KDialog"), + "1.0", I18N_NOOP( "KDialog can be used to show nice dialog boxes from shell scripts" ), + TDEAboutData::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"); + + TDECmdLineArgs::init(argc, argv, &aboutData); + TDECmdLineArgs::addCmdLineOptions( options ); // Add our own options. + + TDEApplication app; + + TDECmdLineArgs *args = TDECmdLineArgs::parsedArgs(); + + // execute direct kdialog command + return directCommand(args); +} + 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..498e333af --- /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(TQWidget* parent, const TQString& caption, const TQString& 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 TQString& 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..cdfca1ccb --- /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(TQWidget* parent = 0, const TQString& caption = TQString::null, const TQString& text = TQString::null, int totalSteps = 100); + + void setTotalSteps( int ); + int totalSteps() const; + + void setProgress( int ); + int progress() const; + + void setLabel(const TQString&); + + 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..068e5de38 --- /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 TQString& ) =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/tdelistboxdialog.cpp b/kdialog/tdelistboxdialog.cpp new file mode 100644 index 000000000..f961a7d45 --- /dev/null +++ b/kdialog/tdelistboxdialog.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 <tqlabel.h> +#include <tqlistbox.h> +#include <tqvbox.h> + +#include "tdelistboxdialog.h" +#include "tdelistboxdialog.moc" + +#include "tdelocale.h" + +TDEListBoxDialog::TDEListBoxDialog(TQString text, TQWidget *parent) + : KDialogBase( parent, 0, true, TQString::null, Ok|Cancel, Ok, true ) +{ + TQVBox *page = makeVBoxMainWidget(); + + label = new TQLabel(text, page); + label->setAlignment(AlignCenter); + + table = new TQListBox(page); + table->setFocus(); +} + +void TDEListBoxDialog::insertItem(const TQString& item) +{ + table->insertItem(item); + table->setCurrentItem(0); +} + +void TDEListBoxDialog::setCurrentItem(const TQString& item) +{ + for ( int i=0; i < (int) table->count(); i++ ) { + if ( table->text(i) == item ) { + table->setCurrentItem(i); + break; + } + } +} + +int TDEListBoxDialog::currentItem() +{ + return table->currentItem(); +} diff --git a/kdialog/tdelistboxdialog.h b/kdialog/tdelistboxdialog.h new file mode 100644 index 000000000..a93e7d002 --- /dev/null +++ b/kdialog/tdelistboxdialog.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 _TDELISTBOXDIALOG_H_ +#define _TDELISTBOXDIALOG_H_ + +#include <kdialogbase.h> + +class TDEListBoxDialog : public KDialogBase +{ + Q_OBJECT + +public: + + TDEListBoxDialog(TQString text, TQWidget *parent=0); + ~TDEListBoxDialog() {}; + + TQListBox &getTable() { return *table; }; + + void insertItem( const TQString& text ); + void setCurrentItem ( const TQString& text ); + int currentItem(); + +protected: + + TQListBox *table; + TQLabel *label; + +}; + + +#endif 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..fb90bbb25 --- /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 <tdelocale.h> +#include <tdemessagebox.h> + +#include "widgets.h" +#include "tdelistboxdialog.h" +#include "progressdialog.h" +#include <kinputdialog.h> +#include <kpassdlg.h> +#include <kcombobox.h> +#include <kdebug.h> +#include <tdeapplication.h> + +#include <tqlabel.h> +#include <ktextedit.h> +#include <tqvbox.h> +#include <tqfile.h> + +#if defined Q_WS_X11 && ! defined K_WS_QTONLY +#include <netwm.h> +#endif + +void Widgets::handleXGeometry(TQWidget * 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 = TDEApplication::desktop()->width() + x - w; + if ( (m & YNegative) ) + y = TDEApplication::desktop()->height() + y - h; + dlg->setGeometry(x, y, w, h); + // kdDebug() << "x: " << x << " y: " << y << " w: " << w << " h: " << h << endl; + } +#endif +} + +bool Widgets::inputBox(TQWidget *parent, const TQString& title, const TQString& text, const TQString& init, TQString &result) +{ + bool ok; + TQString str = KInputDialog::text( title, text, init, &ok, parent, 0, 0, TQString::null ); + if ( ok ) + result = str; + return ok; +} + +bool Widgets::passwordBox(TQWidget *parent, const TQString& title, const TQString& text, TQCString &result) +{ + KPasswordDialog dlg( KPasswordDialog::Password, false, 0, parent ); + + kapp->setTopWidget( &dlg ); + dlg.setCaption(title); + dlg.setPrompt(text); + + handleXGeometry(&dlg); + + bool retcode = (dlg.exec() == TQDialog::Accepted); + if ( retcode ) + result = dlg.password(); + return retcode; +} + +int Widgets::textBox(TQWidget *parent, int width, int height, const TQString& title, const TQString& 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); + + TQFile f(file); + if (!f.open(IO_ReadOnly)) + { + kdError() << i18n("kdialog: could not open file ") << file << endl; + return -1; + } + TQTextStream s(&f); + + while (!s.eof()) + edit->append(s.readLine()); + + edit->moveCursor(TQTextEdit::MoveHome, false); + + f.close(); + + if ( width > 0 && height > 0 ) + dlg.setInitialSize( TQSize( width, height ) ); + + handleXGeometry(&dlg); + dlg.setCaption(title); + dlg.exec(); + return 0; +} + +int Widgets::textInputBox(TQWidget *parent, int width, int height, const TQString& title, const TQStringList& args, TQCString &result) +{ +// KTextBox dlg(parent, 0, TRUE, width, height, file); + KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok, KDialogBase::Ok ); + + kapp->setTopWidget( &dlg ); + TQVBox* vbox = dlg.makeVBoxMainWidget(); + + if( args.count() > 0 ) + { + TQLabel *label = new TQLabel(vbox); + label->setText(args[0]); + } + + KTextEdit *edit = new KTextEdit( vbox ); + edit->setReadOnly(FALSE); + edit->setTextFormat( TQt::PlainText ); + edit->setFocus(); + + if( args.count() > 1 ) + edit->setText( args[1] ); + + if ( width > 0 && height > 0 ) + dlg.setInitialSize( TQSize( width, height ) ); + + handleXGeometry(&dlg); + dlg.setCaption(title); + dlg.exec(); + result = edit->text().local8Bit(); + return 0; +} + +bool Widgets::comboBox(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, + const TQString& defaultEntry, TQString &result) +{ + KDialogBase dlg( parent, 0, true, title, KDialogBase::Ok|KDialogBase::Cancel, + KDialogBase::Ok ); + + kapp->setTopWidget( &dlg ); + dlg.setCaption(title); + TQVBox* vbox = dlg.makeVBoxMainWidget(); + + TQLabel label (vbox); + label.setText (text); + KComboBox combo (vbox); + combo.insertStringList (args); + combo.setCurrentItem( defaultEntry, false ); + + handleXGeometry(&dlg); + + bool retcode = (dlg.exec() == TQDialog::Accepted); + + if (retcode) + result = combo.currentText(); + + return retcode; +} + +bool Widgets::listBox(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, + const TQString& defaultEntry, TQString &result) +{ + TDEListBoxDialog 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() == TQDialog::Accepted); + if ( retcode ) + result = args[ box.currentItem()*2 ]; + return retcode; +} + + +bool Widgets::checkList(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, bool separateOutput, TQStringList &result) +{ + TQStringList entries, tags; + TQString rs; + + result.clear(); + + TDEListBoxDialog box(text,parent); + + TQListBox &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] == TQString::fromLatin1("on") ); + } + + handleXGeometry(&box); + + bool retcode = (box.exec() == TQDialog::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 += TQString::fromLatin1("\"") + tags[i] + TQString::fromLatin1("\" "); + result.append(rs); + } + } + return retcode; +} + + +bool Widgets::radioBox(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, TQString &result) +{ + TQStringList entries, tags; + + TDEListBoxDialog box(text,parent); + + TQListBox &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] == TQString::fromLatin1("on") ); + } + + handleXGeometry(&box); + + bool retcode = (box.exec() == TQDialog::Accepted); + if ( retcode ) + result = tags[ table.currentItem() ]; + return retcode; +} + +bool Widgets::progressBar(TQWidget *parent, const TQString& title, const TQString& 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..e6576d36e --- /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 <tqwidget.h> +#include <tqstring.h> + +namespace Widgets +{ + bool inputBox(TQWidget *parent, const TQString& title, const TQString& text, const TQString& init, TQString &result); + bool passwordBox(TQWidget *parent, const TQString& title, const TQString& text, TQCString &result); + int textBox(TQWidget *parent, int width, int height, const TQString& title, const TQString& file); + int textInputBox(TQWidget *parent, int width, int height, const TQString& title, const TQStringList& args, TQCString &result); + bool listBox(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, const TQString &defaultEntry, TQString &result); + bool checkList(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, bool separateOutput, TQStringList &result); + bool radioBox(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, TQString &result); + bool comboBox(TQWidget *parent, const TQString& title, const TQString& text, const TQStringList& args, const TQString& defaultEntry, TQString &result); + bool progressBar(TQWidget *parent, const TQString& title, const TQString& text, int totalSteps); + + void handleXGeometry(TQWidget * dlg); + +} + +#endif |