]> gitweb.hamatoma.de Git - reqt/commitdiff
dayly work
authorhama <hama@siduction.net>
Sun, 1 Nov 2015 00:17:11 +0000 (01:17 +0100)
committerhama <hama@siduction.net>
Sun, 1 Nov 2015 00:17:11 +0000 (01:17 +0100)
22 files changed:
.gitignore
appl/refind/filefinder.cpp
appl/refind/mainwindow.cpp
appl/refind/mainwindow.hpp
appl/refind/refind.pro
appl/refind/textfinder.cpp
appl/refind/utils.cpp
appl/reidos/FileCommander.cpp
appl/reidos/idosmain.cpp
appl/reidos/idosmain.hpp
base/ReFileUtils.cpp
base/ReFileUtils.hpp
base/ReLogger.cpp
base/ReLogger.hpp
base/ReQStringUtils.hpp
gui/ReEdit.hpp
gui/ReGuiValidator.cpp
gui/ReGuiValidator.hpp
guiwidget/ReFileTable.cpp
guiwidget/ReFileTable.hpp
guiwidget/reguiwidget.hpp
os/ReFileSystem.cpp

index 5c1c43ba7739fd0a68bbfa6725ad770f602a09b5..a427b8f171335113a6d3dcc813a74ac00c1e6d93 100644 (file)
@@ -10,3 +10,4 @@ doc/
 rpldoc.zip
 build/
 appl/build-reidos-Desktop-Debug/
+.metadata
index 9dbc6926be6a4da072e9ac4370db4c1639a08a89..d6b453390dddda8b544dd75a171511109ef1ecfa 100644 (file)
  * Constructor.
  */
 FileFinder::FileFinder() :
-            m_lines(0),
-            m_patterns(),
-            m_antiPatterns(),
-            m_minSize(0),
-            m_maxSize(-1),
-            m_youngerThan(),
-            m_olderThan(),
-            m_fileTypes(QDir::NoFilter),
-            m_minDepth(0),
-            m_maxDepth(512),
-            m_baseDir(""),
-            m_checkDates(false),
-            m_excludedDirs(),
-            m_textFinder(NULL){
+                       m_lines(0),
+                       m_patterns(),
+                       m_antiPatterns(),
+                       m_minSize(0),
+                       m_maxSize(-1),
+                       m_youngerThan(),
+                       m_olderThan(),
+                       m_fileTypes(QDir::NoFilter),
+                       m_minDepth(0),
+                       m_maxDepth(512),
+                       m_baseDir(""),
+                       m_checkDates(false),
+                       m_excludedDirs(),
+                       m_textFinder(NULL){
    m_youngerThan.setMSecsSinceEpoch(0);
    m_olderThan.setMSecsSinceEpoch(0);
 }
@@ -78,14 +78,14 @@ QString fileSize(int64_t size){
 QString typeOf(const QFileInfo& info){
    QString rc;
    if (info.isSymLink()){
-      if (info.isDir())
-         rc = QObject::tr("link (dir)");
-      else
-         rc = QObject::tr("link (file)");
+         if (info.isDir())
+                rc = QObject::tr("link (dir)");
+         else
+                rc = QObject::tr("link (file)");
    }else if (info.isDir())
-      rc = QObject::tr("dir");
+         rc = QObject::tr("dir");
    else
-      rc = QObject::tr("file");
+         rc = QObject::tr("file");
    return rc;
 }
 
@@ -113,73 +113,73 @@ void FileFinder::fillTable(const QString& path, int depth, QTableWidget* table,
    table->setSortingEnabled(false);
    QDir::Filters filters = m_fileTypes | QDir::NoDotAndDotDot;
    if (m_patterns.count() == 0)
-      entries = dir.entryInfoList(filters, QDir::NoSort);
+         entries = dir.entryInfoList(filters, QDir::NoSort);
    else
-      entries = dir.entryInfoList(m_patterns, filters, QDir::NoSort);
-   QString relativePath = ReQStringUtil::nativePath(
-      path.mid(1 + m_baseDir.length()));
+         entries = dir.entryInfoList(m_patterns, filters, QDir::NoSort);
+   QString relativePath = ReQStringUtils::nativePath(
+         path.mid(1 + m_baseDir.length()));
    QString node, ext;
    QList<QRegExp*> antiPatterns;
    QStringList::const_iterator it3;
    for (it3 = m_antiPatterns.begin(); it3 != m_antiPatterns.end(); ++it3){
-       QString pattern(*it3);
-       antiPatterns.append(new QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard));
+          QString pattern(*it3);
+          antiPatterns.append(new QRegExp(pattern, Qt::CaseInsensitive, QRegExp::Wildcard));
    }
    QList<QRegExp*>::const_iterator it2;
    QList <QFileInfo>::const_iterator it;
    for (it = entries.begin(); it != entries.end(); ++it){
-      node = it->fileName();
-      if (node == "." || node == "..")
-         continue;
-      bool ignore = false;
-      for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){
-          if ((*it2)->indexIn(node) >= 0){
-              ignore = true;
-              break;
-          }
-      }
-      if (ignore)
-          continue;
-      if (depth >= m_minDepth && isValid(*it)){
-         if (m_lines >= table->rowCount()){
-            table->setRowCount(m_lines + 500);
-         }
-         bool isDir = it->isDir();
-         if (isDir)
-            statistics.m_dirs++;
-         else
-            statistics.m_files++;
-         table->setItem(m_lines, TC_NODE, new QTableWidgetItem(node));
-         int ix = node.lastIndexOf('.');
-         ext = ix <= 0 ? "" : node.mid(ix + 1).toLower();
-         table->setItem(m_lines, TC_EXT, new QTableWidgetItem(ext));
-         table->setItem(m_lines, TC_TYPE, new QTableWidgetItem(typeOf(*it)));
-         table->setItem(m_lines, TC_PATH, new QTableWidgetItem(relativePath));
-         QTableWidgetItem* item = new QTableWidgetItem(
-            isDir ? "" : fileSize(it->size()));
-         if (!isDir)
-            statistics.m_bytes += it->size();
-         item->setTextAlignment(Qt::AlignRight);
-         table->setItem(m_lines, TC_SIZE, item);
-         table->setItem(m_lines, TC_MODIFIED,
-            new QTableWidgetItem(
-               it->lastModified().toString("yyyy.MM.dd/hh:mm:ss")));
-         m_lines++;
-      }
+         node = it->fileName();
+         if (node == "." || node == "..")
+                continue;
+         bool ignore = false;
+         for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){
+                 if ((*it2)->indexIn(node) >= 0){
+                         ignore = true;
+                         break;
+                 }
+         }
+         if (ignore)
+                 continue;
+         if (depth >= m_minDepth && isValid(*it)){
+                if (m_lines >= table->rowCount()){
+                       table->setRowCount(m_lines + 500);
+                }
+                bool isDir = it->isDir();
+                if (isDir)
+                       statistics.m_dirs++;
+                else
+                       statistics.m_files++;
+                table->setItem(m_lines, TC_NODE, new QTableWidgetItem(node));
+                int ix = node.lastIndexOf('.');
+                ext = ix <= 0 ? "" : node.mid(ix + 1).toLower();
+                table->setItem(m_lines, TC_EXT, new QTableWidgetItem(ext));
+                table->setItem(m_lines, TC_TYPE, new QTableWidgetItem(typeOf(*it)));
+                table->setItem(m_lines, TC_PATH, new QTableWidgetItem(relativePath));
+                QTableWidgetItem* item = new QTableWidgetItem(
+                       isDir ? "" : fileSize(it->size()));
+                if (!isDir)
+                       statistics.m_bytes += it->size();
+                item->setTextAlignment(Qt::AlignRight);
+                table->setItem(m_lines, TC_SIZE, item);
+                table->setItem(m_lines, TC_MODIFIED,
+                       new QTableWidgetItem(
+                          it->lastModified().toString("yyyy.MM.dd/hh:mm:ss")));
+                m_lines++;
+         }
    }
    for (it2 = antiPatterns.begin(); it2 != antiPatterns.end(); ++it2){
-       delete *it2;
+          delete *it2;
    }
    if (depth < m_maxDepth || m_maxDepth < 0){
-      entries = dir.entryInfoList(
-         QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDir::NoSort);
-      bool filtered = m_excludedDirs.length() > 0;
-      for (it = entries.begin(); it != entries.end(); ++it){
-         QString node = it->fileName();
-         if (!filtered || !isExcludedDir(node))
-            fillTable(path + QDir::separator() + node, depth + 1, table,
-               statistics);
-      }
+         entries = dir.entryInfoList(
+                QDir::NoSymLinks | QDir::NoDotAndDotDot | QDir::AllDirs, QDir::NoSort);
+         bool filtered = m_excludedDirs.length() > 0;
+         for (it = entries.begin(); it != entries.end(); ++it){
+                QString node = it->fileName();
+                if (!filtered || !isExcludedDir(node))
+                       fillTable(path + QDir::separator() + node, depth + 1, table,
+                          statistics);
+         }
    }
    table->setRowCount(m_lines);
 }
