Bug 66342 - a dialog for showing progress bars would be useful
Summary: a dialog for showing progress bars would be useful
Status: RESOLVED FIXED
Alias: None
Product: kdialog
Classification: Applications
Component: general (show other bugs)
Version: unspecified
Platform: Compiled Sources Linux
: NOR wishlist
Target Milestone: ---
Assignee: David Faure
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2003-10-21 14:49 UTC by Magnus Johansson
Modified: 2004-06-14 17:41 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Magnus Johansson 2003-10-21 14:49:12 UTC
Version:            (using KDE Devel)
Installed from:    Compiled sources
OS:          Linux

I would like to be able to display a progress dialog using kdialog. It would work something like this:

1. The shell script calls kdialog with the text to be displayed and the total number of steps required. Perhaps also whether to display a "done" button when finished. Since a progressbar needs to be run in the background, kdialog could e.g. fork a child to display the dialog, and then return immediatly, returning the process id of the child. It might also be possible to solve this in another way.
2. The script could then use the pid to do DCOP calls to the progress bar in order to update it, or change the text displayed.
3. The progressbar shouldn't quit (or display an active "done" button) until told so by the script.

A "cancel"-button would also be nice to be able to have, but I suppose the script would have to poll the progressbar, using DCOP, to find out if the button has been pressed.
Comment 1 Stephan Binner 2004-06-12 21:52:43 UTC
CVS commit by binner: 

Presenting a simple non-cancelable progress bar dialog for kdialog

> dialog=`kdialog --title Example --progressbar "Working..."`
> dcop $dialog setValue 50
> dcop $dialog
QCStringList interfaces()
QCStringList functions()
void setTotalSteps(int)
int totalSteps()
void setValue(int)
int value()
void setLabel(QString)
void close()

CCMAIL: 66342@bugs.kde.org


  A            progressdialog.cpp   1.1 [GPL (v2+)]
  A            progressdialog.h   1.1 [GPL (v2+)]
  A            progressdialogiface.h   1.1 [no copyright]
  M +1 -1      Makefile.am   1.3
  M +19 -1     kdialog.cpp   1.23
  M +10 -0     widgets.cpp   1.8
  M +1 -0      widgets.h   1.6


--- kdebase/kdialog/Makefile.am  #1.2:1.3
@@ -4,5 +4,5 @@
 bin_PROGRAMS = kdialog
 
-kdialog_SOURCES = kdialog.cpp widgets.cpp klistboxdialog.cpp
+kdialog_SOURCES = kdialog.cpp widgets.cpp klistboxdialog.cpp progressdialog.cpp progressdialogiface.skel
 kdialog_LDADD = $(LIB_KIO)
 kdialog_LDFLAGS = $(all_libraries) $(KDE_RPATH)

--- kdebase/kdialog/kdialog.cpp  #1.22:1.23
@@ -75,4 +75,5 @@ static KCmdLineOptions options[] =
     { "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"), 0},
 
     // TODO gauge stuff, reading values from stdin
@@ -478,4 +479,21 @@ static int directCommand(KCmdLineArgs *a
     }
 
+    // --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

--- kdebase/kdialog/widgets.cpp  #1.7:1.8
@@ -24,4 +24,5 @@
 #include "widgets.h"
 #include "klistboxdialog.h"
+#include "progressdialog.h"
 #include <kinputdialog.h>
 #include <kpassdlg.h>
@@ -201,2 +202,11 @@ bool Widgets::radioBox(QWidget *parent, 
   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 );
+  dlg.exec();
+  return dlg.wasCancelled();
+}

--- kdebase/kdialog/widgets.h  #1.5:1.6
@@ -34,4 +34,5 @@ namespace Widgets
     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, QString &result);
+    bool progressBar(QWidget *parent, const QString& title, const QString& text, int totalSteps);
 }
 


Comment 2 Stephan Binner 2004-06-14 17:41:41 UTC
CVS commit by binner: 

Added setAutoClose(bool), showCancelButton(bool) and wasCancelled()
CCMAIL: 66342-done@bugs.kde.org


  M +29 -6     progressdialog.cpp   1.3
  M +9 -3      progressdialog.h   1.3
  M +7 -2      progressdialogiface.h   1.3


--- kdebase/kdialog/progressdialog.cpp  #1.2:1.3
@@ -32,19 +32,21 @@ void ProgressDialog::setTotalSteps( int 
 {
     progressBar()->setTotalSteps( totalSteps );
+    if ( progress()>=totalSteps )
     showCancelButton( false );
 }
 
-int ProgressDialog::totalSteps()
+int ProgressDialog::totalSteps() const
 {
     return progressBar()->totalSteps();
 }
     
-void ProgressDialog::setProgress( int value )
+void ProgressDialog::setProgress( int progress )
 {
-    progressBar()->setProgress( value );
+    progressBar()->setProgress( progress );
+    if (progress>=totalSteps() )
     showCancelButton( false );
 }      
       
-int ProgressDialog::progress()
+int ProgressDialog::progress() const
 {
     return progressBar()->progress();
@@ -56,4 +58,25 @@ void ProgressDialog::setLabel(const QStr
 }
 
+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()
 {

--- kdebase/kdialog/progressdialog.h  #1.2:1.3
@@ -31,11 +31,17 @@ class ProgressDialog : public KProgressD
       
       void setTotalSteps( int );
-      int totalSteps();
+      int totalSteps() const;
     
       void setProgress( int );
-      int progress();
+      int progress() const;
       
       void setLabel(const QString&);
       
+      void showCancelButton(bool show);
+      bool wasCancelled() const;
+
+      void setAutoClose( bool );
+      bool autoClose() const;
+                  
       void close();
 };

--- kdebase/kdialog/progressdialogiface.h  #1.2:1.3
@@ -10,11 +10,16 @@ class ProgressDialogIface : virtual publ
 
     virtual void setTotalSteps( int ) =0;
-    virtual int totalSteps() =0;
+    virtual int totalSteps() const =0;
     
     virtual void setProgress( int ) =0;
-    virtual int progress() =0;
+    virtual int progress() const =0;
     
     virtual void setLabel( const QString& ) =0;
     
+    virtual void showCancelButton ( bool ) =0;
+    virtual bool wasCancelled() const =0;
+    
+    virtual void setAutoClose( bool ) =0;
+    virtual bool autoClose() const =0;    
     virtual void close() =0;
 };