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 ) ));
m_horizontalHeader->setSortIndicator(col, m_lastOrder);
}
+void MainWindow::preview(){
+ QString value;
+ QTextStream stream(&value);
+ exportToStream(stream, 1);
+}
+
/**
* @brief Destructor.
*/
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.
*
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.
*
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:
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;
<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">
</property>
<widget class="QWidget" name="tabMain">
<attribute name="title">
- <string>Directory, File Patterns, Text Pattern</string>
+ <string>&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>&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>&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>&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>&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><html><head/><body><p>Text at the top of the export file.</p><p>Placeholders:</p><p><u><li>\n newline</li
+<li>\t tabulator</li>
+<li>\\ slash</li>
+</ul></p>
+</body></html></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><html><head/><body><p>Text at the top of the export file.</p><p>Placeholders:</p><p><u><li>\n newline</li
+<li>\t tabulator</li>
+<li>\\ slash</li>
+</ul></p>
+</body></html></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>&Export</string>
</property>
</widget>
<layoutdefault spacing="6" margin="11"/>
<tabstops>
- <tabstop>tabWidget</tabstop>
<tabstop>comboBoxDirectory</tabstop>
<tabstop>pushButtonUp</tabstop>
<tabstop>pushButtonDirectory</tabstop>
<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>
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;
+}
+
ReNotImplementedException(const char* message);
};
+class ReQException {
+public:
+ ReQException(const QString message);
+ ~ReQException();
+public:
+ QString message() const;
+
+protected:
+ QString m_message;
+};
+
#endif // REEXCEPTION_HPP