Make kdialog use Plasma's notification bling (via D-Bus) if possible,
[personal-kdebase.git] / apps / kdialog / kdialog.cpp
blob977aaaa2820a37928b9f7116c400978bb2e0572e
1 //
2 // Copyright (C) 1998 Matthias Hoelzer <hoelzer@kde.org>
3 // Copyright (C) 2002 David Faure <faure@kde.org>
4 // Copyright (C) 2005 Brad Hards <bradh@frogmouth.net>
5 // Copyright (C) 2008 by Dmitry Suzdalev <dimsuz@gmail.com>
6 //
7 // This program is free software; you can redistribute it and/or modify
8 // it under the terms of the GNU General Public License as published by
9 // the Free Software Foundation; either version 2 of the License, or
10 // (at your option) any later version.
12 // This program is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the7 implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
17 // You should have received a copy of the GNU General Public License
18 // along with this program; if not, write to the Free Software
19 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 #include <QDate>
23 #include <kdebug.h>
24 #include "widgets.h"
26 #include <kmessagebox.h>
27 #include <kapplication.h>
28 #include <kpassivepopup.h>
29 #include <krecentdocument.h>
30 #include <kcmdlineargs.h>
31 #include <kaboutdata.h>
32 #include <kfiledialog.h>
33 #include <kicondialog.h>
34 #include <kdirselectdialog.h>
35 #include <kcolordialog.h>
36 #include <kwindowsystem.h>
38 #include <QtCore/QTimer>
39 #include <QtGui/QDesktopWidget>
41 #include <iostream>
43 #if defined Q_WS_X11 && ! defined K_WS_QTONLY
44 #include <netwm.h>
45 #endif
47 #include "../config-apps.h"
48 #ifdef QT_QTDBUS_FOUND
49 #include <QtDBus/QDBusConnection>
50 #include <QtDBus/QDBusConnectionInterface>
51 #endif
53 #ifdef Q_WS_WIN
54 #include <QtGui/QFileDialog>
55 #endif
56 #include <unistd.h>
58 using namespace std;
60 // this class hooks into the eventloop and outputs the id
61 // of shown dialogs or makes the dialog transient for other winids.
62 // Will destroy itself on app exit.
63 class WinIdEmbedder: public QObject
65 public:
66 WinIdEmbedder(bool printID, WId winId):
67 QObject(kapp), print(printID), id(winId)
69 if (kapp)
70 kapp->installEventFilter(this);
72 protected:
73 bool eventFilter(QObject *o, QEvent *e);
74 private:
75 bool print;
76 WId id;
79 bool WinIdEmbedder::eventFilter(QObject *o, QEvent *e)
81 if (e->type() == QEvent::Show && o->isWidgetType()
82 && o->inherits("KDialog"))
84 QWidget *w = static_cast<QWidget*>(o);
85 if (print)
86 cout << "winId: " << w->winId() << endl;
87 if (id)
88 KWindowSystem::setMainWindow(w, id);
89 deleteLater(); // WinIdEmbedder is not needed anymore after the first dialog was shown
90 return false;
92 return QObject::eventFilter(o, e);
95 /**
96 * Display a passive notification popup using the D-Bus interface, if possible.
97 * @return true if the notification was successfully sent, false otherwise.
99 bool sendVisualNotification(QString text, QString title, int timeout)
101 #ifdef QT_QTDBUS_FOUND
102 const QString dbusServiceName = "org.kde.VisualNotifications";
103 const QString dbusInterfaceName = "org.kde.VisualNotifications";
104 const QString dbusPath = "/VisualNotifications";
106 // check if service already exists on plugin instantiation
107 QDBusConnectionInterface* interface = QDBusConnection::sessionBus().interface();
109 if (!interface || !interface->isServiceRegistered(dbusServiceName)) {
110 //kDebug() << dbusServiceName << "D-Bus service not registered";
111 return false;
114 if (timeout == 0)
115 timeout = 10 * 1000;
117 QDBusMessage m = QDBusMessage::createMethodCall(dbusServiceName, dbusPath, dbusInterfaceName, "Notify");
118 QList<QVariant> args;
120 args.append("kdialog"); // app_name
121 args.append(0U); // replaces_id
122 args.append("kdialogPassivePopup"); // event_id
123 args.append("dialog-information"); // app_icon
124 args.append(title); // summary
125 args.append(text); // body
126 args.append(QStringList()); // actions - unused for plain passive popups
127 args.append(QVariantMap()); // hints - unused atm
128 args.append(timeout); // expire timout
130 m.setArguments(args);
132 QDBusMessage replyMsg = QDBusConnection::sessionBus().call(m);
133 if(replyMsg.type() == QDBusMessage::ReplyMessage) {
134 if (!replyMsg.arguments().isEmpty()) {
135 return true;
137 // Not displaying any error messages as this is optional for kdialog
138 // and KPassivePopup is a perfectly valid fallback.
139 //else {
140 // kDebug() << "Error: received reply with no arguments.";
142 } else if (replyMsg.type() == QDBusMessage::ErrorMessage) {
143 //kDebug() << "Error: failed to send D-Bus message";
144 //kDebug() << replyMsg;
145 } else {
146 //kDebug() << "Unexpected reply type";
148 #endif
149 return false;
152 static void outputStringList(const QStringList &list, bool separateOutput)
154 if ( separateOutput) {
155 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
156 cout << (*it).toLocal8Bit().data() << endl;
158 } else {
159 for ( QStringList::ConstIterator it = list.begin(); it != list.end(); ++it ) {
160 cout << (*it).toLocal8Bit().data() << " ";
162 cout << endl;
166 static int directCommand(KCmdLineArgs *args)
168 QString title;
169 bool separateOutput = false;
170 bool printWId = args->isSet("print-winid");
171 QString defaultEntry;
173 // --title text
174 KCmdLineArgs *qtargs = KCmdLineArgs::parsedArgs("qt"); // --title is a qt option
175 if(qtargs->isSet("title")) {
176 title = qtargs->getOption("title");
179 // --separate-output
180 if (args->isSet("separate-output"))
182 separateOutput = true;
185 WId winid = 0;
186 bool attach = args->isSet("attach");
187 if(attach) {
188 #ifdef Q_WS_WIN
189 winid = reinterpret_cast<WId>(args->getOption("attach").toLong(&attach, 0)); //C style parsing. If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
190 #else
191 winid = args->getOption("attach").toLong(&attach, 0); //C style parsing. If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
192 #endif
193 } else if(args->isSet("embed")) {
194 /* KDialog originally used --embed for attaching the dialog box. However this is misleading and so we changed to --attach.
195 * For consistancy, we silently map --embed to --attach */
196 attach = true;
197 #ifdef Q_WS_WIN
198 winid = reinterpret_cast<WId>(args->getOption("embed").toLong(&attach, 0)); //C style parsing. If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
199 #else
200 winid = args->getOption("embed").toLong(&attach, 0); //C style parsing. If the string begins with "0x", base 16 is used; if the string begins with "0", base 8 is used; otherwise, base 10 is used.
201 #endif
204 if (printWId || attach)
206 (void)new WinIdEmbedder(printWId, winid);
209 // --yesno and other message boxes
210 KMessageBox::DialogType type = (KMessageBox::DialogType) 0;
211 QByteArray option;
212 if (args->isSet("yesno")) {
213 option = "yesno";
214 type = KMessageBox::QuestionYesNo;
216 else if (args->isSet("yesnocancel")) {
217 option = "yesnocancel";
218 type = KMessageBox::QuestionYesNoCancel;
220 else if (args->isSet("warningyesno")) {
221 option = "warningyesno";
222 type = KMessageBox::WarningYesNo;
224 else if (args->isSet("warningcontinuecancel")) {
225 option = "warningcontinuecancel";
226 type = KMessageBox::WarningContinueCancel;
228 else if (args->isSet("warningyesnocancel")) {
229 option = "warningyesnocancel";
230 type = KMessageBox::WarningYesNoCancel;
232 else if (args->isSet("sorry")) {
233 option = "sorry";
234 type = KMessageBox::Sorry;
236 else if (args->isSet("error")) {
237 option = "error";
238 type = KMessageBox::Error;
240 else if (args->isSet("msgbox")) {
241 option = "msgbox";
242 type = KMessageBox::Information;
245 if ( !option.isEmpty() )
247 KConfig* dontagaincfg = NULL;
248 // --dontagain
249 QString dontagain; // QString()
250 if (args->isSet("dontagain"))
252 QString value = args->getOption("dontagain");
253 QStringList values = value.split( ':', QString::SkipEmptyParts );
254 if( values.count() == 2 )
256 dontagaincfg = new KConfig( values[ 0 ] );
257 KMessageBox::setDontShowAskAgainConfig( dontagaincfg );
258 dontagain = values[ 1 ];
260 else
261 qDebug( "Incorrect --dontagain!" );
263 int ret;
265 QString text = args->getOption( option );
266 int pos;
267 while ((pos = text.indexOf( QLatin1String("\\n") )) >= 0)
269 text.replace(pos, 2, QLatin1String("\n"));
272 if ( type == KMessageBox::WarningContinueCancel ) {
273 /* TODO configurable button texts*/
274 ret = KMessageBox::messageBox( 0, type, text, title, KStandardGuiItem::cont(),
275 KStandardGuiItem::no(), KStandardGuiItem::cancel(), dontagain );
276 } else {
277 ret = KMessageBox::messageBox( 0, type, text, title /*, TODO configurable button texts*/,
278 KStandardGuiItem::yes(), KStandardGuiItem::no(), KStandardGuiItem::cancel(), dontagain );
280 delete dontagaincfg;
281 // ret is 1 for Ok, 2 for Cancel, 3 for Yes, 4 for No and 5 for Continue.
282 // We want to return 0 for ok, yes and continue, 1 for no and 2 for cancel
283 return (ret == KMessageBox::Ok || ret == KMessageBox::Yes || ret == KMessageBox::Continue) ? 0
284 : ( ret == KMessageBox::No ? 1 : 2 );
287 // --inputbox text [init]
288 if (args->isSet("inputbox"))
290 QString result;
291 QString init;
293 if (args->count() > 0)
294 init = args->arg(0);
296 bool retcode = Widgets::inputBox(0, title, args->getOption("inputbox"), init, result);
297 cout << result.toLocal8Bit().data() << endl;
298 return retcode ? 0 : 1;
302 // --password text
303 if (args->isSet("password"))
305 QString result;
306 bool retcode = Widgets::passwordBox(0, title, args->getOption("password"), result);
307 cout << qPrintable(result) << endl;
308 return retcode ? 0 : 1;
311 // --passivepopup
312 if (args->isSet("passivepopup"))
314 int duration = 0;
315 if (args->count() > 0)
316 duration = 1000 * args->arg(0).toInt();
317 if (duration == 0)
318 duration = 10000;
320 // try to use more stylish notifications
321 if (sendVisualNotification(args->getOption("passivepopup"), title, duration))
322 return 0;
324 // ...did not work, use KPassivePopup as fallback
325 KPassivePopup *popup = KPassivePopup::message( KPassivePopup::Boxed, // style
326 title,
327 args->getOption("passivepopup"),
328 QPixmap() /* do not crash 0*/, // icon
329 (QWidget*)0UL, // parent
330 duration );
331 KDialog::centerOnScreen( popup );
332 QTimer *timer = new QTimer();
333 QObject::connect( timer, SIGNAL( timeout() ), kapp, SLOT( quit() ) );
334 QObject::connect( popup, SIGNAL( clicked() ), kapp, SLOT( quit() ) );
335 timer->setSingleShot( true );
336 timer->start( duration );
338 #ifdef Q_WS_X11
339 QString geometry;
340 KCmdLineArgs *args = KCmdLineArgs::parsedArgs("kde");
341 if (args && args->isSet("geometry"))
342 geometry = args->getOption("geometry");
343 if ( !geometry.isEmpty()) {
344 int x, y;
345 int w, h;
346 int m = XParseGeometry( geometry.toLatin1(), &x, &y, (unsigned int*)&w, (unsigned int*)&h);
347 if ( (m & XNegative) )
348 x = KApplication::desktop()->width() + x - w;
349 if ( (m & YNegative) )
350 y = KApplication::desktop()->height() + y - h;
351 popup->setAnchor( QPoint(x, y) );
353 #endif
354 kapp->exec();
355 return 0;
358 // --textbox file [width] [height]
359 if (args->isSet("textbox"))
361 int w = 0;
362 int h = 0;
364 if (args->count() == 2) {
365 w = args->arg(0).toInt();
366 h = args->arg(1).toInt();
369 return Widgets::textBox(0, w, h, title, args->getOption("textbox"));
372 // --textinputbox file [width] [height]
373 if (args->isSet("textinputbox"))
375 int w = 400;
376 int h = 200;
378 if (args->count() == 4) {
379 w = args->arg(2).toInt();
380 h = args->arg(3).toInt();
383 QStringList list;
384 list.append(args->getOption("textinputbox"));
386 if (args->count() >= 1) {
387 for (int i = 0; i < args->count(); i++)
388 list.append(args->arg(i));
391 QString result;
392 int ret = Widgets::textInputBox(0, w, h, title, list, result);
393 cout << qPrintable(result) << endl;
394 return ret;
397 // --combobox <text> [tag item] [tag item] ..."
398 if (args->isSet("combobox")) {
399 QStringList list;
400 if (args->count() >= 2) {
401 for (int i = 0; i < args->count(); i++) {
402 list.append(args->arg(i));
404 QString text = args->getOption("combobox");
405 if (args->isSet("default")) {
406 defaultEntry = args->getOption("default");
408 QString result;
409 bool retcode = Widgets::comboBox(0, title, text, list, defaultEntry, result);
410 cout << result.toLocal8Bit().data() << endl;
411 return retcode ? 0 : 1;
413 return -1;
416 // --menu text [tag item] [tag item] ...
417 if (args->isSet("menu")) {
418 QStringList list;
419 if (args->count() >= 2) {
420 for (int i = 0; i < args->count(); i++) {
421 list.append(args->arg(i));
423 QString text = args->getOption("menu");
424 if (args->isSet("default")) {
425 defaultEntry = args->getOption("default");
427 QString result;
428 bool retcode = Widgets::listBox(0, title, text, list, defaultEntry, result);
429 if (1 == retcode) { // OK was selected
430 cout << result.toLocal8Bit().data() << endl;
432 return retcode ? 0 : 1;
434 return -1;
437 // --checklist text [tag item status] [tag item status] ...
438 if (args->isSet("checklist")) {
439 QStringList list;
440 if (args->count() >= 3) {
441 for (int i = 0; i < args->count(); i++) {
442 list.append(args->arg(i));
445 QString text = args->getOption("checklist");
446 QStringList result;
448 bool retcode = Widgets::checkList(0, title, text, list, separateOutput, result);
450 for (int i=0; i<result.count(); i++)
451 if (!result.at(i).toLocal8Bit().isEmpty()) {
452 cout << result.at(i).toLocal8Bit().data() << endl;
454 exit( retcode ? 0 : 1 );
456 return -1;
459 // --radiolist text width height menuheight [tag item status]
460 if (args->isSet("radiolist")) {
461 QStringList list;
462 if (args->count() >= 3) {
463 for (int i = 0; i < args->count(); i++) {
464 list.append(args->arg(i));
467 QString text = args->getOption("radiolist");
468 QString result;
469 bool retcode = Widgets::radioBox(0, title, text, list, result);
470 cout << result.toLocal8Bit().data() << endl;
471 exit( retcode ? 0 : 1 );
473 return -1;
476 // getopenfilename [startDir] [filter]
477 if (args->isSet("getopenfilename")) {
478 QString startDir;
479 QString filter;
480 startDir = args->getOption("getopenfilename");
481 if (args->count() >= 1) {
482 filter = args->arg(0);
484 KFileDialog dlg( startDir, filter, 0 );
485 dlg.setOperationMode( KFileDialog::Opening );
487 if (args->isSet("multiple")) {
488 dlg.setMode(KFile::Files | KFile::LocalOnly);
489 } else {
490 dlg.setMode(KFile::File | KFile::LocalOnly);
492 Widgets::handleXGeometry(&dlg);
493 kapp->setTopWidget( &dlg );
494 dlg.setCaption(title.isNull() ? i18n("Open") : title);
495 dlg.exec();
497 if (args->isSet("multiple")) {
498 QStringList result = dlg.selectedFiles();
499 if ( !result.isEmpty() ) {
500 outputStringList( result, separateOutput );
501 return 0;
503 } else {
504 QString result = dlg.selectedFile();
505 if (!result.isEmpty()) {
506 cout << result.toLocal8Bit().data() << endl;
507 return 0;
510 return 1; // canceled
514 // getsaveurl [startDir] [filter]
515 // getsavefilename [startDir] [filter]
516 if ( (args->isSet("getsavefilename") ) || (args->isSet("getsaveurl") ) ) {
517 QString startDir;
518 QString filter;
519 if ( args->isSet("getsavefilename") ) {
520 startDir = args->getOption("getsavefilename");
521 } else {
522 startDir = args->getOption("getsaveurl");
524 if (args->count() >= 1) {
525 filter = args->arg(0);
527 // copied from KFileDialog::getSaveFileName(), so we can add geometry
528 bool specialDir = ( startDir.at(0) == ':' );
529 KFileDialog dlg( specialDir ? startDir : QString(), filter, 0 );
530 if ( !specialDir )
531 dlg.setSelection( startDir );
532 dlg.setOperationMode( KFileDialog::Saving );
533 Widgets::handleXGeometry(&dlg);
534 kapp->setTopWidget( &dlg );
535 dlg.setCaption(title.isNull() ? i18n("Save As") : title);
536 dlg.exec();
538 if ( args->isSet("getsaveurl") ) {
539 KUrl result = dlg.selectedUrl();
540 if ( result.isValid()) {
542 cout << result.url().toLocal8Bit().data() << endl;
543 return 0;
545 } else { // getsavefilename
546 QString result = dlg.selectedFile();
547 if (!result.isEmpty()) {
548 KRecentDocument::add(result);
549 cout << result.toLocal8Bit().data() << endl;
550 return 0;
553 return 1; // canceled
556 // getexistingdirectory [startDir]
557 if (args->isSet("getexistingdirectory")) {
558 QString startDir;
559 startDir = args->getOption("getexistingdirectory");
560 QString result;
561 #ifdef Q_WS_WIN
562 result = QFileDialog::getExistingDirectory( 0, title, startDir,
563 QFileDialog::DontResolveSymlinks |
564 QFileDialog::ShowDirsOnly);
565 #else
566 KUrl url;
567 KDirSelectDialog myDialog( startDir, true, 0 );
569 kapp->setTopWidget( &myDialog );
571 Widgets::handleXGeometry(&myDialog);
572 if ( !title.isNull() )
573 myDialog.setCaption( title );
575 if ( myDialog.exec() == QDialog::Accepted )
576 url = myDialog.url();
578 if ( url.isValid() )
579 result = url.path();
580 #endif
581 if (!result.isEmpty()) {
582 cout << result.toLocal8Bit().data() << endl;
583 return 0;
585 return 1; // canceled
588 // getopenurl [startDir] [filter]
589 if (args->isSet("getopenurl")) {
590 QString startDir;
591 QString filter;
592 startDir = args->getOption("getopenurl");
593 if (args->count() >= 1) {
594 filter = args->arg(0);
596 KFileDialog dlg( startDir, filter, 0 );
597 dlg.setOperationMode( KFileDialog::Opening );
599 if (args->isSet("multiple")) {
600 dlg.setMode(KFile::Files);
601 } else {
602 dlg.setMode(KFile::File);
604 Widgets::handleXGeometry(&dlg);
605 kapp->setTopWidget( &dlg );
606 dlg.setCaption(title.isNull() ? i18n("Open") : title);
607 dlg.exec();
609 if (args->isSet("multiple")) {
610 KUrl::List result = dlg.selectedUrls();
611 if ( !result.isEmpty() ) {
612 outputStringList( result.toStringList(), separateOutput );
613 return 0;
615 } else {
616 KUrl result = dlg.selectedUrl();
617 if (!result.isEmpty()) {
618 cout << result.url().toLocal8Bit().data() << endl;
619 return 0;
622 return 1; // canceled
625 // geticon [group] [context]
626 if (args->isSet("geticon")) {
627 QString groupStr, contextStr;
628 groupStr = args->getOption("geticon");
629 if (args->count() >= 1) {
630 contextStr = args->arg(0);
632 KIconLoader::Group group = KIconLoader::NoGroup;
633 if ( groupStr == QLatin1String( "Desktop" ) )
634 group = KIconLoader::Desktop;
635 else if ( groupStr == QLatin1String( "Toolbar" ) )
636 group = KIconLoader::Toolbar;
637 else if ( groupStr == QLatin1String( "MainToolbar" ) )
638 group = KIconLoader::MainToolbar;
639 else if ( groupStr == QLatin1String( "Small" ) )
640 group = KIconLoader::Small;
641 else if ( groupStr == QLatin1String( "Panel" ) )
642 group = KIconLoader::Panel;
643 else if ( groupStr == QLatin1String( "User" ) )
644 group = KIconLoader::User;
645 KIconLoader::Context context = KIconLoader::Any;
646 // From kicontheme.cpp
647 if ( contextStr == QLatin1String( "Devices" ) )
648 context = KIconLoader::Device;
649 else if ( contextStr == QLatin1String( "MimeTypes" ) )
650 context = KIconLoader::MimeType;
651 else if ( contextStr == QLatin1String( "FileSystems" ) )
652 context = KIconLoader::FileSystem;
653 else if ( contextStr == QLatin1String( "Applications" ) )
654 context = KIconLoader::Application;
655 else if ( contextStr == QLatin1String( "Actions" ) )
656 context = KIconLoader::Action;
658 KIconDialog dlg((QWidget*)0L);
659 kapp->setTopWidget( &dlg );
660 dlg.setup( group, context);
661 if (!title.isNull())
662 dlg.setCaption(title);
663 Widgets::handleXGeometry(&dlg);
665 QString result = dlg.openDialog();
667 if (!result.isEmpty()) {
668 cout << result.toLocal8Bit().data() << endl;
669 return 0;
671 return 1; // canceled
674 // --progressbar text totalsteps
675 if (args->isSet("progressbar"))
677 cout << "org.kde.kdialog-" << getpid() << " /ProgressDialog" << endl;
678 if (fork())
679 _exit(0);
680 close(1);
682 int totalsteps = 100;
683 QString text = args->getOption("progressbar");
685 if (args->count() == 1)
686 totalsteps = args->arg(0).toInt();
688 return Widgets::progressBar(0, title, text, totalsteps) ? 1 : 0;
691 // --getcolor
692 if (args->isSet("getcolor")) {
693 KColorDialog dlg((QWidget*)0L, true);
695 if (args->isSet("default")) {
696 defaultEntry = args->getOption("default");
697 dlg.setColor(defaultEntry);
699 Widgets::handleXGeometry(&dlg);
700 kapp->setTopWidget(&dlg);
701 dlg.setCaption(title.isNull() ? i18n("Choose Color") : title);
703 if (dlg.exec() == KColorDialog::Accepted) {
704 QString result;
705 if (dlg.color().isValid()) {
706 result = dlg.color().name();
707 } else {
708 result = dlg.defaultColor().name();
710 cout << result.toLocal8Bit().data() << endl;
711 return 0;
713 return 1; // cancelled
715 if (args->isSet("slider"))
717 int miniValue = 0;
718 int maxValue = 0;
719 int step = 0;
720 QString text = args->getOption( "slider" );
721 if ( args->count() == 3 )
723 miniValue = args->arg(0).toInt();
724 maxValue = args->arg( 1 ).toInt();
725 step = args->arg( 2 ).toInt();
727 int result = 0;
729 bool returnCode = Widgets::slider(0, title, text, miniValue, maxValue, step, result);
730 if ( returnCode )
731 cout << result << endl;
732 return returnCode;
734 if (args->isSet("calendar"))
736 QString text = args->getOption( "calendar" );
737 QDate result;
739 bool returnCode = Widgets::calendar(0, title, text, result);
740 if ( returnCode )
741 cout << result.toString().toLocal8Bit().data() << endl;
742 return returnCode;
745 KCmdLineArgs::usage();
746 return -2; // NOTREACHED
750 int main(int argc, char *argv[])
752 KAboutData aboutData( "kdialog", 0, ki18n("KDialog"),
753 "1.0", ki18n( "KDialog can be used to show nice dialog boxes from shell scripts" ),
754 KAboutData::License_GPL,
755 ki18n("(C) 2000, Nick Thompson"));
756 aboutData.addAuthor(ki18n("David Faure"), ki18n("Current maintainer"),"faure@kde.org");
757 aboutData.addAuthor(ki18n("Brad Hards"), KLocalizedString(), "bradh@frogmouth.net");
758 aboutData.addAuthor(ki18n("Nick Thompson"),KLocalizedString(), 0/*"nickthompson@lucent.com" bounces*/);
759 aboutData.addAuthor(ki18n("Matthias Hölzer"),KLocalizedString(),"hoelzer@kde.org");
760 aboutData.addAuthor(ki18n("David Gümbel"),KLocalizedString(),"david.guembel@gmx.net");
761 aboutData.addAuthor(ki18n("Richard Moore"),KLocalizedString(),"rich@kde.org");
762 aboutData.addAuthor(ki18n("Dawit Alemayehu"),KLocalizedString(),"adawit@kde.org");
763 aboutData.setProgramIconName("system-run");
766 KCmdLineArgs::init(argc, argv, &aboutData);
768 KCmdLineOptions options;
769 options.add("yesno <text>", ki18n("Question message box with yes/no buttons"));
770 options.add("yesnocancel <text>", ki18n("Question message box with yes/no/cancel buttons"));
771 options.add("warningyesno <text>", ki18n("Warning message box with yes/no buttons"));
772 options.add("warningcontinuecancel <text>", ki18n("Warning message box with continue/cancel buttons"));
773 options.add("warningyesnocancel <text>", ki18n("Warning message box with yes/no/cancel buttons"));
774 options.add("sorry <text>", ki18n("'Sorry' message box"));
775 options.add("error <text>", ki18n("'Error' message box"));
776 options.add("msgbox <text>", ki18n("Message Box dialog"));
777 options.add("inputbox <text> <init>", ki18n("Input Box dialog"));
778 options.add("password <text>", ki18n("Password dialog"));
779 options.add("textbox <file> [width] [height]", ki18n("Text Box dialog"));
780 options.add("textinputbox <text> <init> [width] [height]", ki18n("Text Input Box dialog"));
781 options.add("combobox <text> [tag item] [tag item] ...", ki18n("ComboBox dialog"));
782 options.add("menu <text> [tag item] [tag item] ...", ki18n("Menu dialog"));
783 options.add("checklist <text> [tag item status] ...", ki18n("Check List dialog"));
784 options.add("radiolist <text> [tag item status] ...", ki18n("Radio List dialog"));
785 options.add("passivepopup <text> <timeout>", ki18n("Passive Popup"));
786 options.add("getopenfilename [startDir] [filter]", ki18n("File dialog to open an existing file"));
787 options.add("getsavefilename [startDir] [filter]", ki18n("File dialog to save a file"));
788 options.add("getexistingdirectory [startDir]", ki18n("File dialog to select an existing directory"));
789 options.add("getopenurl [startDir] [filter]", ki18n("File dialog to open an existing URL"));
790 options.add("getsaveurl [startDir] [filter]", ki18n("File dialog to save a URL"));
791 options.add("geticon [group] [context]", ki18n("Icon chooser dialog"));
792 options.add("progressbar <text> [totalsteps]", ki18n("Progress bar dialog, returns a D-Bus reference for communication"));
793 options.add("getcolor", ki18n("Color dialog to select a color"));
794 // TODO gauge stuff, reading values from stdin
795 options.add("title <text>", ki18n("Dialog title"));
796 options.add("default <text>", ki18n("Default entry to use for combobox, menu and color"));
797 options.add("multiple", ki18n("Allows the --getopenurl and --getopenfilename options to return multiple files"));
798 options.add("separate-output", ki18n("Return list items on separate lines (for checklist option and file open with --multiple)"));
799 options.add("print-winid", ki18n("Outputs the winId of each dialog"));
800 options.add("dontagain <file:entry>", ki18n("Config file and option name for saving the \"do-not-show/ask-again\" state"));
801 options.add( "slider <text> [minvalue] [maxvalue] [step]", ki18n( "Slider dialogbox, returns value selected" ) );
802 options.add( "calendar <text>", ki18n( "Calendar dialogbox, return selected date" ) );
803 /* kdialog originally used --embed for attaching the dialog box. However this is misleading and so we changed to --attach.
804 * For backwards compatibility, we silently map --embed to --attach */
805 options.add("attach <winid>", ki18n("Makes the dialog transient for an X app specified by winid"));
806 options.add("embed <winid>");
808 options.add("+[arg]", ki18n("Arguments - depending on main option"));
810 KCmdLineArgs::addCmdLineOptions( options ); // Add our own options.
812 KApplication app;
814 KCmdLineArgs *args = KCmdLineArgs::parsedArgs();
816 // execute direct kdialog command
817 return directCommand(args);