]> gitweb.hamatoma.de Git - reqt/commitdiff
Export works
authorhama <hama@siduction.net>
Sat, 25 Apr 2015 01:34:17 +0000 (03:34 +0200)
committerhama <hama@siduction.net>
Sat, 25 Apr 2015 01:34:17 +0000 (03:34 +0200)
appl/refind/icons/cog_edit.png [new file with mode: 0644]
appl/refind/icons/database_save.png [new file with mode: 0644]
appl/refind/icons/disk.png [new file with mode: 0644]
appl/refind/mainwindow.cpp
appl/refind/mainwindow.hpp
appl/refind/mainwindow.ui
appl/refind/refind.qrc
base/ReException.cpp
base/ReException.hpp

diff --git a/appl/refind/icons/cog_edit.png b/appl/refind/icons/cog_edit.png
new file mode 100644 (file)
index 0000000..47b75a4
Binary files /dev/null and b/appl/refind/icons/cog_edit.png differ
diff --git a/appl/refind/icons/database_save.png b/appl/refind/icons/database_save.png
new file mode 100644 (file)
index 0000000..44c06dd
Binary files /dev/null and b/appl/refind/icons/database_save.png differ
diff --git a/appl/refind/icons/disk.png b/appl/refind/icons/disk.png
new file mode 100644 (file)
index 0000000..99d532e
Binary files /dev/null and b/appl/refind/icons/disk.png differ
index f21da77a402521e2371f08df54531d080014ee18..2ca36ff5a628f2ed09f73f22c4196c40b59ad728 100644 (file)
@@ -58,6 +58,11 @@ MainWindow::MainWindow(const QString& startDir, QWidget *parent) :
       SLOT(fullNameToClipboard()));
    connect(ui->actionReset, SIGNAL(triggered()), this, SLOT(resetParameters()));
    connect(ui->tableWidget, SIGNAL(cellClicked(int,int)), this, SLOT(cellEntered(int, int)));
+   connect(ui->actionExport, SIGNAL(triggered()), this, SLOT(exportFiles()));
+   connect(ui->pushButtonExport, SIGNAL(clicked()), this, SLOT(exportFiles()));
+   connect(ui->pushButtonExportFile, SIGNAL(clicked()), this,
+      SLOT(selectExportFile()));
+
    m_horizontalHeader = ui->tableWidget->horizontalHeader();
    connect(m_horizontalHeader, SIGNAL(sectionClicked ( int ) ),
             this, SLOT(headerClicked ( int ) ));
@@ -83,6 +88,12 @@ void MainWindow::headerClicked(int col){
    m_horizontalHeader->setSortIndicator(col, m_lastOrder);
 }
 
+void MainWindow::preview(){
+   QString value;
+   QTextStream stream(&value);
+   exportToStream(stream, 1);
+}
+
 /**
  * @brief Destructor.
  */
@@ -131,6 +142,127 @@ void MainWindow::baseDirToClipboard(){
    clipboard->setText(m_lastBaseDir.absolutePath());
 }
 
