<property name="windowTitle">
<string>Dialog</string>
</property>
+ <property name="modal">
+ <bool>true</bool>
+ </property>
<widget class="QTextEdit" name="textEdit">
<property name="geometry">
<rect>
<string>&OK</string>
</property>
</widget>
- <action name="actionOk">
- <property name="text">
- <string>&Ok</string>
- </property>
- <property name="toolTip">
- <string>Close the dialog</string>
- </property>
- <property name="shortcut">
- <string>Ctrl+X</string>
- </property>
- </action>
</widget>
<resources/>
<connections>
<connection>
- <sender>actionOk</sender>
- <signal>triggered()</signal>
+ <sender>pushButtonOK</sender>
+ <signal>clicked()</signal>
<receiver>AboutDialog</receiver>
<slot>close()</slot>
<hints>
<hint type="sourcelabel">
- <x>-1</x>
- <y>-1</y>
+ <x>196</x>
+ <y>183</y>
</hint>
<hint type="destinationlabel">
<x>199</x>
#include <QDir>
#include "base/rebase.hpp"
+#include "gui/regui.hpp"
#include "mainwindow.hpp"
#include "filefinder.hpp"
#include "textfinder.hpp"
#include <QApplication>
#include "base/rebase.hpp"
+#include "gui/regui.hpp"
#include "mainwindow.hpp"
int main(int argc, char *argv[]){
#include <QClipboard>
#include <QLineEdit>
#include "base/rebase.hpp"
+#include "gui/regui.hpp"
#include "textfinder.hpp"
#include "mainwindow.hpp"
#include "ui_mainwindow.h"
ui(new Ui::MainWindow),
m_statusMessage(NULL),
m_stdLabelBackgroundRole(NULL),
- m_errors(0),
m_textFinder(),
m_lastBaseDir(),
m_horizontalHeader(NULL),
SLOT(fullNameToClipboard()));
connect(ui->actionGetFullName, SIGNAL(triggered()), this,
SLOT(fullNameToClipboard()));
- connect(ui->actionReset, SIGNAL(triggered()), this,
- SLOT(resetParameters()));
+ connect(ui->actionReset, SIGNAL(triggered()), this, SLOT(resetParameters()));
connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int, int)));
m_horizontalHeader = ui->tableWidget->horizontalHeader();
connect(m_horizontalHeader, SIGNAL(sectionClicked ( int ) ),
*/
void MainWindow::about(){
AboutDialog dialog;
- dialog.setModal(true);
- dialog.show();
+ dialog.exec();
}
/**
}
}
-/**
- * Returns the date given as formula in a combobox.
- *
- * @param combo the combobox with the date/time formula
- *
- * @return the date resulting from the formula or begin of the epoch (error case)
- */
-QDateTime MainWindow::comboDate(QComboBox* combo){
- QDateTime rc;
- QString value = combo->currentText();
- if (value.isEmpty())
- rc.setMSecsSinceEpoch(0);
- else{
- ReDateTimeParser parser(value);
- if (parser.isValid()){
- rc = parser.asDateTime();
- setInHistory(combo, value);
- combo->setCurrentText(rc.toString("yyyy.MM.dd/hh:mm"));
- }else{
- guiError(combo, parser.errorMessage());
- rc.setMSecsSinceEpoch(0);
- }
- }
- return rc;
-}
-/**
- * Returns an integer given in a combobox.
- *
- * @param combo the combobox with the integer
- * @param defaultValue the value if the combobox is empty or invalid
- * @return <code>defaultValue</code>: empty or invalid input<br>
- * otherwise: or the size resulting from the formula
- */
-int MainWindow::comboInt(QComboBox* combo, int defaultValue){
- QString value = combo->currentText();
- int rc = defaultValue;
- if (!value.isEmpty()){
- uint nValue = 0;
- if (ReQStringUtil::lengthOfUInt(value, 0, 10, &nValue) == 0)
- guiError(combo, QObject::tr("not an integer: ") + value);
- else{
- setInHistory(combo, value);
- rc = (int) nValue;
- }
- }
- return rc;
-}
-
-/**
- * Returns the size (in bytes) given as formula in a combobox.
- *
- * @param combo the combobox with the size formula
- *
- * @return -1: empty or invalid input<br>
- * otherwise: or the size resulting from the formula
- */
-int64_t MainWindow::comboSize(QComboBox* combo){
- QString value = combo->currentText();
- int64_t rc = -1;
- if (!value.isEmpty()){
- ReSizeParser parser(value);
- rc = parser.asInt64(-1);
- if (rc >= 0){
- setInHistory(combo, value);
- combo->setCurrentText(QString("").sprintf("%ld", rc));
- }else
- guiError(combo, parser.errorMessage());
- }
- return rc;
-}
-
-/**
- * Handles an error found in an interactive widget.
- *
- * @param widget the widget where the error was found
- * @param message the error message
- */
-void MainWindow::guiError(QWidget* widget, const QString& message){
- widget->setFocus(Qt::OtherFocusReason);
- setStatusMessage(true, message);
- m_errors++;
-}
-
-QString MainWindow::comboText(QComboBox* combo){
- QString rc = combo->currentText();
- setInHistory(combo, rc);
- return rc;
-}
-
/**
* Converts the checkbox states to a filetype mask.
* @return the filetypes selected by the checkboxes
*/
void MainWindow::search(){
m_errors = 0;
- QApplication::setOverrideCursor(QCursor(Qt::WaitCursor));
- QString path = ui->comboBoxDirectory->currentText();
+ QApplication::setOverrideCursor (QCursor(Qt::WaitCursor));QString
+ path = ui->comboBoxDirectory->currentText();
QFileInfo dir(path);
if (!dir.exists())
guiError(ui->comboBoxDirectory, tr("directory not found: ") + path);
ui->comboBoxDirectory->setCurrentText(dir);
}
-/**
- * @brief Sets a text in a combobox uses as history.
- *
- * Sets the text as the first entry. If the text can be found in other entries
- * of the combobox it will be deleted there.
- *
- * @param combo the combobox to change
- * @param value the text to set
- */
-void MainWindow::setInHistory(QComboBox* combo, const QString& value){
- if (value.isEmpty()){
- // nothing to do
- }else if (combo->count() == 0)
- combo->addItem(value);
- else{
- if (value != combo->itemText(0)){
- combo->insertItem(0, value);
- }
- for (int ii = 1; ii < combo->count(); ii++){
- if (value == combo->itemText(ii)){
- combo->removeItem(ii);
- }
- }
- if (combo->count() > 20)
- combo->removeItem(20);
- }
-}
-
/**
* Writes a text to the status line.
*
#if ! defined TEXTFINDER_HPP
#include "textfinder.hpp"
#endif
+#if ! defined GUI_REGUI_HPP_
+#include "gui/regui.hpp"
+#endif
namespace Ui {
class MainWindow;
}
TC_NODE, TC_EXT, TC_SIZE, TC_MODIFIED, TC_TYPE, TC_PATH
};
-class MainWindow: public QMainWindow {
+class MainWindow: public QMainWindow, public ReGuiValidator {
Q_OBJECT
void headerClicked(int col);
void resetParameters();
void search();
- void up();
void selectDirectory();
+ void up();
private:
QString buildAbsPath(int row);
QDir::Filters buildFileTypes();
QString cellAsText(int row, int col);
- QDateTime comboDate(QComboBox* combo);
- int comboInt(QComboBox* combo, int defaultValue);
- int64_t comboSize(QComboBox* combo);
- QString comboText(QComboBox* combo);
- void guiError(QWidget* widget, const QString& message);
void prepareTextFind();
- void setInHistory(QComboBox* combo, const QString& value);
- void setStatusMessage(bool error, const QString& message);
+ virtual void setStatusMessage(bool error, const QString& message);
private:
Ui::MainWindow *ui;
QLabel* m_statusMessage;
QPalette::ColorRole* m_stdLabelBackgroundRole;
- int m_errors;
TextFinder m_textFinder;
// the directory of the last search
QDir m_lastBaseDir;
INCLUDEPATH = ../.. /usr/include/c++/4.9
SOURCES += main.cpp\
- mainwindow.cpp \
- ../../base/ReException.cpp \
- ../../base/ReQStringUtil.cpp \
- ../../base/ReLogger.cpp \
- filefinder.cpp \
- textfinder.cpp \
- aboutdialog.cpp
+ mainwindow.cpp \
+ ../../base/ReException.cpp \
+ ../../base/ReQStringUtil.cpp \
+ ../../base/ReLogger.cpp \
+ filefinder.cpp \
+ textfinder.cpp \
+ aboutdialog.cpp \
+ ../../gui/ReStateStorage.cpp \
+ ../../gui/ReGuiValidator.cpp
HEADERS += mainwindow.hpp \
- ../../base/rebase.hpp \
- filefinder.hpp \
- ../../base/ReQStringUtil.hpp \
- textfinder.hpp \
- aboutdialog.hpp
+ ../../base/rebase.hpp \
+ filefinder.hpp \
+ ../../base/ReQStringUtil.hpp \
+ textfinder.hpp \
+ ../../gui/ReStateStorage.hpp \
+ aboutdialog.hpp \
+ ../../gui/ReGuiValidator.hpp \
+ ../../gui/regui.hpp
FORMS += mainwindow.ui \
- aboutdialog.ui
+ aboutdialog.ui
RESOURCES += \
- refind.qrc
+ refind.qrc
* Destructor.
*/
TextFinder::~TextFinder(){
- if (m_ownsRegExpr){
- delete m_regExpr;
- m_regExpr = NULL;
- }
+ if (m_ownsRegExpr){
+ delete m_regExpr;
+ m_regExpr = NULL;
+ }
}
/**
m_ignoreCase = ignoreCase;
m_isRegExpr = isRegExpr;
m_ignoreBinary = ignoreBinary;
- if (! isRegExpr || text.isEmpty()){
- delete m_regExpr;
- m_regExpr = NULL;
- } else {
+ if (!isRegExpr || text.isEmpty()){
+ delete m_regExpr;
+ m_regExpr = NULL;
+ }else{
QRegularExpression::PatternOption option =
ignoreCase ?
QRegularExpression::CaseInsensitiveOption :
*/
QString TextFinder::regExprError(){
QString rc;
- if (m_regExpr != NULL && ! m_regExpr->isValid())
+ if (m_regExpr != NULL && !m_regExpr->isValid())
rc = m_regExpr->errorString();
return rc;
}
--- /dev/null
+/*
+ * ReGuiValidator.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use the license from http://www.wtfpl.net/.
+ * The latest sources: https://github.com/republib
+ */
+
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+
+/**
+ * Constructor.
+ */
+ReGuiValidator::ReGuiValidator() :
+ m_statusLine(NULL), m_errors(0){
+}
+
+/**
+ * Destructor.
+ */
+ReGuiValidator::~ReGuiValidator(){
+}
+
+/**
+ * Returns the date given as formula in a combobox.
+ *
+ * @param combo the combobox with the date/time formula
+ *
+ * @return the date resulting from the formula or begin of the epoch (error case)
+ */
+QDateTime ReGuiValidator::comboDate(QComboBox* combo){
+ QDateTime rc;
+ QString value = combo->currentText();
+ if (value.isEmpty())
+ rc.setMSecsSinceEpoch(0);
+ else{
+ ReDateTimeParser parser(value);
+ if (parser.isValid()){
+ rc = parser.asDateTime();
+ setInHistory(combo, value);
+ combo->setCurrentText(rc.toString("yyyy.MM.dd/hh:mm"));
+ }else{
+ guiError(combo, parser.errorMessage());
+ rc.setMSecsSinceEpoch(0);
+ }
+ }
+ return rc;
+}
+/**
+ * Returns an integer given in a combobox.
+ *
+ * @param combo the combobox with the integer
+ * @param defaultValue the value if the combobox is empty or invalid
+ * @return <code>defaultValue</code>: empty or invalid input<br>
+ * otherwise: or the size resulting from the formula
+ */
+int ReGuiValidator::comboInt(QComboBox* combo, int defaultValue){
+ QString value = combo->currentText();
+ int rc = defaultValue;
+ if (!value.isEmpty()){
+ uint nValue = 0;
+ if (ReQStringUtil::lengthOfUInt(value, 0, 10, &nValue) == 0)
+ guiError(combo, QObject::tr("not an integer: ") + value);
+ else{
+ setInHistory(combo, value);
+ rc = (int) nValue;
+ }
+ }
+ return rc;
+}
+
+/**
+ * Returns the size (in bytes) given as formula in a combobox.
+ *
+ * @param combo the combobox with the size formula
+ *
+ * @return -1: empty or invalid input<br>
+ * otherwise: or the size resulting from the formula
+ */
+int64_t ReGuiValidator::comboSize(QComboBox* combo){
+ QString value = combo->currentText();
+ int64_t rc = -1;
+ if (!value.isEmpty()){
+ ReSizeParser parser(value);
+ rc = parser.asInt64(-1);
+ if (rc >= 0){
+ setInHistory(combo, value);
+ combo->setCurrentText(QString("").sprintf("%ld", rc));
+ }else
+ guiError(combo, parser.errorMessage());
+ }
+ return rc;
+}
+
+/**
+ * Returns the current text from a combobox and puts it into the history.
+ *
+ * @param combo combobox to handle
+ *
+ * @return the current text
+ */
+QString ReGuiValidator::comboText(QComboBox* combo){
+ QString rc = combo->currentText();
+ setInHistory(combo, rc);
+ return rc;
+}
+
+/**
+ * Handles an error found in an interactive widget.
+ *
+ * @param widget the widget where the error was found
+ * @param message the error message
+ */
+void ReGuiValidator::guiError(QWidget* widget, const QString& message){
+ widget->setFocus(Qt::OtherFocusReason);
+ setStatusMessage(true, message);
+ m_errors++;
+}
+
+/**
+ * @brief Sets a text in a combobox uses as history.
+ *
+ * Sets the text as the first entry. If the text can be found in other entries
+ * of the combobox it will be deleted there.
+ *
+ * @param combo the combobox to change
+ * @param value the text to set
+ */
+void ReGuiValidator::setInHistory(QComboBox* combo, const QString& value){
+ if (value.isEmpty()){
+ // nothing to do
+ }else if (combo->count() == 0)
+ combo->addItem(value);
+ else{
+ if (value != combo->itemText(0)){
+ combo->insertItem(0, value);
+ }
+ for (int ii = 1; ii < combo->count(); ii++){
+ if (value == combo->itemText(ii)){
+ combo->removeItem(ii);
+ }
+ }
+ if (combo->count() > 20)
+ combo->removeItem(20);
+ }
+}
+/**
+ * Returns the status line.
+ * @return the status line
+ */
+QStatusBar* ReGuiValidator::statusLine() const{
+ return m_statusLine;
+}
+
+/**
+ * Sets the status line.
+ *
+ * @param statusLine the status line to set
+ */
+void ReGuiValidator::setStatusLine(QStatusBar* statusLine){
+ m_statusLine = statusLine;
+}
+
--- /dev/null
+/*
+ * ReGuiUtils.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use the license from http://www.wtfpl.net/.
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef GUI_REVALIDATOR_HPP_
+#define GUI_REVALIDATOR_HPP_
+
+#include <QComboBox>
+#include <QStatusBar>
+
+class ReGuiValidator {
+public:
+ ReGuiValidator();
+ ~ReGuiValidator();
+public:
+ QDateTime comboDate(QComboBox* combo);
+ int comboInt(QComboBox* combo, int defaultValue);
+ int64_t comboSize(QComboBox* combo);
+ QString comboText(QComboBox* combo);
+ virtual void guiError(QWidget* widget, const QString& message);
+ void setInHistory(QComboBox* combo, const QString& value);
+ void setStatusLine(QStatusBar* statusLine);
+ virtual void setStatusMessage(bool error, const QString& message) = 0;
+ QStatusBar* statusLine() const;
+
+protected:
+ QStatusBar* m_statusLine;
+ int m_errors;
+};
+
+#endif /* GUI_REVALIDATOR_HPP_ */
--- /dev/null
+/*
+ * ReStateStorage.cpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use the license from http://www.wtfpl.net/.
+ * The latest sources: https://github.com/republib
+ */
+
+#include "base/rebase.hpp"
+#include "gui/regui.hpp"
+
+/**
+ * Constructor.
+ *
+ * @param file
+ */
+ReStateStorage::ReStateStorage(const QString& file){
+
+}
+
+ReStateStorage::~ReStateStorage(){
+
+}
+
--- /dev/null
+/*
+ * ReStateStorage.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use the license from http://www.wtfpl.net/.
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef GUI_RESTATESTORAGE_HPP_
+#define GUI_RESTATESTORAGE_HPP_
+
+class ReStateStorage {
+public:
+ ReStateStorage(const QString& file);
+ virtual ~ReStateStorage();
+};
+
+#endif /* GUI_RESTATESTORAGE_HPP_ */
--- /dev/null
+/*
+ * regui.hpp
+ *
+ * License: Public Domain
+ * You can use and modify this file without any restriction.
+ * Do what you want.
+ * No warranties and disclaimer of any damages.
+ * You also can use the license from http://www.wtfpl.net/.
+ * The latest sources: https://github.com/republib
+ */
+
+#ifndef GUI_REGUI_HPP_
+#define GUI_REGUI_HPP_
+
+#include "gui/ReStateStorage.hpp"
+#include "gui/ReGuiValidator.hpp"
+#endif /* GUI_REGUI_HPP_ */