File indexing completed on 2024-12-01 13:50:26

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