@@ -194,10 +194,10 @@ bool FileFinder::isExcludedDir(const QString& node){
    bool rc = false;
    QList <QString>::iterator it;
    for (it = m_excludedDirs.begin(); it != m_excludedDirs.end(); ++it){
-      if (QString::compare(node, *it, Qt::CaseInsensitive) == 0){
-         rc = true;
-         break;
-      }
+         if (QString::compare(node, *it, Qt::CaseInsensitive) == 0){
+                rc = true;
+                break;
+         }
    }
    return rc;
 }
@@ -213,18 +213,18 @@ bool FileFinder::isValid(const QFileInfo& file){
    bool rc = size >= m_minSize && (m_maxSize < 0 || size <= m_maxSize);
    bool checkYounger;
    if (rc
-      && ((checkYounger = m_youngerThan.toMSecsSinceEpoch() > 0)
-         || m_olderThan.toMSecsSinceEpoch() > 0)){
-      QDateTime date = file.lastModified();
-      rc = !checkYounger || date >= m_youngerThan;
-      if (rc)
-         rc = m_olderThan.toMSecsSinceEpoch() == 0 || date <= m_olderThan;
+         && ((checkYounger = m_youngerThan.toMSecsSinceEpoch() > 0)
+                || m_olderThan.toMSecsSinceEpoch() > 0)){
+         QDateTime date = file.lastModified();
+         rc = !checkYounger || date >= m_youngerThan;
+         if (rc)
+                rc = m_olderThan.toMSecsSinceEpoch() == 0 || date <= m_olderThan;
    }
    if (rc && m_textFinder != NULL){
-      QString full = file.absoluteFilePath();
-      TextFinder textFinder(full, file.size());
-      textFinder.getSearchParameter(*m_textFinder);
-      rc = textFinder.contains();
+         QString full = file.absoluteFilePath();
+         TextFinder textFinder(full, file.size());
+         textFinder.getSearchParameter(*m_textFinder);
+         rc = textFinder.contains();
    }
    return rc;
 }
