From 1c9e93d9ec0623bc54cdad6ee19f4c63d2ee59ef Mon Sep 17 00:00:00 2001 From: hama Date: Sat, 25 Apr 2015 03:34:17 +0200 Subject: [PATCH] Export works --- appl/refind/icons/cog_edit.png | Bin 0 -> 865 bytes appl/refind/icons/database_save.png | Bin 0 -> 755 bytes appl/refind/icons/disk.png | Bin 0 -> 620 bytes appl/refind/mainwindow.cpp | 143 +++++++++++++++++ appl/refind/mainwindow.hpp | 4 + appl/refind/mainwindow.ui | 230 +++++++++++++++++++++++++++- appl/refind/refind.qrc | 3 + base/ReException.cpp | 25 +++ base/ReException.hpp | 11 ++ 9 files changed, 409 insertions(+), 7 deletions(-) create mode 100644 appl/refind/icons/cog_edit.png create mode 100644 appl/refind/icons/database_save.png create mode 100644 appl/refind/icons/disk.png diff --git a/appl/refind/icons/cog_edit.png b/appl/refind/icons/cog_edit.png new file mode 100644 index 0000000000000000000000000000000000000000..47b75a456a4bb1487dac02c60b7e2e9cb5e210a6 GIT binary patch literal 865 zcmV-n1D^beP)GR@vSHz5C(pPxHny(nM!6aSI^7R#-{J~?A^0H*YCdW>wX><0M=1!YHEsWHk&65 z2EzpTxW}DK*f^ce)R~!?WFk%?;`Pu5C{Y@ z9*YwPJjH96dcf=xJG z*kl}##L?N=83%;ar!Pg^cVqOf0lN#g5Vlp~vzQCln=Feu@%+Ain zAxsXvy}hQ%p)0kKIRWUX89RYeM1w`x^47xBl|kR;=6}n}%d;PbNXFDkg2d$HB$&Tm z{utC0|DU)7(XWO0;TB^4`9-wVaC#H&fkYyy8yXslc|4xD*f81w?^q4!T|J^pT>J`N z!zOX^g^2B+#!yvN6)P_<|3AiofdL_tJahBjw(;Om)xxQMf{?WUJ4;0fJMO^QaUmuX zzldkm(9nR~++1P8J!ouf?5?h^rbixT09(uOy~>BS_9Toi+4ykpEG-e7Pv>wrR8CF~ z&1SQ^k93^_07cLZBR}_>&jXObH zw2it@svr%qE?kJ(Xuudu+DSW|WWK!jNvbU^UO02#+Tt zYOko4%Vx8c4Gh!M(=Qem7g;XcE?n0Qi^XD?&*vX7@xPFCIh;%;@xMr?(;$(vo9j9i z6;riZMJyIWG#Z6r7^-I5HtO{{DwPWQ`}>&y+Y;!yjz*&a$8prX=XtO!3$0d5J>%Mz z1f8>Jnx-7^X2#7Yb#zC2VYfZ>c17@L{s)8{OuWBa3WHFfVXfhLv2t?V0V~q5R2D*D z&315l_#iF}b>Zoo?-;+7*`WOJWsMw(x3WXv`@U*s@Y-&edFEYpz0skP)dFfu zZ4wIp&Vbb!+|0+3Qa}p<*AH-eY>3q8s6?RA)zqP8W39IT5HLFG9m1F);gE|P`L7@@ zctjKsn1rA6!ZZR%R^(SjU!r=2o$yGp<$KViK~{B;AIcgvN+J+&Nvur+W(Sw&=H?z} zGMRW^U!Nl3AvWzQ3~C%Z*G*(?qLfNCq;tpg2yRW4@yl9;p3CK)O-@c8Sy))OUMiKc zQp#QYFZe-*@LZDInR^#F=Bm=!vA2i6tkEJ#i0aggzp2D%3!>h~r~3uLt(-IMoyFA~H+MJzd|s z^YP1Hc07G_>)Lgir!F1{Qn4GcTg%?koHo<=1qRN{}nPDolOeI^o4N5I>! zU$N=L=sg~ zDx#dOA*B0N~cqPsWI(^rbbkh)DS0_H_UN0C4l_kvWIm2#Kyy6%BCh z(yIUf003&1xdx>t$*eR2ZvXxT0001Z_R$y3Iju92q*wg58};}zm(OaAH=p|y0002M zh5O5#fxp|~jc?yi@+7$`d4Q6Hl%z;WiWG??NXR{Hx%)pMd~SE0000OQI literal 0 HcmV?d00001 diff --git a/appl/refind/mainwindow.cpp b/appl/refind/mainwindow.cpp index f21da77..2ca36ff 100644 --- a/appl/refind/mainwindow.cpp +++ b/appl/refind/mainwindow.cpp @@ -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 text 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. * diff --git a/appl/refind/mainwindow.hpp b/appl/refind/mainwindow.hpp index 6f0df88..6f2fff5 100644 --- a/appl/refind/mainwindow.hpp +++ b/appl/refind/mainwindow.hpp @@ -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; diff --git a/appl/refind/mainwindow.ui b/appl/refind/mainwindow.ui index 86f22c4..6355f21 100644 --- a/appl/refind/mainwindow.ui +++ b/appl/refind/mainwindow.ui @@ -17,6 +17,9 @@ + + + @@ -36,7 +39,7 @@ - Directory, File Patterns, Text Pattern + &Directory, File Patterns, Text Pattern @@ -394,9 +397,9 @@ - + - Size, Date, Depth, Excluded Dirs + &Size, Date, Depth, Excluded Dirs @@ -614,11 +617,220 @@ + + + &Export + + + + + 515 + 106 + 85 + 29 + + + + + + + + + + 10 + 11 + 981 + 101 + + + + + + + Export file: + + + + + + + + + true + + + ${full};${size};${modified} + + + + + + + + 50 + 16777215 + + + + Placeholder for the template + + + ... + + + + + + + + + + + &File + + + false + + + + + + + Clipboard + + + true + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + + true + + + refind.result.txt + + + + + + + + 50 + 16777215 + + + + Select the export file + + + ... + + + + + + + + + Exports file attributes (specified in the template line) of each found files found file in a textfile or clipboard + + + &Export + + + + :/main/icons/database_save.png:/main/icons/database_save.png + + + Alt+E + + + + + + + File footer: + + + + + + + Line template: + + + + + + + File header: + + + + + + + + 300 + 0 + + + + + 300 + 16777215 + + + + <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> + + + true + + + + + + + <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> + + + true + + + + + + - - - @@ -762,6 +974,7 @@ false + @@ -803,6 +1016,10 @@ + + + :/main/icons/database_save.png:/main/icons/database_save.png + &Export @@ -901,7 +1118,6 @@ - tabWidget comboBoxDirectory pushButtonUp pushButtonDirectory diff --git a/appl/refind/refind.qrc b/appl/refind/refind.qrc index 05e91c4..7c6cce9 100644 --- a/appl/refind/refind.qrc +++ b/appl/refind/refind.qrc @@ -15,5 +15,8 @@ icons/folder_magnify.png icons/folder.png icons/wand.png + icons/cog_edit.png + icons/database_save.png + icons/disk.png diff --git a/base/ReException.cpp b/base/ReException.cpp index 024acbd..6476de5 100644 --- a/base/ReException.cpp +++ b/base/ReException.cpp @@ -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; +} + diff --git a/base/ReException.hpp b/base/ReException.hpp index 03d3909..03782d8 100644 --- a/base/ReException.hpp +++ b/base/ReException.hpp @@ -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 -- 2.39.5