File indexing completed on 2022-10-04 17:30:22

0001 // SPDX-License-Identifier: GPL-2.0-or-later
0002 // SPDX-FileCopyrightText: 2007 Dominik Seichter <domseichter@web.de>
0003 
0004 #ifndef PROGRESS_DIALOG_H
0005 #define PROGRESS_DIALOG_H
0006 
0007 #include <QDialog>
0008 
0009 #include "ui_progressdialog.h"
0010 
0011 #include "krenamefile.h"
0012 
0013 class BatchRenamer;
0014 
0015 class ProgressDialog : public QDialog
0016 {
0017     Q_OBJECT
0018 
0019 public:
0020     ProgressDialog(ESplitMode eSplitMode, unsigned int dot, QWidget *parent = nullptr);
0021 
0022     /** Set the destination of the files
0023      *  so that the user can easily open a file browser
0024      *  theres.
0025      *
0026      *  @param dest the destination directory
0027      */
0028     inline void setDestination(const QUrl &dest);
0029 
0030     /** Set the number of total steps in the progressbar
0031      *  which is displayed to the user.
0032      *
0033      *  @param t the number of steps
0034      */
0035     inline void setProgressTotalSteps(int t);
0036 
0037     /** Set the current progress
0038      *
0039      *  @param p current progress (must be smaller
0040      *           than the total number of steps and bigger than 0)
0041      *
0042      *  \see setProgressTotalSteps
0043      */
0044     inline void setProgress(int p);
0045 
0046     /**
0047      * @returns true if the user has cancelled the operation (otherwise false)
0048      */
0049     inline bool wasCancelled() const;
0050 
0051     /*
0052     inline void setDestination( const KURL & dir );
0053     inline void setRenamedFiles( RenamedList* list, unsigned int size ) ;
0054     inline void setCreatedDirectories( const KURL::List & list );
0055     *    */
0056 
0057     //void done( int errors, int successful, bool allowundo );
0058 
0059     /** Print an information message to the user
0060      *
0061      *  @param text message
0062      *  @param pixmap an optional icon
0063      */
0064     void print(const QString &text, const QString &pixmap = nullptr);
0065 
0066     /** Print an error message to the user
0067      *
0068      *  @param text message
0069      */
0070     void error(const QString &text);
0071 
0072     /** Print a warning message to the user
0073      *
0074      *  @param text message
0075      */
0076     void warning(const QString &text);
0077 
0078     /** Renaming is done.
0079      *
0080      *  Mostly used to disable the cancel button
0081      *  and enable other buttons
0082      *
0083      *  @param enableMore if ture the more button will be enabled
0084      *  @param enableUndo if true the undo button will be enabled
0085      *  @param batchRename is a handle to a batchrenamer instance that can be used to undo the operation and
0086      *                     to determine URLs for a new renaming session
0087      *  @param errros the number of errors that have occurred. If errors have occurred the user
0088      *                has the extra possibility to only rename files with errors again
0089      */
0090     void renamingDone(bool enableMore, bool enableUndo, BatchRenamer *renamer, int errors);
0091 
0092 protected:
0093     void closeEvent(QCloseEvent *event) override;
0094 
0095 private Q_SLOTS:
0096     /** Called when the user cancels the operation
0097      */
0098     void slotCancelled();
0099 
0100     /** Called when the users presses the "Open Destination..." button
0101      */
0102     void slotOpenDestination();
0103 
0104     /** Called when the user wants to rename some more files
0105      */
0106     void slotRestartKRename();
0107 
0108     /** Called when the user wants to rename all files again
0109      *  that have been processed without an error.
0110      */
0111     void slotRenameProcessedAgain();
0112 
0113     /** Called when the user wants to rename all files again
0114      *  that have been processed with an error.
0115      */
0116     void slotRenameUnprocessedAgain();
0117 
0118     /** Called when the user wants to rename all files again.
0119      */
0120     void slotRenameAllAgain();
0121 
0122     /** Called when the user wants instant undo
0123      */
0124     void slotUndo();
0125 
0126 private:
0127     Ui::ProgressDialog m_widget;
0128 
0129     bool m_canceled;         ///< the current canceled state
0130     BatchRenamer *m_renamer; ///< A BatchRenamer that can undo the operation
0131     QUrl m_dest;             ///< files destination
0132 
0133     QPushButton *m_buttonUndo;
0134     QPushButton *m_buttonMore;
0135     QPushButton *m_buttonDest;
0136     QPushButton *m_buttonClose;
0137 
0138     QAction     *m_actProcessed;
0139     QAction     *m_actUnprocessed;
0140 
0141     ESplitMode   m_eSplitMode;
0142     unsigned int m_dot;
0143 };
0144 
0145 void ProgressDialog::setDestination(const QUrl &dest)
0146 {
0147     m_dest = dest;
0148 }
0149 
0150 void ProgressDialog::setProgressTotalSteps(int t)
0151 {
0152     m_widget.bar->setMaximum(t);
0153 }
0154 
0155 void ProgressDialog::setProgress(int p)
0156 {
0157     m_widget.bar->setValue(p);
0158 }
0159 
0160 bool ProgressDialog::wasCancelled() const
0161 {
0162     return m_canceled;
0163 }
0164 
0165 #endif // PROGRESS_DIALOG_H