@@ -301,7 +301,7 @@ void FileFinder::setMinSize(const int64_t& minSize){
 void FileFinder::setOlderThan(const QDateTime& olderThan){
    m_olderThan = olderThan;
    if (m_olderThan.toMSecsSinceEpoch() > 0)
-      m_checkDates = true;
+         m_checkDates = true;
 }
 
 /**
@@ -314,14 +314,14 @@ void FileFinder::setPatterns(const QStringList& patterns){
    m_antiPatterns.clear();
    QStringList::const_iterator it;
    for (it = patterns.begin(); it != patterns.end(); ++it){
-       QString pattern = *it;
-       if (pattern.startsWith("-")){
-           if (pattern.length() > 1)
-               m_antiPatterns.append(pattern.mid(1));
-       } else {
-           if (pattern.length() > 0)
-               m_patterns.append(pattern);
-       }
+          QString pattern = *it;
+          if (pattern.startsWith("-")){
+                  if (pattern.length() > 1)
+                          m_antiPatterns.append(pattern.mid(1));
+          } else {
+                  if (pattern.length() > 0)
+                          m_patterns.append(pattern);
+          }
    }
 }
 
@@ -333,6 +333,6 @@ void FileFinder::setPatterns(const QStringList& patterns){
 void FileFinder::setYoungerThan(const QDateTime& youngerThan){
    m_youngerThan = youngerThan;
    if (youngerThan.toMSecsSinceEpoch() > 0)
-      m_checkDates = true;
+         m_checkDates = true;
 }
 
index bdf94df90cd84d00b4d1bb85e0416ba99508f181..92aab297bf3d5cf9c31761bd98ff87a159c472bf 100644 (file)
@@ -49,7 +49,8 @@ MainWindow::MainWindow(const QString& startDir, const QString& homeDir,
                        m_lastOrder(Qt::DescendingOrder),
                        m_homeDir(homeDir),
                        m_storageFile(),
-                       m_contextHandlers(){
+                       m_contextHandlers(),
+                       m_logger(new ReMemoryLogger()){
    ui->setupUi(this);
    initializeHome();
    m_statusMessage = new QLabel(tr("Welcome at refind"));
@@ -180,11 +181,11 @@ QString MainWindow::buildAbsPath(int row, bool withNode, bool uriFormat){
    QString rc(m_lastBaseDir.absolutePath());
    QString value = cellAsText(row, TC_PATH);
    if (!value.isEmpty()){
-         ReQStringUtil::ensureLastChar(rc, '/');
+         ReQStringUtils::ensureLastChar(rc, '/');
          rc += value;
    }
    if (withNode){
-         ReQStringUtil::ensureLastChar(rc, '/');
+         ReQStringUtils::ensureLastChar(rc, '/');
          rc += cellAsText(row, TC_NODE);
    }
    if (uriFormat){
@@ -285,7 +286,7 @@ void MainWindow::exportFiles(){
                 QTextStream stream(fp);
                 exportToStream(stream);
                 fclose(fp);
-                setStatusMessage(false, tr("result exported to ") + fn);
+                say(LOG_INFO, tr("result exported to ") + fn);
          }
    }else{
          QString value;
@@ -295,7 +296,7 @@ void MainWindow::exportFiles(){
          QClipboard* clipboard = QApplication::clipboard();
          clipboard->setText(value);
          if (m_errors == 0)
-                setStatusMessage(false, tr("result exported to the clipboard"));
+                say(LOG_INFO, tr("result exported to the clipboard"));
    }
 }
 
@@ -320,16 +321,16 @@ void MainWindow::exportToStream(QTextStream& stream, int maxRow){
          QString line = ui->comboBoxTemplate->currentText();
          QMap < QString, QString > placeholders;
          QString path = m_lastBaseDir.absoluteFilePath(
-                ReQStringUtil::pathAppend(ui->tableWidget->item(ii, TC_PATH)->text(),
+                ReFileUtils::pathAppend(ui->tableWidget->item(ii, TC_PATH)->text(),
                        ui->tableWidget->item(ii, TC_NODE)->text()));
-         placeholders.insert("full", ReQStringUtil::nativePath(path));
+         placeholders.insert("full", ReQStringUtils::nativePath(path));
          placeholders.insert("path", ui->tableWidget->item(ii, TC_PATH)->text());
          placeholders.insert("ext", ui->tableWidget->item(ii, TC_EXT)->text());
          placeholders.insert("node", ui->tableWidget->item(ii, TC_NODE)->text());
          placeholders.insert("modified",
                 ui->tableWidget->item(ii, TC_MODIFIED)->text());
          placeholders.insert("size", ui->tableWidget->item(ii, TC_SIZE)->text());
-         if (!ReQStringUtil::replacePlaceholders(line, placeholders, &error)){
+         if (!ReQStringUtils::replacePlaceholders(line, placeholders, &error)){
                 guiError(ui->comboBoxTemplate, error);
                 break;
          }
@@ -373,7 +374,7 @@ void MainWindow::fileDragging(){
          QPainter painter(&image);
          QString msg;
          if (urls.size() == 1)
-                msg = tr("copy ") + ReQStringUtil::nodeOf(urls.at(0).toString());
+                msg = tr("copy ") + ReFileUtils::nodeOf(urls.at(0).toString());
          else if (files > 0 && dirs > 0)
                 msg = tr("copy %1 file(s) and %2 dir(s)").arg(files).arg(dirs);
          else if (files > 0)
@@ -454,7 +455,7 @@ void MainWindow::handleCopyToClipboard(int currentRow, const QString& full){
    mimeData->setText(textList);
    QClipboard *clipboard = QApplication::clipboard();
    clipboard->setMimeData(mimeData);
-   setStatusMessage(false,
+   say(LOG_INFO,
          tr("%1 entry/entries copied to clipboard").arg(urls.length()));
 }
 
@@ -485,13 +486,13 @@ void MainWindow::handleExternalCommand(ContextHandler* handler,
    placeholders.insert("full", full);
    placeholders.insert("node", node);
    placeholders.insert("path", parent);
-   placeholders.insert("ext", ReQStringUtil::extensionOf(node));
+   placeholders.insert("ext", ReFileUtils::extensionOf(node));
    QString error;
    QStringList args = arguments.split(' ');
    bool hasErrors = false;
    for (int ix = 0; ix < args.size(); ix++){
          QString arg = args.at(ix);
-         if (!ReQStringUtil::replacePlaceholders(arg, placeholders, &error)){
+         if (!ReQStringUtils::replacePlaceholders(arg, placeholders, &error)){
                 guiError(NULL, error);
                 hasErrors = true;
                 break;
@@ -500,7 +501,7 @@ void MainWindow::handleExternalCommand(ContextHandler* handler,
    }
    if (!hasErrors){
          QProcess::startDetached(handler->m_program, args, dir, NULL);
-         setStatusMessage(false,
+         say(LOG_INFO,
                 tr("started:") + " " + handler->m_program + " " + arguments);
    }
 }
@@ -553,7 +554,7 @@ void MainWindow::handleTableContextMenu(const QPoint& position){
 
          QString node = ui->tableWidget->item(currentRow, TC_NODE)->text();
          QString parent = buildAbsPath(currentRow);
-         QString full = ReQStringUtil::pathAppend(parent, node);
+         QString full = ReFileUtils::pathAppend(parent, node);
          QFileInfo file(full);
          bool isDir = file.isDir();
          QList <ContextHandler*>::const_iterator it;
@@ -685,7 +686,7 @@ QString MainWindow::replaceGlobalPlaceholders(QComboBox* combo,
 QMap <QString, QString>& placeholders){
 QString rc = combo->currentText();
 QString error;
-if (!ReQStringUtil::replacePlaceholders(rc, placeholders, &error))
+if (!ReQStringUtils::replacePlaceholders(rc, placeholders, &error))
    guiError(combo, error);
 return replaceEscSequences(rc);
 }
@@ -716,7 +717,7 @@ ui->checkBoxTextIgnoreCase->setChecked(false);
  * Reads the history of the widget values and other parameters and set it.
  */
 void MainWindow::restoreState(){
-ReStateStorage storage(m_storageFile);
+ReStateStorage storage(m_storageFile, m_logger);
 storage.setForm("main");
 storage.restore(ui->comboBoxDirectory, "comboBoxDirectory", true);
 storage.restore(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs", true);
@@ -740,7 +741,7 @@ storage.close();
  * Stores the history of the widget values and other parameters.
  */
 void MainWindow::saveState(){
-ReStateStorage storage(m_storageFile);
+ReStateStorage storage(m_storageFile, m_logger);
 storage.setForm("main");
 storage.store(ui->comboBoxDirectory, "comboBoxDirectory");
 storage.store(ui->comboBoxExcludedDirs, "comboBoxExcludedDirs");
@@ -812,7 +813,7 @@ else{
                        "Found: %d dir(s) and %d file(s) with %.6f MByte. Duration of the search: %.3f sec").toUtf8(),
                 m_statistics.m_dirs, m_statistics.m_files,
                 m_statistics.m_bytes / 1000000.0, m_statistics.m_runtimeSeconds);
-         setStatusMessage(false, msg);
+         say(LOG_INFO, msg);
    }
 }
 QApplication::restoreOverrideCursor();
@@ -839,18 +840,23 @@ if (!name.isEmpty())
 }
 
 /**
- * Writes a text to the status line.
+ * Issues a message in the status line.
  *
- * @param error     <code>true</code>: the message is an error message
- * @param message   the text to set
- */
-void MainWindow::setStatusMessage(bool error, const QString& message){
-if (m_stdLabelBackgroundRole == NULL)
-   m_stdLabelBackgroundRole = new QPalette::ColorRole(
-         m_statusMessage->backgroundRole());
-m_statusMessage->setBackgroundRole(
-   error ? QPalette::HighlightedText : *m_stdLabelBackgroundRole);
-m_statusMessage->setText(message);
+ * @param level                type of the message, e.g. LOG_INFO or LOG_ERROR
+ * @param message      the message to issue. Use QString::arg() to format,
+ *                                     e.g. <code>say(QString("name: %1 no: %2).arg(name).arg(no)</code>
+ * @return                     <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+ *                                     <code>true</code>: level >= LOG_INFO
+ */
+bool MainWindow::say(ReLoggerLevel level, const QString& message){
+       bool rc = level >= LOG_INFO;
+       if (m_stdLabelBackgroundRole == NULL)
+               m_stdLabelBackgroundRole = new QPalette::ColorRole(
+                                       m_statusMessage->backgroundRole());
+       m_statusMessage->setBackgroundRole(
+                               ! rc ? QPalette::HighlightedText : *m_stdLabelBackgroundRole);
+       m_statusMessage->setText(message);
+       return rc;
 }
 
 /**
index 7391964b90ecd992ee733568206ca1fcd0cac48f..d38e53a5f24f4957cb7de9884556592d54351a4e 100644 (file)
@@ -84,7 +84,7 @@ private:
    QString replaceGlobalPlaceholders(QComboBox* combo,
          QMap <QString, QString>& placeholders);
    void restoreState();
-   virtual void setStatusMessage(bool error, const QString& message);
+   virtual bool say(ReLoggerLevel level, const QString& message);
 private:
    Ui::MainWindow *ui;
    QLabel* m_statusMessage;
@@ -100,6 +100,7 @@ private:
    QAction* m_actionEditor;
    QAction* m_actionStartShell;
    ContextHandlerList m_contextHandlers;
+   ReLogger* m_logger;
 };
 
 #endif // MAINWINDOW_HPP
index 669aac4a90c009a56b5dd0420fade9519ebe2e21..619646a2c6b618ba1f56dd60672ef4509b053a6a 100644 (file)
@@ -18,7 +18,8 @@ INCLUDEPATH = ../.. /usr/include/c++/4.9
 SOURCES += main.cpp\
                  mainwindow.cpp \
         ../../base/ReException.cpp \
-        ../../base/ReQStringUtil.cpp \
+        ../../base/ReQStringUtils.cpp \
+        ../../base/ReFileUtils.cpp \
         ../../base/ReLogger.cpp \
         filefinder.cpp \
         textfinder.cpp \
index 6188eb043b8da54196d77d7259fec0b0a34c1a1f..235286060e6e4b62663cd9a7f8af4d383508fe4b 100644 (file)
  * Constructor.
  */
 TextFinder::TextFinder() :
-            m_ignoreBinary(false),
-            m_filename(),
-            m_length(0),
-            m_file(),
-            m_valid(false),
-            m_regExpr(NULL),
-            m_isRegExpr(false),
-            m_ignoreCase(false),
-            m_ownsRegExpr(false),
-            m_text(){
+                       m_ignoreBinary(false),
+                       m_filename(),
+                       m_length(0),
+                       m_file(),
+                       m_valid(false),
+                       m_regExpr(NULL),
+                       m_isRegExpr(false),
+                       m_ignoreCase(false),
+                       m_ownsRegExpr(false),
+                       m_text(){
 }
 
 TextFinder::TextFinder(const QString& fullName, int64_t length) :
-            m_ignoreBinary(false),
-            m_filename(fullName),
-            m_length(length),
-            m_file(fullName),
-            m_valid(false),
-            m_regExpr(NULL),
-            m_isRegExpr(false),
-            m_ignoreCase(false),
-            m_ownsRegExpr(false),
-            m_text(){
+                       m_ignoreBinary(false),
+                       m_filename(fullName),
+                       m_length(length),
+                       m_file(fullName),
+                       m_valid(false),
+                       m_regExpr(NULL),
+                       m_isRegExpr(false),
+                       m_ignoreCase(false),
+                       m_ownsRegExpr(false),
+                       m_text(){
    m_valid = m_file.open(QIODevice::ReadOnly);
 }
 
@@ -48,8 +48,8 @@ TextFinder::TextFinder(const QString& fullName, int64_t length) :
  */
 TextFinder::~TextFinder(){
    if (m_ownsRegExpr){
-      delete m_regExpr;
-      m_regExpr = NULL;
+         delete m_regExpr;
+         m_regExpr = NULL;
    }
 }
 
@@ -64,30 +64,30 @@ TextFinder::~TextFinder(){
 bool TextFinder::contains(){
    bool rc = false;
    if (!m_ignoreBinary || !isBinary()){
-      m_file.seek(0);
-      QTextStream stream(&m_file);
-      QString line;
-      if (m_regExpr != NULL){
-         QRegularExpressionMatch match;
-         while (!stream.atEnd()){
-            line = stream.readLine();
-            match = m_regExpr->match(line);
-            if (match.hasMatch()){
-               rc = true;
-               break;
-            }
-         }
-      }else{
-         Qt::CaseSensitivity mode =
-                  m_ignoreCase ? Qt::CaseInsensitive : Qt::CaseSensitive;
-         while (!stream.atEnd()){
-            line = stream.readLine();
-            if (line.indexOf(m_text, 0, mode) >= 0){
-               rc = true;
-               break;
-            }
-         }
-      }
+         m_file.seek(0);
+         QTextStream stream(&m_file);
+         QString line;
+         if (m_regExpr != NULL){
+                QRegularExpressionMatch match;
+                while (!stream.atEnd()){
+                       line = stream.readLine();
+                       match = m_regExpr->match(line);
+                       if (match.hasMatch()){
+                          rc = true;
+                          break;
+                       }
+                }
+         }else{
+                Qt::CaseSensitivity mode =
+                                 m_ignoreCase ? Qt::CaseInsensitive : Qt::CaseSensitive;
+                while (!stream.atEnd()){
+                       line = stream.readLine();
+                       if (line.indexOf(m_text, 0, mode) >= 0){
+                          rc = true;
+                          break;
+                       }
+                }
+         }
    }
    return rc;
 }
@@ -114,7 +114,7 @@ bool TextFinder::isBinary(){
    QByteArray data = m_file.read(64 * 1024);
    int length = data.length();
    const char* ptr = reinterpret_cast <const char*>(memchr(data.constData(),
-      '\0', length));
+         '\0', length));
    bool rc = ptr != NULL;
    return rc;
 }
@@ -132,16 +132,16 @@ bool TextFinder::isText(const QByteArray& data, bool* trueAscii){
    uint8_t byte1;
    bool rc = true;
    while ((byte1 = *ptr++) != '\0'){
-      // ASCII with control chars:
-      if (byte1 < ' ' && byte1 != '\t' && byte1 != '\n' && byte1 != '\r'){
-         rc = false;
-         break;
-      }
-      if (rc > 0x7f)
-         isAscii = false;
+         // ASCII with control chars:
+         if (byte1 < ' ' && byte1 != '\t' && byte1 != '\n' && byte1 != '\r'){
+                rc = false;
+                break;
+         }
+         if (byte1 > 0x7f)
+                isAscii = false;
    }
    if (trueAscii != NULL)
-      *trueAscii = rc && isAscii;
+         *trueAscii = rc && isAscii;
    return rc;
 }
 
@@ -158,47 +158,47 @@ bool TextFinder::isUTF8(const QByteArray& data, bool* trueAscii) const{
    uint8_t byte1;
    bool rc = true;
    while ((byte1 = *ptr++) != '\0'){
-      // ASCII with control chars:
-      if ((0x20 <= byte1 && byte1 <= 0x7E) || byte1 == '\t' || byte1 == '\n'
-         || byte1 == '\r'){
-         continue;
-      }
-      isAscii = false;
-      uint8_t byte2 = *ptr++;
-      // non-overlong 2-byte
-      if (0xC2 <= byte1 && byte1 <= 0xDF && 0x80 <= byte2 && byte2 <= 0xBF){
-         continue;
-      }
-      uint8_t byte3 = *ptr++;
-      // excluding overlongs
-      if ((byte1 == 0xE0 && 0xA0 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
-         && byte3 <= 0xBF)
-      // straight 3-byte
-         || (((0xE1 <= byte1 && byte1 <= 0xEC) || byte1 == 0xEE || byte1 == 0xEF)
-            && 0x80 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3 && byte3 <= 0xBF)
-         // excluding surrogates
-         || (byte1 == 0xED && (0x80 <= byte2 && byte2 <= 0x9F)
-            && (0x80 <= byte3 && byte3 <= 0xBF))){
-         continue;
-      }
-      uint8_t byte4 = *ptr++;
-      if ( // planes 1-3
-      (byte1 == 0xF0 && 0x90 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
-         && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
-      // planes 4-15
-         || (0xF1 <= byte1 && byte1 <= 0xF3 && 0x80 <= byte2 && byte2 <= 0xBF
-            && 0x80 <= byte3 && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
-         // plane 16
-         || (byte1 == 0xF4 && 0x80 <= byte2 && byte2 <= 0x8F && 0x80 <= byte3
-            && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)){
-         continue;
-      }
+         // ASCII with control chars:
+         if ((0x20 <= byte1 && byte1 <= 0x7E) || byte1 == '\t' || byte1 == '\n'
+                || byte1 == '\r'){
+                continue;
+         }
+         isAscii = false;
+         uint8_t byte2 = *ptr++;
+         // non-overlong 2-byte
+         if (0xC2 <= byte1 && byte1 <= 0xDF && 0x80 <= byte2 && byte2 <= 0xBF){
+                continue;
+         }
+         uint8_t byte3 = *ptr++;
+         // excluding overlongs
+         if ((byte1 == 0xE0 && 0xA0 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
+                && byte3 <= 0xBF)
+         // straight 3-byte
+                || (((0xE1 <= byte1 && byte1 <= 0xEC) || byte1 == 0xEE || byte1 == 0xEF)
+                       && 0x80 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3 && byte3 <= 0xBF)
+                // excluding surrogates
+                || (byte1 == 0xED && (0x80 <= byte2 && byte2 <= 0x9F)
+                       && (0x80 <= byte3 && byte3 <= 0xBF))){
+                continue;
+         }
+         uint8_t byte4 = *ptr++;
+         if ( // planes 1-3
+         (byte1 == 0xF0 && 0x90 <= byte2 && byte2 <= 0xBF && 0x80 <= byte3
+                && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
+         // planes 4-15
+                || (0xF1 <= byte1 && byte1 <= 0xF3 && 0x80 <= byte2 && byte2 <= 0xBF
+                       && 0x80 <= byte3 && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)
+                // plane 16
+                || (byte1 == 0xF4 && 0x80 <= byte2 && byte2 <= 0x8F && 0x80 <= byte3
+                       && byte3 <= 0xBF && 0x80 <= byte4 && byte4 <= 0xBF)){
+                continue;
+         }
 
-      rc = false;
-      break;
+         rc = false;
+         break;
    }
    if (trueAscii != NULL)
-      *trueAscii = rc && isAscii;
+         *trueAscii = rc && isAscii;
    return rc;
 }
 /**
@@ -224,15 +224,15 @@ void TextFinder::setSearchParameter(const QString& text, bool ignoreCase,
    m_isRegExpr = isRegExpr;
    m_ignoreBinary = ignoreBinary;
    if (!isRegExpr || text.isEmpty()){
-      delete m_regExpr;
-      m_regExpr = NULL;
+         delete m_regExpr;
+         m_regExpr = NULL;
    }else{
-      QRegularExpression::PatternOption option =
-               ignoreCase ?
-                  QRegularExpression::CaseInsensitiveOption :
-                  QRegularExpression::NoPatternOption;
-      m_ownsRegExpr = true;
-      m_regExpr = new QRegularExpression(text, option);
+         QRegularExpression::PatternOption option =
+                          ignoreCase ?
+                                 QRegularExpression::CaseInsensitiveOption :
+                                 QRegularExpression::NoPatternOption;
+         m_ownsRegExpr = true;
+         m_regExpr = new QRegularExpression(text, option);
    }
 }
 
@@ -245,7 +245,7 @@ void TextFinder::setSearchParameter(const QString& text, bool ignoreCase,
 QString TextFinder::regExprError(){
    QString rc;
    if (m_regExpr != NULL && !m_regExpr->isValid())
-      rc = m_regExpr->errorString();
+         rc = m_regExpr->errorString();
    return rc;
 }
 
index 9d0ac1d2a1030fa4fbe2fb03e4e67bda98103cd2..87ed3468236f5e4acad8419cabd2b35ca363dce3 100644 (file)
  * Constructor.
  */
 ContextHandler::ContextHandler(IntrinsicType intrinsicType, const QString& text) :
-            m_text(text),
-            m_program(),
-            m_arguments(),
-            m_directoryMode(DM_UNDEF),
-            m_fileType(FT_ALL),
-            m_intrinsicType(intrinsicType){
+                       m_text(text),
+                       m_program(),
+                       m_arguments(),
+                       m_directoryMode(DM_UNDEF),
+                       m_fileType(FT_ALL),
+                       m_intrinsicType(intrinsicType){
 }
 
 /**
  * Constructor.
  */
 ContextHandler::ContextHandler() :
-            m_text(),
-            m_program(),
-            m_arguments(),
-            m_directoryMode(DM_TO_PARENT),
-            m_fileType(FT_FILE),
-            m_intrinsicType(IT_UNDEF){
+                       m_text(),
+                       m_program(),
+                       m_arguments(),
+                       m_directoryMode(DM_TO_PARENT),
+                       m_fileType(FT_FILE),
+                       m_intrinsicType(IT_UNDEF){
 }
 
 /**
@@ -49,7 +49,7 @@ ContextHandler::IntrinsicType ContextHandler::intrinsicType() const{
  * Constructor.
  */
 ContextHandlerList::ContextHandlerList() :
-         m_list(){
+                m_list(){
 }
 
 /**
@@ -65,7 +65,7 @@ ContextHandlerList::~ContextHandlerList(){
  * @return          the instance itself
  */
 ContextHandlerList::ContextHandlerList(const ContextHandlerList& source) :
-         m_list(){
+                m_list(){
    copy(source);
 }
 
@@ -85,7 +85,7 @@ ContextHandlerList& ContextHandlerList::operator =(
  */
 void ContextHandlerList::addIntrinsics(){
    m_list.append(
-      new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy")));
+         new ContextHandler(ContextHandler::IT_COPY, QObject::tr("copy")));
 }
 
 /**
@@ -94,7 +94,7 @@ void ContextHandlerList::addIntrinsics(){
 void ContextHandlerList::clear(){
    QList <ContextHandler*>::const_iterator it;
    for (it = m_list.begin(); it != m_list.end(); ++it){
-      delete *it;
+         delete *it;
    }
    m_list.clear();
 }
@@ -109,9 +109,9 @@ ContextHandlerList& ContextHandlerList::copy(const ContextHandlerList& source){
    clear();
    QList <ContextHandler*>::const_iterator it;
    for (it = source.m_list.begin(); it != source.m_list.end(); ++it){
-      ContextHandler* handler = *it;
-      if (handler->intrinsicType() == ContextHandler::IT_UNDEF)
-         m_list.append(handler);
+         ContextHandler* handler = *it;
+         if (handler->intrinsicType() == ContextHandler::IT_UNDEF)
+                m_list.append(handler);
    }
    addIntrinsics();
    return *this;
@@ -123,16 +123,16 @@ ContextHandlerList& ContextHandlerList::copy(const ContextHandlerList& source){
  * @param storage   IN/OUT: the storage
  */
 void ContextHandlerList::save(ReStateStorage& storage){
-   QString name = "context.program";
+   const char* name = "context.program";
    QString value;
    for (int ix = 0; ix < m_list.size(); ix++){
-      ContextHandler* handler = m_list.at(ix);
-      if (handler->intrinsicType() == ContextHandler::IT_UNDEF){
-         value = handler->m_text + "\t" + handler->m_program + "\t"
-            + handler->m_arguments + "\t" + QString::number(handler->m_fileType)
-            + "\t" + QString::number(handler->m_directoryMode);
-         storage.store(name, value, ix);
-      }
+         ContextHandler* handler = m_list.at(ix);
+         if (handler->intrinsicType() == ContextHandler::IT_UNDEF){
+                value = handler->m_text + "\t" + handler->m_program + "\t"
+                       + handler->m_arguments + "\t" + QString::number(handler->m_fileType)
+                       + "\t" + QString::number(handler->m_directoryMode);
+                storage.store(name, value, ix);
+         }
    }
 }
 
@@ -141,18 +141,18 @@ ContextHandler* createHandlerIfExists(const QString& file,
    QFileInfo info(file);
    ContextHandler* handler = NULL;
    if (info.exists()){
-      handler = new ContextHandler;
-      handler->m_text = ReQStringUtil::nodeOf(file);
-      handler->m_program = file;
-      handler->m_arguments = "${full}";
+         handler = new ContextHandler;
+         handler->m_text = ReFileUtils::nodeOf(file);
+         handler->m_program = file;
+         handler->m_arguments = "${full}";
 #if defined WIN32
-      if (handler->m_text == "cmd.exe")
-      handler->m_arguments = "";
+         if (handler->m_text == "cmd.exe")
+         handler->m_arguments = "";
 #endif
-      handler->m_fileType = fileType;
-      handler->m_directoryMode =
-               fileType == ContextHandler::FT_FILE ?
-                  ContextHandler::DM_TO_PARENT : ContextHandler::DM_TO_FILE;
+         handler->m_fileType = fileType;
+         handler->m_directoryMode =
+                          fileType == ContextHandler::FT_FILE ?
+                                 ContextHandler::DM_TO_PARENT : ContextHandler::DM_TO_FILE;
    }
    return handler;
 }
@@ -163,53 +163,53 @@ ContextHandler* createHandlerIfExists(const QString& file,
  * @param storage
  */
 void ContextHandlerList::restore(ReStateStorage& storage){
-   QString name = "context.program";
+   const char* name = "context.program";
    clear();
    int ix = -1;
    QString value;
    QStringList cols;
    ContextHandler* handler;
    while (true){
-      ix++;
-      value = storage.restore(name, ix);
-      if (value.isEmpty())
-         break;
-      cols = value.split('\t');
-      if (cols.size() < 3)
-         continue;
-      handler = new ContextHandler;
-      handler->m_text = cols.at(0);
-      handler->m_program = cols.at(1);
-      handler->m_arguments = cols.at(2);
-      const char* sValue = cols.at(3).toUtf8().constData();
-      handler->m_fileType = ContextHandler::FileType(atol(sValue));
-      sValue = cols.at(4).toUtf8().constData();
-      handler->m_directoryMode = ContextHandler::DirMode(atol(sValue));
-      m_list.append(handler);
+         ix++;
+         value = storage.restore(name, ix);
+         if (value.isEmpty())
+                break;
+         cols = value.split('\t');
+         if (cols.size() < 3)
+                continue;
+         handler = new ContextHandler;
+         handler->m_text = cols.at(0);
+         handler->m_program = cols.at(1);
+         handler->m_arguments = cols.at(2);
+         const char* sValue = cols.at(3).toUtf8().constData();
+         handler->m_fileType = ContextHandler::FileType(atol(sValue));
+         sValue = cols.at(4).toUtf8().constData();
+         handler->m_directoryMode = ContextHandler::DirMode(atol(sValue));
+         m_list.append(handler);
    }
    if (m_list.size() == 0){
 #if defined __linux__
-      handler = createHandlerIfExists("/usr/bin/kate");
-      if (handler == NULL)
-      handler = createHandlerIfExists("/usr/bin/geany");
-      if (handler == NULL)
-      handler = createHandlerIfExists("/usr/bin/kwrite");
-      if (handler == NULL)
-      handler = createHandlerIfExists("/usr/bin/gedit");
-      if (handler != NULL)
-      m_list.append(handler);
-      handler = createHandlerIfExists("/usr/bin/konsole", ContextHandler::FT_DIR);
-      if (handler == NULL)
-      handler = createHandlerIfExists("/usr/bin/gnome-terminal", ContextHandler::FT_DIR);
-      if (handler != NULL)
-      m_list.append(handler);
+         handler = createHandlerIfExists("/usr/bin/kate");
+         if (handler == NULL)
+         handler = createHandlerIfExists("/usr/bin/geany");
+         if (handler == NULL)
+         handler = createHandlerIfExists("/usr/bin/kwrite");
+         if (handler == NULL)
+         handler = createHandlerIfExists("/usr/bin/gedit");
+         if (handler != NULL)
+         m_list.append(handler);
+         handler = createHandlerIfExists("/usr/bin/konsole", ContextHandler::FT_DIR);
+         if (handler == NULL)
+         handler = createHandlerIfExists("/usr/bin/gnome-terminal", ContextHandler::FT_DIR);
+         if (handler != NULL)
+         m_list.append(handler);
 #elif defined WIN32
-      handler = createHandlerIfExists("c:\\windows\\system32\\notepad.exe");
-      if (handler != NULL)
-      m_list.append(handler);
-      handler = createHandlerIfExists("c:\\windows\\system32\\cmd.exe", ContextHandler::FT_DIR);
-      if (handler != NULL)
-      m_list.append(handler);
+         handler = createHandlerIfExists("c:\\windows\\system32\\notepad.exe");
+         if (handler != NULL)
+         m_list.append(handler);
+         handler = createHandlerIfExists("c:\\windows\\system32\\cmd.exe", ContextHandler::FT_DIR);
+         if (handler != NULL)
+         m_list.append(handler);
 
 #endif
    }
index af58f82b2933ed8e9e98eb66b35a00b277d7a4ee..77709e376475731be6f71f1575b746aae0e06bef 100644 (file)
@@ -88,7 +88,7 @@ void FileCommander::buildFs(const QString& url, ReFileSystem& filesystem)
        if (url.startsWith("file:", Qt::CaseInsensitive)){
 
        } else {
-               m_main->setStatusMessage(true, QObject::tr("unknown protocol in url: ") + url);
+               m_main->say(LOG_ERROR, QObject::tr("unknown protocol in url: ") + url);
        }
 }
 
index 4067d3b93e76ac64128e4310388b0734a0710e26..b36c4813ee8e879893b5a6daadfb5091d6951e33 100644 (file)
@@ -69,11 +69,15 @@ void IDosMain::initializeHome(){
 /**
  * Writes a text to the status line.
  *
- * @param error     <code>true</code>: the message is an error message
+ * @param level     the type of the message, e.g. LOG_ERROR
  * @param message   the text to set
+ * @return                     <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+ *                                     <code>true</code>: level == LOG_INFO
  */
-void IDosMain::setStatusMessage(bool error, const QString& message){
-       m_statusMessage->setText(error ? "+++ " + message : message);
+bool IDosMain::say(ReLoggerLevel level, const QString& message){
+       bool rc = level == LOG_INFO;
+       m_statusMessage->setText(! rc ? "+++ " + message : message);
+       return rc;
 }
 
 /**
index 37739d480319202d368b17cf2979ba94ed689b9e..6fc4ff55e549d5760cdd3d4c7897c12a0df50e56 100644 (file)
@@ -27,7 +27,7 @@ public:
 
 public:
        void error(const QString& message);
-       virtual void setStatusMessage(bool error, const QString& message);
+       virtual bool say(ReLoggerLevel level, const QString& message);
 protected:
        void initializeHome();
        void restoreState();
index d5e0476349f33fc634944421df60ff00eb243c19..dc4909444620c9ba48bbb6bf548795d3ed520241 100644 (file)
@@ -121,7 +121,7 @@ bool ReFileUtils::deleteTree(const QString& path, bool withBase,
        if (withBase && (rmdir(path.toUtf8())) != 0) {
                rc = false;
                logger->logv(LOG_ERROR, LOC_DELETE_TREE_3,
-            "cannot delete directory (%d): %s", errno, path.toUtf8().constData());
+                       "cannot delete directory (%d): %s", errno, path.toUtf8().constData());
        }
        return rc;
 }
@@ -269,6 +269,31 @@ QByteArray ReFileUtils::nodeOf(const char* filename) {
        return rc;
 }
 
+/**
+ * Extracts the path of a full filename.
+ *
+ * @param filename  the filename (with or without path)
+ * @return          "": no path available<br>
+ *                                     "/": filename = "/"<br>
+ *                                     otherwise: the path of <code>filename</code> including
+ *                                     trailing separator
+ */
+QString ReFileUtils::parentOf(const QString& filename) {
+       QString rc;
+
+       int ix = filename.size() - 1;
+       while (ix >= 0) {
+               if (filename[ix] == '/' || filename[ix] == '\\') {
+                       rc = filename.mid(ix + 1);
+                       break;
+               }
+               ix--;
+       }
+       if (ix >= 0)
+               rc = filename.mid(0, ix + 1);
+       return rc;
+}
+
 /** Normalizes a file path.
  *
  * Removes duplicated slashes and "." and "..", but not leading ".."
index 3b276363b0b01d4cc10164768840394a376d60fd..8fa57c4c84cba1f082690458f2016876727832c5 100644 (file)
@@ -29,7 +29,7 @@ public:
 class ReFileUtils {
 public:
        static bool deleteTree(const QString& path, bool withBase,
-           ReLogger* logger);
+               ReLogger* logger);
        static QByteArray cleanPath(const char* path);
        static QString extensionOf(const QString& filename);
        static QByteArray extensionOf(const char* filename);
@@ -37,6 +37,7 @@ public:
        static bool isAbsolutPath(const char* path);
        static QString nodeOf(const QString& filename);
        static QByteArray nodeOf(const char* filename);
+       static QString parentOf(const QString& filename);
        static QString pathAppend(const QString& base, const QString& path);
        static QByteArray pathAppend(const char* base, const char* path);
        static QByteArray& readFromFile(const char* filename, QByteArray& buffer);
@@ -44,16 +45,16 @@ public:
        static QByteArray replaceExtension(const char* path, const char* ext);
        static int seek(FILE* file, int64_t offset, int whence);
        static bool setTimes(const char* filename, const QDateTime& modified,
-           const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
+               const QDateTime& accessed = m_undefinedTime, ReLogger* logger = NULL);
        static int64_t tell(FILE* file);
        static QByteArray tempDir(const char* node, const char* parent = NULL,
-           bool withSeparator = true);
+               bool withSeparator = true);
        static QByteArray tempDirEmpty(const char* node, const char* parent = NULL,
-           bool withSeparator = true);
+               bool withSeparator = true);
        static QByteArray tempFile(const char* node, const char* parent = NULL,
-           bool deleteIfExists = true);
+               bool deleteIfExists = true);
        static void writeToFile(const char* filename, const char* content,
-           size_t contentLength = (size_t) - 1, const char* mode = "w");
+               size_t contentLength = (size_t) - 1, const char* mode = "w");
 public:
        static QDateTime m_undefinedTime;
 };
index 234bc6563ce292b14b7769691bf1583ccd817977..eb1885518d648801e773b52c517eec342c515704 100644 (file)
@@ -681,3 +681,4 @@ ReMemoryLogger::ReMemoryLogger() :
 {
        addAppender(this);
 }
+
index c8b24fe07013cece0415c56e7feaa3a4f56e59cd..9c5035927de3024221467b4fcff94cd4b3ac49de 100644 (file)
@@ -16,6 +16,7 @@
  */
 class ReLogger;
 class ReConfig;
+
 /**
  * @brief Logging level: for controlling of the logging.
  *
@@ -30,6 +31,25 @@ enum ReLoggerLevel {
        LOG_DEBUG = 25          ///< for debug purpose only
 };
 
+/**
+ * Very poor logger normally used for GUI programs with status line.
+ *
+ * This is a pure abstract class: implementation of the method say() is needed.
+ */
+class ReAnnouncer{
+public:
+       /**
+        * Issues a message.
+        *
+        * @param level         type of the message, e.g. LOG_INFO or LOG_ERROR
+        * @param message       the message to issue. Use QString::arg() to format,
+        *                                      e.g. <code>say(QString("name: %1 no: %2).arg(name).arg(no)</code>
+        * @return                      <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+        *                                      <code>true</code>: level >= LOG_INFO
+        */
+       virtual bool say(ReLoggerLevel level, const QString& message) = 0;
+};
+
 class ReAppender {
 public:
        ReAppender(const QByteArray& name);
index a0eedbbae269ff06b58f07d5465ca26c21250a07..6f0e1cb6babc438b0861859e7a61c5475f1646ef 100644 (file)
@@ -20,8 +20,6 @@ public:
        static ReString chomp(const ReString& text);
        static int countOf(const QString& value, QChar toFind, int start = 0);
        static QString& ensureLastChar(QString& value, QChar lastChar);
-       static QString extensionOf(const QString& filename);
-       static QByteArray extensionOf(const char* filename);
        static int lengthOfDate(const ReString& text, int start = 0, QDate* value =
                NULL);
        static int lengthOfDateTime(const ReString& text, int start = 0,
index e10cde4a578b2366d50877576fb7cd75cef63b46..67cf3153868dbcc20e0a498847848a9787707285 100644 (file)
@@ -345,7 +345,8 @@ protected:
        void drawScrollbars(QPainter& painter, const QRect& rect,
                double sizeVertical, double posVertical, double sizeHorizontal,
                double posHorizontal);
-       void ensureCursorVisible();protected slots:
+       void ensureCursorVisible();
+protected slots:
        void keyPressEvent(QKeyEvent* event);
        void paintEvent(QPaintEvent *);
        void mouseMoveEvent(QMouseEvent* event);
index d09a6e11eac6c1a8819540e27b3bf256008ae2f0..608cf831c33fa05fe6f46d22ed8673e4bebc3492 100644 (file)
@@ -125,7 +125,7 @@ QString ReGuiValidator::comboText(QComboBox* combo) {
 void ReGuiValidator::guiError(QWidget* widget, const QString& message) {
        if (widget != NULL)
                widget->setFocus(Qt::OtherFocusReason);
-       setStatusMessage(true, message);
+       say(LOG_ERROR, message);
        m_errors++;
 }
 
index 60465a6c1cde670f310637844468c0ad23e93530..c044b362a70d1678999cb2a7e2484be7aa4ea498 100644 (file)
 #include <QComboBox>
 #include <QStatusBar>
 
-class ReGuiValidator {
+class ReGuiValidator : public ReAnnouncer {
 public:
        ReGuiValidator();
        ~ReGuiValidator();
 public:
        QDateTime comboDate(QComboBox* combo);
        int comboInt(QComboBox* combo, int defaultValue, const char* specialString =
-           NULL, int specialValue = 0);
+               NULL, int specialValue = 0);
        int64_t comboSize(QComboBox* combo);
        QString comboText(QComboBox* combo);
        virtual void guiError(QWidget* widget, const QString& message);
        void setInHistory(QComboBox* combo, const QString& value);
-       virtual void setStatusMessage(bool error, const QString& message) = 0;
 
 protected:
        int m_errors;
index 7b78e3ef3a66d828605340f23280f3717654ea2e..c616776151f1572d7de0b5ffcf8c757ad21f6df4 100644 (file)
@@ -21,7 +21,8 @@ ReFileTable::ReFileTable(QWidget *parent) :
        tableWidget(new QTableWidget(this)),
        fileSystem(NULL),
        matcher("*"),
-       m_dateFormat("yyyy.MM.dd hh:mm:ss")
+       m_dateFormat("yyyy.MM.dd hh:mm:ss"),
+       announcer(NULL)
 {
        setLayout(mainLayout);
        mainLayout->setSpacing(0);
@@ -48,10 +49,12 @@ ReFileTable::ReFileTable(QWidget *parent) :
        tableWidget->setColumnWidth(TYPE, 60);
        tableWidget->setColumnWidth(SIZE, 125);
        tableWidget->setColumnWidth(MODIFIED, 175);
-       connect(this, SIGNAL(keyPress(QKeyEvent*)), SLOT(keyPressEvent(QKeyEvent*)));
+       connect(pushButtonUp, SIGNAL(clicked()), SLOT(pushButtonUpClicked()));
+       connect(pushButtonRoot, SIGNAL(clicked()), SLOT(pushButtonRootClicked()));
 
        tableWidget->setHorizontalHeaderLabels(labels);
        tableWidget->horizontalHeader()->setStretchLastSection(true);
+       tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
 }
 
 /**
@@ -76,16 +79,23 @@ void ReFileTable::fillTable()
                tableWidget->setRowCount(list.length());
                int row = 0;
                for (it = list.cbegin(); it != list.cend(); ++it){
-                       // TC_EXT, TC_SIZE, TC_MODIFIED, TC_NODE
+                       bool isDir = S_ISDIR(it->m_mode);
                        QString modified = it->m_modified.toString(m_dateFormat);
-                       QString size = QString::number(it->m_size);
-                       QString ext = ReFileUtils::extensionOf(it->m_node);
+                       QString size = isDir ? ReQStringUtils::m_empty : QString::number(it->m_size);
+                       QString ext = isDir ? tr("<dir>") : ReFileUtils::extensionOf(it->m_node);
                        if (tableWidget->item(row, 0) == NULL){
-                               tableWidget->setItem(row, NAME, new QTableWidgetItem(it->m_node));
-                               tableWidget->setItem(row, MODIFIED, new QTableWidgetItem(modified));
-                               tableWidget->setItem(row, TYPE, new QTableWidgetItem(ext));
-                               QTableWidgetItem* item = new QTableWidgetItem(size);
-                               item->setTextAlignment(Qt::AlignRight);
+                               QTableWidgetItem* item = new QTableWidgetItem(it->m_node);
+                               item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+                               tableWidget->setItem(row, NAME, item);
+                               item = new QTableWidgetItem(modified);
+                               item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+                               tableWidget->setItem(row, MODIFIED, item);
+                               item = new QTableWidgetItem(ext);
+                               item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+                               tableWidget->setItem(row, TYPE, item);
+                               item = new QTableWidgetItem(size);
+                               item->setFlags(item->flags() ^ Qt::ItemIsEditable);
+                               item->setTextAlignment(Qt::AlignRight | Qt::AlignVCenter);
                                tableWidget->setItem(row, SIZE, item);
                        } else {
                                tableWidget->item(row, NAME)->setText(it->m_node);
@@ -98,21 +108,78 @@ void ReFileTable::fillTable()
        }
 }
 
+/**
+ * Changes the current directory.
+ *
+ * @param directory    full path of the new directory
+ */
+void ReFileTable::chDir(const QString& directory){
+       if (directory != fileSystem->directory()){
+               if (directory.indexOf('*') < 0){
+                       if (fileSystem->setDirectory(directory) != ReFileSystem::EC_SUCCESS){
+                               say(LOG_ERROR, tr("unknown directory:") + " " + directory);
+                       } else {
+                               comboBoxPath->setCurrentText(directory);
+                               // update the history:
+                               comboText(comboBoxPath);
+                               fillTable();
+                       }
+               } else {
+
+               }
+       }
+}
+
 /**
  * Handles the key press event.
  *
- * @param event
+ * @param event        event data
  */
-void ReFileTable::keyPress(QKeyEvent* event){
-       if (event->key() == Qt::Key_Return){
-               /*
-               if (changeDirectory(box->currentText())){
-                       comboText(box);
-                       fillTable(m_topIsActive ? ui->tableWidgetTop : ui->tableWidgetTop);
+void ReFileTable::keyPressEvent(QKeyEvent* event){
+       Qt::KeyboardModifiers modifiers = event->modifiers();
+       QWidget* sender = QApplication::focusWidget();
+       int key = event->key();
+       if (sender == comboBoxPath){
+               if (key == Qt::Key_Return){
+                       if (modifiers == Qt::NoModifier)
+                               chDir(comboBoxPath->currentText());
                }
-               */
+       } else if (sender == comboBoxPatterns){
+
+       } else if (sender == tableWidget){
+
        }
 
 }
+/**
+ * Handles the event push button "up" clicked()
+ */
+void ReFileTable::pushButtonUpClicked()
+{
+       chDir(ReFileUtils::parentOf(comboBoxPath->currentText()));
+}
+
+/**
+ * Handles the event push button "root" clicked()
+ */
+void ReFileTable::pushButtonRootClicked()
+{
+       chDir("/");
+}
+
+/**
+ * Handles user messages including errors/warnings.
+ *
+ * @param level                type of the message: LOG_ERROR...
+ * @param message      message for the user
+ * @return                     <code>false</code>: level == LOG_ERROR or LOG_WARNING<br>
+ *                                     <code>true</code>: level >= LOG_INFO
+ */
+bool ReFileTable::say(ReLoggerLevel level, const QString& message)
+{
+       if (announcer != NULL)
+               announcer->say(level, message);
+       return level >= LOG_INFO;
+}
 
 
index 94e4f644b2336cc006804ccfada05e128d40123a..150749b13f2fc8ad6d311f25deff54b62dcce853 100644 (file)
@@ -12,7 +12,7 @@
 // needed for moc_ReFileTable.cpp
 #include "guiwidget/reguiwidget.hpp"
 #endif
-class ReFileTable : public QWidget
+class ReFileTable : public QWidget, public ReGuiValidator
 {
 public:
        enum { TYPE, MODIFIED, SIZE, NAME, COL_COUNT };
@@ -26,12 +26,16 @@ public slots:
 
 public:
        void fillTable();
-       void keyPress(QKeyEvent* event);
-
+       void chDir(const QString& directory);
+protected slots:
+       void keyPressEvent(QKeyEvent* event);
+       void pushButtonUpClicked();
+       void pushButtonRootClicked();
 protected:
        QVBoxLayout* mainLayout;
        QHBoxLayout* horizontalLayout;
        QString m_dateFormat;
+       virtual bool say(ReLoggerLevel level, const QString& message);
 public:
        QComboBox* comboBoxPath;
        QComboBox* comboBoxPatterns;
@@ -41,6 +45,7 @@ public:
        QTableWidget* tableWidget;
        ReFileSystem* fileSystem;
        ReIncludeExcludeMatcher matcher;
+       ReAnnouncer* announcer;
 };
 
 #endif // REFILETABLE_HPP
index b5291dbd5a03142e95f2d96d7678ca9b8034f4f0..1c927f5cf3d58af22349b0efe9c3144d3c839e2e 100644 (file)
@@ -26,6 +26,7 @@
 #include "QTableWidget"
 #include "QHeaderView"
 #include "QKeyEvent"
+#include "QApplication"
 #include "guiwidget/ReFileTable.hpp"
 #endif // REGUIWIDGET_HPP
 
index e6014915887c371e3202d59b8c894bf9d1186685..bff8b785cd9fdeb36790eee5146c1d9316717d3f 100644 (file)
@@ -279,14 +279,17 @@ ReFileSystem::ErrorCode ReLocalFileSystem::makeDir(const QString& node) {
  */
 ReFileSystem::ErrorCode ReLocalFileSystem::setDirectory(const QString& path) {
        ErrorCode rc;
-       if (ReFileUtils::isAbsolutPath(path))
-               rc = m_dir.setCurrent(path) ? EC_SUCCESS : EC_PATH_NOT_FOUND;
-       else
+       if (ReFileUtils::isAbsolutPath(path)){
+               m_dir.setPath(path);
+               rc = m_dir.exists() ? EC_SUCCESS : EC_PATH_NOT_FOUND;
+       } else
                rc = m_dir.setCurrent(ReFileUtils::pathAppend(
                        m_dir.absolutePath(), path))
                                ? EC_SUCCESS : EC_PATH_NOT_FOUND;
-       m_directory = m_dir.absolutePath();
-       ReQStringUtils::ensureLastChar(m_directory, OS_SEPARATOR);
+       if (rc == EC_SUCCESS){
+               m_directory = m_dir.absolutePath();
+               ReQStringUtils::ensureLastChar(m_directory, OS_SEPARATOR);
+       }
        return rc;
 }