1 /***************************************************************************
2                         progressdialog.h  -  description
3                              -------------------
4     begin                : Sun Jul 1 2007
5     copyright            : (C) 2007 by Dominik Seichter
6     email                : domseichter@web.de
7 ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 
18 #ifndef PROGRESS_DIALOG_H
19 #define PROGRESS_DIALOG_H
20 
21 #include <QDialog>
22 
23 #include "ui_progressdialog.h"
24 
25 #include "krenamefile.h"
26 
27 class BatchRenamer;
28 
29 class ProgressDialog : public QDialog
30 {
31     Q_OBJECT
32 
33 public:
34     ProgressDialog(ESplitMode eSplitMode, unsigned int dot, QWidget *parent = nullptr);
35 
36     /** Set the destination of the files
37      *  so that the user can easily open a file browser
38      *  theres.
39      *
40      *  @param dest the destination directory
41      */
42     inline void setDestination(const QUrl &dest);
43 
44     /** Set the number of total steps in the progressbar
45      *  which is displayed to the user.
46      *
47      *  @param t the number of steps
48      */
49     inline void setProgressTotalSteps(int t);
50 
51     /** Set the current progress
52      *
53      *  @param p current progress (must be smaller
54      *           than the total number of steps and bigger than 0)
55      *
56      *  \see setProgressTotalSteps
57      */
58     inline void setProgress(int p);
59 
60     /**
61      * @returns true if the user has cancelled the operation (otherwise false)
62      */
63     inline bool wasCancelled() const;
64 
65     /*
66     inline void setDestination( const KURL & dir );
67     inline void setRenamedFiles( RenamedList* list, unsigned int size ) ;
68     inline void setCreatedDirectories( const KURL::List & list );
69     *    */
70 
71     //void done( int errors, int successful, bool allowundo );
72 
73     /** Print an information message to the user
74      *
75      *  @param text message
76      *  @param pixmap an optional icon
77      */
78     void print(const QString &text, const QString &pixmap = nullptr);
79 
80     /** Print an error message to the user
81      *
82      *  @param text message
83      */
84     void error(const QString &text);
85 
86     /** Print a warning message to the user
87      *
88      *  @param text message
89      */
90     void warning(const QString &text);
91 
92     /** Renaming is done.
93      *
94      *  Mostly used to disable the cancel button
95      *  and enable other buttons
96      *
97      *  @param enableMore if ture the more button will be enabled
98      *  @param enableUndo if true the undo button will be enabled
99      *  @param batchRename is a handle to a batchrenamer instance that can be used to undo the operation and
100      *                     to determine URLs for a new renaming session
101      *  @param errros the number of errors that have occurred. If errors have occurred the user
102      *                has the extra possibility to only rename files with errors again
103      */
104     void renamingDone(bool enableMore, bool enableUndo, BatchRenamer *renamer, int errors);
105 
106 protected:
107     void closeEvent(QCloseEvent *event) override;
108 
109 private Q_SLOTS:
110     /** Called when the user cancels the operation
111      */
112     void slotCancelled();
113 
114     /** Called when the users presses the "Open Destination..." button
115      */
116     void slotOpenDestination();
117 
118     /** Called when the user wants to rename some more files
119      */
120     void slotRestartKRename();
121 
122     /** Called when the user wants to rename all files again
123      *  that have been processed without an error.
124      */
125     void slotRenameProcessedAgain();
126 
127     /** Called when the user wants to rename all files again
128      *  that have been processed with an error.
129      */
130     void slotRenameUnprocessedAgain();
131 
132     /** Called when the user wants to rename all files again.
133      */
134     void slotRenameAllAgain();
135 
136     /** Called when the user wants instant undo
137      */
138     void slotUndo();
139 
140 private:
141     Ui::ProgressDialog m_widget;
142 
143     bool m_canceled;         ///< the current canceled state
144     BatchRenamer *m_renamer; ///< A BatchRenamer that can undo the operation
145     QUrl m_dest;             ///< files destination
146 
147     QPushButton *m_buttonUndo;
148     QPushButton *m_buttonMore;
149     QPushButton *m_buttonDest;
150     QPushButton *m_buttonClose;
151 
152     QAction     *m_actProcessed;
153     QAction     *m_actUnprocessed;
154 
155     ESplitMode   m_eSplitMode;
156     unsigned int m_dot;
157 };
158 
setDestination(const QUrl & dest)159 void ProgressDialog::setDestination(const QUrl &dest)
160 {
161     m_dest = dest;
162 }
163 
setProgressTotalSteps(int t)164 void ProgressDialog::setProgressTotalSteps(int t)
165 {
166     m_widget.bar->setMaximum(t);
167 }
168 
setProgress(int p)169 void ProgressDialog::setProgress(int p)
170 {
171     m_widget.bar->setValue(p);
172 }
173 
wasCancelled()174 bool ProgressDialog::wasCancelled() const
175 {
176     return m_canceled;
177 }
178 
179 #endif // PROGRESS_DIALOG_H
180