+/**
+ * Replaces the esc sequences like '\n'.
+ *
+ * @param text  the text to convert
+ * @return      <code>text</code> with the esc sequences replaced
+ */
+QString replaceEscSequences(const QString& text){
+   QString rc = text;
+   int start = 0;
+   QString replacement;
+   while (start < rc.length()){
+      start = text.indexOf('\\', start);
+      if (start < 0)
+         break;
+      QChar replacement = 0;
+      switch (text[start + 1].toLatin1()) {
+      case 'n':
+         replacement = '\n';
+         break;
+      case 't':
+         replacement = '\t';
+         break;
+      case 'r':
+         replacement = '\r';
+         break;
+      default:
+         replacement = text[start + 1];
+         break;
+      }
+      rc.remove(start, 1);
+      rc[start] = replacement;
+      start++;
+   }
+   return rc;
+}
+
+/**
+ * Exports the found files into a stream with header and footer.
+ *
+ * @param stream    OUT: the stream for the export
+ * @param maxRow    -1 or the maximum row to export
+ */
+void MainWindow::exportToStream(QTextStream& stream, int maxRow){
+   if (!ui->comboBoxHeader->currentText().isEmpty()){
+      stream << replaceEscSequences(ui->comboBoxHeader->currentText()) << endl;
+   }
+   int count = ui->tabWidget->count();
+   if (count > 0 && maxRow > 0)
+      count = maxRow;
+   for (int ii = 0; ii < count; ii++){
+      QString line = ui->comboBoxTemplate->currentText();
+      int start = 0;
+      QString replacement;
+      QString name;
+      while (start >= 0){
+         start = line.indexOf("${", start);
+         if (start < 0)
+            break;
+         int end = line.indexOf('}', start + 1);
+         if (end < 0)
+            break;
+         name = line.mid(start + 2, end - start - 2);
+         if (name == "full"){
+            QString path = ui->tableWidget->item(ii, TC_PATH)->text();
+            if (path.isEmpty())
+               path = ui->tableWidget->item(ii, TC_NODE)->text();
+            else
+               path += ui->tableWidget->item(ii, TC_NODE)->text();
+            replacement = m_lastBaseDir.absoluteFilePath(path);
+         }else if (name == "path")
+            replacement = ui->tableWidget->item(ii, TC_PATH)->text();
+         else if (name == "ext")
+            replacement = ui->tableWidget->item(ii, TC_EXT)->text();
+         else if (name == "node")
+            replacement = ui->tableWidget->item(ii, TC_NODE)->text();
+         else if (name == "modified")
+            replacement = ui->tableWidget->item(ii, TC_MODIFIED)->text();
+         else if (name == "size")
+            replacement = ui->tableWidget->item(ii, TC_SIZE)->text();
+         else{
+            throw ReQException(tr("unknown placeholder: ") + name);
+         }
+         line = line.replace("${" + name + "}", replacement);
+         start += replacement.length();
+      }
+      stream << replaceEscSequences(line) << endl;
+   }
+   if (!ui->comboBoxFooter->currentText().isEmpty()){
+      stream << replaceEscSequences(ui->comboBoxFooter->currentText()) << endl;
+   }
+}
+
+/**
+ * Handles the click of the "export" button.
+ */
+void MainWindow::exportFiles(){
+   comboText(ui->comboBoxHeader);
+   comboText(ui->comboBoxTemplate);
+   comboText(ui->comboBoxExportFile);
+   comboText(ui->comboBoxFooter);
+   if (ui->radioButtonFile->isChecked()){
+      QString fn = ui->comboBoxExportFile->currentText();
+      FILE* fp = fopen(fn.toUtf8(), "w");
+      if (fp == NULL)
+         guiError(ui->comboBoxExportFile, tr("not a valid file: ") + fn);
+      else{
+         QTextStream stream(fp);
+         exportToStream(stream);
+         fclose(fp);
+         setStatusMessage(false, tr("result exported to ") + fn);
+      }
+   }else{
+      QString value;
+      QTextStream stream(&value);
+      exportToStream(stream);
+      QClipboard* clipboard = QApplication::clipboard();
+      clipboard->setText(value);
+      setStatusMessage(false, tr("result exported to the clipboard"));
+   }
+}
+
 /**
  * Gets the content of the given cell as string.
  *
@@ -286,6 +418,17 @@ void MainWindow::selectDirectory(){
       ui->comboBoxDirectory->setCurrentText(dir);
 }
 
+/**
+ * Calls the file selection dialog.
+ */
+void MainWindow::selectExportFile(){
+   QString name = QFileDialog::getOpenFileName(this, tr("Select Export File"),
+      ui->comboBoxExportFile->currentText());
+   if (!name.isEmpty())
+      ui->comboBoxExportFile->setCurrentText(name);
+
+}
+
 /**
  * Writes a text to the status line.
  *
index 6f0df8834f10a2629e8cbd6d1ed5ffd560dc3518..6f2fff5bb5a0af9376716c762f01bf2087c35cbb 100644 (file)
@@ -44,11 +44,14 @@ private slots:
    void about();
    void absPathToClipboard();
    void baseDirToClipboard();
+   void exportFiles();
    void fullNameToClipboard();
    void headerClicked(int col);
+   void preview();
    void resetParameters();
    void search();
    void selectDirectory();
+   void selectExportFile();
    void up();
 
 private:
@@ -57,6 +60,7 @@ private:
    QString cellAsText(int row, int col);
    void prepareTextFind();
    virtual void setStatusMessage(bool error, const QString& message);
+   void exportToStream(QTextStream& stream, int maxRow = -1);
 private:
    Ui::MainWindow *ui;
    QLabel* m_statusMessage;
index 86f22c47c5445d9339ced3f16a98caf4b467c9b4..6355f211e388ad7e578e7865c88769250e623e53 100644 (file)
@@ -17,6 +17,9 @@
    <layout class="QVBoxLayout" name="verticalLayout_3">
     <item>
      <layout class="QVBoxLayout" name="verticalLayout_2">
+      <item>
+       <layout class="QVBoxLayout" name="verticalLayout"/>
+      </item>
       <item>
        <widget class="QTabWidget" name="tabWidget">
         <property name="sizePolicy">
@@ -36,7 +39,7 @@
         </property>
         <widget class="QWidget" name="tabMain">
          <attribute name="title">
-          <string>Directory, File Patterns, Text Pattern</string>
+          <string>&amp;Directory, File Patterns, Text Pattern</string>
          </attribute>
          <layout class="QHBoxLayout" name="horizontalLayout_4">
           <item>
           </item>
          </layout>
         </widget>
-        <widget class="QWidget" name="tab_2">
+        <widget class="QWidget" name="tabDateSize">
          <attribute name="title">
-          <string>Size, Date, Depth, Excluded Dirs</string>
+          <string>&amp;Size, Date, Depth, Excluded Dirs</string>
          </attribute>
          <widget class="QWidget" name="layoutWidget">
           <property name="geometry">
           </layout>
          </widget>
         </widget>
+        <widget class="QWidget" name="tabExport">
+         <attribute name="title">
+          <string>&amp;Export</string>
+         </attribute>
+         <widget class="QLabel" name="label_14">
+          <property name="geometry">
+           <rect>
+            <x>515</x>
+            <y>106</y>
+            <width>85</width>
+            <height>29</height>
+           </rect>
+          </property>
+          <property name="text">
+           <string/>
+          </property>
+         </widget>
+         <widget class="QWidget" name="">
+          <property name="geometry">
+           <rect>
+            <x>10</x>
+            <y>11</y>
+            <width>981</width>
+            <height>101</height>
+           </rect>
+          </property>
+          <layout class="QGridLayout" name="gridLayout_3">
+           <item row="1" column="0">
+            <widget class="QLabel" name="label_9">
+             <property name="text">
+              <string>Export file:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="0" column="1">
+            <layout class="QHBoxLayout" name="horizontalLayout_7">
+             <item>
+              <widget class="QComboBox" name="comboBoxTemplate">
+               <property name="editable">
+                <bool>true</bool>
+               </property>
+               <property name="currentText">
+                <string notr="true">${full};${size};${modified}</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QPushButton" name="pushButtonPlaceholder">
+               <property name="maximumSize">
+                <size>
+                 <width>50</width>
+                 <height>16777215</height>
+                </size>
+               </property>
+               <property name="toolTip">
+                <string>Placeholder for the template</string>
+               </property>
+               <property name="text">
+                <string>...</string>
+               </property>
+              </widget>
+             </item>
+            </layout>
+           </item>
+           <item row="2" column="1">
+            <layout class="QHBoxLayout" name="horizontalLayout_8">
+             <item>
+              <widget class="QRadioButton" name="radioButtonFile">
+               <property name="text">
+                <string>&amp;File</string>
+               </property>
+               <property name="checked">
+                <bool>false</bool>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QRadioButton" name="radioButtonClipboard">
+               <property name="text">
+                <string>Clipboard</string>
+               </property>
+               <property name="checked">
+                <bool>true</bool>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <spacer name="horizontalSpacer">
+               <property name="orientation">
+                <enum>Qt::Horizontal</enum>
+               </property>
+               <property name="sizeHint" stdset="0">
+                <size>
+                 <width>40</width>
+                 <height>20</height>
+                </size>
+               </property>
+              </spacer>
+             </item>
+            </layout>
+           </item>
+           <item row="1" column="1">
+            <layout class="QHBoxLayout" name="horizontalLayout_6">
+             <item>
+              <widget class="QComboBox" name="comboBoxExportFile">
+               <property name="editable">
+                <bool>true</bool>
+               </property>
+               <property name="currentText">
+                <string>refind.result.txt</string>
+               </property>
+              </widget>
+             </item>
+             <item>
+              <widget class="QPushButton" name="pushButtonExportFile">
+               <property name="maximumSize">
+                <size>
+                 <width>50</width>
+                 <height>16777215</height>
+                </size>
+               </property>
+               <property name="toolTip">
+                <string>Select the export file</string>
+               </property>
+               <property name="text">
+                <string>...</string>
+               </property>
+              </widget>
+             </item>
+            </layout>
+           </item>
+           <item row="2" column="3">
+            <widget class="QPushButton" name="pushButtonExport">
+             <property name="toolTip">
+              <string>Exports file attributes (specified in the template line)  of each found files  found file in a textfile or clipboard</string>
+             </property>
+             <property name="text">
+              <string>&amp;Export</string>
+             </property>
+             <property name="icon">
+              <iconset resource="refind.qrc">
+               <normaloff>:/main/icons/database_save.png</normaloff>:/main/icons/database_save.png</iconset>
+             </property>
+             <property name="shortcut">
+              <string>Alt+E</string>
+             </property>
+            </widget>
+           </item>
+           <item row="1" column="2">
+            <widget class="QLabel" name="label_15">
+             <property name="text">
+              <string>File footer:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="0" column="0">
+            <widget class="QLabel" name="label_8">
+             <property name="text">
+              <string>Line template:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="0" column="2">
+            <widget class="QLabel" name="label_10">
+             <property name="text">
+              <string>File header:</string>
+             </property>
+            </widget>
+           </item>
+           <item row="0" column="3">
+            <widget class="QComboBox" name="comboBoxHeader">
+             <property name="minimumSize">
+              <size>
+               <width>300</width>
+               <height>0</height>
+              </size>
+             </property>
+             <property name="maximumSize">
+              <size>
+               <width>300</width>
+               <height>16777215</height>
+              </size>
+             </property>
+             <property name="toolTip">
+              <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Text at the top of the export file.&lt;/p&gt;&lt;p&gt;Placeholders:&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;li&gt;\n newline&lt;/li
+&lt;li&gt;\t tabulator&lt;/li&gt;
+&lt;li&gt;\\ slash&lt;/li&gt;
+&lt;/ul&gt;&lt;/p&gt;
+&lt;/body&gt;&lt;/html&gt;</string>
+             </property>
+             <property name="editable">
+              <bool>true</bool>
+             </property>
+            </widget>
+           </item>
+           <item row="1" column="3">
+            <widget class="QComboBox" name="comboBoxFooter">
+             <property name="toolTip">
+              <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;Text at the top of the export file.&lt;/p&gt;&lt;p&gt;Placeholders:&lt;/p&gt;&lt;p&gt;&lt;u&gt;&lt;li&gt;\n newline&lt;/li
+&lt;li&gt;\t tabulator&lt;/li&gt;
+&lt;li&gt;\\ slash&lt;/li&gt;
+&lt;/ul&gt;&lt;/p&gt;
+&lt;/body&gt;&lt;/html&gt;</string>
+             </property>
+             <property name="editable">
+              <bool>true</bool>
+             </property>
+            </widget>
+           </item>
+          </layout>
+         </widget>
+        </widget>
        </widget>
       </item>
-      <item>
-       <layout class="QVBoxLayout" name="verticalLayout"/>
-      </item>
       <item>
        <widget class="QTableWidget" name="tableWidget">
         <column>
    <attribute name="toolBarBreak">
     <bool>false</bool>
    </attribute>
+   <addaction name="actionExport"/>
    <addaction name="actionExit"/>
   </widget>
   <action name="actionExit">
    </property>
   </action>
   <action name="actionExport">
+   <property name="icon">
+    <iconset resource="refind.qrc">
+     <normaloff>:/main/icons/database_save.png</normaloff>:/main/icons/database_save.png</iconset>
+   </property>
    <property name="text">
     <string>&amp;Export</string>
    </property>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <tabstops>
-  <tabstop>tabWidget</tabstop>
   <tabstop>comboBoxDirectory</tabstop>
   <tabstop>pushButtonUp</tabstop>
   <tabstop>pushButtonDirectory</tabstop>
index 05e91c4cb69004e5aaf361e02251a8863794215d..7c6cce90851acd0440e11c5fb3fcaf46a32e2f26 100644 (file)
@@ -15,5 +15,8 @@
         <file>icons/folder_magnify.png</file>
         <file>icons/folder.png</file>
         <file>icons/wand.png</file>
+        <file>icons/cog_edit.png</file>
+        <file>icons/database_save.png</file>
+        <file>icons/disk.png</file>
     </qresource>
 </RCC>
index 024acbd8a79220d49181de56708da7c16168a1e9..6476de5526b88924d7c5825f18818733889211d6 100644 (file)
@@ -214,3 +214,28 @@ ReNotImplementedException::ReNotImplementedException(const char* message) :
    ReLogger::globalLogger()->log(LOG_ERROR, LOC_NOT_IMPLEMENTED_1,
       getMessage());
 }
+
+/**
+ * Constructor.
+ *
+ * @param message   the description of the exception
+ */
+ReQException::ReQException(const QString message) :
+         m_message(message){
+}
+
+/**
+ * Destructor.
+ */
+ReQException::~ReQException(){
+
+}
+/**
+ * Returns the message.
+ *
+ * @return the description of the exception
+ */
+QString ReQException::message() const{
+   return m_message;
+}
+
index 03d3909e847b8e7ead4a9e12288fd45243bf594e..03782d8f9725c5fb59cb14bf6e3c2e801d5e0757 100644 (file)
@@ -51,4 +51,15 @@ public:
    ReNotImplementedException(const char* message);
 };
 
+class ReQException {
+public:
+   ReQException(const QString message);
+   ~ReQException();
+public:
+   QString message() const;
+
+protected:
+   QString m_message;
+};
+
 #endif // REEXCEPTION_HPP